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