Mercurial > mercurial > hgweb_rsearcher.cgi
comparison src/rsearcher.cpp @ 0:d3b8cd5aeb70
make repo.
author | pyon@macmini |
---|---|
date | Sun, 30 Sep 2018 17:27:04 +0900 |
parents | |
children | eaa27e4ed5be |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d3b8cd5aeb70 |
---|---|
1 // Filename : rsearcher.cpp | |
2 // Last Change: 2018-09-16 Sun 18:25:30. | |
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 { | |
150 this->SetIcon( wxIcon( wxT( "sample" ) ) ); | |
151 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | |
152 //this->SetBackgroundColour( wxColour( 0, 150, 230 ) ); | |
153 | |
154 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
155 | |
156 // Left | |
157 wxImageList* imgList = new wxImageList( 16, 16, false, 1 ); | |
158 wxBitmap bmp( wxT( "image/blue.png" ), wxBITMAP_TYPE_PNG ); | |
159 imgList->Add( bmp, wxNullBitmap ); | |
160 bmp.LoadFile( wxT( "image/water.png" ), wxBITMAP_TYPE_PNG ); | |
161 imgList->Add( bmp, wxNullBitmap ); | |
162 | |
163 m_notebook = new wxNotebook( this, ID_NBOOK, wxDefaultPosition, wxDefaultSize, 0 ); | |
164 m_notebook->SetImageList( imgList ); | |
165 | |
166 m_scrolledWindow1 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
167 m_scrolledWindow1->SetScrollRate( 5, 5 ); | |
168 m_notebook->AddPage( m_scrolledWindow1, wxT( "Image-01" ), false, 0 ); | |
169 | |
170 m_scrolledWindow2 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
171 m_scrolledWindow2->SetScrollRate( 5, 5 ); | |
172 m_notebook->AddPage( m_scrolledWindow2, wxT( "Image-02" ), false, 0 ); | |
173 | |
174 m_scrolledWindow3 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
175 m_scrolledWindow3->SetScrollRate( 5, 5 ); | |
176 m_notebook->AddPage( m_scrolledWindow3, wxT( "Image-03" ), false, 0 ); | |
177 | |
178 m_scrolledWindow4 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
179 m_scrolledWindow4->SetScrollRate( 5, 5 ); | |
180 m_notebook->AddPage( m_scrolledWindow4, wxT( "Image-04" ), false, 0 ); | |
181 | |
182 m_scrolledWindow5 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
183 m_scrolledWindow5->SetScrollRate( 5, 5 ); | |
184 m_notebook->AddPage( m_scrolledWindow5, wxT( "Image-05" ), false, 0 ); | |
185 | |
186 m_scrolledWindow6 = new wxScrolledWindow( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); | |
187 m_scrolledWindow6->SetScrollRate( 5, 5 ); | |
188 m_notebook->AddPage( m_scrolledWindow6, wxT( "Image-06" ), false, 0 ); | |
189 | |
190 bSizerTop->Add( m_notebook, 1, wxEXPAND|wxALL, 5 ); | |
191 | |
192 // Right | |
193 wxBoxSizer* bSizerRight = new wxBoxSizer( wxVERTICAL ); | |
194 | |
195 m_searchCtrl = new MySearchCtrl( this, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxSize( -1, 24 ), wxTE_PROCESS_ENTER ); | |
196 bSizerRight->Add( m_searchCtrl, 0, wxALL, 5 ); | |
197 m_searchCtrl->SetFocus(); | |
198 | |
199 m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, -1 ), 0 ); | |
200 m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) ); | |
201 bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 ); | |
202 | |
203 m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 120, -1 ), 0 ); | |
204 m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) ); | |
205 bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 ); | |
206 | |
207 m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE ); | |
208 m_dataViewListColumnNo = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ), wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE ); | |
209 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 120, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE ); | |
210 | |
211 bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 ); | |
212 | |
213 m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); | |
214 bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 ); | |
215 | |
216 m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1,200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL ); | |
217 bSizerRight->Add( m_slider, 0, wxALL, 5 ); | |
218 | |
219 m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 ); | |
220 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 ); | |
221 | |
222 m_button = new wxButton( this, ID_TEST, wxT( "MyButton" ), wxDefaultPosition, wxDefaultSize, 0 ); | |
223 bSizerRight->Add( m_button, 0, wxALL, 5 ); | |
224 | |
225 bSizerTop->Add( bSizerRight, 0, wxEXPAND, 5 ); | |
226 | |
227 this->SetSizer( bSizerTop ); | |
228 this->Layout(); | |
229 | |
230 //this->Centre( wxBOTH ); | |
231 | |
232 m_staticBitmap1 = new MyStaticBitmap( m_scrolledWindow1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); | |
233 m_staticBitmap2 = new MyStaticBitmap( m_scrolledWindow2, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); | |
234 m_staticBitmap3 = new MyStaticBitmap( m_scrolledWindow3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); | |
235 m_staticBitmap4 = new MyStaticBitmap( m_scrolledWindow4, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); | |
236 m_staticBitmap5 = new MyStaticBitmap( m_scrolledWindow5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString ); | |
237 | |
238 InDevelop(); | |
239 } | |
240 | |
241 MainFrame::~MainFrame() | |
242 { | |
243 } | |
244 | |
245 // Event Table | |
246 BEGIN_EVENT_TABLE( MainFrame, wxFrame ) | |
247 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked ) | |
248 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged ) | |
249 EVT_BUTTON( ID_TEST, MainFrame::OnTestButton ) | |
250 EVT_CLOSE( MainFrame::SaveConfig ) | |
251 //EVT_IDLE( MainFrame::OnIdle ) | |
252 END_EVENT_TABLE() | |
253 | |
254 | |
255 // Event Handler | |
256 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) ) | |
257 { | |
258 wxMessageBox( "dcli" ); | |
259 int r = m_dataViewListCtrl->GetSelectedRow(); | |
260 wxString no = m_dataViewListCtrl->GetTextValue( r, 0 ); | |
261 | |
262 LoadBitmaps(); | |
263 } | |
264 | |
265 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) ) | |
266 { | |
267 for ( int i = 0; i < m_notebook->GetPageCount(); i++ ) { | |
268 m_notebook->SetPageImage( i, 1 ); | |
269 } | |
270 m_notebook->SetPageImage( m_notebook->GetSelection(), 0 ); | |
271 } | |
272 | |
273 /* | |
274 void MainFrame::OnItemSelected( wxDataViewEvent& event ) | |
275 { | |
276 dclick or select ? | |
277 } | |
278 */ | |
279 | |
280 | |
281 /* | |
282 void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) | |
283 { | |
284 } | |
285 | |
286 */ | |
287 void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) | |
288 { | |
289 if ( !IsIconized() && !IsMaximized() ) { | |
290 wxGetApp().rect = this->GetRect(); | |
291 } | |
292 Destroy(); | |
293 } | |
294 | |
295 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) ) | |
296 { | |
297 /* ok | |
298 Cmd( m_searchCtrl->GetValue() ); | |
299 Cmd( wxT( "0100012345" ) ); | |
300 */ | |
301 | |
302 wxBitmap bmp( wxT("db/19970101/img088.jpg"), wxBITMAP_TYPE_JPEG ); | |
303 int width = bmp.GetWidth(); | |
304 int height = bmp.GetHeight(); | |
305 wxImage img = bmp.ConvertToImage(); | |
306 | |
307 int ww, wh; | |
308 m_scrolledWindow1->GetSize( &ww, &wh ); | |
309 | |
310 float w = ww; | |
311 float h = w * height / width; | |
312 m_staticBitmap1->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) ); | |
313 m_scrolledWindow1->SetScrollbars( 10, 10, w / 10, h / 10 ); | |
314 | |
315 for ( int i = 0; i < 5; i++ ) { | |
316 w *= 1.1; | |
317 h *= 1.1; | |
318 m_staticBitmap1->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) ); | |
319 } | |
320 } | |
321 | |
322 // Functions | |
323 void MainFrame::Cmd( wxString cmd ) | |
324 { | |
325 m_dataViewListCtrl->DeleteAllItems(); | |
326 | |
327 if ( cmd.Cmp( wxT( "q" ) ) == 0 || cmd.Cmp( wxT( "9" ) ) == 0 ) { | |
328 Close(); | |
329 } | |
330 | |
331 if ( cmd.Cmp( wxT( "." ) ) == 0 ) { | |
332 wxString appdir = wxGetCwd(); | |
333 wxString execmd = wxT( "explorer " ) + appdir; | |
334 wxExecute( execmd ); | |
335 return; | |
336 } | |
337 | |
338 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) ); | |
339 if ( reHhs.Matches( cmd ) ) { | |
340 wxArrayString output, errors; | |
341 cmd = wxT( "./rsearcher -q " ) + cmd; | |
342 wxExecute( cmd, output, errors, wxEXEC_SYNC, NULL ); // ok | |
343 | |
344 if ( output.GetCount() > 0 ) { | |
345 m_textCtrlName->SetValue( output[0] ); | |
346 m_textCtrlAddr->SetValue( output[2] ); | |
347 for ( int i = 5, n = 1; i < output.GetCount(); i++, n++ ) { | |
348 wxVector<wxVariant> data; | |
349 data.push_back( wxString::Format( wxT( "%02d" ), n ) ); | |
350 data.push_back( output[i] ); | |
351 m_dataViewListCtrl->AppendItem( data ); | |
352 data.clear(); | |
353 } | |
354 } | |
355 | |
356 if ( errors.GetCount() > 0 ) { | |
357 wxMessageBox( errors[0], wxT( "Error" ) ); | |
358 } | |
359 } | |
360 } | |
361 | |
362 void MainFrame::LoadBitmap( wxStaticBitmap* sb, wxString file ) | |
363 { | |
364 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG ); | |
365 int width = bmp.GetWidth(); | |
366 int height = bmp.GetHeight(); | |
367 wxImage img = bmp.ConvertToImage(); | |
368 | |
369 int ww, wh; | |
370 sb->GetSize( &ww, &wh ); | |
371 | |
372 float w = ww; | |
373 float h = w * height / width; | |
374 sb->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) ); | |
375 //sb->SetScrollbars( 10, 10, w / 10, h / 10 ); | |
376 | |
377 for ( int i = 0; i < 5; i++ ) { | |
378 w *= 1.1; | |
379 h *= 1.1; | |
380 //sb->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) ); | |
381 } | |
382 } | |
383 | |
384 void MainFrame::LoadBitmaps( void ) | |
385 { | |
386 int no = 1; | |
387 LoadBitmap( m_staticBitmap1, wxString::Format( ".cache/%02d_1", no ) ); | |
388 LoadBitmap( m_staticBitmap2, wxString::Format( ".cache/%02d_2", no ) ); | |
389 LoadBitmap( m_staticBitmap3, wxString::Format( ".cache/%02d_3", no ) ); | |
390 LoadBitmap( m_staticBitmap4, wxString::Format( ".cache/%02d_4", no ) ); | |
391 LoadBitmap( m_staticBitmap5, wxString::Format( ".cache/%02d_5", no ) ); | |
392 } | |
393 | |
394 void MainFrame::GetImage( wxString hhs, wxString no ) | |
395 { | |
396 // http get | |
397 } | |
398 | |
399 void MainFrame::InDevelop( void ) | |
400 { | |
401 LoadBitmaps(); | |
402 | |
403 m_slider->Enable( false ); | |
404 m_slider->Show( false ); | |
405 | |
406 m_buttonPrint->Enable( false ); | |
407 m_buttonPrint->Show( false ); | |
408 | |
409 m_button->Enable( false ); | |
410 m_button->Show( false ); | |
411 } | |
412 |