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