]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/combobox.h
renamed m_boxes to m_buttons because, well, it contains the radio buttons and not...
[wxWidgets.git] / include / wx / univ / combobox.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/univ/combobox.h
3// Purpose: the universal combobox
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 30.08.00
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12/*
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?
15
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.
21
22 So we define a base wxComboControl which can use any control as pop down
77ffb593 23 list and wxComboBox deriving from it which implements the standard wxWidgets
1e6feb95
VZ
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.
30
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.
34 */
35
36#ifndef _WX_UNIV_COMBOBOX_H_
37#define _WX_UNIV_COMBOBOX_H_
38
1e6feb95
VZ
39class WXDLLEXPORT wxComboControl;
40class WXDLLEXPORT wxListBox;
41class WXDLLEXPORT wxPopupComboWindow;
8cb172b4
JS
42class WXDLLEXPORT wxTextCtrl;
43class WXDLLEXPORT wxButton;
1e6feb95
VZ
44
45// ----------------------------------------------------------------------------
46// the actions supported by this control
47// ----------------------------------------------------------------------------
48
49// all actions of single line text controls are supported
50
51// popup/dismiss the choice window
52#define wxACTION_COMBOBOX_POPUP _T("popup")
53#define wxACTION_COMBOBOX_DISMISS _T("dismiss")
54
55// choose the next/prev/specified (by numArg) item
56#define wxACTION_COMBOBOX_SELECT_NEXT _T("next")
57#define wxACTION_COMBOBOX_SELECT_PREV _T("prev")
58#define wxACTION_COMBOBOX_SELECT _T("select")
59
60// ----------------------------------------------------------------------------
61// wxComboPopup is the interface which must be implemented by a control to be
62// used as a popup by wxComboControl
63// ----------------------------------------------------------------------------
64
65class WXDLLEXPORT wxComboPopup
66{
67public:
68 wxComboPopup(wxComboControl *combo) { m_combo = combo; }
23ff76d5 69 virtual ~wxComboPopup() {}
1e6feb95
VZ
70
71 // we must have an associated control which is subclassed by the combobox
72 virtual wxControl *GetControl() = 0;
73
74 // called before showing the control to set the initial selection - notice
75 // that the text passed to this method might not correspond to any valid
76 // item (if the user edited it directly), in which case the method should
a290fa5a 77 // just return false but not emit any errors
1e6feb95
VZ
78 virtual bool SetSelection(const wxString& value) = 0;
79
80 // called immediately after the control is shown
81 virtual void OnShow() = 0;
82
e2ca829e
JS
83 virtual wxCoord GetBestWidth() const {return 0; }
84
1e6feb95
VZ
85protected:
86 wxComboControl *m_combo;
87};
88
89// ----------------------------------------------------------------------------
90// wxComboControl: a combination of a (single line) text control with a button
91// opening a popup window which contains the control from which the user can
92// choose the value directly.
93// ----------------------------------------------------------------------------
94
95class WXDLLEXPORT wxComboControl : public wxControl
96{
97public:
98 // construction
6463b9f5
JS
99 wxComboControl()
100 {
101 Init();
102 }
1e6feb95
VZ
103
104 wxComboControl(wxWindow *parent,
105 wxWindowID id,
106 const wxString& value = wxEmptyString,
107 const wxPoint& pos = wxDefaultPosition,
108 const wxSize& size = wxDefaultSize,
109 long style = 0,
110 const wxValidator& validator = wxDefaultValidator,
6463b9f5
JS
111 const wxString& name = wxComboBoxNameStr)
112 {
113 Init();
114
115 (void)Create(parent, id, value, pos, size, style, validator, name);
116 }
1e6feb95
VZ
117
118 bool Create(wxWindow *parent,
119 wxWindowID id,
120 const wxString& value = wxEmptyString,
121 const wxPoint& pos = wxDefaultPosition,
122 const wxSize& size = wxDefaultSize,
123 long style = 0,
124 const wxValidator& validator = wxDefaultValidator,
125 const wxString& name = wxComboBoxNameStr);
126
127 virtual ~wxComboControl();
128
129 // a combo control needs a control for popup window it displays
130 void SetPopupControl(wxComboPopup *popup);
131 wxComboPopup *GetPopupControl() const { return m_popup; }
132
133 // show/hide popup window
134 void ShowPopup();
135 void HidePopup();
136
a290fa5a 137 // return true if the popup is currently shown
1e6feb95
VZ
138 bool IsPopupShown() const { return m_isPopupShown; }
139
140 // get the popup window containing the popup control
141 wxPopupComboWindow *GetPopupWindow() const { return m_winPopup; }
142
143 // get the text control which is part of the combobox
144 wxTextCtrl *GetText() const { return m_text; }
145
146 // implementation only from now on
147 // -------------------------------
148
149 // notifications from wxComboPopup (shouldn't be called by anybody else)
150
151 // called when the user selects something in the popup: this normally hides
152 // the popup and sets the text to the new value
153 virtual void OnSelect(const wxString& value);
154
155 // called when the user dismisses the popup
156 virtual void OnDismiss();
157
158 // forward these functions to all subcontrols
a290fa5a
WS
159 virtual bool Enable(bool enable = true);
160 virtual bool Show(bool show = true);
1e6feb95 161
d4e5272b
JS
162#if wxUSE_TOOLTIPS
163 virtual void DoSetToolTip( wxToolTip *tip );
164#endif // wxUSE_TOOLTIPS
165
6f02a879
VZ
166 // we have our own input handler and our own actions
167 virtual bool PerformAction(const wxControlAction& action,
168 long numArg = 0l,
169 const wxString& strArg = wxEmptyString);
170
1e6feb95
VZ
171protected:
172 // override the base class virtuals involved into geometry calculations
173 virtual wxSize DoGetBestClientSize() const;
174 virtual void DoMoveWindow(int x, int y, int width, int height);
175 virtual void DoSetSize(int x, int y,
176 int width, int height,
177 int sizeFlags = wxSIZE_AUTO);
178
1e6feb95 179 // event handlers
2e9f62da 180 void OnKey(wxKeyEvent& event);
1e6feb95
VZ
181
182 // common part of all ctors
183 void Init();
184
185private:
186 // the text control and button we show all the time
187 wxTextCtrl *m_text;
188 wxButton *m_btn;
189
190 // the popup control
191 wxComboPopup *m_popup;
192
193 // and the popup window containing it
194 wxPopupComboWindow *m_winPopup;
195
196 // the height of the combobox popup as calculated in Create()
197 wxCoord m_heightPopup;
198
199 // is the popup window currenty shown?
200 bool m_isPopupShown;
201
202 DECLARE_EVENT_TABLE()
203};
204
205// ----------------------------------------------------------------------------
206// wxComboBox: a combination of text control and a listbox
207// ----------------------------------------------------------------------------
208
209class WXDLLEXPORT wxComboBox : public wxComboControl, public wxComboBoxBase
210{
211public:
212 // ctors and such
6463b9f5 213 wxComboBox() { Init(); }
1e6feb95
VZ
214
215 wxComboBox(wxWindow *parent,
216 wxWindowID id,
217 const wxString& value = wxEmptyString,
218 const wxPoint& pos = wxDefaultPosition,
219 const wxSize& size = wxDefaultSize,
220 int n = 0,
ba1e9d6c 221 const wxString choices[] = (const wxString *) NULL,
1e6feb95
VZ
222 long style = 0,
223 const wxValidator& validator = wxDefaultValidator,
6463b9f5
JS
224 const wxString& name = wxComboBoxNameStr)
225 {
226 Init();
227
228 (void)Create(parent, id, value, pos, size, n, choices,
229 style, validator, name);
230 }
584ad2a3
MB
231 wxComboBox(wxWindow *parent,
232 wxWindowID id,
233 const wxString& value,
234 const wxPoint& pos,
235 const wxSize& size,
236 const wxArrayString& choices,
237 long style = 0,
238 const wxValidator& validator = wxDefaultValidator,
239 const wxString& name = wxComboBoxNameStr);
1e6feb95
VZ
240
241 bool Create(wxWindow *parent,
242 wxWindowID id,
243 const wxString& value = wxEmptyString,
244 const wxPoint& pos = wxDefaultPosition,
245 const wxSize& size = wxDefaultSize,
246 int n = 0,
247 const wxString choices[] = (const wxString *) NULL,
248 long style = 0,
249 const wxValidator& validator = wxDefaultValidator,
250 const wxString& name = wxComboBoxNameStr);
584ad2a3
MB
251 bool Create(wxWindow *parent,
252 wxWindowID id,
253 const wxString& value,
254 const wxPoint& pos,
255 const wxSize& size,
256 const wxArrayString& choices,
257 long style = 0,
258 const wxValidator& validator = wxDefaultValidator,
259 const wxString& name = wxComboBoxNameStr);
1e6feb95
VZ
260
261 virtual ~wxComboBox();
262
263 // the wxUniversal-specific methods
264 // --------------------------------
265
266 // implement the combobox interface
267
268 // wxTextCtrl methods
269 virtual wxString GetValue() const;
270 virtual void SetValue(const wxString& value);
271 virtual void Copy();
272 virtual void Cut();
273 virtual void Paste();
274 virtual void SetInsertionPoint(long pos);
275 virtual void SetInsertionPointEnd();
276 virtual long GetInsertionPoint() const;
7d8268a1 277 virtual wxTextPos GetLastPosition() const;
1e6feb95
VZ
278 virtual void Replace(long from, long to, const wxString& value);
279 virtual void Remove(long from, long to);
280 virtual void SetSelection(long from, long to);
281 virtual void SetEditable(bool editable);
150e31d2
JS
282 virtual bool IsEditable() const;
283
284 virtual void Undo();
285 virtual void Redo();
286 virtual void SelectAll();
287
288 virtual bool CanCopy() const;
289 virtual bool CanCut() const;
290 virtual bool CanPaste() const;
291 virtual bool CanUndo() const;
292 virtual bool CanRedo() const;
1e6feb95
VZ
293
294 // wxControlWithItems methods
295 virtual void Clear();
aa61d352
VZ
296 virtual void Delete(unsigned int n);
297 virtual unsigned int GetCount() const;
298 virtual wxString GetString(unsigned int n) const;
299 virtual void SetString(unsigned int n, const wxString& s);
853dcc57 300 virtual int FindString(const wxString& s, bool bCase = false) const;
c6179a84 301 virtual void SetSelection(int n);
1e6feb95 302 virtual int GetSelection() const;
dcfb179b 303
6f6f938f 304 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
990ff5ec 305
1e6feb95
VZ
306protected:
307 virtual int DoAppend(const wxString& item);
aa61d352
VZ
308 virtual int DoInsert(const wxString& item, unsigned int pos);
309 virtual void DoSetItemClientData(unsigned int n, void* clientData);
310 virtual void* DoGetItemClientData(unsigned int n) const;
311 virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData);
312 virtual wxClientData* DoGetItemClientObject(unsigned int n) const;
1e6feb95
VZ
313
314 // common part of all ctors
315 void Init();
316
317 // get the associated listbox
318 wxListBox *GetLBox() const { return m_lbox; }
319
320private:
321 // the popup listbox
322 wxListBox *m_lbox;
323
324 //DECLARE_EVENT_TABLE()
325 DECLARE_DYNAMIC_CLASS(wxComboBox)
326};
327
328// ----------------------------------------------------------------------------
329// wxStdComboBoxInputHandler: allows the user to open/close the combo from kbd
330// ----------------------------------------------------------------------------
331
332class WXDLLEXPORT wxStdComboBoxInputHandler : public wxStdInputHandler
333{
334public:
335 wxStdComboBoxInputHandler(wxInputHandler *inphand);
336
23645bfa 337 virtual bool HandleKey(wxInputConsumer *consumer,
1e6feb95
VZ
338 const wxKeyEvent& event,
339 bool pressed);
340};
341
342#endif // _WX_UNIV_COMBOBOX_H_