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