]>
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 | 28 | |
75cb911c | 29 | #include "wx/filename.h" |
ec376c8f | 30 | #include "wx/filepicker.h" |
ec376c8f | 31 | |
b9bb74e9 VZ |
32 | #include "wx/scopedptr.h" |
33 | ||
ec376c8f VZ |
34 | |
35 | // ============================================================================ | |
36 | // implementation | |
37 | // ============================================================================ | |
38 | ||
ec376c8f VZ |
39 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton) |
40 | IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton) | |
41 | ||
42 | // ---------------------------------------------------------------------------- | |
43 | // wxGenericFileButton | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
68623b59 VZ |
46 | bool wxGenericFileDirButton::Create(wxWindow *parent, |
47 | wxWindowID id, | |
48 | const wxString& label, | |
49 | const wxString& path, | |
50 | const wxString& message, | |
51 | const wxString& wildcard, | |
52 | const wxPoint& pos, | |
53 | const wxSize& size, | |
8eca1205 | 54 | long style, |
68623b59 VZ |
55 | const wxValidator& validator, |
56 | const wxString& name) | |
ec376c8f | 57 | { |
8eca1205 VZ |
58 | m_pickerStyle = style; |
59 | ||
75bc8b34 VZ |
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 | |
62 | // it. | |
63 | long styleButton = 0; | |
64 | wxString labelButton; | |
65 | if ( m_pickerStyle & wxPB_SMALL ) | |
66 | { | |
67 | labelButton = _("..."); | |
68 | styleButton = wxBU_EXACTFIT; | |
69 | } | |
70 | else | |
71 | { | |
72 | labelButton = label; | |
73 | } | |
74 | ||
ec376c8f | 75 | // create this button |
75bc8b34 VZ |
76 | if ( !wxButton::Create(parent, id, labelButton, |
77 | pos, size, styleButton, validator, name) ) | |
ec376c8f VZ |
78 | { |
79 | wxFAIL_MSG( wxT("wxGenericFileButton creation failed") ); | |
80 | return false; | |
81 | } | |
82 | ||
83 | // and handle user clicks on it | |
ce7fe42e | 84 | Connect(GetId(), wxEVT_BUTTON, |
ec376c8f VZ |
85 | wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick), |
86 | NULL, this); | |
87 | ||
88 | // create the dialog associated with this button | |
89 | m_path = path; | |
556151f5 MW |
90 | m_message = message; |
91 | m_wildcard = wildcard; | |
92 | ||
93 | return true; | |
ec376c8f VZ |
94 | } |
95 | ||
96 | void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev)) | |
97 | { | |
b9bb74e9 | 98 | wxScopedPtr<wxDialog> p(CreateDialog()); |
556151f5 | 99 | if (p->ShowModal() == wxID_OK) |
ec376c8f | 100 | { |
556151f5 | 101 | // save updated path in m_path |
b9bb74e9 | 102 | UpdatePathFromDialog(p.get()); |
ec376c8f VZ |
103 | |
104 | // fire an event | |
105 | wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path); | |
106 | GetEventHandler()->ProcessEvent(event); | |
107 | } | |
108 | } | |
109 | ||
75cb911c VZ |
110 | void wxGenericFileDirButton::SetInitialDirectory(const wxString& dir) |
111 | { | |
112 | m_initialDir = dir; | |
113 | } | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
06a41924 | 116 | // wxGenericFileButton |
75cb911c VZ |
117 | // ---------------------------------------------------------------------------- |
118 | ||
75cb911c VZ |
119 | wxDialog *wxGenericFileButton::CreateDialog() |
120 | { | |
06a41924 VZ |
121 | // Determine the initial directory for the dialog: it comes either from the |
122 | // default path, if it has it, or from the separately specified initial | |
123 | // directory that can be set even if the path is e.g. empty. | |
124 | wxFileName fn(m_path); | |
125 | wxString initialDir = fn.GetPath(); | |
126 | if ( initialDir.empty() ) | |
127 | initialDir = m_initialDir; | |
128 | ||
129 | return new wxFileDialog | |
130 | ( | |
131 | GetDialogParent(), | |
132 | m_message, | |
133 | initialDir, | |
134 | fn.GetFullName(), | |
135 | m_wildcard, | |
136 | GetDialogStyle() | |
137 | ); | |
75cb911c VZ |
138 | } |
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // wxGenericDirButton | |
142 | // ---------------------------------------------------------------------------- | |
143 | ||
144 | wxDialog *wxGenericDirButton::CreateDialog() | |
145 | { | |
146 | wxDirDialog* const dialog = new wxDirDialog | |
147 | ( | |
148 | GetDialogParent(), | |
149 | m_message, | |
150 | m_path.empty() ? m_initialDir : m_path, | |
151 | GetDialogStyle() | |
152 | ); | |
153 | return dialog; | |
154 | } | |
155 | ||
ec376c8f | 156 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL |