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"
22 //-----------------------------------------------------------------------------
23 // wxFileButton and wxDirButton shared code
24 // (cannot be a base class since they need to derive from wxGenericFileButton
25 // and from wxGenericDirButton classes !)
26 //-----------------------------------------------------------------------------
28 #define FILEDIRBTN_OVERRIDES \
29 /* NULL is because of a problem with destruction order which happens */ \
30 /* if we pass GetParent(): in fact, this GTK native implementation */ \
31 /* needs to create the dialog in ::Create() and not for each user */ \
32 /* request in response to the user click as the generic implementation */ \
34 virtual wxWindow *GetDialogParent() \
39 virtual bool Destroy() \
41 m_dialog->Destroy(); \
42 return wxButton::Destroy(); \
45 /* even if wx derive from wxGenericFileButton, i.e. from wxButton, our */ \
46 /* native GTK+ widget does not derive from GtkButton thus *all* uses */ \
47 /* GTK_BUTTON(m_widget) macro done by wxButton must be bypassed to */ \
48 /* avoid bunch of GTK+ warnings like: */ \
49 /* invalid cast from `GtkFileChooserButton' to `GtkButton' */ \
50 /* so, override wxButton::GTKGetWindow and return NULL as GTK+ doesn't */ \
51 /* give us access to the internal GdkWindow of a GtkFileChooserButton */ \
52 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const \
56 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
60 class WXDLLIMPEXP_CORE wxFileButton
: public wxGenericFileButton
63 wxFileButton() { m_dialog
= NULL
; }
64 wxFileButton(wxWindow
*parent
,
66 const wxString
& label
= wxFilePickerWidgetLabel
,
67 const wxString
&path
= wxEmptyString
,
68 const wxString
&message
= wxFileSelectorPromptStr
,
69 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
70 const wxPoint
& pos
= wxDefaultPosition
,
71 const wxSize
& size
= wxDefaultSize
,
72 long style
= wxFILEBTN_DEFAULT_STYLE
,
73 const wxValidator
& validator
= wxDefaultValidator
,
74 const wxString
& name
= wxFilePickerWidgetNameStr
)
77 Create(parent
, id
, label
, path
, message
, wildcard
,
78 pos
, size
, style
, validator
, name
);
81 virtual ~wxFileButton();
86 bool Create(wxWindow
*parent
,
88 const wxString
& label
= wxFilePickerWidgetLabel
,
89 const wxString
&path
= wxEmptyString
,
90 const wxString
&message
= wxFileSelectorPromptStr
,
91 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
92 const wxPoint
& pos
= wxDefaultPosition
,
93 const wxSize
& size
= wxDefaultSize
,
95 const wxValidator
& validator
= wxDefaultValidator
,
96 const wxString
& name
= wxFilePickerWidgetNameStr
);
98 // event handler for the click
99 void OnDialogOK(wxCommandEvent
&);
102 public: // some overrides
104 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_ACTION_SAVE
105 // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN; since wxFD_SAVE
106 // is not supported, wxFD_OVERWRITE_PROMPT isn't too...
107 virtual long GetDialogStyle() const
109 return (wxGenericFileButton::GetDialogStyle() &
110 ~(wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
)) | wxFD_OPEN
;
113 virtual void SetPath(const wxString
&str
);
115 // see macro defined above
122 DECLARE_DYNAMIC_CLASS(wxFileButton
)
126 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
130 class WXDLLIMPEXP_CORE wxDirButton
: public wxGenericDirButton
133 wxDirButton() { Init(); }
134 wxDirButton(wxWindow
*parent
,
136 const wxString
& label
= wxFilePickerWidgetLabel
,
137 const wxString
&path
= wxEmptyString
,
138 const wxString
&message
= wxFileSelectorPromptStr
,
139 const wxPoint
& pos
= wxDefaultPosition
,
140 const wxSize
& size
= wxDefaultSize
,
141 long style
= wxDIRBTN_DEFAULT_STYLE
,
142 const wxValidator
& validator
= wxDefaultValidator
,
143 const wxString
& name
= wxFilePickerWidgetNameStr
)
147 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
148 pos
, size
, style
, validator
, name
);
151 virtual ~wxDirButton();
156 bool Create(wxWindow
*parent
,
158 const wxString
& label
= wxFilePickerWidgetLabel
,
159 const wxString
&path
= wxEmptyString
,
160 const wxString
&message
= wxFileSelectorPromptStr
,
161 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
162 const wxPoint
& pos
= wxDefaultPosition
,
163 const wxSize
& size
= wxDefaultSize
,
165 const wxValidator
& validator
= wxDefaultValidator
,
166 const wxString
& name
= wxFilePickerWidgetNameStr
);
169 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
170 // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
171 long GetDialogStyle() const
173 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST
);
176 virtual void SetPath(const wxString
&str
);
178 // see macro defined above
182 // common part of all ctors
186 m_bIgnoreNextChange
= false;
191 public: // used by the GTK callback only
193 bool m_bIgnoreNextChange
;
195 void UpdatePath(const char *gtkpath
)
196 { m_path
= wxString::FromAscii(gtkpath
); }
199 DECLARE_DYNAMIC_CLASS(wxDirButton
)
202 #undef FILEDIRBTN_OVERRIDES
204 #endif // _WX_GTK_FILEPICKER_H_