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