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_DIRPICKER_CHANGED
, wxFileDirPickerEvent
);
21 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_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;
61 virtual void SetInitialDirectory(const wxString
& dir
);
65 bool Create(wxWindow
*parent
, wxWindowID id
,
66 const wxString
& label
= wxFilePickerWidgetLabel
,
67 const wxString
& path
= wxEmptyString
,
68 const wxString
&message
= wxFileSelectorPromptStr
,
69 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
70 const wxPoint
& pos
= wxDefaultPosition
,
71 const wxSize
& size
= wxDefaultSize
,
73 const wxValidator
& validator
= wxDefaultValidator
,
74 const wxString
& name
= wxFilePickerWidgetNameStr
);
76 // event handler for the click
77 void OnButtonClick(wxCommandEvent
&);
80 wxString m_message
, m_wildcard
;
82 // we just store the style passed to the ctor here instead of passing it to
83 // wxButton as some of our bits can conflict with wxButton styles and it
84 // just doesn't make sense to use picker styles for wxButton anyhow
87 // Initial directory set by SetInitialDirectory() call or empty.
88 wxString m_initialDir
;
91 // common part of all ctors
92 void Init() { m_pickerStyle
= -1; }
96 //-----------------------------------------------------------------------------
97 // wxGenericFileButton: a button which brings up a wxFileDialog
98 //-----------------------------------------------------------------------------
100 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
102 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
105 wxGenericFileButton() {}
106 wxGenericFileButton(wxWindow
*parent
,
108 const wxString
& label
= wxFilePickerWidgetLabel
,
109 const wxString
& path
= wxEmptyString
,
110 const wxString
&message
= wxFileSelectorPromptStr
,
111 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
114 long style
= wxFILEBTN_DEFAULT_STYLE
,
115 const wxValidator
& validator
= wxDefaultValidator
,
116 const wxString
& name
= wxFilePickerWidgetNameStr
)
118 Create(parent
, id
, label
, path
, message
, wildcard
,
119 pos
, size
, style
, validator
, name
);
122 public: // overridable
124 virtual long GetDialogStyle() const
126 // the derived class must initialize it if it doesn't use the
127 // non-default wxGenericFileDirButton ctor
128 wxASSERT_MSG( m_pickerStyle
!= -1,
129 "forgot to initialize m_pickerStyle?" );
132 long filedlgstyle
= 0;
134 if ( m_pickerStyle
& wxFLP_OPEN
)
135 filedlgstyle
|= wxFD_OPEN
;
136 if ( m_pickerStyle
& wxFLP_SAVE
)
137 filedlgstyle
|= wxFD_SAVE
;
138 if ( m_pickerStyle
& wxFLP_OVERWRITE_PROMPT
)
139 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
140 if ( m_pickerStyle
& wxFLP_FILE_MUST_EXIST
)
141 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
142 if ( m_pickerStyle
& wxFLP_CHANGE_DIR
)
143 filedlgstyle
|= wxFD_CHANGE_DIR
;
148 virtual wxDialog
*CreateDialog();
150 wxEventType
GetEventType() const
151 { return wxEVT_FILEPICKER_CHANGED
; }
154 void UpdateDialogPath(wxDialog
*p
)
155 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
156 void UpdatePathFromDialog(wxDialog
*p
)
157 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
160 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
164 //-----------------------------------------------------------------------------
165 // wxGenericDirButton: a button which brings up a wxDirDialog
166 //-----------------------------------------------------------------------------
168 #define wxDIRBTN_DEFAULT_STYLE 0
170 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
173 wxGenericDirButton() {}
174 wxGenericDirButton(wxWindow
*parent
,
176 const wxString
& label
= wxDirPickerWidgetLabel
,
177 const wxString
& path
= wxEmptyString
,
178 const wxString
&message
= wxDirSelectorPromptStr
,
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
181 long style
= wxDIRBTN_DEFAULT_STYLE
,
182 const wxValidator
& validator
= wxDefaultValidator
,
183 const wxString
& name
= wxDirPickerWidgetNameStr
)
185 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
186 pos
, size
, style
, validator
, name
);
189 public: // overridable
191 virtual long GetDialogStyle() const
193 long dirdlgstyle
= wxDD_DEFAULT_STYLE
;
195 if ( m_pickerStyle
& wxDIRP_DIR_MUST_EXIST
)
196 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
197 if ( m_pickerStyle
& wxDIRP_CHANGE_DIR
)
198 dirdlgstyle
|= wxDD_CHANGE_DIR
;
203 virtual wxDialog
*CreateDialog();
205 wxEventType
GetEventType() const
206 { return wxEVT_DIRPICKER_CHANGED
; }
209 void UpdateDialogPath(wxDialog
*p
)
210 { wxStaticCast(p
, wxDirDialog
)->SetPath(m_path
); }
211 void UpdatePathFromDialog(wxDialog
*p
)
212 { m_path
= wxStaticCast(p
, wxDirDialog
)->GetPath(); }
215 DECLARE_DYNAMIC_CLASS(wxGenericDirButton
)
218 // old wxEVT_COMMAND_* constants
219 //#define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
220 //#define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
222 #endif // _WX_FILEDIRPICKER_H_