Mercurial > mercurial > hgweb_mover2.cgi
diff src/myframe.cpp @ 0:7bf900d47e9e
start mover2
author | pyon@macmini |
---|---|
date | Sat, 15 Oct 2011 13:24:27 +0900 |
parents | |
children | b47bd4618c16 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/myframe.cpp Sat Oct 15 13:24:27 2011 +0900 @@ -0,0 +1,330 @@ +// Filename : myframe.cpp +// Last Change: 15-Oct-2011. +// + +#include "main.h" +#include "myframe.h" + +////////////////////////////////////////////////////////////////////////// +// frame constructor +MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) +{ + this->SetBackgroundColour( wxColour(wxT("WHEAT")) ); + // set the frame icon + //SetIcon(wxICON(sample)); + + // メニューバー + m_menubarFile = new wxMenuBar(); + m_menuFile = new wxMenu(); + wxMenuItem* m_menuItemParam; + m_menuItemParam = new wxMenuItem( m_menuFile, ID_MENUITEMPARAM, wxString( wxT("パラメータ(&P)") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemParam ); + + wxMenuItem* m_menuItemAppDIr; + m_menuItemAppDIr = new wxMenuItem( m_menuFile, ID_MENUITEMAPPDIR, wxString( wxT("アプリフォルダを開く(&O)") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemAppDIr ); + + wxMenuItem* m_separator; + m_separator = m_menuFile->AppendSeparator(); // ---- + + wxMenuItem* m_menuItemQuit; + m_menuItemQuit = new wxMenuItem( m_menuFile, ID_MENUITEMQUIT, wxString( wxT("終了(&X)") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuFile->Append( m_menuItemQuit ); + + m_menubarFile->Append( m_menuFile, wxT("ファイル(&F)") ); + + this->SetMenuBar( m_menubarFile ); + + // コントロール + wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizerFrom = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextWork = new wxStaticText( this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerFrom->Add( m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_dirPickerWork = new wxDirPickerCtrl( this, wxID_ANY, wxGetApp().workdir, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE ); + bSizerFrom->Add( m_dirPickerWork, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerFrom, 0, wxEXPAND, 5 ); + + wxBoxSizer* bSizerCcn = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextDrive = new wxStaticText( this, wxID_ANY, wxT("ドライブ"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerCcn->Add( m_staticTextDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + wxArrayString drives; + drives.Add(wxT("C:")); + drives.Add(wxT("Y:")); + drives.Add(wxT("Z:")); + m_comboBoxDrive = new wxComboBox( this, wxID_ANY, wxT("C:"), wxDefaultPosition, wxSize(50,-1), drives, 0 ); + bSizerCcn->Add( m_comboBoxDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT("開催日"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerCcn->Add( m_staticTextDate, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN ); + bSizerCcn->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT("合議体"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerCcn->Add( m_staticTextCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + wxArrayString ccns; + ccns.Add(wxT("角館1")); ccns.Add(wxT("角館2")); ccns.Add(wxT("角館3")); ccns.Add(wxT("角館4")); + ccns.Add(wxT("西仙1")); ccns.Add(wxT("西仙2")); ccns.Add(wxT("西仙3")); + ccns.Add(wxT("千畑1")); ccns.Add(wxT("千畑2")); ccns.Add(wxT("千畑3")); + ccns.Add(wxT("大曲1")); ccns.Add(wxT("大曲2")); ccns.Add(wxT("大曲3")); ccns.Add(wxT("大曲4")); ccns.Add(wxT("大曲5")); ccns.Add(wxT("大曲6")); + ccns.Add(wxT("六郷1")); ccns.Add(wxT("六郷2")); ccns.Add(wxT("六郷3")); + m_comboBoxCcn = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100,-1), ccns, 0 ); + bSizerCcn->Add( m_comboBoxCcn, 0, wxALL, 5 ); + + m_buttonMkDir = new wxButton( this, ID_BUTTONMKDIR, wxT("適用"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerCcn->Add( m_buttonMkDir, 0, wxALL, 5 ); + + bSizerTop->Add( bSizerCcn, 0, wxEXPAND, 5 ); + + wxBoxSizer* bSizerDist = new wxBoxSizer( wxHORIZONTAL ); + + m_staticTextDist = new wxStaticText( this, wxID_ANY, wxT("保存フォルダ"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerDist->Add( m_staticTextDist, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_textCtrlDist = new wxTextCtrl( this, ID_TEXTCTRLDIST, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrlDist->SetMaxLength( 15 ); + bSizerDist->Add( m_textCtrlDist, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerDist->Add( 0, 0, 1, wxEXPAND, 5 ); + + bSizerTop->Add( bSizerDist, 0, wxEXPAND, 5 ); + + wxBoxSizer* bSizerManip = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* bSizerGuess = new wxBoxSizer( wxVERTICAL ); + + m_staticTextName = new wxStaticText( this, wxID_ANY, wxT("氏名"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGuess->Add( m_staticTextName, 0, wxALL, 5 ); + m_bitmapName = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGuess->Add( m_bitmapName, 0, wxALL, 5 ); + + m_staticTextHhsno = new wxStaticText( this, wxID_ANY, wxT("被保険者番号"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGuess->Add( m_staticTextHhsno, 0, wxALL, 5 ); + m_bitmapHHsno = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGuess->Add( m_bitmapHHsno, 0, wxALL, 5 ); + + m_staticTextGuess = new wxStaticText( this, wxID_ANY, wxT("推定値"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerGuess->Add( m_staticTextGuess, 0, wxALL, 5 ); + m_textCtrlGuess = new wxTextCtrl( this, ID_TEXTCTRLGUESS, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrlGuess->SetMaxLength( 10 ); + bSizerGuess->Add( m_textCtrlGuess, 0, wxALL, 5 ); + + bSizerManip->Add( bSizerGuess, 0, wxEXPAND, 5 ); + + m_listCtrlView = new wxListCtrl( this, ID_LISTCTRLVIEW, wxDefaultPosition, wxDefaultSize, wxLC_ICON ); + bSizerManip->Add( m_listCtrlView, 1, wxALL|wxEXPAND, 5 ); + m_imageList = new wxImageList( 63, 89 ); + m_listCtrlView->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL ); + + wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL ); + + m_buttonMove = new wxButton( this, ID_BUTTONMOVE, wxT("移動"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonMove, 0, wxALL, 5 ); + m_buttonDel = new wxButton( this, ID_BUTTONDEL, wxT("削除"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonDel, 0, wxALL, 5 ); + m_buttonUndo = new wxButton( this, ID_BUTTONUNDO, wxT("戻す"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonUndo, 0, wxALL, 5 ); + + bSizerManip->Add( bSizerButton, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 ); + + this->SetSizer( bSizerTop ); + this->Layout(); + + // ステータスバー + int widths[] = { -1, 150, 120, 120 }; + m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP ); + m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); + m_statusBar->SetStatusText( wxEmptyString, 0 ); + + this->Centre( wxBOTH ); + + ReadyImage(); +} + +// destructor +MyFrame::~MyFrame() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( MyFrame, wxFrame ) + EVT_SIZE( MyFrame::OnSize ) + EVT_MOVE( MyFrame::OnMove ) + /* + EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) + EVT_MENU( wxID_ABOUT, MyFrame::OnAbout ) + EVT_MENU( ID_OPWORK, MyFrame::OnOpenWorkDir ) + EVT_BUTTON( ID_STDIR, MyFrame::SetDir ) + EVT_BUTTON( ID_MKDIR, MyFrame::MakeDir ) + EVT_BUTTON( ID_DOMOVE, MyFrame::MoveImages ) + EVT_LIST_ITEM_ACTIVATED( ID_LIST, MyFrame::OnOpenHhsDir ) + */ + EVT_CLOSE( MyFrame::SaveConfig ) +END_EVENT_TABLE() + +// Event Handlers +/* 移動先フォルダセット */ +void MyFrame::SetDir(wxCommandEvent& WXUNUSED(event)) +{ + wxString dir; + dir.Append( m_comboBoxDrive->GetValue() ); + dir.Append( wxFILE_SEP_PATH ); + wxDateTime dt = m_datePicker->GetValue(); + dir.Append( dt.Format(wxT("%Y%m%d")) ); + dir.Append( wxFILE_SEP_PATH ); + dir.Append( m_comboBoxCcn->GetValue() ); + m_textCtrlDist->SetValue( dir ); +} + +/* 移動先フォルダ作成 */ +void MyFrame::MakeDir(wxCommandEvent& WXUNUSED(event)) +{ + wxString distdir = m_textCtrlDist->GetValue(); + wxString ccn = m_comboBoxCcn->GetValue(); + if ( distdir.Len() < 15 || ccn.IsEmpty() ) { + wxMessageBox(wxT("フォルダを指定してください.")); + return; + } + + wxStringTokenizer tkz( distdir, wxFILE_SEP_PATH ); + wxString d; + while ( tkz.HasMoreTokens() ) { + d.Append( tkz.GetNextToken() ); + d.Append( wxFILE_SEP_PATH ); + if ( !wxDirExists( d ) ) wxMkdir( d ); + } + + wxMessageBox(wxT("移動先フォルダ準備完了")); + wxString cmd = wxT("explorer ") + distdir; + wxExecute( cmd ); +} + +void MyFrame::Do(wxCommandEvent& WXUNUSED(event)) +{ + MoveImage(); + ReadyImage(); +} + +/* 画像をリストコントロールに表示 */ +void MyFrame::ReadyImage() +{ + wxString workdir = m_dirPickerWork->GetPath(); + wxDir dir( workdir ); + if ( !dir.IsOpened() ) return; + + wxString filename; + bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES ); + + int i = 0; + m_listCtrlView->DeleteAllItems(); + m_imageList->RemoveAll(); + wxListItem item; + while ( cout ) { + if ( i > 7 ) break; + + wxString imagefile = workdir + wxFILE_SEP_PATH + filename; + if ( i > 1 && IsMarksheet() ) cout = false; + + item.SetId(i); + item.SetMask(wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE); + item.SetStateMask(wxLIST_STATE_SELECTED); + item.SetState(wxLIST_STATE_SELECTED); + item.SetImage(i); + item.SetText(filename); + m_listCtrlView->InsertItem( item ); + m_listCtrlView->SetItem( item ); + + wxImage img( imagefile, wxBITMAP_TYPE_JPEG ); + wxBitmap bmp( img.Scale( 63, 89, wxIMAGE_QUALITY_HIGH ) ); + m_imageList->Add( bmp ); + // write log + i++; + cout = dir.GetNext( &filename ); + } + /* + wxImage img_org( s, wxBITMAP_TYPE_JPEG ); + wxImage img_name; + img_name = img_org.GetSubImage( wxRect( wxPoint(328,556), wxSize(626,288) ) ); + img_name = img_name.Scale( 200, 92 ); + */ +} + +/* 画像移動 */ +void MyFrame::MoveImage() +{ + wxString distdir = m_textCtrlDist->GetValue(); + wxString ccn = m_comboBoxCcn->GetValue(); + if ( distdir.IsEmpty() || ccn.IsEmpty() ) { + wxMessageBox(wxT("フォルダを指定してください.")); + return; + } + + distdir.Append( wxFILE_SEP_PATH ); + if ( !wxDirExists( distdir ) ) { + wxMessageBox(wxT("フォルダが存在しません.")); + return; + } + + /* + wxString to = distdir + wxFILE_SEP_PATH + hhs + wxFILE_SEP_PATH + filename; + wxRenameFile( from, to, false ); + */ +} + +// 以下,定型もの +/* アプリフォルダを開く */ +void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event)) +{ + wxString appdir = m_dirPickerWork->GetPath(); + wxString execmd = wxT("explorer ") + appdir; + wxExecute( execmd ); +} + +/* サイズ変更 */ +void MyFrame::OnSize(wxSizeEvent& event) +{ + this->Refresh( true, NULL ); + TellLocation(); + event.Skip(); +} +/* ウィンドウ移動 */ +void MyFrame::OnMove(wxMoveEvent& WXUNUSED(event)) +{ + TellLocation(); + return; +} +/* ウィンドウ位置とサイズを表示 */ +void MyFrame::TellLocation( void ) +{ + wxRect r = this->GetRect(); + int x = r.GetX(); + int y = r.GetY(); + int w = r.GetWidth(); + int h = r.GetHeight(); + SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 2 ); +} +/* 終了 */ +void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) +{ + Close(true); +} +/* 設定を保存 */ +void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event)) +{ + if ( !IsIconized() && !IsMaximized() ) { + wxGetApp().rect = this->GetRect(); + } + wxGetApp().workdir = m_dirPickerWork->GetPath(); + + Destroy(); +} +