1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/filedirpicker.h
3 // Purpose: wxFileButton, wxDirButton header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_FILEPICKER_H_
12 #define _WX_GTK_FILEPICKER_H_
14 // since GtkColorButton is available only for GTK+ >= 2.4,
15 // we need to use generic versions if we detect (at runtime)
17 #include "wx/generic/filepickerg.h"
19 //-----------------------------------------------------------------------------
20 // wxFileButton and wxDirButton shared code
21 // (cannot be a base class since they need to derive from wxGenericFileButton
22 // and from wxGenericDirButton classes !)
23 //-----------------------------------------------------------------------------
25 #define FILEDIRBTN_OVERRIDES \
26 /* NULL is because of a problem with destruction order which happens */ \
27 /* if we pass GetParent(): in fact, this GTK native implementation */ \
28 /* needs to create the dialog in ::Create() and not for each user */ \
29 /* request in response to the user click as the generic implementation */ \
31 virtual wxWindow *GetDialogParent() \
36 /* even if wx derive from wxGenericFileButton, i.e. from wxButton, our */ \
37 /* native GTK+ widget does not derive from GtkButton thus *all* uses */ \
38 /* GTK_BUTTON(m_widget) macro done by wxButton must be bypassed to */ \
39 /* avoid bunch of GTK+ warnings like: */ \
40 /* invalid cast from `GtkFileChooserButton' to `GtkButton' */ \
41 /* so, override wxButton::GTKGetWindow and return NULL as GTK+ doesn't */ \
42 /* give us access to the internal GdkWindow of a GtkFileChooserButton */ \
45 GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const \
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 class WXDLLIMPEXP_CORE wxFileButton
: public wxGenericFileButton
56 wxFileButton() { Init(); }
57 wxFileButton(wxWindow
*parent
,
59 const wxString
& label
= wxFilePickerWidgetLabel
,
60 const wxString
&path
= wxEmptyString
,
61 const wxString
&message
= wxFileSelectorPromptStr
,
62 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
63 const wxPoint
& pos
= wxDefaultPosition
,
64 const wxSize
& size
= wxDefaultSize
,
65 long style
= wxFILEBTN_DEFAULT_STYLE
,
66 const wxValidator
& validator
= wxDefaultValidator
,
67 const wxString
& name
= wxFilePickerWidgetNameStr
)
70 m_pickerStyle
= style
;
71 Create(parent
, id
, label
, path
, message
, wildcard
,
72 pos
, size
, style
, validator
, name
);
75 virtual ~wxFileButton();
80 bool Create(wxWindow
*parent
,
82 const wxString
& label
= wxFilePickerWidgetLabel
,
83 const wxString
&path
= wxEmptyString
,
84 const wxString
&message
= wxFileSelectorPromptStr
,
85 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
89 const wxValidator
& validator
= wxDefaultValidator
,
90 const wxString
& name
= wxFilePickerWidgetNameStr
);
92 // event handler for the click
93 void OnDialogOK(wxCommandEvent
&);
95 virtual void SetPath(const wxString
&str
);
96 virtual void SetInitialDirectory(const wxString
& dir
);
98 // see macro defined above
105 // common part of all ctors
106 void Init() { m_dialog
= NULL
; }
108 DECLARE_DYNAMIC_CLASS(wxFileButton
)
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
116 class WXDLLIMPEXP_CORE wxDirButton
: public wxGenericDirButton
119 wxDirButton() { Init(); }
120 wxDirButton(wxWindow
*parent
,
122 const wxString
& label
= wxFilePickerWidgetLabel
,
123 const wxString
&path
= wxEmptyString
,
124 const wxString
&message
= wxFileSelectorPromptStr
,
125 const wxPoint
& pos
= wxDefaultPosition
,
126 const wxSize
& size
= wxDefaultSize
,
127 long style
= wxDIRBTN_DEFAULT_STYLE
,
128 const wxValidator
& validator
= wxDefaultValidator
,
129 const wxString
& name
= wxFilePickerWidgetNameStr
)
133 m_pickerStyle
= style
;
135 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
136 pos
, size
, style
, validator
, name
);
139 virtual ~wxDirButton();
144 bool Create(wxWindow
*parent
,
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
,
153 const wxValidator
& validator
= wxDefaultValidator
,
154 const wxString
& name
= wxFilePickerWidgetNameStr
);
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
161 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST
);
164 virtual void SetPath(const wxString
&str
);
165 virtual void SetInitialDirectory(const wxString
& dir
);
167 // see macro defined above
173 public: // used by the GTK callback only
175 bool m_bIgnoreNextChange
;
177 void GTKUpdatePath(const char *gtkpath
);
183 m_bIgnoreNextChange
= false;
186 DECLARE_DYNAMIC_CLASS(wxDirButton
)
189 #undef FILEDIRBTN_OVERRIDES
191 #endif // _WX_GTK_FILEPICKER_H_