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