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