]> git.saurik.com Git - wxWidgets.git/blob - src/common/combocmn.cpp
Focus event recursion fix
[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/log.h"
32 #include "wx/dcclient.h"
33 #include "wx/settings.h"
34 #include "wx/dialog.h"
35 #include "wx/timer.h"
36 #endif
37
38 #include "wx/tooltip.h"
39
40 #include "wx/combo.h"
41
42
43
44 // constants
45 // ----------------------------------------------------------------------------
46
47 #define DEFAULT_DROPBUTTON_WIDTH 19
48
49 #define BMP_BUTTON_MARGIN 4
50
51 #define DEFAULT_POPUP_HEIGHT 400
52
53 #define DEFAULT_TEXT_INDENT 3
54
55 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
56
57
58 #if defined(__WXMSW__)
59
60 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
61 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
62 // native controls work on it like normal.
63 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
64 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
65
66 //#undef wxUSE_POPUPWIN
67 //#define wxUSE_POPUPWIN 0
68
69 #elif defined(__WXGTK__)
70
71 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
72 // this bug: If wxDialog is hidden, its position becomes corrupt
73 // between hide and next show, but without internal coordinates being
74 // reflected (or something like that - atleast commenting out ->Hide()
75 // seemed to eliminate the position change).
76
77 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
78 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
79 // native controls work on it like normal.
80 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
81 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
82
83 #elif defined(__WXMAC__)
84
85 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
86 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
87 // native controls work on it like normal.
88 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
89 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
90
91 #else
92
93 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
94 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
95 // native controls work on it like normal.
96 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
97 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
98
99 #endif
100
101
102 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
103 // what the wxUSE_POPUPWIN says.
104 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
105 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
106 #undef wxUSE_POPUPWIN
107 #define wxUSE_POPUPWIN 0
108 #endif
109
110
111 #if wxUSE_POPUPWIN
112 #include "wx/popupwin.h"
113 #else
114 #undef USE_TRANSIENT_POPUP
115 #define USE_TRANSIENT_POPUP 0
116 #endif
117
118
119 // Define different types of popup windows
120 enum
121 {
122 POPUPWIN_NONE = 0,
123 POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1,
124 POPUPWIN_WXPOPUPWINDOW = 2,
125 POPUPWIN_WXDIALOG = 3
126 };
127
128
129 #if USE_TRANSIENT_POPUP
130 // wxPopupTransientWindow is implemented
131
132 #define wxComboPopupWindowBase wxPopupTransientWindow
133 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
134 #define USES_WXPOPUPTRANSIENTWINDOW 1
135
136 #if TRANSIENT_POPUPWIN_IS_PERFECT
137 //
138 #elif POPUPWIN_IS_PERFECT
139 #define wxComboPopupWindowBase2 wxPopupWindow
140 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
141 #define USES_WXPOPUPWINDOW 1
142 #else
143 #define wxComboPopupWindowBase2 wxDialog
144 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
145 #define USES_WXDIALOG 1
146 #endif
147
148 #elif wxUSE_POPUPWIN
149 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
150
151 #define wxComboPopupWindowBase wxPopupWindow
152 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
153 #define USES_WXPOPUPWINDOW 1
154
155 #if !POPUPWIN_IS_PERFECT
156 #define wxComboPopupWindowBase2 wxDialog
157 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
158 #define USES_WXDIALOG 1
159 #endif
160
161 #else
162 // wxPopupWindow is not implemented
163
164 #define wxComboPopupWindowBase wxDialog
165 #define PRIMARY_POPUP_TYPE POPUPWIN_WXDIALOG
166 #define USES_WXDIALOG 1
167
168 #endif
169
170
171 #ifndef USES_WXPOPUPTRANSIENTWINDOW
172 #define USES_WXPOPUPTRANSIENTWINDOW 0
173 #endif
174
175 #ifndef USES_WXPOPUPWINDOW
176 #define USES_WXPOPUPWINDOW 0
177 #endif
178
179 #ifndef USES_WXDIALOG
180 #define USES_WXDIALOG 0
181 #endif
182
183
184 #if USES_WXPOPUPWINDOW
185 #define INSTALL_TOPLEV_HANDLER 1
186 #else
187 #define INSTALL_TOPLEV_HANDLER 0
188 #endif
189
190
191 //
192 // ** TODO **
193 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
194 //
195
196
197 // ----------------------------------------------------------------------------
198 // wxComboFrameEventHandler takes care of hiding the popup when events happen
199 // in its top level parent.
200 // ----------------------------------------------------------------------------
201
202 #if INSTALL_TOPLEV_HANDLER
203
204 //
205 // This will no longer be necessary after wxTransientPopupWindow
206 // works well on all platforms.
207 //
208
209 class wxComboFrameEventHandler : public wxEvtHandler
210 {
211 public:
212 wxComboFrameEventHandler( wxComboCtrlBase* pCb );
213 virtual ~wxComboFrameEventHandler();
214
215 void OnPopup();
216
217 void OnIdle( wxIdleEvent& event );
218 void OnMouseEvent( wxMouseEvent& event );
219 void OnActivate( wxActivateEvent& event );
220 void OnResize( wxSizeEvent& event );
221 void OnMove( wxMoveEvent& event );
222 void OnMenuEvent( wxMenuEvent& event );
223 void OnClose( wxCloseEvent& event );
224
225 protected:
226 wxWindow* m_focusStart;
227 wxComboCtrlBase* m_combo;
228
229 private:
230 DECLARE_EVENT_TABLE()
231 };
232
233 BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler)
234 EVT_IDLE(wxComboFrameEventHandler::OnIdle)
235 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
236 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
237 EVT_SIZE(wxComboFrameEventHandler::OnResize)
238 EVT_MOVE(wxComboFrameEventHandler::OnMove)
239 EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent)
240 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent)
241 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate)
242 EVT_CLOSE(wxComboFrameEventHandler::OnClose)
243 END_EVENT_TABLE()
244
245 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase* combo )
246 : wxEvtHandler()
247 {
248 m_combo = combo;
249 }
250
251 wxComboFrameEventHandler::~wxComboFrameEventHandler()
252 {
253 }
254
255 void wxComboFrameEventHandler::OnPopup()
256 {
257 m_focusStart = ::wxWindow::FindFocus();
258 }
259
260 void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
261 {
262 wxWindow* winFocused = ::wxWindow::FindFocus();
263
264 wxWindow* popup = m_combo->GetPopupControl()->GetControl();
265 wxWindow* winpopup = m_combo->GetPopupWindow();
266
267 if (
268 winFocused != m_focusStart &&
269 winFocused != popup &&
270 winFocused->GetParent() != popup &&
271 winFocused != winpopup &&
272 winFocused->GetParent() != winpopup &&
273 winFocused != m_combo &&
274 winFocused != m_combo->GetButton() // GTK (atleast) requires this
275 )
276 {
277 m_combo->HidePopup();
278 }
279
280 event.Skip();
281 }
282
283 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
284 {
285 m_combo->HidePopup();
286 event.Skip();
287 }
288
289 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
290 {
291 m_combo->HidePopup();
292 event.Skip();
293 }
294
295 void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
296 {
297 m_combo->HidePopup();
298 event.Skip();
299 }
300
301 void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
302 {
303 m_combo->HidePopup();
304 event.Skip();
305 }
306
307 void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
308 {
309 m_combo->HidePopup();
310 event.Skip();
311 }
312
313 void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
314 {
315 m_combo->HidePopup();
316 event.Skip();
317 }
318
319 #endif // INSTALL_TOPLEV_HANDLER
320
321 // ----------------------------------------------------------------------------
322 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
323 // wxComboCtrl.
324 // ----------------------------------------------------------------------------
325
326 class wxComboPopupWindow : public wxComboPopupWindowBase
327 {
328 public:
329
330 wxComboPopupWindow( wxComboCtrlBase *parent,
331 int style )
332 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
333 : wxComboPopupWindowBase(parent,style)
334 #else
335 : wxComboPopupWindowBase(parent,
336 wxID_ANY,
337 wxEmptyString,
338 wxPoint(-21,-21),
339 wxSize(20,20),
340 style)
341 #endif
342 {
343 m_inShow = 0;
344 }
345
346 #if USES_WXPOPUPTRANSIENTWINDOW
347 virtual bool Show( bool show );
348 virtual bool ProcessLeftDown(wxMouseEvent& event);
349 virtual void OnDismiss();
350 #endif
351
352 private:
353 wxByte m_inShow;
354 };
355
356
357 #if USES_WXPOPUPTRANSIENTWINDOW
358 bool wxComboPopupWindow::Show( bool show )
359 {
360 // Guard against recursion
361 if ( m_inShow )
362 return wxComboPopupWindowBase::Show(show);
363
364 m_inShow++;
365
366 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow)) );
367
368 wxPopupTransientWindow* ptw = (wxPopupTransientWindow*) this;
369 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
370
371 if ( show != ptw->IsShown() )
372 {
373 if ( show )
374 ptw->Popup(combo->GetPopupControl()->GetControl());
375 else
376 ptw->Dismiss();
377 }
378
379 m_inShow--;
380
381 return true;
382 }
383
384 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event)
385 {
386 return wxPopupTransientWindow::ProcessLeftDown(event);
387 }
388
389 // First thing that happens when a transient popup closes is that this method gets called.
390 void wxComboPopupWindow::OnDismiss()
391 {
392 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
393 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)),
394 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
395
396 combo->OnPopupDismiss();
397 }
398 #endif // USES_WXPOPUPTRANSIENTWINDOW
399
400
401 // ----------------------------------------------------------------------------
402 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
403 // of a popup window. It is separate so we can have different types
404 // of popup windows.
405 // ----------------------------------------------------------------------------
406
407 class wxComboPopupWindowEvtHandler : public wxEvtHandler
408 {
409 public:
410
411 wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent )
412 {
413 m_combo = parent;
414 }
415
416 void OnSizeEvent( wxSizeEvent& event );
417 void OnKeyEvent(wxKeyEvent& event);
418 #if USES_WXDIALOG
419 void OnActivate( wxActivateEvent& event );
420 #endif
421
422 private:
423 wxComboCtrlBase* m_combo;
424
425 DECLARE_EVENT_TABLE()
426 };
427
428
429 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler)
430 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent)
431 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent)
432 #if USES_WXDIALOG
433 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate)
434 #endif
435 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent)
436 END_EVENT_TABLE()
437
438
439 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) )
440 {
441 // Block the event so that the popup control does not get auto-resized.
442 }
443
444 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
445 {
446 // Relay keyboard event to the main child controls
447 wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
448 wxWindowList::iterator node = children.begin();
449 wxWindow* child = (wxWindow*)*node;
450 child->AddPendingEvent(event);
451 }
452
453 #if USES_WXDIALOG
454 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
455 {
456 if ( !event.GetActive() )
457 {
458 // Tell combo control that we are dismissed.
459 m_combo->HidePopup();
460
461 event.Skip();
462 }
463 }
464 #endif
465
466
467 // ----------------------------------------------------------------------------
468 // wxComboPopup
469 //
470 // ----------------------------------------------------------------------------
471
472 wxComboPopup::~wxComboPopup()
473 {
474 }
475
476 void wxComboPopup::OnPopup()
477 {
478 }
479
480 void wxComboPopup::OnDismiss()
481 {
482 }
483
484 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
485 int prefHeight,
486 int WXUNUSED(maxHeight) )
487 {
488 return wxSize(minWidth,prefHeight);
489 }
490
491 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
492 wxDC& dc, const wxRect& rect )
493 {
494 if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
495 {
496 combo->PrepareBackground(dc,rect,0);
497
498 dc.DrawText( combo->GetValue(),
499 rect.x + combo->GetTextIndent(),
500 (rect.height-dc.GetCharHeight())/2 + rect.y );
501 }
502 }
503
504 void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
505 {
506 DefaultPaintComboControl(m_combo,dc,rect);
507 }
508
509 void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
510 {
511 event.Skip();
512 }
513
514 void wxComboPopup::OnComboDoubleClick()
515 {
516 }
517
518 void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
519 {
520 }
521
522 bool wxComboPopup::LazyCreate()
523 {
524 return false;
525 }
526
527 void wxComboPopup::Dismiss()
528 {
529 m_combo->HidePopup();
530 }
531
532 // ----------------------------------------------------------------------------
533 // input handling
534 // ----------------------------------------------------------------------------
535
536 //
537 // This is pushed to the event handler queue of the child textctrl.
538 //
539 class wxComboBoxExtraInputHandler : public wxEvtHandler
540 {
541 public:
542
543 wxComboBoxExtraInputHandler( wxComboCtrlBase* combo )
544 : wxEvtHandler()
545 {
546 m_combo = combo;
547 }
548 virtual ~wxComboBoxExtraInputHandler() { }
549 void OnKey(wxKeyEvent& event);
550 void OnFocus(wxFocusEvent& event);
551
552 protected:
553 wxComboCtrlBase* m_combo;
554
555 private:
556 DECLARE_EVENT_TABLE()
557 };
558
559
560 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
561 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
562 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
563 END_EVENT_TABLE()
564
565
566 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event)
567 {
568 // Let the wxComboCtrl event handler have a go first.
569 wxComboCtrlBase* combo = m_combo;
570 wxObject* prevObj = event.GetEventObject();
571
572 event.SetId(combo->GetId());
573 event.SetEventObject(combo);
574 combo->GetEventHandler()->ProcessEvent(event);
575
576 event.SetId(((wxWindow*)prevObj)->GetId());
577 event.SetEventObject(prevObj);
578 }
579
580 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
581 {
582 // FIXME: This code does run when control is clicked,
583 // yet on Windows it doesn't select all the text.
584 if ( !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) )
585 {
586 if ( m_combo->GetTextCtrl() )
587 m_combo->GetTextCtrl()->SelectAll();
588 else
589 m_combo->SetSelection(-1,-1);
590 }
591
592 // Send focus indication to parent.
593 // NB: This is needed for cases where the textctrl gets focus
594 // instead of its parent. While this may trigger multiple
595 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
596 // from combo's focus event handler), they should be quite
597 // harmless.
598 wxFocusEvent evt2(wxEVT_SET_FOCUS,m_combo->GetId());
599 evt2.SetEventObject(m_combo);
600 m_combo->GetEventHandler()->ProcessEvent(evt2);
601
602 event.Skip();
603 }
604
605
606 //
607 // This is pushed to the event handler queue of the control in popup.
608 //
609
610 class wxComboPopupExtraEventHandler : public wxEvtHandler
611 {
612 public:
613
614 wxComboPopupExtraEventHandler( wxComboCtrlBase* combo )
615 : wxEvtHandler()
616 {
617 m_combo = combo;
618 m_beenInside = false;
619 }
620 virtual ~wxComboPopupExtraEventHandler() { }
621
622 void OnMouseEvent( wxMouseEvent& event );
623
624 // Called from wxComboCtrlBase::OnPopupDismiss
625 void OnPopupDismiss()
626 {
627 m_beenInside = false;
628 }
629
630 protected:
631 wxComboCtrlBase* m_combo;
632
633 bool m_beenInside;
634
635 private:
636 DECLARE_EVENT_TABLE()
637 };
638
639
640 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler, wxEvtHandler)
641 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent)
642 END_EVENT_TABLE()
643
644
645 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent& event )
646 {
647 wxPoint pt = event.GetPosition();
648 wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize();
649 int evtType = event.GetEventType();
650 bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y;
651
652 if ( evtType == wxEVT_MOTION ||
653 evtType == wxEVT_LEFT_DOWN ||
654 evtType == wxEVT_RIGHT_DOWN )
655 {
656 // Block motion and click events outside the popup
657 if ( !isInside || !m_combo->IsPopupShown() )
658 {
659 event.Skip(false);
660 return;
661 }
662 }
663 else if ( evtType == wxEVT_LEFT_UP )
664 {
665 if ( !m_combo->IsPopupShown() )
666 {
667 event.Skip(false);
668 return;
669 }
670
671 if ( !m_beenInside )
672 {
673 if ( isInside )
674 {
675 m_beenInside = true;
676 }
677 else
678 {
679 //
680 // Some mouse events to popup that happen outside it, before cursor
681 // has been inside the popu, need to be ignored by it but relayed to
682 // the dropbutton.
683 //
684 wxWindow* btn = m_combo->GetButton();
685 if ( btn )
686 btn->GetEventHandler()->AddPendingEvent(event);
687 else
688 m_combo->GetEventHandler()->AddPendingEvent(event);
689
690 return;
691 }
692
693 event.Skip();
694 }
695 }
696
697 event.Skip();
698 }
699
700 // ----------------------------------------------------------------------------
701 // wxComboCtrlBase
702 // ----------------------------------------------------------------------------
703
704
705 BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl)
706 EVT_TEXT(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
707 EVT_SIZE(wxComboCtrlBase::OnSizeEvent)
708 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent)
709 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent)
710 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
711 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent)
712 EVT_TEXT_ENTER(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
713 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged)
714 END_EVENT_TABLE()
715
716
717 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
718
719 void wxComboCtrlBase::Init()
720 {
721 m_winPopup = (wxWindow *)NULL;
722 m_popup = (wxWindow *)NULL;
723 m_popupWinState = Hidden;
724 m_btn = (wxWindow*) NULL;
725 m_text = (wxTextCtrl*) NULL;
726 m_popupInterface = (wxComboPopup*) NULL;
727
728 m_popupExtraHandler = (wxEvtHandler*) NULL;
729 m_textEvtHandler = (wxEvtHandler*) NULL;
730
731 #if INSTALL_TOPLEV_HANDLER
732 m_toplevEvtHandler = (wxEvtHandler*) NULL;
733 #endif
734
735 m_mainCtrlWnd = this;
736
737 m_heightPopup = -1;
738 m_widthMinPopup = -1;
739 m_anchorSide = 0;
740 m_widthCustomPaint = 0;
741 m_widthCustomBorder = 0;
742
743 m_btnState = 0;
744 m_btnWidDefault = 0;
745 m_blankButtonBg = false;
746 m_ignoreEvtText = 0;
747 m_popupWinType = POPUPWIN_NONE;
748 m_btnWid = m_btnHei = -1;
749 m_btnSide = wxRIGHT;
750 m_btnSpacingX = 0;
751
752 m_extLeft = 0;
753 m_extRight = 0;
754 m_absIndent = -1;
755 m_iFlags = 0;
756 m_timeCanAcceptClick = 0;
757 }
758
759 bool wxComboCtrlBase::Create(wxWindow *parent,
760 wxWindowID id,
761 const wxString& value,
762 const wxPoint& pos,
763 const wxSize& size,
764 long style,
765 const wxValidator& validator,
766 const wxString& name)
767 {
768 if ( !wxControl::Create(parent,
769 id,
770 pos,
771 size,
772 style | wxWANTS_CHARS,
773 validator,
774 name) )
775 return false;
776
777 m_valueString = value;
778
779 // Get colours
780 OnThemeChange();
781 m_absIndent = GetNativeTextIndent();
782
783 m_iFlags |= wxCC_IFLAG_CREATED;
784
785 // If x and y indicate valid size, wxSizeEvent won't be
786 // emitted automatically, so we need to add artifical one.
787 if ( size.x > 0 && size.y > 0 )
788 {
789 wxSizeEvent evt(size,GetId());
790 GetEventHandler()->AddPendingEvent(evt);
791 }
792
793 return true;
794 }
795
796 void wxComboCtrlBase::InstallInputHandlers()
797 {
798 if ( m_text )
799 {
800 m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
801 m_text->PushEventHandler(m_textEvtHandler);
802 }
803 }
804
805 void
806 wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
807 {
808 if ( !(m_windowStyle & wxCB_READONLY) )
809 {
810 if ( m_text )
811 m_text->Destroy();
812
813 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
814 // not used by the wxPropertyGrid and therefore the tab is processed by
815 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
816 // navigation event is then sent to the wrong window.
817 style |= wxTE_PROCESS_TAB;
818
819 if ( HasFlag(wxTE_PROCESS_ENTER) )
820 style |= wxTE_PROCESS_ENTER;
821
822 // Ignore EVT_TEXT generated by the constructor (but only
823 // if the event redirector already exists)
824 // NB: This must be " = 1" instead of "++";
825 if ( m_textEvtHandler )
826 m_ignoreEvtText = 1;
827 else
828 m_ignoreEvtText = 0;
829
830 m_text = new wxTextCtrl(this, wxID_ANY, m_valueString,
831 wxDefaultPosition, wxDefaultSize,
832 style, validator);
833
834 // This is required for some platforms (GTK+ atleast)
835 m_text->SetSizeHints(2,4);
836 }
837 }
838
839 void wxComboCtrlBase::OnThemeChange()
840 {
841 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
842 }
843
844 wxComboCtrlBase::~wxComboCtrlBase()
845 {
846 if ( HasCapture() )
847 ReleaseMouse();
848
849 #if INSTALL_TOPLEV_HANDLER
850 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
851 m_toplevEvtHandler = (wxEvtHandler*) NULL;
852 #endif
853
854 DestroyPopup();
855
856 if ( m_text )
857 m_text->RemoveEventHandler(m_textEvtHandler);
858
859 delete m_textEvtHandler;
860 }
861
862
863 // ----------------------------------------------------------------------------
864 // geometry stuff
865 // ----------------------------------------------------------------------------
866
867 // Recalculates button and textctrl areas
868 void wxComboCtrlBase::CalculateAreas( int btnWidth )
869 {
870 wxSize sz = GetClientSize();
871 int customBorder = m_widthCustomBorder;
872 int btnBorder; // border for button only
873
874 // check if button should really be outside the border: we'll do it it if
875 // its platform default or bitmap+pushbutton background is used, but not if
876 // there is vertical size adjustment or horizontal spacing.
877 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
878 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
879 m_btnSpacingX == 0 &&
880 m_btnHei <= 0 )
881 {
882 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
883 btnBorder = 0;
884 }
885 else
886 {
887 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
888 btnBorder = customBorder;
889 }
890
891 // Defaul indentation
892 if ( m_absIndent < 0 )
893 m_absIndent = GetNativeTextIndent();
894
895 int butWidth = btnWidth;
896
897 if ( butWidth <= 0 )
898 butWidth = m_btnWidDefault;
899 else
900 m_btnWidDefault = butWidth;
901
902 if ( butWidth <= 0 )
903 return;
904
905 int butHeight = sz.y - btnBorder*2;
906
907 // Adjust button width
908 if ( m_btnWid > 0 )
909 butWidth = m_btnWid;
910 else
911 {
912 // Adjust button width to match aspect ratio
913 // (but only if control is smaller than best size).
914 int bestHeight = GetBestSize().y;
915 int height = GetSize().y;
916
917 if ( height < bestHeight )
918 {
919 // Make very small buttons square, as it makes
920 // them accommodate arrow image better and still
921 // looks decent.
922 if ( height > 18 )
923 butWidth = (height*butWidth)/bestHeight;
924 else
925 butWidth = butHeight;
926 }
927 }
928
929 // Adjust button height
930 if ( m_btnHei > 0 )
931 butHeight = m_btnHei;
932
933 // Use size of normal bitmap if...
934 // It is larger
935 // OR
936 // button width is set to default and blank button bg is not drawn
937 if ( m_bmpNormal.Ok() )
938 {
939 int bmpReqWidth = m_bmpNormal.GetWidth();
940 int bmpReqHeight = m_bmpNormal.GetHeight();
941
942 // If drawing blank button background, we need to add some margin.
943 if ( m_blankButtonBg )
944 {
945 bmpReqWidth += BMP_BUTTON_MARGIN*2;
946 bmpReqHeight += BMP_BUTTON_MARGIN*2;
947 }
948
949 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
950 butWidth = bmpReqWidth;
951 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
952 butHeight = bmpReqHeight;
953
954 // Need to fix height?
955 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
956 {
957 int newY = butHeight+(customBorder*2);
958 SetClientSize(wxDefaultCoord,newY);
959 sz.y = newY;
960 }
961 }
962
963 int butAreaWid = butWidth + (m_btnSpacingX*2);
964
965 m_btnSize.x = butWidth;
966 m_btnSize.y = butHeight;
967
968 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
969 m_btnArea.y = btnBorder;
970 m_btnArea.width = butAreaWid;
971 m_btnArea.height = sz.y - (btnBorder*2);
972
973 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder;
974 m_tcArea.y = customBorder;
975 m_tcArea.width = sz.x - butAreaWid - (customBorder*2);
976 m_tcArea.height = sz.y - (customBorder*2);
977
978 /*
979 if ( m_text )
980 {
981 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
982 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
983 }
984 */
985 }
986
987 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
988 {
989 if ( !m_text )
990 return;
991
992 wxSize sz = GetClientSize();
993 int customBorder = m_widthCustomBorder;
994
995 #if !TEXTCTRL_TEXT_CENTERED
996 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
997 {
998 // Centre textctrl
999 int tcSizeY = m_text->GetBestSize().y;
1000 int diff = sz.y - tcSizeY;
1001 int y = textCtrlYAdjust + (diff/2);
1002
1003 if ( y < customBorder )
1004 y = customBorder;
1005
1006 m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
1007 y,
1008 m_tcArea.width - COMBO_MARGIN -
1009 (textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
1010 -1 );
1011
1012 // Make sure textctrl doesn't exceed the bottom custom border
1013 wxSize tsz = m_text->GetSize();
1014 diff = (y + tsz.y) - (sz.y - customBorder);
1015 if ( diff >= 0 )
1016 {
1017 tsz.y = tsz.y - diff - 1;
1018 m_text->SetSize(tsz);
1019 }
1020 }
1021 else
1022 #else
1023 wxUnusedVar(textCtrlXAdjust);
1024 wxUnusedVar(textCtrlYAdjust);
1025 #endif
1026 {
1027 // If it has border, have textctrl will the entire text field.
1028 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1029 customBorder,
1030 sz.x - m_btnArea.width - m_widthCustomPaint - customBorder,
1031 sz.y-(customBorder*2) );
1032 }
1033 }
1034
1035 wxSize wxComboCtrlBase::DoGetBestSize() const
1036 {
1037 wxSize sizeText(150,0);
1038
1039 if ( m_text )
1040 sizeText = m_text->GetBestSize();
1041
1042 // TODO: Better method to calculate close-to-native control height.
1043
1044 int fhei;
1045 if ( m_font.Ok() )
1046 fhei = (m_font.GetPointSize()*2) + 5;
1047 else if ( wxNORMAL_FONT->Ok() )
1048 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1049 else
1050 fhei = sizeText.y + 4;
1051
1052 // Need to force height to accomodate bitmap?
1053 int btnSizeY = m_btnSize.y;
1054 if ( m_bmpNormal.Ok() && fhei < btnSizeY )
1055 fhei = btnSizeY;
1056
1057 // Control height doesn't depend on border
1058 /*
1059 // Add border
1060 int border = m_windowStyle & wxBORDER_MASK;
1061 if ( border == wxSIMPLE_BORDER )
1062 fhei += 2;
1063 else if ( border == wxNO_BORDER )
1064 fhei += (m_widthCustomBorder*2);
1065 else
1066 // Sunken etc.
1067 fhei += 4;
1068 */
1069
1070 // Final adjustments
1071 #ifdef __WXGTK__
1072 fhei += 1;
1073 #endif
1074
1075 wxSize ret(sizeText.x + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH,
1076 fhei);
1077
1078 CacheBestSize(ret);
1079 return ret;
1080 }
1081
1082 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1083 {
1084 if ( !IsCreated() )
1085 return;
1086
1087 // defined by actual wxComboCtrls
1088 OnResize();
1089
1090 event.Skip();
1091 }
1092
1093 // ----------------------------------------------------------------------------
1094 // standard operations
1095 // ----------------------------------------------------------------------------
1096
1097 bool wxComboCtrlBase::Enable(bool enable)
1098 {
1099 if ( !wxControl::Enable(enable) )
1100 return false;
1101
1102 if ( m_btn )
1103 m_btn->Enable(enable);
1104 if ( m_text )
1105 m_text->Enable(enable);
1106
1107 return true;
1108 }
1109
1110 bool wxComboCtrlBase::Show(bool show)
1111 {
1112 if ( !wxControl::Show(show) )
1113 return false;
1114
1115 if (m_btn)
1116 m_btn->Show(show);
1117
1118 if (m_text)
1119 m_text->Show(show);
1120
1121 return true;
1122 }
1123
1124 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1125 {
1126 if ( !wxControl::SetFont(font) )
1127 return false;
1128
1129 if (m_text)
1130 m_text->SetFont(font);
1131
1132 return true;
1133 }
1134
1135 #if wxUSE_TOOLTIPS
1136 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1137 {
1138 wxControl::DoSetToolTip(tooltip);
1139
1140 // Set tool tip for button and text box
1141 if ( tooltip )
1142 {
1143 const wxString &tip = tooltip->GetTip();
1144 if ( m_text ) m_text->SetToolTip(tip);
1145 if ( m_btn ) m_btn->SetToolTip(tip);
1146 }
1147 else
1148 {
1149 if ( m_text ) m_text->SetToolTip( (wxToolTip*) NULL );
1150 if ( m_btn ) m_btn->SetToolTip( (wxToolTip*) NULL );
1151 }
1152 }
1153 #endif // wxUSE_TOOLTIPS
1154
1155 // ----------------------------------------------------------------------------
1156 // painting
1157 // ----------------------------------------------------------------------------
1158
1159 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1160 // prepare combo box background on area in a way typical on platform
1161 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1162 {
1163 wxSize sz = GetClientSize();
1164 bool isEnabled;
1165 bool isFocused; // also selected
1166
1167 // For smaller size control (and for disabled background) use less spacing
1168 int focusSpacingX;
1169 int focusSpacingY;
1170
1171 if ( !(flags & wxCONTROL_ISSUBMENU) )
1172 {
1173 // Drawing control
1174 isEnabled = IsEnabled();
1175 isFocused = ShouldDrawFocus();
1176
1177 // Windows-style: for smaller size control (and for disabled background) use less spacing
1178 focusSpacingX = isEnabled ? 2 : 1;
1179 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1180 }
1181 else
1182 {
1183 // Drawing a list item
1184 isEnabled = true; // they are never disabled
1185 isFocused = flags & wxCONTROL_SELECTED ? true : false;
1186
1187 focusSpacingX = 0;
1188 focusSpacingY = 0;
1189 }
1190
1191 // Set the background sub-rectangle for selection, disabled etc
1192 wxRect selRect(rect);
1193 selRect.y += focusSpacingY;
1194 selRect.height -= (focusSpacingY*2);
1195
1196 int wcp = 0;
1197
1198 if ( !(flags & wxCONTROL_ISSUBMENU) )
1199 wcp += m_widthCustomPaint;
1200
1201 selRect.x += wcp + focusSpacingX;
1202 selRect.width -= wcp + (focusSpacingX*2);
1203
1204 wxColour bgCol;
1205
1206 if ( isEnabled )
1207 {
1208 // If popup is hidden and this control is focused,
1209 // then draw the focus-indicator (selbgcolor background etc.).
1210 if ( isFocused )
1211 {
1212 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
1213 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1214 }
1215 else
1216 {
1217 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
1218 bgCol = GetBackgroundColour();
1219 }
1220 }
1221 else
1222 {
1223 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
1224 bgCol = GetBackgroundColour();
1225 }
1226
1227 dc.SetBrush( bgCol );
1228 dc.SetPen( bgCol );
1229 dc.DrawRectangle( selRect );
1230
1231 // Don't clip exactly to the selection rectangle so we can draw
1232 // to the non-selected area in front of it.
1233 wxRect clipRect(rect.x,rect.y,
1234 (selRect.x+selRect.width)-rect.x,rect.height);
1235 dc.SetClippingRegion(clipRect);
1236 }
1237 #else
1238 // Save the library size a bit for platforms that re-implement this.
1239 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1240 {
1241 }
1242 #endif
1243
1244 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, bool paintBg )
1245 {
1246 int drawState = m_btnState;
1247
1248 #ifdef __WXGTK__
1249 if ( GetPopupWindowState() >= Animating )
1250 drawState |= wxCONTROL_PRESSED;
1251 #endif
1252
1253 wxRect drawRect(rect.x+m_btnSpacingX,
1254 rect.y+((rect.height-m_btnSize.y)/2),
1255 m_btnSize.x,
1256 m_btnSize.y);
1257
1258 // Make sure area is not larger than the control
1259 if ( drawRect.y < rect.y )
1260 drawRect.y = rect.y;
1261 if ( drawRect.height > rect.height )
1262 drawRect.height = rect.height;
1263
1264 bool enabled = IsEnabled();
1265
1266 if ( !enabled )
1267 drawState |= wxCONTROL_DISABLED;
1268
1269 if ( !m_bmpNormal.Ok() )
1270 {
1271 // Need to clear button background even if m_btn is present
1272 if ( paintBg )
1273 {
1274 wxColour bgCol;
1275
1276 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1277 bgCol = GetParent()->GetBackgroundColour();
1278 else
1279 bgCol = GetBackgroundColour();
1280
1281 dc.SetBrush(bgCol);
1282 dc.SetPen(bgCol);
1283 dc.DrawRectangle(rect);
1284 }
1285
1286 // Draw standard button
1287 wxRendererNative::Get().DrawComboBoxDropButton(this,
1288 dc,
1289 drawRect,
1290 drawState);
1291 }
1292 else
1293 {
1294 // Draw bitmap
1295
1296 wxBitmap* pBmp;
1297
1298 if ( !enabled )
1299 pBmp = &m_bmpDisabled;
1300 else if ( m_btnState & wxCONTROL_PRESSED )
1301 pBmp = &m_bmpPressed;
1302 else if ( m_btnState & wxCONTROL_CURRENT )
1303 pBmp = &m_bmpHover;
1304 else
1305 pBmp = &m_bmpNormal;
1306
1307 if ( m_blankButtonBg )
1308 {
1309 // If using blank button background, we need to clear its background
1310 // with button face colour instead of colour for rest of the control.
1311 if ( paintBg )
1312 {
1313 wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1314 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1315 dc.SetPen(bgCol);
1316 dc.SetBrush(bgCol);
1317 dc.DrawRectangle(rect);
1318 }
1319
1320 wxRendererNative::Get().DrawPushButton(this,
1321 dc,
1322 drawRect,
1323 drawState);
1324
1325 }
1326 else
1327
1328 {
1329 // Need to clear button background even if m_btn is present
1330 // (assume non-button background was cleared just before this call so brushes are good)
1331 if ( paintBg )
1332 dc.DrawRectangle(rect);
1333 }
1334
1335 // Draw bitmap centered in drawRect
1336 dc.DrawBitmap(*pBmp,
1337 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1338 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1339 true);
1340 }
1341 }
1342
1343 void wxComboCtrlBase::RecalcAndRefresh()
1344 {
1345 if ( IsCreated() )
1346 {
1347 wxSizeEvent evt(GetSize(),GetId());
1348 GetEventHandler()->ProcessEvent(evt);
1349 Refresh();
1350 }
1351 }
1352
1353 // ----------------------------------------------------------------------------
1354 // miscellaneous event handlers
1355 // ----------------------------------------------------------------------------
1356
1357 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1358 {
1359 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1360 {
1361 if ( m_ignoreEvtText > 0 )
1362 {
1363 m_ignoreEvtText--;
1364 return;
1365 }
1366 }
1367
1368 // Change event id, object and string before relaying it forward
1369 event.SetId(GetId());
1370 wxString s = event.GetString();
1371 event.SetEventObject(this);
1372 event.SetString(s);
1373 event.Skip();
1374 }
1375
1376 // call if cursor is on button area or mouse is captured for the button
1377 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1378 int flags )
1379 {
1380 int type = event.GetEventType();
1381
1382 if ( type == wxEVT_MOTION )
1383 {
1384 if ( flags & wxCC_MF_ON_BUTTON )
1385 {
1386 if ( !(m_btnState & wxCONTROL_CURRENT) )
1387 {
1388 // Mouse hover begins
1389 m_btnState |= wxCONTROL_CURRENT;
1390 if ( HasCapture() ) // Retain pressed state.
1391 m_btnState |= wxCONTROL_PRESSED;
1392 Refresh();
1393 }
1394 }
1395 else if ( (m_btnState & wxCONTROL_CURRENT) )
1396 {
1397 // Mouse hover ends
1398 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1399 Refresh();
1400 }
1401 }
1402 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1403 {
1404 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1405 {
1406 m_btnState |= wxCONTROL_PRESSED;
1407 Refresh();
1408
1409 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1410 OnButtonClick();
1411 else
1412 // If showing popup now, do not capture mouse or there will be interference
1413 CaptureMouse();
1414 }
1415 }
1416 else if ( type == wxEVT_LEFT_UP )
1417 {
1418
1419 // Only accept event if mouse was left-press was previously accepted
1420 if ( HasCapture() )
1421 ReleaseMouse();
1422
1423 if ( m_btnState & wxCONTROL_PRESSED )
1424 {
1425 // If mouse was inside, fire the click event.
1426 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1427 {
1428 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1429 OnButtonClick();
1430 }
1431
1432 m_btnState &= ~(wxCONTROL_PRESSED);
1433 Refresh();
1434 }
1435 }
1436 else if ( type == wxEVT_LEAVE_WINDOW )
1437 {
1438 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1439 {
1440 m_btnState &= ~(wxCONTROL_CURRENT);
1441
1442 // Mouse hover ends
1443 if ( IsPopupWindowState(Hidden) )
1444 {
1445 m_btnState &= ~(wxCONTROL_PRESSED);
1446 Refresh();
1447 }
1448 }
1449 }
1450 else
1451 return false;
1452
1453 return true;
1454 }
1455
1456 // returns true if event was consumed or filtered
1457 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1458 int WXUNUSED(flags) )
1459 {
1460 wxLongLong t = ::wxGetLocalTimeMillis();
1461 int evtType = event.GetEventType();
1462
1463 #if USES_WXPOPUPWINDOW || USES_WXDIALOG
1464 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1465 {
1466 if ( IsPopupWindowState(Visible) &&
1467 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1468 {
1469 HidePopup();
1470 return true;
1471 }
1472 }
1473 #endif
1474
1475 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1476 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1477 {
1478 event.SetEventType(0);
1479 return true;
1480 }
1481
1482 return false;
1483 }
1484
1485 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1486 {
1487 int evtType = event.GetEventType();
1488
1489 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1490 (m_windowStyle & wxCB_READONLY) )
1491 {
1492 if ( GetPopupWindowState() >= Animating )
1493 {
1494 #if USES_WXPOPUPWINDOW
1495 // Click here always hides the popup.
1496 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1497 HidePopup();
1498 #endif
1499 }
1500 else
1501 {
1502 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1503 {
1504 // In read-only mode, clicking the text is the
1505 // same as clicking the button.
1506 OnButtonClick();
1507 }
1508 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1509 {
1510 //if ( m_popupInterface->CycleValue() )
1511 // Refresh();
1512 if ( m_popupInterface )
1513 m_popupInterface->OnComboDoubleClick();
1514 }
1515 }
1516 }
1517 else
1518 if ( IsPopupShown() )
1519 {
1520 // relay (some) mouse events to the popup
1521 if ( evtType == wxEVT_MOUSEWHEEL )
1522 m_popup->AddPendingEvent(event);
1523 }
1524 else if ( evtType )
1525 event.Skip();
1526 }
1527
1528 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1529 {
1530 if ( IsPopupShown() )
1531 {
1532 // pass it to the popped up control
1533 GetPopupControl()->GetControl()->AddPendingEvent(event);
1534 }
1535 else // no popup
1536 {
1537 int keycode = event.GetKeyCode();
1538
1539 if ( keycode == WXK_TAB )
1540 {
1541 wxNavigationKeyEvent evt;
1542
1543 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1544
1545 evt.SetFlags(wxNavigationKeyEvent::FromTab|
1546 (!event.ShiftDown() ? wxNavigationKeyEvent::IsForward
1547 : wxNavigationKeyEvent::IsBackward));
1548 evt.SetEventObject(mainCtrl);
1549 evt.SetCurrentFocus(mainCtrl);
1550 mainCtrl->GetParent()->GetEventHandler()->AddPendingEvent(evt);
1551 return;
1552 }
1553
1554 if ( IsKeyPopupToggle(event) )
1555 {
1556 OnButtonClick();
1557 return;
1558 }
1559
1560 int comboStyle = GetWindowStyle();
1561 wxComboPopup* popupInterface = GetPopupControl();
1562
1563 if ( !popupInterface )
1564 {
1565 event.Skip();
1566 return;
1567 }
1568
1569 if ( (comboStyle & wxCB_READONLY) ||
1570 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
1571 {
1572 popupInterface->OnComboKeyEvent(event);
1573 }
1574 else
1575 event.Skip();
1576 }
1577 }
1578
1579 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
1580 {
1581 if ( event.GetEventType() == wxEVT_SET_FOCUS )
1582 {
1583 #ifndef __WXMAC__
1584 wxWindow* tc = GetTextCtrl();
1585 if ( tc && tc != DoFindFocus() )
1586 tc->SetFocus();
1587 #endif
1588 }
1589
1590 Refresh();
1591 }
1592
1593 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
1594 {
1595 OnThemeChange();
1596 // indentation may also have changed
1597 if ( !(m_iFlags & wxCC_IFLAG_INDENT_SET) )
1598 m_absIndent = GetNativeTextIndent();
1599 RecalcAndRefresh();
1600 }
1601
1602 // ----------------------------------------------------------------------------
1603 // popup handling
1604 // ----------------------------------------------------------------------------
1605
1606 // Create popup window and the child control
1607 void wxComboCtrlBase::CreatePopup()
1608 {
1609 wxComboPopup* popupInterface = m_popupInterface;
1610 wxWindow* popup;
1611
1612 if ( !m_winPopup )
1613 {
1614 #ifdef wxComboPopupWindowBase2
1615 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
1616 {
1617 #if !USES_WXDIALOG
1618 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
1619 #else
1620 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
1621 wxPoint(-21,-21), wxSize(20, 20),
1622 wxNO_BORDER );
1623 #endif
1624 m_popupWinType = SECONDARY_POPUP_TYPE;
1625 }
1626 else
1627 #endif
1628 {
1629 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
1630 m_popupWinType = PRIMARY_POPUP_TYPE;
1631 }
1632 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
1633 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
1634 }
1635
1636 popupInterface->Create(m_winPopup);
1637 m_popup = popup = popupInterface->GetControl();
1638
1639 m_popupExtraHandler = new wxComboPopupExtraEventHandler(this);
1640 popup->PushEventHandler( m_popupExtraHandler );
1641
1642 // This may be helpful on some platforms
1643 // (eg. it bypasses a wxGTK popupwindow bug where
1644 // window is not initially hidden when it should be)
1645 m_winPopup->Hide();
1646
1647 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
1648 }
1649
1650 // Destroy popup window and the child control
1651 void wxComboCtrlBase::DestroyPopup()
1652 {
1653 HidePopup();
1654
1655 if ( m_popup )
1656 m_popup->RemoveEventHandler(m_popupExtraHandler);
1657
1658 delete m_popupExtraHandler;
1659
1660 delete m_popupInterface;
1661
1662 if ( m_winPopup )
1663 {
1664 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
1665 delete m_popupWinEvtHandler;
1666 m_popupWinEvtHandler = NULL;
1667 m_winPopup->Destroy();
1668 }
1669
1670 m_popupExtraHandler = (wxEvtHandler*) NULL;
1671 m_popupInterface = (wxComboPopup*) NULL;
1672 m_winPopup = (wxWindow*) NULL;
1673 m_popup = (wxWindow*) NULL;
1674 }
1675
1676 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
1677 {
1678 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
1679
1680 DestroyPopup();
1681
1682 iface->InitBase(this);
1683 iface->Init();
1684
1685 m_popupInterface = iface;
1686
1687 if ( !iface->LazyCreate() )
1688 {
1689 CreatePopup();
1690 }
1691 else
1692 {
1693 m_popup = (wxWindow*) NULL;
1694 }
1695
1696 // This must be done after creation
1697 if ( m_valueString.length() )
1698 {
1699 iface->SetStringValue(m_valueString);
1700 //Refresh();
1701 }
1702 }
1703
1704 // Ensures there is atleast the default popup
1705 void wxComboCtrlBase::EnsurePopupControl()
1706 {
1707 if ( !m_popupInterface )
1708 SetPopupControl(NULL);
1709 }
1710
1711 void wxComboCtrlBase::OnButtonClick()
1712 {
1713 // Derived classes can override this method for totally custom
1714 // popup action
1715 ShowPopup();
1716 }
1717
1718 void wxComboCtrlBase::ShowPopup()
1719 {
1720 EnsurePopupControl();
1721 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
1722
1723 if ( IsPopupWindowState(Animating) )
1724 return;
1725
1726 SetFocus();
1727
1728 // Space above and below
1729 int screenHeight;
1730 wxPoint scrPos;
1731 int spaceAbove;
1732 int spaceBelow;
1733 int maxHeightPopup;
1734 wxSize ctrlSz = GetSize();
1735
1736 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
1737 scrPos = GetParent()->ClientToScreen(GetPosition());
1738
1739 spaceAbove = scrPos.y;
1740 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
1741
1742 maxHeightPopup = spaceBelow;
1743 if ( spaceAbove > spaceBelow )
1744 maxHeightPopup = spaceAbove;
1745
1746 // Width
1747 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
1748
1749 if ( widthPopup < m_widthMinPopup )
1750 widthPopup = m_widthMinPopup;
1751
1752 wxWindow* winPopup = m_winPopup;
1753 wxWindow* popup;
1754
1755 // Need to disable tab traversal of parent
1756 //
1757 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1758 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1759 // that if transient popup is open, then tab traversal is to be ignored.
1760 // However, I think this code would still be needed for cases where
1761 // transient popup doesn't work yet (wxWinCE?).
1762 wxWindow* parent = GetParent();
1763 int parentFlags = parent->GetWindowStyle();
1764 if ( parentFlags & wxTAB_TRAVERSAL )
1765 {
1766 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
1767 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
1768 }
1769
1770 if ( !winPopup )
1771 {
1772 CreatePopup();
1773 winPopup = m_winPopup;
1774 popup = m_popup;
1775 }
1776 else
1777 {
1778 popup = m_popup;
1779 }
1780
1781 winPopup->Enable();
1782
1783 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
1784
1785 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
1786 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
1787 maxHeightPopup);
1788
1789 popup->SetSize(adjustedSize);
1790 popup->Move(0,0);
1791 m_popupInterface->OnPopup();
1792
1793 //
1794 // Reposition and resize popup window
1795 //
1796
1797 wxSize szp = popup->GetSize();
1798
1799 int popupX;
1800 int popupY = scrPos.y + ctrlSz.y;
1801
1802 // Default anchor is wxLEFT
1803 int anchorSide = m_anchorSide;
1804 if ( !anchorSide )
1805 anchorSide = wxLEFT;
1806
1807 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
1808 int leftX = scrPos.x - m_extLeft;
1809 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
1810
1811 // If there is not enough horizontal space, anchor on the other side.
1812 // If there is no space even then, place the popup at x 0.
1813 if ( anchorSide == wxRIGHT )
1814 {
1815 if ( rightX < 0 )
1816 {
1817 if ( (leftX+szp.x) < screenWidth )
1818 anchorSide = wxLEFT;
1819 else
1820 anchorSide = 0;
1821 }
1822 }
1823 else
1824 {
1825 if ( (leftX+szp.x) >= screenWidth )
1826 {
1827 if ( rightX >= 0 )
1828 anchorSide = wxRIGHT;
1829 else
1830 anchorSide = 0;
1831 }
1832 }
1833
1834 // Select x coordinate according to the anchor side
1835 if ( anchorSide == wxRIGHT )
1836 popupX = rightX;
1837 else if ( anchorSide == wxLEFT )
1838 popupX = leftX;
1839 else
1840 popupX = 0;
1841
1842 int showFlags = CanDeferShow;
1843
1844 if ( spaceBelow < szp.y )
1845 {
1846 popupY = scrPos.y - szp.y;
1847 showFlags |= ShowAbove;
1848 }
1849
1850 #if INSTALL_TOPLEV_HANDLER
1851 // Put top level window event handler into place
1852 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1853 {
1854 if ( !m_toplevEvtHandler )
1855 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
1856
1857 wxWindow* toplev = ::wxGetTopLevelParent( this );
1858 wxASSERT( toplev );
1859 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
1860 toplev->PushEventHandler( m_toplevEvtHandler );
1861 }
1862 #endif
1863
1864 // Set string selection (must be this way instead of SetStringSelection)
1865 if ( m_text )
1866 {
1867 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
1868 m_text->SelectAll();
1869
1870 m_popupInterface->SetStringValue( m_text->GetValue() );
1871 }
1872 else
1873 {
1874 // This is neede since focus/selection indication may change when popup is shown
1875 Refresh();
1876 }
1877
1878 // This must be after SetStringValue
1879 m_popupWinState = Animating;
1880
1881 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
1882
1883 m_popup = popup;
1884 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
1885 AnimateShow( popupWinRect, showFlags ) )
1886 {
1887 DoShowPopup( popupWinRect, showFlags );
1888 }
1889 }
1890
1891 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
1892 {
1893 return true;
1894 }
1895
1896 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
1897 {
1898 wxWindow* winPopup = m_winPopup;
1899
1900 if ( IsPopupWindowState(Animating) )
1901 {
1902 // Make sure the popup window is shown in the right position.
1903 // Should not matter even if animation already did this.
1904
1905 // Some platforms (GTK) may like SetSize and Move to be separate
1906 // (though the bug was probably fixed).
1907 winPopup->SetSize( rect );
1908
1909 winPopup->Show();
1910
1911 m_popupWinState = Visible;
1912 }
1913 else if ( IsPopupWindowState(Hidden) )
1914 {
1915 // Animation was aborted
1916
1917 wxASSERT( !winPopup->IsShown() );
1918
1919 m_popupWinState = Hidden;
1920 }
1921 }
1922
1923 void wxComboCtrlBase::OnPopupDismiss()
1924 {
1925 // Just in case, avoid double dismiss
1926 if ( IsPopupWindowState(Hidden) )
1927 return;
1928
1929 // This must be set before focus - otherwise there will be recursive
1930 // OnPopupDismisses.
1931 m_popupWinState = Hidden;
1932
1933 //SetFocus();
1934 m_winPopup->Disable();
1935
1936 // Inform popup control itself
1937 m_popupInterface->OnDismiss();
1938
1939 if ( m_popupExtraHandler )
1940 ((wxComboPopupExtraEventHandler*)m_popupExtraHandler)->OnPopupDismiss();
1941
1942 #if INSTALL_TOPLEV_HANDLER
1943 // Remove top level window event handler
1944 if ( m_toplevEvtHandler )
1945 {
1946 wxWindow* toplev = ::wxGetTopLevelParent( this );
1947 if ( toplev )
1948 toplev->RemoveEventHandler( m_toplevEvtHandler );
1949 }
1950 #endif
1951
1952 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
1953
1954 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1955 m_timeCanAcceptClick += 150;
1956
1957 // If cursor not on dropdown button, then clear its state
1958 // (technically not required by all ports, but do it for all just in case)
1959 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
1960 m_btnState = 0;
1961
1962 // Return parent's tab traversal flag.
1963 // See ShowPopup for notes.
1964 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
1965 {
1966 wxWindow* parent = GetParent();
1967 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
1968 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
1969 }
1970
1971 // refresh control (necessary even if m_text)
1972 Refresh();
1973
1974 SetFocus();
1975 }
1976
1977 void wxComboCtrlBase::HidePopup()
1978 {
1979 // Should be able to call this without popup interface
1980 if ( IsPopupWindowState(Hidden) )
1981 return;
1982
1983 // transfer value and show it in textctrl, if any
1984 if ( !IsPopupWindowState(Animating) )
1985 SetValue( m_popupInterface->GetStringValue() );
1986
1987 m_winPopup->Hide();
1988
1989 OnPopupDismiss();
1990 }
1991
1992 // ----------------------------------------------------------------------------
1993 // customization methods
1994 // ----------------------------------------------------------------------------
1995
1996 void wxComboCtrlBase::SetButtonPosition( int width, int height,
1997 int side, int spacingX )
1998 {
1999 m_btnWid = width;
2000 m_btnHei = height;
2001 m_btnSide = side;
2002 m_btnSpacingX = spacingX;
2003
2004 RecalcAndRefresh();
2005 }
2006
2007 wxSize wxComboCtrlBase::GetButtonSize()
2008 {
2009 if ( m_btnSize.x > 0 )
2010 return m_btnSize;
2011
2012 wxSize retSize(m_btnWid,m_btnHei);
2013
2014 // Need to call CalculateAreas now if button size is
2015 // is not explicitly specified.
2016 if ( retSize.x <= 0 || retSize.y <= 0)
2017 {
2018 OnResize();
2019
2020 retSize = m_btnSize;
2021 }
2022
2023 return retSize;
2024 }
2025
2026 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2027 bool blankButtonBg,
2028 const wxBitmap& bmpPressed,
2029 const wxBitmap& bmpHover,
2030 const wxBitmap& bmpDisabled )
2031 {
2032 m_bmpNormal = bmpNormal;
2033 m_blankButtonBg = blankButtonBg;
2034
2035 if ( bmpPressed.Ok() )
2036 m_bmpPressed = bmpPressed;
2037 else
2038 m_bmpPressed = bmpNormal;
2039
2040 if ( bmpHover.Ok() )
2041 m_bmpHover = bmpHover;
2042 else
2043 m_bmpHover = bmpNormal;
2044
2045 if ( bmpDisabled.Ok() )
2046 m_bmpDisabled = bmpDisabled;
2047 else
2048 m_bmpDisabled = bmpNormal;
2049
2050 RecalcAndRefresh();
2051 }
2052
2053 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2054 {
2055 if ( m_text )
2056 {
2057 // move textctrl accordingly
2058 wxRect r = m_text->GetRect();
2059 int inc = width - m_widthCustomPaint;
2060 r.x += inc;
2061 r.width -= inc;
2062 m_text->SetSize( r );
2063 }
2064
2065 m_widthCustomPaint = width;
2066
2067 RecalcAndRefresh();
2068 }
2069
2070 void wxComboCtrlBase::SetTextIndent( int indent )
2071 {
2072 if ( indent < 0 )
2073 {
2074 m_absIndent = GetNativeTextIndent();
2075 m_iFlags &= ~(wxCC_IFLAG_INDENT_SET);
2076 }
2077 else
2078 {
2079 m_absIndent = indent;
2080 m_iFlags |= wxCC_IFLAG_INDENT_SET;
2081 }
2082
2083 RecalcAndRefresh();
2084 }
2085
2086 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2087 {
2088 return DEFAULT_TEXT_INDENT;
2089 }
2090
2091 // ----------------------------------------------------------------------------
2092 // methods forwarded to wxTextCtrl
2093 // ----------------------------------------------------------------------------
2094
2095 wxString wxComboCtrlBase::GetValue() const
2096 {
2097 if ( m_text )
2098 return m_text->GetValue();
2099 return m_valueString;
2100 }
2101
2102 void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent)
2103 {
2104 if ( m_text )
2105 {
2106 if ( !withEvent )
2107 m_ignoreEvtText++;
2108
2109 m_text->SetValue(value);
2110 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2111 m_text->SelectAll();
2112 }
2113
2114 m_valueString = value;
2115
2116 Refresh();
2117
2118 // Since wxComboPopup may want to paint the combo as well, we need
2119 // to set the string value here (as well as sometimes in ShowPopup).
2120 if ( m_valueString != value && m_popupInterface )
2121 {
2122 m_popupInterface->SetStringValue(value);
2123 }
2124 }
2125
2126 void wxComboCtrlBase::SetValue(const wxString& value)
2127 {
2128 SetValueWithEvent(value, false);
2129 }
2130
2131 // In this SetValue variant wxComboPopup::SetStringValue is not called
2132 void wxComboCtrlBase::SetText(const wxString& value)
2133 {
2134 // Unlike in SetValue(), this must be called here or
2135 // the behaviour will no be consistent in readonlys.
2136 EnsurePopupControl();
2137
2138 m_valueString = value;
2139
2140 if ( m_text )
2141 {
2142 m_ignoreEvtText++;
2143 m_text->SetValue( value );
2144 }
2145
2146 Refresh();
2147 }
2148
2149 void wxComboCtrlBase::Copy()
2150 {
2151 if ( m_text )
2152 m_text->Copy();
2153 }
2154
2155 void wxComboCtrlBase::Cut()
2156 {
2157 if ( m_text )
2158 m_text->Cut();
2159 }
2160
2161 void wxComboCtrlBase::Paste()
2162 {
2163 if ( m_text )
2164 m_text->Paste();
2165 }
2166
2167 void wxComboCtrlBase::SetInsertionPoint(long pos)
2168 {
2169 if ( m_text )
2170 m_text->SetInsertionPoint(pos);
2171 }
2172
2173 void wxComboCtrlBase::SetInsertionPointEnd()
2174 {
2175 if ( m_text )
2176 m_text->SetInsertionPointEnd();
2177 }
2178
2179 long wxComboCtrlBase::GetInsertionPoint() const
2180 {
2181 if ( m_text )
2182 return m_text->GetInsertionPoint();
2183
2184 return 0;
2185 }
2186
2187 long wxComboCtrlBase::GetLastPosition() const
2188 {
2189 if ( m_text )
2190 return m_text->GetLastPosition();
2191
2192 return 0;
2193 }
2194
2195 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2196 {
2197 if ( m_text )
2198 m_text->Replace(from, to, value);
2199 }
2200
2201 void wxComboCtrlBase::Remove(long from, long to)
2202 {
2203 if ( m_text )
2204 m_text->Remove(from, to);
2205 }
2206
2207 void wxComboCtrlBase::SetSelection(long from, long to)
2208 {
2209 if ( m_text )
2210 m_text->SetSelection(from, to);
2211 }
2212
2213 void wxComboCtrlBase::Undo()
2214 {
2215 if ( m_text )
2216 m_text->Undo();
2217 }
2218
2219 #endif // wxUSE_COMBOCTRL