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