1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filepickerg.h
3 // Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FILEDIRPICKER_H_
13 #define _WX_FILEDIRPICKER_H_
15 #include "wx/button.h"
16 #include "wx/filename.h"
17 #include "wx/filedlg.h"
18 #include "wx/dirdlg.h"
21 extern WXDLLEXPORT_DATA(const wxEventType
) wxEVT_COMMAND_DIRPICKER_CHANGED
;
22 extern WXDLLEXPORT_DATA(const wxEventType
) wxEVT_COMMAND_FILEPICKER_CHANGED
;
25 //-----------------------------------------------------------------------------
26 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
27 //-----------------------------------------------------------------------------
29 class WXDLLIMPEXP_CORE wxGenericFileDirButton
: public wxButton
,
30 public wxFileDirPickerWidgetBase
33 wxGenericFileDirButton() { }
34 wxGenericFileDirButton(wxWindow
*parent
,
36 const wxString
& label
= wxFilePickerWidgetLabel
,
37 const wxString
& path
= wxEmptyString
,
38 const wxString
&message
= wxFileSelectorPromptStr
,
39 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
40 const wxPoint
& pos
= wxDefaultPosition
,
41 const wxSize
& size
= wxDefaultSize
,
43 const wxValidator
& validator
= wxDefaultValidator
,
44 const wxString
& name
= wxFilePickerWidgetNameStr
)
46 Create(parent
, id
, label
, path
, message
, wildcard
,
47 pos
, size
, style
, validator
, name
);
50 virtual ~wxGenericFileDirButton() {}
52 public: // overrideable
54 virtual wxDialog
*CreateDialog() = 0;
56 virtual wxWindow
*GetDialogParent()
57 { return GetParent(); }
59 virtual wxEventType
GetEventType() const = 0;
63 bool Create(wxWindow
*parent
, wxWindowID id
,
64 const wxString
& label
= wxFilePickerWidgetLabel
,
65 const wxString
& path
= wxEmptyString
,
66 const wxString
&message
= wxFileSelectorPromptStr
,
67 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
68 const wxPoint
& pos
= wxDefaultPosition
,
69 const wxSize
& size
= wxDefaultSize
,
71 const wxValidator
& validator
= wxDefaultValidator
,
72 const wxString
& name
= wxFilePickerWidgetNameStr
);
74 // event handler for the click
75 void OnButtonClick(wxCommandEvent
&);
78 wxString m_message
, m_wildcard
;
82 //-----------------------------------------------------------------------------
83 // wxGenericFileButton: a button which brings up a wxFileDialog
84 //-----------------------------------------------------------------------------
86 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
88 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
91 wxGenericFileButton() {}
92 wxGenericFileButton(wxWindow
*parent
,
94 const wxString
& label
= wxFilePickerWidgetLabel
,
95 const wxString
& path
= wxEmptyString
,
96 const wxString
&message
= wxFileSelectorPromptStr
,
97 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
98 const wxPoint
& pos
= wxDefaultPosition
,
99 const wxSize
& size
= wxDefaultSize
,
100 long style
= wxFILEBTN_DEFAULT_STYLE
,
101 const wxValidator
& validator
= wxDefaultValidator
,
102 const wxString
& name
= wxFilePickerWidgetNameStr
)
104 Create(parent
, id
, label
, path
, message
, wildcard
,
105 pos
, size
, style
, validator
, name
);
108 public: // overrideable
110 virtual long GetDialogStyle() const
112 long filedlgstyle
= 0;
114 if (this->HasFlag(wxFLP_OPEN
))
115 filedlgstyle
|= wxFD_OPEN
;
116 if (this->HasFlag(wxFLP_SAVE
))
117 filedlgstyle
|= wxFD_SAVE
;
118 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT
))
119 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
120 if (this->HasFlag(wxFLP_FILE_MUST_EXIST
))
121 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
122 if (this->HasFlag(wxFLP_CHANGE_DIR
))
123 filedlgstyle
|= wxFD_CHANGE_DIR
;
128 virtual wxDialog
*CreateDialog()
130 wxFileDialog
*p
= new wxFileDialog(GetDialogParent(), m_message
,
131 wxEmptyString
, wxEmptyString
,
132 m_wildcard
, GetDialogStyle());
134 // this sets both the default folder and the default file of the dialog
139 void UpdateDialogPath(wxDialog
*p
)
140 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
141 void UpdatePathFromDialog(wxDialog
*p
)
142 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
143 wxEventType
GetEventType() const
144 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
147 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
151 //-----------------------------------------------------------------------------
152 // wxGenericDirButton: a button which brings up a wxDirDialog
153 //-----------------------------------------------------------------------------
155 #define wxDIRBTN_DEFAULT_STYLE 0
157 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
160 wxGenericDirButton() {}
161 wxGenericDirButton(wxWindow
*parent
,
163 const wxString
& label
= wxDirPickerWidgetLabel
,
164 const wxString
& path
= wxEmptyString
,
165 const wxString
&message
= wxDirSelectorPromptStr
,
166 const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
,
168 long style
= wxDIRBTN_DEFAULT_STYLE
,
169 const wxValidator
& validator
= wxDefaultValidator
,
170 const wxString
& name
= wxDirPickerWidgetNameStr
)
172 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
173 pos
, size
, style
, validator
, name
);
176 public: // overrideable
178 virtual long GetDialogStyle() const
180 long dirdlgstyle
= 0;
182 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST
))
183 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
184 if (this->HasFlag(wxDIRP_CHANGE_DIR
))
185 dirdlgstyle
|= wxDD_CHANGE_DIR
;
190 virtual wxDialog
*CreateDialog()
192 return new wxDirDialog(GetDialogParent(), m_message
, m_path
,
196 void UpdateDialogPath(wxDialog
*p
)
197 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
198 void UpdatePathFromDialog(wxDialog
*p
)
199 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
200 wxEventType
GetEventType() const
201 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
204 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
208 #endif // _WX_FILEDIRPICKER_H_