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 /* 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 */ \
46 GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const \
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 class WXDLLIMPEXP_CORE wxFileButton
: public wxGenericFileButton
57 wxFileButton() { Init(); }
58 wxFileButton(wxWindow
*parent
,
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
)
71 m_pickerStyle
= style
;
72 Create(parent
, id
, label
, path
, message
, wildcard
,
73 pos
, size
, style
, validator
, name
);
76 virtual ~wxFileButton();
81 bool Create(wxWindow
*parent
,
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
,
90 const wxValidator
& validator
= wxDefaultValidator
,
91 const wxString
& name
= wxFilePickerWidgetNameStr
);
93 // event handler for the click
94 void OnDialogOK(wxCommandEvent
&);
96 virtual void SetPath(const wxString
&str
);
97 virtual void SetInitialDirectory(const wxString
& dir
);
99 // see macro defined above
106 // common part of all ctors
107 void Init() { m_dialog
= NULL
; }
109 DECLARE_DYNAMIC_CLASS(wxFileButton
)
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
117 class WXDLLIMPEXP_CORE wxDirButton
: public wxGenericDirButton
120 wxDirButton() { Init(); }
121 wxDirButton(wxWindow
*parent
,
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
)
134 m_pickerStyle
= style
;
136 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
137 pos
, size
, style
, validator
, name
);
140 virtual ~wxDirButton();
145 bool Create(wxWindow
*parent
,
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
,
154 const wxValidator
& validator
= wxDefaultValidator
,
155 const wxString
& name
= wxFilePickerWidgetNameStr
);
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
162 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST
);
165 virtual void SetPath(const wxString
&str
);
166 virtual void SetInitialDirectory(const wxString
& dir
);
168 // see macro defined above
174 public: // used by the GTK callback only
176 bool m_bIgnoreNextChange
;
178 void GTKUpdatePath(const char *gtkpath
);
184 m_bIgnoreNextChange
= false;
187 DECLARE_DYNAMIC_CLASS(wxDirButton
)
190 #undef FILEDIRBTN_OVERRIDES
192 #endif // _WX_GTK_FILEPICKER_H_