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