comparison src/myframe.cpp @ 1:7b6dab24f4b8

Gui parts complete.
author pyon@macmini
date Sun, 04 Aug 2013 21:42:49 +0900
parents 0c0701a935f8
children c066fde99517
comparison
equal deleted inserted replaced
0:0c0701a935f8 1:7b6dab24f4b8
1 // Filename : myframe.cpp 1 // Filename : myframe.cpp
2 // Last Change: 21-Jul-2013. 2 // Last Change: 04-Aug-2013.
3 // 3 //
4 #include "main.h" 4 #include "main.h"
5 #include "db.h"
5 #include "myframe.h" 6 #include "myframe.h"
6 #include "about.h" 7 #include "about.h"
7 #include "kana.h" 8 #include "kana.h"
8 #include "hist.h" 9 #include "hist.h"
9 #include "index.h" 10 #include "index.h"
10 #include "mask.h" 11 #include "mask.h"
11 12
13 ///////////////////////////////////////////////////////////////
14 // カスタム検索ボックス
15 MySearchBox::MySearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style )
16 : wxSearchCtrl( parent, id, value, pos, size, style )
17 {
18 }
19
20 MySearchBox::~MySearchBox()
21 {
22 }
23
24 // Event Table
25 BEGIN_EVENT_TABLE( MySearchBox, wxSearchCtrl )
26 EVT_CHAR( MySearchBox::OnKey )
27 END_EVENT_TABLE()
28
29 // Event Handlers & Functions
30 void MySearchBox::OnKey( wxKeyEvent& event )
31 {
32 wxString s = GetValue();
33 // statustext( s.Len() );
34
35 if ( event.GetKeyCode() == 45 ) { // テンキーの '-' キーで1文字削除
36 wxString t = GetStringSelection();
37 if ( t.IsEmpty() ) {
38 long p = GetInsertionPoint();
39 if ( p > 0 ) Remove( p - 1, p );
40 }
41 else {
42 Cut();
43 }
44 return;
45 }
46
47 if ( event.GetKeyCode() == WXK_RETURN ) {
48
49 if ( s.IsSameAs( wxT("+") ) ) {
50 wxMessageBox(wxT("pripri"));
51 return;
52 }
53
54 wxRegEx reHhs( wxT("^0[1238][0-9]{8}$") );
55 if ( reHhs.Matches( s ) ) {
56 wxString t = GetHhsInfoByHhsNo( s );
57 wxArrayString array = GetPathByHhsNo( s );
58 wxMessageBox( t );
59 return;
60 }
61
62 wxRegEx reNo( wxT("^[0-9]{1,2}$") );
63 if ( reNo.Matches( s ) ) {
64 return;
65 }
66
67 //m_parent->SetStatusMessage(wxT("bad input"), 0 );
68 return;
69 }
70
71 event.Skip();
72 }
73
74 ///////////////////////////////////////////////////////////////
75 // メインフレーム
12 #define WINL_W 400 76 #define WINL_W 400
13 #define LOGO_W 200 77 #define LOGO_W 200
14 #define LOGO_H 92 78 #define LOGO_H 92
15 79
16 // resources 80 // resources
17 #if !defined(__WXMSW__) && !defined(__WXPM__) 81 #if !defined(__WXMSW__) && !defined(__WXPM__)
18 #include "sample.xpm" 82 #include "sample.xpm"
19 #endif 83 #endif
20 84
21
22 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 85 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
23 : wxFrame( parent, id, title, pos, size, style ) 86 : wxFrame( parent, id, title, pos, size, style )
24 { 87 {
25 this->SetSizeHints( wxSize( WINL_W, 500 ), wxDefaultSize ); 88 this->SetSizeHints( wxSize( WINL_W, 500 ), wxDefaultSize );
26 this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) ); 89 this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) );
58 121
59 // 122 //
60 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); 123 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
61 124
62 m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D ); 125 m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D );
63 //m_splitter->Connect( wxEVT_IDLE, wxIdleEventHandler( MyFrame::m_splitterOnIdle ), NULL, this ); 126 wxBoxSizer* bSizerL = new wxBoxSizer( wxVERTICAL );
64 127
128 // left-pane
65 m_panelL = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); 129 m_panelL = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
66 wxBoxSizer* bSizerL = new wxBoxSizer( wxVERTICAL );
67 130
68 wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png"); 131 wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png");
69 wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG ); 132 wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG );
70 m_bitmap = new wxStaticBitmap( m_panelL, wxID_ANY, bmp, wxDefaultPosition, wxSize( LOGO_W, LOGO_H ), 0 ); 133 m_bitmap = new wxStaticBitmap( m_panelL, wxID_ANY, bmp, wxDefaultPosition, wxSize( LOGO_W, LOGO_H ), 0 );
71 bSizerL->Add( m_bitmap, 0, wxALL, 5 ); 134 bSizerL->Add( m_bitmap, 0, wxALL, 5 );
89 m_listCtrl->SetColumnWidth( 2, 300 ); 152 m_listCtrl->SetColumnWidth( 2, 300 );
90 bSizerL->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 ); 153 bSizerL->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
91 154
92 wxBoxSizer* bSizerCmd = new wxBoxSizer( wxHORIZONTAL ); 155 wxBoxSizer* bSizerCmd = new wxBoxSizer( wxHORIZONTAL );
93 156
94 //m_staticText = new wxStaticText( m_panelL, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 ); 157 m_staticText = new wxStaticText( m_panelL, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 );
95 //bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 158 bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
96 159
97 m_searchCtrl = new wxSearchCtrl( m_panelL, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); 160 m_searchBox = new MySearchBox( m_panelL, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
98 #ifndef __WXMAC__ 161 #ifndef __WXMAC__
99 m_searchCtrl->ShowSearchButton( true ); 162 m_searchBox->ShowSearchButton( true );
100 #endif 163 #endif
101 m_searchCtrl->ShowCancelButton( false ); 164 m_searchBox->ShowCancelButton( false );
102 bSizerCmd->Add( m_searchCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 165 m_searchBox->SetFocus();
103 166 bSizerCmd->Add( m_searchBox, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
104 m_buttonKana = new wxButton( m_panelL, ID_KANA, wxT("カナ検索"), wxDefaultPosition, wxDefaultSize, 0 ); 167
105 bSizerCmd->Add( m_buttonKana, 0, wxALL, 5 ); 168 m_buttonKana = new wxButton( m_panelL, ID_KANA, wxT("カナ検索"), wxDefaultPosition, wxSize( 65, -1 ), 0 );
106 169 bSizerCmd->Add( m_buttonKana, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 20 );
107 m_buttonHist = new wxButton( m_panelL, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxDefaultSize, 0 ); 170
171 m_buttonHist = new wxButton( m_panelL, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxSize( 65, -1 ), 0 );
108 bSizerCmd->Add( m_buttonHist, 0, wxALL, 5 ); 172 bSizerCmd->Add( m_buttonHist, 0, wxALL, 5 );
109 173
110 bSizerL->Add( bSizerCmd, 0, wxEXPAND, 5 ); 174 bSizerL->Add( bSizerCmd, 0, wxEXPAND, 5 );
111 175
112 m_panelL->SetSizer( bSizerL ); 176 m_panelL->SetSizer( bSizerL );
113 m_panelL->Layout(); 177 m_panelL->Layout();
114 bSizerL->Fit( m_panelL ); 178 bSizerL->Fit( m_panelL );
115 179
180 // right-pane
116 m_panelR = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); 181 m_panelR = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
117 wxBoxSizer* bSizerR = new wxBoxSizer( wxHORIZONTAL ); 182 wxBoxSizer* bSizerR = new wxBoxSizer( wxHORIZONTAL );
118 183
119 m_bitmapView = new wxStaticBitmap( m_panelR, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); 184 m_bitmapView = new wxStaticBitmap( m_panelR, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
120 bSizerR->Add( m_bitmapView, 1, wxALL|wxEXPAND, 5 ); 185 bSizerR->Add( m_bitmapView, 1, wxALL|wxEXPAND, 5 );
125 m_panelR->SetSizer( bSizerR ); 190 m_panelR->SetSizer( bSizerR );
126 m_panelR->Layout(); 191 m_panelR->Layout();
127 bSizerR->Fit( m_panelR ); 192 bSizerR->Fit( m_panelR );
128 193
129 m_panelR->Show( false ); 194 m_panelR->Show( false );
195 m_splitter->Initialize( m_panelL );
130 bSizerTop->Add( m_splitter, 1, wxEXPAND, 5 ); 196 bSizerTop->Add( m_splitter, 1, wxEXPAND, 5 );
131 197
132 this->SetSizer( bSizerTop ); 198 this->SetSizer( bSizerTop );
133 this->Layout(); 199 this->Layout();
134 200
135 // ステータスバー Statusbar 201 // ステータスバー Statusbar
136 m_statusBar = this->CreateStatusBar( 4, wxST_SIZEGRIP, wxID_ANY ); 202 m_statusBar = new wxStatusBar( this, wxID_ANY, wxST_SIZEGRIP );
137 int widths[] = { 200, 100, -1, 90 }; 203 int widths[] = { 200, 100, -1, 90 };
138 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); 204 m_statusBar->SetFieldsCount( 4, widths );
205 this->SetStatusBar( m_statusBar );
206 SetStatusText( wxT("被保番を入力してスタート!") );
139 207
140 this->Centre( wxBOTH ); 208 this->Centre( wxBOTH );
209 LoadMaskParam();
141 } 210 }
142 211
143 MyFrame::~MyFrame() 212 MyFrame::~MyFrame()
144 { 213 {
145 } 214 }
166 { 235 {
167 IndexDialog* index = new IndexDialog( this, wxID_ANY, wxT("インデックス作成"), wxDefaultPosition, wxSize( 500, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); 236 IndexDialog* index = new IndexDialog( this, wxID_ANY, wxT("インデックス作成"), wxDefaultPosition, wxSize( 500, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
168 index->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); 237 index->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
169 index->ShowModal(); 238 index->ShowModal();
170 } 239 }
240 /* マスクパラメータを設定ファイルから読み込む */
241 void MyFrame::LoadMaskParam( void )
242 {
243 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf");
244 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
245
246 int x, y, w, h;
247
248 config->SetPath( wxT("/Mask") );
249
250 config->Read( wxT("x1"), &x );
251 config->Read( wxT("y1"), &y );
252 config->Read( wxT("w1"), &w );
253 config->Read( wxT("h1"), &h );
254 m_mask1.SetPosition( wxPoint( x, y ) );
255 m_mask1.SetSize( wxSize( w, h ) );
256
257 config->Read( wxT("x2"), &x );
258 config->Read( wxT("y2"), &y );
259 config->Read( wxT("w2"), &w );
260 config->Read( wxT("h2"), &h );
261 m_mask2.SetPosition( wxPoint( x, y ) );
262 m_mask2.SetSize( wxSize( w, h ) );
263
264 config->Read( wxT("x3"), &x );
265 config->Read( wxT("y3"), &y );
266 config->Read( wxT("w3"), &w );
267 config->Read( wxT("h3"), &h );
268 m_mask3.SetPosition( wxPoint( x, y ) );
269 m_mask3.SetSize( wxSize( w, h ) );
270
271 }
171 /* マスクパラメータ設定ダイアログ */ 272 /* マスクパラメータ設定ダイアログ */
172 void MyFrame::OnMaskParam( wxCommandEvent& WXUNUSED(event) ) 273 void MyFrame::OnMaskParam( wxCommandEvent& WXUNUSED(event) )
173 { 274 {
174 MaskDialog* mask = new MaskDialog( this, wxID_ANY, wxT("マスク位置とサイズの指定"), wxDefaultPosition, wxSize( 400, 210 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); 275 MaskDialog* mask = new MaskDialog( this, wxID_ANY, wxT("マスク位置とサイズの指定"), wxDefaultPosition, wxSize( 400, 210 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
276 mask->SetMask1( m_mask1 );
277 mask->SetMask2( m_mask2 );
278 mask->SetMask3( m_mask3 );
279 mask->LoadParams();
175 mask->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); 280 mask->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
176 mask->ShowModal(); 281
282 if ( mask->ShowModal() == wxID_OK ) {
283 m_mask1 = mask->GetMask1();
284 m_mask2 = mask->GetMask2();
285 m_mask3 = mask->GetMask3();
286
287 config->SetPath( wxT("/Mask") );
288
289 config->Write( wxT("x1"), m_mask1.GetX() );
290 config->Write( wxT("y1"), m_mask1.GetY() );
291 config->Write( wxT("w1"), m_mask1.GetWidth() );
292 config->Write( wxT("h1"), m_mask1.GetHeight() );
293
294 config->Write( wxT("x2"), m_mask2.GetX() );
295 config->Write( wxT("y2"), m_mask2.GetY() );
296 config->Write( wxT("w2"), m_mask2.GetWidth() );
297 config->Write( wxT("h2"), m_mask2.GetHeight() );
298
299 config->Write( wxT("x3"), m_mask3.GetX() );
300 config->Write( wxT("y3"), m_mask3.GetY() );
301 config->Write( wxT("w3"), m_mask3.GetWidth() );
302 config->Write( wxT("h3"), m_mask3.GetHeight() );
303
304 delete config;
305 }
177 } 306 }
178 /* アプリフォルダを開く */ 307 /* アプリフォルダを開く */
179 void MyFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) ) 308 void MyFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) )
180 { 309 {
181 wxString appdir = wxGetCwd(); 310 wxString appdir = wxGetCwd();
216 dvf->m_dir = hhsdir; 345 dvf->m_dir = hhsdir;
217 dvf->LoadListImage(); 346 dvf->LoadListImage();
218 dvf->Show(true); 347 dvf->Show(true);
219 */ 348 */
220 } 349 }
350
221 /* カナ検索ダイアログ */ 351 /* カナ検索ダイアログ */
222 void MyFrame::OnKana( wxCommandEvent& WXUNUSED(event) ) 352 void MyFrame::OnKana( wxCommandEvent& WXUNUSED(event) )
223 { 353 {
224 KanaDialog* kana = new KanaDialog( this, wxID_ANY, wxT("カナ氏名で被保番を検索"), wxDefaultPosition, wxSize( 500, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxRESIZE_BORDER|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); 354 KanaDialog* kana = new KanaDialog( this, wxID_ANY, wxT("カナ氏名で被保番を検索"), wxDefaultPosition, wxSize( 600, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxRESIZE_BORDER|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
225 kana->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); 355 kana->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
226 kana->ShowModal(); 356
357 if ( kana->ShowModal() == wxID_OK ) {
358 wxMessageBox( kana->GetHhsNo() );
359 }
360
361 UpdateList();
227 } 362 }
228 /* 検索履歴検索ダイアログ */ 363 /* 検索履歴検索ダイアログ */
229 void MyFrame::OnHistory( wxCommandEvent& WXUNUSED(event) ) 364 void MyFrame::OnHistory( wxCommandEvent& WXUNUSED(event) )
230 { 365 {
231 HistDialog* hist = new HistDialog( this, wxID_ANY, wxT("検索履歴"), wxDefaultPosition, wxSize( 550, 500 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); 366 HistDialog* hist = new HistDialog( this, wxID_ANY, wxT("検索履歴"), wxDefaultPosition, wxSize( 550, 500 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
232 hist->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); 367 hist->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
233 hist->ShowModal(); 368
369 if ( hist->ShowModal() == wxID_OK ) {
370
371 }
372
373 UpdateList();
374 }
375
376 /* 検索結果をリストアップ */
377 void MyFrame::UpdateList( void )
378 {
379 m_listCtrl->DeleteAllItems();
380 }
381
382 /* ステータスバーにメッセージを出力 */
383 void MyFrame::SetStatusMessage( wxString msg, long n )
384 {
385 if ( GetStatusBar() )
386 SetStatusText( msg, n );
234 } 387 }
235 388
236 /* サイズ変更 */ 389 /* サイズ変更 */
237 void MyFrame::OnWinSize( wxSizeEvent& event ) 390 void MyFrame::OnWinSize( wxSizeEvent& event )
238 { 391 {
252 wxRect r = this->GetRect(); 405 wxRect r = this->GetRect();
253 int x = r.GetX(); 406 int x = r.GetX();
254 int y = r.GetY(); 407 int y = r.GetY();
255 int w = r.GetWidth(); 408 int w = r.GetWidth();
256 int h = r.GetHeight(); 409 int h = r.GetHeight();
257 //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); 410
411 if ( GetStatusBar() )
412 SetStatusText( wxString::Format(wxT( "(%d,%d) %dx%d"),x,y,w,h ), 3 );
258 } 413 }
259 /* 終了 */ 414 /* 終了 */
260 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) 415 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
261 { 416 {
262 Close( true ); 417 Close( true );