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 // If there is no default file or if it doesn't have any path, use the
143 // explicitly set initial directory.
145 // Notice that it is important to call this before SetPath() below as if we
146 // do have m_initialDir and no directory in m_path, we need to interpret
147 // the path as being relative with respect to m_initialDir.
148 if ( !m_initialDir
.empty() )
149 DoSetInitialDirectory(dialog
, m_initialDir
);
151 // This sets both the default file name and the default directory of the
152 // dialog if m_path contains directory part.
153 dialog
->SetPath(m_path
);
158 // ----------------------------------------------------------------------------
159 // wxGenericDirButton
160 // ----------------------------------------------------------------------------
162 wxDialog
*wxGenericDirButton::CreateDialog()
164 wxDirDialog
* const dialog
= new wxDirDialog
168 m_path
.empty() ? m_initialDir
: m_path
,
174 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL