use sizes from the HIG for the best height of the ComboCtrl on wxMac
[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, wxSize(10,-1),
832 style, validator);
833 }
834 }
835
836 void wxComboCtrlBase::OnThemeChange()
837 {
838 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
839 }
840
841 wxComboCtrlBase::~wxComboCtrlBase()
842 {
843 if ( HasCapture() )
844 ReleaseMouse();
845
846 #if INSTALL_TOPLEV_HANDLER
847 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
848 m_toplevEvtHandler = (wxEvtHandler*) NULL;
849 #endif
850
851 DestroyPopup();
852
853 if ( m_text )
854 m_text->RemoveEventHandler(m_textEvtHandler);
855
856 delete m_textEvtHandler;
857 }
858
859
860 // ----------------------------------------------------------------------------
861 // geometry stuff
862 // ----------------------------------------------------------------------------
863
864 // Recalculates button and textctrl areas
865 void wxComboCtrlBase::CalculateAreas( int btnWidth )
866 {
867 wxSize sz = GetClientSize();
868 int customBorder = m_widthCustomBorder;
869 int btnBorder; // border for button only
870
871 // check if button should really be outside the border: we'll do it it if
872 // its platform default or bitmap+pushbutton background is used, but not if
873 // there is vertical size adjustment or horizontal spacing.
874 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
875 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
876 m_btnSpacingX == 0 &&
877 m_btnHei <= 0 )
878 {
879 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
880 btnBorder = 0;
881 }
882 else
883 {
884 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
885 btnBorder = customBorder;
886 }
887
888 // Defaul indentation
889 if ( m_absIndent < 0 )
890 m_absIndent = GetNativeTextIndent();
891
892 int butWidth = btnWidth;
893
894 if ( butWidth <= 0 )
895 butWidth = m_btnWidDefault;
896 else
897 m_btnWidDefault = butWidth;
898
899 if ( butWidth <= 0 )
900 return;
901
902 int butHeight = sz.y - btnBorder*2;
903
904 // Adjust button width
905 if ( m_btnWid > 0 )
906 butWidth = m_btnWid;
907 else
908 {
909 // Adjust button width to match aspect ratio
910 // (but only if control is smaller than best size).
911 int bestHeight = GetBestSize().y;
912 int height = GetSize().y;
913
914 if ( height < bestHeight )
915 {
916 // Make very small buttons square, as it makes
917 // them accommodate arrow image better and still
918 // looks decent.
919 if ( height > 18 )
920 butWidth = (height*butWidth)/bestHeight;
921 else
922 butWidth = butHeight;
923 }
924 }
925
926 // Adjust button height
927 if ( m_btnHei > 0 )
928 butHeight = m_btnHei;
929
930 // Use size of normal bitmap if...
931 // It is larger
932 // OR
933 // button width is set to default and blank button bg is not drawn
934 if ( m_bmpNormal.Ok() )
935 {
936 int bmpReqWidth = m_bmpNormal.GetWidth();
937 int bmpReqHeight = m_bmpNormal.GetHeight();
938
939 // If drawing blank button background, we need to add some margin.
940 if ( m_blankButtonBg )
941 {
942 bmpReqWidth += BMP_BUTTON_MARGIN*2;
943 bmpReqHeight += BMP_BUTTON_MARGIN*2;
944 }
945
946 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
947 butWidth = bmpReqWidth;
948 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
949 butHeight = bmpReqHeight;
950
951 // Need to fix height?
952 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
953 {
954 int newY = butHeight+(customBorder*2);
955 SetClientSize(wxDefaultCoord,newY);
956 sz.y = newY;
957 }
958 }
959
960 int butAreaWid = butWidth + (m_btnSpacingX*2);
961
962 m_btnSize.x = butWidth;
963 m_btnSize.y = butHeight;
964
965 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
966 m_btnArea.y = btnBorder;
967 m_btnArea.width = butAreaWid;
968 m_btnArea.height = sz.y - (btnBorder*2);
969
970 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder;
971 m_tcArea.y = customBorder;
972 m_tcArea.width = sz.x - butAreaWid - (customBorder*2);
973 m_tcArea.height = sz.y - (customBorder*2);
974
975 /*
976 if ( m_text )
977 {
978 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
979 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
980 }
981 */
982 }
983
984 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
985 {
986 if ( !m_text )
987 return;
988
989 wxSize sz = GetClientSize();
990 int customBorder = m_widthCustomBorder;
991
992 #if !TEXTCTRL_TEXT_CENTERED
993 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
994 {
995 // Centre textctrl
996 int tcSizeY = m_text->GetBestSize().y;
997 int diff = sz.y - tcSizeY;
998 int y = textCtrlYAdjust + (diff/2);
999
1000 if ( y < customBorder )
1001 y = customBorder;
1002
1003 m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
1004 y,
1005 m_tcArea.width - COMBO_MARGIN -
1006 (textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
1007 -1 );
1008
1009 // Make sure textctrl doesn't exceed the bottom custom border
1010 wxSize tsz = m_text->GetSize();
1011 diff = (y + tsz.y) - (sz.y - customBorder);
1012 if ( diff >= 0 )
1013 {
1014 tsz.y = tsz.y - diff - 1;
1015 m_text->SetSize(tsz);
1016 }
1017 }
1018 else
1019 #else
1020 wxUnusedVar(textCtrlXAdjust);
1021 wxUnusedVar(textCtrlYAdjust);
1022 #endif
1023 {
1024 // If it has border, have textctrl will the entire text field.
1025 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1026 customBorder,
1027 sz.x - m_btnArea.width - m_widthCustomPaint - customBorder,
1028 sz.y-(customBorder*2) );
1029 }
1030 }
1031
1032 wxSize wxComboCtrlBase::DoGetBestSize() const
1033 {
1034 wxSize sizeText(150,0);
1035
1036 if ( m_text )
1037 sizeText = m_text->GetBestSize();
1038
1039 // TODO: Better method to calculate close-to-native control height.
1040
1041 int fhei;
1042 if ( m_font.Ok() )
1043 fhei = (m_font.GetPointSize()*2) + 5;
1044 else if ( wxNORMAL_FONT->Ok() )
1045 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1046 else
1047 fhei = sizeText.y + 4;
1048
1049 // Need to force height to accomodate bitmap?
1050 int btnSizeY = m_btnSize.y;
1051 if ( m_bmpNormal.Ok() && fhei < btnSizeY )
1052 fhei = btnSizeY;
1053
1054 // Control height doesn't depend on border
1055 /*
1056 // Add border
1057 int border = m_windowStyle & wxBORDER_MASK;
1058 if ( border == wxSIMPLE_BORDER )
1059 fhei += 2;
1060 else if ( border == wxNO_BORDER )
1061 fhei += (m_widthCustomBorder*2);
1062 else
1063 // Sunken etc.
1064 fhei += 4;
1065 */
1066
1067 // Final adjustments
1068 #ifdef __WXGTK__
1069 fhei += 1;
1070 #endif
1071
1072 #ifdef __WXMAC__
1073 // these are the numbers from the HIG:
1074 switch ( m_windowVariant )
1075 {
1076 case wxWINDOW_VARIANT_NORMAL:
1077 default :
1078 fhei = 22;
1079 break;
1080 case wxWINDOW_VARIANT_SMALL:
1081 fhei = 19;
1082 break;
1083 case wxWINDOW_VARIANT_MINI:
1084 fhei = 15;
1085 break;
1086 }
1087 #endif
1088
1089 wxSize ret(sizeText.x + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH,
1090 fhei);
1091
1092 CacheBestSize(ret);
1093 return ret;
1094 }
1095
1096 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1097 {
1098 if ( !IsCreated() )
1099 return;
1100
1101 // defined by actual wxComboCtrls
1102 OnResize();
1103
1104 event.Skip();
1105 }
1106
1107 // ----------------------------------------------------------------------------
1108 // standard operations
1109 // ----------------------------------------------------------------------------
1110
1111 bool wxComboCtrlBase::Enable(bool enable)
1112 {
1113 if ( !wxControl::Enable(enable) )
1114 return false;
1115
1116 if ( m_btn )
1117 m_btn->Enable(enable);
1118 if ( m_text )
1119 m_text->Enable(enable);
1120
1121 return true;
1122 }
1123
1124 bool wxComboCtrlBase::Show(bool show)
1125 {
1126 if ( !wxControl::Show(show) )
1127 return false;
1128
1129 if (m_btn)
1130 m_btn->Show(show);
1131
1132 if (m_text)
1133 m_text->Show(show);
1134
1135 return true;
1136 }
1137
1138 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1139 {
1140 if ( !wxControl::SetFont(font) )
1141 return false;
1142
1143 if (m_text)
1144 m_text->SetFont(font);
1145
1146 return true;
1147 }
1148
1149 #if wxUSE_TOOLTIPS
1150 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1151 {
1152 wxControl::DoSetToolTip(tooltip);
1153
1154 // Set tool tip for button and text box
1155 if ( tooltip )
1156 {
1157 const wxString &tip = tooltip->GetTip();
1158 if ( m_text ) m_text->SetToolTip(tip);
1159 if ( m_btn ) m_btn->SetToolTip(tip);
1160 }
1161 else
1162 {
1163 if ( m_text ) m_text->SetToolTip( (wxToolTip*) NULL );
1164 if ( m_btn ) m_btn->SetToolTip( (wxToolTip*) NULL );
1165 }
1166 }
1167 #endif // wxUSE_TOOLTIPS
1168
1169 #if wxUSE_VALIDATORS
1170 void wxComboCtrlBase::SetValidator(const wxValidator& validator)
1171 {
1172 wxTextCtrl* textCtrl = GetTextCtrl();
1173
1174 if ( textCtrl )
1175 textCtrl->SetValidator( validator );
1176 }
1177
1178 wxValidator* wxComboCtrlBase::GetValidator()
1179 {
1180 wxTextCtrl* textCtrl = GetTextCtrl();
1181
1182 if ( textCtrl )
1183 return textCtrl->GetValidator();
1184
1185 return wxControl::GetValidator();
1186 }
1187 #endif // wxUSE_VALIDATORS
1188
1189 // ----------------------------------------------------------------------------
1190 // painting
1191 // ----------------------------------------------------------------------------
1192
1193 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1194 // prepare combo box background on area in a way typical on platform
1195 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1196 {
1197 wxSize sz = GetClientSize();
1198 bool isEnabled;
1199 bool isFocused; // also selected
1200
1201 // For smaller size control (and for disabled background) use less spacing
1202 int focusSpacingX;
1203 int focusSpacingY;
1204
1205 if ( !(flags & wxCONTROL_ISSUBMENU) )
1206 {
1207 // Drawing control
1208 isEnabled = IsEnabled();
1209 isFocused = ShouldDrawFocus();
1210
1211 // Windows-style: for smaller size control (and for disabled background) use less spacing
1212 focusSpacingX = isEnabled ? 2 : 1;
1213 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1214 }
1215 else
1216 {
1217 // Drawing a list item
1218 isEnabled = true; // they are never disabled
1219 isFocused = flags & wxCONTROL_SELECTED ? true : false;
1220
1221 focusSpacingX = 0;
1222 focusSpacingY = 0;
1223 }
1224
1225 // Set the background sub-rectangle for selection, disabled etc
1226 wxRect selRect(rect);
1227 selRect.y += focusSpacingY;
1228 selRect.height -= (focusSpacingY*2);
1229
1230 int wcp = 0;
1231
1232 if ( !(flags & wxCONTROL_ISSUBMENU) )
1233 wcp += m_widthCustomPaint;
1234
1235 selRect.x += wcp + focusSpacingX;
1236 selRect.width -= wcp + (focusSpacingX*2);
1237
1238 wxColour bgCol;
1239
1240 if ( isEnabled )
1241 {
1242 // If popup is hidden and this control is focused,
1243 // then draw the focus-indicator (selbgcolor background etc.).
1244 if ( isFocused )
1245 {
1246 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
1247 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1248 }
1249 else
1250 {
1251 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
1252 bgCol = GetBackgroundColour();
1253 }
1254 }
1255 else
1256 {
1257 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
1258 bgCol = GetBackgroundColour();
1259 }
1260
1261 dc.SetBrush( bgCol );
1262 dc.SetPen( bgCol );
1263 dc.DrawRectangle( selRect );
1264
1265 // Don't clip exactly to the selection rectangle so we can draw
1266 // to the non-selected area in front of it.
1267 wxRect clipRect(rect.x,rect.y,
1268 (selRect.x+selRect.width)-rect.x,rect.height);
1269 dc.SetClippingRegion(clipRect);
1270 }
1271 #else
1272 // Save the library size a bit for platforms that re-implement this.
1273 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1274 {
1275 }
1276 #endif
1277
1278 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int paintBg )
1279 {
1280 int drawState = m_btnState;
1281
1282 #ifdef __WXGTK__
1283 if ( GetPopupWindowState() >= Animating )
1284 drawState |= wxCONTROL_PRESSED;
1285 #endif
1286
1287 wxRect drawRect(rect.x+m_btnSpacingX,
1288 rect.y+((rect.height-m_btnSize.y)/2),
1289 m_btnSize.x,
1290 m_btnSize.y);
1291
1292 // Make sure area is not larger than the control
1293 if ( drawRect.y < rect.y )
1294 drawRect.y = rect.y;
1295 if ( drawRect.height > rect.height )
1296 drawRect.height = rect.height;
1297
1298 bool enabled = IsEnabled();
1299
1300 if ( !enabled )
1301 drawState |= wxCONTROL_DISABLED;
1302
1303 if ( !m_bmpNormal.Ok() )
1304 {
1305 // Need to clear button background even if m_btn is present
1306 if ( paintBg )
1307 {
1308 wxColour bgCol;
1309
1310 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1311 bgCol = GetParent()->GetBackgroundColour();
1312 else
1313 bgCol = GetBackgroundColour();
1314
1315 dc.SetBrush(bgCol);
1316 dc.SetPen(bgCol);
1317 dc.DrawRectangle(rect);
1318 }
1319
1320 // Draw standard button
1321 wxRendererNative::Get().DrawComboBoxDropButton(this,
1322 dc,
1323 drawRect,
1324 drawState);
1325 }
1326 else
1327 {
1328 // Draw bitmap
1329
1330 wxBitmap* pBmp;
1331
1332 if ( !enabled )
1333 pBmp = &m_bmpDisabled;
1334 else if ( m_btnState & wxCONTROL_PRESSED )
1335 pBmp = &m_bmpPressed;
1336 else if ( m_btnState & wxCONTROL_CURRENT )
1337 pBmp = &m_bmpHover;
1338 else
1339 pBmp = &m_bmpNormal;
1340
1341 if ( m_blankButtonBg )
1342 {
1343 // If using blank button background, we need to clear its background
1344 // with button face colour instead of colour for rest of the control.
1345 if ( paintBg )
1346 {
1347 wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1348 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1349 dc.SetPen(bgCol);
1350 dc.SetBrush(bgCol);
1351 dc.DrawRectangle(rect);
1352 }
1353
1354 wxRendererNative::Get().DrawPushButton(this,
1355 dc,
1356 drawRect,
1357 drawState);
1358
1359 }
1360 else
1361
1362 {
1363 // Need to clear button background even if m_btn is present
1364 // (assume non-button background was cleared just before this call so brushes are good)
1365 if ( paintBg )
1366 dc.DrawRectangle(rect);
1367 }
1368
1369 // Draw bitmap centered in drawRect
1370 dc.DrawBitmap(*pBmp,
1371 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1372 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1373 true);
1374 }
1375 }
1376
1377 void wxComboCtrlBase::RecalcAndRefresh()
1378 {
1379 if ( IsCreated() )
1380 {
1381 wxSizeEvent evt(GetSize(),GetId());
1382 GetEventHandler()->ProcessEvent(evt);
1383 Refresh();
1384 }
1385 }
1386
1387 // ----------------------------------------------------------------------------
1388 // miscellaneous event handlers
1389 // ----------------------------------------------------------------------------
1390
1391 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1392 {
1393 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1394 {
1395 if ( m_ignoreEvtText > 0 )
1396 {
1397 m_ignoreEvtText--;
1398 return;
1399 }
1400 }
1401
1402 // Change event id, object and string before relaying it forward
1403 event.SetId(GetId());
1404 wxString s = event.GetString();
1405 event.SetEventObject(this);
1406 event.SetString(s);
1407 event.Skip();
1408 }
1409
1410 // call if cursor is on button area or mouse is captured for the button
1411 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1412 int flags )
1413 {
1414 int type = event.GetEventType();
1415
1416 if ( type == wxEVT_MOTION )
1417 {
1418 if ( flags & wxCC_MF_ON_BUTTON )
1419 {
1420 if ( !(m_btnState & wxCONTROL_CURRENT) )
1421 {
1422 // Mouse hover begins
1423 m_btnState |= wxCONTROL_CURRENT;
1424 if ( HasCapture() ) // Retain pressed state.
1425 m_btnState |= wxCONTROL_PRESSED;
1426 Refresh();
1427 }
1428 }
1429 else if ( (m_btnState & wxCONTROL_CURRENT) )
1430 {
1431 // Mouse hover ends
1432 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1433 Refresh();
1434 }
1435 }
1436 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1437 {
1438 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1439 {
1440 m_btnState |= wxCONTROL_PRESSED;
1441 Refresh();
1442
1443 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1444 OnButtonClick();
1445 else
1446 // If showing popup now, do not capture mouse or there will be interference
1447 CaptureMouse();
1448 }
1449 }
1450 else if ( type == wxEVT_LEFT_UP )
1451 {
1452
1453 // Only accept event if mouse was left-press was previously accepted
1454 if ( HasCapture() )
1455 ReleaseMouse();
1456
1457 if ( m_btnState & wxCONTROL_PRESSED )
1458 {
1459 // If mouse was inside, fire the click event.
1460 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1461 {
1462 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1463 OnButtonClick();
1464 }
1465
1466 m_btnState &= ~(wxCONTROL_PRESSED);
1467 Refresh();
1468 }
1469 }
1470 else if ( type == wxEVT_LEAVE_WINDOW )
1471 {
1472 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1473 {
1474 m_btnState &= ~(wxCONTROL_CURRENT);
1475
1476 // Mouse hover ends
1477 if ( IsPopupWindowState(Hidden) )
1478 {
1479 m_btnState &= ~(wxCONTROL_PRESSED);
1480 Refresh();
1481 }
1482 }
1483 }
1484 else
1485 return false;
1486
1487 return true;
1488 }
1489
1490 // returns true if event was consumed or filtered
1491 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1492 int WXUNUSED(flags) )
1493 {
1494 wxLongLong t = ::wxGetLocalTimeMillis();
1495 int evtType = event.GetEventType();
1496
1497 #if USES_WXPOPUPWINDOW || USES_WXDIALOG
1498 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1499 {
1500 if ( IsPopupWindowState(Visible) &&
1501 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1502 {
1503 HidePopup();
1504 return true;
1505 }
1506 }
1507 #endif
1508
1509 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1510 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1511 {
1512 event.SetEventType(0);
1513 return true;
1514 }
1515
1516 return false;
1517 }
1518
1519 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1520 {
1521 int evtType = event.GetEventType();
1522
1523 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1524 (m_windowStyle & wxCB_READONLY) )
1525 {
1526 if ( GetPopupWindowState() >= Animating )
1527 {
1528 #if USES_WXPOPUPWINDOW
1529 // Click here always hides the popup.
1530 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1531 HidePopup();
1532 #endif
1533 }
1534 else
1535 {
1536 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1537 {
1538 // In read-only mode, clicking the text is the
1539 // same as clicking the button.
1540 OnButtonClick();
1541 }
1542 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1543 {
1544 //if ( m_popupInterface->CycleValue() )
1545 // Refresh();
1546 if ( m_popupInterface )
1547 m_popupInterface->OnComboDoubleClick();
1548 }
1549 }
1550 }
1551 else
1552 if ( IsPopupShown() )
1553 {
1554 // relay (some) mouse events to the popup
1555 if ( evtType == wxEVT_MOUSEWHEEL )
1556 m_popup->AddPendingEvent(event);
1557 }
1558 else if ( evtType )
1559 event.Skip();
1560 }
1561
1562 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1563 {
1564 if ( IsPopupShown() )
1565 {
1566 // pass it to the popped up control
1567 GetPopupControl()->GetControl()->AddPendingEvent(event);
1568 }
1569 else // no popup
1570 {
1571 int keycode = event.GetKeyCode();
1572
1573 if ( keycode == WXK_TAB )
1574 {
1575 wxNavigationKeyEvent evt;
1576
1577 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1578
1579 evt.SetFlags(wxNavigationKeyEvent::FromTab|
1580 (!event.ShiftDown() ? wxNavigationKeyEvent::IsForward
1581 : wxNavigationKeyEvent::IsBackward));
1582 evt.SetEventObject(mainCtrl);
1583 evt.SetCurrentFocus(mainCtrl);
1584 mainCtrl->GetParent()->GetEventHandler()->AddPendingEvent(evt);
1585 return;
1586 }
1587
1588 if ( IsKeyPopupToggle(event) )
1589 {
1590 OnButtonClick();
1591 return;
1592 }
1593
1594 int comboStyle = GetWindowStyle();
1595 wxComboPopup* popupInterface = GetPopupControl();
1596
1597 if ( !popupInterface )
1598 {
1599 event.Skip();
1600 return;
1601 }
1602
1603 if ( (comboStyle & wxCB_READONLY) ||
1604 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
1605 {
1606 popupInterface->OnComboKeyEvent(event);
1607 }
1608 else
1609 event.Skip();
1610 }
1611 }
1612
1613 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
1614 {
1615 if ( event.GetEventType() == wxEVT_SET_FOCUS )
1616 {
1617 #ifndef __WXMAC__
1618 wxWindow* tc = GetTextCtrl();
1619 if ( tc && tc != DoFindFocus() )
1620 tc->SetFocus();
1621 #endif
1622 }
1623
1624 Refresh();
1625 }
1626
1627 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
1628 {
1629 OnThemeChange();
1630 // indentation may also have changed
1631 if ( !(m_iFlags & wxCC_IFLAG_INDENT_SET) )
1632 m_absIndent = GetNativeTextIndent();
1633 RecalcAndRefresh();
1634 }
1635
1636 // ----------------------------------------------------------------------------
1637 // popup handling
1638 // ----------------------------------------------------------------------------
1639
1640 // Create popup window and the child control
1641 void wxComboCtrlBase::CreatePopup()
1642 {
1643 wxComboPopup* popupInterface = m_popupInterface;
1644 wxWindow* popup;
1645
1646 if ( !m_winPopup )
1647 {
1648 #ifdef wxComboPopupWindowBase2
1649 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
1650 {
1651 #if !USES_WXDIALOG
1652 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
1653 #else
1654 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
1655 wxPoint(-21,-21), wxSize(20, 20),
1656 wxNO_BORDER );
1657 #endif
1658 m_popupWinType = SECONDARY_POPUP_TYPE;
1659 }
1660 else
1661 #endif
1662 {
1663 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
1664 m_popupWinType = PRIMARY_POPUP_TYPE;
1665 }
1666 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
1667 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
1668 }
1669
1670 popupInterface->Create(m_winPopup);
1671 m_popup = popup = popupInterface->GetControl();
1672
1673 m_popupExtraHandler = new wxComboPopupExtraEventHandler(this);
1674 popup->PushEventHandler( m_popupExtraHandler );
1675
1676 // This may be helpful on some platforms
1677 // (eg. it bypasses a wxGTK popupwindow bug where
1678 // window is not initially hidden when it should be)
1679 m_winPopup->Hide();
1680
1681 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
1682 }
1683
1684 // Destroy popup window and the child control
1685 void wxComboCtrlBase::DestroyPopup()
1686 {
1687 HidePopup();
1688
1689 if ( m_popup )
1690 m_popup->RemoveEventHandler(m_popupExtraHandler);
1691
1692 delete m_popupExtraHandler;
1693
1694 delete m_popupInterface;
1695
1696 if ( m_winPopup )
1697 {
1698 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
1699 delete m_popupWinEvtHandler;
1700 m_popupWinEvtHandler = NULL;
1701 m_winPopup->Destroy();
1702 }
1703
1704 m_popupExtraHandler = (wxEvtHandler*) NULL;
1705 m_popupInterface = (wxComboPopup*) NULL;
1706 m_winPopup = (wxWindow*) NULL;
1707 m_popup = (wxWindow*) NULL;
1708 }
1709
1710 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
1711 {
1712 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
1713
1714 DestroyPopup();
1715
1716 iface->InitBase(this);
1717 iface->Init();
1718
1719 m_popupInterface = iface;
1720
1721 if ( !iface->LazyCreate() )
1722 {
1723 CreatePopup();
1724 }
1725 else
1726 {
1727 m_popup = (wxWindow*) NULL;
1728 }
1729
1730 // This must be done after creation
1731 if ( m_valueString.length() )
1732 {
1733 iface->SetStringValue(m_valueString);
1734 //Refresh();
1735 }
1736 }
1737
1738 // Ensures there is atleast the default popup
1739 void wxComboCtrlBase::EnsurePopupControl()
1740 {
1741 if ( !m_popupInterface )
1742 SetPopupControl(NULL);
1743 }
1744
1745 void wxComboCtrlBase::OnButtonClick()
1746 {
1747 // Derived classes can override this method for totally custom
1748 // popup action
1749 ShowPopup();
1750 }
1751
1752 void wxComboCtrlBase::ShowPopup()
1753 {
1754 EnsurePopupControl();
1755 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
1756
1757 if ( IsPopupWindowState(Animating) )
1758 return;
1759
1760 SetFocus();
1761
1762 // Space above and below
1763 int screenHeight;
1764 wxPoint scrPos;
1765 int spaceAbove;
1766 int spaceBelow;
1767 int maxHeightPopup;
1768 wxSize ctrlSz = GetSize();
1769
1770 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
1771 scrPos = GetParent()->ClientToScreen(GetPosition());
1772
1773 spaceAbove = scrPos.y;
1774 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
1775
1776 maxHeightPopup = spaceBelow;
1777 if ( spaceAbove > spaceBelow )
1778 maxHeightPopup = spaceAbove;
1779
1780 // Width
1781 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
1782
1783 if ( widthPopup < m_widthMinPopup )
1784 widthPopup = m_widthMinPopup;
1785
1786 wxWindow* winPopup = m_winPopup;
1787 wxWindow* popup;
1788
1789 // Need to disable tab traversal of parent
1790 //
1791 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1792 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1793 // that if transient popup is open, then tab traversal is to be ignored.
1794 // However, I think this code would still be needed for cases where
1795 // transient popup doesn't work yet (wxWinCE?).
1796 wxWindow* parent = GetParent();
1797 int parentFlags = parent->GetWindowStyle();
1798 if ( parentFlags & wxTAB_TRAVERSAL )
1799 {
1800 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
1801 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
1802 }
1803
1804 if ( !winPopup )
1805 {
1806 CreatePopup();
1807 winPopup = m_winPopup;
1808 popup = m_popup;
1809 }
1810 else
1811 {
1812 popup = m_popup;
1813 }
1814
1815 winPopup->Enable();
1816
1817 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
1818
1819 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
1820 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
1821 maxHeightPopup);
1822
1823 popup->SetSize(adjustedSize);
1824 popup->Move(0,0);
1825 m_popupInterface->OnPopup();
1826
1827 //
1828 // Reposition and resize popup window
1829 //
1830
1831 wxSize szp = popup->GetSize();
1832
1833 int popupX;
1834 int popupY = scrPos.y + ctrlSz.y;
1835
1836 // Default anchor is wxLEFT
1837 int anchorSide = m_anchorSide;
1838 if ( !anchorSide )
1839 anchorSide = wxLEFT;
1840
1841 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
1842 int leftX = scrPos.x - m_extLeft;
1843 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
1844
1845 // If there is not enough horizontal space, anchor on the other side.
1846 // If there is no space even then, place the popup at x 0.
1847 if ( anchorSide == wxRIGHT )
1848 {
1849 if ( rightX < 0 )
1850 {
1851 if ( (leftX+szp.x) < screenWidth )
1852 anchorSide = wxLEFT;
1853 else
1854 anchorSide = 0;
1855 }
1856 }
1857 else
1858 {
1859 if ( (leftX+szp.x) >= screenWidth )
1860 {
1861 if ( rightX >= 0 )
1862 anchorSide = wxRIGHT;
1863 else
1864 anchorSide = 0;
1865 }
1866 }
1867
1868 // Select x coordinate according to the anchor side
1869 if ( anchorSide == wxRIGHT )
1870 popupX = rightX;
1871 else if ( anchorSide == wxLEFT )
1872 popupX = leftX;
1873 else
1874 popupX = 0;
1875
1876 int showFlags = CanDeferShow;
1877
1878 if ( spaceBelow < szp.y )
1879 {
1880 popupY = scrPos.y - szp.y;
1881 showFlags |= ShowAbove;
1882 }
1883
1884 #if INSTALL_TOPLEV_HANDLER
1885 // Put top level window event handler into place
1886 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1887 {
1888 if ( !m_toplevEvtHandler )
1889 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
1890
1891 wxWindow* toplev = ::wxGetTopLevelParent( this );
1892 wxASSERT( toplev );
1893 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
1894 toplev->PushEventHandler( m_toplevEvtHandler );
1895 }
1896 #endif
1897
1898 // Set string selection (must be this way instead of SetStringSelection)
1899 if ( m_text )
1900 {
1901 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
1902 m_text->SelectAll();
1903
1904 m_popupInterface->SetStringValue( m_text->GetValue() );
1905 }
1906 else
1907 {
1908 // This is neede since focus/selection indication may change when popup is shown
1909 Refresh();
1910 }
1911
1912 // This must be after SetStringValue
1913 m_popupWinState = Animating;
1914
1915 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
1916
1917 m_popup = popup;
1918 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
1919 AnimateShow( popupWinRect, showFlags ) )
1920 {
1921 DoShowPopup( popupWinRect, showFlags );
1922 }
1923 }
1924
1925 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
1926 {
1927 return true;
1928 }
1929
1930 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
1931 {
1932 wxWindow* winPopup = m_winPopup;
1933
1934 if ( IsPopupWindowState(Animating) )
1935 {
1936 // Make sure the popup window is shown in the right position.
1937 // Should not matter even if animation already did this.
1938
1939 // Some platforms (GTK) may like SetSize and Move to be separate
1940 // (though the bug was probably fixed).
1941 winPopup->SetSize( rect );
1942
1943 winPopup->Show();
1944
1945 m_popupWinState = Visible;
1946 }
1947 else if ( IsPopupWindowState(Hidden) )
1948 {
1949 // Animation was aborted
1950
1951 wxASSERT( !winPopup->IsShown() );
1952
1953 m_popupWinState = Hidden;
1954 }
1955 }
1956
1957 void wxComboCtrlBase::OnPopupDismiss()
1958 {
1959 // Just in case, avoid double dismiss
1960 if ( IsPopupWindowState(Hidden) )
1961 return;
1962
1963 // This must be set before focus - otherwise there will be recursive
1964 // OnPopupDismisses.
1965 m_popupWinState = Hidden;
1966
1967 //SetFocus();
1968 m_winPopup->Disable();
1969
1970 // Inform popup control itself
1971 m_popupInterface->OnDismiss();
1972
1973 if ( m_popupExtraHandler )
1974 ((wxComboPopupExtraEventHandler*)m_popupExtraHandler)->OnPopupDismiss();
1975
1976 #if INSTALL_TOPLEV_HANDLER
1977 // Remove top level window event handler
1978 if ( m_toplevEvtHandler )
1979 {
1980 wxWindow* toplev = ::wxGetTopLevelParent( this );
1981 if ( toplev )
1982 toplev->RemoveEventHandler( m_toplevEvtHandler );
1983 }
1984 #endif
1985
1986 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
1987
1988 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1989 m_timeCanAcceptClick += 150;
1990
1991 // If cursor not on dropdown button, then clear its state
1992 // (technically not required by all ports, but do it for all just in case)
1993 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
1994 m_btnState = 0;
1995
1996 // Return parent's tab traversal flag.
1997 // See ShowPopup for notes.
1998 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
1999 {
2000 wxWindow* parent = GetParent();
2001 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2002 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2003 }
2004
2005 // refresh control (necessary even if m_text)
2006 Refresh();
2007
2008 SetFocus();
2009 }
2010
2011 void wxComboCtrlBase::HidePopup()
2012 {
2013 // Should be able to call this without popup interface
2014 if ( IsPopupWindowState(Hidden) )
2015 return;
2016
2017 // transfer value and show it in textctrl, if any
2018 if ( !IsPopupWindowState(Animating) )
2019 SetValue( m_popupInterface->GetStringValue() );
2020
2021 m_winPopup->Hide();
2022
2023 OnPopupDismiss();
2024 }
2025
2026 // ----------------------------------------------------------------------------
2027 // customization methods
2028 // ----------------------------------------------------------------------------
2029
2030 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2031 int side, int spacingX )
2032 {
2033 m_btnWid = width;
2034 m_btnHei = height;
2035 m_btnSide = side;
2036 m_btnSpacingX = spacingX;
2037
2038 RecalcAndRefresh();
2039 }
2040
2041 wxSize wxComboCtrlBase::GetButtonSize()
2042 {
2043 if ( m_btnSize.x > 0 )
2044 return m_btnSize;
2045
2046 wxSize retSize(m_btnWid,m_btnHei);
2047
2048 // Need to call CalculateAreas now if button size is
2049 // is not explicitly specified.
2050 if ( retSize.x <= 0 || retSize.y <= 0)
2051 {
2052 OnResize();
2053
2054 retSize = m_btnSize;
2055 }
2056
2057 return retSize;
2058 }
2059
2060 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2061 bool blankButtonBg,
2062 const wxBitmap& bmpPressed,
2063 const wxBitmap& bmpHover,
2064 const wxBitmap& bmpDisabled )
2065 {
2066 m_bmpNormal = bmpNormal;
2067 m_blankButtonBg = blankButtonBg;
2068
2069 if ( bmpPressed.Ok() )
2070 m_bmpPressed = bmpPressed;
2071 else
2072 m_bmpPressed = bmpNormal;
2073
2074 if ( bmpHover.Ok() )
2075 m_bmpHover = bmpHover;
2076 else
2077 m_bmpHover = bmpNormal;
2078
2079 if ( bmpDisabled.Ok() )
2080 m_bmpDisabled = bmpDisabled;
2081 else
2082 m_bmpDisabled = bmpNormal;
2083
2084 RecalcAndRefresh();
2085 }
2086
2087 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2088 {
2089 if ( m_text )
2090 {
2091 // move textctrl accordingly
2092 wxRect r = m_text->GetRect();
2093 int inc = width - m_widthCustomPaint;
2094 r.x += inc;
2095 r.width -= inc;
2096 m_text->SetSize( r );
2097 }
2098
2099 m_widthCustomPaint = width;
2100
2101 RecalcAndRefresh();
2102 }
2103
2104 void wxComboCtrlBase::SetTextIndent( int indent )
2105 {
2106 if ( indent < 0 )
2107 {
2108 m_absIndent = GetNativeTextIndent();
2109 m_iFlags &= ~(wxCC_IFLAG_INDENT_SET);
2110 }
2111 else
2112 {
2113 m_absIndent = indent;
2114 m_iFlags |= wxCC_IFLAG_INDENT_SET;
2115 }
2116
2117 RecalcAndRefresh();
2118 }
2119
2120 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2121 {
2122 return DEFAULT_TEXT_INDENT;
2123 }
2124
2125 // ----------------------------------------------------------------------------
2126 // methods forwarded to wxTextCtrl
2127 // ----------------------------------------------------------------------------
2128
2129 wxString wxComboCtrlBase::GetValue() const
2130 {
2131 if ( m_text )
2132 return m_text->GetValue();
2133 return m_valueString;
2134 }
2135
2136 void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent)
2137 {
2138 if ( m_text )
2139 {
2140 if ( !withEvent )
2141 m_ignoreEvtText++;
2142
2143 m_text->SetValue(value);
2144 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2145 m_text->SelectAll();
2146 }
2147
2148 m_valueString = value;
2149
2150 Refresh();
2151
2152 // Since wxComboPopup may want to paint the combo as well, we need
2153 // to set the string value here (as well as sometimes in ShowPopup).
2154 if ( m_valueString != value && m_popupInterface )
2155 {
2156 m_popupInterface->SetStringValue(value);
2157 }
2158 }
2159
2160 void wxComboCtrlBase::SetValue(const wxString& value)
2161 {
2162 SetValueWithEvent(value, false);
2163 }
2164
2165 // In this SetValue variant wxComboPopup::SetStringValue is not called
2166 void wxComboCtrlBase::SetText(const wxString& value)
2167 {
2168 // Unlike in SetValue(), this must be called here or
2169 // the behaviour will no be consistent in readonlys.
2170 EnsurePopupControl();
2171
2172 m_valueString = value;
2173
2174 if ( m_text )
2175 {
2176 m_ignoreEvtText++;
2177 m_text->SetValue( value );
2178 }
2179
2180 Refresh();
2181 }
2182
2183 void wxComboCtrlBase::Copy()
2184 {
2185 if ( m_text )
2186 m_text->Copy();
2187 }
2188
2189 void wxComboCtrlBase::Cut()
2190 {
2191 if ( m_text )
2192 m_text->Cut();
2193 }
2194
2195 void wxComboCtrlBase::Paste()
2196 {
2197 if ( m_text )
2198 m_text->Paste();
2199 }
2200
2201 void wxComboCtrlBase::SetInsertionPoint(long pos)
2202 {
2203 if ( m_text )
2204 m_text->SetInsertionPoint(pos);
2205 }
2206
2207 void wxComboCtrlBase::SetInsertionPointEnd()
2208 {
2209 if ( m_text )
2210 m_text->SetInsertionPointEnd();
2211 }
2212
2213 long wxComboCtrlBase::GetInsertionPoint() const
2214 {
2215 if ( m_text )
2216 return m_text->GetInsertionPoint();
2217
2218 return 0;
2219 }
2220
2221 long wxComboCtrlBase::GetLastPosition() const
2222 {
2223 if ( m_text )
2224 return m_text->GetLastPosition();
2225
2226 return 0;
2227 }
2228
2229 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2230 {
2231 if ( m_text )
2232 m_text->Replace(from, to, value);
2233 }
2234
2235 void wxComboCtrlBase::Remove(long from, long to)
2236 {
2237 if ( m_text )
2238 m_text->Remove(from, to);
2239 }
2240
2241 void wxComboCtrlBase::SetSelection(long from, long to)
2242 {
2243 if ( m_text )
2244 m_text->SetSelection(from, to);
2245 }
2246
2247 void wxComboCtrlBase::Undo()
2248 {
2249 if ( m_text )
2250 m_text->Undo();
2251 }
2252
2253 #endif // wxUSE_COMBOCTRL