Mercurial > mercurial > hgweb_searcher03.cgi
diff src/myframe.cpp @ 9:b455f2d8aac9
Implement Preview.
author | pyon@macmini |
---|---|
date | Thu, 24 Apr 2014 18:31:39 +0900 |
parents | 4967d1e2b30c |
children | 29021e6e1ebe |
line wrap: on
line diff
--- a/src/myframe.cpp Fri Nov 01 18:44:37 2013 +0900 +++ b/src/myframe.cpp Thu Apr 24 18:31:39 2014 +0900 @@ -1,17 +1,19 @@ // Filename : myframe.cpp -// Last Change: 01-Nov-2013. +// Last Change: 24-Apr-2014. // #include "main.h" #include "db.h" #include "about.h" #include "kana.h" #include "hist.h" +#include "preview.h" #include "index.h" #include "param.h" #include "marksheet.h" #include "myframe.h" #include "bprint.h" + /////////////////////////////////////////////////////////////// // カスタム検索ボックス MySearchBox::MySearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style ) @@ -23,6 +25,12 @@ { } +void MySearchBox::SetMessage( wxString msg ) +{ + wxFrame* p = (wxFrame*)FindWindowById( ID_MAIN ); + p->SetStatusText( msg, 0 ); +} + // Event Table BEGIN_EVENT_TABLE( MySearchBox, wxSearchCtrl ) EVT_CHAR( MySearchBox::OnKey ) @@ -31,10 +39,15 @@ // Event Handlers & Functions void MySearchBox::OnKey( wxKeyEvent& event ) { + int kc = event.GetKeyCode(); wxString s = GetValue(); - // statustext( s.Len() ); - if ( event.GetKeyCode() == 45 ) { // テンキーの '-' キーで1文字削除 + if ( kc == 13 ) { + event.Skip(); + return; + } + + if ( kc == 45 ) { // テンキーの '-' キーで1文字削除 wxString t = GetStringSelection(); if ( t.IsEmpty() ) { long p = GetInsertionPoint(); @@ -46,14 +59,138 @@ return; } - if ( event.GetKeyCode() == WXK_ESCAPE ) { // clear by ESC + if ( kc == WXK_ESCAPE ) { // clear by ESC this->Clear(); return; } + // auto-complete + Cut(); + if ( kc >=48 && kc<=57 ) { // [0-9] + kc -= 48; + wxString input = GetValue() + wxString::Format( wxT("%d"), kc ); + if ( input.Len() < 5 ) { + event.Skip(); + return; + } + for ( unsigned int i = 0; i < m_jhhsno.GetCount(); i++ ) { + if ( m_jhhsno[i].StartsWith( input ) ) { + ChangeValue( m_jhhsno[i] ); + SetSelection( input.Len(), 10 ); + + wxArrayString s = wxSplit( GetHhsInfoByHhsNo( m_jhhsno[i] ), '_', '\\' ); + wxString msg = wxT("もしかして... ") + s[0] + wxT(" ?!"); + SetMessage( msg ); + return; + } + SetMessage( wxEmptyString ); + } + event.Skip(); + return; + } event.Skip(); } +/////////////////////////////////////////////////////////////// +// サムネイルパネル +#define THUMB_W 60 +#define THUMB_H 75 +ThumbnailPanel::ThumbnailPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) + : wxPanel( parent, id, pos, size, style ) +{ + wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL ); + this->SetBackgroundColour( wxColour( 192, 192, 192 ) ); + + wxString thumb = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("thumbnail.png"); + wxBitmap bmp = wxBitmap( thumb, wxBITMAP_TYPE_PNG ); + + m_bitmap0 = new wxStaticBitmap( this, ID_THBMP0, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap0, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap0->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick0 ), NULL, this ); + + m_bitmap1 = new wxStaticBitmap( this, ID_THBMP1, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap1->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick1 ), NULL, this ); + + m_bitmap2 = new wxStaticBitmap( this, ID_THBMP2, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap2->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick2 ), NULL, this ); + + m_bitmap3 = new wxStaticBitmap( this, ID_THBMP3, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap3->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick3 ), NULL, this ); + + m_bitmap4 = new wxStaticBitmap( this, ID_THBMP4, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap4, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap4->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick4 ), NULL, this ); + + m_bitmap5 = new wxStaticBitmap( this, ID_THBMP5, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); + bSizer->Add( m_bitmap5, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + m_bitmap5->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick5 ), NULL, this ); + + this->SetSizer( bSizer ); + this->Layout(); +} + +ThumbnailPanel::~ThumbnailPanel() +{ + m_bitmap0->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick0 ), NULL, this ); + m_bitmap1->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick1 ), NULL, this ); + m_bitmap2->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick2 ), NULL, this ); + m_bitmap3->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick3 ), NULL, this ); + m_bitmap4->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick4 ), NULL, this ); + m_bitmap5->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( ThumbnailPanel::OnDClick5 ), NULL, this ); +} + +// Functions +/* サムネイル表示 */ +void ThumbnailPanel::SetImages( wxString dirpath ) +{ + wxDir dir( dirpath ); + if ( !dir.IsOpened() ) return; + m_imagefiles.Clear(); + wxDir::GetAllFiles( dirpath, &m_imagefiles, wxT("*.jpg"), wxDIR_FILES ); + + wxString cachedir = wxT("cache") + dirpath.AfterLast( ':' ); + wxDir cdir( cachedir ); + if ( !cdir.IsOpened() ) return; + + wxArrayString cachefiles; + wxDir::GetAllFiles( cachedir, &cachefiles, wxT("*.png"), wxDIR_FILES ); + + wxString thumb = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("thumbnail.png"); + int n = cachefiles.GetCount(); + if ( n < 6 ) { + while ( n < 6 ) { + cachefiles.Add( thumb ); + n++; + } + } + + wxBitmap bmp; + bmp.LoadFile( cachefiles[0], wxBITMAP_TYPE_PNG ); m_bitmap0->SetBitmap( bmp ); + bmp.LoadFile( cachefiles[1], wxBITMAP_TYPE_PNG ); m_bitmap1->SetBitmap( bmp ); + bmp.LoadFile( cachefiles[2], wxBITMAP_TYPE_PNG ); m_bitmap2->SetBitmap( bmp ); + bmp.LoadFile( cachefiles[3], wxBITMAP_TYPE_PNG ); m_bitmap3->SetBitmap( bmp ); + bmp.LoadFile( cachefiles[4], wxBITMAP_TYPE_PNG ); m_bitmap4->SetBitmap( bmp ); + bmp.LoadFile( cachefiles[5], wxBITMAP_TYPE_PNG ); m_bitmap5->SetBitmap( bmp ); +} +/* 画像クリックで拡大表示 */ +void ThumbnailPanel::OnDClick0( wxMouseEvent& WXUNUSED(event) ) { Preview( 0 ); } +void ThumbnailPanel::OnDClick1( wxMouseEvent& WXUNUSED(event) ) { Preview( 1 ); } +void ThumbnailPanel::OnDClick2( wxMouseEvent& WXUNUSED(event) ) { Preview( 2 ); } +void ThumbnailPanel::OnDClick3( wxMouseEvent& WXUNUSED(event) ) { Preview( 3 ); } +void ThumbnailPanel::OnDClick4( wxMouseEvent& WXUNUSED(event) ) { Preview( 4 ); } +void ThumbnailPanel::OnDClick5( wxMouseEvent& WXUNUSED(event) ) { Preview( 5 ); } +void ThumbnailPanel::Preview( int n ) +{ + if ( m_imagefiles.GetCount() < n ) return; + + PreviewDialog* pd = new PreviewDialog( this, wxID_ANY, wxT("プレビュー"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxFRAME_NO_TASKBAR ); + pd->Show(); + pd->Maximize( true ); + pd->SetImage( m_imagefiles[n] ); +} /////////////////////////////////////////////////////////////// // メインフレーム @@ -70,9 +207,8 @@ : wxFrame( parent, id, title, pos, size, style ) { this->SetSizeHints( wxSize( WINL_W, 500 ), wxDefaultSize ); - this->SetMinSize( wxSize( WINL_W, 500 ) ); - this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) ); - //this->SetBackgroundColour( wxColour(wxT("WHEAT")) ); + //this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) ); + this->SetBackgroundColour( wxColour(wxT("WHEAT")) ); // set the frame icon SetIcon(wxICON(sample)); @@ -89,11 +225,6 @@ m_menuFile->AppendSeparator(); // ---- - wxMenuItem* m_menuItemViewStyle = new wxMenuItem( m_menuFile, ID_MNVIEW, wxString( wxT("ビュースタイル\tF10") ) , wxT("Toggle ViewStyle"), wxITEM_CHECK ); - m_menuFile->Append( m_menuItemViewStyle ); - - m_menuFile->AppendSeparator(); // ---- - wxMenuItem* m_menuItemBkup = new wxMenuItem( m_menuFile, ID_MNDBBKUP, wxString( wxT("DBバックアップ(&B)") ) , wxT("Backup databases"), wxITEM_NORMAL ); m_menuFile->Append( m_menuItemBkup ); @@ -123,12 +254,10 @@ // wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); - m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D ); + m_panelMain = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + wxBoxSizer* bSizerMain = new wxBoxSizer( wxVERTICAL ); - // left-pane - m_panelMain = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png"); wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG ); m_bitmap = new wxStaticBitmap( m_panelMain, wxID_ANY, bmp, wxDefaultPosition, wxSize( LOGO_W, LOGO_H ), 0 ); @@ -151,14 +280,19 @@ itemCol.SetText( wxT("場所") ); m_listCtrl->InsertColumn( 2, itemCol ); m_listCtrl->SetColumnWidth( 2, 300 ); - bSizerMain->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 ); + bSizerMain->Add( m_listCtrl, 1, wxRIGHT|wxLEFT|wxBOTTOM|wxEXPAND, 5 ); + + m_thumbPanel = new ThumbnailPanel( m_panelMain, wxID_ANY, wxDefaultPosition, wxSize( -1, 100 ), wxSUNKEN_BORDER ); + bSizerMain->Add( m_thumbPanel, 0, wxRIGHT|wxLEFT|wxBOTTOM|wxEXPAND, 5 ); + // wxBoxSizer* bSizerCmd = new wxBoxSizer( wxHORIZONTAL ); m_staticText = new wxStaticText( m_panelMain, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_searchBox = new MySearchBox( m_panelMain, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + m_searchBox->SetJudgedHhs( GetJudgedHhsNo() ); #ifndef __WXMAC__ m_searchBox->ShowSearchButton( true ); #endif @@ -172,31 +306,15 @@ m_buttonHist = new wxButton( m_panelMain, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxSize( 65, -1 ), 0 ); bSizerCmd->Add( m_buttonHist, 0, wxALL, 5 ); + // bSizerMain->Add( bSizerCmd, 0, wxEXPAND, 5 ); m_panelMain->SetSizer( bSizerMain ); m_panelMain->Layout(); bSizerMain->Fit( m_panelMain ); - - // right-pane - m_panelView = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* bSizerView = new wxBoxSizer( wxHORIZONTAL ); + bSizerTop->Add( m_panelMain, 1, wxEXPAND|wxALL, 5 ); - m_bitmapView = new wxStaticBitmap( m_panelView, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); - bSizerView->Add( m_bitmapView, 1, wxALL|wxEXPAND, 5 ); - - m_listCtrlThumb = new wxListCtrl( m_panelView, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON ); - bSizerView->Add( m_listCtrlThumb, 0, wxALL|wxEXPAND, 5 ); - - m_panelView->SetSizer( bSizerView ); - m_panelView->Layout(); - bSizerView->Fit( m_panelView ); - - m_panelView->Show( false ); // - m_splitter->Initialize( m_panelMain ); - bSizerTop->Add( m_splitter, 1, wxEXPAND, 5 ); - this->SetSizer( bSizerTop ); this->Layout(); @@ -217,29 +335,34 @@ // Event Table BEGIN_EVENT_TABLE( MyFrame, wxFrame ) - EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) - EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) - EVT_MENU( ID_MNBPNT, MyFrame::OnBPrintMode ) - EVT_MENU( ID_MNVIEW, MyFrame::OnViewStyle ) - EVT_MENU( ID_MNINDEX, MyFrame::OnIndex ) - EVT_MENU( ID_MNDBBKUP, MyFrame::OnDBBackup ) + EVT_MENU( ID_MNABOUT, MyFrame::OnAbout ) + EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) + EVT_MENU( ID_MNBPNT, MyFrame::OnBPrintMode ) + EVT_MENU( ID_MNINDEX, MyFrame::OnIndex ) + EVT_MENU( ID_MNDBBKUP, MyFrame::OnDBBackup ) EVT_MENU( ID_MNMASKPARAM, MyFrame::OnMaskParam ) EVT_MENU( ID_MNMARKPARAM, MyFrame::OnMarkParam ) - EVT_MENU( ID_MNAPPDIR, MyFrame::OnOpenAppDir ) - EVT_LIST_ITEM_ACTIVATED( ID_LIST, MyFrame::OnSelectHhsDir ) + EVT_MENU( ID_MNAPPDIR, MyFrame::OnOpenAppDir ) + EVT_LIST_ITEM_SELECTED( ID_LIST, MyFrame::OnSelectItem ) + EVT_LIST_ITEM_ACTIVATED( ID_LIST, MyFrame::OnDClickItem ) EVT_BUTTON( ID_KANA, MyFrame::OnKana ) EVT_BUTTON( ID_HIST, MyFrame::OnHistory ) + EVT_TEXT_ENTER( ID_SEARCH, MyFrame::OnCommand ) EVT_SIZE( MyFrame::OnWinSize ) EVT_MOVE( MyFrame::OnWinMove ) EVT_CLOSE( MyFrame::SaveConfig ) - EVT_TEXT_ENTER( ID_SEARCH, MyFrame::OnCommand ) END_EVENT_TABLE() // Event Handlers & Functions /* エンターキーフック */ void MyFrame::OnCommand( wxCommandEvent& event ) { - wxString s = m_searchBox->GetValue(); + wxString s = m_searchBox->GetLineText(0); + + if ( s.IsSameAs( wxT(".") ) ) { + OpenAppDir(); + return; + } if ( s.IsSameAs( wxT("99") ) ) { Close(); @@ -255,6 +378,7 @@ if ( reHhs.Matches( s ) ) { m_hhsno = s; UpdateList( m_hhsno ); + UpdateThumbmail( 0 ); return; } @@ -331,12 +455,13 @@ config->Read( wxT("lmax"), &lmax ); config->Read( wxT("zmin"), &zmin ); config->Read( wxT("zmax"), &zmax ); + } /* 印刷 */ void MyFrame::PrintImages( wxString hhsno ) { bool mask_flag = false; - wxMessageDialog md( this, wxT("マクスしますか?"), wxT("印刷オプション"), wxYES_NO, wxDefaultPosition ); + wxMessageDialog md( this, wxT("マスクしますか?"), wxT("印刷オプション"), wxYES_NO, wxDefaultPosition ); if ( md.ShowModal() == wxID_YES ) { mask_flag = true; } @@ -526,29 +651,20 @@ /* アプリフォルダを開く */ void MyFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) ) { + OpenAppDir(); +} +void MyFrame::OpenAppDir( ) +{ wxString appdir = wxGetCwd(); wxString execmd = wxT("explorer ") + appdir; wxExecute( execmd ); } -/* ビューの切替え */ -void MyFrame::OnViewStyle( wxCommandEvent& event ) -{ - if ( event.IsChecked() ) { - int x, y; - GetSize( &x, &y ); - SetSize( WINL_W + 500, y ); - m_splitter->SplitVertically( m_panelMain, m_panelView, 0 ); - } - else { - m_splitter->Unsplit(); - SetSize( WINL_W, -1 ); - } -} /* 被保険者フォルダを開く */ -void MyFrame::OnSelectHhsDir( wxListEvent& event ) +void MyFrame::OnDClickItem( wxListEvent& event ) { int i = event.GetIndex(); OpenHhsDir( i ); + UpdateThumbmail( i ); } /* 番号で指定したフォルダを開く */ void MyFrame::OpenHhsDir( int n ) @@ -572,6 +688,7 @@ if ( kana->ShowModal() == wxID_OK ) { m_hhsno = kana->GetHhsNo(); UpdateList( m_hhsno ); + UpdateThumbmail( 0 ); } } /* 検索履歴検索ダイアログ */ @@ -583,6 +700,7 @@ if ( hist->ShowModal() == wxID_OK ) { m_hhsno = hist->GetHhsNo(); UpdateList( m_hhsno ); + UpdateThumbmail( 0 ); } } @@ -643,6 +761,23 @@ hist.Write(); hist.Close(); } +/* フォルダを選択したとき */ +void MyFrame::OnSelectItem( wxListEvent& event ) +{ + UpdateThumbmail( event.GetIndex() ); +} +/* サムネイルを更新 */ +void MyFrame::UpdateThumbmail( int n ) +{ + wxListItem item; + item.SetId( n ); + + item.SetColumn( 2 ); + item.SetMask( wxLIST_MASK_TEXT ); + m_listCtrl->GetItem( item ); + + m_thumbPanel->SetImages( item.GetText() ); +} /* ステータスバーにメッセージを出力 */ void MyFrame::SetStatusMessage( wxString msg, long n ) { @@ -686,6 +821,7 @@ if ( !IsIconized() && !IsMaximized() ) { wxGetApp().rect = this->GetRect(); } + delete config; Destroy(); } /* アバウトダイアログ */