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