Mercurial > mercurial > hgweb_searcher03.cgi
diff src/miniframe.cpp @ 21:a2ad87cad48b
Enhanced the convenience of Cache dialog.
author | pyon@macmini |
---|---|
date | Wed, 17 Dec 2014 00:52:43 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/miniframe.cpp Wed Dec 17 00:52:43 2014 +0900 @@ -0,0 +1,251 @@ +// Filename : mini.cpp +// Last Change: 12-Dec-2014. +// +#include "main.h" +#include "db.h" +#include "hhsdb.h" +#include "miniframe.h" +#include "update.h" + +/////////////////////////////////////////////////////////////// +// カスタム検索ボックス +MiniSearchBox::MiniSearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style ) + : wxSearchCtrl( parent, id, value, pos, size, style ) +{ + SetMaxLength( 11 ); + #ifndef __WXMAC__ + ShowSearchButton( true ); + #endif + ShowCancelButton( false ); +} + +MiniSearchBox::~MiniSearchBox() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( MiniSearchBox, wxSearchCtrl ) + EVT_CHAR( MiniSearchBox::OnKey ) +END_EVENT_TABLE() + +// Event Handlers & Functions +void MiniSearchBox::OnKey( wxKeyEvent& event ) +{ + int kc = event.GetKeyCode(); + wxString s = GetValue(); + + if ( kc == 13 ) { + event.Skip(); + return; + } + + if ( kc == 45 ) { // テンキーの '-' キーで1文字削除 + wxString t = GetStringSelection(); + if ( t.IsEmpty() ) { + long p = GetInsertionPoint(); + if ( p > 0 ) Remove( p - 1, p ); + } + else { + Cut(); + } + return; + } + + if ( kc == WXK_ESCAPE ) { // clear by ESC + this->Clear(); + return; + } + + Cut(); + event.Skip(); +} + + +/////////////////////////////////////////////////////////////// +// メインフレーム + +// resources +#if !defined(__WXMSW__) && !defined(__WXPM__) + #include "sample.xpm" +#endif + +MiniFrame::MiniFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxFrame( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxSize( 100, 45 ), wxSize( 100, 45 ) ); + this->SetBackgroundColour( wxColour(wxT("WHITE")) ); + + // set the frame icon + SetIcon(wxICON(sample)); + + // + wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); + + m_staticText = new wxStaticText( this, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerTop->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0 ); + + m_searchBox = new MiniSearchBox( this, ID_MSEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + m_searchBox->SetFocus(); + bSizerTop->Add( m_searchBox, 1, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 0 ); + + // + this->SetSizer( bSizerTop ); + this->Layout(); + + this->Centre( wxBOTH ); + LoadParam(); + if ( CheckNewFiles( m_shared ) != 0 ) + Close(); +} + +MiniFrame::~MiniFrame() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( MiniFrame, wxFrame ) + EVT_TEXT_ENTER( ID_MSEARCH, MiniFrame::OnCommand ) +END_EVENT_TABLE() + +// Event Handlers & Functions +/* エンターキーフック */ +void MiniFrame::OnCommand( wxCommandEvent& event ) +{ + wxString s = m_searchBox->GetLineText(0); + + if ( s.IsSameAs( wxT(".") ) ) { + OpenAppDir(); + return; + } + + if ( s.IsSameAs( wxT("z") ) ) { + Transform( wxT("full mode") ); + return; + } + + if ( s.StartsWith( wxT("9") ) || s.IsSameAs( wxT("q") ) ) { + Close(); + return; + } + + wxRegEx reHhs( wxT("^0[1238][0-9]{8}.?$") ); + if ( reHhs.Matches( s ) ) { + + if ( s.Len() == 10 ) { + m_hhsno = s; + } + else { + m_hhsno = s.Left( 10 ); + } + + wxArrayString pathes = GetPathByHhsNo( m_hhsno ); + if ( pathes.IsEmpty() ) { + m_searchBox->SetValue( wxT("No data.") ); + m_searchBox->SelectAll(); + } + else { + if ( s.Right( 1 ).IsSameAs( wxT("+") ) ) { + PrintImages( pathes[0] ); + return; + } + OpenHhsDir( pathes[0] ); + } + return; + } + m_searchBox->SelectAll(); +} +/* パラメータを設定ファイルから読み込む */ +void MiniFrame::LoadParam( void ) +{ + conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); + config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); + + int x, y; + + // Shaerd + config->SetPath( wxT("/Index") ); + config->Read( wxT("shared"), &m_shared ); + +} +/* アプリフォルダを開く */ +void MiniFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) ) +{ + OpenAppDir(); +} +void MiniFrame::OpenAppDir( ) +{ + wxString appdir = wxGetCwd(); + wxString execmd = wxT("explorer ") + appdir; + wxExecute( execmd ); +} +/* 被保険者フォルダを開く */ +void MiniFrame::OpenHhsDir( wxString path ) +{ + wxString execmd = wxT("explorer ") + path; + wxExecute( execmd ); +} +/* 印刷 */ +void MiniFrame::PrintImages( wxString path ) +{ + wxDir dir( path ); + if ( !dir.IsOpened() ) return; + + wxString html; + html = html + wxT("<html><body>\n"); + + wxString file; + bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); + int n = 0; + wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH; + while ( cout ) { + file = path + wxFILE_SEP_PATH + file; + file.Replace( wxFILE_SEP_PATH, wxT("/") ); + wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n ); + wxCopyFile( file, tmpjpg, true ); + html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); + html = html + wxT("<div align=right><font size=-2><u>") + path.Right( 10 ) + wxT("</u></font></div>"); + cout = dir.GetNext( &file ); + n++; + } + html = html + wxT("</body></html>"); + + // start printing + wxHtmlPrintout hpout( wxT("Searcher03") ); + hpout.SetMargins( 0, 0, 0, 0, 0 ); + wxPrintDialogData pd; + wxPrinter p( &pd ); + + hpout.SetHtmlText( html, wxEmptyString, false ); + p.Print( NULL, &hpout, true ); +} +/* フルモードに変形 */ +void MiniFrame::Transform( wxString mode ) +{ + wxTextFile textfile; + textfile.Open( wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf") ); + for ( int i=0; i<textfile.GetLineCount(); i++ ) { + if ( textfile[i].StartsWith( wxT("mode=") ) ) { + textfile.RemoveLine( i ); + textfile.InsertLine( wxT("mode=0"), i ); + } + } + textfile.Write(); + textfile.Close(); + + Show( false ); + wxExecute( wxT("searcher03.exe") ); + wxSleep( 1 ); + + textfile.Open( wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf") ); + for ( int i=0; i<textfile.GetLineCount(); i++ ) { + if ( textfile[i].StartsWith( wxT("mode=") ) ) { + textfile.RemoveLine( i ); + textfile.InsertLine( wxT("mode=1"), i ); + } + } + textfile.Write(); + textfile.Close(); + + Close(); +} +