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
,
137 wxCheckBox
*m_fltr
[3];
140 DECLARE_EVENT_TABLE()
141 DECLARE_WIDGETS_PAGE(DirCtrlWidgetsPage
)
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 BEGIN_EVENT_TABLE(DirCtrlWidgetsPage
, WidgetsPage
)
149 EVT_BUTTON(DirCtrlPage_Reset
, DirCtrlWidgetsPage
::OnButtonReset
)
150 EVT_BUTTON(DirCtrlPage_SetPath
, DirCtrlWidgetsPage
::OnButtonSetPath
)
151 EVT_CHECKBOX(wxID_ANY
, DirCtrlWidgetsPage
::OnCheckBox
)
152 EVT_RADIOBOX(wxID_ANY
, DirCtrlWidgetsPage
::OnRadioBox
)
155 // ============================================================================
157 // ============================================================================
159 IMPLEMENT_WIDGETS_PAGE(DirCtrlWidgetsPage
, wxT("DirCtrl"),
163 DirCtrlWidgetsPage
::DirCtrlWidgetsPage(WidgetsBookCtrl
*book
,
164 wxImageList
*imaglist
)
165 :WidgetsPage(book
, imaglist
, dirctrl_xpm
)
169 void DirCtrlWidgetsPage
::CreateContent()
171 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
174 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Dir control details"));
176 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
178 sizerLeft
->Add( CreateSizerWithTextAndButton( DirCtrlPage_SetPath
, wxT("Set &path"), wxID_ANY
, &m_path
),
179 0, wxALL
| wxALIGN_RIGHT
, 5 );
181 wxSizer
*sizerUseFlags
=
182 new wxStaticBoxSizer(wxVERTICAL
, this, _T("&Flags"));
183 m_chkDirOnly
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_DIR_ONLY"));
184 m_chk3D
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_3D_INTERNAL"));
185 m_chkFirst
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_SELECT_FIRST"));
186 m_chkLabels
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_EDIT_LABELS"));
187 sizerLeft
->Add(sizerUseFlags
, wxSizerFlags().Expand().Border());
189 wxSizer
*sizerFilters
=
190 new wxStaticBoxSizer(wxVERTICAL
, this, _T("&Filters"));
191 m_fltr
[0] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxString
::Format(wxT("all files (%s)|%s"),
192 wxFileSelectorDefaultWildcardStr
, wxFileSelectorDefaultWildcardStr
));
193 m_fltr
[1] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h"));
194 m_fltr
[2] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxT("PNG images (*.png)|*.png"));
195 sizerLeft
->Add(sizerFilters
, wxSizerFlags().Expand().Border());
197 wxButton
*btn
= new wxButton(this, DirCtrlPage_Reset
, _T("&Reset"));
198 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
200 // keep consistency between enum and labels of radiobox
201 wxCOMPILE_TIME_ASSERT( stdPathMax
== WXSIZEOF(stdPaths
), EnumForRadioBoxMismatch
);
204 m_radioStdPath
= new wxRadioBox(this, wxID_ANY
, _T("Standard path"),
205 wxDefaultPosition
, wxDefaultSize
,
206 WXSIZEOF(stdPaths
), stdPaths
, 1);
209 m_dirCtrl
= new wxGenericDirCtrl(
212 wxDirDialogDefaultFolderStr
,
218 // the 3 panes panes compose the window
219 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
220 sizerTop
->Add(m_radioStdPath
, 0, wxGROW
| wxALL
, 10);
221 sizerTop
->Add(m_dirCtrl
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
223 // final initializations
229 void DirCtrlWidgetsPage
::Reset()
231 m_path
->SetValue(m_dirCtrl
->GetPath());
234 void DirCtrlWidgetsPage
::CreateDirCtrl()
236 wxWindowUpdateLocker
noUpdates(this);
238 wxGenericDirCtrl
*dirCtrl
= new wxGenericDirCtrl(
241 wxDirDialogDefaultFolderStr
,
244 ( m_chkDirOnly
->IsChecked() ? wxDIRCTRL_DIR_ONLY
: 0 ) |
245 ( m_chk3D
->IsChecked() ? wxDIRCTRL_3D_INTERNAL
: 0 ) |
246 ( m_chkFirst
->IsChecked() ? wxDIRCTRL_SELECT_FIRST
: 0 ) |
247 ( m_chkLabels
->IsChecked() ? wxDIRCTRL_EDIT_LABELS
: 0 )
251 for (int i
= 0; i
< 3; ++i
)
253 if (m_fltr
[i
]->IsChecked())
255 if (!filter
.IsEmpty())
257 filter
+= m_fltr
[i
]->GetLabel();
260 dirCtrl
->SetFilter(filter
);
262 // update sizer's child window
263 GetSizer()->Replace(m_dirCtrl
, dirCtrl
, true);
265 // update our pointer
269 // relayout the sizer
270 GetSizer()->Layout();
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
277 void DirCtrlWidgetsPage
::OnButtonSetPath(wxCommandEvent
& WXUNUSED(event
))
279 m_dirCtrl
->SetPath(m_path
->GetValue());
282 void DirCtrlWidgetsPage
::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
289 void DirCtrlWidgetsPage
::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
294 void DirCtrlWidgetsPage
::OnRadioBox(wxCommandEvent
& WXUNUSED(event
))
298 wxTheApp
->SetAppName(_T("widgets"));
299 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
301 switch ( m_radioStdPath
->GetSelection() )
310 path
= stdp
.GetConfigDir();
314 path
= stdp
.GetDataDir();
317 case stdPathDocuments
:
318 path
= stdp
.GetDocumentsDir();
321 case stdPathLocalData
:
322 path
= stdp
.GetLocalDataDir();
326 path
= stdp
.GetPluginsDir();
329 case stdPathResources
:
330 path
= stdp
.GetResourcesDir();
333 case stdPathUserConfig
:
334 path
= stdp
.GetUserConfigDir();
337 case stdPathUserData
:
338 path
= stdp
.GetUserDataDir();
341 case stdPathUserLocalData
:
342 path
= stdp
.GetUserLocalDataDir();
346 m_dirCtrl
->SetPath(path
);
347 if(!m_dirCtrl
->GetPath().IsSameAs(path
))
349 wxLogMessage(_T("Selected standard path and path from control do not match!"));
350 m_radioStdPath
->SetSelection(stdPathUnknown
);
354 #endif // wxUSE_DIRDLG