]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
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 | ||
c757b5fe | 27 | #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL |
ec376c8f VZ |
28 | |
29 | #include "wx/filepicker.h" | |
ec376c8f VZ |
30 | |
31 | ||
32 | // ============================================================================ | |
33 | // implementation | |
34 | // ============================================================================ | |
35 | ||
ec376c8f VZ |
36 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton) |
37 | IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton) | |
38 | ||
39 | // ---------------------------------------------------------------------------- | |
40 | // wxGenericFileButton | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
68623b59 VZ |
43 | bool wxGenericFileDirButton::Create(wxWindow *parent, |
44 | wxWindowID id, | |
45 | const wxString& label, | |
46 | const wxString& path, | |
47 | const wxString& message, | |
48 | const wxString& wildcard, | |
49 | const wxPoint& pos, | |
50 | const wxSize& size, | |
8eca1205 | 51 | long style, |
68623b59 VZ |
52 | const wxValidator& validator, |
53 | const wxString& name) | |
ec376c8f | 54 | { |
8eca1205 VZ |
55 | m_pickerStyle = style; |
56 | ||
75bc8b34 VZ |
57 | // If the special wxPB_SMALL flag is used, ignore the provided label and |
58 | // use the shortest possible label and the smallest possible button fitting | |
59 | // it. | |
60 | long styleButton = 0; | |
61 | wxString labelButton; | |
62 | if ( m_pickerStyle & wxPB_SMALL ) | |
63 | { | |
64 | labelButton = _("..."); | |
65 | styleButton = wxBU_EXACTFIT; | |
66 | } | |
67 | else | |
68 | { | |
69 | labelButton = label; | |
70 | } | |
71 | ||
ec376c8f | 72 | // create this button |
75bc8b34 VZ |
73 | if ( !wxButton::Create(parent, id, labelButton, |
74 | pos, size, styleButton, validator, name) ) | |
ec376c8f VZ |
75 | { |
76 | wxFAIL_MSG( wxT("wxGenericFileButton creation failed") ); | |
77 | return false; | |
78 | } | |
79 | ||
80 | // and handle user clicks on it | |
29f571de | 81 | Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED, |
ec376c8f VZ |
82 | wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick), |
83 | NULL, this); | |
84 | ||
85 | // create the dialog associated with this button | |
86 | m_path = path; | |
556151f5 MW |
87 | m_message = message; |
88 | m_wildcard = wildcard; | |
89 | ||
90 | return true; | |
ec376c8f VZ |
91 | } |
92 | ||
93 | void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev)) | |
94 | { | |
556151f5 MW |
95 | wxDialog *p = CreateDialog(); |
96 | if (p->ShowModal() == wxID_OK) | |
ec376c8f | 97 | { |
556151f5 MW |
98 | // save updated path in m_path |
99 | UpdatePathFromDialog(p); | |
ec376c8f VZ |
100 | |
101 | // fire an event | |
102 | wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path); | |
103 | GetEventHandler()->ProcessEvent(event); | |
104 | } | |
556151f5 MW |
105 | |
106 | wxDELETE(p); | |
ec376c8f VZ |
107 | } |
108 | ||
109 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL |