1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/combobox.h
3 // Purpose: the universal combobox
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 A few words about all the classes defined in this file are probably in
14 order: why do we need extra wxComboControl and wxComboPopup classes?
16 This is because a traditional combobox is a combination of a text control
17 (with a button allowing to open the pop down list) with a listbox and
18 wxComboBox class is exactly such control, however we want to also have other
19 combinations - in fact, we want to allow anything at all to be used as pop
20 down list, not just a wxListBox.
22 So we define a base wxComboControl which can use any control as pop down
23 list and wxComboBox deriving from it which implements the standard wxWindows
24 combobox API. wxComboControl needs to be told somehow which control to use
25 and this is done by SetPopupControl(). However, we need something more than
26 just a wxControl in this method as, for example, we need to call
27 SetSelection("initial text value") and wxControl doesn't have such method.
28 So we also need a wxComboPopup which is just a very simple interface which
29 must be implemented by a control to be usable as a popup.
31 We couldn't derive wxComboPopup from wxControl as this would make it
32 impossible to have a class deriving from both wxListBx and from it, so
33 instead it is just a mix-in.
36 #ifndef _WX_UNIV_COMBOBOX_H_
37 #define _WX_UNIV_COMBOBOX_H_
40 #pragma implementation "univcombobox.h"
43 class WXDLLEXPORT wxComboControl
;
44 class WXDLLEXPORT wxListBox
;
45 class WXDLLEXPORT wxPopupComboWindow
;
46 class WXDLLEXPORT wxTextCtrl
;
47 class WXDLLEXPORT wxButton
;
49 // ----------------------------------------------------------------------------
50 // the actions supported by this control
51 // ----------------------------------------------------------------------------
53 // all actions of single line text controls are supported
55 // popup/dismiss the choice window
56 #define wxACTION_COMBOBOX_POPUP _T("popup")
57 #define wxACTION_COMBOBOX_DISMISS _T("dismiss")
59 // choose the next/prev/specified (by numArg) item
60 #define wxACTION_COMBOBOX_SELECT_NEXT _T("next")
61 #define wxACTION_COMBOBOX_SELECT_PREV _T("prev")
62 #define wxACTION_COMBOBOX_SELECT _T("select")
64 // ----------------------------------------------------------------------------
65 // wxComboPopup is the interface which must be implemented by a control to be
66 // used as a popup by wxComboControl
67 // ----------------------------------------------------------------------------
69 class WXDLLEXPORT wxComboPopup
72 wxComboPopup(wxComboControl
*combo
) { m_combo
= combo
; }
74 // we must have an associated control which is subclassed by the combobox
75 virtual wxControl
*GetControl() = 0;
77 // called before showing the control to set the initial selection - notice
78 // that the text passed to this method might not correspond to any valid
79 // item (if the user edited it directly), in which case the method should
80 // just return FALSE but not emit any errors
81 virtual bool SetSelection(const wxString
& value
) = 0;
83 // called immediately after the control is shown
84 virtual void OnShow() = 0;
87 wxComboControl
*m_combo
;
90 // ----------------------------------------------------------------------------
91 // wxComboControl: a combination of a (single line) text control with a button
92 // opening a popup window which contains the control from which the user can
93 // choose the value directly.
94 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxComboControl
: public wxControl
105 wxComboControl(wxWindow
*parent
,
107 const wxString
& value
= wxEmptyString
,
108 const wxPoint
& pos
= wxDefaultPosition
,
109 const wxSize
& size
= wxDefaultSize
,
111 const wxValidator
& validator
= wxDefaultValidator
,
112 const wxString
& name
= wxComboBoxNameStr
)
116 (void)Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
119 bool Create(wxWindow
*parent
,
121 const wxString
& value
= wxEmptyString
,
122 const wxPoint
& pos
= wxDefaultPosition
,
123 const wxSize
& size
= wxDefaultSize
,
125 const wxValidator
& validator
= wxDefaultValidator
,
126 const wxString
& name
= wxComboBoxNameStr
);
128 virtual ~wxComboControl();
130 // a combo control needs a control for popup window it displays
131 void SetPopupControl(wxComboPopup
*popup
);
132 wxComboPopup
*GetPopupControl() const { return m_popup
; }
134 // show/hide popup window
138 // return TRUE if the popup is currently shown
139 bool IsPopupShown() const { return m_isPopupShown
; }
141 // get the popup window containing the popup control
142 wxPopupComboWindow
*GetPopupWindow() const { return m_winPopup
; }
144 // get the text control which is part of the combobox
145 wxTextCtrl
*GetText() const { return m_text
; }
147 // implementation only from now on
148 // -------------------------------
150 // notifications from wxComboPopup (shouldn't be called by anybody else)
152 // called when the user selects something in the popup: this normally hides
153 // the popup and sets the text to the new value
154 virtual void OnSelect(const wxString
& value
);
156 // called when the user dismisses the popup
157 virtual void OnDismiss();
159 // forward these functions to all subcontrols
160 virtual bool Enable(bool enable
= TRUE
);
161 virtual bool Show(bool show
= TRUE
);
164 // override the base class virtuals involved into geometry calculations
165 virtual wxSize
DoGetBestClientSize() const;
166 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
167 virtual void DoSetSize(int x
, int y
,
168 int width
, int height
,
169 int sizeFlags
= wxSIZE_AUTO
);
171 // we have our own input handler and our own actions
172 virtual bool PerformAction(const wxControlAction
& action
,
174 const wxString
& strArg
= wxEmptyString
);
177 void OnKey(wxKeyEvent
& event
);
179 // common part of all ctors
183 // the text control and button we show all the time
188 wxComboPopup
*m_popup
;
190 // and the popup window containing it
191 wxPopupComboWindow
*m_winPopup
;
193 // the height of the combobox popup as calculated in Create()
194 wxCoord m_heightPopup
;
196 // is the popup window currenty shown?
199 DECLARE_EVENT_TABLE()
202 // ----------------------------------------------------------------------------
203 // wxComboBox: a combination of text control and a listbox
204 // ----------------------------------------------------------------------------
206 class WXDLLEXPORT wxComboBox
: public wxComboControl
, public wxComboBoxBase
210 wxComboBox() { Init(); }
212 wxComboBox(wxWindow
*parent
,
214 const wxString
& value
= wxEmptyString
,
215 const wxPoint
& pos
= wxDefaultPosition
,
216 const wxSize
& size
= wxDefaultSize
,
218 const wxString
*choices
= (const wxString
*) NULL
,
220 const wxValidator
& validator
= wxDefaultValidator
,
221 const wxString
& name
= wxComboBoxNameStr
)
225 (void)Create(parent
, id
, value
, pos
, size
, n
, choices
,
226 style
, validator
, name
);
229 bool Create(wxWindow
*parent
,
231 const wxString
& value
= wxEmptyString
,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
,
235 const wxString choices
[] = (const wxString
*) NULL
,
237 const wxValidator
& validator
= wxDefaultValidator
,
238 const wxString
& name
= wxComboBoxNameStr
);
241 virtual ~wxComboBox();
243 // the wxUniversal-specific methods
244 // --------------------------------
246 // implement the combobox interface
248 // wxTextCtrl methods
249 virtual wxString
GetValue() const;
250 virtual void SetValue(const wxString
& value
);
253 virtual void Paste();
254 virtual void SetInsertionPoint(long pos
);
255 virtual void SetInsertionPointEnd();
256 virtual long GetInsertionPoint() const;
257 virtual long GetLastPosition() const;
258 virtual void Replace(long from
, long to
, const wxString
& value
);
259 virtual void Remove(long from
, long to
);
260 virtual void SetSelection(long from
, long to
);
261 virtual void SetEditable(bool editable
);
263 // wxControlWithItems methods
264 virtual void Clear();
265 virtual void Delete(int n
);
266 virtual int GetCount() const;
267 virtual wxString
GetString(int n
) const;
268 virtual void SetString(int n
, const wxString
& s
);
269 virtual int FindString(const wxString
& s
) const;
270 virtual void Select(int n
);
271 virtual int GetSelection() const;
272 void SetSelection(int n
) { Select(n
); }
274 void SetStringSelection(const wxString
& s
) { }
277 virtual int DoAppend(const wxString
& item
);
278 virtual void DoSetItemClientData(int n
, void* clientData
);
279 virtual void* DoGetItemClientData(int n
) const;
280 virtual void DoSetItemClientObject(int n
, wxClientData
* clientData
);
281 virtual wxClientData
* DoGetItemClientObject(int n
) const;
283 // common part of all ctors
286 // get the associated listbox
287 wxListBox
*GetLBox() const { return m_lbox
; }
293 //DECLARE_EVENT_TABLE()
294 DECLARE_DYNAMIC_CLASS(wxComboBox
)
297 // ----------------------------------------------------------------------------
298 // wxStdComboBoxInputHandler: allows the user to open/close the combo from kbd
299 // ----------------------------------------------------------------------------
301 class WXDLLEXPORT wxStdComboBoxInputHandler
: public wxStdInputHandler
304 wxStdComboBoxInputHandler(wxInputHandler
*inphand
);
306 virtual bool HandleKey(wxInputConsumer
*consumer
,
307 const wxKeyEvent
& event
,
311 #endif // _WX_UNIV_COMBOBOX_H_