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
;
81 // we just store the style passed to the ctor here instead of passing it to
82 // wxButton as some of our bits can conflict with wxButton styles and it
83 // just doesn't make sense to use picker styles for wxButton anyhow
88 //-----------------------------------------------------------------------------
89 // wxGenericFileButton: a button which brings up a wxFileDialog
90 //-----------------------------------------------------------------------------
92 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
94 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
97 wxGenericFileButton() {}
98 wxGenericFileButton(wxWindow
*parent
,
100 const wxString
& label
= wxFilePickerWidgetLabel
,
101 const wxString
& path
= wxEmptyString
,
102 const wxString
&message
= wxFileSelectorPromptStr
,
103 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
104 const wxPoint
& pos
= wxDefaultPosition
,
105 const wxSize
& size
= wxDefaultSize
,
106 long style
= wxFILEBTN_DEFAULT_STYLE
,
107 const wxValidator
& validator
= wxDefaultValidator
,
108 const wxString
& name
= wxFilePickerWidgetNameStr
)
110 Create(parent
, id
, label
, path
, message
, wildcard
,
111 pos
, size
, style
, validator
, name
);
114 public: // overrideable
116 virtual long GetDialogStyle() const
118 long filedlgstyle
= 0;
120 if ( m_pickerStyle
& wxFLP_OPEN
)
121 filedlgstyle
|= wxFD_OPEN
;
122 if ( m_pickerStyle
& wxFLP_SAVE
)
123 filedlgstyle
|= wxFD_SAVE
;
124 if ( m_pickerStyle
& wxFLP_OVERWRITE_PROMPT
)
125 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
126 if ( m_pickerStyle
& wxFLP_FILE_MUST_EXIST
)
127 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
128 if ( m_pickerStyle
& wxFLP_CHANGE_DIR
)
129 filedlgstyle
|= wxFD_CHANGE_DIR
;
134 virtual wxDialog
*CreateDialog()
136 wxFileDialog
*p
= new wxFileDialog(GetDialogParent(), m_message
,
137 wxEmptyString
, wxEmptyString
,
138 m_wildcard
, GetDialogStyle());
140 // this sets both the default folder and the default file of the dialog
145 wxEventType
GetEventType() const
146 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
149 void UpdateDialogPath(wxDialog
*p
)
150 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
151 void UpdatePathFromDialog(wxDialog
*p
)
152 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
155 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
159 //-----------------------------------------------------------------------------
160 // wxGenericDirButton: a button which brings up a wxDirDialog
161 //-----------------------------------------------------------------------------
163 #define wxDIRBTN_DEFAULT_STYLE 0
165 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
168 wxGenericDirButton() {}
169 wxGenericDirButton(wxWindow
*parent
,
171 const wxString
& label
= wxDirPickerWidgetLabel
,
172 const wxString
& path
= wxEmptyString
,
173 const wxString
&message
= wxDirSelectorPromptStr
,
174 const wxPoint
& pos
= wxDefaultPosition
,
175 const wxSize
& size
= wxDefaultSize
,
176 long style
= wxDIRBTN_DEFAULT_STYLE
,
177 const wxValidator
& validator
= wxDefaultValidator
,
178 const wxString
& name
= wxDirPickerWidgetNameStr
)
180 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
181 pos
, size
, style
, validator
, name
);
184 public: // overrideable
186 virtual long GetDialogStyle() const
188 long dirdlgstyle
= wxDD_DEFAULT_STYLE
;
190 if ( m_pickerStyle
& wxDIRP_DIR_MUST_EXIST
)
191 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
192 if ( m_pickerStyle
& wxDIRP_CHANGE_DIR
)
193 dirdlgstyle
|= wxDD_CHANGE_DIR
;
198 virtual wxDialog
*CreateDialog()
200 return new wxDirDialog(GetDialogParent(), m_message
, m_path
,
204 wxEventType
GetEventType() const
205 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
208 void UpdateDialogPath(wxDialog
*p
)
209 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
210 void UpdatePathFromDialog(wxDialog
*p
)
211 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
214 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
218 #endif // _WX_FILEDIRPICKER_H_