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