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