]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/filepickerg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/filepickerg.cpp
3 // Purpose: wxGenericFileDirButton class implementation
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
28 #include "wx/filename.h"
29 #include "wx/filepicker.h"
31 #include "wx/scopedptr.h"
34 // ============================================================================
36 // ============================================================================
38 IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton
, wxButton
)
39 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton
, wxButton
)
41 // ----------------------------------------------------------------------------
42 // wxGenericFileButton
43 // ----------------------------------------------------------------------------
45 bool wxGenericFileDirButton::Create(wxWindow
*parent
,
47 const wxString
& label
,
49 const wxString
& message
,
50 const wxString
& wildcard
,
54 const wxValidator
& validator
,
57 m_pickerStyle
= style
;
59 // If the special wxPB_SMALL flag is used, ignore the provided label and
60 // use the shortest possible label and the smallest possible button fitting
64 if ( m_pickerStyle
& wxPB_SMALL
)
66 labelButton
= _("...");
67 styleButton
= wxBU_EXACTFIT
;
75 if ( !wxButton::Create(parent
, id
, labelButton
,
76 pos
, size
, styleButton
, validator
, name
) )
78 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
82 // and handle user clicks on it
83 Connect(GetId(), wxEVT_BUTTON
,
84 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick
),
87 // create the dialog associated with this button
90 m_wildcard
= wildcard
;
95 void wxGenericFileDirButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
97 wxScopedPtr
<wxDialog
> p(CreateDialog());
98 if (p
->ShowModal() == wxID_OK
)
100 // save updated path in m_path
101 UpdatePathFromDialog(p
.get());
104 wxFileDirPickerEvent
event(GetEventType(), this, GetId(), m_path
);
105 GetEventHandler()->ProcessEvent(event
);
109 void wxGenericFileDirButton::SetInitialDirectory(const wxString
& dir
)
114 // ----------------------------------------------------------------------------
115 // wxGenericFileButton
116 // ----------------------------------------------------------------------------
118 wxDialog
*wxGenericFileButton::CreateDialog()
120 // Determine the initial directory for the dialog: it comes either from the
121 // default path, if it has it, or from the separately specified initial
122 // directory that can be set even if the path is e.g. empty.
123 wxFileName
fn(m_path
);
124 wxString initialDir
= fn
.GetPath();
125 if ( initialDir
.empty() )
126 initialDir
= m_initialDir
;
128 return new wxFileDialog
139 // ----------------------------------------------------------------------------
140 // wxGenericDirButton
141 // ----------------------------------------------------------------------------
143 wxDialog
*wxGenericDirButton::CreateDialog()
145 wxDirDialog
* const dialog
= new wxDirDialog
149 m_path
.empty() ? m_initialDir
: m_path
,
155 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL