Use correct style for the dialog shown by generic file/dir pickers.
[wxWidgets.git] / include / wx / generic / filepickerg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filepickerg.h
3 // Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
4 // Author: Francesco Montorsi
5 // Modified by:
6 // Created: 14/4/2006
7 // Copyright: (c) Francesco Montorsi
8 // RCS-ID: $Id$
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FILEDIRPICKER_H_
13 #define _WX_FILEDIRPICKER_H_
14
15 #include "wx/button.h"
16 #include "wx/filedlg.h"
17 #include "wx/dirdlg.h"
18
19
20 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEvent );
21 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEvent );
22
23
24 //-----------------------------------------------------------------------------
25 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
26 //-----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
29 public wxFileDirPickerWidgetBase
30 {
31 public:
32 wxGenericFileDirButton() { }
33 wxGenericFileDirButton(wxWindow *parent,
34 wxWindowID id,
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,
41 long style = 0,
42 const wxValidator& validator = wxDefaultValidator,
43 const wxString& name = wxFilePickerWidgetNameStr)
44 {
45 Create(parent, id, label, path, message, wildcard,
46 pos, size, style, validator, name);
47 }
48
49 virtual ~wxGenericFileDirButton() {}
50
51 virtual wxControl *AsControl() { return this; }
52
53 public: // overrideable
54
55 virtual wxDialog *CreateDialog() = 0;
56
57 virtual wxWindow *GetDialogParent()
58 { return GetParent(); }
59
60 virtual wxEventType GetEventType() const = 0;
61
62 public:
63
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,
71 long style = 0,
72 const wxValidator& validator = wxDefaultValidator,
73 const wxString& name = wxFilePickerWidgetNameStr);
74
75 // event handler for the click
76 void OnButtonClick(wxCommandEvent &);
77
78 protected:
79 wxString m_message, m_wildcard;
80
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
84 long m_pickerStyle;
85 };
86
87
88 //-----------------------------------------------------------------------------
89 // wxGenericFileButton: a button which brings up a wxFileDialog
90 //-----------------------------------------------------------------------------
91
92 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
93
94 class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
95 {
96 public:
97 wxGenericFileButton() {}
98 wxGenericFileButton(wxWindow *parent,
99 wxWindowID id,
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)
109 {
110 Create(parent, id, label, path, message, wildcard,
111 pos, size, style, validator, name);
112 }
113
114 public: // overrideable
115
116 virtual long GetDialogStyle() const
117 {
118 long filedlgstyle = 0;
119
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;
130
131 return filedlgstyle;
132 }
133
134 virtual wxDialog *CreateDialog()
135 {
136 wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
137 wxEmptyString, wxEmptyString,
138 m_wildcard, GetDialogStyle());
139
140 // this sets both the default folder and the default file of the dialog
141 p->SetPath(m_path);
142 return p;
143 }
144
145 wxEventType GetEventType() const
146 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
147
148 protected:
149 void UpdateDialogPath(wxDialog *p)
150 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
151 void UpdatePathFromDialog(wxDialog *p)
152 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
153
154 private:
155 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
156 };
157
158
159 //-----------------------------------------------------------------------------
160 // wxGenericDirButton: a button which brings up a wxDirDialog
161 //-----------------------------------------------------------------------------
162
163 #define wxDIRBTN_DEFAULT_STYLE 0
164
165 class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
166 {
167 public:
168 wxGenericDirButton() {}
169 wxGenericDirButton(wxWindow *parent,
170 wxWindowID id,
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)
179 {
180 Create(parent, id, label, path, message, wxEmptyString,
181 pos, size, style, validator, name);
182 }
183
184 public: // overrideable
185
186 virtual long GetDialogStyle() const
187 {
188 long dirdlgstyle = wxDD_DEFAULT_STYLE;
189
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;
194
195 return dirdlgstyle;
196 }
197
198 virtual wxDialog *CreateDialog()
199 {
200 return new wxDirDialog(GetDialogParent(), m_message, m_path,
201 GetDialogStyle());
202 }
203
204 wxEventType GetEventType() const
205 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
206
207 protected:
208 void UpdateDialogPath(wxDialog *p)
209 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
210 void UpdatePathFromDialog(wxDialog *p)
211 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
212
213 private:
214 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
215 };
216
217
218 #endif // _WX_FILEDIRPICKER_H_