]> git.saurik.com Git - wxWidgets.git/blob - src/generic/filepickerg.cpp
Lazy creation of the picker dialogs (Francesco).
[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 static wxString s_message, s_wildcard;
49
50 bool wxGenericFileDirButton::Create( wxWindow *parent, wxWindowID id,
51 const wxString &label, const wxString &path,
52 const wxString &message, const wxString &wildcard,
53 const wxPoint &pos, const wxSize &size, long style,
54 const wxValidator& validator, const wxString &name)
55 {
56 // create this button
57 if (!wxButton::Create(parent, id, label, pos, size, style,
58 validator, name))
59 {
60 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
61 return false;
62 }
63
64 // and handle user clicks on it
65 Connect(wxEVT_COMMAND_BUTTON_CLICKED,
66 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick),
67 NULL, this);
68
69 // create the dialog associated with this button
70 m_path = path;
71 s_message = message;
72 s_wildcard = wildcard;
73
74 m_dialog = NULL;
75 return true;
76 }
77
78 void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
79 {
80 CreateDialog(s_message, s_wildcard);
81
82 if (m_dialog->ShowModal() == wxID_OK)
83 {
84 // save the path
85 UpdatePathFromDialog();
86
87 // fire an event
88 wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
89 GetEventHandler()->ProcessEvent(event);
90 }
91
92 wxDELETE(m_dialog);
93 }
94
95 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL