]> git.saurik.com Git - wxWidgets.git/blob - src/generic/filepickerg.cpp
Fix VC6 compilation after r73880.
[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 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
28
29 #include "wx/filename.h"
30 #include "wx/filepicker.h"
31
32 #include "wx/scopedptr.h"
33
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton)
40 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton)
41
42 // ----------------------------------------------------------------------------
43 // wxGenericFileButton
44 // ----------------------------------------------------------------------------
45
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,
54 long style,
55 const wxValidator& validator,
56 const wxString& name)
57 {
58 m_pickerStyle = style;
59
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
75 // create this button
76 if ( !wxButton::Create(parent, id, labelButton,
77 pos, size, styleButton, validator, name) )
78 {
79 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
80 return false;
81 }
82
83 // and handle user clicks on it
84 Connect(GetId(), wxEVT_BUTTON,
85 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick),
86 NULL, this);
87
88 // create the dialog associated with this button
89 m_path = path;
90 m_message = message;
91 m_wildcard = wildcard;
92
93 return true;
94 }
95
96 void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
97 {
98 wxScopedPtr<wxDialog> p(CreateDialog());
99 if (p->ShowModal() == wxID_OK)
100 {
101 // save updated path in m_path
102 UpdatePathFromDialog(p.get());
103
104 // fire an event
105 wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
106 GetEventHandler()->ProcessEvent(event);
107 }
108 }
109
110 void wxGenericFileDirButton::SetInitialDirectory(const wxString& dir)
111 {
112 m_initialDir = dir;
113 }
114
115 // ----------------------------------------------------------------------------
116 // wxGenericFileButton
117 // ----------------------------------------------------------------------------
118
119 wxDialog *wxGenericFileButton::CreateDialog()
120 {
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 );
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
156 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL