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