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