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