]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/filepicker.h
Add const to GetTargetSize()
[wxWidgets.git] / include / wx / gtk / filepicker.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/filedirpicker.h
3 // Purpose: wxFileButton, wxDirButton header
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_GTK_FILEPICKER_H_
13 #define _WX_GTK_FILEPICKER_H_
14
15 // since GtkColorButton is available only for GTK+ >= 2.4,
16 // we need to use generic versions if we detect (at runtime)
17 // that GTK+ < 2.4
18 #include "wx/generic/filepickerg.h"
19
20
21
22 //-----------------------------------------------------------------------------
23 // wxFileButton and wxDirButton shared code
24 // (cannot be a base class since they need to derive from wxGenericFileButton
25 // and from wxGenericDirButton classes !)
26 //-----------------------------------------------------------------------------
27
28 #define FILEDIRBTN_OVERRIDES \
29 /* NULL is because of a problem with destruction order which happens */ \
30 /* if we pass GetParent(): in fact, this GTK native implementation */ \
31 /* needs to create the dialog in ::Create() and not for each user */ \
32 /* request in response to the user click as the generic implementation */ \
33 /* does. */ \
34 virtual wxWindow *GetDialogParent() \
35 { \
36 return NULL; \
37 } \
38 \
39 virtual bool Destroy() \
40 { \
41 m_dialog->Destroy(); \
42 return wxButton::Destroy(); \
43 } \
44 \
45 /* even if wx derive from wxGenericFileButton, i.e. from wxButton, our */ \
46 /* native GTK+ widget does not derive from GtkButton thus *all* uses */ \
47 /* GTK_BUTTON(m_widget) macro done by wxButton must be bypassed to */ \
48 /* avoid bunch of GTK+ warnings like: */ \
49 /* invalid cast from `GtkFileChooserButton' to `GtkButton' */ \
50 /* so, override wxButton::GTKGetWindow and return NULL as GTK+ doesn't */ \
51 /* give us access to the internal GdkWindow of a GtkFileChooserButton */ \
52 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const \
53 { return NULL; }
54
55
56 //-----------------------------------------------------------------------------
57 // wxFileButton
58 //-----------------------------------------------------------------------------
59
60 class WXDLLIMPEXP_CORE wxFileButton : public wxGenericFileButton
61 {
62 public:
63 wxFileButton() { m_dialog = NULL; }
64 wxFileButton(wxWindow *parent,
65 wxWindowID id,
66 const wxString& label = wxFilePickerWidgetLabel,
67 const wxString &path = wxEmptyString,
68 const wxString &message = wxFileSelectorPromptStr,
69 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = wxFILEBTN_DEFAULT_STYLE,
73 const wxValidator& validator = wxDefaultValidator,
74 const wxString& name = wxFilePickerWidgetNameStr)
75 {
76 m_dialog = NULL;
77 Create(parent, id, label, path, message, wildcard,
78 pos, size, style, validator, name);
79 }
80
81 virtual ~wxFileButton();
82
83
84 public: // overrides
85
86 bool Create(wxWindow *parent,
87 wxWindowID id,
88 const wxString& label = wxFilePickerWidgetLabel,
89 const wxString &path = wxEmptyString,
90 const wxString &message = wxFileSelectorPromptStr,
91 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
92 const wxPoint& pos = wxDefaultPosition,
93 const wxSize& size = wxDefaultSize,
94 long style = 0,
95 const wxValidator& validator = wxDefaultValidator,
96 const wxString& name = wxFilePickerWidgetNameStr);
97
98 // event handler for the click
99 void OnDialogOK(wxCommandEvent &);
100
101
102 public: // some overrides
103
104 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_ACTION_SAVE
105 // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN; since wxFD_SAVE
106 // is not supported, wxFD_OVERWRITE_PROMPT isn't too...
107 virtual long GetDialogStyle() const
108 {
109 return (wxGenericFileButton::GetDialogStyle() &
110 ~(wxFD_SAVE | wxFD_OVERWRITE_PROMPT)) | wxFD_OPEN;
111 }
112
113 virtual void SetPath(const wxString &str);
114
115 // see macro defined above
116 FILEDIRBTN_OVERRIDES
117
118 protected:
119 wxDialog *m_dialog;
120
121 private:
122 DECLARE_DYNAMIC_CLASS(wxFileButton)
123 };
124
125
126 //-----------------------------------------------------------------------------
127 // wxDirButton
128 //-----------------------------------------------------------------------------
129
130 class WXDLLIMPEXP_CORE wxDirButton : public wxGenericDirButton
131 {
132 public:
133 wxDirButton() { Init(); }
134 wxDirButton(wxWindow *parent,
135 wxWindowID id,
136 const wxString& label = wxFilePickerWidgetLabel,
137 const wxString &path = wxEmptyString,
138 const wxString &message = wxFileSelectorPromptStr,
139 const wxPoint& pos = wxDefaultPosition,
140 const wxSize& size = wxDefaultSize,
141 long style = wxDIRBTN_DEFAULT_STYLE,
142 const wxValidator& validator = wxDefaultValidator,
143 const wxString& name = wxFilePickerWidgetNameStr)
144 {
145 Init();
146
147 Create(parent, id, label, path, message, wxEmptyString,
148 pos, size, style, validator, name);
149 }
150
151 virtual ~wxDirButton();
152
153
154 public: // overrides
155
156 bool Create(wxWindow *parent,
157 wxWindowID id,
158 const wxString& label = wxFilePickerWidgetLabel,
159 const wxString &path = wxEmptyString,
160 const wxString &message = wxFileSelectorPromptStr,
161 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
162 const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize,
164 long style = 0,
165 const wxValidator& validator = wxDefaultValidator,
166 const wxString& name = wxFilePickerWidgetNameStr);
167
168
169 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
170 // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
171 long GetDialogStyle() const
172 {
173 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST);
174 }
175
176 virtual void SetPath(const wxString &str);
177
178 // see macro defined above
179 FILEDIRBTN_OVERRIDES
180
181 protected:
182 // common part of all ctors
183 void Init()
184 {
185 m_dialog = NULL;
186 m_bIgnoreNextChange = false;
187 }
188
189 wxDialog *m_dialog;
190
191 public: // used by the GTK callback only
192
193 bool m_bIgnoreNextChange;
194
195 void UpdatePath(const char *gtkpath)
196 { m_path = wxString::FromAscii(gtkpath); }
197
198 private:
199 DECLARE_DYNAMIC_CLASS(wxDirButton)
200 };
201
202 #undef FILEDIRBTN_OVERRIDES
203
204 #endif // _WX_GTK_FILEPICKER_H_
205