1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing wxGenericDirCtrl
5 // Author: Wlodzimierz 'ABX' Skiba
8 // Copyright: (c) 2006 wxWindows team
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
29 // for all others, include the necessary headers
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
36 #include "wx/checkbox.h"
37 #include "wx/button.h"
40 #include "wx/generic/dirctrlg.h"
42 #include "wx/wupdlock.h"
43 #include "wx/stdpaths.h"
47 #include "icons/dirctrl.xpm"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
56 DirCtrlPage_Reset
= wxID_HIGHEST
,
61 static const wxString stdPaths
[] =
72 _T("&user local data")
90 // ----------------------------------------------------------------------------
91 // CheckBoxWidgetsPage
92 // ----------------------------------------------------------------------------
94 class DirCtrlWidgetsPage
: public WidgetsPage
97 DirCtrlWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
98 virtual ~DirCtrlWidgetsPage() {}
100 virtual wxControl
*GetWidget() const { return m_dirCtrl
; }
101 virtual void RecreateWidget() { CreateDirCtrl(); }
103 // lazy creation of the content
104 virtual void CreateContent();
108 void OnButtonSetPath(wxCommandEvent
& event
);
109 void OnButtonReset(wxCommandEvent
& event
);
110 void OnStdPath(wxCommandEvent
& event
);
111 void OnCheckBox(wxCommandEvent
& event
);
112 void OnRadioBox(wxCommandEvent
& event
);
114 // reset the control parameters
117 // (re)create the m_dirCtrl
118 void CreateDirCtrl();
123 // the control itself and the sizer it is in
124 wxGenericDirCtrl
*m_dirCtrl
;
126 // the text entries for command parameters
129 wxRadioBox
*m_radioStdPath
;
132 wxCheckBox
*m_chkDirOnly
,
139 DECLARE_EVENT_TABLE()
140 DECLARE_WIDGETS_PAGE(DirCtrlWidgetsPage
)
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 BEGIN_EVENT_TABLE(DirCtrlWidgetsPage
, WidgetsPage
)
148 EVT_BUTTON(DirCtrlPage_Reset
, DirCtrlWidgetsPage::OnButtonReset
)
149 EVT_BUTTON(DirCtrlPage_SetPath
, DirCtrlWidgetsPage::OnButtonSetPath
)
150 EVT_CHECKBOX(wxID_ANY
, DirCtrlWidgetsPage::OnCheckBox
)
151 EVT_RADIOBOX(wxID_ANY
, DirCtrlWidgetsPage::OnRadioBox
)
154 // ============================================================================
156 // ============================================================================
158 IMPLEMENT_WIDGETS_PAGE(DirCtrlWidgetsPage
, wxT("DirCtrl"),
162 DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl
*book
,
163 wxImageList
*imaglist
)
164 :WidgetsPage(book
, imaglist
, dirctrl_xpm
)
168 void DirCtrlWidgetsPage::CreateContent()
170 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
173 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Dir control details"));
175 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
177 sizerLeft
->Add( CreateSizerWithTextAndButton( DirCtrlPage_SetPath
, wxT("Set &path"), wxID_ANY
, &m_path
),
178 0, wxALL
| wxALIGN_RIGHT
, 5 );
180 wxSizer
*sizerUseFlags
=
181 new wxStaticBoxSizer(wxVERTICAL
, this, _T("&Flags"));
182 m_chkDirOnly
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_DIR_ONLY"));
183 m_chk3D
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_3D_INTERNAL"));
184 m_chkFirst
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_SELECT_FIRST"));
185 m_chkFilters
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_SHOW_FILTERS"));
186 m_chkLabels
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_EDIT_LABELS"));
187 sizerLeft
->Add(sizerUseFlags
, wxSizerFlags().Expand().Border());
189 wxButton
*btn
= new wxButton(this, DirCtrlPage_Reset
, _T("&Reset"));
190 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
192 // keep consistency between enum and labels of radiobox
193 wxCOMPILE_TIME_ASSERT( stdPathMax
== WXSIZEOF(stdPaths
), EnumForRadioBoxMismatch
);
196 m_radioStdPath
= new wxRadioBox(this, wxID_ANY
, _T("Standard path"),
197 wxDefaultPosition
, wxDefaultSize
,
198 WXSIZEOF(stdPaths
), stdPaths
, 1);
201 m_dirCtrl
= new wxGenericDirCtrl(
204 wxDirDialogDefaultFolderStr
,
210 // the 3 panes panes compose the window
211 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
212 sizerTop
->Add(m_radioStdPath
, 0, wxGROW
| wxALL
, 10);
213 sizerTop
->Add(m_dirCtrl
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
215 // final initializations
221 void DirCtrlWidgetsPage::Reset()
223 m_path
->SetValue(m_dirCtrl
->GetPath());
226 void DirCtrlWidgetsPage::CreateDirCtrl()
228 wxWindowUpdateLocker
noUpdates(this);
230 wxGenericDirCtrl
*dirCtrl
= new wxGenericDirCtrl(
233 wxDirDialogDefaultFolderStr
,
236 ( m_chkDirOnly
->IsChecked() ? wxDIRCTRL_DIR_ONLY
: 0 ) |
237 ( m_chk3D
->IsChecked() ? wxDIRCTRL_3D_INTERNAL
: 0 ) |
238 ( m_chkFirst
->IsChecked() ? wxDIRCTRL_SELECT_FIRST
: 0 ) |
239 ( m_chkFilters
->IsChecked() ? wxDIRCTRL_SHOW_FILTERS
: 0 ) |
240 ( m_chkLabels
->IsChecked() ? wxDIRCTRL_EDIT_LABELS
: 0 )
243 // update sizer's child window
244 GetSizer()->Replace(m_dirCtrl
, dirCtrl
, true);
246 // update our pointer
250 // relayout the sizer
251 GetSizer()->Layout();
254 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
258 void DirCtrlWidgetsPage::OnButtonSetPath(wxCommandEvent
& WXUNUSED(event
))
260 m_dirCtrl
->SetPath(m_path
->GetValue());
263 void DirCtrlWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
270 void DirCtrlWidgetsPage::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
275 void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent
& WXUNUSED(event
))
279 wxTheApp
->SetAppName(_T("widgets"));
280 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
282 switch ( m_radioStdPath
->GetSelection() )
291 path
= stdp
.GetConfigDir();
295 path
= stdp
.GetDataDir();
298 case stdPathDocuments
:
299 path
= stdp
.GetDocumentsDir();
302 case stdPathLocalData
:
303 path
= stdp
.GetLocalDataDir();
307 path
= stdp
.GetPluginsDir();
310 case stdPathResources
:
311 path
= stdp
.GetResourcesDir();
314 case stdPathUserConfig
:
315 path
= stdp
.GetUserConfigDir();
318 case stdPathUserData
:
319 path
= stdp
.GetUserDataDir();
322 case stdPathUserLocalData
:
323 path
= stdp
.GetUserLocalDataDir();
327 m_dirCtrl
->SetPath(path
);
328 if(!m_dirCtrl
->GetPath().IsSameAs(path
))
330 wxLogMessage(_T("Selected standard path and path from control do not match!"));
331 m_radioStdPath
->SetSelection(stdPathUnknown
);
335 #endif // wxUSE_DIRDLG