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