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