1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/filedirpicker.h
3 // Purpose: wxFileButton, wxDirButton header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GTK_FILEPICKER_H_
13 #define _WX_GTK_FILEPICKER_H_
15 // since GtkColorButton is available only for GTK+ >= 2.4,
16 // we need to use generic versions if we detect (at runtime)
18 #include "wx/generic/filepickerg.h"
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 //-----------------------------------------------------------------------------
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 */ \
32 virtual wxWindow *GetDialogParent() \
37 virtual bool Destroy() \
40 m_dialog->Destroy(); \
41 return wxButton::Destroy(); \
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 */ \
53 GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const \
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 class WXDLLIMPEXP_CORE wxFileButton
: public wxGenericFileButton
64 wxFileButton() { Init(); }
65 wxFileButton(wxWindow
*parent
,
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
)
78 m_pickerStyle
= style
;
79 Create(parent
, id
, label
, path
, message
, wildcard
,
80 pos
, size
, style
, validator
, name
);
83 virtual ~wxFileButton();
88 bool Create(wxWindow
*parent
,
90 const wxString
& label
= wxFilePickerWidgetLabel
,
91 const wxString
&path
= wxEmptyString
,
92 const wxString
&message
= wxFileSelectorPromptStr
,
93 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
94 const wxPoint
& pos
= wxDefaultPosition
,
95 const wxSize
& size
= wxDefaultSize
,
97 const wxValidator
& validator
= wxDefaultValidator
,
98 const wxString
& name
= wxFilePickerWidgetNameStr
);
100 // event handler for the click
101 void OnDialogOK(wxCommandEvent
&);
103 virtual void SetPath(const wxString
&str
);
104 virtual void SetInitialDirectory(const wxString
& dir
);
106 // see macro defined above
110 virtual bool GTKShouldConnectSizeRequest() const { return false; }
115 // common part of all ctors
116 void Init() { m_dialog
= NULL
; }
118 DECLARE_DYNAMIC_CLASS(wxFileButton
)
122 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
126 class WXDLLIMPEXP_CORE wxDirButton
: public wxGenericDirButton
129 wxDirButton() { Init(); }
130 wxDirButton(wxWindow
*parent
,
132 const wxString
& label
= wxFilePickerWidgetLabel
,
133 const wxString
&path
= wxEmptyString
,
134 const wxString
&message
= wxFileSelectorPromptStr
,
135 const wxPoint
& pos
= wxDefaultPosition
,
136 const wxSize
& size
= wxDefaultSize
,
137 long style
= wxDIRBTN_DEFAULT_STYLE
,
138 const wxValidator
& validator
= wxDefaultValidator
,
139 const wxString
& name
= wxFilePickerWidgetNameStr
)
143 m_pickerStyle
= style
;
145 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
146 pos
, size
, style
, validator
, name
);
149 virtual ~wxDirButton();
154 bool Create(wxWindow
*parent
,
156 const wxString
& label
= wxFilePickerWidgetLabel
,
157 const wxString
&path
= wxEmptyString
,
158 const wxString
&message
= wxFileSelectorPromptStr
,
159 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
160 const wxPoint
& pos
= wxDefaultPosition
,
161 const wxSize
& size
= wxDefaultSize
,
163 const wxValidator
& validator
= wxDefaultValidator
,
164 const wxString
& name
= wxFilePickerWidgetNameStr
);
167 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
168 // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
169 long GetDialogStyle() const
171 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST
);
174 virtual void SetPath(const wxString
&str
);
175 virtual void SetInitialDirectory(const wxString
& dir
);
177 // see macro defined above
181 // common part of all ctors
185 m_bIgnoreNextChange
= false;
190 public: // used by the GTK callback only
192 bool m_bIgnoreNextChange
;
194 void GTKUpdatePath(const char *gtkpath
);
197 DECLARE_DYNAMIC_CLASS(wxDirButton
)
200 #undef FILEDIRBTN_OVERRIDES
202 #endif // _WX_GTK_FILEPICKER_H_