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