comparison 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
comparison
equal deleted inserted replaced
37:3b54f3deeed9 38:044cc2f5af81
1
2 // Filename : dirview.cpp 1 // Filename : dirview.cpp
3 // Last Change: 24-Oct-2011. 2 // Last Change: 24-Nov-2011.
4 // 3 //
5 4
6 #include "dirview.h" 5 #include "dirview.h"
7 6
7 #define THUMB_W 160
8 #define THUMB_H 226
9
8 // frame constructor 10 // frame constructor
9 DirViewFrame::DirViewFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) 11 DirViewFrame::DirViewFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
10 { 12 {
11 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
12 this->SetBackgroundColour( wxColour(wxT("WHEAT")) ); 13 this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
13 14
14 wxBoxSizer* bSizer; 15 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
15 bSizer = new wxBoxSizer( wxHORIZONTAL );
16 16
17 m_listCtrlAll = new wxListCtrl( this, ID_LISTCTRLALL, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL ); 17 m_listCtrl = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
18 itemCol.SetText( wxT("$BDLHV(B") ); 18 bSizerTop->Add( m_listCtrl, 1, wxEXPAND|wxALL, 5 );
19 m_listCtrlAll->InsertColumn( 0, itemCol ); 19
20 m_listCtrlAll->SetColumnWidth( 0, 100 ); 20 wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL );
21 itemCol.SetText( wxT("$BHoJ]81<THV9f(B") ); 21
22 m_listCtrlAll->InsertColumn( 1, itemCol ); 22 m_buttonExplorer = new wxButton( this, ID_BUTTONEXPLR, wxT("フォルダオープン"), wxDefaultPosition, wxDefaultSize, 0 );
23 m_listCtrlAll->SetColumnWidth( 1, 180 ); 23 bSizerButton->Add( m_buttonExplorer, 1, wxALL, 5 );
24 itemCol.SetText( wxT("$B%U%!%$%k?t(B") ); 24 m_buttonClose = new wxButton( this, ID_BUTTONCLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
25 m_listCtrlAll->InsertColumn( 2, itemCol ); 25 bSizerButton->Add( m_buttonClose, 1, wxALL, 5 );
26 m_listCtrlAll->SetColumnWidth( 1, 100 );
27 bSizer->Add( m_listCtrlAll, 0, wxALL|wxEXPAND, 5 );
28 26
29 m_listCtrlThumbnail = new wxListCtrl( this, ID_LISTCTRLTHUMB, wxDefaultPosition, wxDefaultSize, wxLC_ICON ); 27 bSizerTop->Add( bSizerButton, 0, wxALL, 5 );
30 bSizer->Add( m_listCtrlThumbnail, 0, wxALL|wxEXPAND, 5 ); 28
31 29 this->SetSizer( bSizerTop );
32 m_bitmapPreview = new wxStaticBitmap( this, ID_BITMAPPREVIEW, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
33 bSizer->Add( m_bitmapPreview, 1, wxALL|wxEXPAND, 5 );
34
35 this->SetSizer( bSizer );
36 this->Layout(); 30 this->Layout();
37 31
38 this->Centre( wxBOTH ); 32 this->Centre( wxBOTH );
33 this->LoadListImage();
39 } 34 }
40 35
41 // destructor 36 // destructor
42 DirViewFrame::~DirViewFrame() 37 DirViewFrame::~DirViewFrame()
43 { 38 {
44 } 39 }
45 40
46 // Event Table 41 // Event Table
47 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) 42 BEGIN_EVENT_TABLE( DirViewFrame, wxFrame )
48 EVT_LIST_ITEM_SELECTED( ID_LISTCTRLALL, DirViewFrame::OnThumbnail ) 43 EVT_BUTTON( ID_BUTTONEXPLR, DirViewFrame::OnExplorer )
49 EVT_LIST_ITEM_SELECTED( ID_LISTCTRLTHUMB, DirViewFrame::OnPreview ) 44 EVT_BUTTON( ID_BUTTONCLOSE, DirViewFrame::OnClose )
50 END_EVENT_TABLE() 45 END_EVENT_TABLE()
51 46
52 // Event Handlers 47 // Event Handlers
53 void DirViewFrame::OnThumbnail(wxListEvent& event) 48 void DirViewFrame::OnExplorer(wxCommandEvent& WXUNUSED(event))
54 { 49 {
55 m_listCtrlThumbnail->DeleteAllItems(); 50 wxString execmd = wxT("explorer ") + m_dir; // hhsdir
56 /* 51 //wxExecute( execmd );
57 m_imageList->RemoveAll(); 52 wxMessageBox( execmd );
58 wxDir dir(m_dir); 53 Close(true);
59 wxString filename;
60 if ( !dir.IsOpened() ) return;
61
62 bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );
63
64 int i=0;
65 wxListItem item;
66 while ( cout ) {
67 wxString f = m_dir + wxFILE_SEP_PATH + filename;
68 wxFile file( f );
69 long len = file.Length();
70 if ( !m_checkBox->IsChecked() && len > 150000 ) {
71 cout = dir.GetNext( &filename );
72 continue;
73 }
74
75 item.SetId(i);
76 item.SetMask(wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
77 item.SetStateMask(wxLIST_STATE_SELECTED);
78 item.SetState(wxLIST_STATE_SELECTED);
79 item.SetImage(i);
80 item.SetText(filename);
81 m_listCtrl->InsertItem( item );
82 m_listCtrl->SetItem( item );
83
84 wxImage img( f, wxBITMAP_TYPE_JPEG );
85 wxBitmap bmp( img.Scale( 63, 89, wxIMAGE_QUALITY_HIGH ) );
86 m_imageList->Add( bmp );
87 cout = dir.GetNext( &filename );
88 i++;
89 }
90 */
91
92 return;
93 } 54 }
94 55
95 void DirViewFrame::OnPreview(wxListEvent& event) 56 void DirViewFrame::OnClose(wxCommandEvent& WXUNUSED(event))
96 { 57 {
58 Close(true);
97 } 59 }
98 60
99 // Functions 61 // Functions
100 void DirViewFrame::ListAll(void) 62 void DirViewFrame::LoadListImage()
101 { 63 {
64 wxImageList* imageList = new wxImageList( THUMB_W, THUMB_H );
65 m_listCtrl->AssignImageList( imageList, wxIMAGE_LIST_NORMAL );
66
67 wxArrayString filenames;
68 unsigned int n = wxDir::GetAllFiles( m_dir, &filenames, wxT("*.jpg"), wxDIR_FILES );
69 for ( int i=0; i<n; i++ ) {
70 wxImage image( filenames[i], wxBITMAP_TYPE_JPEG );
71 wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH );
72 wxBitmap bmp( thumbnail );
73 imageList->Add( bmp );
74 m_listCtrl->InsertItem( i, filenames[i], i );
75 m_listCtrl->SetItem( i, 0, filenames[i], i );
76 }
102 } 77 }
78