0
|
1 // Filename : rsearcher.cpp
|
5
|
2 // Last Change: 2018-10-22 ŒŽ 16:20:03.
|
0
|
3 //
|
|
4
|
2
|
5 #include <wx/arrstr.h>
|
3
|
6 #include <wx/html/htmprint.h>
|
5
|
7 #include <wx/clipbrd.h>
|
4
|
8 #include "id.h"
|
0
|
9 #include "rsearcher.h"
|
|
10 #include "main.h"
|
|
11
|
5
|
12
|
|
13 /********************/
|
|
14 /** HhsClass **/
|
|
15 /********************/
|
|
16 HhsClass::HhsClass( wxArrayString& buf )
|
|
17 {
|
|
18 no = buf[0];
|
|
19 birth = buf[1];
|
|
20 name = buf[2];
|
|
21 kana = buf[3];
|
|
22 addr = buf[4];
|
|
23 sex = buf[5];
|
|
24 }
|
|
25
|
0
|
26 /********************/
|
|
27 /** MySearchCtrl **/
|
|
28 /********************/
|
|
29 MySearchCtrl::MySearchCtrl( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style )
|
|
30 : wxSearchCtrl( parent, id, value, pos, size, style )
|
|
31 {
|
|
32 m_parent = parent;
|
|
33 SetMaxLength( 10 );
|
|
34 #ifndef __WXMAC__
|
|
35 ShowSearchButton( true );
|
|
36 #endif
|
|
37 ShowCancelButton( false );
|
|
38
|
|
39 wxFont font( 12, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD );
|
|
40 SetFont( font );
|
|
41 }
|
|
42
|
|
43 MySearchCtrl::~MySearchCtrl()
|
|
44 {
|
|
45 }
|
|
46
|
|
47 // Event Table
|
|
48 BEGIN_EVENT_TABLE( MySearchCtrl, wxSearchCtrl )
|
|
49 EVT_CHAR( MySearchCtrl::OnKey )
|
|
50 END_EVENT_TABLE()
|
|
51
|
|
52 // Event Handlers & Functions
|
|
53 void MySearchCtrl::OnKey( wxKeyEvent& event )
|
|
54 {
|
|
55 int kc = event.GetKeyCode();
|
|
56
|
|
57 if ( kc == 13 ) { // Enter
|
2
|
58 SelectAll();
|
0
|
59
|
|
60 MainFrame* f = (MainFrame*)FindWindowById( ID_MAIN );
|
2
|
61 f->Cmd( GetValue() );
|
0
|
62
|
|
63 event.Skip();
|
|
64 return;
|
|
65 }
|
|
66
|
|
67 if ( kc == 45 ) { // Num-Key '-' as Backspace
|
|
68 wxString t = GetStringSelection();
|
|
69 if ( t.IsEmpty() ) {
|
|
70 long p = GetInsertionPoint();
|
|
71 if ( p > 0 ) Remove( p - 1, p );
|
|
72 }
|
|
73 else {
|
|
74 Cut();
|
|
75 }
|
|
76 return;
|
|
77 }
|
|
78
|
|
79 if ( kc == WXK_ESCAPE ) { // clear by ESC
|
|
80 this->Clear();
|
|
81 return;
|
|
82 }
|
|
83
|
|
84 event.Skip();
|
|
85 }
|
|
86
|
|
87 /********************/
|
|
88 /** MyStaticBitmap **/
|
|
89 /********************/
|
|
90 MyStaticBitmap::MyStaticBitmap( wxScrolledWindow *parent, wxWindowID id, const wxBitmap &label, const wxPoint &pos, const wxSize &size, long style, const wxString &name )
|
|
91 : wxStaticBitmap( parent, id, label, pos, size, style, name )
|
|
92 {
|
|
93 m_parent = parent;
|
3
|
94 Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OnLeftDown ), NULL, this );
|
|
95 Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OnLeftUp ), NULL, this );
|
|
96 Connect( wxEVT_MOTION, wxMouseEventHandler( OnMotion ), NULL, this );
|
|
97 Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OnWheel ), NULL, this );
|
|
98
|
|
99 Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OnStartRGesture ), NULL, this );
|
|
100 Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OnEndRGesture ), NULL, this );
|
0
|
101 }
|
|
102
|
|
103 MyStaticBitmap::~MyStaticBitmap()
|
|
104 {
|
3
|
105 Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OnLeftDown ), NULL, this );
|
|
106 Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( OnLeftUp ), NULL, this );
|
|
107 Disconnect( wxEVT_MOTION, wxMouseEventHandler( OnMotion ), NULL, this );
|
|
108 Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OnWheel ), NULL, this );
|
|
109
|
|
110 Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OnStartRGesture ), NULL, this );
|
|
111 Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( OnEndRGesture ), NULL, this );
|
0
|
112 }
|
|
113
|
|
114 // Event Handlers
|
|
115 void MyStaticBitmap::OnWheel( wxMouseEvent& event )
|
|
116 {
|
|
117 if ( event.ControlDown() ) {
|
|
118 if ( event.GetWheelRotation() < 0 ) {
|
|
119 if ( m_zoom < 4 ) m_zoom++;
|
|
120 }
|
|
121 else {
|
|
122 if ( m_zoom > 0 ) m_zoom--;
|
|
123 }
|
|
124 SetBitmap( m_bmp[ m_zoom ] );
|
|
125 m_parent->SetScrollbars( 10, 10, m_bmp[ m_zoom ].GetWidth() / 10, m_bmp[ m_zoom ].GetHeight() / 10 );
|
|
126 return;
|
|
127 }
|
|
128 event.Skip();
|
|
129 }
|
|
130
|
|
131 void MyStaticBitmap::OnLeftDown( wxMouseEvent& event )
|
|
132 {
|
|
133 event.GetPosition( &m_dragx, &m_dragy );
|
|
134 SetCursor( wxCursor( wxCURSOR_SIZING ) );
|
|
135 }
|
|
136
|
|
137 void MyStaticBitmap::OnLeftUp( wxMouseEvent& WXUNUSED(event) )
|
|
138 {
|
|
139 SetCursor( wxCursor( wxCURSOR_ARROW ) );
|
|
140 }
|
|
141
|
|
142 void MyStaticBitmap::OnMotion( wxMouseEvent& event )
|
|
143 {
|
5
|
144 if ( event.RightIsDown() ) return;
|
0
|
145 if ( event.Dragging() ) {
|
|
146 int xv, yv, x, y;
|
|
147 m_parent->GetViewStart( &xv, &yv );
|
|
148
|
|
149 event.GetPosition( &x, &y );
|
|
150
|
|
151 int xa = abs( x - m_dragx );
|
|
152 int ya = abs( y - m_dragy );
|
|
153 int xs = x - m_dragx < 0 ? -1 : 1;
|
|
154 int ys = y - m_dragy < 0 ? -1 : 1;
|
|
155
|
|
156 /* handai dakedo sumu-zu
|
|
157 m_parent->Scroll( xv + xs * log10( xa + 1 ), yv + ys * log10( ya + 1 ) );
|
|
158 */
|
|
159 m_parent->Scroll( xv + xs * log10( xa + 1 ), yv + ys * log10( ya + 1 ) );
|
|
160
|
|
161 m_dragx = x; m_dragy = y;
|
|
162 }
|
|
163 }
|
|
164
|
3
|
165 /* right-gesture: start detect */
|
|
166 void MyStaticBitmap::OnStartRGesture( wxMouseEvent& event )
|
|
167 {
|
|
168 event.GetPosition( &cx, &cy );
|
|
169 }
|
|
170
|
|
171 /* right-gesture: judge */
|
|
172 void MyStaticBitmap::OnEndRGesture( wxMouseEvent& event )
|
|
173 {
|
|
174 int x, y;
|
|
175 event.GetPosition( &x, &y );
|
|
176
|
|
177 int dx = x - cx;
|
|
178 int dy = y - cy;
|
|
179 float rad = fabs( atan2( dy, dx ) );
|
|
180 float pi = 3.14159;
|
|
181
|
|
182 // to right
|
4
|
183 if ( rad < pi / 8 && dx > 0 ) {
|
|
184 ChangeBook( 1 );
|
3
|
185 }
|
|
186 // to left
|
4
|
187 else if ( rad > pi / 8 * 7 && rad < pi && dx < 0 ) {
|
|
188 ChangeBook( -1 );
|
3
|
189 }
|
|
190 // to up-right
|
4
|
191 else if ( rad > pi / 8 && rad < pi / 8 * 3 && dx > 0 ) {
|
5
|
192 MainFrame* mf = (MainFrame*)FindWindowById( ID_MAIN );
|
|
193 mf->Close();
|
3
|
194 }
|
4
|
195 // down
|
|
196 else if ( rad > pi / 8 * 3 && rad < pi / 8 * 5 && dy > 0 ) {
|
|
197 MainFrame* mf = (MainFrame*)FindWindowById( ID_MAIN );
|
|
198 mf->PrintImages();
|
|
199 }
|
|
200 //wxMessageBox( wxString::Format( "%d %d %f", dx, dy, rad ));
|
3
|
201 }
|
|
202
|
0
|
203 // Functions
|
4
|
204 void MyStaticBitmap::ChangeBook( int i )
|
|
205 {
|
|
206 wxNotebook* nb = (wxNotebook*)FindWindowById( ID_NBOOK );
|
|
207 int n = nb->GetSelection();
|
|
208 if ( i > 0 ) {
|
|
209 if ( n == nb->GetPageCount() - 1 ) return;
|
|
210 nb->SetSelection( ++n );
|
|
211 } else {
|
|
212 if ( n == 0 ) return;
|
|
213 nb->SetSelection( --n );
|
|
214 }
|
|
215 }
|
0
|
216
|
|
217 /********************/
|
|
218 /** Main Frame **/
|
|
219 /********************/
|
|
220 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
221 : wxFrame( parent, id, title, pos, size, style )
|
|
222 {
|
1
|
223 CreateControls();
|
5
|
224 SetAccelerator();
|
|
225 LoadBitmaps( wxEmptyString, false );
|
3
|
226 m_timer.SetOwner( this, ID_TIMER );
|
1
|
227 }
|
|
228
|
|
229 MainFrame::~MainFrame()
|
|
230 {
|
2
|
231 RemoveFile( wxT( "auth.db" ) );
|
|
232 RemoveFile( wxT( "hhs.db" ) );
|
|
233 RemoveFile( wxT( ".cache/*" ) );
|
1
|
234 }
|
|
235
|
|
236 // Event Table
|
|
237 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
|
2
|
238 EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected )
|
1
|
239 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
|
|
240 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
|
3
|
241 EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint )
|
5
|
242 EVT_BUTTON( ID_PSEARCH, MainFrame::OnPasteSearch )
|
|
243 EVT_BUTTON( wxID_HELP, MainFrame::OnHelp )
|
3
|
244 EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout )
|
|
245 EVT_CLOSE( MainFrame::OnClose )
|
|
246 EVT_IDLE( MainFrame::OnIdle )
|
|
247 EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
|
1
|
248 END_EVENT_TABLE()
|
|
249
|
|
250
|
|
251 // Event Handler
|
2
|
252 void MainFrame::OnItemSelected( wxDataViewEvent& WXUNUSED(event) )
|
|
253 {
|
|
254 int r = m_dataViewListCtrl->GetSelectedRow();
|
|
255 wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
|
3
|
256 if ( ready.IsSameAs( wxT( "OK" ), true ) ) {
|
|
257 wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
|
|
258 date.Replace( wxT( "-" ), wxEmptyString, true );
|
5
|
259 LoadBitmaps( date, false );
|
3
|
260 } else {
|
5
|
261 LoadBitmaps( wxEmptyString, false );
|
2
|
262 }
|
|
263 }
|
|
264
|
1
|
265 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) )
|
|
266 {
|
|
267 int r = m_dataViewListCtrl->GetSelectedRow();
|
3
|
268 wxString status = m_dataViewListCtrl->GetTextValue( r, 2 );
|
|
269 if ( status.IsSameAs( wxT( "OK" ), true ) ) return;
|
|
270
|
2
|
271 wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
|
|
272 date.Replace( wxT( "-" ), wxEmptyString, true );
|
|
273 GetImages( m_hhs, date );
|
5
|
274 if ( LoadBitmaps( date, true ) )
|
|
275 m_dataViewListCtrl->SetTextValue( wxT( "OK" ), r, 2 );
|
1
|
276 }
|
|
277
|
|
278 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) )
|
|
279 {
|
|
280 for ( int i = 0; i < m_notebook->GetPageCount(); i++ ) {
|
|
281 m_notebook->SetPageImage( i, 1 );
|
|
282 }
|
|
283 m_notebook->SetPageImage( m_notebook->GetSelection(), 0 );
|
|
284 }
|
|
285
|
3
|
286 void MainFrame::OnClose( wxCloseEvent& WXUNUSED(event) ) // save config
|
1
|
287 {
|
5
|
288 WriteLog( wxT( "[logout]" ) );
|
1
|
289 if ( !IsIconized() && !IsMaximized() ) {
|
|
290 wxGetApp().rect = this->GetRect();
|
|
291 }
|
|
292 Destroy();
|
|
293 }
|
|
294
|
5
|
295 void MainFrame::OnPasteSearch( wxCommandEvent& WXUNUSED(event) )
|
|
296 {
|
|
297 PasteSeaarch();
|
|
298 }
|
|
299
|
3
|
300 void MainFrame::OnPrint( wxCommandEvent& WXUNUSED(event) )
|
|
301 {
|
|
302 PrintImages();
|
|
303 }
|
|
304
|
5
|
305 void MainFrame::OnHelp( wxCommandEvent& WXUNUSED(event) )
|
|
306 {
|
|
307 wxString version, build;
|
|
308 version = wxString::Format( wxT( "Re:Searcher-- version %s / %s\n\n" ), RSVER, RSRELEASE );
|
|
309 build = wxString::Format( wxT( "build with %s\nrunning under %s." ), wxVERSION_STRING, wxGetOsDescription() );
|
|
310
|
|
311 wxMessageBox( version + build, wxT( "Help" ) );
|
|
312 return;
|
|
313 }
|
|
314
|
3
|
315 void MainFrame::OnLogout( wxCommandEvent& WXUNUSED(event) )
|
|
316 {
|
|
317 wxMessageBox("logout");
|
|
318 return;
|
|
319 }
|
|
320
|
|
321 void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) )
|
|
322 {
|
5
|
323 //wxMessageBox( "timer !" );
|
3
|
324 // logout
|
|
325 }
|
|
326
|
|
327 void MainFrame::OnIdle( wxIdleEvent& event )
|
|
328 {
|
|
329 if ( !m_timer.IsRunning() ) {
|
|
330 m_timer.Start( 300 * 1000, wxTIMER_ONE_SHOT );
|
|
331 }
|
|
332 event.RequestMore();
|
|
333 event.Skip();
|
|
334 }
|
|
335
|
1
|
336 // Functions
|
|
337 void MainFrame::CreateControls( void )
|
|
338 {
|
0
|
339 this->SetIcon( wxIcon( wxT( "sample" ) ) );
|
|
340 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
5
|
341 this->SetBackgroundColour( wxColour( 30, 80, 40 ) );
|
|
342 //this->SetBackgroundColour( wxColour( 153, 153, 153 ) );
|
0
|
343
|
|
344 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
|
|
345
|
|
346 // Left
|
|
347 wxImageList* imgList = new wxImageList( 16, 16, false, 1 );
|
|
348 wxBitmap bmp( wxT( "image/blue.png" ), wxBITMAP_TYPE_PNG );
|
|
349 imgList->Add( bmp, wxNullBitmap );
|
|
350 bmp.LoadFile( wxT( "image/water.png" ), wxBITMAP_TYPE_PNG );
|
|
351 imgList->Add( bmp, wxNullBitmap );
|
|
352
|
|
353 m_notebook = new wxNotebook( this, ID_NBOOK, wxDefaultPosition, wxDefaultSize, 0 );
|
|
354 m_notebook->SetImageList( imgList );
|
|
355
|
|
356 m_scrolledWindow1 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
357 m_scrolledWindow1->SetScrollRate( 5, 5 );
|
|
358 m_notebook->AddPage( m_scrolledWindow1, wxT( "Image-01" ), false, 0 );
|
|
359
|
|
360 m_scrolledWindow2 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
361 m_scrolledWindow2->SetScrollRate( 5, 5 );
|
|
362 m_notebook->AddPage( m_scrolledWindow2, wxT( "Image-02" ), false, 0 );
|
|
363
|
|
364 m_scrolledWindow3 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
365 m_scrolledWindow3->SetScrollRate( 5, 5 );
|
|
366 m_notebook->AddPage( m_scrolledWindow3, wxT( "Image-03" ), false, 0 );
|
|
367
|
|
368 m_scrolledWindow4 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
369 m_scrolledWindow4->SetScrollRate( 5, 5 );
|
|
370 m_notebook->AddPage( m_scrolledWindow4, wxT( "Image-04" ), false, 0 );
|
|
371
|
|
372 m_scrolledWindow5 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
373 m_scrolledWindow5->SetScrollRate( 5, 5 );
|
|
374 m_notebook->AddPage( m_scrolledWindow5, wxT( "Image-05" ), false, 0 );
|
|
375
|
|
376 m_scrolledWindow6 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
377 m_scrolledWindow6->SetScrollRate( 5, 5 );
|
|
378 m_notebook->AddPage( m_scrolledWindow6, wxT( "Image-06" ), false, 0 );
|
|
379
|
|
380 bSizerTop->Add( m_notebook, 1, wxEXPAND|wxALL, 5 );
|
|
381
|
|
382 // Right
|
|
383 wxBoxSizer* bSizerRight = new wxBoxSizer( wxVERTICAL );
|
|
384
|
|
385 m_searchCtrl = new MySearchCtrl( this, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxSize( -1, 24 ), wxTE_PROCESS_ENTER );
|
|
386 bSizerRight->Add( m_searchCtrl, 0, wxALL, 5 );
|
|
387 m_searchCtrl->SetFocus();
|
|
388
|
5
|
389 m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, -1 ), wxTE_READONLY );
|
0
|
390 m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) );
|
|
391 bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 );
|
|
392
|
5
|
393 m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 160, -1 ), wxTE_READONLY );
|
0
|
394 m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) );
|
|
395 bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 );
|
|
396
|
|
397 m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE );
|
2
|
398 m_dataViewListColumnNo = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ), wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
|
|
399 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 80, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
|
|
400 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Ready" ), wxDATAVIEW_CELL_INERT, 60, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
|
0
|
401
|
|
402 bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 );
|
|
403
|
|
404 m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
405 bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 );
|
|
406
|
2
|
407 m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1, 200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
|
0
|
408 bSizerRight->Add( m_slider, 0, wxALL, 5 );
|
|
409
|
5
|
410 m_buttonPsearch = new wxButton( this, ID_PSEARCH, wxT( "Paste-Search" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
411 bSizerRight->Add( m_buttonPsearch, 0, wxALL, 5 );
|
|
412
|
3
|
413 m_buttonPrint = new wxButton( this, wxID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
|
0
|
414 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
|
|
415
|
5
|
416 m_buttonHelp = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
417 bSizerRight->Add( m_buttonHelp, 0, wxALL, 5 );
|
|
418
|
3
|
419 m_buttonLogout = new wxButton( this, ID_LOGOUT, wxT( "Logout" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
420 bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 );
|
|
421
|
0
|
422 bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 );
|
|
423
|
|
424 this->SetSizer( bSizerTop );
|
|
425 this->Layout();
|
|
426
|
|
427 //this->Centre( wxBOTH );
|
|
428
|
|
429 m_staticBitmap1 = new MyStaticBitmap( m_scrolledWindow1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
430 m_staticBitmap2 = new MyStaticBitmap( m_scrolledWindow2, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
431 m_staticBitmap3 = new MyStaticBitmap( m_scrolledWindow3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
432 m_staticBitmap4 = new MyStaticBitmap( m_scrolledWindow4, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
433 m_staticBitmap5 = new MyStaticBitmap( m_scrolledWindow5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
434 }
|
|
435
|
5
|
436 void MainFrame::SetAccelerator( void )
|
|
437 {
|
|
438 wxAcceleratorEntry entries[2];
|
|
439 entries[0].Set( wxACCEL_CTRL, (int) 'P', wxID_PRINT );
|
|
440 entries[1].Set( wxACCEL_NORMAL, WXK_F1, wxID_HELP );
|
|
441 /*
|
|
442 entries[1].Set( wxACCEL_CTRL, (int) 'X', wxID_EXIT );
|
|
443 entries[2].Set( wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
|
|
444 entries[3].Set( wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
|
|
445 */
|
|
446 wxAcceleratorTable accel( 2, entries );
|
|
447 SetAcceleratorTable( accel );
|
|
448 }
|
|
449
|
0
|
450 void MainFrame::Cmd( wxString cmd )
|
|
451 {
|
|
452 m_dataViewListCtrl->DeleteAllItems();
|
5
|
453 LoadBitmaps( wxEmptyString, false );
|
|
454 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
|
0
|
455
|
2
|
456 if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) {
|
0
|
457 Close();
|
2
|
458 return;
|
0
|
459 }
|
|
460
|
2
|
461 if ( cmd.IsSameAs( wxT( "c" ), true ) || cmd.IsSameAs( wxT( "cmd" ), true ) ) {
|
|
462 return;
|
|
463 }
|
|
464
|
3
|
465 if ( cmd.IsSameAs( wxT( "k" ), true ) ) {
|
|
466 // hiragana kensaku
|
|
467 return;
|
|
468 }
|
|
469
|
|
470 if ( cmd.IsSameAs( wxT( "." ), false ) ) {
|
0
|
471 wxString appdir = wxGetCwd();
|
|
472 wxString execmd = wxT( "explorer " ) + appdir;
|
|
473 wxExecute( execmd );
|
|
474 return;
|
|
475 }
|
|
476
|
3
|
477 if ( cmd.IsSameAs( wxT( "*" ), false ) ) {
|
5
|
478 PasteSeaarch();
|
|
479 return;
|
3
|
480 }
|
|
481
|
|
482 if ( cmd.IsSameAs( wxT( "+" ), false ) ) {
|
5
|
483 PrintImages();
|
3
|
484 return;
|
|
485 }
|
|
486
|
0
|
487 if ( reHhs.Matches( cmd ) ) {
|
2
|
488 m_hhs = m_searchCtrl->GetValue();
|
|
489 Search();
|
|
490 return;
|
|
491 }
|
0
|
492
|
3
|
493 wxMessageBox( wxT( "Bad Input !!" ) );
|
0
|
494 }
|
|
495
|
5
|
496 bool MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
|
0
|
497 {
|
5
|
498 sb->SetBitmap( wxNullBitmap );
|
|
499 sc->Scroll( 0, 0 );
|
|
500
|
|
501 bool ok = true;
|
2
|
502 if ( startup ) {
|
5
|
503 file = wxT( "image/hello.jpg" );
|
2
|
504 startup = false;
|
|
505 }
|
5
|
506 if ( !wxFileExists( file ) ) {
|
|
507 file = wxT( "image/testpattern.jpg" );
|
|
508 ok = false;
|
|
509 }
|
0
|
510 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
|
|
511 int width = bmp.GetWidth();
|
|
512 int height = bmp.GetHeight();
|
|
513 wxImage img = bmp.ConvertToImage();
|
|
514
|
|
515 int ww, wh;
|
1
|
516 sc->GetSize( &ww, &wh );
|
0
|
517
|
3
|
518 float w = ww - 30;
|
0
|
519 float h = w * height / width;
|
|
520 sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
|
5
|
521 sc->SetScrollbars( 10, 10, (int)w / 10, (int)h / 10 );
|
0
|
522
|
5
|
523 return ok;
|
0
|
524 }
|
|
525
|
5
|
526 bool MainFrame::LoadBitmaps( wxString date, bool reload )
|
0
|
527 {
|
5
|
528 bool ok;
|
|
529 ok = LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( wxT( ".cache/%08s_1" ), date ) );
|
|
530 ok = LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( wxT( ".cache/%08s_2" ), date ) );
|
|
531 ok = LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( wxT( ".cache/%08s_3" ), date ) );
|
|
532 ok = LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( wxT( ".cache/%08s_4" ), date ) );
|
|
533 ok = LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( wxT( ".cache/%08s_5" ), date ) );
|
|
534
|
|
535 if ( !ok && reload ) {
|
|
536 wxSleep( 5 );
|
|
537 LoadBitmaps( date, false );
|
|
538 }
|
|
539 return ok;
|
2
|
540 }
|
|
541
|
|
542 void MainFrame::GetImages( wxString hhs, wxString date )
|
|
543 {
|
|
544 wxArrayString args; // http get
|
|
545 args.Add( wxT( "client.exe" ) );
|
|
546 args.Add( m_server );
|
|
547 args.Add( hhs );
|
|
548 args.Add( date );
|
|
549
|
3
|
550 int estimate = 5;
|
|
551 wxProgressDialog pd( wxT( "Connecting Server" ), wxT( "Start..." ), estimate, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
552 pd.SetSize( wxSize( 320, 140 ) );
|
|
553
|
2
|
554 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_ASYNC|wxEXEC_HIDE_CONSOLE );
|
3
|
555 for ( int i = 0; i < estimate; i++ ) {
|
|
556 wxSleep( 1 );
|
|
557 pd.Update( i, wxT( "Now Loading..." ) );
|
|
558 }
|
0
|
559 }
|
|
560
|
2
|
561 void MainFrame::Search( void )
|
0
|
562 {
|
5
|
563 // hhs info
|
|
564 if ( hhash.count( m_hhs ) ) {
|
|
565 m_textCtrlName->SetValue( hhash[ m_hhs ]->name );
|
|
566 m_textCtrlAddr->SetValue( hhash[ m_hhs ]->addr );
|
|
567 }
|
|
568
|
|
569 // index
|
2
|
570 wxString date;
|
|
571 int match_cnt = 0;
|
|
572 for ( int i = 0; i < m_index.GetCount(); i++ ) {
|
|
573 if ( m_index[i].StartsWith( m_hhs, &date ) ) {
|
|
574 wxVector<wxVariant> data;
|
|
575 data.push_back( wxString::Format( wxT( "%02d" ), ++match_cnt ) );
|
|
576 date = date.Mid( 1, 4 ) + wxT( "-" ) + date.Mid( 5, 2 ) + wxT( "-" ) + date.Mid( 7, 2 );
|
|
577 data.push_back( date );
|
|
578 data.push_back( wxEmptyString );
|
|
579 m_dataViewListCtrl->AppendItem( data );
|
|
580 data.clear();
|
|
581 }
|
|
582 }
|
5
|
583
|
|
584 if ( match_cnt == 0 ) {
|
|
585 wxMessageBox( wxT( "Not Matched !!" ) );
|
|
586 } else {
|
|
587 wxString date = m_dataViewListCtrl->GetTextValue( 0, 1 );
|
|
588 date.Replace( wxT( "-" ), wxEmptyString, true );
|
|
589 GetImages( m_hhs, date );
|
|
590 if ( LoadBitmaps( date, true ) ) {
|
|
591 m_dataViewListCtrl->SetTextValue( wxT( "OK" ), 0, 2 );
|
|
592 m_dataViewListCtrl->SelectRow( 0 );
|
|
593 }
|
|
594 }
|
|
595
|
|
596 WriteLog( wxT( "[search] " ) + m_hhs );
|
2
|
597 }
|
|
598
|
3
|
599 void MainFrame::LoadDB( void )
|
2
|
600 {
|
5
|
601 wxProgressDialog pd( wxT( "Load Data" ), wxT( "Now loading..." ), 100, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
602 pd.SetSize( wxSize( 320, 140 ) );
|
|
603
|
|
604 // index
|
2
|
605 wxTextFile file;
|
|
606 file.Open( wxT( "index.db" ) );
|
|
607 for ( int i = 0; i < file.GetLineCount(); i++ )
|
|
608 m_index.Add( file.GetLine( i ) );
|
|
609 file.Close();
|
|
610 m_index.Sort( true );
|
3
|
611
|
5
|
612 // decrypto
|
|
613 wxString key = wxT( "12345678900123456789abcdefabcdef" );
|
|
614 wxArrayString args;
|
|
615 args.Add( wxT( "crypto.exe" ) );
|
|
616 args.Add( wxT( "-d" ) );
|
|
617 args.Add( wxT( "hhs.db" ) );
|
|
618 args.Add( wxT( "-k" ) );
|
|
619 args.Add( key );
|
|
620
|
|
621 wxArrayString output, errors;
|
|
622 wxExecute( wxJoin( args, ' ', '\\' ), output, errors );
|
|
623
|
|
624 for ( int i = 0; i < 100; i++ ) {
|
|
625 wxMilliSleep( 2 );
|
|
626 pd.Update( i, wxString::Format( wxT( "Now loding ... ( %0.1f %% )" ), (float)i ) );
|
|
627 }
|
|
628 if ( errors.GetCount() > 0 ) {
|
|
629 wxMessageBox( errors[0] );
|
|
630 return;
|
|
631 }
|
|
632 for ( int i = 0; i < output.GetCount(); i++ ) {
|
|
633 wxArrayString buf = wxSplit( output[i], ',', '\\' );
|
|
634 hhash[ buf[0] ] = new HhsClass( buf ); // no, birth, name, kana, addr, sex
|
3
|
635 }
|
5
|
636 }
|
|
637
|
|
638 void MainFrame::PasteSeaarch( void )
|
|
639 {
|
|
640 wxString s;
|
|
641 if ( wxTheClipboard->Open() ) {
|
|
642 if ( wxTheClipboard->IsSupported( wxDF_TEXT ) ) {
|
|
643 wxTextDataObject data;
|
|
644 wxTheClipboard->GetData( data );
|
|
645 s = data.GetText();
|
|
646 }
|
|
647 wxTheClipboard->Close();
|
|
648 }
|
|
649
|
|
650 s.Replace( wxT(" "), wxT(""), true );
|
|
651 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
|
|
652 if ( reHhs.Matches( s ) ) {
|
|
653 m_searchCtrl->SetValue( s );
|
|
654 m_hhs = m_searchCtrl->GetValue();
|
|
655 Search();
|
|
656 return;
|
|
657 }
|
|
658 wxMessageBox( wxT( "Bad Input !!" ) );
|
3
|
659 }
|
|
660
|
|
661 void MainFrame::PrintImages( void )
|
|
662 {
|
|
663 int r = m_dataViewListCtrl->GetSelectedRow();
|
4
|
664 if ( r == wxNOT_FOUND ) {
|
|
665 wxMessageBox( wxT( "Not Ready for Print !!" ) );
|
|
666 return;
|
|
667 }
|
3
|
668 wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
|
|
669
|
|
670 if ( !ready.IsSameAs( wxT( "OK" ), true ) ) {
|
|
671 wxMessageBox( wxT( "Not Ready for Print !!" ) );
|
|
672 return;
|
|
673 }
|
|
674
|
|
675 wxDateTime now = wxDateTime::Now();
|
|
676 wxString nowstr = now.Format( "%Y/%m/%d %H:%M", wxDateTime::GMT9 ).c_str();
|
|
677
|
|
678 wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
|
|
679 date.Replace( wxT( "-" ), wxEmptyString, true );
|
|
680
|
|
681 wxString html, file;
|
|
682 html = wxT( "<html><body>\n" );
|
|
683
|
|
684 for ( int i = 1; i < 6; i++ ) {
|
|
685 file = wxString::Format( wxT( ".cache/%08s_%d" ), date, i );
|
|
686 html = html + wxT( "<img src=\"" ) + file + wxT( "\" width=\"750\" height=\"1060\"/>\n" );
|
|
687 html = html + wxT( "<div align=right><font size=-2><u>" ) + m_hhs + wxT( "@" ) + m_user + wxT( "#" ) + nowstr + wxT( "</u></font></div>\n\n" );
|
|
688 }
|
|
689 html = html + wxT( "</body></html>" );
|
|
690
|
|
691 // start printing
|
|
692 wxHtmlPrintout hpout( wxT( "Re:Searcher" ) );
|
|
693 hpout.SetMargins( 0, 0, 0, 0, 0 );
|
|
694 wxPrintDialogData pd;
|
|
695 wxPrinter p( &pd );
|
|
696
|
|
697 hpout.SetHtmlText( html, wxEmptyString, false );
|
|
698 p.Print( NULL, &hpout, true );
|
5
|
699
|
|
700 WriteLog( wxT( "[print]" ) );
|
2
|
701 }
|
|
702
|
|
703 void MainFrame::RemoveFile( wxString pattern )
|
|
704 {
|
|
705 wxString file = wxFindFirstFile( pattern );
|
|
706 while ( !file.empty() ) {
|
|
707 wxRemoveFile( file );
|
|
708 file = wxFindNextFile();
|
|
709 }
|
0
|
710 }
|
|
711
|
5
|
712 void MainFrame::WriteLog( wxString msg )
|
|
713 {
|
|
714 wxDateTime now = wxDateTime::Now();
|
|
715 wxString file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "log" ) + wxFILE_SEP_PATH + now.Format( wxT( "%Y%m%d" ) ) + wxT( ".log" );
|
|
716
|
|
717 wxTextFile logfile;
|
|
718 if ( !wxFileExists( file ) ) logfile.Create( file );
|
|
719
|
|
720 logfile.Open( file );
|
|
721 logfile.AddLine( now.Format( wxT("%Y-%m-%d %H:%M:%S ") ) + msg );
|
|
722 logfile.Write();
|
|
723 logfile.Close();
|
|
724 }
|
|
725
|
1
|
726 void MainFrame::InDevelop( bool flag )
|
0
|
727 {
|
1
|
728 if ( !flag ) return;
|
0
|
729
|
5
|
730 bool he = false;
|
|
731 m_buttonHelp->Enable( he );
|
|
732 m_buttonHelp->Show( he );
|
|
733
|
3
|
734 bool lo = false;
|
|
735 m_buttonLogout->Enable( lo );
|
|
736 m_buttonLogout->Show( lo );
|
0
|
737
|
3
|
738 bool sl = false;
|
|
739 m_slider->Enable( sl );
|
|
740 m_slider->Show( sl );
|
0
|
741
|
4
|
742 return;
|
0
|
743 }
|
|
744
|