1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk/filedirpicker.h
3 // Purpose:     wxFileButton, wxDirButton header
4 // Author:      Francesco Montorsi
5 // Modified by:
6 // Created:     14/4/2006
7 // Copyright:   (c) Francesco Montorsi
8 // RCS-ID:      $Id: filepicker.h 63601 2010-03-02 00:20:21Z VZ $
9 // Licence:     wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_GTK_FILEPICKER_H_
13 #define _WX_GTK_FILEPICKER_H_
14 
15 // since GtkColorButton is available only for GTK+ >= 2.4,
16 // we need to use generic versions if we detect (at runtime)
17 // that GTK+ < 2.4
18 #include "wx/generic/filepickerg.h"
19 
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 //-----------------------------------------------------------------------------
25 
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 */ \
31     /* does.                                                               */ \
32     virtual wxWindow *GetDialogParent()                                       \
33     {                                                                         \
34         return NULL;                                                          \
35     }                                                                         \
36                                                                               \
37     virtual bool Destroy()                                                    \
38     {                                                                         \
39         if (m_dialog)                                                         \
40             m_dialog->Destroy();                                              \
41         return wxButton::Destroy();                                           \
42     }                                                                         \
43                                                                               \
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  */ \
51 protected:                                                                    \
52     virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const \
53         { return NULL; }
54 
55 
56 //-----------------------------------------------------------------------------
57 // wxFileButton
58 //-----------------------------------------------------------------------------
59 
60 class WXDLLIMPEXP_CORE wxFileButton : public wxGenericFileButton
61 {
62 public:
wxFileButton()63     wxFileButton() { m_dialog = NULL; }
64     wxFileButton(wxWindow *parent,
65                  wxWindowID id,
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)
75     {
76         m_dialog = NULL;
77         Create(parent, id, label, path, message, wildcard,
78                pos, size, style, validator, name);
79     }
80 
81     virtual ~wxFileButton();
82 
83 
84 public:     // overrides
85 
86     bool Create(wxWindow *parent,
87                 wxWindowID id,
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,
94                 long style = 0,
95                 const wxValidator& validator = wxDefaultValidator,
96                 const wxString& name = wxFilePickerWidgetNameStr);
97 
98     // event handler for the click
99     void OnDialogOK(wxCommandEvent &);
100 
101     // GtkFileChooserButton does not support GTK_FILE_CHOOSER_ACTION_SAVE
102     // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN; since wxFD_SAVE
103     // is not supported, wxFD_OVERWRITE_PROMPT isn't too...
GetDialogStyle()104     virtual long GetDialogStyle() const
105     {
106          return (wxGenericFileButton::GetDialogStyle() &
107                      ~(wxFD_SAVE | wxFD_OVERWRITE_PROMPT)) | wxFD_OPEN;
108     }
109 
110     virtual void SetPath(const wxString &str);
111 
112     // see macro defined above
113     FILEDIRBTN_OVERRIDES
114 
115 protected:
116     wxDialog *m_dialog;
117 
118     DECLARE_DYNAMIC_CLASS(wxFileButton)
119 };
120 
121 
122 //-----------------------------------------------------------------------------
123 // wxDirButton
124 //-----------------------------------------------------------------------------
125 
126 class WXDLLIMPEXP_CORE wxDirButton : public wxGenericDirButton
127 {
128 public:
wxDirButton()129     wxDirButton() { Init(); }
130     wxDirButton(wxWindow *parent,
131                 wxWindowID id,
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)
140     {
141         Init();
142 
143         Create(parent, id, label, path, message, wxEmptyString,
144                 pos, size, style, validator, name);
145     }
146 
147     virtual ~wxDirButton();
148 
149 
150 public:     // overrides
151 
152     bool Create(wxWindow *parent,
153                 wxWindowID id,
154                 const wxString& label = wxFilePickerWidgetLabel,
155                 const wxString &path = wxEmptyString,
156                 const wxString &message = wxFileSelectorPromptStr,
157                 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
158                 const wxPoint& pos = wxDefaultPosition,
159                 const wxSize& size = wxDefaultSize,
160                 long style = 0,
161                 const wxValidator& validator = wxDefaultValidator,
162                 const wxString& name = wxFilePickerWidgetNameStr);
163 
164 
165     // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
166     // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
GetDialogStyle()167     long GetDialogStyle() const
168     {
169         return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST);
170     }
171 
172     virtual void SetPath(const wxString &str);
173 
174     // see macro defined above
175     FILEDIRBTN_OVERRIDES
176 
177 protected:
178     // common part of all ctors
Init()179     void Init()
180     {
181         m_dialog = NULL;
182         m_bIgnoreNextChange = false;
183     }
184 
185     wxDialog *m_dialog;
186 
187 public:    // used by the GTK callback only
188 
189     bool m_bIgnoreNextChange;
190 
UpdatePath(const char * gtkpath)191     void UpdatePath(const char *gtkpath)
192         { m_path = wxString::FromUTF8(gtkpath); }
193 
194 private:
195     DECLARE_DYNAMIC_CLASS(wxDirButton)
196 };
197 
198 #undef FILEDIRBTN_OVERRIDES
199 
200 #endif // _WX_GTK_FILEPICKER_H_
201 
202