]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filepickerg.h
Further wxAUI commits
[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 extern WXDLLEXPORT_DATA(const wxEventType) wxEVT_COMMAND_DIRPICKER_CHANGED;
21 extern WXDLLEXPORT_DATA(const wxEventType) wxEVT_COMMAND_FILEPICKER_CHANGED;
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 public: // overrideable
52
53 virtual wxDialog *CreateDialog() = 0;
54
55 virtual wxWindow *GetDialogParent()
56 { return GetParent(); }
57
58 virtual wxEventType GetEventType() const = 0;
59
60 public:
61
62 bool Create(wxWindow *parent, wxWindowID id,
63 const wxString& label = wxFilePickerWidgetLabel,
64 const wxString& path = wxEmptyString,
65 const wxString &message = wxFileSelectorPromptStr,
66 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
67 const wxPoint& pos = wxDefaultPosition,
68 const wxSize& size = wxDefaultSize,
69 long style = 0,
70 const wxValidator& validator = wxDefaultValidator,
71 const wxString& name = wxFilePickerWidgetNameStr);
72
73 // event handler for the click
74 void OnButtonClick(wxCommandEvent &);
75
76 protected:
77 wxString m_message, m_wildcard;
78 };
79
80
81 //-----------------------------------------------------------------------------
82 // wxGenericFileButton: a button which brings up a wxFileDialog
83 //-----------------------------------------------------------------------------
84
85 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
86
87 class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
88 {
89 public:
90 wxGenericFileButton() {}
91 wxGenericFileButton(wxWindow *parent,
92 wxWindowID id,
93 const wxString& label = wxFilePickerWidgetLabel,
94 const wxString& path = wxEmptyString,
95 const wxString &message = wxFileSelectorPromptStr,
96 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
97 const wxPoint& pos = wxDefaultPosition,
98 const wxSize& size = wxDefaultSize,
99 long style = wxFILEBTN_DEFAULT_STYLE,
100 const wxValidator& validator = wxDefaultValidator,
101 const wxString& name = wxFilePickerWidgetNameStr)
102 {
103 Create(parent, id, label, path, message, wildcard,
104 pos, size, style, validator, name);
105 }
106
107 public: // overrideable
108
109 virtual long GetDialogStyle() const
110 {
111 long filedlgstyle = 0;
112
113 if (this->HasFlag(wxFLP_OPEN))
114 filedlgstyle |= wxFD_OPEN;
115 if (this->HasFlag(wxFLP_SAVE))
116 filedlgstyle |= wxFD_SAVE;
117 if (this->HasFlag(wxFLP_OVERWRITE_PROMPT))
118 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
119 if (this->HasFlag(wxFLP_FILE_MUST_EXIST))
120 filedlgstyle |= wxFD_FILE_MUST_EXIST;
121 if (this->HasFlag(wxFLP_CHANGE_DIR))
122 filedlgstyle |= wxFD_CHANGE_DIR;
123
124 return filedlgstyle;
125 }
126
127 virtual wxDialog *CreateDialog()
128 {
129 wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
130 wxEmptyString, wxEmptyString,
131 m_wildcard, GetDialogStyle());
132
133 // this sets both the default folder and the default file of the dialog
134 p->SetPath(m_path);
135 return p;
136 }
137
138 wxEventType GetEventType() const
139 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
140
141 protected:
142 void UpdateDialogPath(wxDialog *p)
143 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
144 void UpdatePathFromDialog(wxDialog *p)
145 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
146
147 private:
148 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
149 };
150
151
152 //-----------------------------------------------------------------------------
153 // wxGenericDirButton: a button which brings up a wxDirDialog
154 //-----------------------------------------------------------------------------
155
156 #define wxDIRBTN_DEFAULT_STYLE 0
157
158 class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
159 {
160 public:
161 wxGenericDirButton() {}
162 wxGenericDirButton(wxWindow *parent,
163 wxWindowID id,
164 const wxString& label = wxDirPickerWidgetLabel,
165 const wxString& path = wxEmptyString,
166 const wxString &message = wxDirSelectorPromptStr,
167 const wxPoint& pos = wxDefaultPosition,
168 const wxSize& size = wxDefaultSize,
169 long style = wxDIRBTN_DEFAULT_STYLE,
170 const wxValidator& validator = wxDefaultValidator,
171 const wxString& name = wxDirPickerWidgetNameStr)
172 {
173 Create(parent, id, label, path, message, wxEmptyString,
174 pos, size, style, validator, name);
175 }
176
177 public: // overrideable
178
179 virtual long GetDialogStyle() const
180 {
181 long dirdlgstyle = 0;
182
183 if (this->HasFlag(wxDIRP_DIR_MUST_EXIST))
184 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
185 if (this->HasFlag(wxDIRP_CHANGE_DIR))
186 dirdlgstyle |= wxDD_CHANGE_DIR;
187
188 return dirdlgstyle;
189 }
190
191 virtual wxDialog *CreateDialog()
192 {
193 return new wxDirDialog(GetDialogParent(), m_message, m_path,
194 GetDialogStyle());
195 }
196
197 wxEventType GetEventType() const
198 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
199
200 protected:
201 void UpdateDialogPath(wxDialog *p)
202 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
203 void UpdatePathFromDialog(wxDialog *p)
204 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
205
206 private:
207 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
208 };
209
210
211 #endif // _WX_FILEDIRPICKER_H_