diff src/dirview.cpp @ 38:044cc2f5af81 v2.4 v2.7

small fix.
author pyon@macmini
date Thu, 24 Nov 2011 22:26:15 +0900
parents 868ccd73e238
children ce5b61376fd0
line wrap: on
line diff
--- a/src/dirview.cpp	Fri Nov 18 20:46:12 2011 +0900
+++ b/src/dirview.cpp	Thu Nov 24 22:26:15 2011 +0900
@@ -1,41 +1,36 @@
-
 // Filename   : dirview.cpp
-// Last Change: 24-Oct-2011.
+// Last Change: 24-Nov-2011.
 //
 
 #include "dirview.h"
 
+#define THUMB_W 160
+#define THUMB_H 226
+
 // frame constructor
 DirViewFrame::DirViewFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
 {
-	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
     this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
 	
-	wxBoxSizer* bSizer;
-	bSizer = new wxBoxSizer( wxHORIZONTAL );
+	wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
 	
-	m_listCtrlAll = new wxListCtrl( this, ID_LISTCTRLALL, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
-    itemCol.SetText( wxT("$BDLHV(B") );
-    m_listCtrlAll->InsertColumn( 0, itemCol );
-    m_listCtrlAll->SetColumnWidth( 0, 100 );
-    itemCol.SetText( wxT("$BHoJ]81<THV9f(B") );
-    m_listCtrlAll->InsertColumn( 1, itemCol );
-    m_listCtrlAll->SetColumnWidth( 1, 180 );
-    itemCol.SetText( wxT("$B%U%!%$%k?t(B") );
-    m_listCtrlAll->InsertColumn( 2, itemCol );
-    m_listCtrlAll->SetColumnWidth( 1, 100 );
-	bSizer->Add( m_listCtrlAll, 0, wxALL|wxEXPAND, 5 );
+	m_listCtrl = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
+	bSizerTop->Add( m_listCtrl, 1, wxEXPAND|wxALL, 5 );
+
+	wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL );
+
+	m_buttonExplorer = new wxButton( this, ID_BUTTONEXPLR, wxT("フォルダオープン"), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerButton->Add( m_buttonExplorer, 1, wxALL, 5 );
+	m_buttonClose = new wxButton( this, ID_BUTTONCLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerButton->Add( m_buttonClose, 1, wxALL, 5 );
 	
-	m_listCtrlThumbnail = new wxListCtrl( this, ID_LISTCTRLTHUMB, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
-	bSizer->Add( m_listCtrlThumbnail, 0, wxALL|wxEXPAND, 5 );
-	
-	m_bitmapPreview = new wxStaticBitmap( this, ID_BITMAPPREVIEW, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
-	bSizer->Add( m_bitmapPreview, 1, wxALL|wxEXPAND, 5 );
-	
-	this->SetSizer( bSizer );
+	bSizerTop->Add( bSizerButton, 0, wxALL, 5 );
+
+	this->SetSizer( bSizerTop );
 	this->Layout();
 	
 	this->Centre( wxBOTH );
+    this->LoadListImage();
 }
 
 // destructor
@@ -44,59 +39,40 @@
 }
 
 // Event Table
-BEGIN_EVENT_TABLE( MyFrame, wxFrame )
-    EVT_LIST_ITEM_SELECTED( ID_LISTCTRLALL,   DirViewFrame::OnThumbnail )
-    EVT_LIST_ITEM_SELECTED( ID_LISTCTRLTHUMB, DirViewFrame::OnPreview   )
+BEGIN_EVENT_TABLE( DirViewFrame, wxFrame )
+    EVT_BUTTON( ID_BUTTONEXPLR, DirViewFrame::OnExplorer )
+    EVT_BUTTON( ID_BUTTONCLOSE, DirViewFrame::OnClose )
 END_EVENT_TABLE()
 
 // Event Handlers
-void DirViewFrame::OnThumbnail(wxListEvent& event)
+void DirViewFrame::OnExplorer(wxCommandEvent& WXUNUSED(event))
 {
-    m_listCtrlThumbnail->DeleteAllItems();
-    /*
-    m_imageList->RemoveAll();
-    wxDir dir(m_dir);
-    wxString filename;
-    if ( !dir.IsOpened() ) return;
-
-    bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );
-
-    int i=0;
-    wxListItem item;
-    while ( cout ) {
-        wxString f = m_dir + wxFILE_SEP_PATH + filename;
-        wxFile file( f );
-        long len = file.Length();
-        if ( !m_checkBox->IsChecked() && len > 150000 ) { 
-            cout = dir.GetNext( &filename );
-            continue;
-        }
-
-        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_listCtrl->InsertItem( item );
-        m_listCtrl->SetItem( item );
-
-        wxImage img( f, wxBITMAP_TYPE_JPEG );
-        wxBitmap bmp( img.Scale( 63, 89, wxIMAGE_QUALITY_HIGH ) );
-        m_imageList->Add( bmp );
-        cout = dir.GetNext( &filename );
-        i++;
-    }
-    */
-
-    return;
+    wxString execmd = wxT("explorer ") + m_dir; // hhsdir
+    //wxExecute( execmd );
+    wxMessageBox( execmd );
+    Close(true);
 } 
 
-void DirViewFrame::OnPreview(wxListEvent& event)
+void DirViewFrame::OnClose(wxCommandEvent& WXUNUSED(event))
 {
+    Close(true);
 }
 
 // Functions
-void DirViewFrame::ListAll(void)
+void DirViewFrame::LoadListImage()
 {
+    wxImageList* imageList = new wxImageList( THUMB_W, THUMB_H );
+    m_listCtrl->AssignImageList( imageList, wxIMAGE_LIST_NORMAL );
+
+    wxArrayString filenames;
+    unsigned int n = wxDir::GetAllFiles( m_dir, &filenames, wxT("*.jpg"), wxDIR_FILES );
+    for ( int i=0; i<n; i++ ) {
+        wxImage image( filenames[i], wxBITMAP_TYPE_JPEG );
+        wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH );
+        wxBitmap bmp( thumbnail );
+        imageList->Add( bmp );
+        m_listCtrl->InsertItem( i, filenames[i], i );
+        m_listCtrl->SetItem( i, 0, filenames[i], i );
+    }
 }
+