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"
33 #include "wx/tooltip.h"
36 #include "wx/textctrl.h"
40 // ============================================================================
42 // ============================================================================
44 IMPLEMENT_ABSTRACT_CLASS(wxPickerBase
, wxControl
)
46 BEGIN_EVENT_TABLE(wxPickerBase
, wxControl
)
47 EVT_SIZE(wxPickerBase::OnSize
)
48 WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase
)
50 WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase
, wxControl
)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 bool wxPickerBase::CreateBase(wxWindow
*parent
,
63 const wxValidator
& validator
,
66 // remove any border style from our style as wxPickerBase's window must be
67 // invisible (user styles must be set on the textctrl or the platform-dependent picker)
68 style
&= ~wxBORDER_MASK
;
70 if (!wxControl::Create(parent
, id
, pos
, size
, style
| wxNO_BORDER
| wxTAB_TRAVERSAL
,
76 m_sizer
= new wxBoxSizer(wxHORIZONTAL
);
78 if (HasFlag(wxPB_USE_TEXTCTRL
))
80 // NOTE: the style of this class (wxPickerBase) and the style of the
81 // attached text control are different: GetTextCtrlStyle() extracts
82 // the styles related to the textctrl from the styles passed here
83 m_text
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
,
84 wxDefaultPosition
, wxDefaultSize
,
85 GetTextCtrlStyle(style
));
88 wxFAIL_MSG( wxT("wxPickerBase's textctrl creation failed") );
92 // set the maximum lenght allowed for this textctrl.
93 // This is very important since any change to it will trigger an update in
94 // the m_picker; for very long strings, this real-time synchronization could
95 // become a CPU-blocker and thus should be avoided.
96 // 32 characters will be more than enough for all common uses.
97 m_text
->SetMaxLength(32);
99 // set the initial contents of the textctrl
100 m_text
->SetValue(text
);
102 m_text
->Connect(m_text
->GetId(), wxEVT_COMMAND_TEXT_UPDATED
,
103 wxCommandEventHandler(wxPickerBase::OnTextCtrlUpdate
),
105 m_text
->Connect(m_text
->GetId(), wxEVT_KILL_FOCUS
,
106 wxFocusEventHandler(wxPickerBase::OnTextCtrlKillFocus
),
109 m_text
->Connect(m_text
->GetId(), wxEVT_DESTROY
,
110 wxWindowDestroyEventHandler(wxPickerBase::OnTextCtrlDelete
),
113 // the text control's proportion values defaults to 2
114 m_sizer
->Add(m_text
, 2, GetDefaultTextCtrlFlag(), 5);
120 void wxPickerBase::PostCreation()
122 // the picker's proportion value defaults to 1 when there's no text control
123 // associated with it - in that case it defaults to 0
124 m_sizer
->Add(m_picker
, HasTextCtrl() ? 0 : 1, GetDefaultPickerCtrlFlag(), 5);
128 SetInitialSize( GetMinSize() );
133 void wxPickerBase::DoSetToolTip(wxToolTip
*tip
)
135 // don't set the tooltip on us but rather on our two child windows
136 // as otherwise it would appear only when the cursor is placed on the
137 // small area around the child windows which belong to wxPickerBase
138 m_picker
->SetToolTip(tip
);
140 // do a copy as wxWindow will own the pointer we pass
142 m_text
->SetToolTip(tip
? new wxToolTip(tip
->GetTip()) : NULL
);
145 #endif // wxUSE_TOOLTIPS
147 // ----------------------------------------------------------------------------
148 // wxPickerBase - event handlers
149 // ----------------------------------------------------------------------------
151 void wxPickerBase::OnTextCtrlKillFocus(wxFocusEvent
& event
)
155 // don't leave the textctrl empty
156 if (m_text
&& m_text
->GetValue().empty())
157 UpdateTextCtrlFromPicker();
160 void wxPickerBase::OnTextCtrlDelete(wxWindowDestroyEvent
&)
162 // the textctrl has been deleted; our pointer is invalid!
166 void wxPickerBase::OnTextCtrlUpdate(wxCommandEvent
&)
168 // for each text-change, update the picker
169 UpdatePickerFromTextCtrl();
172 void wxPickerBase::OnSize(wxSizeEvent
&event
)
179 #endif // Any picker in use