diff src/rsearcher.cpp @ 3:db4813125eb8

many changes.
author pyon@macmini
date Thu, 11 Oct 2018 22:11:09 +0900
parents 7fe3417cefc8
children 06342fc544e4
line wrap: on
line diff
--- a/src/rsearcher.cpp	Tue Oct 02 21:20:05 2018 +0900
+++ b/src/rsearcher.cpp	Thu Oct 11 22:11:09 2018 +0900
@@ -1,8 +1,9 @@
 // Filename   : rsearcher.cpp
-// Last Change: 2018-10-02 Tue 19:43:14.
+// Last Change: 2018-10-11 –Ø 18:28:07.
 //
 
 #include <wx/arrstr.h> 
+#include <wx/html/htmprint.h>
 #include "rsearcher.h"
 #include "main.h"
 
@@ -74,18 +75,25 @@
     : wxStaticBitmap( parent, id, label, pos, size, style, name )
 {
 	m_parent = parent;
-    Connect( wxEVT_LEFT_DOWN,  wxMouseEventHandler( MyStaticBitmap::OnLeftDown ), NULL, this );
-    Connect( wxEVT_LEFT_UP,    wxMouseEventHandler( MyStaticBitmap::OnLeftUp   ), NULL, this );
-    Connect( wxEVT_MOTION,     wxMouseEventHandler( MyStaticBitmap::OnMotion   ), NULL, this );
-    Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( MyStaticBitmap::OnWheel    ), NULL, this );
+    Connect( wxEVT_LEFT_DOWN,  wxMouseEventHandler( OnLeftDown ), NULL, this );
+    Connect( wxEVT_LEFT_UP,    wxMouseEventHandler( OnLeftUp   ), NULL, this );
+    Connect( wxEVT_MOTION,     wxMouseEventHandler( OnMotion   ), NULL, this );
+    Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OnWheel    ), NULL, this );
+
+    Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OnStartRGesture ), NULL, this );
+    Connect( wxEVT_RIGHT_UP,   wxMouseEventHandler( OnEndRGesture   ), NULL, this );
 }
 
 MyStaticBitmap::~MyStaticBitmap()
 {
-    Disconnect( wxEVT_LEFT_DOWN,  wxMouseEventHandler( MyStaticBitmap::OnLeftDown ), NULL, this );
-    Disconnect( wxEVT_LEFT_UP,    wxMouseEventHandler( MyStaticBitmap::OnLeftUp   ), NULL, this );
-    Disconnect( wxEVT_MOTION,     wxMouseEventHandler( MyStaticBitmap::OnMotion   ), NULL, this );
-    Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( MyStaticBitmap::OnWheel    ), NULL, this );
+    Disconnect( wxEVT_LEFT_DOWN,  wxMouseEventHandler( OnLeftDown ), NULL, this );
+    Disconnect( wxEVT_LEFT_UP,    wxMouseEventHandler( OnLeftUp   ), NULL, this );
+    Disconnect( wxEVT_MOTION,     wxMouseEventHandler( OnMotion   ), NULL, this );
+    Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OnWheel    ), NULL, this );
+
+    Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OnStartRGesture ), NULL, this );
+    Disconnect( wxEVT_RIGHT_UP,   wxMouseEventHandler( OnEndRGesture   ), NULL, this );
+
 }
 
 // Event Handlers
@@ -138,6 +146,38 @@
     }
 }
 
+/* right-gesture: start detect */
+void MyStaticBitmap::OnStartRGesture( wxMouseEvent& event )
+{
+    event.GetPosition( &cx, &cy );
+}
+
+/* right-gesture: judge */
+void MyStaticBitmap::OnEndRGesture( wxMouseEvent& event )
+{
+    int x, y;
+    event.GetPosition( &x, &y );
+
+    int dx = x - cx;
+    int dy = y - cy;
+    float rad = fabs( atan2( dy, dx ) );
+    float pi = 3.14159;
+
+    // to right
+    if ( rad < pi/8 && dx > 0 ) {
+		wxMessageBox("right");
+    }
+    // to left
+    else if ( rad > pi/8*7 && rad < pi && dx < 0 ) { 
+		wxMessageBox("left");
+    }
+    // to up-right
+    else if ( rad > pi/8 && rad < pi/8*3 && dx > 0 ) {
+		wxMessageBox("right-up");
+        //Close();
+    }
+}
+
 // Functions
 
 /********************/
@@ -146,8 +186,10 @@
 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
 	: wxFrame( parent, id, title, pos, size, style )
 {
-	LoadIndex();
 	CreateControls();
+	LoadDB();
+    LoadBitmaps( wxEmptyString );
+	m_timer.SetOwner( this, ID_TIMER );
 }
 
 MainFrame::~MainFrame()
@@ -162,9 +204,12 @@
     EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected )
     EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
     EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
+	EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint )
+	EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout )
 	EVT_BUTTON( ID_TEST, MainFrame::OnTestButton )
-	EVT_CLOSE( MainFrame::SaveConfig )
-    //EVT_IDLE( MainFrame::OnIdle )
+	EVT_CLOSE( MainFrame::OnClose )
+    EVT_IDLE( MainFrame::OnIdle )
+    EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
 END_EVENT_TABLE()
 
 
@@ -173,19 +218,27 @@
 {
     int r = m_dataViewListCtrl->GetSelectedRow();
     wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
-	if ( ready.IsSameAs( wxT( "ok" ), true ) ) {
-		wxString buf = m_dataViewListCtrl->GetTextValue( r, 1 );
-		LoadBitmaps( wxT( "00000000" ) );
+	if ( ready.IsSameAs( wxT( "OK" ), true ) ) {
+		wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
+		date.Replace( wxT( "-" ), wxEmptyString, true );
+		LoadBitmaps( date );
+	} else {
+		LoadBitmaps( wxEmptyString );
 	}
 }
 
 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) )
 {
     int r = m_dataViewListCtrl->GetSelectedRow();
+	wxString status = m_dataViewListCtrl->GetTextValue( r, 2 );
+	if ( status.IsSameAs( wxT( "OK" ), true ) )	return;
+
     wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
 	date.Replace( wxT( "-" ), wxEmptyString, true );
 	GetImages( m_hhs, date );
-	LoadBitmaps( wxT( "00000000" ) );
+	LoadBitmaps( date );
+
+    m_dataViewListCtrl->SetTextValue( wxT( "OK" ), r, 2 );
 }
 
 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) )
@@ -196,14 +249,7 @@
     m_notebook->SetPageImage( m_notebook->GetSelection(), 0 );
 }
 
-/*
-void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
-{
-}
-
-*/
-
-void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
+void MainFrame::OnClose( wxCloseEvent& WXUNUSED(event) )	// save config
 {
     if ( !IsIconized() && !IsMaximized() ) {
         wxGetApp().rect = this->GetRect();
@@ -211,11 +257,38 @@
     Destroy();
 }
 
+void MainFrame::OnPrint( wxCommandEvent& WXUNUSED(event) )
+{
+	PrintImages();
+}
+
+void MainFrame::OnLogout( wxCommandEvent& WXUNUSED(event) )
+{
+	wxMessageBox("logout");
+	return;
+}
+
 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) )
 {
 	return;
 }
 
+
+void MainFrame::OnTimer( wxTimerEvent& WXUNUSED(event) )
+{
+	wxMessageBox( "timer !" );
+	// logout
+}
+
+void MainFrame::OnIdle( wxIdleEvent& event )
+{
+	if ( !m_timer.IsRunning() ) {
+        m_timer.Start( 300 * 1000, wxTIMER_ONE_SHOT );
+    }
+    event.RequestMore();
+    event.Skip();
+}
+
 // Functions
 void MainFrame::CreateControls( void )
 {
@@ -290,9 +363,12 @@
 	m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1, 200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
 	bSizerRight->Add( m_slider, 0, wxALL, 5 );
 	
-	m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonPrint = new wxButton( this, wxID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
 	
+	m_buttonLogout = new wxButton( this, ID_LOGOUT, wxT( "Logout" ), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 );
+	
 	m_buttonTest = new wxButton( this, ID_TEST, wxT( "Test" ), wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerRight->Add( m_buttonTest, 0, wxALL, 5 );
 	
@@ -325,13 +401,27 @@
 		return;
     }
 
-    if ( cmd.IsSameAs( wxT( "." ), true ) ) {
+    if ( cmd.IsSameAs( wxT( "k" ), true ) ) {
+		// hiragana kensaku
+        return;
+	}
+
+    if ( cmd.IsSameAs( wxT( "." ), false ) ) {
         wxString appdir = wxGetCwd();
         wxString execmd = wxT( "explorer " ) + appdir;
         wxExecute( execmd );
         return;
     }
 
+    if ( cmd.IsSameAs( wxT( "*" ), false ) ) {
+		// cmd = clipboard // paste clipboard
+	}
+
+    if ( cmd.IsSameAs( wxT( "+" ), false ) ) {
+		// print
+        return;
+	}
+
     wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
     if ( reHhs.Matches( cmd ) ) {
 		m_hhs = m_searchCtrl->GetValue();
@@ -339,7 +429,7 @@
 		return;
 	}
 
-	wxMessageBox( wxT( "Bad Input!!" ) );
+	wxMessageBox( wxT( "Bad Input !!" ) );
 }
 
 void MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
@@ -357,7 +447,7 @@
     int ww, wh;
     sc->GetSize( &ww, &wh );
 
-    float w = ww - 50;
+    float w = ww - 30;
     float h = w * height / width;
     sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
     sc->SetScrollbars( 10, 10, w / 10, h / 10 );
@@ -387,7 +477,15 @@
 	args.Add( date );
 
 	//wxMessageBox( wxJoin( args, ' ', '\\' ) );
+	int estimate = 5;
+    wxProgressDialog pd( wxT( "Connecting Server" ), wxT( "Start..." ), estimate, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
+    pd.SetSize( wxSize( 320, 140 ) );
+	
 	wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_ASYNC|wxEXEC_HIDE_CONSOLE );
+	for ( int i = 0; i < estimate; i++ ) {
+		wxSleep( 1 );
+		pd.Update( i, wxT( "Now Loading..." ) );
+	}
 }
 
 void MainFrame::Search( void )
@@ -405,10 +503,10 @@
 			data.clear();
 		}
 	}
-	if ( match_cnt == 0 ) wxMessageBox( wxT( "Not Matched!!" ) );
+	if ( match_cnt == 0 ) wxMessageBox( wxT( "Not Matched !!" ) );
 }
 
-void MainFrame::LoadIndex( void )
+void MainFrame::LoadDB( void )
 {
 	wxTextFile file;
 	file.Open( wxT( "index.db" ) );
@@ -416,6 +514,50 @@
 		m_index.Add( file.GetLine( i ) );
 	file.Close();
 	m_index.Sort( true );
+
+	/*
+	file.Open( wxT( "hhs.db" ) );
+	for ( int i = 0; i < file.GetLineCount(); i++ ) {
+	//
+	}
+	file.Close();
+	*/
+}
+
+void MainFrame::PrintImages( void )
+{
+    int r = m_dataViewListCtrl->GetSelectedRow();
+    wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
+
+	if ( !ready.IsSameAs( wxT( "OK" ), true ) ) {
+		wxMessageBox( wxT( "Not Ready for Print !!" ) );
+		return;
+	}
+
+	wxDateTime now = wxDateTime::Now();
+	wxString nowstr = now.Format( "%Y/%m/%d %H:%M", wxDateTime::GMT9 ).c_str();
+
+	wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
+	date.Replace( wxT( "-" ), wxEmptyString, true );
+
+	wxString html, file;
+	html = wxT( "<html><body>\n" );
+
+	for ( int i = 1; i < 6; i++ ) {
+		file = wxString::Format( wxT( ".cache/%08s_%d" ), date, i );
+		html = html + wxT( "<img src=\"" ) + file + wxT( "\" width=\"750\" height=\"1060\"/>\n" );
+		html = html + wxT( "<div align=right><font size=-2><u>" ) + m_hhs + wxT( "@" ) + m_user + wxT( "#" ) + nowstr + wxT( "</u></font></div>\n\n" );
+	}
+	html = html + wxT( "</body></html>" );
+
+	// start printing
+	wxHtmlPrintout hpout( wxT( "Re:Searcher" ) );
+	hpout.SetMargins( 0, 0, 0, 0, 0 );
+	wxPrintDialogData pd;
+	wxPrinter p( &pd );
+
+	hpout.SetHtmlText( html, wxEmptyString, false );
+	p.Print( NULL, &hpout, true );
 }
 
 void MainFrame::RemoveFile( wxString pattern )
@@ -430,21 +572,20 @@
 void MainFrame::InDevelop( bool flag )
 {
     if ( !flag ) return;
-    //LoadBitmaps( wxT( "00000000" ) );
-    LoadBitmaps( wxEmptyString );
     
-	m_slider->Enable( false );
-	m_slider->Show( false );
+	bool lo = false;
+	m_buttonLogout->Enable( lo );
+	m_buttonLogout->Show( lo );
 
-	bool pr = true;
-	m_buttonPrint->Enable( false );
-	m_buttonPrint->Show( true );
+	bool sl = false;
+	m_slider->Enable( sl );
+	m_slider->Show( sl );
 
-	bool tb = true;
+	bool tb = false;
 	m_buttonTest->Enable( tb );
 	m_buttonTest->Show( tb );
 
-	bool srch = true;
-	m_searchCtrl->Enable( srch );
+	// search
+	m_searchCtrl->SetValue( wxT( "0100122642" ) );
 }