]> git.saurik.com Git - wxWidgets.git/blame - src/common/pickerbase.cpp
made the rest of wxEncodingConverter tables const
[wxWidgets.git] / src / common / pickerbase.cpp
CommitLineData
ec376c8f 1///////////////////////////////////////////////////////////////////////////////
fec9cc08 2// Name: src/common/pickerbase.cpp
ec376c8f
VZ
3// Purpose: wxPickerBase 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
9a6384ca
WS
27#if wxUSE_COLOURPICKERCTRL || \
28 wxUSE_DIRPICKERCTRL || \
29 wxUSE_FILEPICKERCTRL || \
30 wxUSE_FONTPICKERCTRL
31
ec376c8f
VZ
32#include "wx/pickerbase.h"
33
fec9cc08
WS
34#ifndef WX_PRECOMP
35 #include "wx/textctrl.h"
36#endif
ec376c8f
VZ
37
38// ============================================================================
39// implementation
40// ============================================================================
41
3c3b3558 42IMPLEMENT_ABSTRACT_CLASS(wxPickerBase, wxControl)
ec376c8f 43
a65ffcb2
VZ
44BEGIN_EVENT_TABLE(wxPickerBase, wxControl)
45 EVT_SIZE(wxPickerBase::OnSize)
46 WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase)
47END_EVENT_TABLE()
6c20e8f8 48WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase, wxControl)
a65ffcb2
VZ
49
50
ec376c8f
VZ
51// ----------------------------------------------------------------------------
52// wxPickerBase
53// ----------------------------------------------------------------------------
54
ec376c8f
VZ
55bool wxPickerBase::CreateBase(wxWindow *parent,
56 wxWindowID id,
57 const wxString &text,
58 const wxPoint& pos,
59 const wxSize& size,
60 long style,
61 const wxValidator& validator,
5f6475c1
VZ
62 const wxString& name,
63 long textstyle)
ec376c8f
VZ
64{
65 // remove any border style from our style as wxPickerBase's window must be
66 // invisible (user styles must be set on the textctrl or the platform-dependent picker)
67 style &= ~wxBORDER_MASK;
fec9cc08 68 if (!wxControl::Create(parent, id, pos, size, style | wxNO_BORDER | wxTAB_TRAVERSAL,
a65ffcb2 69 validator, name))
ec376c8f
VZ
70 return false;
71
a65ffcb2
VZ
72 m_sizer = new wxBoxSizer(wxHORIZONTAL);
73
ec376c8f
VZ
74 if (HasFlag(wxPB_USE_TEXTCTRL))
75 {
76 // NOTE: the style of this class (wxPickerBase) and the style of the
77 // attached text control are different: GetTextCtrlStyle() extracts
78 // the styles related to the textctrl from the styles passed here
5f6475c1
VZ
79 m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
80 wxDefaultPosition, wxDefaultSize,
81 GetTextCtrlStyle(style) | textstyle);
ec376c8f
VZ
82 if (!m_text)
83 {
84 wxFAIL_MSG( wxT("wxPickerBase's textctrl creation failed") );
85 return false;
86 }
87
88 // set the maximum lenght allowed for this textctrl.
89 // This is very important since any change to it will trigger an update in
90 // the m_picker; for very long strings, this real-time synchronization could
91 // become a CPU-blocker and thus should be avoided.
92 // 32 characters will be more than enough for all common uses.
93 m_text->SetMaxLength(32);
94
95 // set the initial contents of the textctrl
96 m_text->SetValue(text);
97
98 m_text->Connect(wxEVT_COMMAND_TEXT_UPDATED,
99 wxCommandEventHandler(wxPickerBase::OnTextCtrlUpdate),
100 NULL, this);
101 m_text->Connect(wxEVT_KILL_FOCUS,
102 wxFocusEventHandler(wxPickerBase::OnTextCtrlKillFocus),
103 NULL, this);
104
105 m_text->Connect(wxEVT_DESTROY,
106 wxWindowDestroyEventHandler(wxPickerBase::OnTextCtrlDelete),
107 NULL, this);
a65ffcb2 108
ecd87e5b 109 // the text control's proportion values defaults to 2
a65ffcb2 110 m_sizer->Add(m_text, 2, GetDefaultTextCtrlFlag(), 5);
ec376c8f
VZ
111 }
112
113 return true;
114}
115
a65ffcb2
VZ
116void wxPickerBase::PostCreation()
117{
ecd87e5b
VZ
118 // the picker's proportion value defaults to 1 when there's no text control
119 // associated with it - in that case it defaults to 0
120 m_sizer->Add(m_picker, HasTextCtrl() ? 0 : 1, GetDefaultPickerCtrlFlag(), 5);
a65ffcb2
VZ
121
122 SetSizer(m_sizer);
123 m_sizer->SetSizeHints(this);
124}
125
ec376c8f
VZ
126void wxPickerBase::OnTextCtrlKillFocus(wxFocusEvent &)
127{
128 wxASSERT(m_text);
129
130 // don't leave the textctrl empty
fec9cc08 131 if (m_text->GetValue().empty())
ec376c8f
VZ
132 UpdateTextCtrlFromPicker();
133}
134
135void wxPickerBase::OnTextCtrlDelete(wxWindowDestroyEvent &)
136{
137 // the textctrl has been deleted; our pointer is invalid!
138 m_text = NULL;
139}
140
141void wxPickerBase::OnTextCtrlUpdate(wxCommandEvent &)
142{
143 // for each text-change, update the picker
144 UpdatePickerFromTextCtrl();
145}
146
a65ffcb2 147void wxPickerBase::OnSize(wxSizeEvent &event)
06f23ff9 148{
a65ffcb2
VZ
149 if (GetAutoLayout())
150 Layout();
151 event.Skip();
06f23ff9 152}
9a6384ca
WS
153
154#endif // Any picker in use