]> git.saurik.com Git - wxWidgets.git/blob - src/common/combocmn.cpp
Increase the number of visible OS X combo items.
[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 // Copyright: (c) 2005 Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/wxprec.h"
20
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24
25 #include "wx/combo.h"
26
27 #ifdef __WXMSW__
28 #include "wx/msw/private.h"
29 #endif
30
31 #if wxUSE_COMBOBOX
32 #include "wx/combobox.h"
33 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr[] = "comboBox";
34
35 // ----------------------------------------------------------------------------
36 // XTI
37 // ----------------------------------------------------------------------------
38
39 wxDEFINE_FLAGS( wxComboBoxStyle )
40 wxBEGIN_FLAGS( wxComboBoxStyle )
41 // new style border flags, we put them first to
42 // use them for streaming out
43 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
44 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
45 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
46 wxFLAGS_MEMBER(wxBORDER_RAISED)
47 wxFLAGS_MEMBER(wxBORDER_STATIC)
48 wxFLAGS_MEMBER(wxBORDER_NONE)
49
50 // old style border flags
51 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
52 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
53 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
54 wxFLAGS_MEMBER(wxRAISED_BORDER)
55 wxFLAGS_MEMBER(wxSTATIC_BORDER)
56 wxFLAGS_MEMBER(wxBORDER)
57
58 // standard window styles
59 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
60 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
61 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
62 wxFLAGS_MEMBER(wxWANTS_CHARS)
63 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
64 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
65 wxFLAGS_MEMBER(wxVSCROLL)
66 wxFLAGS_MEMBER(wxHSCROLL)
67
68 wxFLAGS_MEMBER(wxCB_SIMPLE)
69 wxFLAGS_MEMBER(wxCB_SORT)
70 wxFLAGS_MEMBER(wxCB_READONLY)
71 wxFLAGS_MEMBER(wxCB_DROPDOWN)
72
73 wxEND_FLAGS( wxComboBoxStyle )
74
75 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl, "wx/combobox.h")
76
77 wxBEGIN_PROPERTIES_TABLE(wxComboBox)
78 wxEVENT_PROPERTY( Select, wxEVT_COMBOBOX, wxCommandEvent )
79 wxEVENT_PROPERTY( TextEnter, wxEVT_TEXT_ENTER, wxCommandEvent )
80
81 // TODO DELEGATES
82 wxPROPERTY( Font, wxFont, SetFont, GetFont, wxEMPTY_PARAMETER_VALUE, \
83 0 /*flags*/, wxT("Helpstring"), wxT("group"))
84 wxPROPERTY_COLLECTION( Choices, wxArrayString, wxString, AppendString, \
85 GetStrings, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
86 wxPROPERTY( Value,wxString, SetValue, GetValue, wxEMPTY_PARAMETER_VALUE, \
87 0 /*flags*/, wxT("Helpstring"), wxT("group"))
88 wxPROPERTY( Selection,int, SetSelection, GetSelection, wxEMPTY_PARAMETER_VALUE, \
89 0 /*flags*/, wxT("Helpstring"), wxT("group"))
90
91 wxPROPERTY_FLAGS( WindowStyle, wxComboBoxStyle, long, SetWindowStyleFlag, \
92 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
93 wxT("Helpstring"), wxT("group")) // style
94 wxEND_PROPERTIES_TABLE()
95
96 wxEMPTY_HANDLERS_TABLE(wxComboBox)
97
98 wxCONSTRUCTOR_5( wxComboBox, wxWindow*, Parent, wxWindowID, Id, \
99 wxString, Value, wxPoint, Position, wxSize, Size )
100
101 #endif // wxUSE_COMBOBOX
102
103 #if wxUSE_COMBOCTRL
104
105 #ifndef WX_PRECOMP
106 #include "wx/app.h"
107 #include "wx/log.h"
108 #include "wx/dcclient.h"
109 #include "wx/settings.h"
110 #include "wx/timer.h"
111 #include "wx/textctrl.h"
112 #endif
113
114 #include "wx/tooltip.h"
115
116 // constants
117 // ----------------------------------------------------------------------------
118
119 #define DEFAULT_DROPBUTTON_WIDTH 19
120
121 #define BMP_BUTTON_MARGIN 4
122
123 #define DEFAULT_POPUP_HEIGHT 400
124
125 #define DEFAULT_TEXT_INDENT 3
126
127 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
128
129
130 #if defined(__WXMSW__)
131
132 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
133 #include "wx/frame.h"
134 #define wxCC_GENERIC_TLW_IS_FRAME
135 #define wxComboCtrlGenericTLW wxFrame
136
137 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
138 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
139 // native controls work on it like normal.
140 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
141 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
142 #define FOCUS_RING 0 // No focus ring on wxMSW
143
144 //#undef wxUSE_POPUPWIN
145 //#define wxUSE_POPUPWIN 0
146
147 #elif defined(__WXGTK__)
148
149 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
150 // this bug: If wxDialog is hidden, its position becomes corrupt
151 // between hide and next show, but without internal coordinates being
152 // reflected (or something like that - atleast commenting out ->Hide()
153 // seemed to eliminate the position change).
154
155 #include "wx/dialog.h"
156 #define wxCC_GENERIC_TLW_IS_DIALOG
157 #define wxComboCtrlGenericTLW wxDialog
158
159 #if defined(__WXGTK20__)
160 # include "wx/gtk/private.h"
161 #else
162 # include "wx/gtk1/private.h"
163 #endif
164
165 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
166 // 'perfect' popup, as it can successfully host child controls even in
167 // popups that are shown in modal dialogs.
168
169 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
170 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
171 // native controls work on it like normal.
172 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
173 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
174 #define FOCUS_RING 0 // No focus ring on wxGTK
175
176 #elif defined(__WXMAC__)
177
178 #include "wx/nonownedwnd.h"
179 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
180 #define wxComboCtrlGenericTLW wxNonOwnedWindow
181
182 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
183 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
184 // native controls work on it like normal.
185 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
186 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
187 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
188
189 #undef DEFAULT_DROPBUTTON_WIDTH
190 #define DEFAULT_DROPBUTTON_WIDTH 22
191 #undef COMBO_MARGIN
192 #define COMBO_MARGIN FOCUS_RING
193
194 #else
195
196 #include "wx/dialog.h"
197 #define wxCC_GENERIC_TLW_IS_DIALOG
198 #define wxComboCtrlGenericTLW wxDialog
199
200 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
201 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
202 // native controls work on it like normal.
203 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
204 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
205 #define FOCUS_RING 0
206
207 #endif
208
209
210 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
211 // what the wxUSE_POPUPWIN says.
212 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
213 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
214 #undef wxUSE_POPUPWIN
215 #define wxUSE_POPUPWIN 0
216 #endif
217
218
219 #if wxUSE_POPUPWIN
220 #include "wx/popupwin.h"
221 #else
222 #undef USE_TRANSIENT_POPUP
223 #define USE_TRANSIENT_POPUP 0
224 #endif
225
226
227 // Define different types of popup windows
228 enum
229 {
230 POPUPWIN_NONE = 0,
231 POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1,
232 POPUPWIN_WXPOPUPWINDOW = 2,
233 POPUPWIN_GENERICTLW = 3
234 };
235
236
237 #if USE_TRANSIENT_POPUP
238 // wxPopupTransientWindow is implemented
239
240 #define wxComboPopupWindowBase wxPopupTransientWindow
241 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
242 #define USES_WXPOPUPTRANSIENTWINDOW 1
243
244 #if TRANSIENT_POPUPWIN_IS_PERFECT
245 //
246 #elif POPUPWIN_IS_PERFECT
247 #define wxComboPopupWindowBase2 wxPopupWindow
248 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
249 #define USES_WXPOPUPWINDOW 1
250 #else
251 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
252 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
253 #define USES_GENERICTLW 1
254 #endif
255
256 #elif wxUSE_POPUPWIN
257 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
258
259 #define wxComboPopupWindowBase wxPopupWindow
260 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
261 #define USES_WXPOPUPWINDOW 1
262
263 #if !POPUPWIN_IS_PERFECT
264 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
265 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
266 #define USES_GENERICTLW 1
267 #endif
268
269 #else
270 // wxPopupWindow is not implemented
271
272 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
273 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
274 #define USES_GENERICTLW 1
275
276 #endif
277
278
279 #ifndef USES_WXPOPUPTRANSIENTWINDOW
280 #define USES_WXPOPUPTRANSIENTWINDOW 0
281 #endif
282
283 #ifndef USES_WXPOPUPWINDOW
284 #define USES_WXPOPUPWINDOW 0
285 #endif
286
287 #ifndef USES_GENERICTLW
288 #define USES_GENERICTLW 0
289 #endif
290
291
292 #if USES_WXPOPUPWINDOW
293 #define INSTALL_TOPLEV_HANDLER 1
294 #else
295 #define INSTALL_TOPLEV_HANDLER 0
296 #endif
297
298
299 // Returns true if given popup window type can be classified as perfect
300 // on this platform.
301 static inline bool IsPopupWinTypePerfect( wxByte popupWinType )
302 {
303 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
304 wxUnusedVar(popupWinType);
305 return true;
306 #else
307 return ( popupWinType == POPUPWIN_GENERICTLW
308 #if POPUPWIN_IS_PERFECT
309 || popupWinType == POPUPWIN_WXPOPUPWINDOW
310 #endif
311 #if TRANSIENT_POPUPWIN_IS_PERFECT
312 || popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW
313 #endif
314 );
315 #endif
316 }
317
318
319 //
320 // ** TODO **
321 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
322 //
323
324
325 // ----------------------------------------------------------------------------
326 // wxComboFrameEventHandler takes care of hiding the popup when events happen
327 // in its top level parent.
328 // ----------------------------------------------------------------------------
329
330 #if INSTALL_TOPLEV_HANDLER
331
332 //
333 // This will no longer be necessary after wxTransientPopupWindow
334 // works well on all platforms.
335 //
336
337 class wxComboFrameEventHandler : public wxEvtHandler
338 {
339 public:
340 wxComboFrameEventHandler( wxComboCtrlBase* pCb );
341 virtual ~wxComboFrameEventHandler();
342
343 void OnPopup();
344
345 void OnIdle( wxIdleEvent& event );
346 void OnMouseEvent( wxMouseEvent& event );
347 void OnActivate( wxActivateEvent& event );
348 void OnResize( wxSizeEvent& event );
349 void OnMove( wxMoveEvent& event );
350 void OnMenuEvent( wxMenuEvent& event );
351 void OnClose( wxCloseEvent& event );
352
353 protected:
354 wxWindow* m_focusStart;
355 wxComboCtrlBase* m_combo;
356
357 private:
358 DECLARE_EVENT_TABLE()
359 };
360
361 BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler)
362 EVT_IDLE(wxComboFrameEventHandler::OnIdle)
363 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
364 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
365 EVT_SIZE(wxComboFrameEventHandler::OnResize)
366 EVT_MOVE(wxComboFrameEventHandler::OnMove)
367 EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent)
368 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent)
369 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate)
370 EVT_CLOSE(wxComboFrameEventHandler::OnClose)
371 END_EVENT_TABLE()
372
373 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase* combo )
374 : wxEvtHandler()
375 {
376 m_combo = combo;
377 }
378
379 wxComboFrameEventHandler::~wxComboFrameEventHandler()
380 {
381 }
382
383 void wxComboFrameEventHandler::OnPopup()
384 {
385 m_focusStart = ::wxWindow::FindFocus();
386 }
387
388 void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
389 {
390 wxWindow* winFocused = ::wxWindow::FindFocus();
391
392 wxWindow* popup = m_combo->GetPopupControl()->GetControl();
393 wxWindow* winpopup = m_combo->GetPopupWindow();
394
395 if ( !winFocused || (
396 winFocused != m_focusStart &&
397 winFocused != popup &&
398 winFocused->GetParent() != popup &&
399 winFocused != winpopup &&
400 winFocused->GetParent() != winpopup &&
401 winFocused != m_combo &&
402 winFocused != m_combo->GetButton() // GTK (atleast) requires this
403 )
404 )
405 {
406 m_combo->HidePopup(true);
407 }
408
409 event.Skip();
410 }
411
412 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
413 {
414 m_combo->HidePopup(true);
415 event.Skip();
416 }
417
418 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
419 {
420 m_combo->HidePopup(true);
421 event.Skip();
422 }
423
424 void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
425 {
426 m_combo->HidePopup(true);
427 event.Skip();
428 }
429
430 void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
431 {
432 m_combo->HidePopup(true);
433 event.Skip();
434 }
435
436 void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
437 {
438 m_combo->HidePopup(true);
439 event.Skip();
440 }
441
442 void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
443 {
444 m_combo->HidePopup(true);
445 event.Skip();
446 }
447
448 #endif // INSTALL_TOPLEV_HANDLER
449
450 // ----------------------------------------------------------------------------
451 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
452 // wxComboCtrl.
453 // ----------------------------------------------------------------------------
454
455 class wxComboPopupWindow : public wxComboPopupWindowBase
456 {
457 public:
458
459 wxComboPopupWindow( wxComboCtrlBase *parent,
460 int style )
461 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
462 : wxComboPopupWindowBase(parent,style)
463 #else
464 : wxComboPopupWindowBase(parent,
465 wxID_ANY,
466 wxEmptyString,
467 wxPoint(-21,-21),
468 wxSize(20,20),
469 style)
470 #endif
471 {
472 m_inShow = 0;
473 }
474
475 #if USES_WXPOPUPTRANSIENTWINDOW
476 virtual bool Show( bool show );
477 virtual bool ProcessLeftDown(wxMouseEvent& event);
478 protected:
479 virtual void OnDismiss();
480 #endif
481
482 private:
483 wxByte m_inShow;
484 };
485
486
487 #if USES_WXPOPUPTRANSIENTWINDOW
488 bool wxComboPopupWindow::Show( bool show )
489 {
490 // Guard against recursion
491 if ( m_inShow )
492 return wxComboPopupWindowBase::Show(show);
493
494 m_inShow++;
495
496 wxPopupTransientWindow* const
497 ptw = static_cast<wxPopupTransientWindow*>(this);
498
499 if ( show != ptw->IsShown() )
500 {
501 if ( show )
502 // We used to do wxPopupTransientWindow::Popup here,
503 // but this would hide normal Show, which we are
504 // also going to need.
505 ptw->Show();
506 else
507 ptw->Dismiss();
508 }
509
510 m_inShow--;
511
512 return true;
513 }
514
515 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event)
516 {
517 return wxPopupTransientWindow::ProcessLeftDown(event);
518 }
519
520 // First thing that happens when a transient popup closes is that this method gets called.
521 void wxComboPopupWindow::OnDismiss()
522 {
523 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
524 wxASSERT_MSG( wxDynamicCast(combo, wxComboCtrlBase),
525 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
526
527 combo->OnPopupDismiss(true);
528 }
529 #endif // USES_WXPOPUPTRANSIENTWINDOW
530
531
532 // ----------------------------------------------------------------------------
533 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
534 // of a popup window. It is separate so we can have different types
535 // of popup windows.
536 // ----------------------------------------------------------------------------
537
538 class wxComboPopupWindowEvtHandler : public wxEvtHandler
539 {
540 public:
541
542 wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent )
543 {
544 m_combo = parent;
545 }
546
547 void OnSizeEvent( wxSizeEvent& event );
548 void OnKeyEvent(wxKeyEvent& event);
549 #if USES_GENERICTLW
550 void OnActivate( wxActivateEvent& event );
551 #endif
552
553 private:
554 wxComboCtrlBase* m_combo;
555
556 DECLARE_EVENT_TABLE()
557 };
558
559
560 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler)
561 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent)
562 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent)
563 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent)
564 #if USES_GENERICTLW
565 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate)
566 #endif
567 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent)
568 END_EVENT_TABLE()
569
570
571 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) )
572 {
573 // Block the event so that the popup control does not get auto-resized.
574 }
575
576 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
577 {
578 // Relay keyboard event to the main child controls
579 wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
580 wxWindowList::iterator node = children.begin();
581 wxWindow* child = (wxWindow*)*node;
582 child->GetEventHandler()->ProcessEvent(event);
583 }
584
585 #if USES_GENERICTLW
586 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
587 {
588 if ( !event.GetActive() )
589 {
590 // Tell combo control that we are dismissed.
591 m_combo->HidePopup(true);
592
593 event.Skip();
594 }
595 }
596 #endif
597
598
599 // ----------------------------------------------------------------------------
600 // wxComboPopup
601 //
602 // ----------------------------------------------------------------------------
603
604 wxComboPopup::~wxComboPopup()
605 {
606 }
607
608 void wxComboPopup::OnPopup()
609 {
610 }
611
612 void wxComboPopup::OnDismiss()
613 {
614 }
615
616 wxComboCtrl* wxComboPopup::GetComboCtrl() const
617 {
618 return wxStaticCast(m_combo, wxComboCtrl);
619 }
620
621 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
622 int prefHeight,
623 int WXUNUSED(maxHeight) )
624 {
625 return wxSize(minWidth,prefHeight);
626 }
627
628 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
629 wxDC& dc, const wxRect& rect )
630 {
631 if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
632 {
633 combo->PrepareBackground(dc,rect,0);
634
635 dc.DrawText( combo->GetValue(),
636 rect.x + combo->m_marginLeft,
637 (rect.height-dc.GetCharHeight())/2 + rect.y );
638 }
639 }
640
641 void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
642 {
643 DefaultPaintComboControl(m_combo,dc,rect);
644 }
645
646 void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
647 {
648 event.Skip();
649 }
650
651 void wxComboPopup::OnComboCharEvent( wxKeyEvent& event )
652 {
653 event.Skip();
654 }
655
656 void wxComboPopup::OnComboDoubleClick()
657 {
658 }
659
660 void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
661 {
662 }
663
664 bool wxComboPopup::FindItem(const wxString& WXUNUSED(item),
665 wxString* WXUNUSED(trueItem))
666 {
667 return true;
668 }
669
670 bool wxComboPopup::LazyCreate()
671 {
672 return false;
673 }
674
675 void wxComboPopup::Dismiss()
676 {
677 m_combo->HidePopup(true);
678 }
679
680 void wxComboPopup::DestroyPopup()
681 {
682 // Here we make sure that the popup control's Destroy() gets called.
683 // This is necessary for the wxPersistentWindow to work properly.
684 wxWindow* popupCtrl = GetControl();
685 if ( popupCtrl )
686 {
687 // While all wxComboCtrl examples have m_popupInterface and
688 // popupCtrl as the same class (that will be deleted via the
689 // Destroy() call below), it is technically still possible to
690 // have implementations where they are in fact not same
691 // multiple-inherited class. Here we use C++ RTTI to check for
692 // this rare case.
693 #ifndef wxNO_RTTI
694 // It is probably better to delete m_popupInterface first, so
695 // that it retains access to its popup control window.
696 if ( dynamic_cast<void*>(this) !=
697 dynamic_cast<void*>(popupCtrl) )
698 delete this;
699 #endif
700 popupCtrl->Destroy();
701 }
702 else
703 {
704 delete this;
705 }
706 }
707
708 // ----------------------------------------------------------------------------
709 // input handling
710 // ----------------------------------------------------------------------------
711
712 //
713 // This is pushed to the event handler queue of the child textctrl.
714 //
715 class wxComboBoxExtraInputHandler : public wxEvtHandler
716 {
717 public:
718
719 wxComboBoxExtraInputHandler( wxComboCtrlBase* combo )
720 : wxEvtHandler()
721 {
722 m_combo = combo;
723 }
724 virtual ~wxComboBoxExtraInputHandler() { }
725 void OnKey(wxKeyEvent& event);
726 void OnFocus(wxFocusEvent& event);
727
728 protected:
729 wxComboCtrlBase* m_combo;
730
731 private:
732 DECLARE_EVENT_TABLE()
733 };
734
735
736 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
737 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
738 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey)
739 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey)
740 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
741 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
742 END_EVENT_TABLE()
743
744
745 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event)
746 {
747 // Let the wxComboCtrl event handler have a go first.
748 wxComboCtrlBase* combo = m_combo;
749
750 wxKeyEvent redirectedEvent(event);
751 redirectedEvent.SetId(combo->GetId());
752 redirectedEvent.SetEventObject(combo);
753
754 if ( !combo->GetEventHandler()->ProcessEvent(redirectedEvent) )
755 {
756 // Don't let TAB through to the text ctrl - looks ugly
757 if ( event.GetKeyCode() != WXK_TAB )
758 event.Skip();
759 }
760 }
761
762 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
763 {
764 // FIXME: This code does run when control is clicked,
765 // yet on Windows it doesn't select all the text.
766 if ( event.GetEventType() == wxEVT_SET_FOCUS &&
767 !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) )
768 {
769 if ( m_combo->GetTextCtrl() )
770 m_combo->GetTextCtrl()->SelectAll();
771 else
772 m_combo->SelectAll();
773 }
774
775 // Send focus indication to parent.
776 // NB: This is needed for cases where the textctrl gets focus
777 // instead of its parent. While this may trigger multiple
778 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
779 // from combo's focus event handler), they should be quite
780 // harmless.
781 wxFocusEvent evt2(event);
782 evt2.SetId(m_combo->GetId());
783 evt2.SetEventObject(m_combo);
784 m_combo->GetEventHandler()->ProcessEvent(evt2);
785
786 event.Skip();
787 }
788
789
790 //
791 // This is pushed to the event handler queue of the control in popup.
792 //
793
794 class wxComboPopupEvtHandler : public wxEvtHandler
795 {
796 public:
797
798 wxComboPopupEvtHandler( wxComboCtrlBase* combo )
799 : wxEvtHandler()
800 {
801 m_combo = combo;
802 m_beenInside = false;
803
804 // Let's make it so that the popup control will not receive mouse
805 // events until mouse left button has been up.
806 m_blockEventsToPopup = true;
807 }
808 virtual ~wxComboPopupEvtHandler() { }
809
810 void OnMouseEvent( wxMouseEvent& event );
811
812 // Called from wxComboCtrlBase::OnPopupDismiss
813 void OnPopupDismiss()
814 {
815 m_beenInside = false;
816 m_blockEventsToPopup = true;
817 }
818
819 protected:
820 wxComboCtrlBase* m_combo;
821
822 bool m_beenInside;
823 bool m_blockEventsToPopup;
824
825 private:
826 DECLARE_EVENT_TABLE()
827 };
828
829
830 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler, wxEvtHandler)
831 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent)
832 END_EVENT_TABLE()
833
834
835 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent& event )
836 {
837 wxPoint pt = event.GetPosition();
838 wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize();
839 int evtType = event.GetEventType();
840 bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y;
841 bool relayToButton = false;
842
843 event.Skip();
844
845 if ( !isInside || !m_combo->IsPopupShown() )
846 {
847 // Mouse is outside the popup or popup is not actually shown (yet)
848
849 if ( evtType == wxEVT_MOTION ||
850 evtType == wxEVT_LEFT_DOWN ||
851 evtType == wxEVT_LEFT_UP ||
852 evtType == wxEVT_RIGHT_DOWN )
853 {
854 // Block motion and click events outside the popup
855 event.Skip(false);
856 }
857 }
858 else
859 {
860 // Mouse is inside the popup, which is fully shown
861
862 m_beenInside = true;
863
864 // Do not let the popup control respond to mouse events until
865 // mouse press used to display the popup has been lifted. This
866 // is important for users with slower mouse fingers or mouse
867 // drivers. Note that we have some redundancy here, just in
868 // case the popup is some native control that does not emit all
869 // mouse event types.
870 if ( evtType == wxEVT_MOTION )
871 {
872 if ( m_blockEventsToPopup )
873 {
874 if ( event.LeftIsDown() )
875 event.Skip(false);
876 else
877 m_blockEventsToPopup = false;
878 }
879 }
880 else if ( evtType == wxEVT_LEFT_DOWN )
881 {
882 if ( m_blockEventsToPopup )
883 m_blockEventsToPopup = false;
884 }
885 else if ( evtType == wxEVT_LEFT_UP )
886 {
887 if ( m_blockEventsToPopup )
888 {
889 // On first left up, stop blocking mouse events (but still
890 // block this one)
891 m_blockEventsToPopup = false;
892 event.Skip(false);
893
894 // Also, this button press was (probably) used to display
895 // the popup, so relay it back to the drop-down button
896 // (which supposedly originated it). This is necessary to
897 // refresh it properly.
898 relayToButton = true;
899 }
900 }
901 else if ( m_blockEventsToPopup )
902 {
903 event.Skip(false);
904 }
905 }
906
907 //
908 // Some mouse events to popup that happen outside it, before cursor
909 // has been inside the popup, need to be ignored by it but relayed to
910 // the dropbutton.
911 //
912 if ( evtType == wxEVT_LEFT_UP )
913 {
914 if ( !m_combo->IsPopupShown() )
915 {
916 event.Skip(false);
917 relayToButton = true;
918 }
919 else if ( !isInside && !m_beenInside )
920 {
921 // Popup is shown but the cursor is not inside, nor it has been
922 relayToButton = true;
923 }
924 }
925
926 if ( relayToButton )
927 {
928 wxWindow* btn = m_combo->GetButton();
929 if ( btn )
930 btn->GetEventHandler()->ProcessEvent(event);
931 else
932 // Bypass the event handling mechanism. Using it would be
933 // confusing for the platform-specific wxComboCtrl
934 // implementations.
935 m_combo->HandleButtonMouseEvent(event, 0);
936 }
937 }
938
939 // ----------------------------------------------------------------------------
940 // wxComboCtrlTextCtrl
941 // ----------------------------------------------------------------------------
942
943 class wxComboCtrlTextCtrl : public wxTextCtrl
944 {
945 public:
946 wxComboCtrlTextCtrl() : wxTextCtrl() { }
947 virtual ~wxComboCtrlTextCtrl() { }
948
949 virtual wxWindow *GetMainWindowOfCompositeControl()
950 {
951 wxComboCtrl* combo = (wxComboCtrl*) GetParent();
952
953 // Returning this instead of just 'parent' lets FindFocus work
954 // correctly even when parent control is a child of a composite
955 // generic control (as is case with wxGenericDatePickerCtrl).
956 return combo->GetMainWindowOfCompositeControl();
957 }
958 };
959
960 // ----------------------------------------------------------------------------
961 // wxComboCtrlBase
962 // ----------------------------------------------------------------------------
963
964
965 BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl)
966 EVT_SIZE(wxComboCtrlBase::OnSizeEvent)
967 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent)
968 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent)
969 EVT_IDLE(wxComboCtrlBase::OnIdleEvent)
970 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
971 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent)
972 EVT_CHAR(wxComboCtrlBase::OnCharEvent)
973 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged)
974 END_EVENT_TABLE()
975
976
977 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
978
979 void wxComboCtrlBase::Init()
980 {
981 m_winPopup = NULL;
982 m_popup = NULL;
983 m_popupWinState = Hidden;
984 m_btn = NULL;
985 m_text = NULL;
986 m_popupInterface = NULL;
987
988 m_popupEvtHandler = NULL;
989 m_textEvtHandler = NULL;
990
991 #if INSTALL_TOPLEV_HANDLER
992 m_toplevEvtHandler = NULL;
993 #endif
994
995 m_mainCtrlWnd = this;
996
997 m_heightPopup = -1;
998 m_widthMinPopup = -1;
999 m_anchorSide = 0;
1000 m_widthCustomPaint = 0;
1001 m_widthCustomBorder = 0;
1002
1003 m_btnState = 0;
1004 m_btnWidDefault = 0;
1005 m_blankButtonBg = false;
1006 m_ignoreEvtText = 0;
1007 m_popupWinType = POPUPWIN_NONE;
1008 m_btnWid = m_btnHei = -1;
1009 m_btnSide = wxRIGHT;
1010 m_btnSpacingX = 0;
1011
1012 m_extLeft = 0;
1013 m_extRight = 0;
1014 m_marginLeft = -1;
1015 m_iFlags = 0;
1016 m_textCtrlStyle = 0;
1017 m_timeCanAcceptClick = 0;
1018
1019 m_resetFocus = false;
1020 m_hasTcBgCol = false;
1021 }
1022
1023 bool wxComboCtrlBase::Create(wxWindow *parent,
1024 wxWindowID id,
1025 const wxString& value,
1026 const wxPoint& pos,
1027 const wxSize& size,
1028 long style,
1029 const wxValidator& validator,
1030 const wxString& name)
1031 {
1032 if ( !wxControl::Create(parent,
1033 id,
1034 pos,
1035 size,
1036 style | wxWANTS_CHARS,
1037 validator,
1038 name) )
1039 return false;
1040
1041 m_valueString = value;
1042
1043 // Get colours
1044 OnThemeChange();
1045 m_marginLeft = GetNativeTextIndent();
1046
1047 m_iFlags |= wxCC_IFLAG_CREATED;
1048
1049 // If x and y indicate valid size, wxSizeEvent won't be
1050 // emitted automatically, so we need to add artificial one.
1051 if ( size.x > 0 && size.y > 0 )
1052 {
1053 wxSizeEvent evt(size,GetId());
1054 evt.SetEventObject(this);
1055 GetEventHandler()->AddPendingEvent(evt);
1056 }
1057
1058 return true;
1059 }
1060
1061 void wxComboCtrlBase::InstallInputHandlers()
1062 {
1063 if ( m_text )
1064 {
1065 m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
1066 m_text->PushEventHandler(m_textEvtHandler);
1067 }
1068 }
1069
1070 void
1071 wxComboCtrlBase::CreateTextCtrl(int style)
1072 {
1073 if ( !(m_windowStyle & wxCB_READONLY) )
1074 {
1075 if ( m_text )
1076 m_text->Destroy();
1077
1078 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1079 // not used by the wxPropertyGrid and therefore the tab is processed by
1080 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1081 // navigation event is then sent to the wrong window.
1082 style |= wxTE_PROCESS_TAB | m_textCtrlStyle;
1083
1084 if ( HasFlag(wxTE_PROCESS_ENTER) )
1085 style |= wxTE_PROCESS_ENTER;
1086
1087 // Ignore EVT_TEXT generated by the constructor (but only
1088 // if the event redirector already exists)
1089 // NB: This must be " = 1" instead of "++";
1090 if ( m_textEvtHandler )
1091 m_ignoreEvtText = 1;
1092 else
1093 m_ignoreEvtText = 0;
1094
1095 m_text = new wxComboCtrlTextCtrl();
1096 m_text->Create(this, wxID_ANY, m_valueString,
1097 wxDefaultPosition, wxSize(10,-1),
1098 style);
1099
1100 // Connecting the events is currently the most reliable way
1101 wxWindowID id = m_text->GetId();
1102 m_text->Connect(id, wxEVT_TEXT,
1103 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent),
1104 NULL, this);
1105 m_text->Connect(id, wxEVT_TEXT_ENTER,
1106 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent),
1107 NULL, this);
1108
1109 m_text->SetHint(m_hintText);
1110 }
1111 }
1112
1113 void wxComboCtrlBase::OnThemeChange()
1114 {
1115 // Because wxComboCtrl has transparent parts on most platforms, we
1116 // don't want to touch the actual background colour. Instead, we just
1117 // usually re-obtain m_tcBgCol here.
1118
1119 #if defined(__WXMSW__) || defined(__WXGTK__)
1120 wxVisualAttributes vattrs = wxComboBox::GetClassDefaultAttributes();
1121 #else
1122 wxVisualAttributes vattrs;
1123 vattrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1124 vattrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1125 #endif
1126
1127 if ( !m_hasTcBgCol )
1128 m_tcBgCol = vattrs.colBg;
1129
1130 #ifndef __WXMAC__
1131 // Only change the colours if application has not specified
1132 // custom ones.
1133 if ( !m_hasFgCol )
1134 {
1135 SetOwnForegroundColour(vattrs.colFg);
1136 }
1137 if ( !HasTransparentBackground() )
1138 {
1139 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1140 }
1141 #endif // !__WXMAC__
1142 }
1143
1144 wxComboCtrlBase::~wxComboCtrlBase()
1145 {
1146 if ( HasCapture() )
1147 ReleaseMouse();
1148
1149 #if INSTALL_TOPLEV_HANDLER
1150 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
1151 m_toplevEvtHandler = NULL;
1152 #endif
1153
1154 DestroyPopup();
1155
1156 if ( m_text )
1157 m_text->RemoveEventHandler(m_textEvtHandler);
1158
1159 delete m_textEvtHandler;
1160 }
1161
1162
1163 // ----------------------------------------------------------------------------
1164 // geometry stuff
1165 // ----------------------------------------------------------------------------
1166
1167 // Recalculates button and textctrl areas
1168 void wxComboCtrlBase::CalculateAreas( int btnWidth )
1169 {
1170 wxSize sz = GetClientSize();
1171 int customBorder = m_widthCustomBorder;
1172 int btnBorder; // border for button only
1173
1174 // check if button should really be outside the border: we'll do it it if
1175 // its platform default or bitmap+pushbutton background is used, but not if
1176 // there is vertical size adjustment or horizontal spacing.
1177 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
1178 (m_bmpNormal.IsOk() && m_blankButtonBg) ) &&
1179 m_btnSpacingX == 0 &&
1180 m_btnHei <= 0 )
1181 {
1182 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
1183 btnBorder = 0;
1184 }
1185 else if ( (m_iFlags & wxCC_BUTTON_COVERS_BORDER) &&
1186 m_btnSpacingX == 0 && !m_bmpNormal.IsOk() )
1187 {
1188 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1189 btnBorder = 0;
1190 }
1191 else
1192 {
1193 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
1194 btnBorder = customBorder;
1195 }
1196
1197 // Defaul indentation
1198 if ( m_marginLeft < 0 )
1199 m_marginLeft = GetNativeTextIndent();
1200
1201 int butWidth = btnWidth;
1202
1203 if ( butWidth <= 0 )
1204 butWidth = m_btnWidDefault;
1205 else
1206 m_btnWidDefault = butWidth;
1207
1208 if ( butWidth <= 0 )
1209 return;
1210
1211 int butHeight = sz.y - btnBorder*2;
1212
1213 // Adjust button width
1214 if ( m_btnWid > 0 )
1215 butWidth = m_btnWid;
1216 else
1217 {
1218 // Adjust button width to match aspect ratio
1219 // (but only if control is smaller than best size).
1220 int bestHeight = GetBestSize().y;
1221 int height = GetSize().y;
1222
1223 if ( height < bestHeight )
1224 {
1225 // Make very small buttons square, as it makes
1226 // them accommodate arrow image better and still
1227 // looks decent.
1228 if ( height > 18 )
1229 butWidth = (height*butWidth)/bestHeight;
1230 else
1231 butWidth = butHeight;
1232 }
1233 }
1234
1235 // Adjust button height
1236 if ( m_btnHei > 0 )
1237 butHeight = m_btnHei;
1238
1239 // Use size of normal bitmap if...
1240 // It is larger
1241 // OR
1242 // button width is set to default and blank button bg is not drawn
1243 if ( m_bmpNormal.IsOk() )
1244 {
1245 int bmpReqWidth = m_bmpNormal.GetWidth();
1246 int bmpReqHeight = m_bmpNormal.GetHeight();
1247
1248 // If drawing blank button background, we need to add some margin.
1249 if ( m_blankButtonBg )
1250 {
1251 bmpReqWidth += BMP_BUTTON_MARGIN*2;
1252 bmpReqHeight += BMP_BUTTON_MARGIN*2;
1253 }
1254
1255 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
1256 butWidth = bmpReqWidth;
1257 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
1258 butHeight = bmpReqHeight;
1259
1260 // Need to fix height?
1261 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
1262 {
1263 int newY = butHeight+(customBorder*2);
1264 SetClientSize(wxDefaultCoord,newY);
1265 if ( m_bmpNormal.IsOk() || m_btnArea.width != butWidth || m_btnArea.height != butHeight )
1266 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1267 else
1268 m_iFlags &= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
1269
1270 sz.y = newY;
1271 }
1272 }
1273
1274 int butAreaWid = butWidth + (m_btnSpacingX*2);
1275
1276 m_btnSize.x = butWidth;
1277 m_btnSize.y = butHeight;
1278
1279 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
1280 m_btnArea.y = btnBorder + FOCUS_RING;
1281 m_btnArea.width = butAreaWid;
1282 m_btnArea.height = sz.y - ((btnBorder+FOCUS_RING)*2);
1283
1284 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder + FOCUS_RING;
1285 m_tcArea.y = customBorder + FOCUS_RING;
1286 m_tcArea.width = sz.x - butAreaWid - (customBorder*2) - (FOCUS_RING*2);
1287 m_tcArea.height = sz.y - ((customBorder+FOCUS_RING)*2);
1288
1289 /*
1290 if ( m_text )
1291 {
1292 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1293 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1294 }
1295 */
1296 }
1297
1298 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
1299 {
1300 if ( !m_text )
1301 return;
1302
1303 wxSize sz = GetClientSize();
1304
1305 int customBorder = m_widthCustomBorder;
1306 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
1307 {
1308 int x;
1309
1310 if ( !m_widthCustomPaint )
1311 {
1312 // No special custom paint area - we can use 0 left margin
1313 // with wxTextCtrl.
1314 if ( m_text->SetMargins(0) )
1315 textCtrlXAdjust = 0;
1316 x = m_tcArea.x + m_marginLeft + textCtrlXAdjust;
1317 }
1318 else
1319 {
1320 // There is special custom paint area - it is better to
1321 // use some margin with the wxTextCtrl.
1322 m_text->SetMargins(m_marginLeft);
1323 x = m_tcArea.x + m_widthCustomPaint +
1324 m_marginLeft + textCtrlXAdjust;
1325 }
1326
1327 // Centre textctrl vertically, if needed
1328 #if !TEXTCTRL_TEXT_CENTERED
1329 int tcSizeY = m_text->GetBestSize().y;
1330 int diff0 = sz.y - tcSizeY;
1331 int y = textCtrlYAdjust + (diff0/2);
1332 #else
1333 wxUnusedVar(textCtrlYAdjust);
1334 int y = 0;
1335 #endif
1336
1337 if ( y < customBorder )
1338 y = customBorder;
1339
1340 m_text->SetSize(x,
1341 y,
1342 m_tcArea.width - m_tcArea.x - x,
1343 -1 );
1344
1345 // Make sure textctrl doesn't exceed the bottom custom border
1346 wxSize tsz = m_text->GetSize();
1347 int diff1 = (y + tsz.y) - (sz.y - customBorder);
1348 if ( diff1 >= 0 )
1349 {
1350 tsz.y = tsz.y - diff1 - 1;
1351 m_text->SetSize(tsz);
1352 }
1353 }
1354 else
1355 {
1356 // If it has border, have textctrl fill the entire text field.
1357 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1358 m_tcArea.y,
1359 m_tcArea.width - m_widthCustomPaint,
1360 m_tcArea.height );
1361 }
1362 }
1363
1364 wxSize wxComboCtrlBase::DoGetBestSize() const
1365 {
1366 int width = m_text ? m_text->GetBestSize().x : 80;
1367
1368 return GetSizeFromTextSize(width);
1369 }
1370
1371 wxSize wxComboCtrlBase::DoGetSizeFromTextSize(int xlen, int ylen) const
1372 {
1373 // Calculate close-to-native control height
1374
1375 int fhei;
1376
1377 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
1378 fhei = EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight());
1379 #elif defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
1380 // Control creation is not entirely cheap, so cache the heights to
1381 // avoid repeatedly creating dummy controls:
1382 static wxString s_last_font;
1383 static int s_last_fhei = -1;
1384 wxString fontdesc;
1385 if ( m_font.IsOk() )
1386 fontdesc = m_font.GetNativeFontInfoDesc();
1387 if ( s_last_fhei != -1 && fontdesc == s_last_font )
1388 {
1389 fhei = s_last_fhei;
1390 }
1391 else
1392 {
1393 wxComboBox* cb = new wxComboBox;
1394 cb->Hide();
1395 cb->Create(const_cast<wxComboCtrlBase*>(this), wxID_ANY);
1396 if ( m_font.IsOk() )
1397 cb->SetFont(m_font);
1398 s_last_font = fontdesc;
1399 s_last_fhei = fhei = cb->GetBestSize().y;
1400 cb->Destroy();
1401 }
1402 #else
1403 if ( m_font.IsOk() )
1404 fhei = (m_font.GetPointSize()*2) + 5;
1405 else if ( wxNORMAL_FONT->IsOk() )
1406 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1407 else
1408 fhei = 22;
1409 #endif // only for wxComboBox on MSW or GTK
1410
1411 // Need to force height to accommodate bitmap?
1412 int btnSizeY = m_btnSize.y;
1413 if ( m_bmpNormal.IsOk() && fhei < btnSizeY )
1414 fhei = btnSizeY;
1415
1416 // Control height doesn't depend on border
1417 /*
1418 // Add border
1419 int border = m_windowStyle & wxBORDER_MASK;
1420 if ( border == wxSIMPLE_BORDER )
1421 fhei += 2;
1422 else if ( border == wxNO_BORDER )
1423 fhei += (m_widthCustomBorder*2);
1424 else
1425 // Sunken etc.
1426 fhei += 4;
1427 */
1428
1429 #ifdef __WXMAC__
1430 // these are the numbers from the HIG:
1431 switch ( m_windowVariant )
1432 {
1433 case wxWINDOW_VARIANT_NORMAL:
1434 default :
1435 fhei = 22;
1436 break;
1437 case wxWINDOW_VARIANT_SMALL:
1438 fhei = 19;
1439 break;
1440 case wxWINDOW_VARIANT_MINI:
1441 fhei = 15;
1442 break;
1443 }
1444 #endif
1445
1446 fhei += 2 * FOCUS_RING;
1447
1448 // Calculate width
1449 int fwid = xlen + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH;
1450
1451 // Add the margins we have previously set
1452 wxPoint marg( GetMargins() );
1453 fwid += wxMax(0, marg.x);
1454 fhei += wxMax(0, marg.y);
1455
1456 if ( ylen > 0 )
1457 fhei += ylen - GetCharHeight();
1458
1459 return wxSize(fwid, fhei);
1460 }
1461
1462 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1463 {
1464 if ( !IsCreated() )
1465 return;
1466
1467 // defined by actual wxComboCtrls
1468 OnResize();
1469
1470 event.Skip();
1471 }
1472
1473 // ----------------------------------------------------------------------------
1474 // standard operations
1475 // ----------------------------------------------------------------------------
1476
1477 bool wxComboCtrlBase::Enable(bool enable)
1478 {
1479 if ( !wxControl::Enable(enable) )
1480 return false;
1481
1482 if ( m_btn )
1483 m_btn->Enable(enable);
1484 if ( m_text )
1485 m_text->Enable(enable);
1486
1487 Refresh();
1488
1489 return true;
1490 }
1491
1492 bool wxComboCtrlBase::Show(bool show)
1493 {
1494 if ( !wxControl::Show(show) )
1495 return false;
1496
1497 if (m_btn)
1498 m_btn->Show(show);
1499
1500 if (m_text)
1501 m_text->Show(show);
1502
1503 return true;
1504 }
1505
1506 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1507 {
1508 if ( !wxControl::SetFont(font) )
1509 return false;
1510
1511 if ( m_text )
1512 {
1513 // Without hiding the wxTextCtrl there would be some
1514 // visible 'flicker' (at least on Windows XP).
1515 m_text->Hide();
1516 m_text->SetFont(font);
1517 OnResize();
1518 m_text->Show();
1519 }
1520
1521 return true;
1522 }
1523
1524 #if wxUSE_TOOLTIPS
1525 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1526 {
1527 wxControl::DoSetToolTip(tooltip);
1528
1529 // Set tool tip for button and text box
1530 if ( tooltip )
1531 {
1532 const wxString &tip = tooltip->GetTip();
1533 if ( m_text ) m_text->SetToolTip(tip);
1534 if ( m_btn ) m_btn->SetToolTip(tip);
1535 }
1536 else
1537 {
1538 if ( m_text ) m_text->SetToolTip( NULL );
1539 if ( m_btn ) m_btn->SetToolTip( NULL );
1540 }
1541 }
1542 #endif // wxUSE_TOOLTIPS
1543
1544 bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour)
1545 {
1546 if ( wxControl::SetForegroundColour(colour) )
1547 {
1548 if ( m_text )
1549 m_text->SetForegroundColour(colour);
1550 return true;
1551 }
1552 return false;
1553 }
1554
1555 bool wxComboCtrlBase::SetBackgroundColour(const wxColour& colour)
1556 {
1557 if ( m_text )
1558 m_text->SetBackgroundColour(colour);
1559 m_tcBgCol = colour;
1560 m_hasTcBgCol = true;
1561 return true;
1562 }
1563
1564 wxColour wxComboCtrlBase::GetBackgroundColour() const
1565 {
1566 if ( m_text )
1567 return m_text->GetBackgroundColour();
1568 return m_tcBgCol;
1569 }
1570
1571 // ----------------------------------------------------------------------------
1572 // painting
1573 // ----------------------------------------------------------------------------
1574
1575 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1576 // prepare combo box background on area in a way typical on platform
1577 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1578 {
1579 wxSize sz = GetClientSize();
1580 bool isEnabled;
1581 bool doDrawFocusRect; // also selected
1582
1583 // For smaller size control (and for disabled background) use less spacing
1584 int focusSpacingX;
1585 int focusSpacingY;
1586
1587 if ( !(flags & wxCONTROL_ISSUBMENU) )
1588 {
1589 // Drawing control
1590 isEnabled = IsEnabled();
1591 doDrawFocusRect = ShouldDrawFocus() && !(m_iFlags & wxCC_FULL_BUTTON);
1592
1593 // Windows-style: for smaller size control (and for disabled background) use less spacing
1594 focusSpacingX = isEnabled ? 2 : 1;
1595 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1596 }
1597 else
1598 {
1599 // Drawing a list item
1600 isEnabled = true; // they are never disabled
1601 doDrawFocusRect = (flags & wxCONTROL_SELECTED) != 0;
1602
1603 focusSpacingX = 0;
1604 focusSpacingY = 0;
1605 }
1606
1607 // Set the background sub-rectangle for selection, disabled etc
1608 wxRect selRect(rect);
1609 selRect.y += focusSpacingY;
1610 selRect.height -= (focusSpacingY*2);
1611
1612 int wcp = 0;
1613
1614 if ( !(flags & wxCONTROL_ISSUBMENU) )
1615 wcp += m_widthCustomPaint;
1616
1617 selRect.x += wcp + focusSpacingX;
1618 selRect.width -= wcp + (focusSpacingX*2);
1619
1620 wxColour bgCol;
1621 wxColour fgCol;
1622
1623 bool doDrawSelRect = true;
1624
1625 // Determine foreground colour
1626 if ( isEnabled )
1627 {
1628 if ( doDrawFocusRect )
1629 {
1630 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1631 }
1632 else if ( m_hasFgCol )
1633 {
1634 // Honour the custom foreground colour
1635 fgCol = GetForegroundColour();
1636 }
1637 else
1638 {
1639 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1640 }
1641 }
1642 else
1643 {
1644 fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
1645 }
1646
1647 // Determine background colour
1648 if ( isEnabled )
1649 {
1650 if ( doDrawFocusRect )
1651 {
1652 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1653 }
1654 else if ( m_hasTcBgCol )
1655 {
1656 // Honour the custom background colour
1657 bgCol = m_tcBgCol;
1658 }
1659 else
1660 {
1661 #ifndef __WXMAC__ // see note in OnThemeChange
1662 doDrawSelRect = false;
1663 bgCol = GetBackgroundColour();
1664 #else
1665 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1666 #endif
1667 }
1668 }
1669 else
1670 {
1671 #ifndef __WXMAC__ // see note in OnThemeChange
1672 bgCol = GetBackgroundColour();
1673 #else
1674 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1675 #endif
1676 }
1677
1678 dc.SetTextForeground( fgCol );
1679 dc.SetBrush( bgCol );
1680 if ( doDrawSelRect )
1681 {
1682 dc.SetPen( bgCol );
1683 dc.DrawRectangle( selRect );
1684 }
1685
1686 // Don't clip exactly to the selection rectangle so we can draw
1687 // to the non-selected area in front of it.
1688 wxRect clipRect(rect.x,rect.y,
1689 (selRect.x+selRect.width)-rect.x,rect.height);
1690 dc.SetClippingRegion(clipRect);
1691 }
1692 #else
1693 // Save the library size a bit for platforms that re-implement this.
1694 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1695 {
1696 }
1697 #endif
1698
1699 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags )
1700 {
1701 int drawState = m_btnState;
1702
1703 if ( (m_iFlags & wxCC_BUTTON_STAYS_DOWN) &&
1704 GetPopupWindowState() >= Animating )
1705 drawState |= wxCONTROL_PRESSED;
1706
1707 wxRect drawRect(rect.x+m_btnSpacingX,
1708 rect.y+((rect.height-m_btnSize.y)/2),
1709 m_btnSize.x,
1710 m_btnSize.y);
1711
1712 // Make sure area is not larger than the control
1713 if ( drawRect.y < rect.y )
1714 drawRect.y = rect.y;
1715 if ( drawRect.height > rect.height )
1716 drawRect.height = rect.height;
1717
1718 bool enabled = IsEnabled();
1719
1720 if ( !enabled )
1721 drawState |= wxCONTROL_DISABLED;
1722
1723 // Need to clear button background even if m_btn is present
1724 // and also when using custom bitmap for the button
1725 if ( (flags & Button_PaintBackground) &&
1726 (!HasTransparentBackground() ||
1727 !(m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE)) )
1728 {
1729 wxColour bgCol;
1730
1731 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1732 bgCol = GetParent()->GetBackgroundColour();
1733 else
1734 bgCol = GetBackgroundColour();
1735
1736 dc.SetBrush(bgCol);
1737 dc.SetPen(bgCol);
1738 dc.DrawRectangle(rect);
1739 }
1740
1741 if ( !m_bmpNormal.IsOk() )
1742 {
1743 if ( flags & Button_BitmapOnly )
1744 return;
1745
1746 // Draw standard button
1747 wxRendererNative::Get().DrawComboBoxDropButton(this,
1748 dc,
1749 drawRect,
1750 drawState);
1751 }
1752 else
1753 {
1754 // Draw bitmap
1755
1756 wxBitmap* pBmp;
1757
1758 if ( !enabled )
1759 pBmp = &m_bmpDisabled;
1760 else if ( m_btnState & wxCONTROL_PRESSED )
1761 pBmp = &m_bmpPressed;
1762 else if ( m_btnState & wxCONTROL_CURRENT )
1763 pBmp = &m_bmpHover;
1764 else
1765 pBmp = &m_bmpNormal;
1766
1767 if ( m_blankButtonBg )
1768 {
1769 if ( !(flags & Button_BitmapOnly) )
1770 {
1771 wxRendererNative::Get().DrawPushButton(this,
1772 dc,
1773 drawRect,
1774 drawState);
1775 }
1776 }
1777
1778 // Draw bitmap centered in drawRect
1779 dc.DrawBitmap(*pBmp,
1780 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1781 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1782 true);
1783 }
1784 }
1785
1786 void wxComboCtrlBase::RecalcAndRefresh()
1787 {
1788 if ( IsCreated() )
1789 {
1790 wxSizeEvent evt(GetSize(),GetId());
1791 evt.SetEventObject(this);
1792 GetEventHandler()->ProcessEvent(evt);
1793 Refresh();
1794 }
1795 }
1796
1797 // ----------------------------------------------------------------------------
1798 // miscellaneous event handlers
1799 // ----------------------------------------------------------------------------
1800
1801 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1802 {
1803 // Avoid infinite recursion
1804 if ( event.GetEventObject() == this )
1805 {
1806 event.Skip();
1807 return;
1808 }
1809
1810 if ( event.GetEventType() == wxEVT_TEXT )
1811 {
1812 if ( m_ignoreEvtText > 0 )
1813 {
1814 m_ignoreEvtText--;
1815 return;
1816 }
1817 }
1818
1819 // For safety, completely re-create a new wxCommandEvent
1820 wxCommandEvent evt2(event);
1821 evt2.SetId(GetId());
1822 evt2.SetEventObject(this);
1823 HandleWindowEvent(evt2);
1824
1825 event.StopPropagation();
1826 }
1827
1828 // call if cursor is on button area or mouse is captured for the button
1829 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1830 int flags )
1831 {
1832 int type = event.GetEventType();
1833
1834 if ( type == wxEVT_MOTION )
1835 {
1836 if ( (flags & wxCC_MF_ON_BUTTON) &&
1837 IsPopupWindowState(Hidden) )
1838 {
1839 if ( !(m_btnState & wxCONTROL_CURRENT) )
1840 {
1841 // Mouse hover begins
1842 m_btnState |= wxCONTROL_CURRENT;
1843 if ( HasCapture() ) // Retain pressed state.
1844 m_btnState |= wxCONTROL_PRESSED;
1845 Refresh();
1846 }
1847 }
1848 else if ( (m_btnState & wxCONTROL_CURRENT) )
1849 {
1850 // Mouse hover ends
1851 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1852 Refresh();
1853 }
1854 }
1855 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1856 {
1857 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1858 {
1859 m_btnState |= wxCONTROL_PRESSED;
1860 Refresh();
1861
1862 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1863 OnButtonClick();
1864 else
1865 // If showing popup now, do not capture mouse or there will be interference
1866 CaptureMouse();
1867 }
1868 }
1869 else if ( type == wxEVT_LEFT_UP )
1870 {
1871
1872 // Only accept event if mouse was left-press was previously accepted
1873 if ( HasCapture() )
1874 ReleaseMouse();
1875
1876 if ( m_btnState & wxCONTROL_PRESSED )
1877 {
1878 // If mouse was inside, fire the click event.
1879 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1880 {
1881 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1882 OnButtonClick();
1883 }
1884
1885 m_btnState &= ~(wxCONTROL_PRESSED);
1886 Refresh();
1887 }
1888 }
1889 else if ( type == wxEVT_LEAVE_WINDOW )
1890 {
1891 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1892 {
1893 m_btnState &= ~(wxCONTROL_CURRENT);
1894
1895 // Mouse hover ends
1896 if ( IsPopupWindowState(Hidden) )
1897 {
1898 m_btnState &= ~(wxCONTROL_PRESSED);
1899 Refresh();
1900 }
1901 }
1902 }
1903 else
1904 return false;
1905
1906 // Never have 'hot' state when popup is being shown
1907 // (this is mostly needed because of the animation).
1908 if ( !IsPopupWindowState(Hidden) )
1909 m_btnState &= ~wxCONTROL_CURRENT;
1910
1911 return true;
1912 }
1913
1914 // returns true if event was consumed or filtered
1915 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1916 int WXUNUSED(flags) )
1917 {
1918 wxLongLong t = ::wxGetLocalTimeMillis();
1919 int evtType = event.GetEventType();
1920
1921 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1922 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1923 {
1924 if ( IsPopupWindowState(Visible) &&
1925 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1926 {
1927 HidePopup(true);
1928 return true;
1929 }
1930 }
1931 #endif
1932
1933 // Filter out clicks on button immediately after popup dismiss
1934 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1935 {
1936 event.SetEventType(0);
1937 return true;
1938 }
1939
1940 return false;
1941 }
1942
1943 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1944 {
1945 int evtType = event.GetEventType();
1946
1947 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1948 (m_windowStyle & wxCB_READONLY) )
1949 {
1950 if ( GetPopupWindowState() >= Animating )
1951 {
1952 #if USES_WXPOPUPWINDOW
1953 // Click here always hides the popup.
1954 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1955 HidePopup(true);
1956 #endif
1957 }
1958 else
1959 {
1960 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1961 {
1962 // In read-only mode, clicking the text is the
1963 // same as clicking the button.
1964 OnButtonClick();
1965 }
1966 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1967 {
1968 //if ( m_popupInterface->CycleValue() )
1969 // Refresh();
1970 if ( m_popupInterface )
1971 m_popupInterface->OnComboDoubleClick();
1972 }
1973 }
1974 }
1975 else if ( evtType == wxEVT_MOUSEWHEEL )
1976 {
1977 if ( IsPopupShown() )
1978 {
1979 // relay (some) mouse events to the popup
1980 m_popup->GetEventHandler()->ProcessEvent(event);
1981 }
1982 else if ( event.GetWheelAxis() == 0 &&
1983 event.GetWheelRotation() != 0 &&
1984 event.GetModifiers() == 0 )
1985 {
1986 // Translate mousewheel actions into key up/down. This is
1987 // the simplest way of getting native behaviour: scrolling the
1988 // wheel moves selection up/down by one item.
1989 wxKeyEvent kevent(wxEVT_KEY_DOWN);
1990 kevent.m_keyCode = event.GetWheelRotation() > 0
1991 ? WXK_UP
1992 : WXK_DOWN;
1993 GetEventHandler()->ProcessEvent(kevent);
1994 }
1995 else
1996 {
1997 event.Skip();
1998 }
1999 }
2000 else if ( evtType )
2001 {
2002 event.Skip();
2003 }
2004 }
2005
2006 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
2007 {
2008 if ( IsPopupShown() )
2009 {
2010 // pass it to the popped up control
2011 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
2012 }
2013 else // no popup
2014 {
2015 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
2016
2017 if ( mainCtrl->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
2018 {
2019 if ( mainCtrl->HandleAsNavigationKey(event) )
2020 return;
2021 }
2022
2023 if ( IsKeyPopupToggle(event) )
2024 {
2025 OnButtonClick();
2026 return;
2027 }
2028
2029 int comboStyle = GetWindowStyle();
2030 wxComboPopup* popupInterface = GetPopupControl();
2031
2032 if ( !popupInterface )
2033 {
2034 event.Skip();
2035 return;
2036 }
2037
2038 int keycode = event.GetKeyCode();
2039
2040 if ( (comboStyle & wxCB_READONLY) ||
2041 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
2042 {
2043 popupInterface->OnComboKeyEvent(event);
2044 }
2045 else
2046 event.Skip();
2047 }
2048 }
2049
2050 void wxComboCtrlBase::OnCharEvent(wxKeyEvent& event)
2051 {
2052 if ( IsPopupShown() )
2053 {
2054 // pass it to the popped up control
2055 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event);
2056 }
2057 else // no popup
2058 {
2059 wxComboPopup* popupInterface = GetPopupControl();
2060 if ( popupInterface )
2061 {
2062 popupInterface->OnComboCharEvent(event);
2063 }
2064 else
2065 {
2066 event.Skip();
2067 }
2068 }
2069 }
2070
2071 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
2072 {
2073 // On Mac, setting focus here leads to infinite recursion and eventually
2074 // a crash due to the SetFocus call producing another event.
2075 // Handle Mac in OnIdleEvent using m_resetFocus.
2076
2077 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2078 {
2079 if ( GetTextCtrl() && !GetTextCtrl()->HasFocus() )
2080 {
2081 #ifdef __WXMAC__
2082 m_resetFocus = true;
2083 #else
2084 GetTextCtrl()->SetFocus();
2085 #endif
2086 }
2087 }
2088
2089 Refresh();
2090 }
2091
2092 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
2093 {
2094 if ( m_resetFocus )
2095 {
2096 m_resetFocus = false;
2097 if ( GetTextCtrl() )
2098 GetTextCtrl()->SetFocus();
2099 }
2100 }
2101
2102 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
2103 {
2104 OnThemeChange();
2105 // left margin may also have changed
2106 if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) )
2107 m_marginLeft = GetNativeTextIndent();
2108 RecalcAndRefresh();
2109 }
2110
2111 // ----------------------------------------------------------------------------
2112 // popup handling
2113 // ----------------------------------------------------------------------------
2114
2115 // Create popup window and the child control
2116 void wxComboCtrlBase::CreatePopup()
2117 {
2118 wxComboPopup* popupInterface = m_popupInterface;
2119 wxWindow* popup;
2120
2121 if ( !m_winPopup )
2122 {
2123 #ifdef wxComboPopupWindowBase2
2124 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
2125 {
2126 #if !USES_GENERICTLW
2127 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
2128 #else
2129 int tlwFlags = wxNO_BORDER;
2130 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2131 tlwFlags |= wxFRAME_NO_TASKBAR;
2132 #endif
2133
2134 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2135 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY,
2136 wxPoint(-21,-21), wxSize(20, 20),
2137 tlwFlags );
2138 #else
2139 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
2140 wxPoint(-21,-21), wxSize(20, 20),
2141 tlwFlags );
2142 #endif
2143 #endif
2144 m_popupWinType = SECONDARY_POPUP_TYPE;
2145 }
2146 else
2147 #endif // wxComboPopupWindowBase2
2148 {
2149 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
2150 m_popupWinType = PRIMARY_POPUP_TYPE;
2151 }
2152 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
2153 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
2154 }
2155
2156 popupInterface->Create(m_winPopup);
2157 m_popup = popup = popupInterface->GetControl();
2158
2159 m_popupEvtHandler = new wxComboPopupEvtHandler(this);
2160 popup->PushEventHandler( m_popupEvtHandler );
2161
2162 // This may be helpful on some platforms
2163 // (eg. it bypasses a wxGTK popupwindow bug where
2164 // window is not initially hidden when it should be)
2165 m_winPopup->Hide();
2166
2167 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
2168 }
2169
2170 // Destroy popup window and the child control
2171 void wxComboCtrlBase::DestroyPopup()
2172 {
2173 HidePopup(true);
2174
2175 if ( m_popup )
2176 m_popup->RemoveEventHandler(m_popupEvtHandler);
2177
2178 wxDELETE(m_popupEvtHandler);
2179
2180 if ( m_popupInterface )
2181 {
2182 // NB: DestroyPopup() performs 'delete this'.
2183 m_popupInterface->DestroyPopup();
2184 m_popupInterface = NULL;
2185 }
2186
2187 if ( m_winPopup )
2188 {
2189 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
2190 wxDELETE(m_popupWinEvtHandler);
2191 m_winPopup->Destroy();
2192 m_winPopup = NULL;
2193 }
2194
2195 m_popup = NULL;
2196 }
2197
2198 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
2199 {
2200 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
2201
2202 DestroyPopup();
2203
2204 iface->InitBase(this);
2205 iface->Init();
2206
2207 m_popupInterface = iface;
2208
2209 if ( !iface->LazyCreate() )
2210 {
2211 CreatePopup();
2212 }
2213 else
2214 {
2215 m_popup = NULL;
2216 }
2217
2218 // This must be done after creation
2219 if ( !m_valueString.empty() )
2220 {
2221 iface->SetStringValue(m_valueString);
2222 //Refresh();
2223 }
2224 }
2225
2226 // Ensures there is atleast the default popup
2227 void wxComboCtrlBase::EnsurePopupControl()
2228 {
2229 if ( !m_popupInterface )
2230 SetPopupControl(NULL);
2231 }
2232
2233 void wxComboCtrlBase::OnButtonClick()
2234 {
2235 // Derived classes can override this method for totally custom
2236 // popup action
2237 switch ( GetPopupWindowState() )
2238 {
2239 case Hidden:
2240 {
2241 Popup();
2242 break;
2243 }
2244
2245 case Animating:
2246 case Visible:
2247 {
2248 HidePopup(true);
2249 break;
2250 }
2251 }
2252 }
2253
2254 void wxComboCtrlBase::Popup()
2255 {
2256 wxCommandEvent event(wxEVT_COMBOBOX_DROPDOWN, GetId());
2257 event.SetEventObject(this);
2258 HandleWindowEvent(event);
2259
2260 ShowPopup();
2261 }
2262
2263 void wxComboCtrlBase::ShowPopup()
2264 {
2265 EnsurePopupControl();
2266 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
2267
2268 if ( IsPopupWindowState(Animating) )
2269 return;
2270
2271 SetFocus();
2272
2273 // Space above and below
2274 int screenHeight;
2275 wxPoint scrPos;
2276 int spaceAbove;
2277 int spaceBelow;
2278 int maxHeightPopup;
2279 wxSize ctrlSz = GetSize();
2280
2281 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
2282 scrPos = GetParent()->ClientToScreen(GetPosition());
2283
2284 spaceAbove = scrPos.y;
2285 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
2286
2287 maxHeightPopup = spaceBelow;
2288 if ( spaceAbove > spaceBelow )
2289 maxHeightPopup = spaceAbove;
2290
2291 // Width
2292 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
2293
2294 if ( widthPopup < m_widthMinPopup )
2295 widthPopup = m_widthMinPopup;
2296
2297 wxWindow* winPopup = m_winPopup;
2298 wxWindow* popup;
2299
2300 // Need to disable tab traversal of parent
2301 //
2302 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2303 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2304 // that if transient popup is open, then tab traversal is to be ignored.
2305 // However, I think this code would still be needed for cases where
2306 // transient popup doesn't work yet (wxWinCE?).
2307 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
2308 wxWindow* parent = mainCtrl->GetParent();
2309 int parentFlags = parent->GetWindowStyle();
2310 if ( parentFlags & wxTAB_TRAVERSAL )
2311 {
2312 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
2313 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
2314 }
2315
2316 if ( !winPopup )
2317 {
2318 CreatePopup();
2319 winPopup = m_winPopup;
2320 popup = m_popup;
2321 }
2322 else
2323 {
2324 popup = m_popup;
2325 }
2326
2327 winPopup->Enable();
2328
2329 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
2330
2331 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
2332 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
2333 maxHeightPopup);
2334
2335 popup->SetSize(adjustedSize);
2336 popup->Move(0,0);
2337 m_popupInterface->OnPopup();
2338
2339 //
2340 // Reposition and resize popup window
2341 //
2342
2343 wxSize szp = popup->GetSize();
2344
2345 int popupX;
2346 int popupY = scrPos.y + ctrlSz.y;
2347
2348 // Default anchor is wxLEFT
2349 int anchorSide = m_anchorSide;
2350 if ( !anchorSide )
2351 anchorSide = wxLEFT;
2352
2353 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
2354 int leftX = scrPos.x - m_extLeft;
2355
2356 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
2357 leftX -= ctrlSz.x;
2358
2359 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
2360
2361 // If there is not enough horizontal space, anchor on the other side.
2362 // If there is no space even then, place the popup at x 0.
2363 if ( anchorSide == wxRIGHT )
2364 {
2365 if ( rightX < 0 )
2366 {
2367 if ( (leftX+szp.x) < screenWidth )
2368 anchorSide = wxLEFT;
2369 else
2370 anchorSide = 0;
2371 }
2372 }
2373 else
2374 {
2375 if ( (leftX+szp.x) >= screenWidth )
2376 {
2377 if ( rightX >= 0 )
2378 anchorSide = wxRIGHT;
2379 else
2380 anchorSide = 0;
2381 }
2382 }
2383
2384 // Select x coordinate according to the anchor side
2385 if ( anchorSide == wxRIGHT )
2386 popupX = rightX;
2387 else if ( anchorSide == wxLEFT )
2388 popupX = leftX;
2389 else
2390 popupX = 0;
2391
2392 int showFlags = CanDeferShow;
2393
2394 if ( spaceBelow < szp.y )
2395 {
2396 popupY = scrPos.y - szp.y;
2397 showFlags |= ShowAbove;
2398 }
2399
2400 #if INSTALL_TOPLEV_HANDLER
2401 // Put top level window event handler into place
2402 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
2403 {
2404 if ( !m_toplevEvtHandler )
2405 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
2406
2407 wxWindow* toplev = ::wxGetTopLevelParent( this );
2408 wxASSERT( toplev );
2409 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
2410 toplev->PushEventHandler( m_toplevEvtHandler );
2411 }
2412 #endif
2413
2414 // Set string selection (must be this way instead of SetStringSelection)
2415 if ( m_text )
2416 {
2417 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2418 m_text->SelectAll();
2419
2420 m_popupInterface->SetStringValue( m_text->GetValue() );
2421 }
2422 else
2423 {
2424 // This is neede since focus/selection indication may change when popup is shown
2425 Refresh();
2426 }
2427
2428 // This must be after SetStringValue
2429 m_popupWinState = Animating;
2430
2431 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
2432
2433 m_popup = popup;
2434 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
2435 AnimateShow( popupWinRect, showFlags ) )
2436 {
2437 DoShowPopup( popupWinRect, showFlags );
2438 }
2439 }
2440
2441 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
2442 {
2443 return true;
2444 }
2445
2446 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
2447 {
2448 wxWindow* winPopup = m_winPopup;
2449
2450 if ( IsPopupWindowState(Animating) )
2451 {
2452 // Make sure the popup window is shown in the right position.
2453 // Should not matter even if animation already did this.
2454
2455 // Some platforms (GTK) may like SetSize and Move to be separate
2456 // (though the bug was probably fixed).
2457 winPopup->SetSize( rect );
2458
2459 #if USES_WXPOPUPTRANSIENTWINDOW
2460 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2461 ((wxPopupTransientWindow*)winPopup)->Popup(m_popup);
2462 else
2463 #endif
2464 winPopup->Show();
2465
2466 m_popupWinState = Visible;
2467
2468 // If popup window was a generic top-level window, or the
2469 // wxPopupWindow implemenation on this platform is classified as
2470 // perfect, then we should be able to safely set focus to the popup
2471 // control.
2472 if ( IsPopupWinTypePerfect(m_popupWinType) )
2473 m_popup->SetFocus();
2474 }
2475 else if ( IsPopupWindowState(Hidden) )
2476 {
2477 // Animation was aborted
2478
2479 wxASSERT( !winPopup->IsShown() );
2480
2481 m_popupWinState = Hidden;
2482 }
2483
2484 Refresh();
2485 }
2486
2487 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent)
2488 {
2489 // Just in case, avoid double dismiss
2490 if ( IsPopupWindowState(Hidden) )
2491 return;
2492
2493 // This must be set before focus - otherwise there will be recursive
2494 // OnPopupDismisses.
2495 m_popupWinState = Hidden;
2496
2497 //SetFocus();
2498 m_winPopup->Disable();
2499
2500 // Inform popup control itself
2501 m_popupInterface->OnDismiss();
2502
2503 if ( m_popupEvtHandler )
2504 ((wxComboPopupEvtHandler*)m_popupEvtHandler)->OnPopupDismiss();
2505
2506 #if INSTALL_TOPLEV_HANDLER
2507 // Remove top level window event handler
2508 if ( m_toplevEvtHandler )
2509 {
2510 wxWindow* toplev = ::wxGetTopLevelParent( this );
2511 if ( toplev )
2512 toplev->RemoveEventHandler( m_toplevEvtHandler );
2513 }
2514 #endif
2515
2516 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
2517
2518 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2519 m_timeCanAcceptClick += 150;
2520
2521 // If cursor not on dropdown button, then clear its state
2522 // (technically not required by all ports, but do it for all just in case)
2523 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
2524 m_btnState = 0;
2525
2526 // Return parent's tab traversal flag.
2527 // See ShowPopup for notes.
2528 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
2529 {
2530 wxWindow* parent = GetParent();
2531 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2532 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2533 }
2534
2535 // refresh control (necessary even if m_text)
2536 Refresh();
2537
2538 SetFocus();
2539
2540 if ( generateEvent )
2541 {
2542 wxCommandEvent event(wxEVT_COMBOBOX_CLOSEUP, GetId());
2543 event.SetEventObject(this);
2544 HandleWindowEvent(event);
2545 }
2546 }
2547
2548 void wxComboCtrlBase::HidePopup(bool generateEvent)
2549 {
2550 // Should be able to call this without popup interface
2551 if ( IsPopupWindowState(Hidden) )
2552 return;
2553
2554 // transfer value and show it in textctrl, if any
2555 if ( !IsPopupWindowState(Animating) )
2556 SetValueByUser( m_popupInterface->GetStringValue() );
2557
2558 m_winPopup->Hide();
2559
2560 OnPopupDismiss(generateEvent);
2561 }
2562
2563 // ----------------------------------------------------------------------------
2564 // customization methods
2565 // ----------------------------------------------------------------------------
2566
2567 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2568 int side, int spacingX )
2569 {
2570 m_btnWid = width;
2571 m_btnHei = height;
2572 m_btnSide = side;
2573 m_btnSpacingX = spacingX;
2574
2575 if ( width > 0 || height > 0 || spacingX )
2576 m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON;
2577
2578 RecalcAndRefresh();
2579 }
2580
2581 wxSize wxComboCtrlBase::GetButtonSize()
2582 {
2583 if ( m_btnSize.x > 0 )
2584 return m_btnSize;
2585
2586 wxSize retSize(m_btnWid,m_btnHei);
2587
2588 // Need to call CalculateAreas now if button size is
2589 // is not explicitly specified.
2590 if ( retSize.x <= 0 || retSize.y <= 0)
2591 {
2592 OnResize();
2593
2594 retSize = m_btnSize;
2595 }
2596
2597 return retSize;
2598 }
2599
2600 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2601 bool blankButtonBg,
2602 const wxBitmap& bmpPressed,
2603 const wxBitmap& bmpHover,
2604 const wxBitmap& bmpDisabled )
2605 {
2606 m_bmpNormal = bmpNormal;
2607 m_blankButtonBg = blankButtonBg;
2608
2609 if ( bmpPressed.IsOk() )
2610 m_bmpPressed = bmpPressed;
2611 else
2612 m_bmpPressed = bmpNormal;
2613
2614 if ( bmpHover.IsOk() )
2615 m_bmpHover = bmpHover;
2616 else
2617 m_bmpHover = bmpNormal;
2618
2619 if ( bmpDisabled.IsOk() )
2620 m_bmpDisabled = bmpDisabled;
2621 else
2622 m_bmpDisabled = bmpNormal;
2623
2624 RecalcAndRefresh();
2625 }
2626
2627 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2628 {
2629 if ( m_text )
2630 {
2631 // move textctrl accordingly
2632 wxRect r = m_text->GetRect();
2633 int inc = width - m_widthCustomPaint;
2634 r.x += inc;
2635 r.width -= inc;
2636 m_text->SetSize( r );
2637 }
2638
2639 m_widthCustomPaint = width;
2640
2641 RecalcAndRefresh();
2642 }
2643
2644 bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins)
2645 {
2646 // For general sanity's sake, we ignore top margin. Instead
2647 // we will always try to center the text vertically.
2648 bool res = true;
2649
2650 if ( margins.x != -1 )
2651 {
2652 m_marginLeft = margins.x;
2653 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2654 }
2655 else
2656 {
2657 m_marginLeft = GetNativeTextIndent();
2658 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2659 }
2660
2661 if ( margins.y != -1 )
2662 {
2663 res = false;
2664 }
2665
2666 RecalcAndRefresh();
2667
2668 return res;
2669 }
2670
2671 wxPoint wxComboCtrlBase::DoGetMargins() const
2672 {
2673 return wxPoint(m_marginLeft, -1);
2674 }
2675
2676 #if WXWIN_COMPATIBILITY_2_8
2677 void wxComboCtrlBase::SetTextIndent( int indent )
2678 {
2679 if ( indent < 0 )
2680 {
2681 m_marginLeft = GetNativeTextIndent();
2682 m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET);
2683 }
2684 else
2685 {
2686 m_marginLeft = indent;
2687 m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET;
2688 }
2689
2690 RecalcAndRefresh();
2691 }
2692
2693 wxCoord wxComboCtrlBase::GetTextIndent() const
2694 {
2695 return m_marginLeft;
2696 }
2697 #endif
2698
2699 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2700 {
2701 return DEFAULT_TEXT_INDENT;
2702 }
2703
2704 void wxComboCtrlBase::SetTextCtrlStyle( int style )
2705 {
2706 m_textCtrlStyle = style;
2707
2708 if ( m_text )
2709 m_text->SetWindowStyle(style);
2710 }
2711
2712 // ----------------------------------------------------------------------------
2713 // wxTextEntry interface
2714 // ----------------------------------------------------------------------------
2715
2716 wxString wxComboCtrlBase::DoGetValue() const
2717 {
2718 if ( m_text )
2719 return m_text->GetValue();
2720 return m_valueString;
2721 }
2722
2723 void wxComboCtrlBase::SetValueWithEvent(const wxString& value,
2724 bool withEvent)
2725 {
2726 DoSetValue(value, withEvent ? SetValue_SendEvent : 0);
2727 }
2728
2729 void wxComboCtrlBase::OnSetValue(const wxString& value)
2730 {
2731 // Note: before wxComboCtrl inherited from wxTextEntry,
2732 // this code used to be in SetValueWithEvent().
2733
2734 // Since wxComboPopup may want to paint the combo as well, we need
2735 // to set the string value here (as well as sometimes in ShowPopup).
2736 if ( m_valueString != value )
2737 {
2738 bool found = true;
2739 wxString trueValue = value;
2740
2741 // Conform to wxComboBox behaviour: read-only control can only accept
2742 // valid list items and empty string
2743 if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() )
2744 {
2745 found = m_popupInterface->FindItem(value,
2746 &trueValue);
2747 }
2748
2749 if ( found )
2750 {
2751 m_valueString = trueValue;
2752
2753 EnsurePopupControl();
2754
2755 if ( m_popupInterface )
2756 m_popupInterface->SetStringValue(trueValue);
2757 }
2758 }
2759
2760 Refresh();
2761 }
2762
2763 void wxComboCtrlBase::SetValueByUser(const wxString& value)
2764 {
2765 // NB: Order of function calls is important here. Otherwise
2766 // the SelectAll() may not work.
2767
2768 if ( m_text )
2769 {
2770 m_text->SetValue(value);
2771
2772 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2773 m_text->SelectAll();
2774 }
2775
2776 OnSetValue(value);
2777 }
2778
2779 // In this SetValue variant wxComboPopup::SetStringValue is not called
2780 void wxComboCtrlBase::SetText(const wxString& value)
2781 {
2782 // Unlike in SetValue(), this must be called here or
2783 // the behaviour will no be consistent in readonlys.
2784 EnsurePopupControl();
2785
2786 m_valueString = value;
2787
2788 if ( m_text )
2789 {
2790 m_ignoreEvtText++;
2791 m_text->SetValue( value );
2792 }
2793
2794 Refresh();
2795 }
2796
2797 void wxComboCtrlBase::Copy()
2798 {
2799 if ( m_text )
2800 m_text->Copy();
2801 }
2802
2803 void wxComboCtrlBase::Cut()
2804 {
2805 if ( m_text )
2806 m_text->Cut();
2807 }
2808
2809 void wxComboCtrlBase::Paste()
2810 {
2811 if ( m_text )
2812 m_text->Paste();
2813 }
2814
2815 void wxComboCtrlBase::SetInsertionPoint(long pos)
2816 {
2817 if ( m_text )
2818 m_text->SetInsertionPoint(pos);
2819 }
2820
2821 long wxComboCtrlBase::GetInsertionPoint() const
2822 {
2823 if ( m_text )
2824 return m_text->GetInsertionPoint();
2825
2826 return 0;
2827 }
2828
2829 long wxComboCtrlBase::GetLastPosition() const
2830 {
2831 if ( m_text )
2832 return m_text->GetLastPosition();
2833
2834 return 0;
2835 }
2836
2837 void wxComboCtrlBase::WriteText(const wxString& text)
2838 {
2839 if ( m_text )
2840 {
2841 m_text->WriteText(text);
2842 OnSetValue(m_text->GetValue());
2843 }
2844 else
2845 {
2846 OnSetValue(text);
2847 }
2848 }
2849
2850 void wxComboCtrlBase::DoSetValue(const wxString& value, int flags)
2851 {
2852 if ( m_text )
2853 {
2854 if ( flags & SetValue_SendEvent )
2855 m_text->SetValue(value);
2856 else
2857 m_text->ChangeValue(value);
2858 }
2859
2860 OnSetValue(value);
2861 }
2862
2863 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2864 {
2865 if ( m_text )
2866 {
2867 m_text->Replace(from, to, value);
2868 OnSetValue(m_text->GetValue());
2869 }
2870 }
2871
2872 void wxComboCtrlBase::Remove(long from, long to)
2873 {
2874 if ( m_text )
2875 {
2876 m_text->Remove(from, to);
2877 OnSetValue(m_text->GetValue());
2878 }
2879 }
2880
2881 void wxComboCtrlBase::SetSelection(long from, long to)
2882 {
2883 if ( m_text )
2884 m_text->SetSelection(from, to);
2885 }
2886
2887 void wxComboCtrlBase::GetSelection(long *from, long *to) const
2888 {
2889 if ( m_text )
2890 {
2891 m_text->GetSelection(from, to);
2892 }
2893 else
2894 {
2895 *from = 0;
2896 *to = 0;
2897 }
2898 }
2899
2900 bool wxComboCtrlBase::IsEditable() const
2901 {
2902 if ( m_text )
2903 return m_text->IsEditable();
2904 return false;
2905 }
2906
2907 void wxComboCtrlBase::SetEditable(bool editable)
2908 {
2909 if ( m_text )
2910 m_text->SetEditable(editable);
2911 }
2912
2913 void wxComboCtrlBase::Undo()
2914 {
2915 if ( m_text )
2916 m_text->Undo();
2917 }
2918
2919 void wxComboCtrlBase::Redo()
2920 {
2921 if ( m_text )
2922 m_text->Redo();
2923 }
2924
2925 bool wxComboCtrlBase::CanUndo() const
2926 {
2927 if ( m_text )
2928 return m_text->CanUndo();
2929
2930 return false;
2931 }
2932
2933 bool wxComboCtrlBase::CanRedo() const
2934 {
2935 if ( m_text )
2936 return m_text->CanRedo();
2937
2938 return false;
2939 }
2940
2941 bool wxComboCtrlBase::SetHint(const wxString& hint)
2942 {
2943 m_hintText = hint;
2944 bool res = true;
2945 if ( m_text )
2946 res = m_text->SetHint(hint);
2947 Refresh();
2948 return res;
2949 }
2950
2951 wxString wxComboCtrlBase::GetHint() const
2952 {
2953 return m_hintText;
2954 }
2955
2956 #endif // wxUSE_COMBOCTRL