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