]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filepickerg.h
Use wxGetTranslation() instead of _() in the public headers.
[wxWidgets.git] / include / wx / generic / filepickerg.h
CommitLineData
ec376c8f
VZ
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
ec376c8f
VZ
8// Licence: wxWindows Licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_FILEDIRPICKER_H_
12#define _WX_FILEDIRPICKER_H_
13
45f9b662 14#include "wx/button.h"
ec376c8f
VZ
15#include "wx/filedlg.h"
16#include "wx/dirdlg.h"
17
18
ce7fe42e
VZ
19wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRPICKER_CHANGED, wxFileDirPickerEvent );
20wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILEPICKER_CHANGED, wxFileDirPickerEvent );
ec376c8f
VZ
21
22
23//-----------------------------------------------------------------------------
24// wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
25//-----------------------------------------------------------------------------
26
27class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
28 public wxFileDirPickerWidgetBase
29{
30public:
459128ac 31 wxGenericFileDirButton() { Init(); }
ec376c8f
VZ
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 {
459128ac 44 Init();
ec376c8f
VZ
45 Create(parent, id, label, path, message, wildcard,
46 pos, size, style, validator, name);
47 }
48
af6ad984
VS
49 virtual wxControl *AsControl() { return this; }
50
d13b34d3 51public: // overridable
ec376c8f 52
556151f5 53 virtual wxDialog *CreateDialog() = 0;
ec376c8f 54
ec376c8f 55 virtual wxWindow *GetDialogParent()
556151f5 56 { return GetParent(); }
ec376c8f
VZ
57
58 virtual wxEventType GetEventType() const = 0;
59
75cb911c
VZ
60 virtual void SetInitialDirectory(const wxString& dir);
61
ec376c8f
VZ
62public:
63
ec376c8f
VZ
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
556151f5
MW
78protected:
79 wxString m_message, m_wildcard;
8eca1205
VZ
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;
459128ac 85
75cb911c
VZ
86 // Initial directory set by SetInitialDirectory() call or empty.
87 wxString m_initialDir;
88
459128ac
VZ
89private:
90 // common part of all ctors
91 void Init() { m_pickerStyle = -1; }
ec376c8f
VZ
92};
93
94
95//-----------------------------------------------------------------------------
96// wxGenericFileButton: a button which brings up a wxFileDialog
97//-----------------------------------------------------------------------------
98
556151f5 99#define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
ec376c8f
VZ
100
101class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
102{
103public:
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
d13b34d3 121public: // overridable
ec376c8f
VZ
122
123 virtual long GetDialogStyle() const
124 {
459128ac
VZ
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
ec376c8f
VZ
131 long filedlgstyle = 0;
132
8eca1205 133 if ( m_pickerStyle & wxFLP_OPEN )
ec376c8f 134 filedlgstyle |= wxFD_OPEN;
8eca1205 135 if ( m_pickerStyle & wxFLP_SAVE )
ec376c8f 136 filedlgstyle |= wxFD_SAVE;
8eca1205 137 if ( m_pickerStyle & wxFLP_OVERWRITE_PROMPT )
ec376c8f 138 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
8eca1205 139 if ( m_pickerStyle & wxFLP_FILE_MUST_EXIST )
ec376c8f 140 filedlgstyle |= wxFD_FILE_MUST_EXIST;
8eca1205 141 if ( m_pickerStyle & wxFLP_CHANGE_DIR )
ec376c8f
VZ
142 filedlgstyle |= wxFD_CHANGE_DIR;
143
144 return filedlgstyle;
145 }
146
75cb911c 147 virtual wxDialog *CreateDialog();
ec376c8f 148
c757b5fe 149 wxEventType GetEventType() const
ce7fe42e 150 { return wxEVT_FILEPICKER_CHANGED; }
c757b5fe
PC
151
152protected:
556151f5
MW
153 void UpdateDialogPath(wxDialog *p)
154 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
155 void UpdatePathFromDialog(wxDialog *p)
156 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
ec376c8f
VZ
157
158private:
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
169class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
170{
171public:
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
d13b34d3 188public: // overridable
ec376c8f
VZ
189
190 virtual long GetDialogStyle() const
191 {
b5c4d59e 192 long dirdlgstyle = wxDD_DEFAULT_STYLE;
ec376c8f 193
8eca1205 194 if ( m_pickerStyle & wxDIRP_DIR_MUST_EXIST )
ec376c8f 195 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
8eca1205 196 if ( m_pickerStyle & wxDIRP_CHANGE_DIR )
ec376c8f
VZ
197 dirdlgstyle |= wxDD_CHANGE_DIR;
198
199 return dirdlgstyle;
200 }
201
75cb911c 202 virtual wxDialog *CreateDialog();
ec376c8f 203
c757b5fe 204 wxEventType GetEventType() const
ce7fe42e 205 { return wxEVT_DIRPICKER_CHANGED; }
c757b5fe
PC
206
207protected:
556151f5
MW
208 void UpdateDialogPath(wxDialog *p)
209 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
210 void UpdatePathFromDialog(wxDialog *p)
211 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
ec376c8f
VZ
212
213private:
214 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
215};
216
ce7fe42e
VZ
217// old wxEVT_COMMAND_* constants
218//#define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
219//#define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
ec376c8f
VZ
220
221#endif // _WX_FILEDIRPICKER_H_