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