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 request */ \
32 /* in response to the user click as the generic implementation does */ \
33 virtual wxWindow *GetDialogParent() \
38 virtual bool Destroy() \
40 m_dialog->Destroy(); \
41 return wxButton::Destroy(); \
44 virtual void SetPath(const wxString &str) \
47 UpdateDialogPath(m_dialog); \
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 class WXDLLIMPEXP_CORE wxFileButton
: public wxGenericFileButton
58 wxFileButton() { m_dialog
= NULL
; }
59 wxFileButton(wxWindow
*parent
,
61 const wxString
& label
= wxFilePickerWidgetLabel
,
62 const wxString
&path
= wxEmptyString
,
63 const wxString
&message
= wxFileSelectorPromptStr
,
64 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 const wxSize
& size
= wxDefaultSize
,
67 long style
= wxFILEBTN_DEFAULT_STYLE
,
68 const wxValidator
& validator
= wxDefaultValidator
,
69 const wxString
& name
= wxFilePickerWidgetNameStr
)
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
&);
97 public: // some overrides
99 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_ACTION_SAVE
100 // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN; since wxFD_SAVE
101 // is not supported, wxFD_OVERWRITE_PROMPT isn't too...
102 virtual long GetDialogStyle() const
104 return (wxGenericFileButton::GetDialogStyle() &
105 ~(wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
)) | wxFD_OPEN
;
108 // see macro defined above
115 DECLARE_DYNAMIC_CLASS(wxFileButton
)
119 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
123 class WXDLLIMPEXP_CORE wxDirButton
: public wxGenericDirButton
126 wxDirButton() { m_dialog
= NULL
;}
127 wxDirButton(wxWindow
*parent
,
129 const wxString
& label
= wxFilePickerWidgetLabel
,
130 const wxString
&path
= wxEmptyString
,
131 const wxString
&message
= wxFileSelectorPromptStr
,
132 const wxPoint
& pos
= wxDefaultPosition
,
133 const wxSize
& size
= wxDefaultSize
,
134 long style
= wxDIRBTN_DEFAULT_STYLE
,
135 const wxValidator
& validator
= wxDefaultValidator
,
136 const wxString
& name
= wxFilePickerWidgetNameStr
)
139 Create(parent
, id
, label
, path
, message
, wxEmptyString
,
140 pos
, size
, style
, validator
, name
);
143 virtual ~wxDirButton();
148 bool Create(wxWindow
*parent
,
150 const wxString
& label
= wxFilePickerWidgetLabel
,
151 const wxString
&path
= wxEmptyString
,
152 const wxString
&message
= wxFileSelectorPromptStr
,
153 const wxString
&wildcard
= wxFileSelectorDefaultWildcardStr
,
154 const wxPoint
& pos
= wxDefaultPosition
,
155 const wxSize
& size
= wxDefaultSize
,
157 const wxValidator
& validator
= wxDefaultValidator
,
158 const wxString
& name
= wxFilePickerWidgetNameStr
);
160 // used by the GTK callback only
161 void UpdatePath(char *gtkpath
)
162 { m_path
= wxString::FromAscii(gtkpath
); }
164 // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
165 // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
166 long GetDialogStyle() const
168 return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST
);
171 // see macro defined above
178 DECLARE_DYNAMIC_CLASS(wxDirButton
)
181 #undef FILEDIRBTN_OVERRIDES
183 #endif // _WX_GTK_FILEPICKER_H_