0
|
1 // Filename : rsearcher.cpp
|
1
|
2 // Last Change: 2018-10-01 Mon 23:15:33.
|
0
|
3 //
|
|
4
|
|
5 #include "rsearcher.h"
|
|
6 #include "main.h"
|
|
7
|
|
8 /********************/
|
|
9 /** MySearchCtrl **/
|
|
10 /********************/
|
|
11 MySearchCtrl::MySearchCtrl( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style )
|
|
12 : wxSearchCtrl( parent, id, value, pos, size, style )
|
|
13 {
|
|
14 m_parent = parent;
|
|
15 SetMaxLength( 10 );
|
|
16 #ifndef __WXMAC__
|
|
17 ShowSearchButton( true );
|
|
18 #endif
|
|
19 ShowCancelButton( false );
|
|
20
|
|
21 wxFont font( 12, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD );
|
|
22 SetFont( font );
|
|
23 }
|
|
24
|
|
25 MySearchCtrl::~MySearchCtrl()
|
|
26 {
|
|
27 }
|
|
28
|
|
29 // Event Table
|
|
30 BEGIN_EVENT_TABLE( MySearchCtrl, wxSearchCtrl )
|
|
31 EVT_CHAR( MySearchCtrl::OnKey )
|
|
32 END_EVENT_TABLE()
|
|
33
|
|
34 // Event Handlers & Functions
|
|
35 void MySearchCtrl::OnKey( wxKeyEvent& event )
|
|
36 {
|
|
37 int kc = event.GetKeyCode();
|
|
38
|
|
39 if ( kc == 13 ) { // Enter
|
|
40 // select all
|
|
41 wxString s = GetValue();
|
|
42
|
|
43 MainFrame* f = (MainFrame*)FindWindowById( ID_MAIN );
|
|
44 f->Cmd( s );
|
|
45
|
|
46 wxMessageBox( "Enter ed" );
|
|
47 event.Skip();
|
|
48 return;
|
|
49 }
|
|
50
|
|
51 if ( kc == 45 ) { // Num-Key '-' as Backspace
|
|
52 wxString t = GetStringSelection();
|
|
53 if ( t.IsEmpty() ) {
|
|
54 long p = GetInsertionPoint();
|
|
55 if ( p > 0 ) Remove( p - 1, p );
|
|
56 }
|
|
57 else {
|
|
58 Cut();
|
|
59 }
|
|
60 return;
|
|
61 }
|
|
62
|
|
63 if ( kc == WXK_ESCAPE ) { // clear by ESC
|
|
64 this->Clear();
|
|
65 return;
|
|
66 }
|
|
67
|
|
68 event.Skip();
|
|
69 }
|
|
70
|
|
71 /********************/
|
|
72 /** MyStaticBitmap **/
|
|
73 /********************/
|
|
74 MyStaticBitmap::MyStaticBitmap( wxScrolledWindow *parent, wxWindowID id, const wxBitmap &label, const wxPoint &pos, const wxSize &size, long style, const wxString &name )
|
|
75 : wxStaticBitmap( parent, id, label, pos, size, style, name )
|
|
76 {
|
|
77 m_parent = parent;
|
|
78 Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( MyStaticBitmap::OnLeftDown ), NULL, this );
|
|
79 Connect( wxEVT_LEFT_UP, wxMouseEventHandler( MyStaticBitmap::OnLeftUp ), NULL, this );
|
|
80 Connect( wxEVT_MOTION, wxMouseEventHandler( MyStaticBitmap::OnMotion ), NULL, this );
|
|
81 Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( MyStaticBitmap::OnWheel ), NULL, this );
|
|
82 }
|
|
83
|
|
84 MyStaticBitmap::~MyStaticBitmap()
|
|
85 {
|
|
86 Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( MyStaticBitmap::OnLeftDown ), NULL, this );
|
|
87 Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( MyStaticBitmap::OnLeftUp ), NULL, this );
|
|
88 Disconnect( wxEVT_MOTION, wxMouseEventHandler( MyStaticBitmap::OnMotion ), NULL, this );
|
|
89 Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( MyStaticBitmap::OnWheel ), NULL, this );
|
|
90 }
|
|
91
|
|
92 // Event Handlers
|
|
93 void MyStaticBitmap::OnWheel( wxMouseEvent& event )
|
|
94 {
|
|
95 if ( event.ControlDown() ) {
|
|
96 if ( event.GetWheelRotation() < 0 ) {
|
|
97 if ( m_zoom < 4 ) m_zoom++;
|
|
98 }
|
|
99 else {
|
|
100 if ( m_zoom > 0 ) m_zoom--;
|
|
101 }
|
|
102 SetBitmap( m_bmp[ m_zoom ] );
|
|
103 m_parent->SetScrollbars( 10, 10, m_bmp[ m_zoom ].GetWidth() / 10, m_bmp[ m_zoom ].GetHeight() / 10 );
|
|
104 return;
|
|
105 }
|
|
106 event.Skip();
|
|
107 }
|
|
108
|
|
109 void MyStaticBitmap::OnLeftDown( wxMouseEvent& event )
|
|
110 {
|
|
111 event.GetPosition( &m_dragx, &m_dragy );
|
|
112 SetCursor( wxCursor( wxCURSOR_SIZING ) );
|
|
113 }
|
|
114
|
|
115 void MyStaticBitmap::OnLeftUp( wxMouseEvent& WXUNUSED(event) )
|
|
116 {
|
|
117 SetCursor( wxCursor( wxCURSOR_ARROW ) );
|
|
118 }
|
|
119
|
|
120 void MyStaticBitmap::OnMotion( wxMouseEvent& event )
|
|
121 {
|
|
122 if ( event.Dragging() ) {
|
|
123 int xv, yv, x, y;
|
|
124 m_parent->GetViewStart( &xv, &yv );
|
|
125
|
|
126 event.GetPosition( &x, &y );
|
|
127
|
|
128 int xa = abs( x - m_dragx );
|
|
129 int ya = abs( y - m_dragy );
|
|
130 int xs = x - m_dragx < 0 ? -1 : 1;
|
|
131 int ys = y - m_dragy < 0 ? -1 : 1;
|
|
132
|
|
133 /* handai dakedo sumu-zu
|
|
134 m_parent->Scroll( xv + xs * log10( xa + 1 ), yv + ys * log10( ya + 1 ) );
|
|
135 */
|
|
136 m_parent->Scroll( xv + xs * log10( xa + 1 ), yv + ys * log10( ya + 1 ) );
|
|
137
|
|
138 m_dragx = x; m_dragy = y;
|
|
139 }
|
|
140 }
|
|
141
|
|
142 // Functions
|
|
143
|
|
144 /********************/
|
|
145 /** Main Frame **/
|
|
146 /********************/
|
|
147 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
148 : wxFrame( parent, id, title, pos, size, style )
|
|
149 {
|
1
|
150 CreateControls();
|
|
151 }
|
|
152
|
|
153 MainFrame::~MainFrame()
|
|
154 {
|
|
155 }
|
|
156
|
|
157 // Event Table
|
|
158 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
|
|
159 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
|
|
160 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
|
|
161 EVT_BUTTON( ID_TEST, MainFrame::OnTestButton )
|
|
162 EVT_CLOSE( MainFrame::SaveConfig )
|
|
163 //EVT_IDLE( MainFrame::OnIdle )
|
|
164 END_EVENT_TABLE()
|
|
165
|
|
166
|
|
167 // Event Handler
|
|
168 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) )
|
|
169 {
|
|
170 wxMessageBox( "dcli" );
|
|
171 int r = m_dataViewListCtrl->GetSelectedRow();
|
|
172 wxString no = m_dataViewListCtrl->GetTextValue( r, 0 );
|
|
173
|
|
174 LoadBitmaps();
|
|
175 }
|
|
176
|
|
177 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) )
|
|
178 {
|
|
179 for ( int i = 0; i < m_notebook->GetPageCount(); i++ ) {
|
|
180 m_notebook->SetPageImage( i, 1 );
|
|
181 }
|
|
182 m_notebook->SetPageImage( m_notebook->GetSelection(), 0 );
|
|
183 }
|
|
184
|
|
185 /*
|
|
186 void MainFrame::OnItemSelected( wxDataViewEvent& event )
|
|
187 {
|
|
188 dclick or select ?
|
|
189 }
|
|
190 */
|
|
191
|
|
192
|
|
193 /*
|
|
194 void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
|
195 {
|
|
196 }
|
|
197
|
|
198 */
|
|
199 void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
|
|
200 {
|
|
201 if ( !IsIconized() && !IsMaximized() ) {
|
|
202 wxGetApp().rect = this->GetRect();
|
|
203 }
|
|
204 Destroy();
|
|
205 }
|
|
206
|
|
207 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) )
|
|
208 {
|
|
209 /* ok
|
|
210 Cmd( m_searchCtrl->GetValue() );
|
|
211 Cmd( wxT( "0100012345" ) );
|
|
212 */
|
|
213
|
|
214 wxBitmap bmp( wxT(".cache/01_1"), wxBITMAP_TYPE_JPEG );
|
|
215 int width = bmp.GetWidth();
|
|
216 int height = bmp.GetHeight();
|
|
217 wxImage img = bmp.ConvertToImage();
|
|
218
|
|
219 int ww, wh;
|
|
220 m_scrolledWindow6->GetSize( &ww, &wh );
|
|
221
|
|
222 float w = ww;
|
|
223 float h = w * height / width;
|
|
224 m_staticBitmap6->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
|
|
225 m_scrolledWindow6->SetScrollbars( 10, 10, w / 10, h / 10 );
|
|
226
|
|
227 for ( int i = 0; i < 5; i++ ) {
|
|
228 w *= 1.1;
|
|
229 h *= 1.1;
|
|
230 //m_staticBitmap6->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
|
|
231 }
|
|
232 }
|
|
233
|
|
234 // Functions
|
|
235 void MainFrame::CreateControls( void )
|
|
236 {
|
0
|
237 this->SetIcon( wxIcon( wxT( "sample" ) ) );
|
|
238 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
239 //this->SetBackgroundColour( wxColour( 0, 150, 230 ) );
|
|
240
|
|
241 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
|
|
242
|
|
243 // Left
|
|
244 wxImageList* imgList = new wxImageList( 16, 16, false, 1 );
|
|
245 wxBitmap bmp( wxT( "image/blue.png" ), wxBITMAP_TYPE_PNG );
|
|
246 imgList->Add( bmp, wxNullBitmap );
|
|
247 bmp.LoadFile( wxT( "image/water.png" ), wxBITMAP_TYPE_PNG );
|
|
248 imgList->Add( bmp, wxNullBitmap );
|
|
249
|
|
250 m_notebook = new wxNotebook( this, ID_NBOOK, wxDefaultPosition, wxDefaultSize, 0 );
|
|
251 m_notebook->SetImageList( imgList );
|
|
252
|
|
253 m_scrolledWindow1 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
254 m_scrolledWindow1->SetScrollRate( 5, 5 );
|
|
255 m_notebook->AddPage( m_scrolledWindow1, wxT( "Image-01" ), false, 0 );
|
|
256
|
|
257 m_scrolledWindow2 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
258 m_scrolledWindow2->SetScrollRate( 5, 5 );
|
|
259 m_notebook->AddPage( m_scrolledWindow2, wxT( "Image-02" ), false, 0 );
|
|
260
|
|
261 m_scrolledWindow3 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
262 m_scrolledWindow3->SetScrollRate( 5, 5 );
|
|
263 m_notebook->AddPage( m_scrolledWindow3, wxT( "Image-03" ), false, 0 );
|
|
264
|
|
265 m_scrolledWindow4 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
266 m_scrolledWindow4->SetScrollRate( 5, 5 );
|
|
267 m_notebook->AddPage( m_scrolledWindow4, wxT( "Image-04" ), false, 0 );
|
|
268
|
|
269 m_scrolledWindow5 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
270 m_scrolledWindow5->SetScrollRate( 5, 5 );
|
|
271 m_notebook->AddPage( m_scrolledWindow5, wxT( "Image-05" ), false, 0 );
|
|
272
|
|
273 m_scrolledWindow6 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
|
|
274 m_scrolledWindow6->SetScrollRate( 5, 5 );
|
|
275 m_notebook->AddPage( m_scrolledWindow6, wxT( "Image-06" ), false, 0 );
|
|
276
|
|
277 bSizerTop->Add( m_notebook, 1, wxEXPAND|wxALL, 5 );
|
|
278
|
|
279 // Right
|
|
280 wxBoxSizer* bSizerRight = new wxBoxSizer( wxVERTICAL );
|
|
281
|
|
282 m_searchCtrl = new MySearchCtrl( this, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxSize( -1, 24 ), wxTE_PROCESS_ENTER );
|
|
283 bSizerRight->Add( m_searchCtrl, 0, wxALL, 5 );
|
|
284 m_searchCtrl->SetFocus();
|
|
285
|
|
286 m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, -1 ), 0 );
|
|
287 m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) );
|
|
288 bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 );
|
|
289
|
|
290 m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 120, -1 ), 0 );
|
|
291 m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) );
|
|
292 bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 );
|
|
293
|
|
294 m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE );
|
|
295 m_dataViewListColumnNo = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ), wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
|
|
296 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 120, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
|
|
297
|
|
298 bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 );
|
|
299
|
|
300 m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
301 bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 );
|
|
302
|
|
303 m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1,200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
|
|
304 bSizerRight->Add( m_slider, 0, wxALL, 5 );
|
|
305
|
|
306 m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
307 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
|
|
308
|
1
|
309 m_buttonTest = new wxButton( this, ID_TEST, wxT( "Test" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
310 bSizerRight->Add( m_buttonTest, 0, wxALL, 5 );
|
0
|
311
|
|
312 bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 );
|
|
313
|
|
314 this->SetSizer( bSizerTop );
|
|
315 this->Layout();
|
|
316
|
|
317 //this->Centre( wxBOTH );
|
|
318
|
|
319 m_staticBitmap1 = new MyStaticBitmap( m_scrolledWindow1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
320 m_staticBitmap2 = new MyStaticBitmap( m_scrolledWindow2, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
321 m_staticBitmap3 = new MyStaticBitmap( m_scrolledWindow3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
322 m_staticBitmap4 = new MyStaticBitmap( m_scrolledWindow4, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
323 m_staticBitmap5 = new MyStaticBitmap( m_scrolledWindow5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
|
324 }
|
|
325
|
|
326 void MainFrame::Cmd( wxString cmd )
|
|
327 {
|
|
328 m_dataViewListCtrl->DeleteAllItems();
|
|
329
|
|
330 if ( cmd.Cmp( wxT( "q" ) ) == 0 || cmd.Cmp( wxT( "9" ) ) == 0 ) {
|
|
331 Close();
|
|
332 }
|
|
333
|
|
334 if ( cmd.Cmp( wxT( "." ) ) == 0 ) {
|
|
335 wxString appdir = wxGetCwd();
|
|
336 wxString execmd = wxT( "explorer " ) + appdir;
|
|
337 wxExecute( execmd );
|
|
338 return;
|
|
339 }
|
|
340
|
|
341 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
|
|
342 if ( reHhs.Matches( cmd ) ) {
|
|
343 wxArrayString output, errors;
|
|
344 cmd = wxT( "./rsearcher -q " ) + cmd;
|
|
345 wxExecute( cmd, output, errors, wxEXEC_SYNC, NULL ); // ok
|
|
346
|
|
347 if ( output.GetCount() > 0 ) {
|
|
348 m_textCtrlName->SetValue( output[0] );
|
|
349 m_textCtrlAddr->SetValue( output[2] );
|
|
350 for ( int i = 5, n = 1; i < output.GetCount(); i++, n++ ) {
|
|
351 wxVector<wxVariant> data;
|
|
352 data.push_back( wxString::Format( wxT( "%02d" ), n ) );
|
|
353 data.push_back( output[i] );
|
|
354 m_dataViewListCtrl->AppendItem( data );
|
|
355 data.clear();
|
|
356 }
|
|
357 }
|
|
358
|
|
359 if ( errors.GetCount() > 0 ) {
|
|
360 wxMessageBox( errors[0], wxT( "Error" ) );
|
|
361 }
|
|
362 }
|
|
363 }
|
|
364
|
1
|
365 void MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
|
0
|
366 {
|
|
367 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
|
|
368 int width = bmp.GetWidth();
|
|
369 int height = bmp.GetHeight();
|
|
370 wxImage img = bmp.ConvertToImage();
|
|
371
|
|
372 int ww, wh;
|
1
|
373 sc->GetSize( &ww, &wh );
|
0
|
374
|
1
|
375 float w = ww - 50;
|
0
|
376 float h = w * height / width;
|
|
377 sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
|
1
|
378 sc->SetScrollbars( 10, 10, w / 10, h / 10 );
|
0
|
379
|
|
380 for ( int i = 0; i < 5; i++ ) {
|
|
381 w *= 1.1;
|
|
382 h *= 1.1;
|
|
383 //sb->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
|
|
384 }
|
|
385 }
|
|
386
|
|
387 void MainFrame::LoadBitmaps( void )
|
|
388 {
|
1
|
389 int date = 0;
|
|
390 LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( ".cache/%08d_1", date ) );
|
|
391 LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( ".cache/%08d_2", date ) );
|
|
392 LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( ".cache/%08d_3", date ) );
|
|
393 LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( ".cache/%08d_4", date ) );
|
|
394 LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( ".cache/%08d_5", date ) );
|
0
|
395 }
|
|
396
|
|
397 void MainFrame::GetImage( wxString hhs, wxString no )
|
|
398 {
|
|
399 // http get
|
|
400 }
|
|
401
|
1
|
402 void MainFrame::InDevelop( bool flag )
|
0
|
403 {
|
1
|
404 if ( !flag ) return;
|
0
|
405 LoadBitmaps();
|
|
406
|
|
407 m_slider->Enable( false );
|
|
408 m_slider->Show( false );
|
|
409
|
|
410 m_buttonPrint->Enable( false );
|
|
411 m_buttonPrint->Show( false );
|
|
412
|
1
|
413 bool tb = false;
|
|
414 m_buttonTest->Enable( tb );
|
|
415 m_buttonTest->Show( tb );
|
|
416
|
|
417 m_searchCtrl->Enable( false );
|
0
|
418 }
|
|
419
|