1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filepickerg.h
3 // Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_FILEDIRPICKER_H_
12 #define _WX_FILEDIRPICKER_H_
14 #include "wx/button.h"
15 #include "wx/filedlg.h"
16 #include "wx/dirdlg.h"
19 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_DIRPICKER_CHANGED
, wxFileDirPickerEvent
);
20 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_FILEPICKER_CHANGED
, wxFileDirPickerEvent
);
23 //-----------------------------------------------------------------------------
24 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
25 //-----------------------------------------------------------------------------
27 class WXDLLIMPEXP_CORE wxGenericFileDirButton
: public wxButton
,
28 public wxFileDirPickerWidgetBase
31 wxGenericFileDirButton() { Init(); }
32 wxGenericFileDirButton(wxWindow
*parent
,
34 const wxString
& label
= wxFilePickerWidgetLabel
,
35 const wxString
& path
= wxEmptyString
,
36 const wxString
&message
= wxFileSelectorPromptStr
,
37 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
,
41 const wxValidator
& validator
= wxDefaultValidator
,
42 const wxString
& name
= wxFilePickerWidgetNameStr
)
45 Create(parent
, id
, label
, path
, message
, wildcard
,
46 pos
, size
, style
, validator
, name
);
49 virtual wxControl
*AsControl() { return this; }
51 public: // overridable
53 virtual wxDialog
*CreateDialog() = 0;
55 virtual wxWindow
*GetDialogParent()
56 { return GetParent(); }
58 virtual wxEventType
GetEventType() const = 0;
60 virtual void SetInitialDirectory(const wxString
& dir
);
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
86 // Initial directory set by SetInitialDirectory() call or empty.
87 wxString m_initialDir
;
90 // common part of all ctors
91 void Init() { m_pickerStyle
= -1; }
95 //-----------------------------------------------------------------------------
96 // wxGenericFileButton: a button which brings up a wxFileDialog
97 //-----------------------------------------------------------------------------
99 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
101 class WXDLLIMPEXP_CORE wxGenericFileButton
: public wxGenericFileDirButton
104 wxGenericFileButton() {}
105 wxGenericFileButton(wxWindow
*parent
,
107 const wxString
& label
= wxFilePickerWidgetLabel
,
108 const wxString
& path
= wxEmptyString
,
109 const wxString
&message
= wxFileSelectorPromptStr
,
110 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
113 long style
= wxFILEBTN_DEFAULT_STYLE
,
114 const wxValidator
& validator
= wxDefaultValidator
,
115 const wxString
& name
= wxFilePickerWidgetNameStr
)
117 Create(parent
, id
, label
, path
, message
, wildcard
,
118 pos
, size
, style
, validator
, name
);
121 public: // overridable
123 virtual long GetDialogStyle() const
125 // the derived class must initialize it if it doesn't use the
126 // non-default wxGenericFileDirButton ctor
127 wxASSERT_MSG( m_pickerStyle
!= -1,
128 "forgot to initialize m_pickerStyle?" );
131 long filedlgstyle
= 0;
133 if ( m_pickerStyle
& wxFLP_OPEN
)
134 filedlgstyle
|= wxFD_OPEN
;
135 if ( m_pickerStyle
& wxFLP_SAVE
)
136 filedlgstyle
|= wxFD_SAVE
;
137 if ( m_pickerStyle
& wxFLP_OVERWRITE_PROMPT
)
138 filedlgstyle
|= wxFD_OVERWRITE_PROMPT
;
139 if ( m_pickerStyle
& wxFLP_FILE_MUST_EXIST
)
140 filedlgstyle
|= wxFD_FILE_MUST_EXIST
;
141 if ( m_pickerStyle
& wxFLP_CHANGE_DIR
)
142 filedlgstyle
|= wxFD_CHANGE_DIR
;
147 virtual wxDialog
*CreateDialog();
149 wxEventType
GetEventType() const
150 { return wxEVT_FILEPICKER_CHANGED
; }
153 void UpdateDialogPath(wxDialog
*p
)
154 { wxStaticCast(p
, wxFileDialog
)->SetPath(m_path
); }
155 void UpdatePathFromDialog(wxDialog
*p
)
156 { m_path
= wxStaticCast(p
, wxFileDialog
)->GetPath(); }
159 DECLARE_DYNAMIC_CLASS(wxGenericFileButton
)
163 //-----------------------------------------------------------------------------
164 // wxGenericDirButton: a button which brings up a wxDirDialog
165 //-----------------------------------------------------------------------------
167 #define wxDIRBTN_DEFAULT_STYLE 0
169 class WXDLLIMPEXP_CORE wxGenericDirButton
: public wxGenericFileDirButton
172 wxGenericDirButton() {}
173 wxGenericDirButton(wxWindow
*parent
,
175 const wxString
& label
= wxDirPickerWidgetLabel
,
176 const wxString
& path
= wxEmptyString
,
177 const wxString
&message
= wxDirSelectorPromptStr
,
178 const wxPoint
& pos
= wxDefaultPosition
,
179 const wxSize
& size
= wxDefaultSize
,
180 long style
= wxDIRBTN_DEFAULT_STYLE
,
181 const wxValidator
& validator
= wxDefaultValidator
,
182 const wxString
& name
= wxDirPickerWidgetNameStr
)
184 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
185 pos
, size
, style
, validator
, name
);
188 public: // overridable
190 virtual long GetDialogStyle() const
192 long dirdlgstyle
= wxDD_DEFAULT_STYLE
;
194 if ( m_pickerStyle
& wxDIRP_DIR_MUST_EXIST
)
195 dirdlgstyle
|= wxDD_DIR_MUST_EXIST
;
196 if ( m_pickerStyle
& wxDIRP_CHANGE_DIR
)
197 dirdlgstyle
|= wxDD_CHANGE_DIR
;
202 virtual wxDialog
*CreateDialog();
204 wxEventType
GetEventType() const
205 { return wxEVT_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
)
217 // old wxEVT_COMMAND_* constants
218 //#define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
219 //#define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
221 #endif // _WX_FILEDIRPICKER_H_