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