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() { m_dialog
= NULL
; }
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
)
47 Create(parent
, id
, label
, path
, message
, wildcard
,
48 pos
, size
, style
, validator
, name
);
51 virtual ~wxGenericFileDirButton() {}
53 public: // overrideable
55 virtual bool CreateDialog(const wxString
&message
,
56 const wxString
&wildcard
) = 0;
58 // NULL is because of a problem with destruction order in both generic & GTK code
59 virtual wxWindow
*GetDialogParent()
62 virtual wxEventType
GetEventType() const = 0;
68 if (m_dialog
) m_dialog
->Destroy();
69 return wxButton::Destroy();
72 bool Create(wxWindow
*parent
, wxWindowID id
,
73 const wxString
& label
= wxFilePickerWidgetLabel
,
74 const wxString
& path
= wxEmptyString
,
75 const wxString
&message
= wxFileSelectorPromptStr
,
76 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
77 const wxPoint
& pos
= wxDefaultPosition
,
78 const wxSize
& size
= wxDefaultSize
,
80 const wxValidator
& validator
= wxDefaultValidator
,
81 const wxString
& name
= wxFilePickerWidgetNameStr
);
83 // event handler for the click
84 void OnButtonClick(wxCommandEvent
&);
90 //-----------------------------------------------------------------------------
91 // wxGenericFileButton: a button which brings up a wxFileDialog
92 //-----------------------------------------------------------------------------
94 #define wxFILEBTN_DEFAULT_STYLE wxFLP_OPEN
96 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
99 wxGenericFileButton() {}
100 wxGenericFileButton(wxWindow
*parent
,
102 const wxString
& label
= wxFilePickerWidgetLabel
,
103 const wxString
& path
= wxEmptyString
,
104 const wxString
&message
= wxFileSelectorPromptStr
,
105 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
106 const wxPoint
& pos
= wxDefaultPosition
,
107 const wxSize
& size
= wxDefaultSize
,
108 long style
= wxFILEBTN_DEFAULT_STYLE
,
109 const wxValidator
& validator
= wxDefaultValidator
,
110 const wxString
& name
= wxFilePickerWidgetNameStr
)
112 Create(parent
, id
, label
, path
, message
, wildcard
,
113 pos
, size
, style
, validator
, name
);
116 public: // overrideable
118 virtual long GetDialogStyle() const
120 long filedlgstyle
= 0;
122 if (this->HasFlag(wxFLP_OPEN
))
123 filedlgstyle
|= wxFD_OPEN
;
124 if (this->HasFlag(wxFLP_SAVE
))
125 filedlgstyle
|= wxFD_SAVE
;
126 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT
))
127 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
128 if (this->HasFlag(wxFLP_FILE_MUST_EXIST
))
129 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
130 if (this->HasFlag(wxFLP_CHANGE_DIR
))
131 filedlgstyle
|= wxFD_CHANGE_DIR
;
136 virtual bool CreateDialog(const wxString
&message
, const wxString
&wildcard
)
138 m_dialog
= new wxFileDialog(GetDialogParent(), message
,
139 wxEmptyString
, wxEmptyString
,
140 wildcard
, GetDialogStyle());
142 // this sets both the default folder and the default file of the dialog
143 GetDialog()->SetPath(m_path
);
148 wxFileDialog
*GetDialog()
149 { return wxStaticCast(m_dialog
, wxFileDialog
); }
150 void UpdateDialogPath()
151 { GetDialog()->SetPath(m_path
); }
152 void UpdatePathFromDialog()
153 { m_path
= GetDialog()->GetPath(); }
154 wxEventType
GetEventType() const
155 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
158 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
162 //-----------------------------------------------------------------------------
163 // wxGenericDirButton: a button which brings up a wxDirDialog
164 //-----------------------------------------------------------------------------
166 #define wxDIRBTN_DEFAULT_STYLE 0
168 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
171 wxGenericDirButton() {}
172 wxGenericDirButton(wxWindow
*parent
,
174 const wxString
& label
= wxDirPickerWidgetLabel
,
175 const wxString
& path
= wxEmptyString
,
176 const wxString
&message
= wxDirSelectorPromptStr
,
177 const wxPoint
& pos
= wxDefaultPosition
,
178 const wxSize
& size
= wxDefaultSize
,
179 long style
= wxDIRBTN_DEFAULT_STYLE
,
180 const wxValidator
& validator
= wxDefaultValidator
,
181 const wxString
& name
= wxDirPickerWidgetNameStr
)
183 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
184 pos
, size
, style
, validator
, name
);
187 public: // overrideable
189 virtual long GetDialogStyle() const
191 long dirdlgstyle
= 0;
193 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST
))
194 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
195 if (this->HasFlag(wxDIRP_CHANGE_DIR
))
196 dirdlgstyle
|= wxDD_CHANGE_DIR
;
201 virtual bool CreateDialog(const wxString
&message
, const wxString
&WXUNUSED(wildcard
))
203 m_dialog
= new wxDirDialog(GetDialogParent(), message
, m_path
,
208 wxDirDialog
*GetDialog()
209 { return wxStaticCast(m_dialog
, wxDirDialog
); }
210 void UpdateDialogPath()
211 { GetDialog()->SetPath(m_path
); }
212 void UpdatePathFromDialog()
213 { m_path
= GetDialog()->GetPath(); }
214 wxEventType
GetEventType() const
215 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
218 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
222 #endif // _WX_FILEDIRPICKER_H_