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() { Init(); }
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 wxControl
*AsControl() { return this; }
52 public: // overridable
54 virtual wxDialog
*CreateDialog() = 0;
56 virtual wxWindow
*GetDialogParent()
57 { return GetParent(); }
59 virtual wxEventType
GetEventType() const = 0;
63 bool Create(wxWindow
*parent
, wxWindowID id
,
64 const wxString
& label
= wxFilePickerWidgetLabel
,
65 const wxString
& path
= wxEmptyString
,
66 const wxString
&message
= wxFileSelectorPromptStr
,
67 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
68 const wxPoint
& pos
= wxDefaultPosition
,
69 const wxSize
& size
= wxDefaultSize
,
71 const wxValidator
& validator
= wxDefaultValidator
,
72 const wxString
& name
= wxFilePickerWidgetNameStr
);
74 // event handler for the click
75 void OnButtonClick(wxCommandEvent
&);
78 wxString m_message
, m_wildcard
;
80 // we just store the style passed to the ctor here instead of passing it to
81 // wxButton as some of our bits can conflict with wxButton styles and it
82 // just doesn't make sense to use picker styles for wxButton anyhow
86 // common part of all ctors
87 void Init() { m_pickerStyle
= -1; }
91 //-----------------------------------------------------------------------------
92 // wxGenericFileButton: a button which brings up a wxFileDialog
93 //-----------------------------------------------------------------------------
95 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
97 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
100 wxGenericFileButton() {}
101 wxGenericFileButton(wxWindow
*parent
,
103 const wxString
& label
= wxFilePickerWidgetLabel
,
104 const wxString
& path
= wxEmptyString
,
105 const wxString
&message
= wxFileSelectorPromptStr
,
106 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
107 const wxPoint
& pos
= wxDefaultPosition
,
108 const wxSize
& size
= wxDefaultSize
,
109 long style
= wxFILEBTN_DEFAULT_STYLE
,
110 const wxValidator
& validator
= wxDefaultValidator
,
111 const wxString
& name
= wxFilePickerWidgetNameStr
)
113 Create(parent
, id
, label
, path
, message
, wildcard
,
114 pos
, size
, style
, validator
, name
);
117 public: // overridable
119 virtual long GetDialogStyle() const
121 // the derived class must initialize it if it doesn't use the
122 // non-default wxGenericFileDirButton ctor
123 wxASSERT_MSG( m_pickerStyle
!= -1,
124 "forgot to initialize m_pickerStyle?" );
127 long filedlgstyle
= 0;
129 if ( m_pickerStyle
& wxFLP_OPEN
)
130 filedlgstyle
|= wxFD_OPEN
;
131 if ( m_pickerStyle
& wxFLP_SAVE
)
132 filedlgstyle
|= wxFD_SAVE
;
133 if ( m_pickerStyle
& wxFLP_OVERWRITE_PROMPT
)
134 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
135 if ( m_pickerStyle
& wxFLP_FILE_MUST_EXIST
)
136 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
137 if ( m_pickerStyle
& wxFLP_CHANGE_DIR
)
138 filedlgstyle
|= wxFD_CHANGE_DIR
;
143 virtual wxDialog
*CreateDialog()
145 wxFileDialog
*p
= new wxFileDialog(GetDialogParent(), m_message
,
146 wxEmptyString
, wxEmptyString
,
147 m_wildcard
, GetDialogStyle());
149 // this sets both the default folder and the default file of the dialog
154 wxEventType
GetEventType() const
155 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
158 void UpdateDialogPath(wxDialog
*p
)
159 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
160 void UpdatePathFromDialog(wxDialog
*p
)
161 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
164 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
168 //-----------------------------------------------------------------------------
169 // wxGenericDirButton: a button which brings up a wxDirDialog
170 //-----------------------------------------------------------------------------
172 #define wxDIRBTN_DEFAULT_STYLE 0
174 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
177 wxGenericDirButton() {}
178 wxGenericDirButton(wxWindow
*parent
,
180 const wxString
& label
= wxDirPickerWidgetLabel
,
181 const wxString
& path
= wxEmptyString
,
182 const wxString
&message
= wxDirSelectorPromptStr
,
183 const wxPoint
& pos
= wxDefaultPosition
,
184 const wxSize
& size
= wxDefaultSize
,
185 long style
= wxDIRBTN_DEFAULT_STYLE
,
186 const wxValidator
& validator
= wxDefaultValidator
,
187 const wxString
& name
= wxDirPickerWidgetNameStr
)
189 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
190 pos
, size
, style
, validator
, name
);
193 public: // overridable
195 virtual long GetDialogStyle() const
197 long dirdlgstyle
= wxDD_DEFAULT_STYLE
;
199 if ( m_pickerStyle
& wxDIRP_DIR_MUST_EXIST
)
200 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
201 if ( m_pickerStyle
& wxDIRP_CHANGE_DIR
)
202 dirdlgstyle
|= wxDD_CHANGE_DIR
;
207 virtual wxDialog
*CreateDialog()
209 return new wxDirDialog(GetDialogParent(), m_message
, m_path
,
213 wxEventType
GetEventType() const
214 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
217 void UpdateDialogPath(wxDialog
*p
)
218 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
219 void UpdatePathFromDialog(wxDialog
*p
)
220 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
223 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
227 #endif // _WX_FILEDIRPICKER_H_