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/filedlg.h"
17 #include "wx/dirdlg.h"
20 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRPICKER_CHANGED
, wxFileDirPickerEvent
);
21 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FILEPICKER_CHANGED
, wxFileDirPickerEvent
);
24 //-----------------------------------------------------------------------------
25 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
26 //-----------------------------------------------------------------------------
28 class WXDLLIMPEXP_CORE wxGenericFileDirButton
: public wxButton
,
29 public wxFileDirPickerWidgetBase
32 wxGenericFileDirButton() { }
33 wxGenericFileDirButton(wxWindow
*parent
,
35 const wxString
& label
= wxFilePickerWidgetLabel
,
36 const wxString
& path
= wxEmptyString
,
37 const wxString
&message
= wxFileSelectorPromptStr
,
38 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
39 const wxPoint
& pos
= wxDefaultPosition
,
40 const wxSize
& size
= wxDefaultSize
,
42 const wxValidator
& validator
= wxDefaultValidator
,
43 const wxString
& name
= wxFilePickerWidgetNameStr
)
45 Create(parent
, id
, label
, path
, message
, wildcard
,
46 pos
, size
, style
, validator
, name
);
49 virtual ~wxGenericFileDirButton() {}
51 virtual wxControl
*AsControl() { return this; }
53 public: // overrideable
55 virtual wxDialog
*CreateDialog() = 0;
57 virtual wxWindow
*GetDialogParent()
58 { return GetParent(); }
60 virtual wxEventType
GetEventType() const = 0;
64 bool Create(wxWindow
*parent
, wxWindowID id
,
65 const wxString
& label
= wxFilePickerWidgetLabel
,
66 const wxString
& path
= wxEmptyString
,
67 const wxString
&message
= wxFileSelectorPromptStr
,
68 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
69 const wxPoint
& pos
= wxDefaultPosition
,
70 const wxSize
& size
= wxDefaultSize
,
72 const wxValidator
& validator
= wxDefaultValidator
,
73 const wxString
& name
= wxFilePickerWidgetNameStr
);
75 // event handler for the click
76 void OnButtonClick(wxCommandEvent
&);
79 wxString m_message
, m_wildcard
;
83 //-----------------------------------------------------------------------------
84 // wxGenericFileButton: a button which brings up a wxFileDialog
85 //-----------------------------------------------------------------------------
87 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
89 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
92 wxGenericFileButton() {}
93 wxGenericFileButton(wxWindow
*parent
,
95 const wxString
& label
= wxFilePickerWidgetLabel
,
96 const wxString
& path
= wxEmptyString
,
97 const wxString
&message
= wxFileSelectorPromptStr
,
98 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
99 const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
,
101 long style
= wxFILEBTN_DEFAULT_STYLE
,
102 const wxValidator
& validator
= wxDefaultValidator
,
103 const wxString
& name
= wxFilePickerWidgetNameStr
)
105 Create(parent
, id
, label
, path
, message
, wildcard
,
106 pos
, size
, style
, validator
, name
);
109 public: // overrideable
111 virtual long GetDialogStyle() const
113 long filedlgstyle
= 0;
115 if (this->HasFlag(wxFLP_OPEN
))
116 filedlgstyle
|= wxFD_OPEN
;
117 if (this->HasFlag(wxFLP_SAVE
))
118 filedlgstyle
|= wxFD_SAVE
;
119 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT
))
120 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
121 if (this->HasFlag(wxFLP_FILE_MUST_EXIST
))
122 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
123 if (this->HasFlag(wxFLP_CHANGE_DIR
))
124 filedlgstyle
|= wxFD_CHANGE_DIR
;
129 virtual wxDialog
*CreateDialog()
131 wxFileDialog
*p
= new wxFileDialog(GetDialogParent(), m_message
,
132 wxEmptyString
, wxEmptyString
,
133 m_wildcard
, GetDialogStyle());
135 // this sets both the default folder and the default file of the dialog
140 wxEventType
GetEventType() const
141 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
144 void UpdateDialogPath(wxDialog
*p
)
145 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
146 void UpdatePathFromDialog(wxDialog
*p
)
147 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
150 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
154 //-----------------------------------------------------------------------------
155 // wxGenericDirButton: a button which brings up a wxDirDialog
156 //-----------------------------------------------------------------------------
158 #define wxDIRBTN_DEFAULT_STYLE 0
160 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
163 wxGenericDirButton() {}
164 wxGenericDirButton(wxWindow
*parent
,
166 const wxString
& label
= wxDirPickerWidgetLabel
,
167 const wxString
& path
= wxEmptyString
,
168 const wxString
&message
= wxDirSelectorPromptStr
,
169 const wxPoint
& pos
= wxDefaultPosition
,
170 const wxSize
& size
= wxDefaultSize
,
171 long style
= wxDIRBTN_DEFAULT_STYLE
,
172 const wxValidator
& validator
= wxDefaultValidator
,
173 const wxString
& name
= wxDirPickerWidgetNameStr
)
175 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
176 pos
, size
, style
, validator
, name
);
179 public: // overrideable
181 virtual long GetDialogStyle() const
183 long dirdlgstyle
= wxDD_DEFAULT_STYLE
;
185 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST
))
186 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
187 if (this->HasFlag(wxDIRP_CHANGE_DIR
))
188 dirdlgstyle
|= wxDD_CHANGE_DIR
;
193 virtual wxDialog
*CreateDialog()
195 return new wxDirDialog(GetDialogParent(), m_message
, m_path
,
199 wxEventType
GetEventType() const
200 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
203 void UpdateDialogPath(wxDialog
*p
)
204 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
205 void UpdatePathFromDialog(wxDialog
*p
)
206 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
209 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
213 #endif // _WX_FILEDIRPICKER_H_