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