1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/filepickerg.cpp
3 // Purpose: wxGenericFileDirButton class implementation
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
29 #include "wx/filename.h"
30 #include "wx/filepicker.h"
32 #include "wx/scopedptr.h"
35 // ============================================================================
37 // ============================================================================
39 IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton
, wxButton
)
40 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton
, wxButton
)
42 // ----------------------------------------------------------------------------
43 // wxGenericFileButton
44 // ----------------------------------------------------------------------------
46 bool wxGenericFileDirButton::Create(wxWindow
*parent
,
48 const wxString
& label
,
50 const wxString
& message
,
51 const wxString
& wildcard
,
55 const wxValidator
& validator
,
58 m_pickerStyle
= style
;
60 // If the special wxPB_SMALL flag is used, ignore the provided label and
61 // use the shortest possible label and the smallest possible button fitting
65 if ( m_pickerStyle
& wxPB_SMALL
)
67 labelButton
= _("...");
68 styleButton
= wxBU_EXACTFIT
;
76 if ( !wxButton::Create(parent
, id
, labelButton
,
77 pos
, size
, styleButton
, validator
, name
) )
79 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
83 // and handle user clicks on it
84 Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED
,
85 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick
),
88 // create the dialog associated with this button
91 m_wildcard
= wildcard
;
96 void wxGenericFileDirButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
98 wxScopedPtr
<wxDialog
> p(CreateDialog());
99 if (p
->ShowModal() == wxID_OK
)
101 // save updated path in m_path
102 UpdatePathFromDialog(p
.get());
105 wxFileDirPickerEvent
event(GetEventType(), this, GetId(), m_path
);
106 GetEventHandler()->ProcessEvent(event
);
110 void wxGenericFileDirButton::SetInitialDirectory(const wxString
& dir
)
115 // ----------------------------------------------------------------------------
116 // wxGenericFileButton
117 // ----------------------------------------------------------------------------
119 wxDialog
*wxGenericFileButton::CreateDialog()
121 // Determine the initial directory for the dialog: it comes either from the
122 // default path, if it has it, or from the separately specified initial
123 // directory that can be set even if the path is e.g. empty.
124 wxFileName
fn(m_path
);
125 wxString initialDir
= fn
.GetPath();
126 if ( initialDir
.empty() )
127 initialDir
= m_initialDir
;
129 return new wxFileDialog
140 // ----------------------------------------------------------------------------
141 // wxGenericDirButton
142 // ----------------------------------------------------------------------------
144 wxDialog
*wxGenericDirButton::CreateDialog()
146 wxDirDialog
* const dialog
= new wxDirDialog
150 m_path
.empty() ? m_initialDir
: m_path
,
156 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL