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
223 void DirCtrlWidgetsPage::Reset()
225 m_path
->SetValue(m_dirCtrl
->GetPath());
228 void DirCtrlWidgetsPage::CreateDirCtrl()
230 wxWindowUpdateLocker
noUpdates(this);
232 wxGenericDirCtrl
*dirCtrl
= new wxGenericDirCtrl(
235 wxDirDialogDefaultFolderStr
,
238 ( m_chkDirOnly
->IsChecked() ? wxDIRCTRL_DIR_ONLY
: 0 ) |
239 ( m_chk3D
->IsChecked() ? wxDIRCTRL_3D_INTERNAL
: 0 ) |
240 ( m_chkFirst
->IsChecked() ? wxDIRCTRL_SELECT_FIRST
: 0 ) |
241 ( m_chkFilters
->IsChecked() ? wxDIRCTRL_SHOW_FILTERS
: 0 ) |
242 ( m_chkLabels
->IsChecked() ? wxDIRCTRL_EDIT_LABELS
: 0 )
245 // update sizer's child window
246 GetSizer()->Replace(m_dirCtrl
, dirCtrl
, true);
248 // update our pointer
252 // relayout the sizer
253 GetSizer()->Layout();
256 // ----------------------------------------------------------------------------
258 // ----------------------------------------------------------------------------
260 void DirCtrlWidgetsPage::OnButtonSetPath(wxCommandEvent
& WXUNUSED(event
))
262 m_dirCtrl
->SetPath(m_path
->GetValue());
265 void DirCtrlWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
272 void DirCtrlWidgetsPage::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
277 void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent
& WXUNUSED(event
))
281 wxTheApp
->SetAppName(_T("widgets"));
282 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
284 switch ( m_radioStdPath
->GetSelection() )
293 path
= stdp
.GetConfigDir();
297 path
= stdp
.GetDataDir();
300 case stdPathDocuments
:
301 path
= stdp
.GetDocumentsDir();
304 case stdPathLocalData
:
305 path
= stdp
.GetLocalDataDir();
309 path
= stdp
.GetPluginsDir();
312 case stdPathResources
:
313 path
= stdp
.GetResourcesDir();
316 case stdPathUserConfig
:
317 path
= stdp
.GetUserConfigDir();
320 case stdPathUserData
:
321 path
= stdp
.GetUserDataDir();
324 case stdPathUserLocalData
:
325 path
= stdp
.GetUserLocalDataDir();
329 m_dirCtrl
->SetPath(path
);
330 if(!m_dirCtrl
->GetPath().IsSameAs(path
))
332 wxLogMessage(_T("Selected standard path and path from control do not match!"));
333 m_radioStdPath
->SetSelection(stdPathUnknown
);
337 #endif // wxUSE_DIRDLG