1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/pickerbase.cpp
3 // Purpose: wxPickerBase class implementation
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_COLOURPICKERCTRL || \
28 wxUSE_DIRPICKERCTRL || \
29 wxUSE_FILEPICKERCTRL || \
32 #include "wx/pickerbase.h"
35 #include "wx/textctrl.h"
38 // ============================================================================
40 // ============================================================================
42 IMPLEMENT_ABSTRACT_CLASS(wxPickerBase
, wxControl
)
44 BEGIN_EVENT_TABLE(wxPickerBase
, wxControl
)
45 EVT_SIZE(wxPickerBase::OnSize
)
46 WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase
)
48 WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase
, wxControl
)
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 bool wxPickerBase::CreateBase(wxWindow
*parent
,
61 const wxValidator
& validator
,
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
;
68 if (!wxControl::Create(parent
, id
, pos
, size
, style
| wxNO_BORDER
| wxTAB_TRAVERSAL
,
72 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
74 if (HasFlag(wxPB_USE_TEXTCTRL
))
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
79 m_text
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
80 wxDefaultPosition
, wxDefaultSize
,
81 GetTextCtrlStyle(style
) | textstyle
);
84 wxFAIL_MSG( wxT("wxPickerBase's textctrl creation failed") );
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);
95 // set the initial contents of the textctrl
96 m_text
->SetValue(text
);
98 m_text
->Connect(wxEVT_COMMAND_TEXT_UPDATED
,
99 wxCommandEventHandler(wxPickerBase::OnTextCtrlUpdate
),
101 m_text
->Connect(wxEVT_KILL_FOCUS
,
102 wxFocusEventHandler(wxPickerBase::OnTextCtrlKillFocus
),
105 m_text
->Connect(wxEVT_DESTROY
,
106 wxWindowDestroyEventHandler(wxPickerBase::OnTextCtrlDelete
),
109 // the text control's proportion values defaults to 2
110 m_sizer
->Add(m_text
, 2, GetDefaultTextCtrlFlag(), 5);
116 void wxPickerBase::PostCreation()
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);
123 m_sizer
->SetSizeHints(this);
126 void wxPickerBase::OnTextCtrlKillFocus(wxFocusEvent
&)
130 // don't leave the textctrl empty
131 if (m_text
->GetValue().empty())
132 UpdateTextCtrlFromPicker();
135 void wxPickerBase::OnTextCtrlDelete(wxWindowDestroyEvent
&)
137 // the textctrl has been deleted; our pointer is invalid!
141 void wxPickerBase::OnTextCtrlUpdate(wxCommandEvent
&)
143 // for each text-change, update the picker
144 UpdatePickerFromTextCtrl();
147 void wxPickerBase::OnSize(wxSizeEvent
&event
)
154 #endif // Any picker in use