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