Remove all lines containing cvs/svn "$Id$" keyword.
[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 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_FILEDIRPICKER_H_
12 #define _WX_FILEDIRPICKER_H_
13
14 #include "wx/button.h"
15 #include "wx/filedlg.h"
16 #include "wx/dirdlg.h"
17
18
19 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRPICKER_CHANGED, wxFileDirPickerEvent );
20 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILEPICKER_CHANGED, wxFileDirPickerEvent );
21
22
23 //-----------------------------------------------------------------------------
24 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
25 //-----------------------------------------------------------------------------
26
27 class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
28 public wxFileDirPickerWidgetBase
29 {
30 public:
31 wxGenericFileDirButton() { Init(); }
32 wxGenericFileDirButton(wxWindow *parent,
33 wxWindowID id,
34 const wxString& label = wxFilePickerWidgetLabel,
35 const wxString& path = wxEmptyString,
36 const wxString &message = wxFileSelectorPromptStr,
37 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 long style = 0,
41 const wxValidator& validator = wxDefaultValidator,
42 const wxString& name = wxFilePickerWidgetNameStr)
43 {
44 Init();
45 Create(parent, id, label, path, message, wildcard,
46 pos, size, style, validator, name);
47 }
48
49 virtual wxControl *AsControl() { return this; }
50
51 public: // overridable
52
53 virtual wxDialog *CreateDialog() = 0;
54
55 virtual wxWindow *GetDialogParent()
56 { return GetParent(); }
57
58 virtual wxEventType GetEventType() const = 0;
59
60 virtual void SetInitialDirectory(const wxString& dir);
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 // Initial directory set by SetInitialDirectory() call or empty.
87 wxString m_initialDir;
88
89 private:
90 // common part of all ctors
91 void Init() { m_pickerStyle = -1; }
92 };
93
94
95 //-----------------------------------------------------------------------------
96 // wxGenericFileButton: a button which brings up a wxFileDialog
97 //-----------------------------------------------------------------------------
98
99 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
100
101 class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
102 {
103 public:
104 wxGenericFileButton() {}
105 wxGenericFileButton(wxWindow *parent,
106 wxWindowID id,
107 const wxString& label = wxFilePickerWidgetLabel,
108 const wxString& path = wxEmptyString,
109 const wxString &message = wxFileSelectorPromptStr,
110 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
111 const wxPoint& pos = wxDefaultPosition,
112 const wxSize& size = wxDefaultSize,
113 long style = wxFILEBTN_DEFAULT_STYLE,
114 const wxValidator& validator = wxDefaultValidator,
115 const wxString& name = wxFilePickerWidgetNameStr)
116 {
117 Create(parent, id, label, path, message, wildcard,
118 pos, size, style, validator, name);
119 }
120
121 public: // overridable
122
123 virtual long GetDialogStyle() const
124 {
125 // the derived class must initialize it if it doesn't use the
126 // non-default wxGenericFileDirButton ctor
127 wxASSERT_MSG( m_pickerStyle != -1,
128 "forgot to initialize m_pickerStyle?" );
129
130
131 long filedlgstyle = 0;
132
133 if ( m_pickerStyle & wxFLP_OPEN )
134 filedlgstyle |= wxFD_OPEN;
135 if ( m_pickerStyle & wxFLP_SAVE )
136 filedlgstyle |= wxFD_SAVE;
137 if ( m_pickerStyle & wxFLP_OVERWRITE_PROMPT )
138 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
139 if ( m_pickerStyle & wxFLP_FILE_MUST_EXIST )
140 filedlgstyle |= wxFD_FILE_MUST_EXIST;
141 if ( m_pickerStyle & wxFLP_CHANGE_DIR )
142 filedlgstyle |= wxFD_CHANGE_DIR;
143
144 return filedlgstyle;
145 }
146
147 virtual wxDialog *CreateDialog();
148
149 wxEventType GetEventType() const
150 { return wxEVT_FILEPICKER_CHANGED; }
151
152 protected:
153 void UpdateDialogPath(wxDialog *p)
154 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
155 void UpdatePathFromDialog(wxDialog *p)
156 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
157
158 private:
159 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
160 };
161
162
163 //-----------------------------------------------------------------------------
164 // wxGenericDirButton: a button which brings up a wxDirDialog
165 //-----------------------------------------------------------------------------
166
167 #define wxDIRBTN_DEFAULT_STYLE 0
168
169 class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
170 {
171 public:
172 wxGenericDirButton() {}
173 wxGenericDirButton(wxWindow *parent,
174 wxWindowID id,
175 const wxString& label = wxDirPickerWidgetLabel,
176 const wxString& path = wxEmptyString,
177 const wxString &message = wxDirSelectorPromptStr,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
180 long style = wxDIRBTN_DEFAULT_STYLE,
181 const wxValidator& validator = wxDefaultValidator,
182 const wxString& name = wxDirPickerWidgetNameStr)
183 {
184 Create(parent, id, label, path, message, wxEmptyString,
185 pos, size, style, validator, name);
186 }
187
188 public: // overridable
189
190 virtual long GetDialogStyle() const
191 {
192 long dirdlgstyle = wxDD_DEFAULT_STYLE;
193
194 if ( m_pickerStyle & wxDIRP_DIR_MUST_EXIST )
195 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
196 if ( m_pickerStyle & wxDIRP_CHANGE_DIR )
197 dirdlgstyle |= wxDD_CHANGE_DIR;
198
199 return dirdlgstyle;
200 }
201
202 virtual wxDialog *CreateDialog();
203
204 wxEventType GetEventType() const
205 { return wxEVT_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 // old wxEVT_COMMAND_* constants
218 //#define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
219 //#define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
220
221 #endif // _WX_FILEDIRPICKER_H_