2006-10-05 10:20:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Program: wxWidgets Widgets Sample
|
|
|
|
// Name: dirctrl.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxGenericDirCtrl
|
|
|
|
// Author: Wlodzimierz 'ABX' Skiba
|
|
|
|
// Created: 4 Oct 2006
|
|
|
|
// Copyright: (c) 2006 wxWindows team
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2006-10-05 10:20:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_DIRDLG
|
|
|
|
|
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
2006-10-05 12:11:12 +00:00
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/log.h"
|
2006-10-05 10:20:32 +00:00
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/statbox.h"
|
|
|
|
#include "wx/radiobox.h"
|
|
|
|
#include "wx/checkbox.h"
|
|
|
|
#include "wx/button.h"
|
2007-05-28 02:31:54 +00:00
|
|
|
#include "wx/filedlg.h"
|
2006-10-05 10:20:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/generic/dirctrlg.h"
|
|
|
|
|
|
|
|
#include "wx/wupdlock.h"
|
|
|
|
#include "wx/stdpaths.h"
|
2012-10-29 18:30:14 +00:00
|
|
|
#include "wx/filename.h"
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
#include "widgets.h"
|
|
|
|
|
|
|
|
#include "icons/dirctrl.xpm"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// control ids
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DirCtrlPage_Reset = wxID_HIGHEST,
|
|
|
|
DirCtrlPage_SetPath,
|
|
|
|
DirCtrlPage_Ctrl
|
|
|
|
};
|
|
|
|
|
|
|
|
static const wxString stdPaths[] =
|
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
wxT("&none"),
|
|
|
|
wxT("&config"),
|
|
|
|
wxT("&data"),
|
|
|
|
wxT("&documents"),
|
|
|
|
wxT("&local data"),
|
|
|
|
wxT("&plugins"),
|
|
|
|
wxT("&resources"),
|
|
|
|
wxT("&user config"),
|
|
|
|
wxT("&user data"),
|
|
|
|
wxT("&user local data")
|
2006-10-05 10:20:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
stdPathUnknown = 0,
|
|
|
|
stdPathConfig,
|
|
|
|
stdPathData,
|
|
|
|
stdPathDocuments,
|
|
|
|
stdPathLocalData,
|
|
|
|
stdPathPlugins,
|
|
|
|
stdPathResources,
|
|
|
|
stdPathUserConfig,
|
|
|
|
stdPathUserData,
|
|
|
|
stdPathUserLocalData,
|
|
|
|
stdPathMax
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// CheckBoxWidgetsPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class DirCtrlWidgetsPage : public WidgetsPage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DirCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
|
|
|
virtual ~DirCtrlWidgetsPage() {}
|
|
|
|
|
2015-07-31 15:53:55 +00:00
|
|
|
virtual wxWindow *GetWidget() const wxOVERRIDE { return m_dirCtrl; }
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void RecreateWidget() wxOVERRIDE { CreateDirCtrl(); }
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
// lazy creation of the content
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void CreateContent() wxOVERRIDE;
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
void OnButtonSetPath(wxCommandEvent& event);
|
|
|
|
void OnButtonReset(wxCommandEvent& event);
|
|
|
|
void OnStdPath(wxCommandEvent& event);
|
|
|
|
void OnCheckBox(wxCommandEvent& event);
|
|
|
|
void OnRadioBox(wxCommandEvent& event);
|
2012-11-01 17:15:08 +00:00
|
|
|
void OnSelChanged(wxTreeEvent& event);
|
2013-05-16 14:33:07 +00:00
|
|
|
void OnFileActivated(wxTreeEvent& event);
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
// reset the control parameters
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// (re)create the m_dirCtrl
|
|
|
|
void CreateDirCtrl();
|
|
|
|
|
|
|
|
// the controls
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// the control itself and the sizer it is in
|
|
|
|
wxGenericDirCtrl *m_dirCtrl;
|
|
|
|
|
|
|
|
// the text entries for command parameters
|
|
|
|
wxTextCtrl *m_path;
|
|
|
|
|
|
|
|
wxRadioBox *m_radioStdPath;
|
|
|
|
|
|
|
|
// flags
|
|
|
|
wxCheckBox *m_chkDirOnly,
|
|
|
|
*m_chk3D,
|
|
|
|
*m_chkFirst,
|
2013-03-09 15:07:49 +00:00
|
|
|
*m_chkFilters,
|
2009-06-06 14:00:51 +00:00
|
|
|
*m_chkLabels,
|
|
|
|
*m_chkMulti;
|
|
|
|
|
2007-05-24 00:14:59 +00:00
|
|
|
// filters
|
|
|
|
wxCheckBox *m_fltr[3];
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2006-10-05 10:20:32 +00:00
|
|
|
DECLARE_WIDGETS_PAGE(DirCtrlWidgetsPage)
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(DirCtrlWidgetsPage, WidgetsPage)
|
2006-10-05 10:20:32 +00:00
|
|
|
EVT_BUTTON(DirCtrlPage_Reset, DirCtrlWidgetsPage::OnButtonReset)
|
|
|
|
EVT_BUTTON(DirCtrlPage_SetPath, DirCtrlWidgetsPage::OnButtonSetPath)
|
|
|
|
EVT_CHECKBOX(wxID_ANY, DirCtrlWidgetsPage::OnCheckBox)
|
|
|
|
EVT_RADIOBOX(wxID_ANY, DirCtrlWidgetsPage::OnRadioBox)
|
2013-05-16 14:33:01 +00:00
|
|
|
EVT_DIRCTRL_SELECTIONCHANGED(DirCtrlPage_Ctrl, DirCtrlWidgetsPage::OnSelChanged)
|
2013-05-16 14:33:07 +00:00
|
|
|
EVT_DIRCTRL_FILEACTIVATED(DirCtrlPage_Ctrl, DirCtrlWidgetsPage::OnFileActivated)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-10-05 10:20:32 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
IMPLEMENT_WIDGETS_PAGE(DirCtrlWidgetsPage, wxT("DirCtrl"),
|
|
|
|
GENERIC_CTRLS
|
|
|
|
);
|
|
|
|
|
|
|
|
DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl *book,
|
|
|
|
wxImageList *imaglist)
|
|
|
|
:WidgetsPage(book, imaglist, dirctrl_xpm)
|
|
|
|
{
|
2012-11-01 17:15:08 +00:00
|
|
|
m_dirCtrl = NULL;
|
2006-10-05 10:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::CreateContent()
|
|
|
|
{
|
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
// left pane
|
|
|
|
wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Dir control details"));
|
|
|
|
|
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
|
|
|
sizerLeft->Add( CreateSizerWithTextAndButton( DirCtrlPage_SetPath , wxT("Set &path"), wxID_ANY, &m_path ),
|
|
|
|
0, wxALL | wxALIGN_RIGHT , 5 );
|
|
|
|
|
|
|
|
wxSizer *sizerUseFlags =
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Flags"));
|
|
|
|
m_chkDirOnly = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_DIR_ONLY"));
|
|
|
|
m_chk3D = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_3D_INTERNAL"));
|
|
|
|
m_chkFirst = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_SELECT_FIRST"));
|
2013-03-09 15:07:49 +00:00
|
|
|
m_chkFilters = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_SHOW_FILTERS"));
|
2009-07-23 20:30:22 +00:00
|
|
|
m_chkLabels = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_EDIT_LABELS"));
|
|
|
|
m_chkMulti = CreateCheckBoxAndAddToSizer(sizerUseFlags, wxT("wxDIRCTRL_MULTIPLE"));
|
2006-10-05 10:20:32 +00:00
|
|
|
sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border());
|
|
|
|
|
2007-05-24 00:14:59 +00:00
|
|
|
wxSizer *sizerFilters =
|
2009-07-23 20:30:22 +00:00
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Filters"));
|
2007-05-24 00:14:59 +00:00
|
|
|
m_fltr[0] = CreateCheckBoxAndAddToSizer(sizerFilters, wxString::Format(wxT("all files (%s)|%s"),
|
|
|
|
wxFileSelectorDefaultWildcardStr, wxFileSelectorDefaultWildcardStr));
|
|
|
|
m_fltr[1] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h"));
|
|
|
|
m_fltr[2] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("PNG images (*.png)|*.png"));
|
|
|
|
sizerLeft->Add(sizerFilters, wxSizerFlags().Expand().Border());
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wxButton *btn = new wxButton(this, DirCtrlPage_Reset, wxT("&Reset"));
|
2006-10-05 10:20:32 +00:00
|
|
|
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
|
|
|
|
|
|
|
// keep consistency between enum and labels of radiobox
|
|
|
|
wxCOMPILE_TIME_ASSERT( stdPathMax == WXSIZEOF(stdPaths), EnumForRadioBoxMismatch);
|
|
|
|
|
|
|
|
// middle pane
|
2009-07-23 20:30:22 +00:00
|
|
|
m_radioStdPath = new wxRadioBox(this, wxID_ANY, wxT("Standard path"),
|
2006-10-05 10:20:32 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(stdPaths), stdPaths, 1);
|
|
|
|
|
|
|
|
// right pane
|
|
|
|
m_dirCtrl = new wxGenericDirCtrl(
|
|
|
|
this,
|
|
|
|
DirCtrlPage_Ctrl,
|
|
|
|
wxDirDialogDefaultFolderStr,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
// the 3 panes panes compose the window
|
|
|
|
sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
|
|
|
|
sizerTop->Add(m_radioStdPath, 0, wxGROW | wxALL , 10);
|
|
|
|
sizerTop->Add(m_dirCtrl, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
|
|
|
|
|
|
|
|
// final initializations
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::Reset()
|
|
|
|
{
|
|
|
|
m_path->SetValue(m_dirCtrl->GetPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::CreateDirCtrl()
|
|
|
|
{
|
|
|
|
wxWindowUpdateLocker noUpdates(this);
|
|
|
|
|
|
|
|
wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl(
|
|
|
|
this,
|
|
|
|
DirCtrlPage_Ctrl,
|
|
|
|
wxDirDialogDefaultFolderStr,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
|
|
|
( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) |
|
|
|
|
( m_chk3D->IsChecked() ? wxDIRCTRL_3D_INTERNAL : 0 ) |
|
|
|
|
( m_chkFirst->IsChecked() ? wxDIRCTRL_SELECT_FIRST : 0 ) |
|
2013-03-09 15:07:49 +00:00
|
|
|
( m_chkFilters->IsChecked() ? wxDIRCTRL_SHOW_FILTERS : 0 ) |
|
2009-06-06 14:00:51 +00:00
|
|
|
( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 ) |
|
|
|
|
( m_chkMulti->IsChecked() ? wxDIRCTRL_MULTIPLE : 0)
|
2006-10-05 10:20:32 +00:00
|
|
|
);
|
|
|
|
|
2007-05-24 00:14:59 +00:00
|
|
|
wxString filter;
|
2009-06-06 14:00:51 +00:00
|
|
|
for (int i = 0; i < 3; ++i)
|
2007-05-24 00:14:59 +00:00
|
|
|
{
|
2009-06-06 14:00:51 +00:00
|
|
|
if (m_fltr[i]->IsChecked())
|
2007-05-24 00:14:59 +00:00
|
|
|
{
|
|
|
|
if (!filter.IsEmpty())
|
|
|
|
filter += wxT("|");
|
|
|
|
filter += m_fltr[i]->GetLabel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dirCtrl->SetFilter(filter);
|
|
|
|
|
2006-10-05 10:20:32 +00:00
|
|
|
// update sizer's child window
|
|
|
|
GetSizer()->Replace(m_dirCtrl, dirCtrl, true);
|
|
|
|
|
|
|
|
// update our pointer
|
|
|
|
delete m_dirCtrl;
|
|
|
|
m_dirCtrl = dirCtrl;
|
|
|
|
|
|
|
|
// relayout the sizer
|
|
|
|
GetSizer()->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::OnButtonSetPath(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_dirCtrl->SetPath(m_path->GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
CreateDirCtrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::OnCheckBox(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
CreateDirCtrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wxTheApp->SetAppName(wxT("widgets"));
|
2006-10-05 10:20:32 +00:00
|
|
|
wxStandardPathsBase& stdp = wxStandardPaths::Get();
|
|
|
|
|
|
|
|
switch ( m_radioStdPath->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case stdPathUnknown:
|
|
|
|
case stdPathMax:
|
|
|
|
// leave path
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathConfig:
|
|
|
|
path = stdp.GetConfigDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathData:
|
|
|
|
path = stdp.GetDataDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathDocuments:
|
|
|
|
path = stdp.GetDocumentsDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathLocalData:
|
|
|
|
path = stdp.GetLocalDataDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathPlugins:
|
|
|
|
path = stdp.GetPluginsDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathResources:
|
|
|
|
path = stdp.GetResourcesDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathUserConfig:
|
|
|
|
path = stdp.GetUserConfigDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathUserData:
|
|
|
|
path = stdp.GetUserDataDir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stdPathUserLocalData:
|
|
|
|
path = stdp.GetUserLocalDataDir();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dirCtrl->SetPath(path);
|
2012-10-29 18:30:14 +00:00
|
|
|
|
|
|
|
// Notice that we must use wxFileName comparison instead of simple wxString
|
|
|
|
// comparison as the paths returned may differ by case only.
|
|
|
|
if ( wxFileName(m_dirCtrl->GetPath()) != path )
|
2006-10-05 10:20:32 +00:00
|
|
|
{
|
2012-10-29 18:30:14 +00:00
|
|
|
wxLogMessage("Failed to go to \"%s\", the current path is \"%s\".",
|
|
|
|
path, m_dirCtrl->GetPath());
|
2006-10-05 10:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 17:15:08 +00:00
|
|
|
void DirCtrlWidgetsPage::OnSelChanged(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
if ( m_dirCtrl )
|
|
|
|
{
|
|
|
|
wxLogMessage("Selection changed to \"%s\"",
|
|
|
|
m_dirCtrl->GetPath(event.GetItem()));
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2013-05-16 14:33:07 +00:00
|
|
|
void DirCtrlWidgetsPage::OnFileActivated(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
if ( m_dirCtrl )
|
|
|
|
{
|
|
|
|
wxLogMessage("File activated \"%s\"",
|
|
|
|
m_dirCtrl->GetPath(event.GetItem()));
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2006-10-05 10:20:32 +00:00
|
|
|
#endif // wxUSE_DIRDLG
|