Commit pickers-fixes.patch added to 1472329 (Francesco Montorsi)
[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/filename.h"
17 #include "wx/filedlg.h"
18 #include "wx/dirdlg.h"
19
20
21 extern WXDLLEXPORT_DATA(const wxEventType) wxEVT_COMMAND_DIRPICKER_CHANGED;
22 extern WXDLLEXPORT_DATA(const wxEventType) wxEVT_COMMAND_FILEPICKER_CHANGED;
23
24
25 //-----------------------------------------------------------------------------
26 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
27 //-----------------------------------------------------------------------------
28
29 class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
30 public wxFileDirPickerWidgetBase
31 {
32 public:
33 wxGenericFileDirButton() { }
34 wxGenericFileDirButton(wxWindow *parent,
35 wxWindowID id,
36 const wxString& label = wxFilePickerWidgetLabel,
37 const wxString& path = wxEmptyString,
38 const wxString &message = wxFileSelectorPromptStr,
39 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
40 const wxPoint& pos = wxDefaultPosition,
41 const wxSize& size = wxDefaultSize,
42 long style = 0,
43 const wxValidator& validator = wxDefaultValidator,
44 const wxString& name = wxFilePickerWidgetNameStr)
45 {
46 Create(parent, id, label, path, message, wildcard,
47 pos, size, style, validator, name);
48 }
49
50 virtual ~wxGenericFileDirButton() {}
51
52 public: // overrideable
53
54 virtual wxDialog *CreateDialog() = 0;
55
56 virtual wxWindow *GetDialogParent()
57 { return GetParent(); }
58
59 virtual wxEventType GetEventType() const = 0;
60
61 public:
62
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,
70 long style = 0,
71 const wxValidator& validator = wxDefaultValidator,
72 const wxString& name = wxFilePickerWidgetNameStr);
73
74 // event handler for the click
75 void OnButtonClick(wxCommandEvent &);
76
77 protected:
78 wxString m_message, m_wildcard;
79 };
80
81
82 //-----------------------------------------------------------------------------
83 // wxGenericFileButton: a button which brings up a wxFileDialog
84 //-----------------------------------------------------------------------------
85
86 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
87
88 class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
89 {
90 public:
91 wxGenericFileButton() {}
92 wxGenericFileButton(wxWindow *parent,
93 wxWindowID id,
94 const wxString& label = wxFilePickerWidgetLabel,
95 const wxString& path = wxEmptyString,
96 const wxString &message = wxFileSelectorPromptStr,
97 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
98 const wxPoint& pos = wxDefaultPosition,
99 const wxSize& size = wxDefaultSize,
100 long style = wxFILEBTN_DEFAULT_STYLE,
101 const wxValidator& validator = wxDefaultValidator,
102 const wxString& name = wxFilePickerWidgetNameStr)
103 {
104 Create(parent, id, label, path, message, wildcard,
105 pos, size, style, validator, name);
106 }
107
108 public: // overrideable
109
110 virtual long GetDialogStyle() const
111 {
112 long filedlgstyle = 0;
113
114 if (this->HasFlag(wxFLP_OPEN))
115 filedlgstyle |= wxFD_OPEN;
116 if (this->HasFlag(wxFLP_SAVE))
117 filedlgstyle |= wxFD_SAVE;
118 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT))
119 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
120 if (this->HasFlag(wxFLP_FILE_MUST_EXIST))
121 filedlgstyle |= wxFD_FILE_MUST_EXIST;
122 if (this->HasFlag(wxFLP_CHANGE_DIR))
123 filedlgstyle |= wxFD_CHANGE_DIR;
124
125 return filedlgstyle;
126 }
127
128 virtual wxDialog *CreateDialog()
129 {
130 wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
131 wxEmptyString, wxEmptyString,
132 m_wildcard, GetDialogStyle());
133
134 // this sets both the default folder and the default file of the dialog
135 p->SetPath(m_path);
136 return p;
137 }
138
139 void UpdateDialogPath(wxDialog *p)
140 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
141 void UpdatePathFromDialog(wxDialog *p)
142 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
143 wxEventType GetEventType() const
144 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
145
146 private:
147 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
148 };
149
150
151 //-----------------------------------------------------------------------------
152 // wxGenericDirButton: a button which brings up a wxDirDialog
153 //-----------------------------------------------------------------------------
154
155 #define wxDIRBTN_DEFAULT_STYLE 0
156
157 class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
158 {
159 public:
160 wxGenericDirButton() {}
161 wxGenericDirButton(wxWindow *parent,
162 wxWindowID id,
163 const wxString& label = wxDirPickerWidgetLabel,
164 const wxString& path = wxEmptyString,
165 const wxString &message = wxDirSelectorPromptStr,
166 const wxPoint& pos = wxDefaultPosition,
167 const wxSize& size = wxDefaultSize,
168 long style = wxDIRBTN_DEFAULT_STYLE,
169 const wxValidator& validator = wxDefaultValidator,
170 const wxString& name = wxDirPickerWidgetNameStr)
171 {
172 Create(parent, id, label, path, message, wxEmptyString,
173 pos, size, style, validator, name);
174 }
175
176 public: // overrideable
177
178 virtual long GetDialogStyle() const
179 {
180 long dirdlgstyle = 0;
181
182 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST))
183 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
184 if (this->HasFlag(wxDIRP_CHANGE_DIR))
185 dirdlgstyle |= wxDD_CHANGE_DIR;
186
187 return dirdlgstyle;
188 }
189
190 virtual wxDialog *CreateDialog()
191 {
192 return new wxDirDialog(GetDialogParent(), m_message, m_path,
193 GetDialogStyle());
194 }
195
196 void UpdateDialogPath(wxDialog *p)
197 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
198 void UpdatePathFromDialog(wxDialog *p)
199 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
200 wxEventType GetEventType() const
201 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
202
203 private:
204 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
205 };
206
207
208 #endif // _WX_FILEDIRPICKER_H_