comparison src/rsearcher.cpp @ 6:9a8b581c1993

improve performance.
author pyon@macmini
date Tue, 23 Oct 2018 19:15:22 +0900
parents e3b10fb860b3
children 29829e98d510
comparison
equal deleted inserted replaced
5:e3b10fb860b3 6:9a8b581c1993
1 // Filename : rsearcher.cpp 1 // Filename : rsearcher.cpp
2 // Last Change: 2018-10-22 ŒŽ 16:20:03. 2 // Last Change: 2018-10-23 ‰Î 13:09:30.
3 // 3 //
4 4
5 #include <wx/arrstr.h> 5 #include <wx/arrstr.h>
6 #include <wx/html/htmprint.h> 6 #include <wx/html/htmprint.h>
7 #include <wx/clipbrd.h> 7 #include <wx/clipbrd.h>
114 // Event Handlers 114 // Event Handlers
115 void MyStaticBitmap::OnWheel( wxMouseEvent& event ) 115 void MyStaticBitmap::OnWheel( wxMouseEvent& event )
116 { 116 {
117 if ( event.ControlDown() ) { 117 if ( event.ControlDown() ) {
118 if ( event.GetWheelRotation() < 0 ) { 118 if ( event.GetWheelRotation() < 0 ) {
119 if ( m_zoom < 4 ) m_zoom++; 119 //if ( m_zoom < 4 ) m_zoom++;
120 } 120 }
121 else { 121 else {
122 if ( m_zoom > 0 ) m_zoom--; 122 //if ( m_zoom > 0 ) m_zoom--;
123 } 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; 124 return;
127 } 125 }
128 event.Skip(); 126 event.Skip();
129 } 127 }
130 128
226 m_timer.SetOwner( this, ID_TIMER ); 224 m_timer.SetOwner( this, ID_TIMER );
227 } 225 }
228 226
229 MainFrame::~MainFrame() 227 MainFrame::~MainFrame()
230 { 228 {
231 RemoveFile( wxT( "auth.db" ) );
232 RemoveFile( wxT( "hhs.db" ) );
233 RemoveFile( wxT( ".cache/*" ) );
234 } 229 }
235 230
236 // Event Table 231 // Event Table
237 BEGIN_EVENT_TABLE( MainFrame, wxFrame ) 232 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
238 EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected ) 233 EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected )
239 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked ) 234 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
240 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged ) 235 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
241 EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint ) 236 EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint )
242 EVT_BUTTON( ID_PSEARCH, MainFrame::OnPasteSearch ) 237 EVT_BUTTON( ID_PSEARCH, MainFrame::OnPasteSearch )
238 EVT_BUTTON( ID_PZOOM, MainFrame::OnPlusZoom )
239 EVT_BUTTON( ID_MZOOM, MainFrame::OnMinusZoom )
240 EVT_BUTTON( ID_DARK, MainFrame::OnDark )
243 EVT_BUTTON( wxID_HELP, MainFrame::OnHelp ) 241 EVT_BUTTON( wxID_HELP, MainFrame::OnHelp )
244 EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout ) 242 EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout )
245 EVT_CLOSE( MainFrame::OnClose ) 243 EVT_CLOSE( MainFrame::OnClose )
246 EVT_IDLE( MainFrame::OnIdle ) 244 EVT_IDLE( MainFrame::OnIdle )
247 EVT_TIMER( ID_TIMER, MainFrame::OnTimer ) 245 EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
300 void MainFrame::OnPrint( wxCommandEvent& WXUNUSED(event) ) 298 void MainFrame::OnPrint( wxCommandEvent& WXUNUSED(event) )
301 { 299 {
302 PrintImages(); 300 PrintImages();
303 } 301 }
304 302
303 void MainFrame::OnPlusZoom( wxCommandEvent& WXUNUSED(event) )
304 {
305 ChangeCZoom( 1 );
306 }
307
308 void MainFrame::OnMinusZoom( wxCommandEvent& WXUNUSED(event ) )
309 {
310 ChangeCZoom( -1 );
311 }
312
313 void MainFrame::OnDark( wxCommandEvent& WXUNUSED(event ) )
314 {
315 ChangeColor( m_staticBitmap1 );
316 ChangeColor( m_staticBitmap2 );
317 ChangeColor( m_staticBitmap3 );
318 ChangeColor( m_staticBitmap4 );
319 ChangeColor( m_staticBitmap5 );
320 m_dark = !m_dark;
321 }
322
305 void MainFrame::OnHelp( wxCommandEvent& WXUNUSED(event) ) 323 void MainFrame::OnHelp( wxCommandEvent& WXUNUSED(event) )
306 { 324 {
307 wxString version, build; 325 wxString version, build;
308 version = wxString::Format( wxT( "Re:Searcher-- version %s / %s\n\n" ), RSVER, RSRELEASE ); 326 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() ); 327 build = wxString::Format( wxT( "build with %s\nrunning under %s." ), wxVERSION_STRING, wxGetOsDescription() );
411 bSizerRight->Add( m_buttonPsearch, 0, wxALL, 5 ); 429 bSizerRight->Add( m_buttonPsearch, 0, wxALL, 5 );
412 430
413 m_buttonPrint = new wxButton( this, wxID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 ); 431 m_buttonPrint = new wxButton( this, wxID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
414 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 ); 432 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
415 433
416 m_buttonHelp = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
417 bSizerRight->Add( m_buttonHelp, 0, wxALL, 5 );
418
419 m_buttonLogout = new wxButton( this, ID_LOGOUT, wxT( "Logout" ), wxDefaultPosition, wxDefaultSize, 0 ); 434 m_buttonLogout = new wxButton( this, ID_LOGOUT, wxT( "Logout" ), wxDefaultPosition, wxDefaultSize, 0 );
420 bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 ); 435 bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 );
436
437 // invisible buttons for shortcut-key
438 m_buttonPzoom = new wxButton( this, ID_PZOOM, wxT( "ZOOM" ), wxDefaultPosition, wxDefaultSize, 0 );
439 m_buttonPzoom->Hide();
440 m_buttonMzoom = new wxButton( this, ID_MZOOM, wxT( "zoom" ), wxDefaultPosition, wxDefaultSize, 0 );
441 m_buttonMzoom->Hide();
442 m_buttonDark = new wxButton( this, ID_DARK, wxT( "Dark" ), wxDefaultPosition, wxDefaultSize, 0 );
443 m_buttonDark->Hide();
444 m_buttonHelp = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
445 m_buttonHelp->Hide();
421 446
422 bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 ); 447 bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 );
423 448
424 this->SetSizer( bSizerTop ); 449 this->SetSizer( bSizerTop );
425 this->Layout(); 450 this->Layout();
433 m_staticBitmap5 = new MyStaticBitmap( m_scrolledWindow5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); 458 m_staticBitmap5 = new MyStaticBitmap( m_scrolledWindow5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
434 } 459 }
435 460
436 void MainFrame::SetAccelerator( void ) 461 void MainFrame::SetAccelerator( void )
437 { 462 {
438 wxAcceleratorEntry entries[2]; 463 wxAcceleratorEntry entries[5];
439 entries[0].Set( wxACCEL_CTRL, (int) 'P', wxID_PRINT ); 464 entries[0].Set( wxACCEL_CTRL, (int)'P', wxID_PRINT );
440 entries[1].Set( wxACCEL_NORMAL, WXK_F1, wxID_HELP ); 465 entries[1].Set( wxACCEL_NORMAL, WXK_F1, wxID_HELP );
441 /* 466 entries[2].Set( wxACCEL_NORMAL, (int)'Z', ID_PZOOM );
442 entries[1].Set( wxACCEL_CTRL, (int) 'X', wxID_EXIT ); 467 entries[3].Set( wxACCEL_NORMAL, (int)'X', ID_MZOOM );
443 entries[2].Set( wxACCEL_SHIFT, (int) 'A', ID_ABOUT); 468 entries[4].Set( wxACCEL_NORMAL, (int)'D', ID_DARK );
444 entries[3].Set( wxACCEL_NORMAL, WXK_DELETE, wxID_CUT); 469 wxAcceleratorTable accel( 5, entries );
445 */
446 wxAcceleratorTable accel( 2, entries );
447 SetAcceleratorTable( accel ); 470 SetAcceleratorTable( accel );
448 } 471 }
449 472
450 void MainFrame::Cmd( wxString cmd ) 473 void MainFrame::Cmd( wxString cmd )
451 { 474 {
452 m_dataViewListCtrl->DeleteAllItems(); 475 m_dataViewListCtrl->DeleteAllItems();
476 m_textCtrlName->SetValue( wxEmptyString );
477 m_textCtrlAddr->SetValue( wxEmptyString );
453 LoadBitmaps( wxEmptyString, false ); 478 LoadBitmaps( wxEmptyString, false );
479
454 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) ); 480 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
455 481
456 if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) { 482 if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) {
457 Close(); 483 Close();
458 return; 484 return;
478 PasteSeaarch(); 504 PasteSeaarch();
479 return; 505 return;
480 } 506 }
481 507
482 if ( cmd.IsSameAs( wxT( "+" ), false ) ) { 508 if ( cmd.IsSameAs( wxT( "+" ), false ) ) {
483 PrintImages(); 509 //PrintImages();
484 return; 510 return;
485 } 511 }
486 512
487 if ( reHhs.Matches( cmd ) ) { 513 if ( reHhs.Matches( cmd ) ) {
488 m_hhs = m_searchCtrl->GetValue(); 514 m_hhs = m_searchCtrl->GetValue();
491 } 517 }
492 518
493 wxMessageBox( wxT( "Bad Input !!" ) ); 519 wxMessageBox( wxT( "Bad Input !!" ) );
494 } 520 }
495 521
496 bool MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file ) 522 bool MainFrame::LoadBitmap( wxScrolledWindow* sc, MyStaticBitmap* sb, wxString file )
497 { 523 {
498 sb->SetBitmap( wxNullBitmap ); 524 sb->SetBitmap( wxNullBitmap );
525 sb->zoom = 0;
499 sc->Scroll( 0, 0 ); 526 sc->Scroll( 0, 0 );
500 527
501 bool ok = true; 528 bool ok = true;
502 if ( startup ) { 529 if ( startup ) {
503 file = wxT( "image/hello.jpg" ); 530 file = wxT( "image/hello.jpg" );
506 if ( !wxFileExists( file ) ) { 533 if ( !wxFileExists( file ) ) {
507 file = wxT( "image/testpattern.jpg" ); 534 file = wxT( "image/testpattern.jpg" );
508 ok = false; 535 ok = false;
509 } 536 }
510 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG ); 537 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
538 sb->SetOrigImage( bmp );
511 int width = bmp.GetWidth(); 539 int width = bmp.GetWidth();
512 int height = bmp.GetHeight(); 540 int height = bmp.GetHeight();
513 wxImage img = bmp.ConvertToImage(); 541 wxImage img = bmp.ConvertToImage();
514 542
515 int ww, wh; 543 int ww, wh;
535 if ( !ok && reload ) { 563 if ( !ok && reload ) {
536 wxSleep( 5 ); 564 wxSleep( 5 );
537 LoadBitmaps( date, false ); 565 LoadBitmaps( date, false );
538 } 566 }
539 return ok; 567 return ok;
568 }
569
570 void MainFrame::ChangeCZoom( int z )
571 {
572 int n = m_notebook->GetSelection();
573 if ( n == 0 ) ChangeZoom( m_scrolledWindow1, m_staticBitmap1, z );
574 if ( n == 1 ) ChangeZoom( m_scrolledWindow2, m_staticBitmap2, z );
575 if ( n == 2 ) ChangeZoom( m_scrolledWindow3, m_staticBitmap3, z );
576 if ( n == 3 ) ChangeZoom( m_scrolledWindow4, m_staticBitmap4, z );
577 if ( n == 4 ) ChangeZoom( m_scrolledWindow5, m_staticBitmap5, z );
578 }
579
580 void MainFrame::ChangeZoom( wxScrolledWindow* sc, MyStaticBitmap* sb, int z )
581 {
582 if ( z > 0 ) sb->zoom++;
583 else sb->zoom--;
584
585 float zz = pow( 1.1, sb->zoom );
586
587 int x, y;
588 sc->GetViewStart( &x, &y );
589 sc->Scroll( 0, 0 );
590 wxBitmap bmp = sb->GetOrigImage();
591
592 int width = bmp.GetWidth();
593 int height = bmp.GetHeight();
594 wxImage img = bmp.ConvertToImage();
595
596 int ww, wh;
597 sc->GetSize( &ww, &wh );
598
599 float w = ww * zz - 30;
600 float h = w * height / width;
601 sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
602 sc->SetScrollbars( 10, 10, (int)w / 10, (int)h / 10 );
603 sc->Scroll( x, y );
604
605 if ( m_dark ) ChangeColor( sb );
606 }
607
608 void MainFrame::ChangeColor( MyStaticBitmap* sb )
609 {
610 wxBitmap bmp = sb->GetBitmap();
611 wxImage img = bmp.ConvertToImage();
612 unsigned char r, g, b;
613 for ( int x = 0; x < img.GetWidth(); x++ ) {
614 for ( int y = 0; y < img.GetHeight(); y++ ) {
615 r = 255 - img.GetRed( x, y );
616 g = 255 - img.GetGreen( x, y );
617 b = 255 - img.GetBlue( x, y );
618 img.SetRGB( x, y, r, g, b );
619 }
620 }
621 sb->SetBitmap( wxBitmap( img ) );
540 } 622 }
541 623
542 void MainFrame::GetImages( wxString hhs, wxString date ) 624 void MainFrame::GetImages( wxString hhs, wxString date )
543 { 625 {
544 wxArrayString args; // http get 626 wxArrayString args; // http get
698 p.Print( NULL, &hpout, true ); 780 p.Print( NULL, &hpout, true );
699 781
700 WriteLog( wxT( "[print]" ) ); 782 WriteLog( wxT( "[print]" ) );
701 } 783 }
702 784
703 void MainFrame::RemoveFile( wxString pattern )
704 {
705 wxString file = wxFindFirstFile( pattern );
706 while ( !file.empty() ) {
707 wxRemoveFile( file );
708 file = wxFindNextFile();
709 }
710 }
711
712 void MainFrame::WriteLog( wxString msg ) 785 void MainFrame::WriteLog( wxString msg )
713 { 786 {
714 wxDateTime now = wxDateTime::Now(); 787 wxDateTime now = wxDateTime::Now();
715 wxString file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "log" ) + wxFILE_SEP_PATH + now.Format( wxT( "%Y%m%d" ) ) + wxT( ".log" ); 788 wxString file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "log" ) + wxFILE_SEP_PATH + now.Format( wxT( "%Y%m%d" ) ) + wxT( ".log" );
716 789
725 798
726 void MainFrame::InDevelop( bool flag ) 799 void MainFrame::InDevelop( bool flag )
727 { 800 {
728 if ( !flag ) return; 801 if ( !flag ) return;
729 802
730 bool he = false;
731 m_buttonHelp->Enable( he );
732 m_buttonHelp->Show( he );
733
734 bool lo = false; 803 bool lo = false;
735 m_buttonLogout->Enable( lo ); 804 m_buttonLogout->Enable( lo );
736 m_buttonLogout->Show( lo ); 805 m_buttonLogout->Show( lo );
737 806
738 bool sl = false; 807 bool sl = false;