]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/combobox.h
Added MSWPositionForWxMenu() method which is used to translate wxWindows
[wxWidgets.git] / include / wx / univ / combobox.h
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$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
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
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.
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
39 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
40 #pragma interface "univcombobox.h"
41 #endif
42
43 class WXDLLEXPORT wxComboControl;
44 class WXDLLEXPORT wxListBox;
45 class WXDLLEXPORT wxPopupComboWindow;
46 class WXDLLEXPORT wxTextCtrl;
47 class WXDLLEXPORT wxButton;
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
69 class WXDLLEXPORT wxComboPopup
70 {
71 public:
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
80 // just return FALSE but not emit any errors
81 virtual bool SetSelection(const wxString& value) = 0;
82
83 // called immediately after the control is shown
84 virtual void OnShow() = 0;
85
86 virtual wxCoord GetBestWidth() const {return 0; }
87
88 protected:
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
98 class WXDLLEXPORT wxComboControl : public wxControl
99 {
100 public:
101 // construction
102 wxComboControl();
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,
111 const wxString& name = wxComboBoxNameStr);
112
113 bool Create(wxWindow *parent,
114 wxWindowID id,
115 const wxString& value = wxEmptyString,
116 const wxPoint& pos = wxDefaultPosition,
117 const wxSize& size = wxDefaultSize,
118 long style = 0,
119 const wxValidator& validator = wxDefaultValidator,
120 const wxString& name = wxComboBoxNameStr);
121
122 virtual ~wxComboControl();
123
124 // a combo control needs a control for popup window it displays
125 void SetPopupControl(wxComboPopup *popup);
126 wxComboPopup *GetPopupControl() const { return m_popup; }
127
128 // show/hide popup window
129 void ShowPopup();
130 void HidePopup();
131
132 // return TRUE if the popup is currently shown
133 bool IsPopupShown() const { return m_isPopupShown; }
134
135 // get the popup window containing the popup control
136 wxPopupComboWindow *GetPopupWindow() const { return m_winPopup; }
137
138 // get the text control which is part of the combobox
139 wxTextCtrl *GetText() const { return m_text; }
140
141 // implementation only from now on
142 // -------------------------------
143
144 // notifications from wxComboPopup (shouldn't be called by anybody else)
145
146 // called when the user selects something in the popup: this normally hides
147 // the popup and sets the text to the new value
148 virtual void OnSelect(const wxString& value);
149
150 // called when the user dismisses the popup
151 virtual void OnDismiss();
152
153 // forward these functions to all subcontrols
154 virtual bool Enable(bool enable = TRUE);
155 virtual bool Show(bool show = TRUE);
156
157 #if wxUSE_TOOLTIPS
158 virtual void DoSetToolTip( wxToolTip *tip );
159 #endif // wxUSE_TOOLTIPS
160
161 protected:
162 // override the base class virtuals involved into geometry calculations
163 virtual wxSize DoGetBestClientSize() const;
164 virtual void DoMoveWindow(int x, int y, int width, int height);
165 virtual void DoSetSize(int x, int y,
166 int width, int height,
167 int sizeFlags = wxSIZE_AUTO);
168
169 // we have our own input handler and our own actions
170 virtual bool PerformAction(const wxControlAction& action,
171 long numArg = 0l,
172 const wxString& strArg = wxEmptyString);
173
174 // event handlers
175 void OnKey(wxKeyEvent& event);
176
177 // common part of all ctors
178 void Init();
179
180 private:
181 // the text control and button we show all the time
182 wxTextCtrl *m_text;
183 wxButton *m_btn;
184
185 // the popup control
186 wxComboPopup *m_popup;
187
188 // and the popup window containing it
189 wxPopupComboWindow *m_winPopup;
190
191 // the height of the combobox popup as calculated in Create()
192 wxCoord m_heightPopup;
193
194 // is the popup window currenty shown?
195 bool m_isPopupShown;
196
197 DECLARE_EVENT_TABLE()
198 };
199
200 // ----------------------------------------------------------------------------
201 // wxComboBox: a combination of text control and a listbox
202 // ----------------------------------------------------------------------------
203
204 class WXDLLEXPORT wxComboBox : public wxComboControl, public wxComboBoxBase
205 {
206 public:
207 // ctors and such
208 wxComboBox();
209
210 wxComboBox(wxWindow *parent,
211 wxWindowID id,
212 const wxString& value = wxEmptyString,
213 const wxPoint& pos = wxDefaultPosition,
214 const wxSize& size = wxDefaultSize,
215 int n = 0,
216 const wxString *choices = (const wxString *) NULL,
217 long style = 0,
218 const wxValidator& validator = wxDefaultValidator,
219 const wxString& name = wxComboBoxNameStr);
220
221 bool Create(wxWindow *parent,
222 wxWindowID id,
223 const wxString& value = wxEmptyString,
224 const wxPoint& pos = wxDefaultPosition,
225 const wxSize& size = wxDefaultSize,
226 int n = 0,
227 const wxString choices[] = (const wxString *) NULL,
228 long style = 0,
229 const wxValidator& validator = wxDefaultValidator,
230 const wxString& name = wxComboBoxNameStr);
231
232
233 virtual ~wxComboBox();
234
235 // the wxUniversal-specific methods
236 // --------------------------------
237
238 // implement the combobox interface
239
240 // wxTextCtrl methods
241 virtual wxString GetValue() const;
242 virtual void SetValue(const wxString& value);
243 virtual void Copy();
244 virtual void Cut();
245 virtual void Paste();
246 virtual void SetInsertionPoint(long pos);
247 virtual void SetInsertionPointEnd();
248 virtual long GetInsertionPoint() const;
249 virtual long GetLastPosition() const;
250 virtual void Replace(long from, long to, const wxString& value);
251 virtual void Remove(long from, long to);
252 virtual void SetSelection(long from, long to);
253 virtual void SetEditable(bool editable);
254
255 // wxControlWithItems methods
256 virtual void Clear();
257 virtual void Delete(int n);
258 virtual int GetCount() const;
259 virtual wxString GetString(int n) const;
260 virtual void SetString(int n, const wxString& s);
261 virtual int FindString(const wxString& s) const;
262 virtual void Select(int n);
263 virtual int GetSelection() const;
264 void SetSelection(int n) { Select(n); }
265
266 void SetStringSelection(const wxString& WXUNUSED(s)) { }
267
268 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
269
270 protected:
271 virtual int DoAppend(const wxString& item);
272 virtual int DoInsert(const wxString& item, int pos);
273 virtual void DoSetItemClientData(int n, void* clientData);
274 virtual void* DoGetItemClientData(int n) const;
275 virtual void DoSetItemClientObject(int n, wxClientData* clientData);
276 virtual wxClientData* DoGetItemClientObject(int n) const;
277
278 // common part of all ctors
279 void Init();
280
281 // get the associated listbox
282 wxListBox *GetLBox() const { return m_lbox; }
283
284 private:
285 // the popup listbox
286 wxListBox *m_lbox;
287
288 //DECLARE_EVENT_TABLE()
289 DECLARE_DYNAMIC_CLASS(wxComboBox)
290 };
291
292 // ----------------------------------------------------------------------------
293 // wxStdComboBoxInputHandler: allows the user to open/close the combo from kbd
294 // ----------------------------------------------------------------------------
295
296 class WXDLLEXPORT wxStdComboBoxInputHandler : public wxStdInputHandler
297 {
298 public:
299 wxStdComboBoxInputHandler(wxInputHandler *inphand);
300
301 virtual bool HandleKey(wxInputConsumer *consumer,
302 const wxKeyEvent& event,
303 bool pressed);
304 };
305
306 #endif // _WX_UNIV_COMBOBOX_H_