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"
38 #include "wx/filedlg.h"
41 #include "wx/generic/dirctrlg.h"
43 #include "wx/wupdlock.h"
44 #include "wx/stdpaths.h"
48 #include "icons/dirctrl.xpm"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
57 DirCtrlPage_Reset
= wxID_HIGHEST
,
62 static const wxString stdPaths
[] =
73 _T("&user local data")
91 // ----------------------------------------------------------------------------
92 // CheckBoxWidgetsPage
93 // ----------------------------------------------------------------------------
95 class DirCtrlWidgetsPage
: public WidgetsPage
98 DirCtrlWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
99 virtual ~DirCtrlWidgetsPage() {}
101 virtual wxControl
*GetWidget() const { return m_dirCtrl
; }
102 virtual void RecreateWidget() { CreateDirCtrl(); }
104 // lazy creation of the content
105 virtual void CreateContent();
109 void OnButtonSetPath(wxCommandEvent
& event
);
110 void OnButtonReset(wxCommandEvent
& event
);
111 void OnStdPath(wxCommandEvent
& event
);
112 void OnCheckBox(wxCommandEvent
& event
);
113 void OnRadioBox(wxCommandEvent
& event
);
115 // reset the control parameters
118 // (re)create the m_dirCtrl
119 void CreateDirCtrl();
124 // the control itself and the sizer it is in
125 wxGenericDirCtrl
*m_dirCtrl
;
127 // the text entries for command parameters
130 wxRadioBox
*m_radioStdPath
;
133 wxCheckBox
*m_chkDirOnly
,
140 wxCheckBox
*m_fltr
[3];
143 DECLARE_EVENT_TABLE()
144 DECLARE_WIDGETS_PAGE(DirCtrlWidgetsPage
)
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 BEGIN_EVENT_TABLE(DirCtrlWidgetsPage
, WidgetsPage
)
152 EVT_BUTTON(DirCtrlPage_Reset
, DirCtrlWidgetsPage::OnButtonReset
)
153 EVT_BUTTON(DirCtrlPage_SetPath
, DirCtrlWidgetsPage::OnButtonSetPath
)
154 EVT_CHECKBOX(wxID_ANY
, DirCtrlWidgetsPage::OnCheckBox
)
155 EVT_RADIOBOX(wxID_ANY
, DirCtrlWidgetsPage::OnRadioBox
)
158 // ============================================================================
160 // ============================================================================
162 IMPLEMENT_WIDGETS_PAGE(DirCtrlWidgetsPage
, wxT("DirCtrl"),
166 DirCtrlWidgetsPage::DirCtrlWidgetsPage(WidgetsBookCtrl
*book
,
167 wxImageList
*imaglist
)
168 :WidgetsPage(book
, imaglist
, dirctrl_xpm
)
172 void DirCtrlWidgetsPage::CreateContent()
174 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
177 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Dir control details"));
179 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
181 sizerLeft
->Add( CreateSizerWithTextAndButton( DirCtrlPage_SetPath
, wxT("Set &path"), wxID_ANY
, &m_path
),
182 0, wxALL
| wxALIGN_RIGHT
, 5 );
184 wxSizer
*sizerUseFlags
=
185 new wxStaticBoxSizer(wxVERTICAL
, this, _T("&Flags"));
186 m_chkDirOnly
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_DIR_ONLY"));
187 m_chk3D
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_3D_INTERNAL"));
188 m_chkFirst
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_SELECT_FIRST"));
189 m_chkLabels
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_EDIT_LABELS"));
190 m_chkMulti
= CreateCheckBoxAndAddToSizer(sizerUseFlags
, _T("wxDIRCTRL_MULTIPLE"));
191 sizerLeft
->Add(sizerUseFlags
, wxSizerFlags().Expand().Border());
193 wxSizer
*sizerFilters
=
194 new wxStaticBoxSizer(wxVERTICAL
, this, _T("&Filters"));
195 m_fltr
[0] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxString::Format(wxT("all files (%s)|%s"),
196 wxFileSelectorDefaultWildcardStr
, wxFileSelectorDefaultWildcardStr
));
197 m_fltr
[1] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h"));
198 m_fltr
[2] = CreateCheckBoxAndAddToSizer(sizerFilters
, wxT("PNG images (*.png)|*.png"));
199 sizerLeft
->Add(sizerFilters
, wxSizerFlags().Expand().Border());
201 wxButton
*btn
= new wxButton(this, DirCtrlPage_Reset
, _T("&Reset"));
202 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
204 // keep consistency between enum and labels of radiobox
205 wxCOMPILE_TIME_ASSERT( stdPathMax
== WXSIZEOF(stdPaths
), EnumForRadioBoxMismatch
);
208 m_radioStdPath
= new wxRadioBox(this, wxID_ANY
, _T("Standard path"),
209 wxDefaultPosition
, wxDefaultSize
,
210 WXSIZEOF(stdPaths
), stdPaths
, 1);
213 m_dirCtrl
= new wxGenericDirCtrl(
216 wxDirDialogDefaultFolderStr
,
222 // the 3 panes panes compose the window
223 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
224 sizerTop
->Add(m_radioStdPath
, 0, wxGROW
| wxALL
, 10);
225 sizerTop
->Add(m_dirCtrl
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
227 // final initializations
233 void DirCtrlWidgetsPage::Reset()
235 m_path
->SetValue(m_dirCtrl
->GetPath());
238 void DirCtrlWidgetsPage::CreateDirCtrl()
240 wxWindowUpdateLocker
noUpdates(this);
242 wxGenericDirCtrl
*dirCtrl
= new wxGenericDirCtrl(
245 wxDirDialogDefaultFolderStr
,
248 ( m_chkDirOnly
->IsChecked() ? wxDIRCTRL_DIR_ONLY
: 0 ) |
249 ( m_chk3D
->IsChecked() ? wxDIRCTRL_3D_INTERNAL
: 0 ) |
250 ( m_chkFirst
->IsChecked() ? wxDIRCTRL_SELECT_FIRST
: 0 ) |
251 ( m_chkLabels
->IsChecked() ? wxDIRCTRL_EDIT_LABELS
: 0 ) |
252 ( m_chkMulti
->IsChecked() ? wxDIRCTRL_MULTIPLE
: 0)
256 for (int i
= 0; i
< 3; ++i
)
258 if (m_fltr
[i
]->IsChecked())
260 if (!filter
.IsEmpty())
262 filter
+= m_fltr
[i
]->GetLabel();
265 dirCtrl
->SetFilter(filter
);
267 // update sizer's child window
268 GetSizer()->Replace(m_dirCtrl
, dirCtrl
, true);
270 // update our pointer
274 // relayout the sizer
275 GetSizer()->Layout();
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void DirCtrlWidgetsPage::OnButtonSetPath(wxCommandEvent
& WXUNUSED(event
))
284 m_dirCtrl
->SetPath(m_path
->GetValue());
287 void DirCtrlWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
294 void DirCtrlWidgetsPage::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
299 void DirCtrlWidgetsPage::OnRadioBox(wxCommandEvent
& WXUNUSED(event
))
303 wxTheApp
->SetAppName(_T("widgets"));
304 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
306 switch ( m_radioStdPath
->GetSelection() )
315 path
= stdp
.GetConfigDir();
319 path
= stdp
.GetDataDir();
322 case stdPathDocuments
:
323 path
= stdp
.GetDocumentsDir();
326 case stdPathLocalData
:
327 path
= stdp
.GetLocalDataDir();
331 path
= stdp
.GetPluginsDir();
334 case stdPathResources
:
335 path
= stdp
.GetResourcesDir();
338 case stdPathUserConfig
:
339 path
= stdp
.GetUserConfigDir();
342 case stdPathUserData
:
343 path
= stdp
.GetUserDataDir();
346 case stdPathUserLocalData
:
347 path
= stdp
.GetUserLocalDataDir();
351 m_dirCtrl
->SetPath(path
);
352 if(!m_dirCtrl
->GetPath().IsSameAs(path
))
354 wxLogMessage(_T("Selected standard path and path from control do not match!"));
355 m_radioStdPath
->SetSelection(stdPathUnknown
);
359 #endif // wxUSE_DIRDLG