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