Mercurial > mercurial > hgweb_searcher03.cgi
diff src/myframe.cpp @ 1:7b6dab24f4b8
Gui parts complete.
author | pyon@macmini |
---|---|
date | Sun, 04 Aug 2013 21:42:49 +0900 |
parents | 0c0701a935f8 |
children | c066fde99517 |
line wrap: on
line diff
--- a/src/myframe.cpp Sun Jul 21 16:07:19 2013 +0900 +++ b/src/myframe.cpp Sun Aug 04 21:42:49 2013 +0900 @@ -1,7 +1,8 @@ // Filename : myframe.cpp -// Last Change: 21-Jul-2013. +// Last Change: 04-Aug-2013. // #include "main.h" +#include "db.h" #include "myframe.h" #include "about.h" #include "kana.h" @@ -9,6 +10,69 @@ #include "index.h" #include "mask.h" +/////////////////////////////////////////////////////////////// +// カスタム検索ボックス +MySearchBox::MySearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style ) + : wxSearchCtrl( parent, id, value, pos, size, style ) +{ +} + +MySearchBox::~MySearchBox() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( MySearchBox, wxSearchCtrl ) + EVT_CHAR( MySearchBox::OnKey ) +END_EVENT_TABLE() + +// Event Handlers & Functions +void MySearchBox::OnKey( wxKeyEvent& event ) +{ + wxString s = GetValue(); + // statustext( s.Len() ); + + if ( event.GetKeyCode() == 45 ) { // テンキーの '-' キーで1文字削除 + wxString t = GetStringSelection(); + if ( t.IsEmpty() ) { + long p = GetInsertionPoint(); + if ( p > 0 ) Remove( p - 1, p ); + } + else { + Cut(); + } + return; + } + + if ( event.GetKeyCode() == WXK_RETURN ) { + + if ( s.IsSameAs( wxT("+") ) ) { + wxMessageBox(wxT("pripri")); + return; + } + + wxRegEx reHhs( wxT("^0[1238][0-9]{8}$") ); + if ( reHhs.Matches( s ) ) { + wxString t = GetHhsInfoByHhsNo( s ); + wxArrayString array = GetPathByHhsNo( s ); + wxMessageBox( t ); + return; + } + + wxRegEx reNo( wxT("^[0-9]{1,2}$") ); + if ( reNo.Matches( s ) ) { + return; + } + + //m_parent->SetStatusMessage(wxT("bad input"), 0 ); + return; + } + + event.Skip(); +} + +/////////////////////////////////////////////////////////////// +// メインフレーム #define WINL_W 400 #define LOGO_W 200 #define LOGO_H 92 @@ -18,7 +82,6 @@ #include "sample.xpm" #endif - MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { @@ -60,10 +123,10 @@ wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D ); - //m_splitter->Connect( wxEVT_IDLE, wxIdleEventHandler( MyFrame::m_splitterOnIdle ), NULL, this ); + wxBoxSizer* bSizerL = new wxBoxSizer( wxVERTICAL ); + // left-pane m_panelL = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* bSizerL = new wxBoxSizer( wxVERTICAL ); wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png"); wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG ); @@ -91,20 +154,21 @@ wxBoxSizer* bSizerCmd = new wxBoxSizer( wxHORIZONTAL ); - //m_staticText = new wxStaticText( m_panelL, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 ); - //bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_staticText = new wxStaticText( m_panelL, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - m_searchCtrl = new wxSearchCtrl( m_panelL, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + m_searchBox = new MySearchBox( m_panelL, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); #ifndef __WXMAC__ - m_searchCtrl->ShowSearchButton( true ); + m_searchBox->ShowSearchButton( true ); #endif - m_searchCtrl->ShowCancelButton( false ); - bSizerCmd->Add( m_searchCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_searchBox->ShowCancelButton( false ); + m_searchBox->SetFocus(); + bSizerCmd->Add( m_searchBox, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - m_buttonKana = new wxButton( m_panelL, ID_KANA, wxT("カナ検索"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizerCmd->Add( m_buttonKana, 0, wxALL, 5 ); + m_buttonKana = new wxButton( m_panelL, ID_KANA, wxT("カナ検索"), wxDefaultPosition, wxSize( 65, -1 ), 0 ); + bSizerCmd->Add( m_buttonKana, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 20 ); - m_buttonHist = new wxButton( m_panelL, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonHist = new wxButton( m_panelL, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxSize( 65, -1 ), 0 ); bSizerCmd->Add( m_buttonHist, 0, wxALL, 5 ); bSizerL->Add( bSizerCmd, 0, wxEXPAND, 5 ); @@ -113,6 +177,7 @@ m_panelL->Layout(); bSizerL->Fit( m_panelL ); + // right-pane m_panelR = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* bSizerR = new wxBoxSizer( wxHORIZONTAL ); @@ -127,17 +192,21 @@ bSizerR->Fit( m_panelR ); m_panelR->Show( false ); + m_splitter->Initialize( m_panelL ); bSizerTop->Add( m_splitter, 1, wxEXPAND, 5 ); this->SetSizer( bSizerTop ); this->Layout(); // ステータスバー Statusbar - m_statusBar = this->CreateStatusBar( 4, wxST_SIZEGRIP, wxID_ANY ); + m_statusBar = new wxStatusBar( this, wxID_ANY, wxST_SIZEGRIP ); int widths[] = { 200, 100, -1, 90 }; - m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); + m_statusBar->SetFieldsCount( 4, widths ); + this->SetStatusBar( m_statusBar ); + SetStatusText( wxT("被保番を入力してスタート!") ); this->Centre( wxBOTH ); + LoadMaskParam(); } MyFrame::~MyFrame() @@ -168,12 +237,72 @@ index->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); index->ShowModal(); } +/* マスクパラメータを設定ファイルから読み込む */ +void MyFrame::LoadMaskParam( void ) +{ + conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); + config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); + + int x, y, w, h; + + config->SetPath( wxT("/Mask") ); + + config->Read( wxT("x1"), &x ); + config->Read( wxT("y1"), &y ); + config->Read( wxT("w1"), &w ); + config->Read( wxT("h1"), &h ); + m_mask1.SetPosition( wxPoint( x, y ) ); + m_mask1.SetSize( wxSize( w, h ) ); + + config->Read( wxT("x2"), &x ); + config->Read( wxT("y2"), &y ); + config->Read( wxT("w2"), &w ); + config->Read( wxT("h2"), &h ); + m_mask2.SetPosition( wxPoint( x, y ) ); + m_mask2.SetSize( wxSize( w, h ) ); + + config->Read( wxT("x3"), &x ); + config->Read( wxT("y3"), &y ); + config->Read( wxT("w3"), &w ); + config->Read( wxT("h3"), &h ); + m_mask3.SetPosition( wxPoint( x, y ) ); + m_mask3.SetSize( wxSize( w, h ) ); + +} /* マスクパラメータ設定ダイアログ */ void MyFrame::OnMaskParam( wxCommandEvent& WXUNUSED(event) ) { MaskDialog* mask = new MaskDialog( this, wxID_ANY, wxT("マスク位置とサイズの指定"), wxDefaultPosition, wxSize( 400, 210 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); + mask->SetMask1( m_mask1 ); + mask->SetMask2( m_mask2 ); + mask->SetMask3( m_mask3 ); + mask->LoadParams(); mask->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); - mask->ShowModal(); + + if ( mask->ShowModal() == wxID_OK ) { + m_mask1 = mask->GetMask1(); + m_mask2 = mask->GetMask2(); + m_mask3 = mask->GetMask3(); + + config->SetPath( wxT("/Mask") ); + + config->Write( wxT("x1"), m_mask1.GetX() ); + config->Write( wxT("y1"), m_mask1.GetY() ); + config->Write( wxT("w1"), m_mask1.GetWidth() ); + config->Write( wxT("h1"), m_mask1.GetHeight() ); + + config->Write( wxT("x2"), m_mask2.GetX() ); + config->Write( wxT("y2"), m_mask2.GetY() ); + config->Write( wxT("w2"), m_mask2.GetWidth() ); + config->Write( wxT("h2"), m_mask2.GetHeight() ); + + config->Write( wxT("x3"), m_mask3.GetX() ); + config->Write( wxT("y3"), m_mask3.GetY() ); + config->Write( wxT("w3"), m_mask3.GetWidth() ); + config->Write( wxT("h3"), m_mask3.GetHeight() ); + + delete config; + } } /* アプリフォルダを開く */ void MyFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) ) @@ -218,19 +347,43 @@ dvf->Show(true); */ } + /* カナ検索ダイアログ */ void MyFrame::OnKana( wxCommandEvent& WXUNUSED(event) ) { - KanaDialog* kana = new KanaDialog( this, wxID_ANY, wxT("カナ氏名で被保番を検索"), wxDefaultPosition, wxSize( 500, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxRESIZE_BORDER|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); + KanaDialog* kana = new KanaDialog( this, wxID_ANY, wxT("カナ氏名で被保番を検索"), wxDefaultPosition, wxSize( 600, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxRESIZE_BORDER|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); kana->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); - kana->ShowModal(); + + if ( kana->ShowModal() == wxID_OK ) { + wxMessageBox( kana->GetHhsNo() ); + } + + UpdateList(); } /* 検索履歴検索ダイアログ */ void MyFrame::OnHistory( wxCommandEvent& WXUNUSED(event) ) { HistDialog* hist = new HistDialog( this, wxID_ANY, wxT("検索履歴"), wxDefaultPosition, wxSize( 550, 500 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL ); hist->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM ); - hist->ShowModal(); + + if ( hist->ShowModal() == wxID_OK ) { + + } + + UpdateList(); +} + +/* 検索結果をリストアップ */ +void MyFrame::UpdateList( void ) +{ + m_listCtrl->DeleteAllItems(); +} + +/* ステータスバーにメッセージを出力 */ +void MyFrame::SetStatusMessage( wxString msg, long n ) +{ + if ( GetStatusBar() ) + SetStatusText( msg, n ); } /* サイズ変更 */ @@ -254,7 +407,9 @@ int y = r.GetY(); int w = r.GetWidth(); int h = r.GetHeight(); - //SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 ); + + if ( GetStatusBar() ) + SetStatusText( wxString::Format(wxT( "(%d,%d) %dx%d"),x,y,w,h ), 3 ); } /* 終了 */ void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )