Commit pickers-fixes.patch added to 1472329 (Francesco Montorsi)
[wxWidgets.git] / src / generic / filepickerg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/filepickerg.cpp
3 // Purpose: wxGenericFileDirButton class implementation
4 // Author: Francesco Montorsi
5 // Modified by:
6 // Created: 15/04/2006
7 // RCS-ID: $Id$
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/window.h"
29 #endif //WX_PRECOMP
30
31 #include "wx/filepicker.h"
32 #include "wx/filedlg.h"
33
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
40
41 IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton)
42 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton)
43
44 // ----------------------------------------------------------------------------
45 // wxGenericFileButton
46 // ----------------------------------------------------------------------------
47
48 bool wxGenericFileDirButton::Create( wxWindow *parent, wxWindowID id,
49 const wxString &label, const wxString &path,
50 const wxString &message, const wxString &wildcard,
51 const wxPoint &pos, const wxSize &size, long style,
52 const wxValidator& validator, const wxString &name)
53 {
54 // create this button
55 if (!wxButton::Create(parent, id, label, pos, size, style,
56 validator, name))
57 {
58 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
59 return false;
60 }
61
62 // and handle user clicks on it
63 Connect(wxEVT_COMMAND_BUTTON_CLICKED,
64 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick),
65 NULL, this);
66
67 // create the dialog associated with this button
68 m_path = path;
69 m_message = message;
70 m_wildcard = wildcard;
71
72 return true;
73 }
74
75 void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
76 {
77 wxDialog *p = CreateDialog();
78 if (p->ShowModal() == wxID_OK)
79 {
80 // save updated path in m_path
81 UpdatePathFromDialog(p);
82
83 // fire an event
84 wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
85 GetEventHandler()->ProcessEvent(event);
86 }
87
88 wxDELETE(p);
89 }
90
91 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL