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 // wxGenericFileutton
117 // ----------------------------------------------------------------------------
120 wxGenericFileButton::DoSetInitialDirectory(wxFileDialog
* dialog
,
123 if ( m_path
.find_first_of(wxFileName::GetPathSeparators()) ==
126 dialog
->SetDirectory(dir
);
130 wxDialog
*wxGenericFileButton::CreateDialog()
132 wxFileDialog
* const dialog
= new wxFileDialog
142 // this sets both the default folder and the default file of the dialog
143 dialog
->SetPath(m_path
);
145 // If there is no default file or if it doesn't have any path, use the
146 // explicitly set initial directory.
147 if ( !m_initialDir
.empty() )
148 DoSetInitialDirectory(dialog
, m_initialDir
);
153 // ----------------------------------------------------------------------------
154 // wxGenericDirButton
155 // ----------------------------------------------------------------------------
157 wxDialog
*wxGenericDirButton::CreateDialog()
159 wxDirDialog
* const dialog
= new wxDirDialog
163 m_path
.empty() ? m_initialDir
: m_path
,
169 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL