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