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