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