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 extern WXDLLEXPORT_DATA(const wxEventType
) wxEVT_COMMAND_DIRPICKER_CHANGED
;
21 extern WXDLLEXPORT_DATA(const wxEventType
) wxEVT_COMMAND_FILEPICKER_CHANGED
;
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 public: // overrideable
53 virtual wxDialog
*CreateDialog() = 0;
55 virtual wxWindow
*GetDialogParent()
56 { return GetParent(); }
58 virtual wxEventType
GetEventType() const = 0;
62 bool Create(wxWindow
*parent
, wxWindowID id
,
63 const wxString
& label
= wxFilePickerWidgetLabel
,
64 const wxString
& path
= wxEmptyString
,
65 const wxString
&message
= wxFileSelectorPromptStr
,
66 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
67 const wxPoint
& pos
= wxDefaultPosition
,
68 const wxSize
& size
= wxDefaultSize
,
70 const wxValidator
& validator
= wxDefaultValidator
,
71 const wxString
& name
= wxFilePickerWidgetNameStr
);
73 // event handler for the click
74 void OnButtonClick(wxCommandEvent
&);
77 wxString m_message
, m_wildcard
;
81 //-----------------------------------------------------------------------------
82 // wxGenericFileButton: a button which brings up a wxFileDialog
83 //-----------------------------------------------------------------------------
85 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
87 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
90 wxGenericFileButton() {}
91 wxGenericFileButton(wxWindow
*parent
,
93 const wxString
& label
= wxFilePickerWidgetLabel
,
94 const wxString
& path
= wxEmptyString
,
95 const wxString
&message
= wxFileSelectorPromptStr
,
96 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
97 const wxPoint
& pos
= wxDefaultPosition
,
98 const wxSize
& size
= wxDefaultSize
,
99 long style
= wxFILEBTN_DEFAULT_STYLE
,
100 const wxValidator
& validator
= wxDefaultValidator
,
101 const wxString
& name
= wxFilePickerWidgetNameStr
)
103 Create(parent
, id
, label
, path
, message
, wildcard
,
104 pos
, size
, style
, validator
, name
);
107 public: // overrideable
109 virtual long GetDialogStyle() const
111 long filedlgstyle
= 0;
113 if (this->HasFlag(wxFLP_OPEN
))
114 filedlgstyle
|= wxFD_OPEN
;
115 if (this->HasFlag(wxFLP_SAVE
))
116 filedlgstyle
|= wxFD_SAVE
;
117 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT
))
118 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
119 if (this->HasFlag(wxFLP_FILE_MUST_EXIST
))
120 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
121 if (this->HasFlag(wxFLP_CHANGE_DIR
))
122 filedlgstyle
|= wxFD_CHANGE_DIR
;
127 virtual wxDialog
*CreateDialog()
129 wxFileDialog
*p
= new wxFileDialog(GetDialogParent(), m_message
,
130 wxEmptyString
, wxEmptyString
,
131 m_wildcard
, GetDialogStyle());
133 // this sets both the default folder and the default file of the dialog
138 wxEventType
GetEventType() const
139 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
142 void UpdateDialogPath(wxDialog
*p
)
143 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
144 void UpdatePathFromDialog(wxDialog
*p
)
145 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
148 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
152 //-----------------------------------------------------------------------------
153 // wxGenericDirButton: a button which brings up a wxDirDialog
154 //-----------------------------------------------------------------------------
156 #define wxDIRBTN_DEFAULT_STYLE 0
158 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
161 wxGenericDirButton() {}
162 wxGenericDirButton(wxWindow
*parent
,
164 const wxString
& label
= wxDirPickerWidgetLabel
,
165 const wxString
& path
= wxEmptyString
,
166 const wxString
&message
= wxDirSelectorPromptStr
,
167 const wxPoint
& pos
= wxDefaultPosition
,
168 const wxSize
& size
= wxDefaultSize
,
169 long style
= wxDIRBTN_DEFAULT_STYLE
,
170 const wxValidator
& validator
= wxDefaultValidator
,
171 const wxString
& name
= wxDirPickerWidgetNameStr
)
173 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
174 pos
, size
, style
, validator
, name
);
177 public: // overrideable
179 virtual long GetDialogStyle() const
181 long dirdlgstyle
= 0;
183 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST
))
184 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
185 if (this->HasFlag(wxDIRP_CHANGE_DIR
))
186 dirdlgstyle
|= wxDD_CHANGE_DIR
;
191 virtual wxDialog
*CreateDialog()
193 return new wxDirDialog(GetDialogParent(), m_message
, m_path
,
197 wxEventType
GetEventType() const
198 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
201 void UpdateDialogPath(wxDialog
*p
)
202 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
203 void UpdatePathFromDialog(wxDialog
*p
)
204 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
207 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
211 #endif // _WX_FILEDIRPICKER_H_