]> git.saurik.com Git - wxWidgets.git/blob - src/common/combocmn.cpp
non-pch build fix
[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 wxPopupTransientWindow* const
493 ptw = static_cast<wxPopupTransientWindow*>(this);
494
495 if ( show != ptw->IsShown() )
496 {
497 if ( show )
498 // We used to do wxPopupTransientWindow::Popup here,
499 // but this would hide normal Show, which we are
500 // also going to need.
501 ptw->Show();
502 else
503 ptw->Dismiss();
504 }
505
506 m_inShow--;
507
508 return true;
509 }
510
511 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event)
512 {
513 return wxPopupTransientWindow::ProcessLeftDown(event);
514 }
515
516 // First thing that happens when a transient popup closes is that this method gets called.
517 void wxComboPopupWindow::OnDismiss()
518 {
519 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
520 wxASSERT_MSG( wxDynamicCast(combo, wxComboCtrlBase),
521 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
522
523 combo->OnPopupDismiss(true);
524 }
525 #endif // USES_WXPOPUPTRANSIENTWINDOW
526
527
528 // ----------------------------------------------------------------------------
529 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
530 // of a popup window. It is separate so we can have different types
531 // of popup windows.
532 // ----------------------------------------------------------------------------
533
534 class wxComboPopupWindowEvtHandler : public wxEvtHandler
535 {
536 public:
537
538 wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent )
539 {
540 m_combo = parent;
541 }
542
543 void OnSizeEvent( wxSizeEvent& event );
544 void OnKeyEvent(wxKeyEvent& event);
545 #if USES_GENERICTLW
546 void OnActivate( wxActivateEvent& event );
547 #endif
548
549 private:
550 wxComboCtrlBase* m_combo;
551
552 DECLARE_EVENT_TABLE()
553 };
554
555
556 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler)
557 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent)
558 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent)
559 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent)
560 #if USES_GENERICTLW
561 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate)
562 #endif
563 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent)
564 END_EVENT_TABLE()
565
566
567 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) )
568 {
569 // Block the event so that the popup control does not get auto-resized.
570 }
571
572 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
573 {
574 // Relay keyboard event to the main child controls
575 wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
576 wxWindowList::iterator node = children.begin();
577 wxWindow* child = (wxWindow*)*node;
578 child->GetEventHandler()->ProcessEvent(event);
579 }
580
581 #if USES_GENERICTLW
582 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
583 {
584 if ( !event.GetActive() )
585 {
586 // Tell combo control that we are dismissed.
587 m_combo->HidePopup(true);
588
589 event.Skip();
590 }
591 }
592 #endif
593
594
595 // ----------------------------------------------------------------------------
596 // wxComboPopup
597 //
598 // ----------------------------------------------------------------------------
599
600 wxComboPopup::~wxComboPopup()
601 {
602 }
603
604 void wxComboPopup::OnPopup()
605 {
606 }
607
608 void wxComboPopup::OnDismiss()
609 {
610 }
611
612 wxComboCtrl* wxComboPopup::GetComboCtrl() const
613 {
614 return wxStaticCast(m_combo, wxComboCtrl);
615 }
616
617 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
618 int prefHeight,
619 int WXUNUSED(maxHeight) )
620 {
621 return wxSize(minWidth,prefHeight);
622 }
623
624 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
625 wxDC& dc, const wxRect& rect )
626 {
627 if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
628 {
629 combo->PrepareBackground(dc,rect,0);
630
631 dc.DrawText( combo->GetValue(),
632 rect.x + combo->m_marginLeft,
633 (rect.height-dc.GetCharHeight())/2 + rect.y );
634 }
635 }
636
637 void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
638 {
639 DefaultPaintComboControl(m_combo,dc,rect);
640 }
641
642 void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
643 {
644 event.Skip();
645 }
646
647 void wxComboPopup::OnComboCharEvent( wxKeyEvent& event )
648 {
649 event.Skip();
650 }
651
652 void wxComboPopup::OnComboDoubleClick()
653 {
654 }
655
656 void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
657 {
658 }
659
660 bool wxComboPopup::FindItem(const wxString& WXUNUSED(item),
661 wxString* WXUNUSED(trueItem))
662 {
663 return true;
664 }
665
666 bool wxComboPopup::LazyCreate()
667 {
668 return false;
669 }
670
671 void wxComboPopup::Dismiss()
672 {
673 m_combo->HidePopup(true);
674 }
675
676 void wxComboPopup::DestroyPopup()
677 {
678 // Here we make sure that the popup control's Destroy() gets called.
679 // This is necessary for the wxPersistentWindow to work properly.
680 wxWindow* popupCtrl = GetControl();
681 if ( popupCtrl )
682 {
683 // While all wxComboCtrl examples have m_popupInterface and
684 // popupCtrl as the same class (that will be deleted via the
685 // Destroy() call below), it is technically still possible to
686 // have implementations where they are in fact not same
687 // multiple-inherited class. Here we use C++ RTTI to check for
688 // this rare case.
689 #ifndef wxNO_RTTI
690 // It is probably better to delete m_popupInterface first, so
691 // that it retains access to its popup control window.
692 if ( dynamic_cast<void*>(this) !=
693 dynamic_cast<void*>(popupCtrl) )
694 delete this;
695 #endif
696 popupCtrl->Destroy();
697 }
698 else
699 {
700 delete this;
701 }
702 }
703
704 // ----------------------------------------------------------------------------
705 // input handling
706 // ----------------------------------------------------------------------------
707
708 //
709 // This is pushed to the event handler queue of the child textctrl.
710 //
711 class wxComboBoxExtraInputHandler : public wxEvtHandler
712 {
713 public:
714
715 wxComboBoxExtraInputHandler( wxComboCtrlBase* combo )
716 : wxEvtHandler()
717 {
718 m_combo = combo;
719 }
720 virtual ~wxComboBoxExtraInputHandler() { }
721 void OnKey(wxKeyEvent& event);
722 void OnFocus(wxFocusEvent& event);
723
724 protected:
725 wxComboCtrlBase* m_combo;
726
727 private:
728 DECLARE_EVENT_TABLE()
729 };
730
731
732 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
733 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
734 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey)
735 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey)
736 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
737 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
738 END_EVENT_TABLE()
739
740
741 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event)
742 {
743 // Let the wxComboCtrl event handler have a go first.
744 wxComboCtrlBase* combo = m_combo;
745
746 wxKeyEvent redirectedEvent(event);
747 redirectedEvent.SetId(combo->GetId());
748 redirectedEvent.SetEventObject(combo);
749
750 if ( !combo->GetEventHandler()->ProcessEvent(redirectedEvent) )
751 {
752 // Don't let TAB through to the text ctrl - looks ugly
753 if ( event.GetKeyCode() != WXK_TAB )
754 event.Skip();
755 }
756 }
757
758 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
759 {
760 // FIXME: This code does run when control is clicked,
761 // yet on Windows it doesn't select all the text.
762 if ( event.GetEventType() == wxEVT_SET_FOCUS &&
763 !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) )
764 {
765 if ( m_combo->GetTextCtrl() )
766 m_combo->GetTextCtrl()->SelectAll();
767 else
768 m_combo->SelectAll();
769 }
770
771 // Send focus indication to parent.
772 // NB: This is needed for cases where the textctrl gets focus
773 // instead of its parent. While this may trigger multiple
774 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
775 // from combo's focus event handler), they should be quite
776 // harmless.
777 wxFocusEvent evt2(event);
778 evt2.SetId(m_combo->GetId());
779 evt2.SetEventObject(m_combo);
780 m_combo->GetEventHandler()->ProcessEvent(evt2);
781
782 event.Skip();
783 }
784
785
786 //
787 // This is pushed to the event handler queue of the control in popup.
788 //
789
790 class wxComboPopupEvtHandler : public wxEvtHandler
791 {
792 public:
793
794 wxComboPopupEvtHandler( wxComboCtrlBase* combo )
795 : wxEvtHandler()
796 {
797 m_combo = combo;
798 m_beenInside = false;
799
800 // Let's make it so that the popup control will not receive mouse
801 // events until mouse left button has been up.
802 m_blockEventsToPopup = true;
803 }
804 virtual ~wxComboPopupEvtHandler() { }
805
806 void OnMouseEvent( wxMouseEvent& event );
807
808 // Called from wxComboCtrlBase::OnPopupDismiss
809 void OnPopupDismiss()
810 {
811 m_beenInside = false;
812 m_blockEventsToPopup = true;
813 }
814
815 protected:
816 wxComboCtrlBase* m_combo;
817
818 bool m_beenInside;
819 bool m_blockEventsToPopup;
820
821 private:
822 DECLARE_EVENT_TABLE()
823 };
824
825
826 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler, wxEvtHandler)
827 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent)
828 END_EVENT_TABLE()
829
830
831 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent& event )
832 {
833 wxPoint pt = event.GetPosition();
834 wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize();
835 int evtType = event.GetEventType();
836 bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y;
837 bool relayToButton = false;
838
839 event.Skip();
840
841 if ( !isInside || !m_combo->IsPopupShown() )
842 {
843 // Mouse is outside the popup or popup is not actually shown (yet)
844
845 if ( evtType == wxEVT_MOTION ||
846 evtType == wxEVT_LEFT_DOWN ||
847 evtType == wxEVT_LEFT_UP ||
848 evtType == wxEVT_RIGHT_DOWN )
849 {
850 // Block motion and click events outside the popup
851 event.Skip(false);
852 }
853 }
854 else
855 {
856 // Mouse is inside the popup, which is fully shown
857
858 m_beenInside = true;
859
860 // Do not let the popup control respond to mouse events until
861 // mouse press used to display the popup has been lifted. This
862 // is important for users with slower mouse fingers or mouse
863 // drivers. Note that we have some redundancy here, just in
864 // case the popup is some native control that does not emit all
865 // mouse event types.
866 if ( evtType == wxEVT_MOTION )
867 {
868 if ( m_blockEventsToPopup )
869 {
870 if ( event.LeftIsDown() )
871 event.Skip(false);
872 else
873 m_blockEventsToPopup = false;
874 }
875 }
876 else if ( evtType == wxEVT_LEFT_DOWN )
877 {
878 if ( m_blockEventsToPopup )
879 m_blockEventsToPopup = false;
880 }
881 else if ( evtType == wxEVT_LEFT_UP )
882 {
883 if ( m_blockEventsToPopup )
884 {
885 // On first left up, stop blocking mouse events (but still
886 // block this one)
887 m_blockEventsToPopup = false;
888 event.Skip(false);
889
890 // Also, this button press was (probably) used to display
891 // the popup, so relay it back to the drop-down button
892 // (which supposedly originated it). This is necessary to
893 // refresh it properly.
894 relayToButton = true;
895 }
896 }
897 else if ( m_blockEventsToPopup )
898 {
899 event.Skip(false);
900 }
901 }
902
903 //
904 // Some mouse events to popup that happen outside it, before cursor
905 // has been inside the popup, need to be ignored by it but relayed to
906 // the dropbutton.
907 //
908 if ( evtType == wxEVT_LEFT_UP )
909 {
910 if ( !m_combo->IsPopupShown() )
911 {
912 event.Skip(false);
913 relayToButton = true;
914 }
915 else if ( !isInside && !m_beenInside )
916 {
917 // Popup is shown but the cursor is not inside, nor it has been
918 relayToButton = true;
919 }
920 }
921
922 if ( relayToButton )
923 {
924 wxWindow* btn = m_combo->GetButton();
925 if ( btn )
926 btn->GetEventHandler()->ProcessEvent(event);
927 else
928 // Bypass the event handling mechanism. Using it would be
929 // confusing for the platform-specific wxComboCtrl
930 // implementations.
931 m_combo->HandleButtonMouseEvent(event, 0);
932 }
933 }
934
935 // ----------------------------------------------------------------------------
936 // wxComboCtrlTextCtrl
937 // ----------------------------------------------------------------------------
938
939 class wxComboCtrlTextCtrl : public wxTextCtrl
940 {
941 public:
942 wxComboCtrlTextCtrl() : wxTextCtrl() { }
943 virtual ~wxComboCtrlTextCtrl() { }
944
945 virtual wxWindow *GetMainWindowOfCompositeControl()
946 {
947 wxComboCtrl* combo = (wxComboCtrl*) GetParent();
948
949 // Returning this instead of just 'parent' lets FindFocus work
950 // correctly even when parent control is a child of a composite
951 // generic control (as is case with wxGenericDatePickerCtrl).
952 return combo->GetMainWindowOfCompositeControl();
953 }
954 };
955
956 // ----------------------------------------------------------------------------
957 // wxComboCtrlBase
958 // ----------------------------------------------------------------------------
959
960
961 BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl)
962 EVT_SIZE(wxComboCtrlBase::OnSizeEvent)
963 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent)
964 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent)
965 EVT_IDLE(wxComboCtrlBase::OnIdleEvent)
966 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
967 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent)
968 EVT_CHAR(wxComboCtrlBase::OnCharEvent)
969 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged)
970 END_EVENT_TABLE()
971
972
973 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
974
975 void wxComboCtrlBase::Init()
976 {
977 m_winPopup = NULL;
978 m_popup = NULL;
979 m_popupWinState = Hidden;
980 m_btn = NULL;
981 m_text = NULL;
982 m_popupInterface = NULL;
983
984 m_popupEvtHandler = NULL;
985 m_textEvtHandler = NULL;
986
987 #if INSTALL_TOPLEV_HANDLER
988 m_toplevEvtHandler = NULL;
989 #endif
990
991 m_mainCtrlWnd = this;
992
993 m_heightPopup = -1;
994 m_widthMinPopup = -1;
995 m_anchorSide = 0;
996 m_widthCustomPaint = 0;
997 m_widthCustomBorder = 0;
998
999 m_btnState = 0;
1000 m_btnWidDefault = 0;
1001 m_blankButtonBg = false;
1002 m_ignoreEvtText = 0;
1003 m_popupWinType = POPUPWIN_NONE;
1004 m_btnWid = m_btnHei = -1;
1005 m_btnSide = wxRIGHT;
1006 m_btnSpacingX = 0;
1007
1008 m_extLeft = 0;
1009 m_extRight = 0;
1010 m_marginLeft = -1;
1011 m_iFlags = 0;
1012 m_textCtrlStyle = 0;
1013 m_timeCanAcceptClick = 0;
1014
1015 m_resetFocus = false;
1016 m_hasTcBgCol = false;
1017 }
1018
1019 bool wxComboCtrlBase::Create(wxWindow *parent,
1020 wxWindowID id,
1021 const wxString& value,
1022 const wxPoint& pos,
1023 const wxSize& size,
1024 long style,
1025 const wxValidator& validator,
1026 const wxString& name)
1027 {
1028 if ( !wxControl::Create(parent,
1029 id,
1030 pos,
1031 size,
1032 style | wxWANTS_CHARS,
1033 validator,
1034 name) )
1035 return false;
1036
1037 m_valueString = value;
1038
1039 // Get colours
1040 OnThemeChange();
1041 m_marginLeft = GetNativeTextIndent();
1042
1043 m_iFlags |= wxCC_IFLAG_CREATED;
1044
1045 // If x and y indicate valid size, wxSizeEvent won't be
1046 // emitted automatically, so we need to add artificial one.
1047 if ( size.x > 0 && size.y > 0 )
1048 {
1049 wxSizeEvent evt(size,GetId());
1050 evt.SetEventObject(this);
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.IsOk() && 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.IsOk() )
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.IsOk() )
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.IsOk() || 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 int width = m_text ? m_text->GetBestSize().x : 80;
1363
1364 return GetSizeFromTextSize(width);
1365 }
1366
1367 wxSize wxComboCtrlBase::DoGetSizeFromTextSize(int xlen, int ylen) const
1368 {
1369 // Calculate close-to-native control height
1370
1371 int fhei;
1372
1373 #if wxUSE_COMBOBOX && (defined(__WXMSW__) || defined(__WXGTK__)) \
1374 && !defined(__WXUNIVERSAL__)
1375 wxComboBox* cb = new wxComboBox;
1376 cb->Hide();
1377 cb->Create(const_cast<wxComboCtrlBase*>(this), wxID_ANY);
1378 if ( m_font.IsOk() )
1379 cb->SetFont(m_font);
1380 fhei = cb->GetBestSize().y;
1381 cb->Destroy();
1382 #else
1383 if ( m_font.IsOk() )
1384 fhei = (m_font.GetPointSize()*2) + 5;
1385 else if ( wxNORMAL_FONT->IsOk() )
1386 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1387 else
1388 fhei = 22;
1389 #endif // only for wxComboBox on MSW or GTK
1390
1391 // Need to force height to accommodate bitmap?
1392 int btnSizeY = m_btnSize.y;
1393 if ( m_bmpNormal.IsOk() && fhei < btnSizeY )
1394 fhei = btnSizeY;
1395
1396 // Control height doesn't depend on border
1397 /*
1398 // Add border
1399 int border = m_windowStyle & wxBORDER_MASK;
1400 if ( border == wxSIMPLE_BORDER )
1401 fhei += 2;
1402 else if ( border == wxNO_BORDER )
1403 fhei += (m_widthCustomBorder*2);
1404 else
1405 // Sunken etc.
1406 fhei += 4;
1407 */
1408
1409 #ifdef __WXMAC__
1410 // these are the numbers from the HIG:
1411 switch ( m_windowVariant )
1412 {
1413 case wxWINDOW_VARIANT_NORMAL:
1414 default :
1415 fhei = 22;
1416 break;
1417 case wxWINDOW_VARIANT_SMALL:
1418 fhei = 19;
1419 break;
1420 case wxWINDOW_VARIANT_MINI:
1421 fhei = 15;
1422 break;
1423 }
1424 #endif
1425
1426 fhei += 2 * FOCUS_RING;
1427
1428 // Calculate width
1429 int fwid = xlen + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH;
1430
1431 // Add the margins we have previously set
1432 wxPoint marg( GetMargins() );
1433 fwid += wxMax(0, marg.x);
1434 fhei += wxMax(0, marg.y);
1435
1436 if ( ylen > 0 )
1437 fhei += ylen - GetCharHeight();
1438
1439 return wxSize(fwid, fhei);
1440 }
1441
1442 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1443 {
1444 if ( !IsCreated() )
1445 return;
1446
1447 // defined by actual wxComboCtrls
1448 OnResize();
1449
1450 event.Skip();
1451 }
1452
1453 // ----------------------------------------------------------------------------
1454 // standard operations
1455 // ----------------------------------------------------------------------------
1456
1457 bool wxComboCtrlBase::Enable(bool enable)
1458 {
1459 if ( !wxControl::Enable(enable) )
1460 return false;
1461
1462 if ( m_btn )
1463 m_btn->Enable(enable);
1464 if ( m_text )
1465 m_text->Enable(enable);
1466
1467 Refresh();
1468
1469 return true;
1470 }
1471
1472 bool wxComboCtrlBase::Show(bool show)
1473 {
1474 if ( !wxControl::Show(show) )
1475 return false;
1476
1477 if (m_btn)
1478 m_btn->Show(show);
1479
1480 if (m_text)
1481 m_text->Show(show);
1482
1483 return true;
1484 }
1485
1486 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1487 {
1488 if ( !wxControl::SetFont(font) )
1489 return false;
1490
1491 if ( m_text )
1492 {
1493 // Without hiding the wxTextCtrl there would be some
1494 // visible 'flicker' (at least on Windows XP).
1495 m_text->Hide();
1496 m_text->SetFont(font);
1497 OnResize();
1498 m_text->Show();
1499 }
1500
1501 return true;
1502 }
1503
1504 #if wxUSE_TOOLTIPS
1505 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1506 {
1507 wxControl::DoSetToolTip(tooltip);
1508
1509 // Set tool tip for button and text box
1510 if ( tooltip )
1511 {
1512 const wxString &tip = tooltip->GetTip();
1513 if ( m_text ) m_text->SetToolTip(tip);
1514 if ( m_btn ) m_btn->SetToolTip(tip);
1515 }
1516 else
1517 {
1518 if ( m_text ) m_text->SetToolTip( NULL );
1519 if ( m_btn ) m_btn->SetToolTip( NULL );
1520 }
1521 }
1522 #endif // wxUSE_TOOLTIPS
1523
1524 bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour)
1525 {
1526 if ( wxControl::SetForegroundColour(colour) )
1527 {
1528 if ( m_text )
1529 m_text->SetForegroundColour(colour);
1530 return true;
1531 }
1532 return false;
1533 }
1534
1535 bool wxComboCtrlBase::SetBackgroundColour(const wxColour& colour)
1536 {
1537 if ( m_text )
1538 m_text->SetBackgroundColour(colour);
1539 m_tcBgCol = colour;
1540 m_hasTcBgCol = true;
1541 return true;
1542 }
1543
1544 wxColour wxComboCtrlBase::GetBackgroundColour() const
1545 {
1546 if ( m_text )
1547 return m_text->GetBackgroundColour();
1548 return m_tcBgCol;
1549 }
1550
1551 // ----------------------------------------------------------------------------
1552 // painting
1553 // ----------------------------------------------------------------------------
1554
1555 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1556 // prepare combo box background on area in a way typical on platform
1557 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1558 {
1559 wxSize sz = GetClientSize();
1560 bool isEnabled;
1561 bool doDrawFocusRect; // also selected
1562
1563 // For smaller size control (and for disabled background) use less spacing
1564 int focusSpacingX;
1565 int focusSpacingY;
1566
1567 if ( !(flags & wxCONTROL_ISSUBMENU) )
1568 {
1569 // Drawing control
1570 isEnabled = IsEnabled();
1571 doDrawFocusRect = ShouldDrawFocus() && !(m_iFlags & wxCC_FULL_BUTTON);
1572
1573 // Windows-style: for smaller size control (and for disabled background) use less spacing
1574 focusSpacingX = isEnabled ? 2 : 1;
1575 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1576 }
1577 else
1578 {
1579 // Drawing a list item
1580 isEnabled = true; // they are never disabled
1581 doDrawFocusRect = (flags & wxCONTROL_SELECTED) != 0;
1582
1583 focusSpacingX = 0;
1584 focusSpacingY = 0;
1585 }
1586
1587 // Set the background sub-rectangle for selection, disabled etc
1588 wxRect selRect(rect);
1589 selRect.y += focusSpacingY;
1590 selRect.height -= (focusSpacingY*2);
1591
1592 int wcp = 0;
1593
1594 if ( !(flags & wxCONTROL_ISSUBMENU) )
1595 wcp += m_widthCustomPaint;
1596
1597 selRect.x += wcp + focusSpacingX;
1598 selRect.width -= wcp + (focusSpacingX*2);
1599
1600 wxColour bgCol;
1601 wxColour fgCol;
1602
1603 bool doDrawSelRect = true;
1604
1605 // Determine foreground colour
1606 if ( isEnabled )
1607 {
1608 if ( doDrawFocusRect )
1609 {
1610 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1611 }
1612 else if ( m_hasFgCol )
1613 {
1614 // Honour the custom foreground colour
1615 fgCol = GetForegroundColour();
1616 }
1617 else
1618 {
1619 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1620 }
1621 }
1622 else
1623 {
1624 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
1625 }
1626
1627 // Determine background colour
1628 if ( isEnabled )
1629 {
1630 if ( doDrawFocusRect )
1631 {
1632 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1633 }
1634 else if ( m_hasTcBgCol )
1635 {
1636 // Honour the custom background colour
1637 bgCol = m_tcBgCol;
1638 }
1639 else
1640 {
1641 #ifndef __WXMAC__ // see note in OnThemeChange
1642 doDrawSelRect = false;
1643 bgCol = GetBackgroundColour();
1644 #else
1645 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1646 #endif
1647 }
1648 }
1649 else
1650 {
1651 #ifndef __WXMAC__ // see note in OnThemeChange
1652 bgCol = GetBackgroundColour();
1653 #else
1654 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1655 #endif
1656 }
1657
1658 dc.SetTextForeground( fgCol );
1659 dc.SetBrush( bgCol );
1660 if ( doDrawSelRect )
1661 {
1662 dc.SetPen( bgCol );
1663 dc.DrawRectangle( selRect );
1664 }
1665
1666 // Don't clip exactly to the selection rectangle so we can draw
1667 // to the non-selected area in front of it.
1668 wxRect clipRect(rect.x,rect.y,
1669 (selRect.x+selRect.width)-rect.x,rect.height);
1670 dc.SetClippingRegion(clipRect);
1671 }
1672 #else
1673 // Save the library size a bit for platforms that re-implement this.
1674 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1675 {
1676 }
1677 #endif
1678
1679 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags )
1680 {
1681 int drawState = m_btnState;
1682
1683 if ( (m_iFlags & wxCC_BUTTON_STAYS_DOWN) &&
1684 GetPopupWindowState() >= Animating )
1685 drawState |= wxCONTROL_PRESSED;
1686
1687 wxRect drawRect(rect.x+m_btnSpacingX,
1688 rect.y+((rect.height-m_btnSize.y)/2),
1689 m_btnSize.x,
1690 m_btnSize.y);
1691
1692 // Make sure area is not larger than the control
1693 if ( drawRect.y < rect.y )
1694 drawRect.y = rect.y;
1695 if ( drawRect.height > rect.height )
1696 drawRect.height = rect.height;
1697
1698 bool enabled = IsEnabled();
1699
1700 if ( !enabled )
1701 drawState |= wxCONTROL_DISABLED;
1702
1703 // Need to clear button background even if m_btn is present
1704 // and also when using custom bitmap for the button
1705 if ( (flags & Button_PaintBackground) &&
1706 (!HasTransparentBackground() ||
1707 !(m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE)) )
1708 {
1709 wxColour bgCol;
1710
1711 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1712 bgCol = GetParent()->GetBackgroundColour();
1713 else
1714 bgCol = GetBackgroundColour();
1715
1716 dc.SetBrush(bgCol);
1717 dc.SetPen(bgCol);
1718 dc.DrawRectangle(rect);
1719 }
1720
1721 if ( !m_bmpNormal.IsOk() )
1722 {
1723 if ( flags & Button_BitmapOnly )
1724 return;
1725
1726 // Draw standard button
1727 wxRendererNative::Get().DrawComboBoxDropButton(this,
1728 dc,
1729 drawRect,
1730 drawState);
1731 }
1732 else
1733 {
1734 // Draw bitmap
1735
1736 wxBitmap* pBmp;
1737
1738 if ( !enabled )
1739 pBmp = &m_bmpDisabled;
1740 else if ( m_btnState & wxCONTROL_PRESSED )
1741 pBmp = &m_bmpPressed;
1742 else if ( m_btnState & wxCONTROL_CURRENT )
1743 pBmp = &m_bmpHover;
1744 else
1745 pBmp = &m_bmpNormal;
1746
1747 if ( m_blankButtonBg )
1748 {
1749 if ( !(flags & Button_BitmapOnly) )
1750 {
1751 wxRendererNative::Get().DrawPushButton(this,
1752 dc,
1753 drawRect,
1754 drawState);
1755 }
1756 }
1757
1758 // Draw bitmap centered in drawRect
1759 dc.DrawBitmap(*pBmp,
1760 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1761 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1762 true);
1763 }
1764 }
1765
1766 void wxComboCtrlBase::RecalcAndRefresh()
1767 {
1768 if ( IsCreated() )
1769 {
1770 wxSizeEvent evt(GetSize(),GetId());
1771 evt.SetEventObject(this);
1772 GetEventHandler()->ProcessEvent(evt);
1773 Refresh();
1774 }
1775 }
1776
1777 // ----------------------------------------------------------------------------
1778 // miscellaneous event handlers
1779 // ----------------------------------------------------------------------------
1780
1781 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1782 {
1783 // Avoid infinite recursion
1784 if ( event.GetEventObject() == this )
1785 {
1786 event.Skip();
1787 return;
1788 }
1789
1790 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1791 {
1792 if ( m_ignoreEvtText > 0 )
1793 {
1794 m_ignoreEvtText--;
1795 return;
1796 }
1797 }
1798
1799 // For safety, completely re-create a new wxCommandEvent
1800 wxCommandEvent evt2(event);
1801 evt2.SetId(GetId());
1802 evt2.SetEventObject(this);
1803 HandleWindowEvent(evt2);
1804
1805 event.StopPropagation();
1806 }
1807
1808 // call if cursor is on button area or mouse is captured for the button
1809 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1810 int flags )
1811 {
1812 int type = event.GetEventType();
1813
1814 if ( type == wxEVT_MOTION )
1815 {
1816 if ( (flags & wxCC_MF_ON_BUTTON) &&
1817 IsPopupWindowState(Hidden) )
1818 {
1819 if ( !(m_btnState & wxCONTROL_CURRENT) )
1820 {
1821 // Mouse hover begins
1822 m_btnState |= wxCONTROL_CURRENT;
1823 if ( HasCapture() ) // Retain pressed state.
1824 m_btnState |= wxCONTROL_PRESSED;
1825 Refresh();
1826 }
1827 }
1828 else if ( (m_btnState & wxCONTROL_CURRENT) )
1829 {
1830 // Mouse hover ends
1831 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1832 Refresh();
1833 }
1834 }
1835 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1836 {
1837 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1838 {
1839 m_btnState |= wxCONTROL_PRESSED;
1840 Refresh();
1841
1842 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1843 OnButtonClick();
1844 else
1845 // If showing popup now, do not capture mouse or there will be interference
1846 CaptureMouse();
1847 }
1848 }
1849 else if ( type == wxEVT_LEFT_UP )
1850 {
1851
1852 // Only accept event if mouse was left-press was previously accepted
1853 if ( HasCapture() )
1854 ReleaseMouse();
1855
1856 if ( m_btnState & wxCONTROL_PRESSED )
1857 {
1858 // If mouse was inside, fire the click event.
1859 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1860 {
1861 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1862 OnButtonClick();
1863 }
1864
1865 m_btnState &= ~(wxCONTROL_PRESSED);
1866 Refresh();
1867 }
1868 }
1869 else if ( type == wxEVT_LEAVE_WINDOW )
1870 {
1871 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1872 {
1873 m_btnState &= ~(wxCONTROL_CURRENT);
1874
1875 // Mouse hover ends
1876 if ( IsPopupWindowState(Hidden) )
1877 {
1878 m_btnState &= ~(wxCONTROL_PRESSED);
1879 Refresh();
1880 }
1881 }
1882 }
1883 else
1884 return false;
1885
1886 // Never have 'hot' state when popup is being shown
1887 // (this is mostly needed because of the animation).
1888 if ( !IsPopupWindowState(Hidden) )
1889 m_btnState &= ~wxCONTROL_CURRENT;
1890
1891 return true;
1892 }
1893
1894 // returns true if event was consumed or filtered
1895 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1896 int WXUNUSED(flags) )
1897 {
1898 wxLongLong t = ::wxGetLocalTimeMillis();
1899 int evtType = event.GetEventType();
1900
1901 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1902 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1903 {
1904 if ( IsPopupWindowState(Visible) &&
1905 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1906 {
1907 HidePopup(true);
1908 return true;
1909 }
1910 }
1911 #endif
1912
1913 // Filter out clicks on button immediately after popup dismiss
1914 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1915 {
1916 event.SetEventType(0);
1917 return true;
1918 }
1919
1920 return false;
1921 }
1922
1923 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1924 {
1925 int evtType = event.GetEventType();
1926
1927 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1928 (m_windowStyle & wxCB_READONLY) )
1929 {
1930 if ( GetPopupWindowState() >= Animating )
1931 {
1932 #if USES_WXPOPUPWINDOW
1933 // Click here always hides the popup.
1934 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1935 HidePopup(true);
1936 #endif
1937 }
1938 else
1939 {
1940 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1941 {
1942 // In read-only mode, clicking the text is the
1943 // same as clicking the button.
1944 OnButtonClick();
1945 }
1946 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1947 {
1948 //if ( m_popupInterface->CycleValue() )
1949 // Refresh();
1950 if ( m_popupInterface )
1951 m_popupInterface->OnComboDoubleClick();
1952 }
1953 }
1954 }
1955 else if ( evtType == wxEVT_MOUSEWHEEL )
1956 {
1957 if ( IsPopupShown() )
1958 {
1959 // relay (some) mouse events to the popup
1960 m_popup->GetEventHandler()->ProcessEvent(event);
1961 }
1962 else if ( event.GetWheelAxis() == 0 &&
1963 event.GetWheelRotation() != 0 &&
1964 event.GetModifiers() == 0 )
1965 {
1966 // Translate mousewheel actions into key up/down. This is
1967 // the simplest way of getting native behaviour: scrolling the
1968 // wheel moves selection up/down by one item.
1969 wxKeyEvent kevent(wxEVT_KEY_DOWN);
1970 kevent.m_keyCode = event.GetWheelRotation() > 0
1971 ? WXK_UP
1972 : WXK_DOWN;
1973 GetEventHandler()->ProcessEvent(kevent);
1974 }
1975 else
1976 {
1977 event.Skip();
1978 }
1979 }
1980 else if ( evtType )
1981 {
1982 event.Skip();
1983 }
1984 }
1985
1986 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1987 {
1988 if ( IsPopupShown() )
1989 {
1990 // pass it to the popped up control
1991 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
1992 }
1993 else // no popup
1994 {
1995 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1996
1997 if ( mainCtrl->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
1998 {
1999 if ( mainCtrl->HandleAsNavigationKey(event) )
2000 return;
2001 }
2002
2003 if ( IsKeyPopupToggle(event) )
2004 {
2005 OnButtonClick();
2006 return;
2007 }
2008
2009 int comboStyle = GetWindowStyle();
2010 wxComboPopup* popupInterface = GetPopupControl();
2011
2012 if ( !popupInterface )
2013 {
2014 event.Skip();
2015 return;
2016 }
2017
2018 int keycode = event.GetKeyCode();
2019
2020 if ( (comboStyle & wxCB_READONLY) ||
2021 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
2022 {
2023 popupInterface->OnComboKeyEvent(event);
2024 }
2025 else
2026 event.Skip();
2027 }
2028 }
2029
2030 void wxComboCtrlBase::OnCharEvent(wxKeyEvent& event)
2031 {
2032 if ( IsPopupShown() )
2033 {
2034 // pass it to the popped up control
2035 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
2036 }
2037 else // no popup
2038 {
2039 wxComboPopup* popupInterface = GetPopupControl();
2040 if ( popupInterface )
2041 {
2042 popupInterface->OnComboCharEvent(event);
2043 }
2044 else
2045 {
2046 event.Skip();
2047 }
2048 }
2049 }
2050
2051 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
2052 {
2053 // On Mac, this leads to infinite recursion and eventually a crash
2054 #ifndef __WXMAC__
2055 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2056 {
2057 wxWindow* tc = GetTextCtrl();
2058 if ( tc && tc != DoFindFocus() )
2059 {
2060 tc->SetFocus();
2061 }
2062 }
2063
2064 Refresh();
2065 #endif
2066 }
2067
2068 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
2069 {
2070 if ( m_resetFocus )
2071 {
2072 m_resetFocus = false;
2073 wxWindow* tc = GetTextCtrl();
2074 if ( tc )
2075 tc->SetFocus();
2076 }
2077 }
2078
2079 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
2080 {
2081 OnThemeChange();
2082 // left margin may also have changed
2083 if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
2084 m_marginLeft = GetNativeTextIndent();
2085 RecalcAndRefresh();
2086 }
2087
2088 // ----------------------------------------------------------------------------
2089 // popup handling
2090 // ----------------------------------------------------------------------------
2091
2092 // Create popup window and the child control
2093 void wxComboCtrlBase::CreatePopup()
2094 {
2095 wxComboPopup* popupInterface = m_popupInterface;
2096 wxWindow* popup;
2097
2098 if ( !m_winPopup )
2099 {
2100 #ifdef wxComboPopupWindowBase2
2101 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
2102 {
2103 #if !USES_GENERICTLW
2104 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
2105 #else
2106 int tlwFlags = wxNO_BORDER;
2107 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2108 tlwFlags |= wxFRAME_NO_TASKBAR;
2109 #endif
2110
2111 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2112 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY,
2113 wxPoint(-21,-21), wxSize(20, 20),
2114 tlwFlags );
2115 #else
2116 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
2117 wxPoint(-21,-21), wxSize(20, 20),
2118 tlwFlags );
2119 #endif
2120 #endif
2121 m_popupWinType = SECONDARY_POPUP_TYPE;
2122 }
2123 else
2124 #endif // wxComboPopupWindowBase2
2125 {
2126 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
2127 m_popupWinType = PRIMARY_POPUP_TYPE;
2128 }
2129 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
2130 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
2131 }
2132
2133 popupInterface->Create(m_winPopup);
2134 m_popup = popup = popupInterface->GetControl();
2135
2136 m_popupEvtHandler = new wxComboPopupEvtHandler(this);
2137 popup->PushEventHandler( m_popupEvtHandler );
2138
2139 // This may be helpful on some platforms
2140 // (eg. it bypasses a wxGTK popupwindow bug where
2141 // window is not initially hidden when it should be)
2142 m_winPopup->Hide();
2143
2144 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
2145 }
2146
2147 // Destroy popup window and the child control
2148 void wxComboCtrlBase::DestroyPopup()
2149 {
2150 HidePopup(true);
2151
2152 if ( m_popup )
2153 m_popup->RemoveEventHandler(m_popupEvtHandler);
2154
2155 wxDELETE(m_popupEvtHandler);
2156
2157 if ( m_popupInterface )
2158 {
2159 // NB: DestroyPopup() performs 'delete this'.
2160 m_popupInterface->DestroyPopup();
2161 m_popupInterface = NULL;
2162 }
2163
2164 if ( m_winPopup )
2165 {
2166 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
2167 wxDELETE(m_popupWinEvtHandler);
2168 m_winPopup->Destroy();
2169 m_winPopup = NULL;
2170 }
2171
2172 m_popup = NULL;
2173 }
2174
2175 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
2176 {
2177 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
2178
2179 DestroyPopup();
2180
2181 iface->InitBase(this);
2182 iface->Init();
2183
2184 m_popupInterface = iface;
2185
2186 if ( !iface->LazyCreate() )
2187 {
2188 CreatePopup();
2189 }
2190 else
2191 {
2192 m_popup = NULL;
2193 }
2194
2195 // This must be done after creation
2196 if ( !m_valueString.empty() )
2197 {
2198 iface->SetStringValue(m_valueString);
2199 //Refresh();
2200 }
2201 }
2202
2203 // Ensures there is atleast the default popup
2204 void wxComboCtrlBase::EnsurePopupControl()
2205 {
2206 if ( !m_popupInterface )
2207 SetPopupControl(NULL);
2208 }
2209
2210 void wxComboCtrlBase::OnButtonClick()
2211 {
2212 // Derived classes can override this method for totally custom
2213 // popup action
2214 switch ( GetPopupWindowState() )
2215 {
2216 case Hidden:
2217 {
2218 Popup();
2219 break;
2220 }
2221
2222 case Animating:
2223 case Visible:
2224 {
2225 HidePopup(true);
2226 break;
2227 }
2228 }
2229 }
2230
2231 void wxComboCtrlBase::Popup()
2232 {
2233 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId());
2234 event.SetEventObject(this);
2235 HandleWindowEvent(event);
2236
2237 ShowPopup();
2238 }
2239
2240 void wxComboCtrlBase::ShowPopup()
2241 {
2242 EnsurePopupControl();
2243 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
2244
2245 if ( IsPopupWindowState(Animating) )
2246 return;
2247
2248 SetFocus();
2249
2250 // Space above and below
2251 int screenHeight;
2252 wxPoint scrPos;
2253 int spaceAbove;
2254 int spaceBelow;
2255 int maxHeightPopup;
2256 wxSize ctrlSz = GetSize();
2257
2258 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
2259 scrPos = GetParent()->ClientToScreen(GetPosition());
2260
2261 spaceAbove = scrPos.y;
2262 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
2263
2264 maxHeightPopup = spaceBelow;
2265 if ( spaceAbove > spaceBelow )
2266 maxHeightPopup = spaceAbove;
2267
2268 // Width
2269 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
2270
2271 if ( widthPopup < m_widthMinPopup )
2272 widthPopup = m_widthMinPopup;
2273
2274 wxWindow* winPopup = m_winPopup;
2275 wxWindow* popup;
2276
2277 // Need to disable tab traversal of parent
2278 //
2279 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2280 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2281 // that if transient popup is open, then tab traversal is to be ignored.
2282 // However, I think this code would still be needed for cases where
2283 // transient popup doesn't work yet (wxWinCE?).
2284 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
2285 wxWindow* parent = mainCtrl->GetParent();
2286 int parentFlags = parent->GetWindowStyle();
2287 if ( parentFlags & wxTAB_TRAVERSAL )
2288 {
2289 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
2290 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
2291 }
2292
2293 if ( !winPopup )
2294 {
2295 CreatePopup();
2296 winPopup = m_winPopup;
2297 popup = m_popup;
2298 }
2299 else
2300 {
2301 popup = m_popup;
2302 }
2303
2304 winPopup->Enable();
2305
2306 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
2307
2308 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
2309 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
2310 maxHeightPopup);
2311
2312 popup->SetSize(adjustedSize);
2313 popup->Move(0,0);
2314 m_popupInterface->OnPopup();
2315
2316 //
2317 // Reposition and resize popup window
2318 //
2319
2320 wxSize szp = popup->GetSize();
2321
2322 int popupX;
2323 int popupY = scrPos.y + ctrlSz.y;
2324
2325 // Default anchor is wxLEFT
2326 int anchorSide = m_anchorSide;
2327 if ( !anchorSide )
2328 anchorSide = wxLEFT;
2329
2330 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
2331 int leftX = scrPos.x - m_extLeft;
2332
2333 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
2334 leftX -= ctrlSz.x;
2335
2336 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
2337
2338 // If there is not enough horizontal space, anchor on the other side.
2339 // If there is no space even then, place the popup at x 0.
2340 if ( anchorSide == wxRIGHT )
2341 {
2342 if ( rightX < 0 )
2343 {
2344 if ( (leftX+szp.x) < screenWidth )
2345 anchorSide = wxLEFT;
2346 else
2347 anchorSide = 0;
2348 }
2349 }
2350 else
2351 {
2352 if ( (leftX+szp.x) >= screenWidth )
2353 {
2354 if ( rightX >= 0 )
2355 anchorSide = wxRIGHT;
2356 else
2357 anchorSide = 0;
2358 }
2359 }
2360
2361 // Select x coordinate according to the anchor side
2362 if ( anchorSide == wxRIGHT )
2363 popupX = rightX;
2364 else if ( anchorSide == wxLEFT )
2365 popupX = leftX;
2366 else
2367 popupX = 0;
2368
2369 int showFlags = CanDeferShow;
2370
2371 if ( spaceBelow < szp.y )
2372 {
2373 popupY = scrPos.y - szp.y;
2374 showFlags |= ShowAbove;
2375 }
2376
2377 #if INSTALL_TOPLEV_HANDLER
2378 // Put top level window event handler into place
2379 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
2380 {
2381 if ( !m_toplevEvtHandler )
2382 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
2383
2384 wxWindow* toplev = ::wxGetTopLevelParent( this );
2385 wxASSERT( toplev );
2386 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
2387 toplev->PushEventHandler( m_toplevEvtHandler );
2388 }
2389 #endif
2390
2391 // Set string selection (must be this way instead of SetStringSelection)
2392 if ( m_text )
2393 {
2394 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2395 m_text->SelectAll();
2396
2397 m_popupInterface->SetStringValue( m_text->GetValue() );
2398 }
2399 else
2400 {
2401 // This is neede since focus/selection indication may change when popup is shown
2402 Refresh();
2403 }
2404
2405 // This must be after SetStringValue
2406 m_popupWinState = Animating;
2407
2408 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
2409
2410 m_popup = popup;
2411 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
2412 AnimateShow( popupWinRect, showFlags ) )
2413 {
2414 DoShowPopup( popupWinRect, showFlags );
2415 }
2416 }
2417
2418 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
2419 {
2420 return true;
2421 }
2422
2423 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
2424 {
2425 wxWindow* winPopup = m_winPopup;
2426
2427 if ( IsPopupWindowState(Animating) )
2428 {
2429 // Make sure the popup window is shown in the right position.
2430 // Should not matter even if animation already did this.
2431
2432 // Some platforms (GTK) may like SetSize and Move to be separate
2433 // (though the bug was probably fixed).
2434 winPopup->SetSize( rect );
2435
2436 #if USES_WXPOPUPTRANSIENTWINDOW
2437 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2438 ((wxPopupTransientWindow*)winPopup)->Popup(m_popup);
2439 else
2440 #endif
2441 winPopup->Show();
2442
2443 m_popupWinState = Visible;
2444
2445 // If popup window was a generic top-level window, or the
2446 // wxPopupWindow implemenation on this platform is classified as
2447 // perfect, then we should be able to safely set focus to the popup
2448 // control.
2449 if ( IsPopupWinTypePerfect(m_popupWinType) )
2450 m_popup->SetFocus();
2451 }
2452 else if ( IsPopupWindowState(Hidden) )
2453 {
2454 // Animation was aborted
2455
2456 wxASSERT( !winPopup->IsShown() );
2457
2458 m_popupWinState = Hidden;
2459 }
2460
2461 Refresh();
2462 }
2463
2464 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
2465 {
2466 // Just in case, avoid double dismiss
2467 if ( IsPopupWindowState(Hidden) )
2468 return;
2469
2470 // This must be set before focus - otherwise there will be recursive
2471 // OnPopupDismisses.
2472 m_popupWinState = Hidden;
2473
2474 //SetFocus();
2475 m_winPopup->Disable();
2476
2477 // Inform popup control itself
2478 m_popupInterface->OnDismiss();
2479
2480 if ( m_popupEvtHandler )
2481 ((wxComboPopupEvtHandler*)m_popupEvtHandler)->OnPopupDismiss();
2482
2483 #if INSTALL_TOPLEV_HANDLER
2484 // Remove top level window event handler
2485 if ( m_toplevEvtHandler )
2486 {
2487 wxWindow* toplev = ::wxGetTopLevelParent( this );
2488 if ( toplev )
2489 toplev->RemoveEventHandler( m_toplevEvtHandler );
2490 }
2491 #endif
2492
2493 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
2494
2495 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2496 m_timeCanAcceptClick += 150;
2497
2498 // If cursor not on dropdown button, then clear its state
2499 // (technically not required by all ports, but do it for all just in case)
2500 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
2501 m_btnState = 0;
2502
2503 // Return parent's tab traversal flag.
2504 // See ShowPopup for notes.
2505 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
2506 {
2507 wxWindow* parent = GetParent();
2508 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2509 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2510 }
2511
2512 // refresh control (necessary even if m_text)
2513 Refresh();
2514
2515 SetFocus();
2516
2517 if ( generateEvent )
2518 {
2519 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId());
2520 event.SetEventObject(this);
2521 HandleWindowEvent(event);
2522 }
2523 }
2524
2525 void wxComboCtrlBase::HidePopup(bool generateEvent)
2526 {
2527 // Should be able to call this without popup interface
2528 if ( IsPopupWindowState(Hidden) )
2529 return;
2530
2531 // transfer value and show it in textctrl, if any
2532 if ( !IsPopupWindowState(Animating) )
2533 SetValueByUser( m_popupInterface->GetStringValue() );
2534
2535 m_winPopup->Hide();
2536
2537 OnPopupDismiss(generateEvent);
2538 }
2539
2540 // ----------------------------------------------------------------------------
2541 // customization methods
2542 // ----------------------------------------------------------------------------
2543
2544 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2545 int side, int spacingX )
2546 {
2547 m_btnWid = width;
2548 m_btnHei = height;
2549 m_btnSide = side;
2550 m_btnSpacingX = spacingX;
2551
2552 if ( width > 0 || height > 0 || spacingX )
2553 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
2554
2555 RecalcAndRefresh();
2556 }
2557
2558 wxSize wxComboCtrlBase::GetButtonSize()
2559 {
2560 if ( m_btnSize.x > 0 )
2561 return m_btnSize;
2562
2563 wxSize retSize(m_btnWid,m_btnHei);
2564
2565 // Need to call CalculateAreas now if button size is
2566 // is not explicitly specified.
2567 if ( retSize.x <= 0 || retSize.y <= 0)
2568 {
2569 OnResize();
2570
2571 retSize = m_btnSize;
2572 }
2573
2574 return retSize;
2575 }
2576
2577 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2578 bool blankButtonBg,
2579 const wxBitmap& bmpPressed,
2580 const wxBitmap& bmpHover,
2581 const wxBitmap& bmpDisabled )
2582 {
2583 m_bmpNormal = bmpNormal;
2584 m_blankButtonBg = blankButtonBg;
2585
2586 if ( bmpPressed.IsOk() )
2587 m_bmpPressed = bmpPressed;
2588 else
2589 m_bmpPressed = bmpNormal;
2590
2591 if ( bmpHover.IsOk() )
2592 m_bmpHover = bmpHover;
2593 else
2594 m_bmpHover = bmpNormal;
2595
2596 if ( bmpDisabled.IsOk() )
2597 m_bmpDisabled = bmpDisabled;
2598 else
2599 m_bmpDisabled = bmpNormal;
2600
2601 RecalcAndRefresh();
2602 }
2603
2604 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2605 {
2606 if ( m_text )
2607 {
2608 // move textctrl accordingly
2609 wxRect r = m_text->GetRect();
2610 int inc = width - m_widthCustomPaint;
2611 r.x += inc;
2612 r.width -= inc;
2613 m_text->SetSize( r );
2614 }
2615
2616 m_widthCustomPaint = width;
2617
2618 RecalcAndRefresh();
2619 }
2620
2621 bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
2622 {
2623 // For general sanity's sake, we ignore top margin. Instead
2624 // we will always try to center the text vertically.
2625 bool res = true;
2626
2627 if ( margins.x != -1 )
2628 {
2629 m_marginLeft = margins.x;
2630 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2631 }
2632 else
2633 {
2634 m_marginLeft = GetNativeTextIndent();
2635 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2636 }
2637
2638 if ( margins.y != -1 )
2639 {
2640 res = false;
2641 }
2642
2643 RecalcAndRefresh();
2644
2645 return res;
2646 }
2647
2648 wxPoint wxComboCtrlBase::DoGetMargins() const
2649 {
2650 return wxPoint(m_marginLeft, -1);
2651 }
2652
2653 #if WXWIN_COMPATIBILITY_2_8
2654 void wxComboCtrlBase::SetTextIndent( int indent )
2655 {
2656 if ( indent < 0 )
2657 {
2658 m_marginLeft = GetNativeTextIndent();
2659 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2660 }
2661 else
2662 {
2663 m_marginLeft = indent;
2664 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2665 }
2666
2667 RecalcAndRefresh();
2668 }
2669
2670 wxCoord wxComboCtrlBase::GetTextIndent() const
2671 {
2672 return m_marginLeft;
2673 }
2674 #endif
2675
2676 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2677 {
2678 return DEFAULT_TEXT_INDENT;
2679 }
2680
2681 void wxComboCtrlBase::SetTextCtrlStyle( int style )
2682 {
2683 m_textCtrlStyle = style;
2684
2685 if ( m_text )
2686 m_text->SetWindowStyle(style);
2687 }
2688
2689 // ----------------------------------------------------------------------------
2690 // wxTextEntry interface
2691 // ----------------------------------------------------------------------------
2692
2693 wxString wxComboCtrlBase::DoGetValue() const
2694 {
2695 if ( m_text )
2696 return m_text->GetValue();
2697 return m_valueString;
2698 }
2699
2700 void wxComboCtrlBase::SetValueWithEvent(const wxString& value,
2701 bool withEvent)
2702 {
2703 DoSetValue(value, withEvent ? SetValue_SendEvent : 0);
2704 }
2705
2706 void wxComboCtrlBase::OnSetValue(const wxString& value)
2707 {
2708 // Note: before wxComboCtrl inherited from wxTextEntry,
2709 // this code used to be in SetValueWithEvent().
2710
2711 // Since wxComboPopup may want to paint the combo as well, we need
2712 // to set the string value here (as well as sometimes in ShowPopup).
2713 if ( m_valueString != value )
2714 {
2715 bool found = true;
2716 wxString trueValue = value;
2717
2718 // Conform to wxComboBox behaviour: read-only control can only accept
2719 // valid list items and empty string
2720 if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() )
2721 {
2722 found = m_popupInterface->FindItem(value,
2723 &trueValue);
2724 }
2725
2726 if ( found )
2727 {
2728 m_valueString = trueValue;
2729
2730 EnsurePopupControl();
2731
2732 if ( m_popupInterface )
2733 m_popupInterface->SetStringValue(trueValue);
2734 }
2735 }
2736
2737 Refresh();
2738 }
2739
2740 void wxComboCtrlBase::SetValueByUser(const wxString& value)
2741 {
2742 // NB: Order of function calls is important here. Otherwise
2743 // the SelectAll() may not work.
2744
2745 if ( m_text )
2746 {
2747 m_text->SetValue(value);
2748
2749 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2750 m_text->SelectAll();
2751 }
2752
2753 OnSetValue(value);
2754 }
2755
2756 // In this SetValue variant wxComboPopup::SetStringValue is not called
2757 void wxComboCtrlBase::SetText(const wxString& value)
2758 {
2759 // Unlike in SetValue(), this must be called here or
2760 // the behaviour will no be consistent in readonlys.
2761 EnsurePopupControl();
2762
2763 m_valueString = value;
2764
2765 if ( m_text )
2766 {
2767 m_ignoreEvtText++;
2768 m_text->SetValue( value );
2769 }
2770
2771 Refresh();
2772 }
2773
2774 void wxComboCtrlBase::Copy()
2775 {
2776 if ( m_text )
2777 m_text->Copy();
2778 }
2779
2780 void wxComboCtrlBase::Cut()
2781 {
2782 if ( m_text )
2783 m_text->Cut();
2784 }
2785
2786 void wxComboCtrlBase::Paste()
2787 {
2788 if ( m_text )
2789 m_text->Paste();
2790 }
2791
2792 void wxComboCtrlBase::SetInsertionPoint(long pos)
2793 {
2794 if ( m_text )
2795 m_text->SetInsertionPoint(pos);
2796 }
2797
2798 long wxComboCtrlBase::GetInsertionPoint() const
2799 {
2800 if ( m_text )
2801 return m_text->GetInsertionPoint();
2802
2803 return 0;
2804 }
2805
2806 long wxComboCtrlBase::GetLastPosition() const
2807 {
2808 if ( m_text )
2809 return m_text->GetLastPosition();
2810
2811 return 0;
2812 }
2813
2814 void wxComboCtrlBase::WriteText(const wxString& text)
2815 {
2816 if ( m_text )
2817 {
2818 m_text->WriteText(text);
2819 OnSetValue(m_text->GetValue());
2820 }
2821 else
2822 {
2823 OnSetValue(text);
2824 }
2825 }
2826
2827 void wxComboCtrlBase::DoSetValue(const wxString& value, int flags)
2828 {
2829 if ( m_text )
2830 {
2831 if ( flags & SetValue_SendEvent )
2832 m_text->SetValue(value);
2833 else
2834 m_text->ChangeValue(value);
2835 }
2836
2837 OnSetValue(value);
2838 }
2839
2840 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2841 {
2842 if ( m_text )
2843 {
2844 m_text->Replace(from, to, value);
2845 OnSetValue(m_text->GetValue());
2846 }
2847 }
2848
2849 void wxComboCtrlBase::Remove(long from, long to)
2850 {
2851 if ( m_text )
2852 {
2853 m_text->Remove(from, to);
2854 OnSetValue(m_text->GetValue());
2855 }
2856 }
2857
2858 void wxComboCtrlBase::SetSelection(long from, long to)
2859 {
2860 if ( m_text )
2861 m_text->SetSelection(from, to);
2862 }
2863
2864 void wxComboCtrlBase::GetSelection(long *from, long *to) const
2865 {
2866 if ( m_text )
2867 {
2868 m_text->GetSelection(from, to);
2869 }
2870 else
2871 {
2872 *from = 0;
2873 *to = 0;
2874 }
2875 }
2876
2877 bool wxComboCtrlBase::IsEditable() const
2878 {
2879 if ( m_text )
2880 return m_text->IsEditable();
2881 return false;
2882 }
2883
2884 void wxComboCtrlBase::SetEditable(bool editable)
2885 {
2886 if ( m_text )
2887 m_text->SetEditable(editable);
2888 }
2889
2890 void wxComboCtrlBase::Undo()
2891 {
2892 if ( m_text )
2893 m_text->Undo();
2894 }
2895
2896 void wxComboCtrlBase::Redo()
2897 {
2898 if ( m_text )
2899 m_text->Redo();
2900 }
2901
2902 bool wxComboCtrlBase::CanUndo() const
2903 {
2904 if ( m_text )
2905 return m_text->CanUndo();
2906
2907 return false;
2908 }
2909
2910 bool wxComboCtrlBase::CanRedo() const
2911 {
2912 if ( m_text )
2913 return m_text->CanRedo();
2914
2915 return false;
2916 }
2917
2918 bool wxComboCtrlBase::SetHint(const wxString& hint)
2919 {
2920 m_hintText = hint;
2921 bool res = true;
2922 if ( m_text )
2923 res = m_text->SetHint(hint);
2924 Refresh();
2925 return res;
2926 }
2927
2928 wxString wxComboCtrlBase::GetHint() const
2929 {
2930 return m_hintText;
2931 }
2932
2933 #endif // wxUSE_COMBOCTRL