]> git.saurik.com Git - wxWidgets.git/blob - src/common/combocmn.cpp
1432300dc62101d0a3d4ae75649a1ebdf3361a22
[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 m_hasTcBgCol = false;
992 }
993
994 bool wxComboCtrlBase::Create(wxWindow *parent,
995 wxWindowID id,
996 const wxString& value,
997 const wxPoint& pos,
998 const wxSize& size,
999 long style,
1000 const wxValidator& validator,
1001 const wxString& name)
1002 {
1003 if ( !wxControl::Create(parent,
1004 id,
1005 pos,
1006 size,
1007 style | wxWANTS_CHARS,
1008 validator,
1009 name) )
1010 return false;
1011
1012 m_valueString = value;
1013
1014 // Get colours
1015 OnThemeChange();
1016 m_marginLeft = GetNativeTextIndent();
1017
1018 m_iFlags |= wxCC_IFLAG_CREATED;
1019
1020 // If x and y indicate valid size, wxSizeEvent won't be
1021 // emitted automatically, so we need to add artifical one.
1022 if ( size.x > 0 && size.y > 0 )
1023 {
1024 wxSizeEvent evt(size,GetId());
1025 GetEventHandler()->AddPendingEvent(evt);
1026 }
1027
1028 return true;
1029 }
1030
1031 void wxComboCtrlBase::InstallInputHandlers()
1032 {
1033 if ( m_text )
1034 {
1035 m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
1036 m_text->PushEventHandler(m_textEvtHandler);
1037 }
1038 }
1039
1040 void
1041 wxComboCtrlBase::CreateTextCtrl(int style)
1042 {
1043 if ( !(m_windowStyle & wxCB_READONLY) )
1044 {
1045 if ( m_text )
1046 m_text->Destroy();
1047
1048 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1049 // not used by the wxPropertyGrid and therefore the tab is processed by
1050 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1051 // navigation event is then sent to the wrong window.
1052 style |= wxTE_PROCESS_TAB | m_textCtrlStyle;
1053
1054 if ( HasFlag(wxTE_PROCESS_ENTER) )
1055 style |= wxTE_PROCESS_ENTER;
1056
1057 // Ignore EVT_TEXT generated by the constructor (but only
1058 // if the event redirector already exists)
1059 // NB: This must be " = 1" instead of "++";
1060 if ( m_textEvtHandler )
1061 m_ignoreEvtText = 1;
1062 else
1063 m_ignoreEvtText = 0;
1064
1065 m_text = new wxComboCtrlTextCtrl();
1066 m_text->Create(this, wxID_ANY, m_valueString,
1067 wxDefaultPosition, wxSize(10,-1),
1068 style);
1069 m_text->SetHint(m_hintText);
1070 }
1071 }
1072
1073 void wxComboCtrlBase::OnThemeChange()
1074 {
1075 // Because wxComboCtrl has transparent parts on most platforms, we
1076 // don't want to touch the actual background colour. Instead, we just
1077 // usually re-obtain m_tcBgCol here.
1078
1079 #if defined(__WXMSW__) || defined(__WXGTK__)
1080 wxVisualAttributes vattrs = wxComboBox::GetClassDefaultAttributes();
1081 #else
1082 wxVisualAttributes vattrs;
1083 vattrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1084 vattrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1085 #endif
1086
1087 if ( !m_hasTcBgCol )
1088 m_tcBgCol = vattrs.colBg;
1089
1090 #ifndef __WXMAC__
1091 // Only change the colours if application has not specified
1092 // custom ones.
1093 if ( !m_hasFgCol )
1094 {
1095 SetOwnForegroundColour(vattrs.colFg);
1096 }
1097 if ( !HasTransparentBackground() )
1098 {
1099 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1100 }
1101 #endif // !__WXMAC__
1102 }
1103
1104 wxComboCtrlBase::~wxComboCtrlBase()
1105 {
1106 if ( HasCapture() )
1107 ReleaseMouse();
1108
1109 #if INSTALL_TOPLEV_HANDLER
1110 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
1111 m_toplevEvtHandler = NULL;
1112 #endif
1113
1114 DestroyPopup();
1115
1116 if ( m_text )
1117 m_text->RemoveEventHandler(m_textEvtHandler);
1118
1119 delete m_textEvtHandler;
1120 }
1121
1122
1123 // ----------------------------------------------------------------------------
1124 // geometry stuff
1125 // ----------------------------------------------------------------------------
1126
1127 // Recalculates button and textctrl areas
1128 void wxComboCtrlBase::CalculateAreas( int btnWidth )
1129 {
1130 wxSize sz = GetClientSize();
1131 int customBorder = m_widthCustomBorder;
1132 int btnBorder; // border for button only
1133
1134 // check if button should really be outside the border: we'll do it it if
1135 // its platform default or bitmap+pushbutton background is used, but not if
1136 // there is vertical size adjustment or horizontal spacing.
1137 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
1138 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
1139 m_btnSpacingX == 0 &&
1140 m_btnHei <= 0 )
1141 {
1142 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
1143 btnBorder = 0;
1144 }
1145 else if ( (m_iFlags & wxCC_BUTTON_COVERS_BORDER) &&
1146 m_btnSpacingX == 0 && !m_bmpNormal.Ok() )
1147 {
1148 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1149 btnBorder = 0;
1150 }
1151 else
1152 {
1153 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1154 btnBorder = customBorder;
1155 }
1156
1157 // Defaul indentation
1158 if ( m_marginLeft < 0 )
1159 m_marginLeft = GetNativeTextIndent();
1160
1161 int butWidth = btnWidth;
1162
1163 if ( butWidth <= 0 )
1164 butWidth = m_btnWidDefault;
1165 else
1166 m_btnWidDefault = butWidth;
1167
1168 if ( butWidth <= 0 )
1169 return;
1170
1171 int butHeight = sz.y - btnBorder*2;
1172
1173 // Adjust button width
1174 if ( m_btnWid > 0 )
1175 butWidth = m_btnWid;
1176 else
1177 {
1178 // Adjust button width to match aspect ratio
1179 // (but only if control is smaller than best size).
1180 int bestHeight = GetBestSize().y;
1181 int height = GetSize().y;
1182
1183 if ( height < bestHeight )
1184 {
1185 // Make very small buttons square, as it makes
1186 // them accommodate arrow image better and still
1187 // looks decent.
1188 if ( height > 18 )
1189 butWidth = (height*butWidth)/bestHeight;
1190 else
1191 butWidth = butHeight;
1192 }
1193 }
1194
1195 // Adjust button height
1196 if ( m_btnHei > 0 )
1197 butHeight = m_btnHei;
1198
1199 // Use size of normal bitmap if...
1200 // It is larger
1201 // OR
1202 // button width is set to default and blank button bg is not drawn
1203 if ( m_bmpNormal.Ok() )
1204 {
1205 int bmpReqWidth = m_bmpNormal.GetWidth();
1206 int bmpReqHeight = m_bmpNormal.GetHeight();
1207
1208 // If drawing blank button background, we need to add some margin.
1209 if ( m_blankButtonBg )
1210 {
1211 bmpReqWidth += BMP_BUTTON_MARGIN*2;
1212 bmpReqHeight += BMP_BUTTON_MARGIN*2;
1213 }
1214
1215 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
1216 butWidth = bmpReqWidth;
1217 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
1218 butHeight = bmpReqHeight;
1219
1220 // Need to fix height?
1221 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
1222 {
1223 int newY = butHeight+(customBorder*2);
1224 SetClientSize(wxDefaultCoord,newY);
1225 if ( m_bmpNormal.Ok() || m_btnArea.width != butWidth || m_btnArea.height != butHeight )
1226 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1227 else
1228 m_iFlags &= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1229
1230 sz.y = newY;
1231 }
1232 }
1233
1234 int butAreaWid = butWidth + (m_btnSpacingX*2);
1235
1236 m_btnSize.x = butWidth;
1237 m_btnSize.y = butHeight;
1238
1239 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
1240 m_btnArea.y = btnBorder + FOCUS_RING;
1241 m_btnArea.width = butAreaWid;
1242 m_btnArea.height = sz.y - ((btnBorder+FOCUS_RING)*2);
1243
1244 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder + FOCUS_RING;
1245 m_tcArea.y = customBorder + FOCUS_RING;
1246 m_tcArea.width = sz.x - butAreaWid - (customBorder*2) - (FOCUS_RING*2);
1247 m_tcArea.height = sz.y - ((customBorder+FOCUS_RING)*2);
1248
1249 /*
1250 if ( m_text )
1251 {
1252 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1253 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1254 }
1255 */
1256 }
1257
1258 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
1259 {
1260 if ( !m_text )
1261 return;
1262
1263 wxSize sz = GetClientSize();
1264
1265 int customBorder = m_widthCustomBorder;
1266 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
1267 {
1268 int x;
1269
1270 if ( !m_widthCustomPaint )
1271 {
1272 // No special custom paint area - we can use 0 left margin
1273 // with wxTextCtrl.
1274 if ( m_text->SetMargins(0) )
1275 textCtrlXAdjust = 0;
1276 x = m_tcArea.x + m_marginLeft + textCtrlXAdjust;
1277 }
1278 else
1279 {
1280 // There is special custom paint area - it is better to
1281 // use some margin with the wxTextCtrl.
1282 m_text->SetMargins(m_marginLeft);
1283 x = m_tcArea.x + m_widthCustomPaint +
1284 m_marginLeft + textCtrlXAdjust;
1285 }
1286
1287 // Centre textctrl vertically, if needed
1288 #if !TEXTCTRL_TEXT_CENTERED
1289 int tcSizeY = m_text->GetBestSize().y;
1290 int diff0 = sz.y - tcSizeY;
1291 int y = textCtrlYAdjust + (diff0/2);
1292 #else
1293 wxUnusedVar(textCtrlYAdjust);
1294 int y = 0;
1295 #endif
1296
1297 if ( y < customBorder )
1298 y = customBorder;
1299
1300 m_text->SetSize(x,
1301 y,
1302 m_tcArea.width - m_tcArea.x - x,
1303 -1 );
1304
1305 // Make sure textctrl doesn't exceed the bottom custom border
1306 wxSize tsz = m_text->GetSize();
1307 int diff1 = (y + tsz.y) - (sz.y - customBorder);
1308 if ( diff1 >= 0 )
1309 {
1310 tsz.y = tsz.y - diff1 - 1;
1311 m_text->SetSize(tsz);
1312 }
1313 }
1314 else
1315 {
1316 // If it has border, have textctrl fill the entire text field.
1317 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1318 m_tcArea.y,
1319 m_tcArea.width - m_widthCustomPaint,
1320 m_tcArea.height );
1321 }
1322 }
1323
1324 wxSize wxComboCtrlBase::DoGetBestSize() const
1325 {
1326 wxSize sizeText(150,0);
1327
1328 if ( m_text )
1329 sizeText = m_text->GetBestSize();
1330
1331 // TODO: Better method to calculate close-to-native control height.
1332
1333 int fhei;
1334 if ( m_font.Ok() )
1335 fhei = (m_font.GetPointSize()*2) + 5;
1336 else if ( wxNORMAL_FONT->Ok() )
1337 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1338 else
1339 fhei = sizeText.y + 4;
1340
1341 // Need to force height to accomodate bitmap?
1342 int btnSizeY = m_btnSize.y;
1343 if ( m_bmpNormal.Ok() && fhei < btnSizeY )
1344 fhei = btnSizeY;
1345
1346 // Control height doesn't depend on border
1347 /*
1348 // Add border
1349 int border = m_windowStyle & wxBORDER_MASK;
1350 if ( border == wxSIMPLE_BORDER )
1351 fhei += 2;
1352 else if ( border == wxNO_BORDER )
1353 fhei += (m_widthCustomBorder*2);
1354 else
1355 // Sunken etc.
1356 fhei += 4;
1357 */
1358
1359 // Final adjustments
1360 #ifdef __WXGTK__
1361 fhei += 1;
1362 #endif
1363
1364 #ifdef __WXMAC__
1365 // these are the numbers from the HIG:
1366 switch ( m_windowVariant )
1367 {
1368 case wxWINDOW_VARIANT_NORMAL:
1369 default :
1370 fhei = 22;
1371 break;
1372 case wxWINDOW_VARIANT_SMALL:
1373 fhei = 19;
1374 break;
1375 case wxWINDOW_VARIANT_MINI:
1376 fhei = 15;
1377 break;
1378 }
1379 #endif
1380
1381 fhei += 2 * FOCUS_RING;
1382 int width = sizeText.x + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH;
1383
1384 wxSize ret(width, fhei);
1385 CacheBestSize(ret);
1386 return ret;
1387 }
1388
1389 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1390 {
1391 if ( !IsCreated() )
1392 return;
1393
1394 // defined by actual wxComboCtrls
1395 OnResize();
1396
1397 event.Skip();
1398 }
1399
1400 // ----------------------------------------------------------------------------
1401 // standard operations
1402 // ----------------------------------------------------------------------------
1403
1404 bool wxComboCtrlBase::Enable(bool enable)
1405 {
1406 if ( !wxControl::Enable(enable) )
1407 return false;
1408
1409 if ( m_btn )
1410 m_btn->Enable(enable);
1411 if ( m_text )
1412 m_text->Enable(enable);
1413
1414 Refresh();
1415
1416 return true;
1417 }
1418
1419 bool wxComboCtrlBase::Show(bool show)
1420 {
1421 if ( !wxControl::Show(show) )
1422 return false;
1423
1424 if (m_btn)
1425 m_btn->Show(show);
1426
1427 if (m_text)
1428 m_text->Show(show);
1429
1430 return true;
1431 }
1432
1433 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1434 {
1435 if ( !wxControl::SetFont(font) )
1436 return false;
1437
1438 if ( m_text )
1439 {
1440 // Without hiding the wxTextCtrl there would be some
1441 // visible 'flicker' (at least on Windows XP).
1442 m_text->Hide();
1443 m_text->SetFont(font);
1444 OnResize();
1445 m_text->Show();
1446 }
1447
1448 return true;
1449 }
1450
1451 #if wxUSE_TOOLTIPS
1452 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1453 {
1454 wxControl::DoSetToolTip(tooltip);
1455
1456 // Set tool tip for button and text box
1457 if ( tooltip )
1458 {
1459 const wxString &tip = tooltip->GetTip();
1460 if ( m_text ) m_text->SetToolTip(tip);
1461 if ( m_btn ) m_btn->SetToolTip(tip);
1462 }
1463 else
1464 {
1465 if ( m_text ) m_text->SetToolTip( NULL );
1466 if ( m_btn ) m_btn->SetToolTip( NULL );
1467 }
1468 }
1469 #endif // wxUSE_TOOLTIPS
1470
1471 bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour)
1472 {
1473 if ( wxControl::SetForegroundColour(colour) )
1474 {
1475 if ( m_text )
1476 m_text->SetForegroundColour(colour);
1477 return true;
1478 }
1479 return false;
1480 }
1481
1482 bool wxComboCtrlBase::SetBackgroundColour(const wxColour& colour)
1483 {
1484 if ( m_text )
1485 m_text->SetBackgroundColour(colour);
1486 m_tcBgCol = colour;
1487 m_hasTcBgCol = true;
1488 return true;
1489 }
1490
1491 wxColour wxComboCtrlBase::GetBackgroundColour() const
1492 {
1493 if ( m_text )
1494 return m_text->GetBackgroundColour();
1495 return m_tcBgCol;
1496 }
1497
1498 // ----------------------------------------------------------------------------
1499 // painting
1500 // ----------------------------------------------------------------------------
1501
1502 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1503 // prepare combo box background on area in a way typical on platform
1504 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1505 {
1506 wxSize sz = GetClientSize();
1507 bool isEnabled;
1508 bool doDrawFocusRect; // also selected
1509
1510 // For smaller size control (and for disabled background) use less spacing
1511 int focusSpacingX;
1512 int focusSpacingY;
1513
1514 if ( !(flags & wxCONTROL_ISSUBMENU) )
1515 {
1516 // Drawing control
1517 isEnabled = IsEnabled();
1518 doDrawFocusRect = ShouldDrawFocus() && !(m_iFlags & wxCC_FULL_BUTTON);
1519
1520 // Windows-style: for smaller size control (and for disabled background) use less spacing
1521 focusSpacingX = isEnabled ? 2 : 1;
1522 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1523 }
1524 else
1525 {
1526 // Drawing a list item
1527 isEnabled = true; // they are never disabled
1528 doDrawFocusRect = (flags & wxCONTROL_SELECTED) != 0;
1529
1530 focusSpacingX = 0;
1531 focusSpacingY = 0;
1532 }
1533
1534 // Set the background sub-rectangle for selection, disabled etc
1535 wxRect selRect(rect);
1536 selRect.y += focusSpacingY;
1537 selRect.height -= (focusSpacingY*2);
1538
1539 int wcp = 0;
1540
1541 if ( !(flags & wxCONTROL_ISSUBMENU) )
1542 wcp += m_widthCustomPaint;
1543
1544 selRect.x += wcp + focusSpacingX;
1545 selRect.width -= wcp + (focusSpacingX*2);
1546
1547 wxColour bgCol;
1548 wxColour fgCol;
1549
1550 bool doDrawSelRect = true;
1551
1552 // Determine foreground colour
1553 if ( isEnabled )
1554 {
1555 if ( doDrawFocusRect )
1556 {
1557 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1558 }
1559 else if ( m_hasFgCol )
1560 {
1561 // Honour the custom foreground colour
1562 fgCol = GetForegroundColour();
1563 }
1564 else
1565 {
1566 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1567 }
1568 }
1569 else
1570 {
1571 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
1572 }
1573
1574 // Determine background colour
1575 if ( isEnabled )
1576 {
1577 if ( doDrawFocusRect )
1578 {
1579 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1580 }
1581 else if ( m_hasTcBgCol )
1582 {
1583 // Honour the custom background colour
1584 bgCol = m_tcBgCol;
1585 }
1586 else
1587 {
1588 #ifndef __WXMAC__ // see note in OnThemeChange
1589 doDrawSelRect = false;
1590 bgCol = GetBackgroundColour();
1591 #else
1592 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1593 #endif
1594 }
1595 }
1596 else
1597 {
1598 #ifndef __WXMAC__ // see note in OnThemeChange
1599 bgCol = GetBackgroundColour();
1600 #else
1601 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1602 #endif
1603 }
1604
1605 dc.SetTextForeground( fgCol );
1606 dc.SetBrush( bgCol );
1607 if ( doDrawSelRect )
1608 {
1609 dc.SetPen( bgCol );
1610 dc.DrawRectangle( selRect );
1611 }
1612
1613 // Don't clip exactly to the selection rectangle so we can draw
1614 // to the non-selected area in front of it.
1615 wxRect clipRect(rect.x,rect.y,
1616 (selRect.x+selRect.width)-rect.x,rect.height);
1617 dc.SetClippingRegion(clipRect);
1618 }
1619 #else
1620 // Save the library size a bit for platforms that re-implement this.
1621 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1622 {
1623 }
1624 #endif
1625
1626 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags )
1627 {
1628 int drawState = m_btnState;
1629
1630 if ( (m_iFlags & wxCC_BUTTON_STAYS_DOWN) &&
1631 GetPopupWindowState() >= Animating )
1632 drawState |= wxCONTROL_PRESSED;
1633
1634 wxRect drawRect(rect.x+m_btnSpacingX,
1635 rect.y+((rect.height-m_btnSize.y)/2),
1636 m_btnSize.x,
1637 m_btnSize.y);
1638
1639 // Make sure area is not larger than the control
1640 if ( drawRect.y < rect.y )
1641 drawRect.y = rect.y;
1642 if ( drawRect.height > rect.height )
1643 drawRect.height = rect.height;
1644
1645 bool enabled = IsEnabled();
1646
1647 if ( !enabled )
1648 drawState |= wxCONTROL_DISABLED;
1649
1650 // Need to clear button background even if m_btn is present
1651 // and also when using custom bitmap for the button
1652 if ( (flags & Button_PaintBackground) &&
1653 (!HasTransparentBackground() ||
1654 !(m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE)) )
1655 {
1656 wxColour bgCol;
1657
1658 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1659 bgCol = GetParent()->GetBackgroundColour();
1660 else
1661 bgCol = GetBackgroundColour();
1662
1663 dc.SetBrush(bgCol);
1664 dc.SetPen(bgCol);
1665 dc.DrawRectangle(rect);
1666 }
1667
1668 if ( !m_bmpNormal.Ok() )
1669 {
1670 if ( flags & Button_BitmapOnly )
1671 return;
1672
1673 // Draw standard button
1674 wxRendererNative::Get().DrawComboBoxDropButton(this,
1675 dc,
1676 drawRect,
1677 drawState);
1678 }
1679 else
1680 {
1681 // Draw bitmap
1682
1683 wxBitmap* pBmp;
1684
1685 if ( !enabled )
1686 pBmp = &m_bmpDisabled;
1687 else if ( m_btnState & wxCONTROL_PRESSED )
1688 pBmp = &m_bmpPressed;
1689 else if ( m_btnState & wxCONTROL_CURRENT )
1690 pBmp = &m_bmpHover;
1691 else
1692 pBmp = &m_bmpNormal;
1693
1694 if ( m_blankButtonBg )
1695 {
1696 if ( !(flags & Button_BitmapOnly) )
1697 {
1698 wxRendererNative::Get().DrawPushButton(this,
1699 dc,
1700 drawRect,
1701 drawState);
1702 }
1703 }
1704
1705 // Draw bitmap centered in drawRect
1706 dc.DrawBitmap(*pBmp,
1707 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1708 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1709 true);
1710 }
1711 }
1712
1713 void wxComboCtrlBase::RecalcAndRefresh()
1714 {
1715 if ( IsCreated() )
1716 {
1717 wxSizeEvent evt(GetSize(),GetId());
1718 GetEventHandler()->ProcessEvent(evt);
1719 Refresh();
1720 }
1721 }
1722
1723 // ----------------------------------------------------------------------------
1724 // miscellaneous event handlers
1725 // ----------------------------------------------------------------------------
1726
1727 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1728 {
1729 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1730 {
1731 if ( m_ignoreEvtText > 0 )
1732 {
1733 m_ignoreEvtText--;
1734 return;
1735 }
1736 }
1737
1738 // Change event id, object and string before relaying it forward
1739 event.SetId(GetId());
1740 wxString s = event.GetString();
1741 event.SetEventObject(this);
1742 event.SetString(s);
1743 event.Skip();
1744 }
1745
1746 // call if cursor is on button area or mouse is captured for the button
1747 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1748 int flags )
1749 {
1750 int type = event.GetEventType();
1751
1752 if ( type == wxEVT_MOTION )
1753 {
1754 if ( (flags & wxCC_MF_ON_BUTTON) &&
1755 IsPopupWindowState(Hidden) )
1756 {
1757 if ( !(m_btnState & wxCONTROL_CURRENT) )
1758 {
1759 // Mouse hover begins
1760 m_btnState |= wxCONTROL_CURRENT;
1761 if ( HasCapture() ) // Retain pressed state.
1762 m_btnState |= wxCONTROL_PRESSED;
1763 Refresh();
1764 }
1765 }
1766 else if ( (m_btnState & wxCONTROL_CURRENT) )
1767 {
1768 // Mouse hover ends
1769 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1770 Refresh();
1771 }
1772 }
1773 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1774 {
1775 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1776 {
1777 m_btnState |= wxCONTROL_PRESSED;
1778 Refresh();
1779
1780 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1781 OnButtonClick();
1782 else
1783 // If showing popup now, do not capture mouse or there will be interference
1784 CaptureMouse();
1785 }
1786 }
1787 else if ( type == wxEVT_LEFT_UP )
1788 {
1789
1790 // Only accept event if mouse was left-press was previously accepted
1791 if ( HasCapture() )
1792 ReleaseMouse();
1793
1794 if ( m_btnState & wxCONTROL_PRESSED )
1795 {
1796 // If mouse was inside, fire the click event.
1797 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1798 {
1799 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1800 OnButtonClick();
1801 }
1802
1803 m_btnState &= ~(wxCONTROL_PRESSED);
1804 Refresh();
1805 }
1806 }
1807 else if ( type == wxEVT_LEAVE_WINDOW )
1808 {
1809 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1810 {
1811 m_btnState &= ~(wxCONTROL_CURRENT);
1812
1813 // Mouse hover ends
1814 if ( IsPopupWindowState(Hidden) )
1815 {
1816 m_btnState &= ~(wxCONTROL_PRESSED);
1817 Refresh();
1818 }
1819 }
1820 }
1821 else
1822 return false;
1823
1824 // Never have 'hot' state when popup is being shown
1825 // (this is mostly needed because of the animation).
1826 if ( !IsPopupWindowState(Hidden) )
1827 m_btnState &= ~wxCONTROL_CURRENT;
1828
1829 return true;
1830 }
1831
1832 // returns true if event was consumed or filtered
1833 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1834 int WXUNUSED(flags) )
1835 {
1836 wxLongLong t = ::wxGetLocalTimeMillis();
1837 int evtType = event.GetEventType();
1838
1839 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1840 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1841 {
1842 if ( IsPopupWindowState(Visible) &&
1843 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1844 {
1845 HidePopup(true);
1846 return true;
1847 }
1848 }
1849 #endif
1850
1851 // Filter out clicks on button immediately after popup dismiss
1852 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1853 {
1854 event.SetEventType(0);
1855 return true;
1856 }
1857
1858 return false;
1859 }
1860
1861 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1862 {
1863 int evtType = event.GetEventType();
1864
1865 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1866 (m_windowStyle & wxCB_READONLY) )
1867 {
1868 if ( GetPopupWindowState() >= Animating )
1869 {
1870 #if USES_WXPOPUPWINDOW
1871 // Click here always hides the popup.
1872 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1873 HidePopup(true);
1874 #endif
1875 }
1876 else
1877 {
1878 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1879 {
1880 // In read-only mode, clicking the text is the
1881 // same as clicking the button.
1882 OnButtonClick();
1883 }
1884 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1885 {
1886 //if ( m_popupInterface->CycleValue() )
1887 // Refresh();
1888 if ( m_popupInterface )
1889 m_popupInterface->OnComboDoubleClick();
1890 }
1891 }
1892 }
1893 else if ( evtType == wxEVT_MOUSEWHEEL )
1894 {
1895 if ( IsPopupShown() )
1896 {
1897 // relay (some) mouse events to the popup
1898 m_popup->GetEventHandler()->ProcessEvent(event);
1899 }
1900 else if ( event.GetWheelAxis() == 0 &&
1901 event.GetWheelRotation() != 0 &&
1902 event.GetModifiers() == 0 )
1903 {
1904 // Translate mousewheel actions into key up/down. This is
1905 // the simplest way of getting native behaviour: scrolling the
1906 // wheel moves selection up/down by one item.
1907 wxKeyEvent kevent(wxEVT_KEY_DOWN);
1908 kevent.m_keyCode = event.GetWheelRotation() > 0
1909 ? WXK_UP
1910 : WXK_DOWN;
1911 GetEventHandler()->ProcessEvent(kevent);
1912 }
1913 else
1914 {
1915 event.Skip();
1916 }
1917 }
1918 else if ( evtType )
1919 {
1920 event.Skip();
1921 }
1922 }
1923
1924 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1925 {
1926 if ( IsPopupShown() )
1927 {
1928 // pass it to the popped up control
1929 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
1930 }
1931 else // no popup
1932 {
1933 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1934
1935 if ( mainCtrl->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
1936 {
1937 if ( mainCtrl->HandleAsNavigationKey(event) )
1938 return;
1939 }
1940
1941 if ( IsKeyPopupToggle(event) )
1942 {
1943 OnButtonClick();
1944 return;
1945 }
1946
1947 int comboStyle = GetWindowStyle();
1948 wxComboPopup* popupInterface = GetPopupControl();
1949
1950 if ( !popupInterface )
1951 {
1952 event.Skip();
1953 return;
1954 }
1955
1956 int keycode = event.GetKeyCode();
1957
1958 if ( (comboStyle & wxCB_READONLY) ||
1959 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
1960 {
1961 popupInterface->OnComboKeyEvent(event);
1962 }
1963 else
1964 event.Skip();
1965 }
1966 }
1967
1968 void wxComboCtrlBase::OnCharEvent(wxKeyEvent& event)
1969 {
1970 if ( IsPopupShown() )
1971 {
1972 // pass it to the popped up control
1973 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
1974 }
1975 else // no popup
1976 {
1977 wxComboPopup* popupInterface = GetPopupControl();
1978 if ( popupInterface )
1979 {
1980 popupInterface->OnComboCharEvent(event);
1981 }
1982 else
1983 {
1984 event.Skip();
1985 }
1986 }
1987 }
1988
1989 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
1990 {
1991 if ( event.GetEventType() == wxEVT_SET_FOCUS )
1992 {
1993 wxWindow* tc = GetTextCtrl();
1994 if ( tc && tc != DoFindFocus() )
1995 {
1996 tc->SetFocus();
1997 }
1998 }
1999
2000 Refresh();
2001 }
2002
2003 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
2004 {
2005 if ( m_resetFocus )
2006 {
2007 m_resetFocus = false;
2008 wxWindow* tc = GetTextCtrl();
2009 if ( tc )
2010 tc->SetFocus();
2011 }
2012 }
2013
2014 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
2015 {
2016 OnThemeChange();
2017 // left margin may also have changed
2018 if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
2019 m_marginLeft = GetNativeTextIndent();
2020 RecalcAndRefresh();
2021 }
2022
2023 // ----------------------------------------------------------------------------
2024 // popup handling
2025 // ----------------------------------------------------------------------------
2026
2027 // Create popup window and the child control
2028 void wxComboCtrlBase::CreatePopup()
2029 {
2030 wxComboPopup* popupInterface = m_popupInterface;
2031 wxWindow* popup;
2032
2033 if ( !m_winPopup )
2034 {
2035 #ifdef wxComboPopupWindowBase2
2036 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
2037 {
2038 #if !USES_GENERICTLW
2039 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
2040 #else
2041 int tlwFlags = wxNO_BORDER;
2042 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2043 tlwFlags |= wxFRAME_NO_TASKBAR;
2044 #endif
2045
2046 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2047 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY,
2048 wxPoint(-21,-21), wxSize(20, 20),
2049 tlwFlags );
2050 #else
2051 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
2052 wxPoint(-21,-21), wxSize(20, 20),
2053 tlwFlags );
2054 #endif
2055 #endif
2056 m_popupWinType = SECONDARY_POPUP_TYPE;
2057 }
2058 else
2059 #endif // wxComboPopupWindowBase2
2060 {
2061 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
2062 m_popupWinType = PRIMARY_POPUP_TYPE;
2063 }
2064 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
2065 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
2066 }
2067
2068 popupInterface->Create(m_winPopup);
2069 m_popup = popup = popupInterface->GetControl();
2070
2071 m_popupEvtHandler = new wxComboPopupEvtHandler(this);
2072 popup->PushEventHandler( m_popupEvtHandler );
2073
2074 // This may be helpful on some platforms
2075 // (eg. it bypasses a wxGTK popupwindow bug where
2076 // window is not initially hidden when it should be)
2077 m_winPopup->Hide();
2078
2079 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
2080 }
2081
2082 // Destroy popup window and the child control
2083 void wxComboCtrlBase::DestroyPopup()
2084 {
2085 HidePopup(true);
2086
2087 if ( m_popup )
2088 m_popup->RemoveEventHandler(m_popupEvtHandler);
2089
2090 wxDELETE(m_popupEvtHandler);
2091
2092 wxDELETE(m_popupInterface);
2093
2094 if ( m_winPopup )
2095 {
2096 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
2097 wxDELETE(m_popupWinEvtHandler);
2098 m_winPopup->Destroy();
2099 m_winPopup = NULL;
2100 }
2101
2102 m_popup = NULL;
2103 }
2104
2105 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
2106 {
2107 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
2108
2109 DestroyPopup();
2110
2111 iface->InitBase(this);
2112 iface->Init();
2113
2114 m_popupInterface = iface;
2115
2116 if ( !iface->LazyCreate() )
2117 {
2118 CreatePopup();
2119 }
2120 else
2121 {
2122 m_popup = NULL;
2123 }
2124
2125 // This must be done after creation
2126 if ( !m_valueString.empty() )
2127 {
2128 iface->SetStringValue(m_valueString);
2129 //Refresh();
2130 }
2131 }
2132
2133 // Ensures there is atleast the default popup
2134 void wxComboCtrlBase::EnsurePopupControl()
2135 {
2136 if ( !m_popupInterface )
2137 SetPopupControl(NULL);
2138 }
2139
2140 void wxComboCtrlBase::OnButtonClick()
2141 {
2142 // Derived classes can override this method for totally custom
2143 // popup action
2144 switch ( GetPopupWindowState() )
2145 {
2146 case Hidden:
2147 {
2148 Popup();
2149 break;
2150 }
2151
2152 case Animating:
2153 case Visible:
2154 {
2155 HidePopup(true);
2156 break;
2157 }
2158 }
2159 }
2160
2161 void wxComboCtrlBase::Popup()
2162 {
2163 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
2164 event.SetEventObject(this);
2165 HandleWindowEvent(event);
2166
2167 ShowPopup();
2168 }
2169
2170 void wxComboCtrlBase::ShowPopup()
2171 {
2172 EnsurePopupControl();
2173 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
2174
2175 if ( IsPopupWindowState(Animating) )
2176 return;
2177
2178 SetFocus();
2179
2180 // Space above and below
2181 int screenHeight;
2182 wxPoint scrPos;
2183 int spaceAbove;
2184 int spaceBelow;
2185 int maxHeightPopup;
2186 wxSize ctrlSz = GetSize();
2187
2188 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
2189 scrPos = GetParent()->ClientToScreen(GetPosition());
2190
2191 spaceAbove = scrPos.y;
2192 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
2193
2194 maxHeightPopup = spaceBelow;
2195 if ( spaceAbove > spaceBelow )
2196 maxHeightPopup = spaceAbove;
2197
2198 // Width
2199 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
2200
2201 if ( widthPopup < m_widthMinPopup )
2202 widthPopup = m_widthMinPopup;
2203
2204 wxWindow* winPopup = m_winPopup;
2205 wxWindow* popup;
2206
2207 // Need to disable tab traversal of parent
2208 //
2209 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2210 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2211 // that if transient popup is open, then tab traversal is to be ignored.
2212 // However, I think this code would still be needed for cases where
2213 // transient popup doesn't work yet (wxWinCE?).
2214 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
2215 wxWindow* parent = mainCtrl->GetParent();
2216 int parentFlags = parent->GetWindowStyle();
2217 if ( parentFlags & wxTAB_TRAVERSAL )
2218 {
2219 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
2220 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
2221 }
2222
2223 if ( !winPopup )
2224 {
2225 CreatePopup();
2226 winPopup = m_winPopup;
2227 popup = m_popup;
2228 }
2229 else
2230 {
2231 popup = m_popup;
2232 }
2233
2234 winPopup->Enable();
2235
2236 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
2237
2238 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
2239 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
2240 maxHeightPopup);
2241
2242 popup->SetSize(adjustedSize);
2243 popup->Move(0,0);
2244 m_popupInterface->OnPopup();
2245
2246 //
2247 // Reposition and resize popup window
2248 //
2249
2250 wxSize szp = popup->GetSize();
2251
2252 int popupX;
2253 int popupY = scrPos.y + ctrlSz.y;
2254
2255 // Default anchor is wxLEFT
2256 int anchorSide = m_anchorSide;
2257 if ( !anchorSide )
2258 anchorSide = wxLEFT;
2259
2260 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
2261 int leftX = scrPos.x - m_extLeft;
2262
2263 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
2264 leftX -= ctrlSz.x;
2265
2266 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
2267
2268 // If there is not enough horizontal space, anchor on the other side.
2269 // If there is no space even then, place the popup at x 0.
2270 if ( anchorSide == wxRIGHT )
2271 {
2272 if ( rightX < 0 )
2273 {
2274 if ( (leftX+szp.x) < screenWidth )
2275 anchorSide = wxLEFT;
2276 else
2277 anchorSide = 0;
2278 }
2279 }
2280 else
2281 {
2282 if ( (leftX+szp.x) >= screenWidth )
2283 {
2284 if ( rightX >= 0 )
2285 anchorSide = wxRIGHT;
2286 else
2287 anchorSide = 0;
2288 }
2289 }
2290
2291 // Select x coordinate according to the anchor side
2292 if ( anchorSide == wxRIGHT )
2293 popupX = rightX;
2294 else if ( anchorSide == wxLEFT )
2295 popupX = leftX;
2296 else
2297 popupX = 0;
2298
2299 int showFlags = CanDeferShow;
2300
2301 if ( spaceBelow < szp.y )
2302 {
2303 popupY = scrPos.y - szp.y;
2304 showFlags |= ShowAbove;
2305 }
2306
2307 #if INSTALL_TOPLEV_HANDLER
2308 // Put top level window event handler into place
2309 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
2310 {
2311 if ( !m_toplevEvtHandler )
2312 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
2313
2314 wxWindow* toplev = ::wxGetTopLevelParent( this );
2315 wxASSERT( toplev );
2316 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
2317 toplev->PushEventHandler( m_toplevEvtHandler );
2318 }
2319 #endif
2320
2321 // Set string selection (must be this way instead of SetStringSelection)
2322 if ( m_text )
2323 {
2324 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2325 m_text->SelectAll();
2326
2327 m_popupInterface->SetStringValue( m_text->GetValue() );
2328 }
2329 else
2330 {
2331 // This is neede since focus/selection indication may change when popup is shown
2332 Refresh();
2333 }
2334
2335 // This must be after SetStringValue
2336 m_popupWinState = Animating;
2337
2338 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
2339
2340 m_popup = popup;
2341 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
2342 AnimateShow( popupWinRect, showFlags ) )
2343 {
2344 DoShowPopup( popupWinRect, showFlags );
2345 }
2346 }
2347
2348 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
2349 {
2350 return true;
2351 }
2352
2353 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
2354 {
2355 wxWindow* winPopup = m_winPopup;
2356
2357 if ( IsPopupWindowState(Animating) )
2358 {
2359 // Make sure the popup window is shown in the right position.
2360 // Should not matter even if animation already did this.
2361
2362 // Some platforms (GTK) may like SetSize and Move to be separate
2363 // (though the bug was probably fixed).
2364 winPopup->SetSize( rect );
2365
2366 #if USES_WXPOPUPTRANSIENTWINDOW
2367 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2368 ((wxPopupTransientWindow*)winPopup)->Popup(m_popup);
2369 else
2370 #endif
2371 winPopup->Show();
2372
2373 m_popupWinState = Visible;
2374
2375 // If popup window was a generic top-level window, or the
2376 // wxPopupWindow implemenation on this platform is classified as
2377 // perfect, then we should be able to safely set focus to the popup
2378 // control.
2379 if ( IsPopupWinTypePerfect(m_popupWinType) )
2380 m_popup->SetFocus();
2381 }
2382 else if ( IsPopupWindowState(Hidden) )
2383 {
2384 // Animation was aborted
2385
2386 wxASSERT( !winPopup->IsShown() );
2387
2388 m_popupWinState = Hidden;
2389 }
2390
2391 Refresh();
2392 }
2393
2394 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
2395 {
2396 // Just in case, avoid double dismiss
2397 if ( IsPopupWindowState(Hidden) )
2398 return;
2399
2400 // This must be set before focus - otherwise there will be recursive
2401 // OnPopupDismisses.
2402 m_popupWinState = Hidden;
2403
2404 //SetFocus();
2405 m_winPopup->Disable();
2406
2407 // Inform popup control itself
2408 m_popupInterface->OnDismiss();
2409
2410 if ( m_popupEvtHandler )
2411 ((wxComboPopupEvtHandler*)m_popupEvtHandler)->OnPopupDismiss();
2412
2413 #if INSTALL_TOPLEV_HANDLER
2414 // Remove top level window event handler
2415 if ( m_toplevEvtHandler )
2416 {
2417 wxWindow* toplev = ::wxGetTopLevelParent( this );
2418 if ( toplev )
2419 toplev->RemoveEventHandler( m_toplevEvtHandler );
2420 }
2421 #endif
2422
2423 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
2424
2425 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2426 m_timeCanAcceptClick += 150;
2427
2428 // If cursor not on dropdown button, then clear its state
2429 // (technically not required by all ports, but do it for all just in case)
2430 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
2431 m_btnState = 0;
2432
2433 // Return parent's tab traversal flag.
2434 // See ShowPopup for notes.
2435 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
2436 {
2437 wxWindow* parent = GetParent();
2438 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2439 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2440 }
2441
2442 // refresh control (necessary even if m_text)
2443 Refresh();
2444
2445 SetFocus();
2446
2447 if ( generateEvent )
2448 {
2449 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId());
2450 event.SetEventObject(this);
2451 HandleWindowEvent(event);
2452 }
2453 }
2454
2455 void wxComboCtrlBase::HidePopup(bool generateEvent)
2456 {
2457 // Should be able to call this without popup interface
2458 if ( IsPopupWindowState(Hidden) )
2459 return;
2460
2461 // transfer value and show it in textctrl, if any
2462 if ( !IsPopupWindowState(Animating) )
2463 SetValueByUser( m_popupInterface->GetStringValue() );
2464
2465 m_winPopup->Hide();
2466
2467 OnPopupDismiss(generateEvent);
2468 }
2469
2470 // ----------------------------------------------------------------------------
2471 // customization methods
2472 // ----------------------------------------------------------------------------
2473
2474 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2475 int side, int spacingX )
2476 {
2477 m_btnWid = width;
2478 m_btnHei = height;
2479 m_btnSide = side;
2480 m_btnSpacingX = spacingX;
2481
2482 if ( width > 0 || height > 0 || spacingX )
2483 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
2484
2485 RecalcAndRefresh();
2486 }
2487
2488 wxSize wxComboCtrlBase::GetButtonSize()
2489 {
2490 if ( m_btnSize.x > 0 )
2491 return m_btnSize;
2492
2493 wxSize retSize(m_btnWid,m_btnHei);
2494
2495 // Need to call CalculateAreas now if button size is
2496 // is not explicitly specified.
2497 if ( retSize.x <= 0 || retSize.y <= 0)
2498 {
2499 OnResize();
2500
2501 retSize = m_btnSize;
2502 }
2503
2504 return retSize;
2505 }
2506
2507 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2508 bool blankButtonBg,
2509 const wxBitmap& bmpPressed,
2510 const wxBitmap& bmpHover,
2511 const wxBitmap& bmpDisabled )
2512 {
2513 m_bmpNormal = bmpNormal;
2514 m_blankButtonBg = blankButtonBg;
2515
2516 if ( bmpPressed.Ok() )
2517 m_bmpPressed = bmpPressed;
2518 else
2519 m_bmpPressed = bmpNormal;
2520
2521 if ( bmpHover.Ok() )
2522 m_bmpHover = bmpHover;
2523 else
2524 m_bmpHover = bmpNormal;
2525
2526 if ( bmpDisabled.Ok() )
2527 m_bmpDisabled = bmpDisabled;
2528 else
2529 m_bmpDisabled = bmpNormal;
2530
2531 RecalcAndRefresh();
2532 }
2533
2534 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2535 {
2536 if ( m_text )
2537 {
2538 // move textctrl accordingly
2539 wxRect r = m_text->GetRect();
2540 int inc = width - m_widthCustomPaint;
2541 r.x += inc;
2542 r.width -= inc;
2543 m_text->SetSize( r );
2544 }
2545
2546 m_widthCustomPaint = width;
2547
2548 RecalcAndRefresh();
2549 }
2550
2551 bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
2552 {
2553 // For general sanity's sake, we ignore top margin. Instead
2554 // we will always try to center the text vertically.
2555 bool res = true;
2556
2557 if ( margins.x != -1 )
2558 {
2559 m_marginLeft = margins.x;
2560 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2561 }
2562 else
2563 {
2564 m_marginLeft = GetNativeTextIndent();
2565 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2566 }
2567
2568 if ( margins.y != -1 )
2569 {
2570 res = false;
2571 }
2572
2573 RecalcAndRefresh();
2574
2575 return res;
2576 }
2577
2578 wxPoint wxComboCtrlBase::DoGetMargins() const
2579 {
2580 return wxPoint(m_marginLeft, -1);
2581 }
2582
2583 #if WXWIN_COMPATIBILITY_2_8
2584 void wxComboCtrlBase::SetTextIndent( int indent )
2585 {
2586 if ( indent < 0 )
2587 {
2588 m_marginLeft = GetNativeTextIndent();
2589 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2590 }
2591 else
2592 {
2593 m_marginLeft = indent;
2594 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2595 }
2596
2597 RecalcAndRefresh();
2598 }
2599
2600 wxCoord wxComboCtrlBase::GetTextIndent() const
2601 {
2602 return m_marginLeft;
2603 }
2604 #endif
2605
2606 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2607 {
2608 return DEFAULT_TEXT_INDENT;
2609 }
2610
2611 void wxComboCtrlBase::SetTextCtrlStyle( int style )
2612 {
2613 m_textCtrlStyle = style;
2614
2615 if ( m_text )
2616 m_text->SetWindowStyle(style);
2617 }
2618
2619 // ----------------------------------------------------------------------------
2620 // wxTextEntry interface
2621 // ----------------------------------------------------------------------------
2622
2623 wxString wxComboCtrlBase::DoGetValue() const
2624 {
2625 if ( m_text )
2626 return m_text->GetValue();
2627 return m_valueString;
2628 }
2629
2630 void wxComboCtrlBase::SetValueWithEvent(const wxString& value,
2631 bool withEvent)
2632 {
2633 DoSetValue(value, withEvent ? SetValue_SendEvent : 0);
2634 }
2635
2636 void wxComboCtrlBase::OnSetValue(const wxString& value)
2637 {
2638 // Note: before wxComboCtrl inherited from wxTextEntry,
2639 // this code used to be in SetValueWithEvent().
2640
2641 // Since wxComboPopup may want to paint the combo as well, we need
2642 // to set the string value here (as well as sometimes in ShowPopup).
2643 if ( m_valueString != value )
2644 {
2645 bool found = true;
2646 wxString trueValue = value;
2647
2648 // Conform to wxComboBox behavior: read-only control can only accept
2649 // valid list items and empty string
2650 if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() )
2651 {
2652 found = m_popupInterface->FindItem(value,
2653 &trueValue);
2654 }
2655
2656 if ( found )
2657 {
2658 m_valueString = trueValue;
2659
2660 EnsurePopupControl();
2661
2662 if ( m_popupInterface )
2663 m_popupInterface->SetStringValue(trueValue);
2664 }
2665 }
2666
2667 Refresh();
2668 }
2669
2670 void wxComboCtrlBase::SetValueByUser(const wxString& value)
2671 {
2672 // NB: Order of function calls is important here. Otherwise
2673 // the SelectAll() may not work.
2674
2675 if ( m_text )
2676 {
2677 m_text->SetValue(value);
2678
2679 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2680 m_text->SelectAll();
2681 }
2682
2683 OnSetValue(value);
2684 }
2685
2686 // In this SetValue variant wxComboPopup::SetStringValue is not called
2687 void wxComboCtrlBase::SetText(const wxString& value)
2688 {
2689 // Unlike in SetValue(), this must be called here or
2690 // the behaviour will no be consistent in readonlys.
2691 EnsurePopupControl();
2692
2693 m_valueString = value;
2694
2695 if ( m_text )
2696 {
2697 m_ignoreEvtText++;
2698 m_text->SetValue( value );
2699 }
2700
2701 Refresh();
2702 }
2703
2704 void wxComboCtrlBase::Copy()
2705 {
2706 if ( m_text )
2707 m_text->Copy();
2708 }
2709
2710 void wxComboCtrlBase::Cut()
2711 {
2712 if ( m_text )
2713 m_text->Cut();
2714 }
2715
2716 void wxComboCtrlBase::Paste()
2717 {
2718 if ( m_text )
2719 m_text->Paste();
2720 }
2721
2722 void wxComboCtrlBase::SetInsertionPoint(long pos)
2723 {
2724 if ( m_text )
2725 m_text->SetInsertionPoint(pos);
2726 }
2727
2728 long wxComboCtrlBase::GetInsertionPoint() const
2729 {
2730 if ( m_text )
2731 return m_text->GetInsertionPoint();
2732
2733 return 0;
2734 }
2735
2736 long wxComboCtrlBase::GetLastPosition() const
2737 {
2738 if ( m_text )
2739 return m_text->GetLastPosition();
2740
2741 return 0;
2742 }
2743
2744 void wxComboCtrlBase::WriteText(const wxString& text)
2745 {
2746 if ( m_text )
2747 {
2748 m_text->WriteText(text);
2749 OnSetValue(m_text->GetValue());
2750 }
2751 else
2752 {
2753 OnSetValue(text);
2754 }
2755 }
2756
2757 void wxComboCtrlBase::DoSetValue(const wxString& value, int flags)
2758 {
2759 if ( m_text )
2760 {
2761 if ( flags & SetValue_SendEvent )
2762 m_text->SetValue(value);
2763 else
2764 m_text->ChangeValue(value);
2765 }
2766
2767 OnSetValue(value);
2768 }
2769
2770 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2771 {
2772 if ( m_text )
2773 {
2774 m_text->Replace(from, to, value);
2775 OnSetValue(m_text->GetValue());
2776 }
2777 }
2778
2779 void wxComboCtrlBase::Remove(long from, long to)
2780 {
2781 if ( m_text )
2782 {
2783 m_text->Remove(from, to);
2784 OnSetValue(m_text->GetValue());
2785 }
2786 }
2787
2788 void wxComboCtrlBase::SetSelection(long from, long to)
2789 {
2790 if ( m_text )
2791 m_text->SetSelection(from, to);
2792 }
2793
2794 void wxComboCtrlBase::GetSelection(long *from, long *to) const
2795 {
2796 if ( m_text )
2797 {
2798 m_text->GetSelection(from, to);
2799 }
2800 else
2801 {
2802 *from = 0;
2803 *to = 0;
2804 }
2805 }
2806
2807 bool wxComboCtrlBase::IsEditable() const
2808 {
2809 if ( m_text )
2810 return m_text->IsEditable();
2811 return false;
2812 }
2813
2814 void wxComboCtrlBase::SetEditable(bool editable)
2815 {
2816 if ( m_text )
2817 m_text->SetEditable(editable);
2818 }
2819
2820 void wxComboCtrlBase::Undo()
2821 {
2822 if ( m_text )
2823 m_text->Undo();
2824 }
2825
2826 void wxComboCtrlBase::Redo()
2827 {
2828 if ( m_text )
2829 m_text->Redo();
2830 }
2831
2832 bool wxComboCtrlBase::CanUndo() const
2833 {
2834 if ( m_text )
2835 return m_text->CanUndo();
2836
2837 return false;
2838 }
2839
2840 bool wxComboCtrlBase::CanRedo() const
2841 {
2842 if ( m_text )
2843 return m_text->CanRedo();
2844
2845 return false;
2846 }
2847
2848 bool wxComboCtrlBase::SetHint(const wxString& hint)
2849 {
2850 m_hintText = hint;
2851 bool res = true;
2852 if ( m_text )
2853 res = m_text->SetHint(hint);
2854 Refresh();
2855 return res;
2856 }
2857
2858 wxString wxComboCtrlBase::GetHint() const
2859 {
2860 return m_hintText;
2861 }
2862
2863 #endif // wxUSE_COMBOCTRL