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