]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filepickerg.h
Compilation fix after r62754.
[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
8// RCS-ID: $Id$
9// Licence: wxWindows Licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_FILEDIRPICKER_H_
13#define _WX_FILEDIRPICKER_H_
14
45f9b662 15#include "wx/button.h"
ec376c8f
VZ
16#include "wx/filedlg.h"
17#include "wx/dirdlg.h"
18
19
9b11752c
VZ
20wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEvent );
21wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEvent );
ec376c8f
VZ
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:
556151f5 32 wxGenericFileDirButton() { }
ec376c8f
VZ
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 {
ec376c8f
VZ
45 Create(parent, id, label, path, message, wildcard,
46 pos, size, style, validator, name);
47 }
48
49 virtual ~wxGenericFileDirButton() {}
50
af6ad984
VS
51 virtual wxControl *AsControl() { return this; }
52
ec376c8f
VZ
53public: // overrideable
54
556151f5 55 virtual wxDialog *CreateDialog() = 0;
ec376c8f 56
ec376c8f 57 virtual wxWindow *GetDialogParent()
556151f5 58 { return GetParent(); }
ec376c8f
VZ
59
60 virtual wxEventType GetEventType() const = 0;
61
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;
ec376c8f
VZ
80};
81
82
83//-----------------------------------------------------------------------------
84// wxGenericFileButton: a button which brings up a wxFileDialog
85//-----------------------------------------------------------------------------
86
556151f5 87#define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
ec376c8f
VZ
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
556151f5 129 virtual wxDialog *CreateDialog()
ec376c8f 130 {
556151f5 131 wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
ec376c8f 132 wxEmptyString, wxEmptyString,
556151f5 133 m_wildcard, GetDialogStyle());
ec376c8f
VZ
134
135 // this sets both the default folder and the default file of the dialog
556151f5
MW
136 p->SetPath(m_path);
137 return p;
ec376c8f
VZ
138 }
139
c757b5fe
PC
140 wxEventType GetEventType() const
141 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
142
143protected:
556151f5
MW
144 void UpdateDialogPath(wxDialog *p)
145 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
146 void UpdatePathFromDialog(wxDialog *p)
147 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
ec376c8f
VZ
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 {
b5c4d59e 183 long dirdlgstyle = wxDD_DEFAULT_STYLE;
ec376c8f
VZ
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
556151f5 193 virtual wxDialog *CreateDialog()
ec376c8f 194 {
556151f5 195 return new wxDirDialog(GetDialogParent(), m_message, m_path,
ec376c8f 196 GetDialogStyle());
ec376c8f
VZ
197 }
198
c757b5fe
PC
199 wxEventType GetEventType() const
200 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
201
202protected:
556151f5
MW
203 void UpdateDialogPath(wxDialog *p)
204 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
205 void UpdatePathFromDialog(wxDialog *p)
206 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
ec376c8f
VZ
207
208private:
209 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
210};
211
212
213#endif // _WX_FILEDIRPICKER_H_