Use wxControl as wxComboBox base class for wxRTTI in all ports.
[wxWidgets.git] / src / common / combocmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: Apr-30-2006
7 // RCS-ID: $Id$
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_COMBOCTRL
27
28 #include "wx/combobox.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #include "wx/log.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/timer.h"
36 #include "wx/textctrl.h"
37 #endif
38
39 #include "wx/tooltip.h"
40
41 #include "wx/combo.h"
42
43
44 // ----------------------------------------------------------------------------
45 // XTI
46 // ----------------------------------------------------------------------------
47
48 wxDEFINE_FLAGS( wxComboBoxStyle )
49 wxBEGIN_FLAGS( wxComboBoxStyle )
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
55 wxFLAGS_MEMBER(wxBORDER_RAISED)
56 wxFLAGS_MEMBER(wxBORDER_STATIC)
57 wxFLAGS_MEMBER(wxBORDER_NONE)
58
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
63 wxFLAGS_MEMBER(wxRAISED_BORDER)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER)
65 wxFLAGS_MEMBER(wxBORDER)
66
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
71 wxFLAGS_MEMBER(wxWANTS_CHARS)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
74 wxFLAGS_MEMBER(wxVSCROLL)
75 wxFLAGS_MEMBER(wxHSCROLL)
76
77 wxFLAGS_MEMBER(wxCB_SIMPLE)
78 wxFLAGS_MEMBER(wxCB_SORT)
79 wxFLAGS_MEMBER(wxCB_READONLY)
80 wxFLAGS_MEMBER(wxCB_DROPDOWN)
81
82 wxEND_FLAGS( wxComboBoxStyle )
83
84 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl, "wx/combobox.h")
85
86 wxBEGIN_PROPERTIES_TABLE(wxComboBox)
87 wxEVENT_PROPERTY( Select, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent )
88 wxEVENT_PROPERTY( TextEnter, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent )
89
90 // TODO DELEGATES
91 wxPROPERTY( Font, wxFont, SetFont, GetFont, wxEMPTY_PARAMETER_VALUE, \
92 0 /*flags*/, wxT("Helpstring"), wxT("group"))
93 wxPROPERTY_COLLECTION( Choices, wxArrayString, wxString, AppendString, \
94 GetStrings, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
95 wxPROPERTY( Value,wxString, SetValue, GetValue, wxEMPTY_PARAMETER_VALUE, \
96 0 /*flags*/, wxT("Helpstring"), wxT("group"))
97 wxPROPERTY( Selection,int, SetSelection, GetSelection, wxEMPTY_PARAMETER_VALUE, \
98 0 /*flags*/, wxT("Helpstring"), wxT("group"))
99
100 wxPROPERTY_FLAGS( WindowStyle, wxComboBoxStyle, long, SetWindowStyleFlag, \
101 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
102 wxT("Helpstring"), wxT("group")) // style
103 wxEND_PROPERTIES_TABLE()
104
105 wxEMPTY_HANDLERS_TABLE(wxComboBox)
106
107 wxCONSTRUCTOR_5( wxComboBox, wxWindow*, Parent, wxWindowID, Id, \
108 wxString, Value, wxPoint, Position, wxSize, Size )
109
110 // constants
111 // ----------------------------------------------------------------------------
112
113 #define DEFAULT_DROPBUTTON_WIDTH 19
114
115 #define BMP_BUTTON_MARGIN 4
116
117 #define DEFAULT_POPUP_HEIGHT 400
118
119 #define DEFAULT_TEXT_INDENT 3
120
121 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
122
123
124 #if defined(__WXMSW__)
125
126 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
127 #include "wx/frame.h"
128 #define wxCC_GENERIC_TLW_IS_FRAME
129 #define wxComboCtrlGenericTLW wxFrame
130
131 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
132 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
133 // native controls work on it like normal.
134 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
135 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
136 #define FOCUS_RING 0 // No focus ring on wxMSW
137
138 //#undef wxUSE_POPUPWIN
139 //#define wxUSE_POPUPWIN 0
140
141 #elif defined(__WXGTK__)
142
143 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
144 // this bug: If wxDialog is hidden, its position becomes corrupt
145 // between hide and next show, but without internal coordinates being
146 // reflected (or something like that - atleast commenting out ->Hide()
147 // seemed to eliminate the position change).
148
149 #include "wx/dialog.h"
150 #define wxCC_GENERIC_TLW_IS_DIALOG
151 #define wxComboCtrlGenericTLW wxDialog
152
153 #if defined(__WXGTK20__)
154 # include "wx/gtk/private.h"
155 #else
156 # include "wx/gtk1/private.h"
157 #endif
158
159 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
160 // 'perfect' popup, as it can succesfully host child controls even in
161 // popups that are shown in modal dialogs.
162
163 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
164 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
165 // native controls work on it like normal.
166 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
167 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
168 #define FOCUS_RING 0 // No focus ring on wxGTK
169
170 #elif defined(__WXMAC__)
171
172 #include "wx/nonownedwnd.h"
173 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
174 #define wxComboCtrlGenericTLW wxNonOwnedWindow
175
176 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
177 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
178 // native controls work on it like normal.
179 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
180 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
181 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
182
183 #undef DEFAULT_DROPBUTTON_WIDTH
184 #define DEFAULT_DROPBUTTON_WIDTH 22
185 #undef COMBO_MARGIN
186 #define COMBO_MARGIN FOCUS_RING
187
188 #else
189
190 #include "wx/dialog.h"
191 #define wxCC_GENERIC_TLW_IS_DIALOG
192 #define wxComboCtrlGenericTLW wxDialog
193
194 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
195 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
196 // native controls work on it like normal.
197 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
198 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
199 #define FOCUS_RING 0
200
201 #endif
202
203
204 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
205 // what the wxUSE_POPUPWIN says.
206 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
207 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
208 #undef wxUSE_POPUPWIN
209 #define wxUSE_POPUPWIN 0
210 #endif
211
212
213 #if wxUSE_POPUPWIN
214 #include "wx/popupwin.h"
215 #else
216 #undef USE_TRANSIENT_POPUP
217 #define USE_TRANSIENT_POPUP 0
218 #endif
219
220
221 // Define different types of popup windows
222 enum
223 {
224 POPUPWIN_NONE = 0,
225 POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1,
226 POPUPWIN_WXPOPUPWINDOW = 2,
227 POPUPWIN_GENERICTLW = 3
228 };
229
230
231 #if USE_TRANSIENT_POPUP
232 // wxPopupTransientWindow is implemented
233
234 #define wxComboPopupWindowBase wxPopupTransientWindow
235 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
236 #define USES_WXPOPUPTRANSIENTWINDOW 1
237
238 #if TRANSIENT_POPUPWIN_IS_PERFECT
239 //
240 #elif POPUPWIN_IS_PERFECT
241 #define wxComboPopupWindowBase2 wxPopupWindow
242 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
243 #define USES_WXPOPUPWINDOW 1
244 #else
245 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
246 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
247 #define USES_GENERICTLW 1
248 #endif
249
250 #elif wxUSE_POPUPWIN
251 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
252
253 #define wxComboPopupWindowBase wxPopupWindow
254 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
255 #define USES_WXPOPUPWINDOW 1
256
257 #if !POPUPWIN_IS_PERFECT
258 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
259 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
260 #define USES_GENERICTLW 1
261 #endif
262
263 #else
264 // wxPopupWindow is not implemented
265
266 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
267 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
268 #define USES_GENERICTLW 1
269
270 #endif
271
272
273 #ifndef USES_WXPOPUPTRANSIENTWINDOW
274 #define USES_WXPOPUPTRANSIENTWINDOW 0
275 #endif
276
277 #ifndef USES_WXPOPUPWINDOW
278 #define USES_WXPOPUPWINDOW 0
279 #endif
280
281 #ifndef USES_GENERICTLW
282 #define USES_GENERICTLW 0
283 #endif
284
285
286 #if USES_WXPOPUPWINDOW
287 #define INSTALL_TOPLEV_HANDLER 1
288 #else
289 #define INSTALL_TOPLEV_HANDLER 0
290 #endif
291
292
293 // Returns true if given popup window type can be classified as perfect
294 // on this platform.
295 static inline bool IsPopupWinTypePerfect( wxByte popupWinType )
296 {
297 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
298 wxUnusedVar(popupWinType);
299 return true;
300 #else
301 return ( popupWinType == POPUPWIN_GENERICTLW
302 #if POPUPWIN_IS_PERFECT
303 || popupWinType == POPUPWIN_WXPOPUPWINDOW
304 #endif
305 #if TRANSIENT_POPUPWIN_IS_PERFECT
306 || popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW
307 #endif
308 );
309 #endif
310 }
311
312
313 //
314 // ** TODO **
315 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
316 //
317
318
319 // ----------------------------------------------------------------------------
320 // wxComboFrameEventHandler takes care of hiding the popup when events happen
321 // in its top level parent.
322 // ----------------------------------------------------------------------------
323
324 #if INSTALL_TOPLEV_HANDLER
325
326 //
327 // This will no longer be necessary after wxTransientPopupWindow
328 // works well on all platforms.
329 //
330
331 class wxComboFrameEventHandler : public wxEvtHandler
332 {
333 public:
334 wxComboFrameEventHandler( wxComboCtrlBase* pCb );
335 virtual ~wxComboFrameEventHandler();
336
337 void OnPopup();
338
339 void OnIdle( wxIdleEvent& event );
340 void OnMouseEvent( wxMouseEvent& event );
341 void OnActivate( wxActivateEvent& event );
342 void OnResize( wxSizeEvent& event );
343 void OnMove( wxMoveEvent& event );
344 void OnMenuEvent( wxMenuEvent& event );
345 void OnClose( wxCloseEvent& event );
346
347 protected:
348 wxWindow* m_focusStart;
349 wxComboCtrlBase* m_combo;
350
351 private:
352 DECLARE_EVENT_TABLE()
353 };
354
355 BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler)
356 EVT_IDLE(wxComboFrameEventHandler::OnIdle)
357 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
358 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
359 EVT_SIZE(wxComboFrameEventHandler::OnResize)
360 EVT_MOVE(wxComboFrameEventHandler::OnMove)
361 EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent)
362 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent)
363 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate)
364 EVT_CLOSE(wxComboFrameEventHandler::OnClose)
365 END_EVENT_TABLE()
366
367 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase* combo )
368 : wxEvtHandler()
369 {
370 m_combo = combo;
371 }
372
373 wxComboFrameEventHandler::~wxComboFrameEventHandler()
374 {
375 }
376
377 void wxComboFrameEventHandler::OnPopup()
378 {
379 m_focusStart = ::wxWindow::FindFocus();
380 }
381
382 void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
383 {
384 wxWindow* winFocused = ::wxWindow::FindFocus();
385
386 wxWindow* popup = m_combo->GetPopupControl()->GetControl();
387 wxWindow* winpopup = m_combo->GetPopupWindow();
388
389 if (
390 winFocused != m_focusStart &&
391 winFocused != popup &&
392 winFocused->GetParent() != popup &&
393 winFocused != winpopup &&
394 winFocused->GetParent() != winpopup &&
395 winFocused != m_combo &&
396 winFocused != m_combo->GetButton() // GTK (atleast) requires this
397 )
398 {
399 m_combo->HidePopup(true);
400 }
401
402 event.Skip();
403 }
404
405 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
406 {
407 m_combo->HidePopup(true);
408 event.Skip();
409 }
410
411 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
412 {
413 m_combo->HidePopup(true);
414 event.Skip();
415 }
416
417 void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
418 {
419 m_combo->HidePopup(true);
420 event.Skip();
421 }
422
423 void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
424 {
425 m_combo->HidePopup(true);
426 event.Skip();
427 }
428
429 void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
430 {
431 m_combo->HidePopup(true);
432 event.Skip();
433 }
434
435 void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
436 {
437 m_combo->HidePopup(true);
438 event.Skip();
439 }
440
441 #endif // INSTALL_TOPLEV_HANDLER
442
443 // ----------------------------------------------------------------------------
444 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
445 // wxComboCtrl.
446 // ----------------------------------------------------------------------------
447
448 class wxComboPopupWindow : public wxComboPopupWindowBase
449 {
450 public:
451
452 wxComboPopupWindow( wxComboCtrlBase *parent,
453 int style )
454 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
455 : wxComboPopupWindowBase(parent,style)
456 #else
457 : wxComboPopupWindowBase(parent,
458 wxID_ANY,
459 wxEmptyString,
460 wxPoint(-21,-21),
461 wxSize(20,20),
462 style)
463 #endif
464 {
465 m_inShow = 0;
466 }
467
468 #if USES_WXPOPUPTRANSIENTWINDOW
469 virtual bool Show( bool show );
470 virtual bool ProcessLeftDown(wxMouseEvent& event);
471 protected:
472 virtual void OnDismiss();
473 #endif
474
475 private:
476 wxByte m_inShow;
477 };
478
479
480 #if USES_WXPOPUPTRANSIENTWINDOW
481 bool wxComboPopupWindow::Show( bool show )
482 {
483 // Guard against recursion
484 if ( m_inShow )
485 return wxComboPopupWindowBase::Show(show);
486
487 m_inShow++;
488
489 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow)) );
490
491 wxPopupTransientWindow* ptw = (wxPopupTransientWindow*) this;
492
493 if ( show != ptw->IsShown() )
494 {
495 if ( show )
496 // We used to do wxPopupTransientWindow::Popup here,
497 // but this would hide normal Show, which we are
498 // also going to need.
499 ptw->Show();
500 else
501 ptw->Dismiss();
502 }
503
504 m_inShow--;
505
506 return true;
507 }
508
509 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event)
510 {
511 return wxPopupTransientWindow::ProcessLeftDown(event);
512 }
513
514 // First thing that happens when a transient popup closes is that this method gets called.
515 void wxComboPopupWindow::OnDismiss()
516 {
517 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
518 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)),
519 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
520
521 combo->OnPopupDismiss(true);
522 }
523 #endif // USES_WXPOPUPTRANSIENTWINDOW
524
525
526 // ----------------------------------------------------------------------------
527 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
528 // of a popup window. It is separate so we can have different types
529 // of popup windows.
530 // ----------------------------------------------------------------------------
531
532 class wxComboPopupWindowEvtHandler : public wxEvtHandler
533 {
534 public:
535
536 wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent )
537 {
538 m_combo = parent;
539 }
540
541 void OnSizeEvent( wxSizeEvent& event );
542 void OnKeyEvent(wxKeyEvent& event);
543 #if USES_GENERICTLW
544 void OnActivate( wxActivateEvent& event );
545 #endif
546
547 private:
548 wxComboCtrlBase* m_combo;
549
550 DECLARE_EVENT_TABLE()
551 };
552
553
554 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler)
555 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent)
556 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent)
557 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent)
558 #if USES_GENERICTLW
559 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate)
560 #endif
561 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent)
562 END_EVENT_TABLE()
563
564
565 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) )
566 {
567 // Block the event so that the popup control does not get auto-resized.
568 }
569
570 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
571 {
572 // Relay keyboard event to the main child controls
573 wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
574 wxWindowList::iterator node = children.begin();
575 wxWindow* child = (wxWindow*)*node;
576 child->GetEventHandler()->ProcessEvent(event);
577 }
578
579 #if USES_GENERICTLW
580 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
581 {
582 if ( !event.GetActive() )
583 {
584 // Tell combo control that we are dismissed.
585 m_combo->HidePopup(true);
586
587 event.Skip();
588 }
589 }
590 #endif
591
592
593 // ----------------------------------------------------------------------------
594 // wxComboPopup
595 //
596 // ----------------------------------------------------------------------------
597
598 wxComboPopup::~wxComboPopup()
599 {
600 }
601
602 void wxComboPopup::OnPopup()
603 {
604 }
605
606 void wxComboPopup::OnDismiss()
607 {
608 }
609
610 wxComboCtrl* wxComboPopup::GetComboCtrl() const
611 {
612 return wxStaticCast(m_combo, wxComboCtrl);
613 }
614
615 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
616 int prefHeight,
617 int WXUNUSED(maxHeight) )
618 {
619 return wxSize(minWidth,prefHeight);
620 }
621
622 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
623 wxDC& dc, const wxRect& rect )
624 {
625 if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
626 {
627 combo->PrepareBackground(dc,rect,0);
628
629 dc.DrawText( combo->GetValue(),
630 rect.x + combo->m_marginLeft,
631 (rect.height-dc.GetCharHeight())/2 + rect.y );
632 }
633 }
634
635 void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
636 {
637 DefaultPaintComboControl(m_combo,dc,rect);
638 }
639
640 void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
641 {
642 event.Skip();
643 }
644
645 void wxComboPopup::OnComboCharEvent( wxKeyEvent& event )
646 {
647 event.Skip();
648 }
649
650 void wxComboPopup::OnComboDoubleClick()
651 {
652 }
653
654 void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
655 {
656 }
657
658 bool wxComboPopup::FindItem(const wxString& WXUNUSED(item),
659 wxString* WXUNUSED(trueItem))
660 {
661 return true;
662 }
663
664 bool wxComboPopup::LazyCreate()
665 {
666 return false;
667 }
668
669 void wxComboPopup::Dismiss()
670 {
671 m_combo->HidePopup(true);
672 }
673
674 // ----------------------------------------------------------------------------
675 // input handling
676 // ----------------------------------------------------------------------------
677
678 //
679 // This is pushed to the event handler queue of the child textctrl.
680 //
681 class wxComboBoxExtraInputHandler : public wxEvtHandler
682 {
683 public:
684
685 wxComboBoxExtraInputHandler( wxComboCtrlBase* combo )
686 : wxEvtHandler()
687 {
688 m_combo = combo;
689 }
690 virtual ~wxComboBoxExtraInputHandler() { }
691 void OnKey(wxKeyEvent& event);
692 void OnFocus(wxFocusEvent& event);
693
694 protected:
695 wxComboCtrlBase* m_combo;
696
697 private:
698 DECLARE_EVENT_TABLE()
699 };
700
701
702 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
703 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
704 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey)
705 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey)
706 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
707 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
708 END_EVENT_TABLE()
709
710
711 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event)
712 {
713 // Let the wxComboCtrl event handler have a go first.
714 wxComboCtrlBase* combo = m_combo;
715
716 wxKeyEvent redirectedEvent(event);
717 redirectedEvent.SetId(combo->GetId());
718 redirectedEvent.SetEventObject(combo);
719
720 if ( !combo->GetEventHandler()->ProcessEvent(redirectedEvent) )
721 {
722 // Don't let TAB through to the text ctrl - looks ugly
723 if ( event.GetKeyCode() != WXK_TAB )
724 event.Skip();
725 }
726 }
727
728 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
729 {
730 // FIXME: This code does run when control is clicked,
731 // yet on Windows it doesn't select all the text.
732 if ( event.GetEventType() == wxEVT_SET_FOCUS &&
733 !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) )
734 {
735 if ( m_combo->GetTextCtrl() )
736 m_combo->GetTextCtrl()->SelectAll();
737 else
738 m_combo->SetSelection(-1,-1);
739 }
740
741 // Send focus indication to parent.
742 // NB: This is needed for cases where the textctrl gets focus
743 // instead of its parent. While this may trigger multiple
744 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
745 // from combo's focus event handler), they should be quite
746 // harmless.
747 wxFocusEvent evt2(event);
748 evt2.SetId(m_combo->GetId());
749 evt2.SetEventObject(m_combo);
750 m_combo->GetEventHandler()->ProcessEvent(evt2);
751
752 event.Skip();
753 }
754
755
756 //
757 // This is pushed to the event handler queue of the control in popup.
758 //
759
760 class wxComboPopupEvtHandler : public wxEvtHandler
761 {
762 public:
763
764 wxComboPopupEvtHandler( wxComboCtrlBase* combo )
765 : wxEvtHandler()
766 {
767 m_combo = combo;
768 m_beenInside = false;
769
770 // Let's make it so that the popup control will not receive mouse
771 // events until mouse left button has been up.
772 m_blockEventsToPopup = true;
773 }
774 virtual ~wxComboPopupEvtHandler() { }
775
776 void OnMouseEvent( wxMouseEvent& event );
777
778 // Called from wxComboCtrlBase::OnPopupDismiss
779 void OnPopupDismiss()
780 {
781 m_beenInside = false;
782 m_blockEventsToPopup = true;
783 }
784
785 protected:
786 wxComboCtrlBase* m_combo;
787
788 bool m_beenInside;
789 bool m_blockEventsToPopup;
790
791 private:
792 DECLARE_EVENT_TABLE()
793 };
794
795
796 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler, wxEvtHandler)
797 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent)
798 END_EVENT_TABLE()
799
800
801 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent& event )
802 {
803 wxPoint pt = event.GetPosition();
804 wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize();
805 int evtType = event.GetEventType();
806 bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y;
807 bool relayToButton = false;
808
809 event.Skip();
810
811 if ( !isInside || !m_combo->IsPopupShown() )
812 {
813 // Mouse is outside the popup or popup is not actually shown (yet)
814
815 if ( evtType == wxEVT_MOTION ||
816 evtType == wxEVT_LEFT_DOWN ||
817 evtType == wxEVT_LEFT_UP ||
818 evtType == wxEVT_RIGHT_DOWN )
819 {
820 // Block motion and click events outside the popup
821 event.Skip(false);
822 }
823 }
824 else
825 {
826 // Mouse is inside the popup, which is fully shown
827
828 m_beenInside = true;
829
830 // Do not let the popup control respond to mouse events until
831 // mouse press used to display the popup has been lifted. This
832 // is important for users with slower mouse fingers or mouse
833 // drivers. Note that we have some redundancy here, just in
834 // case the popup is some native control that does not emit all
835 // mouse event types.
836 if ( evtType == wxEVT_MOTION )
837 {
838 if ( m_blockEventsToPopup )
839 {
840 if ( event.LeftIsDown() )
841 event.Skip(false);
842 else
843 m_blockEventsToPopup = false;
844 }
845 }
846 else if ( evtType == wxEVT_LEFT_DOWN )
847 {
848 if ( m_blockEventsToPopup )
849 m_blockEventsToPopup = false;
850 }
851 else if ( evtType == wxEVT_LEFT_UP )
852 {
853 if ( m_blockEventsToPopup )
854 {
855 // On first left up, stop blocking mouse events (but still
856 // block this one)
857 m_blockEventsToPopup = false;
858 event.Skip(false);
859
860 // Also, this button press was (probably) used to display
861 // the popup, so relay it back to the drop-down button
862 // (which supposedly originated it). This is necessary to
863 // refresh it properly.
864 relayToButton = true;
865 }
866 }
867 else if ( m_blockEventsToPopup )
868 {
869 event.Skip(false);
870 }
871 }
872
873 //
874 // Some mouse events to popup that happen outside it, before cursor
875 // has been inside the popup, need to be ignored by it but relayed to
876 // the dropbutton.
877 //
878 if ( evtType == wxEVT_LEFT_UP )
879 {
880 if ( !m_combo->IsPopupShown() )
881 {
882 event.Skip(false);
883 relayToButton = true;
884 }
885 else if ( !isInside && !m_beenInside )
886 {
887 // Popup is shown but the cursor is not inside, nor it has been
888 relayToButton = true;
889 }
890 }
891
892 if ( relayToButton )
893 {
894 wxWindow* btn = m_combo->GetButton();
895 if ( btn )
896 btn->GetEventHandler()->ProcessEvent(event);
897 else
898 // Bypass the event handling mechanism. Using it would be
899 // confusing for the platform-specific wxComboCtrl
900 // implementations.
901 m_combo->HandleButtonMouseEvent(event, 0);
902 }
903 }
904
905 // ----------------------------------------------------------------------------
906 // wxComboCtrlTextCtrl
907 // ----------------------------------------------------------------------------
908
909 class wxComboCtrlTextCtrl : public wxTextCtrl
910 {
911 public:
912 wxComboCtrlTextCtrl() : wxTextCtrl() { }
913 virtual ~wxComboCtrlTextCtrl() { }
914
915 virtual wxWindow *GetMainWindowOfCompositeControl()
916 {
917 wxComboCtrl* combo = (wxComboCtrl*) GetParent();
918
919 // Returning this instead of just 'parent' lets FindFocus work
920 // correctly even when parent control is a child of a composite
921 // generic control (as is case with wxGenericDatePickerCtrl).
922 return combo->GetMainWindowOfCompositeControl();
923 }
924 };
925
926 // ----------------------------------------------------------------------------
927 // wxComboCtrlBase
928 // ----------------------------------------------------------------------------
929
930
931 BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl)
932 EVT_TEXT(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
933 EVT_SIZE(wxComboCtrlBase::OnSizeEvent)
934 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent)
935 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent)
936 EVT_IDLE(wxComboCtrlBase::OnIdleEvent)
937 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
938 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent)
939 EVT_CHAR(wxComboCtrlBase::OnCharEvent)
940 EVT_TEXT_ENTER(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
941 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged)
942 END_EVENT_TABLE()
943
944
945 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
946
947 void wxComboCtrlBase::Init()
948 {
949 m_winPopup = NULL;
950 m_popup = NULL;
951 m_popupWinState = Hidden;
952 m_btn = NULL;
953 m_text = NULL;
954 m_popupInterface = NULL;
955
956 m_popupEvtHandler = NULL;
957 m_textEvtHandler = NULL;
958
959 #if INSTALL_TOPLEV_HANDLER
960 m_toplevEvtHandler = NULL;
961 #endif
962
963 m_mainCtrlWnd = this;
964
965 m_heightPopup = -1;
966 m_widthMinPopup = -1;
967 m_anchorSide = 0;
968 m_widthCustomPaint = 0;
969 m_widthCustomBorder = 0;
970
971 m_btnState = 0;
972 m_btnWidDefault = 0;
973 m_blankButtonBg = false;
974 m_ignoreEvtText = 0;
975 m_popupWinType = POPUPWIN_NONE;
976 m_btnWid = m_btnHei = -1;
977 m_btnSide = wxRIGHT;
978 m_btnSpacingX = 0;
979
980 m_extLeft = 0;
981 m_extRight = 0;
982 m_marginLeft = -1;
983 m_iFlags = 0;
984 m_textCtrlStyle = 0;
985 m_timeCanAcceptClick = 0;
986
987 m_resetFocus = false;
988 }
989
990 bool wxComboCtrlBase::Create(wxWindow *parent,
991 wxWindowID id,
992 const wxString& value,
993 const wxPoint& pos,
994 const wxSize& size,
995 long style,
996 const wxValidator& validator,
997 const wxString& name)
998 {
999 if ( !wxControl::Create(parent,
1000 id,
1001 pos,
1002 size,
1003 style | wxWANTS_CHARS,
1004 validator,
1005 name) )
1006 return false;
1007
1008 m_valueString = value;
1009
1010 // Get colours
1011 OnThemeChange();
1012 m_marginLeft = GetNativeTextIndent();
1013
1014 m_iFlags |= wxCC_IFLAG_CREATED;
1015
1016 // If x and y indicate valid size, wxSizeEvent won't be
1017 // emitted automatically, so we need to add artifical one.
1018 if ( size.x > 0 && size.y > 0 )
1019 {
1020 wxSizeEvent evt(size,GetId());
1021 GetEventHandler()->AddPendingEvent(evt);
1022 }
1023
1024 return true;
1025 }
1026
1027 void wxComboCtrlBase::InstallInputHandlers()
1028 {
1029 if ( m_text )
1030 {
1031 m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
1032 m_text->PushEventHandler(m_textEvtHandler);
1033 }
1034 }
1035
1036 void
1037 wxComboCtrlBase::CreateTextCtrl(int style)
1038 {
1039 if ( !(m_windowStyle & wxCB_READONLY) )
1040 {
1041 if ( m_text )
1042 m_text->Destroy();
1043
1044 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1045 // not used by the wxPropertyGrid and therefore the tab is processed by
1046 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1047 // navigation event is then sent to the wrong window.
1048 style |= wxTE_PROCESS_TAB | m_textCtrlStyle;
1049
1050 if ( HasFlag(wxTE_PROCESS_ENTER) )
1051 style |= wxTE_PROCESS_ENTER;
1052
1053 // Ignore EVT_TEXT generated by the constructor (but only
1054 // if the event redirector already exists)
1055 // NB: This must be " = 1" instead of "++";
1056 if ( m_textEvtHandler )
1057 m_ignoreEvtText = 1;
1058 else
1059 m_ignoreEvtText = 0;
1060
1061 m_text = new wxComboCtrlTextCtrl();
1062 m_text->Create(this, wxID_ANY, m_valueString,
1063 wxDefaultPosition, wxSize(10,-1),
1064 style);
1065 m_text->SetHint(m_hintText);
1066 }
1067 }
1068
1069 void wxComboCtrlBase::OnThemeChange()
1070 {
1071 // Leave the default bg on the Mac so the area used by the focus ring will
1072 // be the correct colour and themed brush. Instead we'll use
1073 // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
1074 #ifndef __WXMAC__
1075 #if defined(__WXMSW__) || defined(__WXGTK__)
1076 wxVisualAttributes vattrs = wxComboBox::GetClassDefaultAttributes();
1077 #else
1078 wxVisualAttributes vattrs;
1079 vattrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1080 vattrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1081 #endif
1082
1083 // Only change the colours if application has not specified
1084 // custom ones.
1085 if ( !m_hasFgCol )
1086 {
1087 SetOwnForegroundColour(vattrs.colFg);
1088 m_hasFgCol = false;
1089 }
1090 if ( !m_hasBgCol )
1091 {
1092 SetOwnBackgroundColour(vattrs.colBg);
1093 m_hasBgCol = false;
1094 }
1095 #endif // !__WXMAC__
1096 }
1097
1098 wxComboCtrlBase::~wxComboCtrlBase()
1099 {
1100 if ( HasCapture() )
1101 ReleaseMouse();
1102
1103 #if INSTALL_TOPLEV_HANDLER
1104 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
1105 m_toplevEvtHandler = NULL;
1106 #endif
1107
1108 DestroyPopup();
1109
1110 if ( m_text )
1111 m_text->RemoveEventHandler(m_textEvtHandler);
1112
1113 delete m_textEvtHandler;
1114 }
1115
1116
1117 // ----------------------------------------------------------------------------
1118 // geometry stuff
1119 // ----------------------------------------------------------------------------
1120
1121 // Recalculates button and textctrl areas
1122 void wxComboCtrlBase::CalculateAreas( int btnWidth )
1123 {
1124 wxSize sz = GetClientSize();
1125 int customBorder = m_widthCustomBorder;
1126 int btnBorder; // border for button only
1127
1128 // check if button should really be outside the border: we'll do it it if
1129 // its platform default or bitmap+pushbutton background is used, but not if
1130 // there is vertical size adjustment or horizontal spacing.
1131 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
1132 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
1133 m_btnSpacingX == 0 &&
1134 m_btnHei <= 0 )
1135 {
1136 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
1137 btnBorder = 0;
1138 }
1139 else if ( (m_iFlags & wxCC_BUTTON_COVERS_BORDER) &&
1140 m_btnSpacingX == 0 && !m_bmpNormal.Ok() )
1141 {
1142 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1143 btnBorder = 0;
1144 }
1145 else
1146 {
1147 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1148 btnBorder = customBorder;
1149 }
1150
1151 // Defaul indentation
1152 if ( m_marginLeft < 0 )
1153 m_marginLeft = GetNativeTextIndent();
1154
1155 int butWidth = btnWidth;
1156
1157 if ( butWidth <= 0 )
1158 butWidth = m_btnWidDefault;
1159 else
1160 m_btnWidDefault = butWidth;
1161
1162 if ( butWidth <= 0 )
1163 return;
1164
1165 int butHeight = sz.y - btnBorder*2;
1166
1167 // Adjust button width
1168 if ( m_btnWid > 0 )
1169 butWidth = m_btnWid;
1170 else
1171 {
1172 // Adjust button width to match aspect ratio
1173 // (but only if control is smaller than best size).
1174 int bestHeight = GetBestSize().y;
1175 int height = GetSize().y;
1176
1177 if ( height < bestHeight )
1178 {
1179 // Make very small buttons square, as it makes
1180 // them accommodate arrow image better and still
1181 // looks decent.
1182 if ( height > 18 )
1183 butWidth = (height*butWidth)/bestHeight;
1184 else
1185 butWidth = butHeight;
1186 }
1187 }
1188
1189 // Adjust button height
1190 if ( m_btnHei > 0 )
1191 butHeight = m_btnHei;
1192
1193 // Use size of normal bitmap if...
1194 // It is larger
1195 // OR
1196 // button width is set to default and blank button bg is not drawn
1197 if ( m_bmpNormal.Ok() )
1198 {
1199 int bmpReqWidth = m_bmpNormal.GetWidth();
1200 int bmpReqHeight = m_bmpNormal.GetHeight();
1201
1202 // If drawing blank button background, we need to add some margin.
1203 if ( m_blankButtonBg )
1204 {
1205 bmpReqWidth += BMP_BUTTON_MARGIN*2;
1206 bmpReqHeight += BMP_BUTTON_MARGIN*2;
1207 }
1208
1209 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
1210 butWidth = bmpReqWidth;
1211 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
1212 butHeight = bmpReqHeight;
1213
1214 // Need to fix height?
1215 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
1216 {
1217 int newY = butHeight+(customBorder*2);
1218 SetClientSize(wxDefaultCoord,newY);
1219 if ( m_bmpNormal.Ok() || m_btnArea.width != butWidth || m_btnArea.height != butHeight )
1220 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1221 else
1222 m_iFlags &= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1223
1224 sz.y = newY;
1225 }
1226 }
1227
1228 int butAreaWid = butWidth + (m_btnSpacingX*2);
1229
1230 m_btnSize.x = butWidth;
1231 m_btnSize.y = butHeight;
1232
1233 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
1234 m_btnArea.y = btnBorder + FOCUS_RING;
1235 m_btnArea.width = butAreaWid;
1236 m_btnArea.height = sz.y - ((btnBorder+FOCUS_RING)*2);
1237
1238 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder + FOCUS_RING;
1239 m_tcArea.y = customBorder + FOCUS_RING;
1240 m_tcArea.width = sz.x - butAreaWid - (customBorder*2) - (FOCUS_RING*2);
1241 m_tcArea.height = sz.y - ((customBorder+FOCUS_RING)*2);
1242
1243 /*
1244 if ( m_text )
1245 {
1246 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1247 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1248 }
1249 */
1250 }
1251
1252 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
1253 {
1254 if ( !m_text )
1255 return;
1256
1257 wxSize sz = GetClientSize();
1258
1259 int customBorder = m_widthCustomBorder;
1260 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
1261 {
1262 int x;
1263
1264 if ( !m_widthCustomPaint )
1265 {
1266 // No special custom paint area - we can use 0 left margin
1267 // with wxTextCtrl.
1268 if ( m_text->SetMargins(0) )
1269 textCtrlXAdjust = 0;
1270 x = m_tcArea.x + m_marginLeft + textCtrlXAdjust;
1271 }
1272 else
1273 {
1274 // There is special custom paint area - it is better to
1275 // use some margin with the wxTextCtrl.
1276 m_text->SetMargins(m_marginLeft);
1277 x = m_tcArea.x + m_widthCustomPaint +
1278 m_marginLeft + textCtrlXAdjust;
1279 }
1280
1281 // Centre textctrl vertically, if needed
1282 #if !TEXTCTRL_TEXT_CENTERED
1283 int tcSizeY = m_text->GetBestSize().y;
1284 int diff0 = sz.y - tcSizeY;
1285 int y = textCtrlYAdjust + (diff0/2);
1286 #else
1287 wxUnusedVar(textCtrlYAdjust);
1288 int y = 0;
1289 #endif
1290
1291 if ( y < customBorder )
1292 y = customBorder;
1293
1294 m_text->SetSize(x,
1295 y,
1296 m_tcArea.width - m_tcArea.x - x,
1297 -1 );
1298
1299 // Make sure textctrl doesn't exceed the bottom custom border
1300 wxSize tsz = m_text->GetSize();
1301 int diff1 = (y + tsz.y) - (sz.y - customBorder);
1302 if ( diff1 >= 0 )
1303 {
1304 tsz.y = tsz.y - diff1 - 1;
1305 m_text->SetSize(tsz);
1306 }
1307 }
1308 else
1309 {
1310 // If it has border, have textctrl fill the entire text field.
1311 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1312 m_tcArea.y,
1313 m_tcArea.width - m_widthCustomPaint,
1314 m_tcArea.height );
1315 }
1316 }
1317
1318 wxSize wxComboCtrlBase::DoGetBestSize() const
1319 {
1320 wxSize sizeText(150,0);
1321
1322 if ( m_text )
1323 sizeText = m_text->GetBestSize();
1324
1325 // TODO: Better method to calculate close-to-native control height.
1326
1327 int fhei;
1328 if ( m_font.Ok() )
1329 fhei = (m_font.GetPointSize()*2) + 5;
1330 else if ( wxNORMAL_FONT->Ok() )
1331 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1332 else
1333 fhei = sizeText.y + 4;
1334
1335 // Need to force height to accomodate bitmap?
1336 int btnSizeY = m_btnSize.y;
1337 if ( m_bmpNormal.Ok() && fhei < btnSizeY )
1338 fhei = btnSizeY;
1339
1340 // Control height doesn't depend on border
1341 /*
1342 // Add border
1343 int border = m_windowStyle & wxBORDER_MASK;
1344 if ( border == wxSIMPLE_BORDER )
1345 fhei += 2;
1346 else if ( border == wxNO_BORDER )
1347 fhei += (m_widthCustomBorder*2);
1348 else
1349 // Sunken etc.
1350 fhei += 4;
1351 */
1352
1353 // Final adjustments
1354 #ifdef __WXGTK__
1355 fhei += 1;
1356 #endif
1357
1358 #ifdef __WXMAC__
1359 // these are the numbers from the HIG:
1360 switch ( m_windowVariant )
1361 {
1362 case wxWINDOW_VARIANT_NORMAL:
1363 default :
1364 fhei = 22;
1365 break;
1366 case wxWINDOW_VARIANT_SMALL:
1367 fhei = 19;
1368 break;
1369 case wxWINDOW_VARIANT_MINI:
1370 fhei = 15;
1371 break;
1372 }
1373 #endif
1374
1375 fhei += 2 * FOCUS_RING;
1376 int width = sizeText.x + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH;
1377
1378 wxSize ret(width, fhei);
1379 CacheBestSize(ret);
1380 return ret;
1381 }
1382
1383 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1384 {
1385 if ( !IsCreated() )
1386 return;
1387
1388 // defined by actual wxComboCtrls
1389 OnResize();
1390
1391 event.Skip();
1392 }
1393
1394 // ----------------------------------------------------------------------------
1395 // standard operations
1396 // ----------------------------------------------------------------------------
1397
1398 bool wxComboCtrlBase::Enable(bool enable)
1399 {
1400 if ( !wxControl::Enable(enable) )
1401 return false;
1402
1403 if ( m_btn )
1404 m_btn->Enable(enable);
1405 if ( m_text )
1406 m_text->Enable(enable);
1407
1408 Refresh();
1409
1410 return true;
1411 }
1412
1413 bool wxComboCtrlBase::Show(bool show)
1414 {
1415 if ( !wxControl::Show(show) )
1416 return false;
1417
1418 if (m_btn)
1419 m_btn->Show(show);
1420
1421 if (m_text)
1422 m_text->Show(show);
1423
1424 return true;
1425 }
1426
1427 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1428 {
1429 if ( !wxControl::SetFont(font) )
1430 return false;
1431
1432 if ( m_text )
1433 {
1434 // Without hiding the wxTextCtrl there would be some
1435 // visible 'flicker' (at least on Windows XP).
1436 m_text->Hide();
1437 m_text->SetFont(font);
1438 OnResize();
1439 m_text->Show();
1440 }
1441
1442 return true;
1443 }
1444
1445 #if wxUSE_TOOLTIPS
1446 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1447 {
1448 wxControl::DoSetToolTip(tooltip);
1449
1450 // Set tool tip for button and text box
1451 if ( tooltip )
1452 {
1453 const wxString &tip = tooltip->GetTip();
1454 if ( m_text ) m_text->SetToolTip(tip);
1455 if ( m_btn ) m_btn->SetToolTip(tip);
1456 }
1457 else
1458 {
1459 if ( m_text ) m_text->SetToolTip( NULL );
1460 if ( m_btn ) m_btn->SetToolTip( NULL );
1461 }
1462 }
1463 #endif // wxUSE_TOOLTIPS
1464
1465 bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour)
1466 {
1467 if ( wxControl::SetForegroundColour(colour) )
1468 {
1469 if ( m_text )
1470 m_text->SetForegroundColour(colour);
1471 return true;
1472 }
1473 return false;
1474 }
1475
1476 bool wxComboCtrlBase::SetBackgroundColour(const wxColour& colour)
1477 {
1478 if ( wxControl::SetBackgroundColour(colour) )
1479 {
1480 if ( m_text )
1481 m_text->SetBackgroundColour(colour);
1482 return true;
1483 }
1484 return false;
1485 }
1486 // ----------------------------------------------------------------------------
1487 // painting
1488 // ----------------------------------------------------------------------------
1489
1490 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1491 // prepare combo box background on area in a way typical on platform
1492 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1493 {
1494 wxSize sz = GetClientSize();
1495 bool isEnabled;
1496 bool doDrawFocusRect; // also selected
1497
1498 // For smaller size control (and for disabled background) use less spacing
1499 int focusSpacingX;
1500 int focusSpacingY;
1501
1502 if ( !(flags & wxCONTROL_ISSUBMENU) )
1503 {
1504 // Drawing control
1505 isEnabled = IsEnabled();
1506 doDrawFocusRect = ShouldDrawFocus() && !(m_iFlags & wxCC_FULL_BUTTON);
1507
1508 // Windows-style: for smaller size control (and for disabled background) use less spacing
1509 focusSpacingX = isEnabled ? 2 : 1;
1510 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1511 }
1512 else
1513 {
1514 // Drawing a list item
1515 isEnabled = true; // they are never disabled
1516 doDrawFocusRect = (flags & wxCONTROL_SELECTED) != 0;
1517
1518 focusSpacingX = 0;
1519 focusSpacingY = 0;
1520 }
1521
1522 // Set the background sub-rectangle for selection, disabled etc
1523 wxRect selRect(rect);
1524 selRect.y += focusSpacingY;
1525 selRect.height -= (focusSpacingY*2);
1526
1527 int wcp = 0;
1528
1529 if ( !(flags & wxCONTROL_ISSUBMENU) )
1530 wcp += m_widthCustomPaint;
1531
1532 selRect.x += wcp + focusSpacingX;
1533 selRect.width -= wcp + (focusSpacingX*2);
1534
1535 wxColour bgCol;
1536 wxColour fgCol;
1537
1538 bool doDrawSelRect = true;
1539
1540 // Determine foreground colour
1541 if ( isEnabled )
1542 {
1543 if ( doDrawFocusRect )
1544 {
1545 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1546 }
1547 else if ( m_hasFgCol )
1548 {
1549 // Honour the custom foreground colour
1550 fgCol = GetForegroundColour();
1551 }
1552 else
1553 {
1554 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1555 }
1556 }
1557 else
1558 {
1559 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
1560 }
1561
1562 // Determine background colour
1563 if ( isEnabled )
1564 {
1565 if ( doDrawFocusRect )
1566 {
1567 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1568 }
1569 else if ( m_hasBgCol )
1570 {
1571 // Honour the custom background colour
1572 bgCol = GetBackgroundColour();
1573 }
1574 else
1575 {
1576 #ifndef __WXMAC__ // see note in OnThemeChange
1577 doDrawSelRect = false;
1578 bgCol = GetBackgroundColour();
1579 #else
1580 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1581 #endif
1582 }
1583 }
1584 else
1585 {
1586 #ifndef __WXMAC__ // see note in OnThemeChange
1587 bgCol = GetBackgroundColour();
1588 #else
1589 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1590 #endif
1591 }
1592
1593 dc.SetTextForeground( fgCol );
1594 dc.SetBrush( bgCol );
1595 if ( doDrawSelRect )
1596 {
1597 dc.SetPen( bgCol );
1598 dc.DrawRectangle( selRect );
1599 }
1600
1601 // Don't clip exactly to the selection rectangle so we can draw
1602 // to the non-selected area in front of it.
1603 wxRect clipRect(rect.x,rect.y,
1604 (selRect.x+selRect.width)-rect.x,rect.height);
1605 dc.SetClippingRegion(clipRect);
1606 }
1607 #else
1608 // Save the library size a bit for platforms that re-implement this.
1609 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1610 {
1611 }
1612 #endif
1613
1614 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags )
1615 {
1616 int drawState = m_btnState;
1617
1618 if ( (m_iFlags & wxCC_BUTTON_STAYS_DOWN) &&
1619 GetPopupWindowState() >= Animating )
1620 drawState |= wxCONTROL_PRESSED;
1621
1622 wxRect drawRect(rect.x+m_btnSpacingX,
1623 rect.y+((rect.height-m_btnSize.y)/2),
1624 m_btnSize.x,
1625 m_btnSize.y);
1626
1627 // Make sure area is not larger than the control
1628 if ( drawRect.y < rect.y )
1629 drawRect.y = rect.y;
1630 if ( drawRect.height > rect.height )
1631 drawRect.height = rect.height;
1632
1633 bool enabled = IsEnabled();
1634
1635 if ( !enabled )
1636 drawState |= wxCONTROL_DISABLED;
1637
1638 if ( !m_bmpNormal.Ok() )
1639 {
1640 if ( flags & Button_BitmapOnly )
1641 return;
1642
1643 // Need to clear button background even if m_btn is present
1644 if ( flags & Button_PaintBackground )
1645 {
1646 wxColour bgCol;
1647
1648 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1649 bgCol = GetParent()->GetBackgroundColour();
1650 else
1651 bgCol = GetBackgroundColour();
1652
1653 dc.SetBrush(bgCol);
1654 dc.SetPen(bgCol);
1655 dc.DrawRectangle(rect);
1656 }
1657
1658 // Draw standard button
1659 wxRendererNative::Get().DrawComboBoxDropButton(this,
1660 dc,
1661 drawRect,
1662 drawState);
1663 }
1664 else
1665 {
1666 // Draw bitmap
1667
1668 wxBitmap* pBmp;
1669
1670 if ( !enabled )
1671 pBmp = &m_bmpDisabled;
1672 else if ( m_btnState & wxCONTROL_PRESSED )
1673 pBmp = &m_bmpPressed;
1674 else if ( m_btnState & wxCONTROL_CURRENT )
1675 pBmp = &m_bmpHover;
1676 else
1677 pBmp = &m_bmpNormal;
1678
1679 if ( m_blankButtonBg )
1680 {
1681 // If using blank button background, we need to clear its background
1682 // with button face colour instead of colour for rest of the control.
1683 if ( flags & Button_PaintBackground )
1684 {
1685 wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1686 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1687 dc.SetPen(bgCol);
1688 dc.SetBrush(bgCol);
1689 dc.DrawRectangle(rect);
1690 }
1691
1692 if ( !(flags & Button_BitmapOnly) )
1693 {
1694 wxRendererNative::Get().DrawPushButton(this,
1695 dc,
1696 drawRect,
1697 drawState);
1698 }
1699 }
1700 else
1701
1702 {
1703 // Need to clear button background even if m_btn is present
1704 // (assume non-button background was cleared just before this call so brushes are good)
1705 if ( flags & Button_PaintBackground )
1706 dc.DrawRectangle(rect);
1707 }
1708
1709 // Draw bitmap centered in drawRect
1710 dc.DrawBitmap(*pBmp,
1711 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1712 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1713 true);
1714 }
1715 }
1716
1717 void wxComboCtrlBase::RecalcAndRefresh()
1718 {
1719 if ( IsCreated() )
1720 {
1721 wxSizeEvent evt(GetSize(),GetId());
1722 GetEventHandler()->ProcessEvent(evt);
1723 Refresh();
1724 }
1725 }
1726
1727 // ----------------------------------------------------------------------------
1728 // miscellaneous event handlers
1729 // ----------------------------------------------------------------------------
1730
1731 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1732 {
1733 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1734 {
1735 if ( m_ignoreEvtText > 0 )
1736 {
1737 m_ignoreEvtText--;
1738 return;
1739 }
1740 }
1741
1742 // Change event id, object and string before relaying it forward
1743 event.SetId(GetId());
1744 wxString s = event.GetString();
1745 event.SetEventObject(this);
1746 event.SetString(s);
1747 event.Skip();
1748 }
1749
1750 // call if cursor is on button area or mouse is captured for the button
1751 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1752 int flags )
1753 {
1754 int type = event.GetEventType();
1755
1756 if ( type == wxEVT_MOTION )
1757 {
1758 if ( (flags & wxCC_MF_ON_BUTTON) &&
1759 IsPopupWindowState(Hidden) )
1760 {
1761 if ( !(m_btnState & wxCONTROL_CURRENT) )
1762 {
1763 // Mouse hover begins
1764 m_btnState |= wxCONTROL_CURRENT;
1765 if ( HasCapture() ) // Retain pressed state.
1766 m_btnState |= wxCONTROL_PRESSED;
1767 Refresh();
1768 }
1769 }
1770 else if ( (m_btnState & wxCONTROL_CURRENT) )
1771 {
1772 // Mouse hover ends
1773 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1774 Refresh();
1775 }
1776 }
1777 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1778 {
1779 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1780 {
1781 m_btnState |= wxCONTROL_PRESSED;
1782 Refresh();
1783
1784 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1785 OnButtonClick();
1786 else
1787 // If showing popup now, do not capture mouse or there will be interference
1788 CaptureMouse();
1789 }
1790 }
1791 else if ( type == wxEVT_LEFT_UP )
1792 {
1793
1794 // Only accept event if mouse was left-press was previously accepted
1795 if ( HasCapture() )
1796 ReleaseMouse();
1797
1798 if ( m_btnState & wxCONTROL_PRESSED )
1799 {
1800 // If mouse was inside, fire the click event.
1801 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1802 {
1803 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1804 OnButtonClick();
1805 }
1806
1807 m_btnState &= ~(wxCONTROL_PRESSED);
1808 Refresh();
1809 }
1810 }
1811 else if ( type == wxEVT_LEAVE_WINDOW )
1812 {
1813 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1814 {
1815 m_btnState &= ~(wxCONTROL_CURRENT);
1816
1817 // Mouse hover ends
1818 if ( IsPopupWindowState(Hidden) )
1819 {
1820 m_btnState &= ~(wxCONTROL_PRESSED);
1821 Refresh();
1822 }
1823 }
1824 }
1825 else
1826 return false;
1827
1828 // Never have 'hot' state when popup is being shown
1829 // (this is mostly needed because of the animation).
1830 if ( !IsPopupWindowState(Hidden) )
1831 m_btnState &= ~wxCONTROL_CURRENT;
1832
1833 return true;
1834 }
1835
1836 // returns true if event was consumed or filtered
1837 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1838 int WXUNUSED(flags) )
1839 {
1840 wxLongLong t = ::wxGetLocalTimeMillis();
1841 int evtType = event.GetEventType();
1842
1843 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1844 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1845 {
1846 if ( IsPopupWindowState(Visible) &&
1847 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1848 {
1849 HidePopup(true);
1850 return true;
1851 }
1852 }
1853 #endif
1854
1855 // Filter out clicks on button immediately after popup dismiss
1856 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1857 {
1858 event.SetEventType(0);
1859 return true;
1860 }
1861
1862 return false;
1863 }
1864
1865 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1866 {
1867 int evtType = event.GetEventType();
1868
1869 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1870 (m_windowStyle & wxCB_READONLY) )
1871 {
1872 if ( GetPopupWindowState() >= Animating )
1873 {
1874 #if USES_WXPOPUPWINDOW
1875 // Click here always hides the popup.
1876 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1877 HidePopup(true);
1878 #endif
1879 }
1880 else
1881 {
1882 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1883 {
1884 // In read-only mode, clicking the text is the
1885 // same as clicking the button.
1886 OnButtonClick();
1887 }
1888 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1889 {
1890 //if ( m_popupInterface->CycleValue() )
1891 // Refresh();
1892 if ( m_popupInterface )
1893 m_popupInterface->OnComboDoubleClick();
1894 }
1895 }
1896 }
1897 else if ( evtType == wxEVT_MOUSEWHEEL )
1898 {
1899 if ( IsPopupShown() )
1900 {
1901 // relay (some) mouse events to the popup
1902 m_popup->GetEventHandler()->ProcessEvent(event);
1903 }
1904 else if ( event.GetWheelAxis() == 0 &&
1905 event.GetWheelRotation() != 0 &&
1906 event.GetModifiers() == 0 )
1907 {
1908 // Translate mousewheel actions into key up/down. This is
1909 // the simplest way of getting native behaviour: scrolling the
1910 // wheel moves selection up/down by one item.
1911 wxKeyEvent kevent(wxEVT_KEY_DOWN);
1912 kevent.m_keyCode = event.GetWheelRotation() > 0
1913 ? WXK_UP
1914 : WXK_DOWN;
1915 GetEventHandler()->ProcessEvent(kevent);
1916 }
1917 else
1918 {
1919 event.Skip();
1920 }
1921 }
1922 else if ( evtType )
1923 {
1924 event.Skip();
1925 }
1926 }
1927
1928 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1929 {
1930 if ( IsPopupShown() )
1931 {
1932 // pass it to the popped up control
1933 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
1934 }
1935 else // no popup
1936 {
1937 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1938
1939 if ( mainCtrl->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
1940 {
1941 if ( mainCtrl->HandleAsNavigationKey(event) )
1942 return;
1943 }
1944
1945 if ( IsKeyPopupToggle(event) )
1946 {
1947 OnButtonClick();
1948 return;
1949 }
1950
1951 int comboStyle = GetWindowStyle();
1952 wxComboPopup* popupInterface = GetPopupControl();
1953
1954 if ( !popupInterface )
1955 {
1956 event.Skip();
1957 return;
1958 }
1959
1960 int keycode = event.GetKeyCode();
1961
1962 if ( (comboStyle & wxCB_READONLY) ||
1963 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
1964 {
1965 popupInterface->OnComboKeyEvent(event);
1966 }
1967 else
1968 event.Skip();
1969 }
1970 }
1971
1972 void wxComboCtrlBase::OnCharEvent(wxKeyEvent& event)
1973 {
1974 if ( IsPopupShown() )
1975 {
1976 // pass it to the popped up control
1977 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
1978 }
1979 else // no popup
1980 {
1981 wxComboPopup* popupInterface = GetPopupControl();
1982 if ( popupInterface )
1983 {
1984 popupInterface->OnComboCharEvent(event);
1985 }
1986 else
1987 {
1988 event.Skip();
1989 }
1990 }
1991 }
1992
1993 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
1994 {
1995 if ( event.GetEventType() == wxEVT_SET_FOCUS )
1996 {
1997 wxWindow* tc = GetTextCtrl();
1998 if ( tc && tc != DoFindFocus() )
1999 {
2000 tc->SetFocus();
2001 }
2002 }
2003
2004 Refresh();
2005 }
2006
2007 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
2008 {
2009 if ( m_resetFocus )
2010 {
2011 m_resetFocus = false;
2012 wxWindow* tc = GetTextCtrl();
2013 if ( tc )
2014 tc->SetFocus();
2015 }
2016 }
2017
2018 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
2019 {
2020 OnThemeChange();
2021 // left margin may also have changed
2022 if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
2023 m_marginLeft = GetNativeTextIndent();
2024 RecalcAndRefresh();
2025 }
2026
2027 // ----------------------------------------------------------------------------
2028 // popup handling
2029 // ----------------------------------------------------------------------------
2030
2031 // Create popup window and the child control
2032 void wxComboCtrlBase::CreatePopup()
2033 {
2034 wxComboPopup* popupInterface = m_popupInterface;
2035 wxWindow* popup;
2036
2037 if ( !m_winPopup )
2038 {
2039 #ifdef wxComboPopupWindowBase2
2040 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
2041 {
2042 #if !USES_GENERICTLW
2043 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
2044 #else
2045 int tlwFlags = wxNO_BORDER;
2046 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2047 tlwFlags |= wxFRAME_NO_TASKBAR;
2048 #endif
2049
2050 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2051 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY,
2052 wxPoint(-21,-21), wxSize(20, 20),
2053 tlwFlags );
2054 #else
2055 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
2056 wxPoint(-21,-21), wxSize(20, 20),
2057 tlwFlags );
2058 #endif
2059 #endif
2060 m_popupWinType = SECONDARY_POPUP_TYPE;
2061 }
2062 else
2063 #endif // wxComboPopupWindowBase2
2064 {
2065 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
2066 m_popupWinType = PRIMARY_POPUP_TYPE;
2067 }
2068 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
2069 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
2070 }
2071
2072 popupInterface->Create(m_winPopup);
2073 m_popup = popup = popupInterface->GetControl();
2074
2075 m_popupEvtHandler = new wxComboPopupEvtHandler(this);
2076 popup->PushEventHandler( m_popupEvtHandler );
2077
2078 // This may be helpful on some platforms
2079 // (eg. it bypasses a wxGTK popupwindow bug where
2080 // window is not initially hidden when it should be)
2081 m_winPopup->Hide();
2082
2083 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
2084 }
2085
2086 // Destroy popup window and the child control
2087 void wxComboCtrlBase::DestroyPopup()
2088 {
2089 HidePopup(true);
2090
2091 if ( m_popup )
2092 m_popup->RemoveEventHandler(m_popupEvtHandler);
2093
2094 wxDELETE(m_popupEvtHandler);
2095
2096 wxDELETE(m_popupInterface);
2097
2098 if ( m_winPopup )
2099 {
2100 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
2101 wxDELETE(m_popupWinEvtHandler);
2102 m_winPopup->Destroy();
2103 m_winPopup = NULL;
2104 }
2105
2106 m_popup = NULL;
2107 }
2108
2109 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
2110 {
2111 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
2112
2113 DestroyPopup();
2114
2115 iface->InitBase(this);
2116 iface->Init();
2117
2118 m_popupInterface = iface;
2119
2120 if ( !iface->LazyCreate() )
2121 {
2122 CreatePopup();
2123 }
2124 else
2125 {
2126 m_popup = NULL;
2127 }
2128
2129 // This must be done after creation
2130 if ( m_valueString.length() )
2131 {
2132 iface->SetStringValue(m_valueString);
2133 //Refresh();
2134 }
2135 }
2136
2137 // Ensures there is atleast the default popup
2138 void wxComboCtrlBase::EnsurePopupControl()
2139 {
2140 if ( !m_popupInterface )
2141 SetPopupControl(NULL);
2142 }
2143
2144 void wxComboCtrlBase::OnButtonClick()
2145 {
2146 // Derived classes can override this method for totally custom
2147 // popup action
2148 switch ( GetPopupWindowState() )
2149 {
2150 case Hidden:
2151 {
2152 Popup();
2153 break;
2154 }
2155
2156 case Animating:
2157 case Visible:
2158 {
2159 HidePopup(true);
2160 break;
2161 }
2162 }
2163 }
2164
2165 void wxComboCtrlBase::Popup()
2166 {
2167 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
2168 event.SetEventObject(this);
2169 HandleWindowEvent(event);
2170
2171 ShowPopup();
2172 }
2173
2174 void wxComboCtrlBase::ShowPopup()
2175 {
2176 EnsurePopupControl();
2177 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
2178
2179 if ( IsPopupWindowState(Animating) )
2180 return;
2181
2182 SetFocus();
2183
2184 // Space above and below
2185 int screenHeight;
2186 wxPoint scrPos;
2187 int spaceAbove;
2188 int spaceBelow;
2189 int maxHeightPopup;
2190 wxSize ctrlSz = GetSize();
2191
2192 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
2193 scrPos = GetParent()->ClientToScreen(GetPosition());
2194
2195 spaceAbove = scrPos.y;
2196 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
2197
2198 maxHeightPopup = spaceBelow;
2199 if ( spaceAbove > spaceBelow )
2200 maxHeightPopup = spaceAbove;
2201
2202 // Width
2203 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
2204
2205 if ( widthPopup < m_widthMinPopup )
2206 widthPopup = m_widthMinPopup;
2207
2208 wxWindow* winPopup = m_winPopup;
2209 wxWindow* popup;
2210
2211 // Need to disable tab traversal of parent
2212 //
2213 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2214 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2215 // that if transient popup is open, then tab traversal is to be ignored.
2216 // However, I think this code would still be needed for cases where
2217 // transient popup doesn't work yet (wxWinCE?).
2218 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
2219 wxWindow* parent = mainCtrl->GetParent();
2220 int parentFlags = parent->GetWindowStyle();
2221 if ( parentFlags & wxTAB_TRAVERSAL )
2222 {
2223 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
2224 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
2225 }
2226
2227 if ( !winPopup )
2228 {
2229 CreatePopup();
2230 winPopup = m_winPopup;
2231 popup = m_popup;
2232 }
2233 else
2234 {
2235 popup = m_popup;
2236 }
2237
2238 winPopup->Enable();
2239
2240 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
2241
2242 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
2243 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
2244 maxHeightPopup);
2245
2246 popup->SetSize(adjustedSize);
2247 popup->Move(0,0);
2248 m_popupInterface->OnPopup();
2249
2250 //
2251 // Reposition and resize popup window
2252 //
2253
2254 wxSize szp = popup->GetSize();
2255
2256 int popupX;
2257 int popupY = scrPos.y + ctrlSz.y;
2258
2259 // Default anchor is wxLEFT
2260 int anchorSide = m_anchorSide;
2261 if ( !anchorSide )
2262 anchorSide = wxLEFT;
2263
2264 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
2265 int leftX = scrPos.x - m_extLeft;
2266
2267 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
2268 leftX -= ctrlSz.x;
2269
2270 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
2271
2272 // If there is not enough horizontal space, anchor on the other side.
2273 // If there is no space even then, place the popup at x 0.
2274 if ( anchorSide == wxRIGHT )
2275 {
2276 if ( rightX < 0 )
2277 {
2278 if ( (leftX+szp.x) < screenWidth )
2279 anchorSide = wxLEFT;
2280 else
2281 anchorSide = 0;
2282 }
2283 }
2284 else
2285 {
2286 if ( (leftX+szp.x) >= screenWidth )
2287 {
2288 if ( rightX >= 0 )
2289 anchorSide = wxRIGHT;
2290 else
2291 anchorSide = 0;
2292 }
2293 }
2294
2295 // Select x coordinate according to the anchor side
2296 if ( anchorSide == wxRIGHT )
2297 popupX = rightX;
2298 else if ( anchorSide == wxLEFT )
2299 popupX = leftX;
2300 else
2301 popupX = 0;
2302
2303 int showFlags = CanDeferShow;
2304
2305 if ( spaceBelow < szp.y )
2306 {
2307 popupY = scrPos.y - szp.y;
2308 showFlags |= ShowAbove;
2309 }
2310
2311 #if INSTALL_TOPLEV_HANDLER
2312 // Put top level window event handler into place
2313 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
2314 {
2315 if ( !m_toplevEvtHandler )
2316 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
2317
2318 wxWindow* toplev = ::wxGetTopLevelParent( this );
2319 wxASSERT( toplev );
2320 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
2321 toplev->PushEventHandler( m_toplevEvtHandler );
2322 }
2323 #endif
2324
2325 // Set string selection (must be this way instead of SetStringSelection)
2326 if ( m_text )
2327 {
2328 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2329 m_text->SelectAll();
2330
2331 m_popupInterface->SetStringValue( m_text->GetValue() );
2332 }
2333 else
2334 {
2335 // This is neede since focus/selection indication may change when popup is shown
2336 Refresh();
2337 }
2338
2339 // This must be after SetStringValue
2340 m_popupWinState = Animating;
2341
2342 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
2343
2344 m_popup = popup;
2345 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
2346 AnimateShow( popupWinRect, showFlags ) )
2347 {
2348 DoShowPopup( popupWinRect, showFlags );
2349 }
2350 }
2351
2352 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
2353 {
2354 return true;
2355 }
2356
2357 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
2358 {
2359 wxWindow* winPopup = m_winPopup;
2360
2361 if ( IsPopupWindowState(Animating) )
2362 {
2363 // Make sure the popup window is shown in the right position.
2364 // Should not matter even if animation already did this.
2365
2366 // Some platforms (GTK) may like SetSize and Move to be separate
2367 // (though the bug was probably fixed).
2368 winPopup->SetSize( rect );
2369
2370 #if USES_WXPOPUPTRANSIENTWINDOW
2371 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2372 ((wxPopupTransientWindow*)winPopup)->Popup(m_popup);
2373 else
2374 #endif
2375 winPopup->Show();
2376
2377 m_popupWinState = Visible;
2378
2379 // If popup window was a generic top-level window, or the
2380 // wxPopupWindow implemenation on this platform is classified as
2381 // perfect, then we should be able to safely set focus to the popup
2382 // control.
2383 if ( IsPopupWinTypePerfect(m_popupWinType) )
2384 m_popup->SetFocus();
2385 }
2386 else if ( IsPopupWindowState(Hidden) )
2387 {
2388 // Animation was aborted
2389
2390 wxASSERT( !winPopup->IsShown() );
2391
2392 m_popupWinState = Hidden;
2393 }
2394
2395 Refresh();
2396 }
2397
2398 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
2399 {
2400 // Just in case, avoid double dismiss
2401 if ( IsPopupWindowState(Hidden) )
2402 return;
2403
2404 // This must be set before focus - otherwise there will be recursive
2405 // OnPopupDismisses.
2406 m_popupWinState = Hidden;
2407
2408 //SetFocus();
2409 m_winPopup->Disable();
2410
2411 // Inform popup control itself
2412 m_popupInterface->OnDismiss();
2413
2414 if ( m_popupEvtHandler )
2415 ((wxComboPopupEvtHandler*)m_popupEvtHandler)->OnPopupDismiss();
2416
2417 #if INSTALL_TOPLEV_HANDLER
2418 // Remove top level window event handler
2419 if ( m_toplevEvtHandler )
2420 {
2421 wxWindow* toplev = ::wxGetTopLevelParent( this );
2422 if ( toplev )
2423 toplev->RemoveEventHandler( m_toplevEvtHandler );
2424 }
2425 #endif
2426
2427 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
2428
2429 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2430 m_timeCanAcceptClick += 150;
2431
2432 // If cursor not on dropdown button, then clear its state
2433 // (technically not required by all ports, but do it for all just in case)
2434 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
2435 m_btnState = 0;
2436
2437 // Return parent's tab traversal flag.
2438 // See ShowPopup for notes.
2439 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
2440 {
2441 wxWindow* parent = GetParent();
2442 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2443 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2444 }
2445
2446 // refresh control (necessary even if m_text)
2447 Refresh();
2448
2449 SetFocus();
2450
2451 if ( generateEvent )
2452 {
2453 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId());
2454 event.SetEventObject(this);
2455 HandleWindowEvent(event);
2456 }
2457 }
2458
2459 void wxComboCtrlBase::HidePopup(bool generateEvent)
2460 {
2461 // Should be able to call this without popup interface
2462 if ( IsPopupWindowState(Hidden) )
2463 return;
2464
2465 // transfer value and show it in textctrl, if any
2466 if ( !IsPopupWindowState(Animating) )
2467 SetValueByUser( m_popupInterface->GetStringValue() );
2468
2469 m_winPopup->Hide();
2470
2471 OnPopupDismiss(generateEvent);
2472 }
2473
2474 // ----------------------------------------------------------------------------
2475 // customization methods
2476 // ----------------------------------------------------------------------------
2477
2478 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2479 int side, int spacingX )
2480 {
2481 m_btnWid = width;
2482 m_btnHei = height;
2483 m_btnSide = side;
2484 m_btnSpacingX = spacingX;
2485
2486 if ( width > 0 || height > 0 || spacingX )
2487 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
2488
2489 RecalcAndRefresh();
2490 }
2491
2492 wxSize wxComboCtrlBase::GetButtonSize()
2493 {
2494 if ( m_btnSize.x > 0 )
2495 return m_btnSize;
2496
2497 wxSize retSize(m_btnWid,m_btnHei);
2498
2499 // Need to call CalculateAreas now if button size is
2500 // is not explicitly specified.
2501 if ( retSize.x <= 0 || retSize.y <= 0)
2502 {
2503 OnResize();
2504
2505 retSize = m_btnSize;
2506 }
2507
2508 return retSize;
2509 }
2510
2511 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2512 bool blankButtonBg,
2513 const wxBitmap& bmpPressed,
2514 const wxBitmap& bmpHover,
2515 const wxBitmap& bmpDisabled )
2516 {
2517 m_bmpNormal = bmpNormal;
2518 m_blankButtonBg = blankButtonBg;
2519
2520 if ( bmpPressed.Ok() )
2521 m_bmpPressed = bmpPressed;
2522 else
2523 m_bmpPressed = bmpNormal;
2524
2525 if ( bmpHover.Ok() )
2526 m_bmpHover = bmpHover;
2527 else
2528 m_bmpHover = bmpNormal;
2529
2530 if ( bmpDisabled.Ok() )
2531 m_bmpDisabled = bmpDisabled;
2532 else
2533 m_bmpDisabled = bmpNormal;
2534
2535 RecalcAndRefresh();
2536 }
2537
2538 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2539 {
2540 if ( m_text )
2541 {
2542 // move textctrl accordingly
2543 wxRect r = m_text->GetRect();
2544 int inc = width - m_widthCustomPaint;
2545 r.x += inc;
2546 r.width -= inc;
2547 m_text->SetSize( r );
2548 }
2549
2550 m_widthCustomPaint = width;
2551
2552 RecalcAndRefresh();
2553 }
2554
2555 bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
2556 {
2557 // For general sanity's sake, we ignore top margin. Instead
2558 // we will always try to center the text vertically.
2559 bool res = true;
2560
2561 if ( margins.x != -1 )
2562 {
2563 m_marginLeft = margins.x;
2564 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2565 }
2566 else
2567 {
2568 m_marginLeft = GetNativeTextIndent();
2569 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2570 }
2571
2572 if ( margins.y != -1 )
2573 {
2574 res = false;
2575 }
2576
2577 RecalcAndRefresh();
2578
2579 return res;
2580 }
2581
2582 wxPoint wxComboCtrlBase::DoGetMargins() const
2583 {
2584 return wxPoint(m_marginLeft, -1);
2585 }
2586
2587 #if WXWIN_COMPATIBILITY_2_8
2588 void wxComboCtrlBase::SetTextIndent( int indent )
2589 {
2590 if ( indent < 0 )
2591 {
2592 m_marginLeft = GetNativeTextIndent();
2593 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2594 }
2595 else
2596 {
2597 m_marginLeft = indent;
2598 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2599 }
2600
2601 RecalcAndRefresh();
2602 }
2603
2604 wxCoord wxComboCtrlBase::GetTextIndent() const
2605 {
2606 return m_marginLeft;
2607 }
2608 #endif
2609
2610 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2611 {
2612 return DEFAULT_TEXT_INDENT;
2613 }
2614
2615 void wxComboCtrlBase::SetTextCtrlStyle( int style )
2616 {
2617 m_textCtrlStyle = style;
2618
2619 if ( m_text )
2620 m_text->SetWindowStyle(style);
2621 }
2622
2623 // ----------------------------------------------------------------------------
2624 // wxTextEntry interface
2625 // ----------------------------------------------------------------------------
2626
2627 wxString wxComboCtrlBase::DoGetValue() const
2628 {
2629 if ( m_text )
2630 return m_text->GetValue();
2631 return m_valueString;
2632 }
2633
2634 void wxComboCtrlBase::SetValueWithEvent(const wxString& value,
2635 bool withEvent)
2636 {
2637 DoSetValue(value, withEvent ? SetValue_SendEvent : 0);
2638 }
2639
2640 void wxComboCtrlBase::OnSetValue(const wxString& value)
2641 {
2642 // Note: before wxComboCtrl inherited from wxTextEntry,
2643 // this code used to be in SetValueWithEvent().
2644
2645 // Since wxComboPopup may want to paint the combo as well, we need
2646 // to set the string value here (as well as sometimes in ShowPopup).
2647 if ( m_valueString != value )
2648 {
2649 bool found = true;
2650 wxString trueValue = value;
2651
2652 // Conform to wxComboBox behavior: read-only control can only accept
2653 // valid list items and empty string
2654 if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() )
2655 {
2656 found = m_popupInterface->FindItem(value,
2657 &trueValue);
2658 }
2659
2660 if ( found )
2661 {
2662 m_valueString = trueValue;
2663
2664 EnsurePopupControl();
2665
2666 if ( m_popupInterface )
2667 m_popupInterface->SetStringValue(trueValue);
2668 }
2669 }
2670
2671 Refresh();
2672 }
2673
2674 void wxComboCtrlBase::SetValueByUser(const wxString& value)
2675 {
2676 // NB: Order of function calls is important here. Otherwise
2677 // the SelectAll() may not work.
2678
2679 if ( m_text )
2680 {
2681 m_text->SetValue(value);
2682
2683 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2684 m_text->SelectAll();
2685 }
2686
2687 OnSetValue(value);
2688 }
2689
2690 // In this SetValue variant wxComboPopup::SetStringValue is not called
2691 void wxComboCtrlBase::SetText(const wxString& value)
2692 {
2693 // Unlike in SetValue(), this must be called here or
2694 // the behaviour will no be consistent in readonlys.
2695 EnsurePopupControl();
2696
2697 m_valueString = value;
2698
2699 if ( m_text )
2700 {
2701 m_ignoreEvtText++;
2702 m_text->SetValue( value );
2703 }
2704
2705 Refresh();
2706 }
2707
2708 void wxComboCtrlBase::Copy()
2709 {
2710 if ( m_text )
2711 m_text->Copy();
2712 }
2713
2714 void wxComboCtrlBase::Cut()
2715 {
2716 if ( m_text )
2717 m_text->Cut();
2718 }
2719
2720 void wxComboCtrlBase::Paste()
2721 {
2722 if ( m_text )
2723 m_text->Paste();
2724 }
2725
2726 void wxComboCtrlBase::SetInsertionPoint(long pos)
2727 {
2728 if ( m_text )
2729 m_text->SetInsertionPoint(pos);
2730 }
2731
2732 long wxComboCtrlBase::GetInsertionPoint() const
2733 {
2734 if ( m_text )
2735 return m_text->GetInsertionPoint();
2736
2737 return 0;
2738 }
2739
2740 long wxComboCtrlBase::GetLastPosition() const
2741 {
2742 if ( m_text )
2743 return m_text->GetLastPosition();
2744
2745 return 0;
2746 }
2747
2748 void wxComboCtrlBase::WriteText(const wxString& text)
2749 {
2750 if ( m_text )
2751 {
2752 m_text->WriteText(text);
2753 OnSetValue(m_text->GetValue());
2754 }
2755 else
2756 {
2757 OnSetValue(text);
2758 }
2759 }
2760
2761 void wxComboCtrlBase::DoSetValue(const wxString& value, int flags)
2762 {
2763 if ( m_text )
2764 {
2765 if ( flags & SetValue_SendEvent )
2766 m_text->SetValue(value);
2767 else
2768 m_text->ChangeValue(value);
2769 }
2770
2771 OnSetValue(value);
2772 }
2773
2774 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2775 {
2776 if ( m_text )
2777 {
2778 m_text->Replace(from, to, value);
2779 OnSetValue(m_text->GetValue());
2780 }
2781 }
2782
2783 void wxComboCtrlBase::Remove(long from, long to)
2784 {
2785 if ( m_text )
2786 {
2787 m_text->Remove(from, to);
2788 OnSetValue(m_text->GetValue());
2789 }
2790 }
2791
2792 void wxComboCtrlBase::SetSelection(long from, long to)
2793 {
2794 if ( m_text )
2795 m_text->SetSelection(from, to);
2796 }
2797
2798 void wxComboCtrlBase::GetSelection(long *from, long *to) const
2799 {
2800 if ( m_text )
2801 {
2802 m_text->GetSelection(from, to);
2803 }
2804 else
2805 {
2806 *from = 0;
2807 *to = 0;
2808 }
2809 }
2810
2811 bool wxComboCtrlBase::IsEditable() const
2812 {
2813 if ( m_text )
2814 return m_text->IsEditable();
2815 return false;
2816 }
2817
2818 void wxComboCtrlBase::SetEditable(bool editable)
2819 {
2820 if ( m_text )
2821 m_text->SetEditable(editable);
2822 }
2823
2824 void wxComboCtrlBase::Undo()
2825 {
2826 if ( m_text )
2827 m_text->Undo();
2828 }
2829
2830 void wxComboCtrlBase::Redo()
2831 {
2832 if ( m_text )
2833 m_text->Redo();
2834 }
2835
2836 bool wxComboCtrlBase::CanUndo() const
2837 {
2838 if ( m_text )
2839 return m_text->CanUndo();
2840
2841 return false;
2842 }
2843
2844 bool wxComboCtrlBase::CanRedo() const
2845 {
2846 if ( m_text )
2847 return m_text->CanRedo();
2848
2849 return false;
2850 }
2851
2852 bool wxComboCtrlBase::SetHint(const wxString& hint)
2853 {
2854 m_hintText = hint;
2855 bool res = true;
2856 if ( m_text )
2857 res = m_text->SetHint(hint);
2858 Refresh();
2859 return res;
2860 }
2861
2862 wxString wxComboCtrlBase::GetHint() const
2863 {
2864 return m_hintText;
2865 }
2866
2867 #endif // wxUSE_COMBOCTRL