view src/dirview.cpp @ 39:e0ebc6a4c4dc v2.7

Added tag v2.7 for changeset 044cc2f5af81
author pyon@macmini
date Fri, 25 Nov 2011 22:08:10 +0900
parents 044cc2f5af81
children ce5b61376fd0
line wrap: on
line source

// Filename   : dirview.cpp
// 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->SetBackgroundColour( wxColour(wxT("WHEAT")) );
	
	wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
	
	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 );
	
	bSizerTop->Add( bSizerButton, 0, wxALL, 5 );

	this->SetSizer( bSizerTop );
	this->Layout();
	
	this->Centre( wxBOTH );
    this->LoadListImage();
}

// destructor
DirViewFrame::~DirViewFrame()
{
}

// Event Table
BEGIN_EVENT_TABLE( DirViewFrame, wxFrame )
    EVT_BUTTON( ID_BUTTONEXPLR, DirViewFrame::OnExplorer )
    EVT_BUTTON( ID_BUTTONCLOSE, DirViewFrame::OnClose )
END_EVENT_TABLE()

// Event Handlers
void DirViewFrame::OnExplorer(wxCommandEvent& WXUNUSED(event))
{
    wxString execmd = wxT("explorer ") + m_dir; // hhsdir
    //wxExecute( execmd );
    wxMessageBox( execmd );
    Close(true);
} 

void DirViewFrame::OnClose(wxCommandEvent& WXUNUSED(event))
{
    Close(true);
}

// Functions
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 );
    }
}