]>
Commit | Line | Data |
---|---|---|
a340b80d VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/combo.h | |
a57d600f | 3 | // Purpose: wxComboCtrl declaration |
a340b80d | 4 | // Author: Jaakko Salli |
40b26d75 | 5 | // Modified by: |
a340b80d VZ |
6 | // Created: Apr-30-2006 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Jaakko Salli | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_COMBOCONTROL_H_BASE_ | |
13 | #define _WX_COMBOCONTROL_H_BASE_ | |
14 | ||
15 | ||
16 | /* | |
17 | A few words about all the classes defined in this file are probably in | |
a57d600f | 18 | order: why do we need extra wxComboCtrl and wxComboPopup classes? |
a340b80d VZ |
19 | |
20 | This is because a traditional combobox is a combination of a text control | |
21 | (with a button allowing to open the pop down list) with a listbox and | |
22 | wxComboBox class is exactly such control, however we want to also have other | |
23 | combinations - in fact, we want to allow anything at all to be used as pop | |
24 | down list, not just a wxListBox. | |
25 | ||
a57d600f | 26 | So we define a base wxComboCtrl which can use any control as pop down |
a340b80d | 27 | list and wxComboBox deriving from it which implements the standard wxWidgets |
a57d600f | 28 | combobox API. wxComboCtrl needs to be told somehow which control to use |
a340b80d VZ |
29 | and this is done by SetPopupControl(). However, we need something more than |
30 | just a wxControl in this method as, for example, we need to call | |
31 | SetSelection("initial text value") and wxControl doesn't have such method. | |
32 | So we also need a wxComboPopup which is just a very simple interface which | |
33 | must be implemented by a control to be usable as a popup. | |
34 | ||
35 | We couldn't derive wxComboPopup from wxControl as this would make it | |
36 | impossible to have a class deriving from both wxListBx and from it, so | |
37 | instead it is just a mix-in. | |
38 | */ | |
39 | ||
40 | ||
41 | #include "wx/defs.h" | |
42 | ||
a57d600f | 43 | #if wxUSE_COMBOCTRL |
a340b80d | 44 | |
dbaf49a9 | 45 | #include "wx/control.h" |
a340b80d | 46 | #include "wx/renderer.h" // this is needed for wxCONTROL_XXX flags |
7e983dab | 47 | #include "wx/bitmap.h" // wxBitmap used by-value |
a340b80d | 48 | |
dbaf49a9 | 49 | class WXDLLIMPEXP_CORE wxTextCtrl; |
a340b80d VZ |
50 | class WXDLLEXPORT wxComboPopup; |
51 | ||
52 | // | |
a57d600f | 53 | // New window styles for wxComboCtrlBase |
a340b80d VZ |
54 | // |
55 | enum | |
56 | { | |
57 | // Double-clicking a read-only combo triggers call to popup's OnComboPopup. | |
58 | // In wxOwnerDrawnComboBox, for instance, it cycles item. | |
59 | wxCC_SPECIAL_DCLICK = 0x0100, | |
60 | ||
a340b80d | 61 | // Dropbutton acts like standard push button. |
21d6b09b | 62 | wxCC_STD_BUTTON = 0x0200 |
a340b80d VZ |
63 | }; |
64 | ||
65 | ||
a57d600f | 66 | // wxComboCtrl internal flags |
a340b80d VZ |
67 | enum |
68 | { | |
69 | // First those that can be passed to Customize. | |
70 | // It is Windows style for all flags to be clear. | |
71 | ||
72 | // Button is preferred outside the border (GTK style) | |
73 | wxCC_BUTTON_OUTSIDE_BORDER = 0x0001, | |
74 | // Show popup on mouse up instead of mouse down (which is the Windows style) | |
75 | wxCC_POPUP_ON_MOUSE_UP = 0x0002, | |
76 | // All text is not automatically selected on click | |
77 | wxCC_NO_TEXT_AUTO_SELECT = 0x0004, | |
78 | ||
79 | // Internal use: signals creation is complete | |
80 | wxCC_IFLAG_CREATED = 0x0100, | |
81 | // Internal use: really put button outside | |
82 | wxCC_IFLAG_BUTTON_OUTSIDE = 0x0200, | |
83 | // Internal use: SetTextIndent has been called | |
84 | wxCC_IFLAG_INDENT_SET = 0x0400, | |
85 | // Internal use: Set wxTAB_TRAVERSAL to parent when popup is dismissed | |
06077aaf VZ |
86 | wxCC_IFLAG_PARENT_TAB_TRAVERSAL = 0x0800, |
87 | // Internal use: Secondary popup window type should be used (if available). | |
88 | wxCC_IFLAG_USE_ALT_POPUP = 0x1000 | |
a340b80d VZ |
89 | }; |
90 | ||
91 | ||
92 | // Flags used by PreprocessMouseEvent and HandleButtonMouseEvent | |
93 | enum | |
94 | { | |
1efad474 RR |
95 | wxCC_MF_ON_BUTTON = 0x0001, // cursor is on dropbutton area |
96 | wxCC_MF_ON_CLICK_AREA = 0x0002 // cursor is on dropbutton or other area | |
97 | // that can be clicked to show the popup. | |
a340b80d VZ |
98 | }; |
99 | ||
100 | ||
a57d600f VZ |
101 | // Namespace for wxComboCtrl feature flags |
102 | struct wxComboCtrlFeatures | |
a340b80d VZ |
103 | { |
104 | enum | |
105 | { | |
106 | MovableButton = 0x0001, // Button can be on either side of control | |
107 | BitmapButton = 0x0002, // Button may be replaced with bitmap | |
108 | ButtonSpacing = 0x0004, // Button can have spacing from the edge | |
109 | // of the control | |
110 | TextIndent = 0x0008, // SetTextIndent can be used | |
111 | PaintControl = 0x0010, // Combo control itself can be custom painted | |
112 | PaintWritable = 0x0020, // A variable-width area in front of writable | |
113 | // combo control's textctrl can be custom | |
114 | // painted | |
115 | Borderless = 0x0040, // wxNO_BORDER window style works | |
116 | ||
117 | // There are no feature flags for... | |
118 | // PushButtonBitmapBackground - if its in wxRendererNative, then it should be | |
119 | // not an issue to have it automatically under the bitmap. | |
120 | ||
121 | All = MovableButton|BitmapButton| | |
122 | ButtonSpacing|TextIndent| | |
123 | PaintControl|PaintWritable| | |
899eacc7 | 124 | Borderless |
a340b80d VZ |
125 | }; |
126 | }; | |
127 | ||
128 | ||
a57d600f | 129 | class WXDLLEXPORT wxComboCtrlBase : public wxControl |
a340b80d VZ |
130 | { |
131 | friend class wxComboPopup; | |
132 | public: | |
133 | // ctors and such | |
a57d600f | 134 | wxComboCtrlBase() : wxControl() { Init(); } |
a340b80d VZ |
135 | |
136 | bool Create(wxWindow *parent, | |
137 | wxWindowID id, | |
138 | const wxString& value, | |
139 | const wxPoint& pos, | |
140 | const wxSize& size, | |
141 | long style, | |
142 | const wxValidator& validator, | |
143 | const wxString& name); | |
144 | ||
a57d600f | 145 | virtual ~wxComboCtrlBase(); |
a340b80d VZ |
146 | |
147 | // show/hide popup window | |
148 | virtual void ShowPopup(); | |
149 | virtual void HidePopup(); | |
150 | ||
151 | // Override for totally custom combo action | |
152 | virtual void OnButtonClick(); | |
153 | ||
154 | // return true if the popup is currently shown | |
974a12f8 | 155 | bool IsPopupShown() const { return m_popupWinState == Visible; } |
a340b80d VZ |
156 | |
157 | // set interface class instance derived from wxComboPopup | |
6d0ce565 | 158 | // NULL popup can be used to indicate default in a derived class |
db53c6ea WS |
159 | void SetPopupControl( wxComboPopup* popup ) |
160 | { | |
161 | DoSetPopupControl(popup); | |
162 | } | |
a340b80d VZ |
163 | |
164 | // get interface class instance derived from wxComboPopup | |
e4e11217 WS |
165 | wxComboPopup* GetPopupControl() |
166 | { | |
167 | EnsurePopupControl(); | |
168 | return m_popupInterface; | |
169 | } | |
a340b80d VZ |
170 | |
171 | // get the popup window containing the popup control | |
172 | wxWindow *GetPopupWindow() const { return m_winPopup; } | |
173 | ||
a340b80d VZ |
174 | // Get the text control which is part of the combobox. |
175 | wxTextCtrl *GetTextCtrl() const { return m_text; } | |
176 | ||
177 | // get the dropdown button which is part of the combobox | |
178 | // note: its not necessarily a wxButton or wxBitmapButton | |
179 | wxWindow *GetButton() const { return m_btn; } | |
180 | ||
181 | // forward these methods to all subcontrols | |
182 | virtual bool Enable(bool enable = true); | |
183 | virtual bool Show(bool show = true); | |
184 | virtual bool SetFont(const wxFont& font); | |
a340b80d VZ |
185 | |
186 | // wxTextCtrl methods - for readonly combo they should return | |
187 | // without errors. | |
188 | virtual wxString GetValue() const; | |
189 | virtual void SetValue(const wxString& value); | |
190 | virtual void Copy(); | |
191 | virtual void Cut(); | |
192 | virtual void Paste(); | |
193 | virtual void SetInsertionPoint(long pos); | |
194 | virtual void SetInsertionPointEnd(); | |
195 | virtual long GetInsertionPoint() const; | |
196 | virtual long GetLastPosition() const; | |
197 | virtual void Replace(long from, long to, const wxString& value); | |
198 | virtual void Remove(long from, long to); | |
199 | virtual void SetSelection(long from, long to); | |
200 | virtual void Undo(); | |
201 | ||
6d0ce565 VZ |
202 | // This method sets the text without affecting list selection |
203 | // (ie. wxComboPopup::SetStringValue doesn't get called). | |
204 | void SetText(const wxString& value); | |
205 | ||
ce968519 RR |
206 | // This method sets value and also optionally sends EVT_TEXT |
207 | // (needed by combo popups) | |
208 | void SetValueWithEvent(const wxString& value, bool withEvent = true); | |
209 | ||
a340b80d VZ |
210 | // |
211 | // Popup customization methods | |
212 | // | |
213 | ||
214 | // Sets minimum width of the popup. If wider than combo control, it will extend to the left. | |
215 | // Remarks: | |
216 | // * Value -1 indicates the default. | |
217 | // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not). | |
218 | void SetPopupMinWidth( int width ) | |
219 | { | |
220 | m_widthMinPopup = width; | |
221 | } | |
222 | ||
223 | // Sets preferred maximum height of the popup. | |
224 | // Remarks: | |
225 | // * Value -1 indicates the default. | |
226 | // * Custom popup may choose to ignore this (wxOwnerDrawnComboBox does not). | |
227 | void SetPopupMaxHeight( int height ) | |
228 | { | |
229 | m_heightPopup = height; | |
230 | } | |
231 | ||
232 | // Extends popup size horizontally, relative to the edges of the combo control. | |
233 | // Remarks: | |
234 | // * Popup minimum width may override extLeft (ie. it has higher precedence). | |
235 | // * Values 0 indicate default. | |
236 | // * Custom popup may not take this fully into account (wxOwnerDrawnComboBox takes). | |
237 | void SetPopupExtents( int extLeft, int extRight ) | |
238 | { | |
239 | m_extLeft = extLeft; | |
240 | m_extRight = extRight; | |
241 | } | |
242 | ||
243 | // Set width, in pixels, of custom paint area in writable combo. | |
244 | // In read-only, used to indicate area that is not covered by the | |
245 | // focus rectangle (which may or may not be drawn, depending on the | |
246 | // popup type). | |
247 | void SetCustomPaintWidth( int width ); | |
248 | int GetCustomPaintWidth() const { return m_widthCustomPaint; } | |
249 | ||
250 | // Set side of the control to which the popup will align itself. | |
251 | // Valid values are wxLEFT, wxRIGHT and 0. The default value 0 wmeans | |
252 | // that the side of the button will be used. | |
253 | void SetPopupAnchor( int anchorSide ) | |
254 | { | |
255 | m_anchorSide = anchorSide; | |
256 | } | |
257 | ||
258 | // Set position of dropdown button. | |
7dc234d6 WS |
259 | // width: button width. <= 0 for default. |
260 | // height: button height. <= 0 for default. | |
a340b80d VZ |
261 | // side: wxLEFT or wxRIGHT, indicates on which side the button will be placed. |
262 | // spacingX: empty space on sides of the button. Default is 0. | |
263 | // Remarks: | |
264 | // There is no spacingY - the button will be centered vertically. | |
7dc234d6 WS |
265 | void SetButtonPosition( int width = -1, |
266 | int height = -1, | |
6d0ce565 VZ |
267 | int side = wxRIGHT, |
268 | int spacingX = 0 ); | |
a340b80d | 269 | |
7dc234d6 WS |
270 | // Returns current size of the dropdown button. |
271 | wxSize GetButtonSize(); | |
a340b80d VZ |
272 | |
273 | // | |
274 | // Sets dropbutton to be drawn with custom bitmaps. | |
275 | // | |
276 | // bmpNormal: drawn when cursor is not on button | |
6d0ce565 VZ |
277 | // pushButtonBg: Draw push button background below the image. |
278 | // NOTE! This is usually only properly supported on platforms with appropriate | |
279 | // method in wxRendererNative. | |
a340b80d VZ |
280 | // bmpPressed: drawn when button is depressed |
281 | // bmpHover: drawn when cursor hovers on button. This is ignored on platforms | |
282 | // that do not generally display hover differently. | |
283 | // bmpDisabled: drawn when combobox is disabled. | |
284 | void SetButtonBitmaps( const wxBitmap& bmpNormal, | |
6d0ce565 | 285 | bool pushButtonBg = false, |
a340b80d VZ |
286 | const wxBitmap& bmpPressed = wxNullBitmap, |
287 | const wxBitmap& bmpHover = wxNullBitmap, | |
288 | const wxBitmap& bmpDisabled = wxNullBitmap ); | |
289 | ||
290 | // | |
291 | // This will set the space in pixels between left edge of the control and the | |
292 | // text, regardless whether control is read-only (ie. no wxTextCtrl) or not. | |
293 | // Platform-specific default can be set with value-1. | |
294 | // Remarks | |
295 | // * This method may do nothing on some native implementations. | |
296 | void SetTextIndent( int indent ); | |
297 | ||
298 | // Returns actual indentation in pixels. | |
299 | wxCoord GetTextIndent() const | |
300 | { | |
301 | return m_absIndent; | |
302 | } | |
303 | ||
b104d1f0 RR |
304 | // Returns area covered by the text field. |
305 | const wxRect& GetTextRect() const | |
306 | { | |
307 | return m_tcArea; | |
308 | } | |
309 | ||
06077aaf VZ |
310 | // Call with enable as true to use a type of popup window that guarantees ability |
311 | // to focus the popup control, and normal function of common native controls. | |
312 | // This alternative popup window is usually a wxDialog, and as such it's parent | |
313 | // frame will appear as if the focus has been lost from it. | |
314 | void UseAltPopupWindow( bool enable = true ) | |
315 | { | |
316 | wxASSERT_MSG( !m_winPopup, | |
317 | wxT("call this only before SetPopupControl") ); | |
318 | ||
319 | if ( enable ) | |
320 | m_iFlags |= wxCC_IFLAG_USE_ALT_POPUP; | |
321 | else | |
322 | m_iFlags &= ~wxCC_IFLAG_USE_ALT_POPUP; | |
323 | } | |
324 | ||
a340b80d VZ |
325 | // |
326 | // Utilies needed by the popups or native implementations | |
327 | // | |
328 | ||
b445b6a7 VZ |
329 | // Returns true if given key combination should toggle the popup. |
330 | // NB: This is a separate from other keyboard handling because: | |
331 | // 1) Replaceability. | |
332 | // 2) Centralized code (otherwise it'd be split up between | |
333 | // wxComboCtrl key handler and wxVListBoxComboPopup's | |
334 | // key handler). | |
335 | virtual bool IsKeyPopupToggle(const wxKeyEvent& event) const = 0; | |
336 | ||
118f5fbd RR |
337 | // Prepare background of combo control or an item in a dropdown list |
338 | // in a way typical on platform. This includes painting the focus/disabled | |
339 | // background and setting the clipping region. | |
a340b80d VZ |
340 | // Unless you plan to paint your own focus indicator, you should always call this |
341 | // in your wxComboPopup::PaintComboControl implementation. | |
342 | // In addition, it sets pen and text colour to what looks good and proper | |
343 | // against the background. | |
344 | // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control | |
345 | // wxCONTROL_SELECTED: list item is selected | |
346 | // wxCONTROL_DISABLED: control/item is disabled | |
118f5fbd | 347 | virtual void PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const; |
a340b80d | 348 | |
6d0ce565 | 349 | // Returns true if focus indicator should be drawn in the control. |
a340b80d VZ |
350 | bool ShouldDrawFocus() const |
351 | { | |
352 | const wxWindow* curFocus = FindFocus(); | |
974a12f8 | 353 | return ( !IsPopupShown() && |
a340b80d VZ |
354 | (curFocus == this || (m_btn && curFocus == m_btn)) && |
355 | (m_windowStyle & wxCB_READONLY) ); | |
356 | } | |
357 | ||
358 | // These methods return references to appropriate dropbutton bitmaps | |
359 | const wxBitmap& GetBitmapNormal() const { return m_bmpNormal; } | |
360 | const wxBitmap& GetBitmapPressed() const { return m_bmpPressed; } | |
361 | const wxBitmap& GetBitmapHover() const { return m_bmpHover; } | |
362 | const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; } | |
363 | ||
364 | // Return internal flags | |
365 | wxUint32 GetInternalFlags() const { return m_iFlags; } | |
366 | ||
367 | // Return true if Create has finished | |
368 | bool IsCreated() const { return m_iFlags & wxCC_IFLAG_CREATED ? true : false; } | |
369 | ||
a340b80d VZ |
370 | // common code to be called on popup hide/dismiss |
371 | void OnPopupDismiss(); | |
372 | ||
974a12f8 RR |
373 | // PopupShown states |
374 | enum | |
375 | { | |
376 | Hidden = 0, | |
377 | //Closing = 1, | |
378 | Animating = 2, | |
379 | Visible = 3 | |
380 | }; | |
381 | ||
382 | bool IsPopupWindowState( int state ) const { return (state == m_popupWinState) ? true : false; } | |
383 | ||
384 | wxByte GetPopupWindowState() const { return m_popupWinState; } | |
385 | ||
a340b80d VZ |
386 | protected: |
387 | ||
388 | // | |
389 | // Override these for customization purposes | |
390 | // | |
391 | ||
392 | // called from wxSizeEvent handler | |
393 | virtual void OnResize() = 0; | |
394 | ||
395 | // Return native text identation (for pure text, not textctrl) | |
396 | virtual wxCoord GetNativeTextIndent() const; | |
397 | ||
398 | // Called in syscolourchanged handler and base create | |
399 | virtual void OnThemeChange(); | |
400 | ||
401 | // Creates wxTextCtrl. | |
402 | // extraStyle: Extra style parameters | |
403 | void CreateTextCtrl( int extraStyle, const wxValidator& validator ); | |
404 | ||
405 | // Installs standard input handler to combo (and optionally to the textctrl) | |
b445b6a7 | 406 | void InstallInputHandlers(); |
a340b80d VZ |
407 | |
408 | // Draws dropbutton. Using wxRenderer or bitmaps, as appropriate. | |
409 | void DrawButton( wxDC& dc, const wxRect& rect, bool paintBg = true ); | |
410 | ||
411 | // Call if cursor is on button area or mouse is captured for the button. | |
412 | //bool HandleButtonMouseEvent( wxMouseEvent& event, bool isInside ); | |
413 | bool HandleButtonMouseEvent( wxMouseEvent& event, int flags ); | |
414 | ||
a340b80d | 415 | // returns true if event was consumed or filtered (event type is also set to 0 in this case) |
a340b80d VZ |
416 | bool PreprocessMouseEvent( wxMouseEvent& event, int flags ); |
417 | ||
418 | // | |
419 | // This will handle left_down and left_dclick events outside button in a Windows-like manner. | |
420 | // If you need alternate behaviour, it is recommended you manipulate and filter events to it | |
421 | // instead of building your own handling routine (for reference, on wxEVT_LEFT_DOWN it will | |
422 | // toggle popup and on wxEVT_LEFT_DCLICK it will do the same or run the popup's dclick method, | |
423 | // if defined - you should pass events of other types of it for common processing). | |
424 | void HandleNormalMouseEvent( wxMouseEvent& event ); | |
425 | ||
426 | // Creates popup window, calls interface->Create(), etc | |
427 | void CreatePopup(); | |
428 | ||
7ca4ac63 WS |
429 | // Destroy popup window and all related constructs |
430 | void DestroyPopup(); | |
431 | ||
a340b80d | 432 | // override the base class virtuals involved in geometry calculations |
a340b80d VZ |
433 | virtual wxSize DoGetBestSize() const; |
434 | ||
db53c6ea WS |
435 | // NULL popup can be used to indicate default in a derived class |
436 | virtual void DoSetPopupControl(wxComboPopup* popup); | |
437 | ||
6d0ce565 VZ |
438 | // ensures there is atleast the default popup |
439 | void EnsurePopupControl(); | |
440 | ||
a340b80d VZ |
441 | // Recalculates button and textctrl areas. Called when size or button setup change. |
442 | // btnWidth: default/calculated width of the dropbutton. 0 means unchanged, | |
443 | // just recalculate. | |
444 | void CalculateAreas( int btnWidth = 0 ); | |
445 | ||
446 | // Standard textctrl positioning routine. Just give it platform-dependant | |
447 | // textctrl coordinate adjustment. | |
448 | void PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust ); | |
449 | ||
450 | // event handlers | |
451 | void OnSizeEvent( wxSizeEvent& event ); | |
452 | void OnFocusEvent(wxFocusEvent& event); | |
453 | void OnTextCtrlEvent(wxCommandEvent& event); | |
454 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
b445b6a7 | 455 | void OnKeyEvent(wxKeyEvent& event); |
a340b80d | 456 | |
a57d600f | 457 | // Set customization flags (directs how wxComboCtrlBase helpers behave) |
a340b80d VZ |
458 | void Customize( wxUint32 flags ) { m_iFlags |= flags; } |
459 | ||
460 | // Dispatches size event and refreshes | |
461 | void RecalcAndRefresh(); | |
462 | ||
974a12f8 RR |
463 | // Flags for DoShowPopup and AnimateShow |
464 | enum | |
465 | { | |
466 | ShowBelow = 0x0000, // Showing popup below the control | |
467 | ShowAbove = 0x0001, // Showing popup above the control | |
468 | CanDeferShow = 0x0002 // Can only return true from AnimateShow if this is set | |
469 | }; | |
470 | ||
471 | // Shows and positions the popup. | |
472 | virtual void DoShowPopup( const wxRect& rect, int flags ); | |
473 | ||
474 | // Implement in derived class to create a drop-down animation. | |
475 | // Return true if finished immediately. Otherwise popup is only | |
476 | // shown when the derived class call DoShowPopup. | |
477 | // Flags are same as for DoShowPopup. | |
478 | virtual bool AnimateShow( const wxRect& rect, int flags ); | |
479 | ||
dcc8cf5a PC |
480 | #if wxUSE_TOOLTIPS |
481 | virtual void DoSetToolTip( wxToolTip *tip ); | |
482 | #endif | |
483 | ||
a340b80d VZ |
484 | // This is used when m_text is hidden (readonly). |
485 | wxString m_valueString; | |
486 | ||
487 | // the text control and button we show all the time | |
488 | wxTextCtrl* m_text; | |
489 | wxWindow* m_btn; | |
490 | ||
491 | // wxPopupWindow or similar containing the window managed by the interface. | |
492 | wxWindow* m_winPopup; | |
493 | ||
494 | // the popup control/panel | |
495 | wxWindow* m_popup; | |
496 | ||
497 | // popup interface | |
6d0ce565 | 498 | wxComboPopup* m_popupInterface; |
a340b80d | 499 | |
b445b6a7 | 500 | // this is input etc. handler for the text control |
a340b80d VZ |
501 | wxEvtHandler* m_textEvtHandler; |
502 | ||
503 | // this is for the top level window | |
504 | wxEvtHandler* m_toplevEvtHandler; | |
505 | ||
506 | // this is for the control in popup | |
507 | wxEvtHandler* m_popupExtraHandler; | |
508 | ||
06077aaf VZ |
509 | // this is for the popup window |
510 | wxEvtHandler* m_popupWinEvtHandler; | |
511 | ||
a340b80d VZ |
512 | // used to prevent immediate re-popupping incase closed popup |
513 | // by clicking on the combo control (needed because of inconsistent | |
514 | // transient implementation across platforms). | |
515 | wxLongLong m_timeCanAcceptClick; | |
516 | ||
517 | // how much popup should expand to the left/right of the control | |
518 | wxCoord m_extLeft; | |
519 | wxCoord m_extRight; | |
520 | ||
521 | // minimum popup width | |
522 | wxCoord m_widthMinPopup; | |
523 | ||
524 | // preferred popup height | |
525 | wxCoord m_heightPopup; | |
526 | ||
527 | // how much of writable combo is custom-paint by callback? | |
528 | // also used to indicate area that is not covered by "blue" | |
529 | // selection indicator. | |
530 | wxCoord m_widthCustomPaint; | |
531 | ||
532 | // absolute text indentation, in pixels | |
533 | wxCoord m_absIndent; | |
534 | ||
535 | // side on which the popup is aligned | |
536 | int m_anchorSide; | |
537 | ||
538 | // Width of the "fake" border | |
539 | wxCoord m_widthCustomBorder; | |
540 | ||
541 | // The button and textctrl click/paint areas | |
542 | wxRect m_tcArea; | |
543 | wxRect m_btnArea; | |
544 | ||
545 | // current button state (uses renderer flags) | |
546 | int m_btnState; | |
547 | ||
548 | // button position | |
549 | int m_btnWid; | |
550 | int m_btnHei; | |
551 | int m_btnSide; | |
552 | int m_btnSpacingX; | |
553 | ||
554 | // last default button width | |
555 | int m_btnWidDefault; | |
556 | ||
557 | // custom dropbutton bitmaps | |
558 | wxBitmap m_bmpNormal; | |
559 | wxBitmap m_bmpPressed; | |
560 | wxBitmap m_bmpHover; | |
561 | wxBitmap m_bmpDisabled; | |
562 | ||
563 | // area used by the button | |
564 | wxSize m_btnSize; | |
565 | ||
566 | // platform-dependant customization and other flags | |
567 | wxUint32 m_iFlags; | |
568 | ||
569 | // draw blank button background under bitmap? | |
570 | bool m_blankButtonBg; | |
571 | ||
572 | // is the popup window currenty shown? | |
974a12f8 | 573 | wxByte m_popupWinState; |
a340b80d | 574 | |
a340b80d VZ |
575 | private: |
576 | void Init(); | |
577 | ||
ce968519 RR |
578 | wxByte m_ignoreEvtText; // Number of next EVT_TEXTs to ignore |
579 | ||
06077aaf VZ |
580 | // Is popup window wxPopupTransientWindow, wxPopupWindow or wxDialog? |
581 | wxByte m_popupWinType; | |
582 | ||
a340b80d VZ |
583 | DECLARE_EVENT_TABLE() |
584 | ||
a57d600f | 585 | DECLARE_ABSTRACT_CLASS(wxComboCtrlBase) |
a340b80d VZ |
586 | }; |
587 | ||
588 | ||
589 | // ---------------------------------------------------------------------------- | |
590 | // wxComboPopup is the interface which must be implemented by a control to be | |
a57d600f | 591 | // used as a popup by wxComboCtrl |
a340b80d VZ |
592 | // ---------------------------------------------------------------------------- |
593 | ||
594 | ||
595 | // wxComboPopup internal flags | |
596 | enum | |
597 | { | |
a57d600f | 598 | wxCP_IFLAG_CREATED = 0x0001 // Set by wxComboCtrlBase after Create is called |
a340b80d VZ |
599 | }; |
600 | ||
601 | ||
602 | class WXDLLEXPORT wxComboPopup | |
603 | { | |
a57d600f | 604 | friend class wxComboCtrlBase; |
a340b80d | 605 | public: |
6d0ce565 | 606 | wxComboPopup() |
a340b80d | 607 | { |
a57d600f | 608 | m_combo = (wxComboCtrlBase*) NULL; |
a340b80d VZ |
609 | m_iFlags = 0; |
610 | } | |
611 | ||
6d0ce565 VZ |
612 | // This is called immediately after construction finishes. m_combo member |
613 | // variable has been initialized before the call. | |
614 | // NOTE: It is not in constructor so the derived class doesn't need to redefine | |
615 | // a default constructor of its own. | |
616 | virtual void Init() { }; | |
617 | ||
a340b80d VZ |
618 | virtual ~wxComboPopup(); |
619 | ||
620 | // Create the popup child control. | |
621 | // Return true for success. | |
622 | virtual bool Create(wxWindow* parent) = 0; | |
623 | ||
624 | // We must have an associated control which is subclassed by the combobox. | |
625 | virtual wxWindow *GetControl() = 0; | |
626 | ||
627 | // Called immediately after the popup is shown | |
628 | virtual void OnPopup(); | |
629 | ||
630 | // Called when popup is dismissed | |
631 | virtual void OnDismiss(); | |
632 | ||
633 | // Called just prior to displaying popup. | |
634 | // Default implementation does nothing. | |
635 | virtual void SetStringValue( const wxString& value ); | |
636 | ||
637 | // Gets displayed string representation of the value. | |
638 | virtual wxString GetStringValue() const = 0; | |
639 | ||
640 | // This is called to custom paint in the combo control itself (ie. not the popup). | |
641 | // Default implementation draws value as string. | |
642 | virtual void PaintComboControl( wxDC& dc, const wxRect& rect ); | |
643 | ||
a57d600f | 644 | // Receives key events from the parent wxComboCtrl. |
a340b80d VZ |
645 | // Events not handled should be skipped, as usual. |
646 | virtual void OnComboKeyEvent( wxKeyEvent& event ); | |
647 | ||
648 | // Implement if you need to support special action when user | |
a57d600f | 649 | // double-clicks on the parent wxComboCtrl. |
a340b80d VZ |
650 | virtual void OnComboDoubleClick(); |
651 | ||
652 | // Return final size of popup. Called on every popup, just prior to OnShow. | |
653 | // minWidth = preferred minimum width for window | |
654 | // prefHeight = preferred height. Only applies if > 0, | |
655 | // maxHeight = max height for window, as limited by screen size | |
656 | // and should only be rounded down, if necessary. | |
657 | virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ); | |
658 | ||
659 | // Return true if you want delay call to Create until the popup is shown | |
660 | // for the first time. It is more efficient, but note that it is often | |
661 | // more convenient to have the control created immediately. | |
662 | // Default returns false. | |
663 | virtual bool LazyCreate(); | |
664 | ||
665 | // | |
666 | // Utilies | |
667 | // | |
668 | ||
669 | // Hides the popup | |
670 | void Dismiss(); | |
671 | ||
672 | // Returns true if Create has been called. | |
673 | bool IsCreated() const | |
674 | { | |
675 | return (m_iFlags & wxCP_IFLAG_CREATED) ? true : false; | |
676 | } | |
677 | ||
6d0ce565 | 678 | // Default PaintComboControl behaviour |
a57d600f | 679 | static void DefaultPaintComboControl( wxComboCtrlBase* combo, |
6d0ce565 VZ |
680 | wxDC& dc, |
681 | const wxRect& rect ); | |
682 | ||
a340b80d | 683 | protected: |
a57d600f | 684 | wxComboCtrlBase* m_combo; |
a340b80d | 685 | wxUint32 m_iFlags; |
6d0ce565 VZ |
686 | |
687 | private: | |
a57d600f VZ |
688 | // Called in wxComboCtrlBase::SetPopupControl |
689 | void InitBase(wxComboCtrlBase *combo) | |
6d0ce565 VZ |
690 | { |
691 | m_combo = combo; | |
692 | } | |
a340b80d VZ |
693 | }; |
694 | ||
695 | ||
696 | // ---------------------------------------------------------------------------- | |
697 | // include the platform-dependent header defining the real class | |
698 | // ---------------------------------------------------------------------------- | |
699 | ||
700 | #if defined(__WXUNIVERSAL__) | |
701 | // No native universal (but it must still be first in the list) | |
702 | #elif defined(__WXMSW__) | |
703 | #include "wx/msw/combo.h" | |
704 | #endif | |
705 | ||
706 | // Any ports may need generic as an alternative | |
707 | #include "wx/generic/combo.h" | |
708 | ||
a57d600f | 709 | #endif // wxUSE_COMBOCTRL |
a340b80d VZ |
710 | |
711 | #endif | |
712 | // _WX_COMBOCONTROL_H_BASE_ |