Mercurial > mercurial > hgweb_searcher03.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 20:226774bf49fc | 21:a2ad87cad48b |
|---|---|
| 1 // Filename : mini.cpp | |
| 2 // Last Change: 12-Dec-2014. | |
| 3 // | |
| 4 #include "main.h" | |
| 5 #include "db.h" | |
| 6 #include "hhsdb.h" | |
| 7 #include "miniframe.h" | |
| 8 #include "update.h" | |
| 9 | |
| 10 /////////////////////////////////////////////////////////////// | |
| 11 // カスタム検索ボックス | |
| 12 MiniSearchBox::MiniSearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style ) | |
| 13 : wxSearchCtrl( parent, id, value, pos, size, style ) | |
| 14 { | |
| 15 SetMaxLength( 11 ); | |
| 16 #ifndef __WXMAC__ | |
| 17 ShowSearchButton( true ); | |
| 18 #endif | |
| 19 ShowCancelButton( false ); | |
| 20 } | |
| 21 | |
| 22 MiniSearchBox::~MiniSearchBox() | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 // Event Table | |
| 27 BEGIN_EVENT_TABLE( MiniSearchBox, wxSearchCtrl ) | |
| 28 EVT_CHAR( MiniSearchBox::OnKey ) | |
| 29 END_EVENT_TABLE() | |
| 30 | |
| 31 // Event Handlers & Functions | |
| 32 void MiniSearchBox::OnKey( wxKeyEvent& event ) | |
| 33 { | |
| 34 int kc = event.GetKeyCode(); | |
| 35 wxString s = GetValue(); | |
| 36 | |
| 37 if ( kc == 13 ) { | |
| 38 event.Skip(); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 if ( kc == 45 ) { // テンキーの '-' キーで1文字削除 | |
| 43 wxString t = GetStringSelection(); | |
| 44 if ( t.IsEmpty() ) { | |
| 45 long p = GetInsertionPoint(); | |
| 46 if ( p > 0 ) Remove( p - 1, p ); | |
| 47 } | |
| 48 else { | |
| 49 Cut(); | |
| 50 } | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 if ( kc == WXK_ESCAPE ) { // clear by ESC | |
| 55 this->Clear(); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 Cut(); | |
| 60 event.Skip(); | |
| 61 } | |
| 62 | |
| 63 | |
| 64 /////////////////////////////////////////////////////////////// | |
| 65 // メインフレーム | |
| 66 | |
| 67 // resources | |
| 68 #if !defined(__WXMSW__) && !defined(__WXPM__) | |
| 69 #include "sample.xpm" | |
| 70 #endif | |
| 71 | |
| 72 MiniFrame::MiniFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | |
| 73 : wxFrame( parent, id, title, pos, size, style ) | |
| 74 { | |
| 75 this->SetSizeHints( wxSize( 100, 45 ), wxSize( 100, 45 ) ); | |
| 76 this->SetBackgroundColour( wxColour(wxT("WHITE")) ); | |
| 77 | |
| 78 // set the frame icon | |
| 79 SetIcon(wxICON(sample)); | |
| 80 | |
| 81 // | |
| 82 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
| 83 | |
| 84 m_staticText = new wxStaticText( this, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 85 bSizerTop->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0 ); | |
| 86 | |
| 87 m_searchBox = new MiniSearchBox( this, ID_MSEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); | |
| 88 m_searchBox->SetFocus(); | |
| 89 bSizerTop->Add( m_searchBox, 1, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 0 ); | |
| 90 | |
| 91 // | |
| 92 this->SetSizer( bSizerTop ); | |
| 93 this->Layout(); | |
| 94 | |
| 95 this->Centre( wxBOTH ); | |
| 96 LoadParam(); | |
| 97 if ( CheckNewFiles( m_shared ) != 0 ) | |
| 98 Close(); | |
| 99 } | |
| 100 | |
| 101 MiniFrame::~MiniFrame() | |
| 102 { | |
| 103 } | |
| 104 | |
| 105 // Event Table | |
| 106 BEGIN_EVENT_TABLE( MiniFrame, wxFrame ) | |
| 107 EVT_TEXT_ENTER( ID_MSEARCH, MiniFrame::OnCommand ) | |
| 108 END_EVENT_TABLE() | |
| 109 | |
| 110 // Event Handlers & Functions | |
| 111 /* エンターキーフック */ | |
| 112 void MiniFrame::OnCommand( wxCommandEvent& event ) | |
| 113 { | |
| 114 wxString s = m_searchBox->GetLineText(0); | |
| 115 | |
| 116 if ( s.IsSameAs( wxT(".") ) ) { | |
| 117 OpenAppDir(); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 if ( s.IsSameAs( wxT("z") ) ) { | |
| 122 Transform( wxT("full mode") ); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 if ( s.StartsWith( wxT("9") ) || s.IsSameAs( wxT("q") ) ) { | |
| 127 Close(); | |
| 128 return; | |
| 129 } | |
| 130 | |
| 131 wxRegEx reHhs( wxT("^0[1238][0-9]{8}.?$") ); | |
| 132 if ( reHhs.Matches( s ) ) { | |
| 133 | |
| 134 if ( s.Len() == 10 ) { | |
| 135 m_hhsno = s; | |
| 136 } | |
| 137 else { | |
| 138 m_hhsno = s.Left( 10 ); | |
| 139 } | |
| 140 | |
| 141 wxArrayString pathes = GetPathByHhsNo( m_hhsno ); | |
| 142 if ( pathes.IsEmpty() ) { | |
| 143 m_searchBox->SetValue( wxT("No data.") ); | |
| 144 m_searchBox->SelectAll(); | |
| 145 } | |
| 146 else { | |
| 147 if ( s.Right( 1 ).IsSameAs( wxT("+") ) ) { | |
| 148 PrintImages( pathes[0] ); | |
| 149 return; | |
| 150 } | |
| 151 OpenHhsDir( pathes[0] ); | |
| 152 } | |
| 153 return; | |
| 154 } | |
| 155 m_searchBox->SelectAll(); | |
| 156 } | |
| 157 /* パラメータを設定ファイルから読み込む */ | |
| 158 void MiniFrame::LoadParam( void ) | |
| 159 { | |
| 160 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); | |
| 161 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); | |
| 162 | |
| 163 int x, y; | |
| 164 | |
| 165 // Shaerd | |
| 166 config->SetPath( wxT("/Index") ); | |
| 167 config->Read( wxT("shared"), &m_shared ); | |
| 168 | |
| 169 } | |
| 170 /* アプリフォルダを開く */ | |
| 171 void MiniFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) ) | |
| 172 { | |
| 173 OpenAppDir(); | |
| 174 } | |
| 175 void MiniFrame::OpenAppDir( ) | |
| 176 { | |
| 177 wxString appdir = wxGetCwd(); | |
| 178 wxString execmd = wxT("explorer ") + appdir; | |
| 179 wxExecute( execmd ); | |
| 180 } | |
| 181 /* 被保険者フォルダを開く */ | |
| 182 void MiniFrame::OpenHhsDir( wxString path ) | |
| 183 { | |
| 184 wxString execmd = wxT("explorer ") + path; | |
| 185 wxExecute( execmd ); | |
| 186 } | |
| 187 /* 印刷 */ | |
| 188 void MiniFrame::PrintImages( wxString path ) | |
| 189 { | |
| 190 wxDir dir( path ); | |
| 191 if ( !dir.IsOpened() ) return; | |
| 192 | |
| 193 wxString html; | |
| 194 html = html + wxT("<html><body>\n"); | |
| 195 | |
| 196 wxString file; | |
| 197 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); | |
| 198 int n = 0; | |
| 199 wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH; | |
| 200 while ( cout ) { | |
| 201 file = path + wxFILE_SEP_PATH + file; | |
| 202 file.Replace( wxFILE_SEP_PATH, wxT("/") ); | |
| 203 wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n ); | |
| 204 wxCopyFile( file, tmpjpg, true ); | |
| 205 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
| 206 html = html + wxT("<div align=right><font size=-2><u>") + path.Right( 10 ) + wxT("</u></font></div>"); | |
| 207 cout = dir.GetNext( &file ); | |
| 208 n++; | |
| 209 } | |
| 210 html = html + wxT("</body></html>"); | |
| 211 | |
| 212 // start printing | |
| 213 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
| 214 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
| 215 wxPrintDialogData pd; | |
| 216 wxPrinter p( &pd ); | |
| 217 | |
| 218 hpout.SetHtmlText( html, wxEmptyString, false ); | |
| 219 p.Print( NULL, &hpout, true ); | |
| 220 } | |
| 221 /* フルモードに変形 */ | |
| 222 void MiniFrame::Transform( wxString mode ) | |
| 223 { | |
| 224 wxTextFile textfile; | |
| 225 textfile.Open( wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf") ); | |
| 226 for ( int i=0; i<textfile.GetLineCount(); i++ ) { | |
| 227 if ( textfile[i].StartsWith( wxT("mode=") ) ) { | |
| 228 textfile.RemoveLine( i ); | |
| 229 textfile.InsertLine( wxT("mode=0"), i ); | |
| 230 } | |
| 231 } | |
| 232 textfile.Write(); | |
| 233 textfile.Close(); | |
| 234 | |
| 235 Show( false ); | |
| 236 wxExecute( wxT("searcher03.exe") ); | |
| 237 wxSleep( 1 ); | |
| 238 | |
| 239 textfile.Open( wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf") ); | |
| 240 for ( int i=0; i<textfile.GetLineCount(); i++ ) { | |
| 241 if ( textfile[i].StartsWith( wxT("mode=") ) ) { | |
| 242 textfile.RemoveLine( i ); | |
| 243 textfile.InsertLine( wxT("mode=1"), i ); | |
| 244 } | |
| 245 } | |
| 246 textfile.Write(); | |
| 247 textfile.Close(); | |
| 248 | |
| 249 Close(); | |
| 250 } | |
| 251 |
