]> git.saurik.com Git - wxWidgets.git/blame - src/generic/filepickerg.cpp
Improve drawing of the tree item buttons in the generic renderer.
[wxWidgets.git] / src / generic / filepickerg.cpp
CommitLineData
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
ec376c8f
VZ
7// Copyright: (c) Francesco Montorsi
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
c757b5fe 26#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
ec376c8f 27
75cb911c 28#include "wx/filename.h"
ec376c8f 29#include "wx/filepicker.h"
ec376c8f 30
b9bb74e9
VZ
31#include "wx/scopedptr.h"
32
ec376c8f
VZ
33
34// ============================================================================
35// implementation
36// ============================================================================
37
ec376c8f
VZ
38IMPLEMENT_DYNAMIC_CLASS(wxGenericFileButton, wxButton)
39IMPLEMENT_DYNAMIC_CLASS(wxGenericDirButton, wxButton)
40
41// ----------------------------------------------------------------------------
42// wxGenericFileButton
43// ----------------------------------------------------------------------------
44
68623b59
VZ
45bool 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,
8eca1205 53 long style,
68623b59
VZ
54 const wxValidator& validator,
55 const wxString& name)
ec376c8f 56{
8eca1205
VZ
57 m_pickerStyle = style;
58
75bc8b34
VZ
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
ec376c8f 74 // create this button
75bc8b34
VZ
75 if ( !wxButton::Create(parent, id, labelButton,
76 pos, size, styleButton, validator, name) )
ec376c8f
VZ
77 {
78 wxFAIL_MSG( wxT("wxGenericFileButton creation failed") );
79 return false;
80 }
81
82 // and handle user clicks on it
ce7fe42e 83 Connect(GetId(), wxEVT_BUTTON,
ec376c8f
VZ
84 wxCommandEventHandler(wxGenericFileDirButton::OnButtonClick),
85 NULL, this);
86
87 // create the dialog associated with this button
88 m_path = path;
556151f5
MW
89 m_message = message;
90 m_wildcard = wildcard;
91
92 return true;
ec376c8f
VZ
93}
94
95void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
96{
b9bb74e9 97 wxScopedPtr<wxDialog> p(CreateDialog());
556151f5 98 if (p->ShowModal() == wxID_OK)
ec376c8f 99 {
556151f5 100 // save updated path in m_path
b9bb74e9 101 UpdatePathFromDialog(p.get());
ec376c8f
VZ
102
103 // fire an event
104 wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
105 GetEventHandler()->ProcessEvent(event);
106 }
107}
108
75cb911c
VZ
109void wxGenericFileDirButton::SetInitialDirectory(const wxString& dir)
110{
111 m_initialDir = dir;
112}
113
114// ----------------------------------------------------------------------------
06a41924 115// wxGenericFileButton
75cb911c
VZ
116// ----------------------------------------------------------------------------
117
75cb911c
VZ
118wxDialog *wxGenericFileButton::CreateDialog()
119{
06a41924
VZ
120 // Determine the initial directory for the dialog: it comes either from the
121 // default path, if it has it, or from the separately specified initial
122 // directory that can be set even if the path is e.g. empty.
123 wxFileName fn(m_path);
124 wxString initialDir = fn.GetPath();
125 if ( initialDir.empty() )
126 initialDir = m_initialDir;
127
128 return new wxFileDialog
129 (
130 GetDialogParent(),
131 m_message,
132 initialDir,
133 fn.GetFullName(),
134 m_wildcard,
135 GetDialogStyle()
136 );
75cb911c
VZ
137}
138
139// ----------------------------------------------------------------------------
140// wxGenericDirButton
141// ----------------------------------------------------------------------------
142
143wxDialog *wxGenericDirButton::CreateDialog()
144{
145 wxDirDialog* const dialog = new wxDirDialog
146 (
147 GetDialogParent(),
148 m_message,
149 m_path.empty() ? m_initialDir : m_path,
150 GetDialogStyle()
151 );
152 return dialog;
153}
154
ec376c8f 155#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL