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/filename.h"
16 #include "wx/filedlg.h"
17 #include "wx/dirdlg.h"
20 extern const wxEventType wxEVT_COMMAND_DIRPICKER_CHANGED
;
21 extern 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() { m_dialog
= NULL
; }
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
)
46 Create(parent
, id
, label
, path
, message
, wildcard
,
47 pos
, size
, style
, validator
, name
);
50 virtual ~wxGenericFileDirButton() {}
52 public: // overrideable
54 virtual bool CreateDialog(const wxString
&message
,
55 const wxString
&wildcard
) = 0;
57 // NULL is because of a problem with destruction order in both generic & GTK code
58 virtual wxWindow
*GetDialogParent()
61 virtual wxEventType
GetEventType() const = 0;
68 return wxButton::Destroy();
71 bool Create(wxWindow
*parent
, wxWindowID id
,
72 const wxString
& label
= wxFilePickerWidgetLabel
,
73 const wxString
& path
= wxEmptyString
,
74 const wxString
&message
= wxFileSelectorPromptStr
,
75 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
76 const wxPoint
& pos
= wxDefaultPosition
,
77 const wxSize
& size
= wxDefaultSize
,
79 const wxValidator
& validator
= wxDefaultValidator
,
80 const wxString
& name
= wxFilePickerWidgetNameStr
);
82 // event handler for the click
83 void OnButtonClick(wxCommandEvent
&);
89 //-----------------------------------------------------------------------------
90 // wxGenericFileButton: a button which brings up a wxFileDialog
91 //-----------------------------------------------------------------------------
93 #define wxFILEBTN_DEFAULT_STYLE wxFLP_OPEN
95 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
98 wxGenericFileButton() {}
99 wxGenericFileButton(wxWindow
*parent
,
101 const wxString
& label
= wxFilePickerWidgetLabel
,
102 const wxString
& path
= wxEmptyString
,
103 const wxString
&message
= wxFileSelectorPromptStr
,
104 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
105 const wxPoint
& pos
= wxDefaultPosition
,
106 const wxSize
& size
= wxDefaultSize
,
107 long style
= wxFILEBTN_DEFAULT_STYLE
,
108 const wxValidator
& validator
= wxDefaultValidator
,
109 const wxString
& name
= wxFilePickerWidgetNameStr
)
111 Create(parent
, id
, label
, path
, message
, wildcard
,
112 pos
, size
, style
, validator
, name
);
115 public: // overrideable
117 virtual long GetDialogStyle() const
119 long filedlgstyle
= 0;
121 if (this->HasFlag(wxFLP_OPEN
))
122 filedlgstyle
|= wxFD_OPEN
;
123 if (this->HasFlag(wxFLP_SAVE
))
124 filedlgstyle
|= wxFD_SAVE
;
125 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT
))
126 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
127 if (this->HasFlag(wxFLP_FILE_MUST_EXIST
))
128 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
129 if (this->HasFlag(wxFLP_CHANGE_DIR
))
130 filedlgstyle
|= wxFD_CHANGE_DIR
;
135 virtual bool CreateDialog(const wxString
&message
, const wxString
&wildcard
)
137 m_dialog
= new wxFileDialog(GetDialogParent(), message
,
138 wxEmptyString
, wxEmptyString
,
139 wildcard
, GetDialogStyle());
141 // this sets both the default folder and the default file of the dialog
142 GetDialog()->SetPath(m_path
);
147 wxFileDialog
*GetDialog()
148 { return wxStaticCast(m_dialog
, wxFileDialog
); }
149 void UpdateDialogPath()
150 { GetDialog()->SetPath(m_path
); }
151 void UpdatePathFromDialog()
152 { m_path
= GetDialog()->GetPath(); }
153 wxEventType
GetEventType() const
154 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
157 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
161 //-----------------------------------------------------------------------------
162 // wxGenericDirButton: a button which brings up a wxDirDialog
163 //-----------------------------------------------------------------------------
165 #define wxDIRBTN_DEFAULT_STYLE 0
167 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
170 wxGenericDirButton() {}
171 wxGenericDirButton(wxWindow
*parent
,
173 const wxString
& label
= wxDirPickerWidgetLabel
,
174 const wxString
& path
= wxEmptyString
,
175 const wxString
&message
= wxDirSelectorPromptStr
,
176 const wxPoint
& pos
= wxDefaultPosition
,
177 const wxSize
& size
= wxDefaultSize
,
178 long style
= wxDIRBTN_DEFAULT_STYLE
,
179 const wxValidator
& validator
= wxDefaultValidator
,
180 const wxString
& name
= wxDirPickerWidgetNameStr
)
182 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
183 pos
, size
, style
, validator
, name
);
186 public: // overrideable
188 virtual long GetDialogStyle() const
190 long dirdlgstyle
= 0;
192 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST
))
193 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
194 if (this->HasFlag(wxDIRP_CHANGE_DIR
))
195 dirdlgstyle
|= wxDD_CHANGE_DIR
;
200 virtual bool CreateDialog(const wxString
&message
, const wxString
&WXUNUSED(wildcard
))
202 m_dialog
= new wxDirDialog(GetDialogParent(), message
, m_path
,
207 wxDirDialog
*GetDialog()
208 { return wxStaticCast(m_dialog
, wxDirDialog
); }
209 void UpdateDialogPath()
210 { GetDialog()->SetPath(m_path
); }
211 void UpdatePathFromDialog()
212 { m_path
= GetDialog()->GetPath(); }
213 wxEventType
GetEventType() const
214 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
217 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
221 #endif // _WX_FILEDIRPICKER_H_