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