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