/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/common/combocmn.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/common/combocmn.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 2 months ago) by william
File size: 62722 byte(s)
committing r3113 initial commit again...
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: combocmn.cpp 55201 2008-08-23 08:20:00Z RR $
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_COMBOCTRL
27
28 #include "wx/combobox.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #include "wx/log.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/dialog.h"
36 #include "wx/timer.h"
37 #endif
38
39 #include "wx/tooltip.h"
40
41 #include "wx/combo.h"
42
43
44
45 // constants
46 // ----------------------------------------------------------------------------
47
48 #define DEFAULT_DROPBUTTON_WIDTH 19
49
50 #define BMP_BUTTON_MARGIN 4
51
52 #define DEFAULT_POPUP_HEIGHT 400
53
54 #define DEFAULT_TEXT_INDENT 3
55
56 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
57
58
59 #if defined(__WXMSW__)
60
61 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
62 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
63 // native controls work on it like normal.
64 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
65 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
66 #define FOCUS_RING 0 // No focus ring on wxMSW
67
68 //#undef wxUSE_POPUPWIN
69 //#define wxUSE_POPUPWIN 0
70
71 #elif defined(__WXGTK__)
72
73 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
74 // this bug: If wxDialog is hidden, its position becomes corrupt
75 // between hide and next show, but without internal coordinates being
76 // reflected (or something like that - atleast commenting out ->Hide()
77 // seemed to eliminate the position change).
78
79 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
80 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
81 // native controls work on it like normal.
82 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
83 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
84 #define FOCUS_RING 0 // No focus ring on wxGTK
85
86 #elif defined(__WXMAC__)
87
88 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
89 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
90 // native controls work on it like normal.
91 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
92 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
93 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
94
95 #undef DEFAULT_DROPBUTTON_WIDTH
96 #define DEFAULT_DROPBUTTON_WIDTH 22
97 #undef COMBO_MARGIN
98 #define COMBO_MARGIN FOCUS_RING
99
100 #else
101
102 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
103 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
104 // native controls work on it like normal.
105 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
106 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
107 #define FOCUS_RING 0
108
109 #endif
110
111
112 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
113 // what the wxUSE_POPUPWIN says.
114 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
115 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
116 #undef wxUSE_POPUPWIN
117 #define wxUSE_POPUPWIN 0
118 #endif
119
120
121 #if wxUSE_POPUPWIN
122 #include "wx/popupwin.h"
123 #else
124 #undef USE_TRANSIENT_POPUP
125 #define USE_TRANSIENT_POPUP 0
126 #endif
127
128
129 // Define different types of popup windows
130 enum
131 {
132 POPUPWIN_NONE = 0,
133 POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1,
134 POPUPWIN_WXPOPUPWINDOW = 2,
135 POPUPWIN_WXDIALOG = 3
136 };
137
138
139 #if USE_TRANSIENT_POPUP
140 // wxPopupTransientWindow is implemented
141
142 #define wxComboPopupWindowBase wxPopupTransientWindow
143 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
144 #define USES_WXPOPUPTRANSIENTWINDOW 1
145
146 #if TRANSIENT_POPUPWIN_IS_PERFECT
147 //
148 #elif POPUPWIN_IS_PERFECT
149 #define wxComboPopupWindowBase2 wxPopupWindow
150 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
151 #define USES_WXPOPUPWINDOW 1
152 #else
153 #define wxComboPopupWindowBase2 wxDialog
154 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
155 #define USES_WXDIALOG 1
156 #endif
157
158 #elif wxUSE_POPUPWIN
159 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
160
161 #define wxComboPopupWindowBase wxPopupWindow
162 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
163 #define USES_WXPOPUPWINDOW 1
164
165 #if !POPUPWIN_IS_PERFECT
166 #define wxComboPopupWindowBase2 wxDialog
167 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
168 #define USES_WXDIALOG 1
169 #endif
170
171 #else
172 // wxPopupWindow is not implemented
173
174 #define wxComboPopupWindowBase wxDialog
175 #define PRIMARY_POPUP_TYPE POPUPWIN_WXDIALOG
176 #define USES_WXDIALOG 1
177
178 #endif
179
180
181 #ifndef USES_WXPOPUPTRANSIENTWINDOW
182 #define USES_WXPOPUPTRANSIENTWINDOW 0
183 #endif
184
185 #ifndef USES_WXPOPUPWINDOW
186 #define USES_WXPOPUPWINDOW 0
187 #endif
188
189 #ifndef USES_WXDIALOG
190 #define USES_WXDIALOG 0
191 #endif
192
193
194 #if USES_WXPOPUPWINDOW
195 #define INSTALL_TOPLEV_HANDLER 1
196 #else
197 #define INSTALL_TOPLEV_HANDLER 0
198 #endif
199
200
201 //
202 // ** TODO **
203 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
204 //
205
206
207 // ----------------------------------------------------------------------------
208 // wxComboFrameEventHandler takes care of hiding the popup when events happen
209 // in its top level parent.
210 // ----------------------------------------------------------------------------
211
212 #if INSTALL_TOPLEV_HANDLER
213
214 //
215 // This will no longer be necessary after wxTransientPopupWindow
216 // works well on all platforms.
217 //
218
219 class wxComboFrameEventHandler : public wxEvtHandler
220 {
221 public:
222 wxComboFrameEventHandler( wxComboCtrlBase* pCb );
223 virtual ~wxComboFrameEventHandler();
224
225 void OnPopup();
226
227 void OnIdle( wxIdleEvent& event );
228 void OnMouseEvent( wxMouseEvent& event );
229 void OnActivate( wxActivateEvent& event );
230 void OnResize( wxSizeEvent& event );
231 void OnMove( wxMoveEvent& event );
232 void OnMenuEvent( wxMenuEvent& event );
233 void OnClose( wxCloseEvent& event );
234
235 protected:
236 wxWindow* m_focusStart;
237 wxComboCtrlBase* m_combo;
238
239 private:
240 DECLARE_EVENT_TABLE()
241 };
242
243 BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler)
244 EVT_IDLE(wxComboFrameEventHandler::OnIdle)
245 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
246 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
247 EVT_SIZE(wxComboFrameEventHandler::OnResize)
248 EVT_MOVE(wxComboFrameEventHandler::OnMove)
249 EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent)
250 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent)
251 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate)
252 EVT_CLOSE(wxComboFrameEventHandler::OnClose)
253 END_EVENT_TABLE()
254
255 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase* combo )
256 : wxEvtHandler()
257 {
258 m_combo = combo;
259 }
260
261 wxComboFrameEventHandler::~wxComboFrameEventHandler()
262 {
263 }
264
265 void wxComboFrameEventHandler::OnPopup()
266 {
267 m_focusStart = ::wxWindow::FindFocus();
268 }
269
270 void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
271 {
272 wxWindow* winFocused = ::wxWindow::FindFocus();
273
274 wxWindow* popup = m_combo->GetPopupControl()->GetControl();
275 wxWindow* winpopup = m_combo->GetPopupWindow();
276
277 if (
278 winFocused != m_focusStart &&
279 winFocused != popup &&
280 winFocused->GetParent() != popup &&
281 winFocused != winpopup &&
282 winFocused->GetParent() != winpopup &&
283 winFocused != m_combo &&
284 winFocused != m_combo->GetButton() // GTK (atleast) requires this
285 )
286 {
287 m_combo->HidePopup();
288 }
289
290 event.Skip();
291 }
292
293 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
294 {
295 m_combo->HidePopup();
296 event.Skip();
297 }
298
299 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
300 {
301 m_combo->HidePopup();
302 event.Skip();
303 }
304
305 void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
306 {
307 m_combo->HidePopup();
308 event.Skip();
309 }
310
311 void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
312 {
313 m_combo->HidePopup();
314 event.Skip();
315 }
316
317 void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
318 {
319 m_combo->HidePopup();
320 event.Skip();
321 }
322
323 void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
324 {
325 m_combo->HidePopup();
326 event.Skip();
327 }
328
329 #endif // INSTALL_TOPLEV_HANDLER
330
331 // ----------------------------------------------------------------------------
332 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
333 // wxComboCtrl.
334 // ----------------------------------------------------------------------------
335
336 class wxComboPopupWindow : public wxComboPopupWindowBase
337 {
338 public:
339
340 wxComboPopupWindow( wxComboCtrlBase *parent,
341 int style )
342 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
343 : wxComboPopupWindowBase(parent,style)
344 #else
345 : wxComboPopupWindowBase(parent,
346 wxID_ANY,
347 wxEmptyString,
348 wxPoint(-21,-21),
349 wxSize(20,20),
350 style)
351 #endif
352 {
353 m_inShow = 0;
354 }
355
356 #if USES_WXPOPUPTRANSIENTWINDOW
357 virtual bool Show( bool show );
358 virtual bool ProcessLeftDown(wxMouseEvent& event);
359 protected:
360 virtual void OnDismiss();
361 #endif
362
363 private:
364 wxByte m_inShow;
365 };
366
367
368 #if USES_WXPOPUPTRANSIENTWINDOW
369 bool wxComboPopupWindow::Show( bool show )
370 {
371 // Guard against recursion
372 if ( m_inShow )
373 return wxComboPopupWindowBase::Show(show);
374
375 m_inShow++;
376
377 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow)) );
378
379 wxPopupTransientWindow* ptw = (wxPopupTransientWindow*) this;
380 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
381
382 if ( show != ptw->IsShown() )
383 {
384 if ( show )
385 ptw->Popup(combo->GetPopupControl()->GetControl());
386 else
387 ptw->Dismiss();
388 }
389
390 m_inShow--;
391
392 return true;
393 }
394
395 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event)
396 {
397 return wxPopupTransientWindow::ProcessLeftDown(event);
398 }
399
400 // First thing that happens when a transient popup closes is that this method gets called.
401 void wxComboPopupWindow::OnDismiss()
402 {
403 wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent();
404 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)),
405 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
406
407 combo->OnPopupDismiss();
408 }
409 #endif // USES_WXPOPUPTRANSIENTWINDOW
410
411
412 // ----------------------------------------------------------------------------
413 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
414 // of a popup window. It is separate so we can have different types
415 // of popup windows.
416 // ----------------------------------------------------------------------------
417
418 class wxComboPopupWindowEvtHandler : public wxEvtHandler
419 {
420 public:
421
422 wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent )
423 {
424 m_combo = parent;
425 }
426
427 void OnSizeEvent( wxSizeEvent& event );
428 void OnKeyEvent(wxKeyEvent& event);
429 #if USES_WXDIALOG
430 void OnActivate( wxActivateEvent& event );
431 #endif
432
433 private:
434 wxComboCtrlBase* m_combo;
435
436 DECLARE_EVENT_TABLE()
437 };
438
439
440 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler)
441 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent)
442 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent)
443 #if USES_WXDIALOG
444 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate)
445 #endif
446 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent)
447 END_EVENT_TABLE()
448
449
450 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) )
451 {
452 // Block the event so that the popup control does not get auto-resized.
453 }
454
455 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
456 {
457 // Relay keyboard event to the main child controls
458 wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
459 wxWindowList::iterator node = children.begin();
460 wxWindow* child = (wxWindow*)*node;
461 child->AddPendingEvent(event);
462 }
463
464 #if USES_WXDIALOG
465 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event )
466 {
467 if ( !event.GetActive() )
468 {
469 // Tell combo control that we are dismissed.
470 m_combo->HidePopup();
471
472 event.Skip();
473 }
474 }
475 #endif
476
477
478 // ----------------------------------------------------------------------------
479 // wxComboPopup
480 //
481 // ----------------------------------------------------------------------------
482
483 wxComboPopup::~wxComboPopup()
484 {
485 }
486
487 void wxComboPopup::OnPopup()
488 {
489 }
490
491 void wxComboPopup::OnDismiss()
492 {
493 }
494
495 wxSize wxComboPopup::GetAdjustedSize( int minWidth,
496 int prefHeight,
497 int WXUNUSED(maxHeight) )
498 {
499 return wxSize(minWidth,prefHeight);
500 }
501
502 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo,
503 wxDC& dc, const wxRect& rect )
504 {
505 if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl
506 {
507 combo->PrepareBackground(dc,rect,0);
508
509 dc.DrawText( combo->GetValue(),
510 rect.x + combo->GetTextIndent(),
511 (rect.height-dc.GetCharHeight())/2 + rect.y );
512 }
513 }
514
515 void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
516 {
517 DefaultPaintComboControl(m_combo,dc,rect);
518 }
519
520 void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
521 {
522 event.Skip();
523 }
524
525 void wxComboPopup::OnComboDoubleClick()
526 {
527 }
528
529 void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) )
530 {
531 }
532
533 bool wxComboPopup::LazyCreate()
534 {
535 return false;
536 }
537
538 void wxComboPopup::Dismiss()
539 {
540 m_combo->HidePopup();
541 }
542
543 // ----------------------------------------------------------------------------
544 // input handling
545 // ----------------------------------------------------------------------------
546
547 //
548 // This is pushed to the event handler queue of the child textctrl.
549 //
550 class wxComboBoxExtraInputHandler : public wxEvtHandler
551 {
552 public:
553
554 wxComboBoxExtraInputHandler( wxComboCtrlBase* combo )
555 : wxEvtHandler()
556 {
557 m_combo = combo;
558 }
559 virtual ~wxComboBoxExtraInputHandler() { }
560 void OnKey(wxKeyEvent& event);
561 void OnFocus(wxFocusEvent& event);
562
563 protected:
564 wxComboCtrlBase* m_combo;
565
566 private:
567 DECLARE_EVENT_TABLE()
568 };
569
570
571 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler)
572 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey)
573 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus)
574 END_EVENT_TABLE()
575
576
577 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event)
578 {
579 // Let the wxComboCtrl event handler have a go first.
580 wxComboCtrlBase* combo = m_combo;
581 wxObject* prevObj = event.GetEventObject();
582
583 event.SetId(combo->GetId());
584 event.SetEventObject(combo);
585 combo->GetEventHandler()->ProcessEvent(event);
586
587 event.SetId(((wxWindow*)prevObj)->GetId());
588 event.SetEventObject(prevObj);
589 }
590
591 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event)
592 {
593 // FIXME: This code does run when control is clicked,
594 // yet on Windows it doesn't select all the text.
595 if ( !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) )
596 {
597 if ( m_combo->GetTextCtrl() )
598 m_combo->GetTextCtrl()->SelectAll();
599 else
600 m_combo->SetSelection(-1,-1);
601 }
602
603 // Send focus indication to parent.
604 // NB: This is needed for cases where the textctrl gets focus
605 // instead of its parent. While this may trigger multiple
606 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
607 // from combo's focus event handler), they should be quite
608 // harmless.
609 wxFocusEvent evt2(wxEVT_SET_FOCUS,m_combo->GetId());
610 evt2.SetEventObject(m_combo);
611 m_combo->GetEventHandler()->ProcessEvent(evt2);
612
613 event.Skip();
614 }
615
616
617 //
618 // This is pushed to the event handler queue of the control in popup.
619 //
620
621 class wxComboPopupExtraEventHandler : public wxEvtHandler
622 {
623 public:
624
625 wxComboPopupExtraEventHandler( wxComboCtrlBase* combo )
626 : wxEvtHandler()
627 {
628 m_combo = combo;
629 m_beenInside = false;
630 }
631 virtual ~wxComboPopupExtraEventHandler() { }
632
633 void OnMouseEvent( wxMouseEvent& event );
634
635 // Called from wxComboCtrlBase::OnPopupDismiss
636 void OnPopupDismiss()
637 {
638 m_beenInside = false;
639 }
640
641 protected:
642 wxComboCtrlBase* m_combo;
643
644 bool m_beenInside;
645
646 private:
647 DECLARE_EVENT_TABLE()
648 };
649
650
651 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler, wxEvtHandler)
652 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent)
653 END_EVENT_TABLE()
654
655
656 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent& event )
657 {
658 wxPoint pt = event.GetPosition();
659 wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize();
660 int evtType = event.GetEventType();
661 bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y;
662
663 if ( evtType == wxEVT_MOTION ||
664 evtType == wxEVT_LEFT_DOWN ||
665 evtType == wxEVT_RIGHT_DOWN )
666 {
667 // Block motion and click events outside the popup
668 if ( !isInside || !m_combo->IsPopupShown() )
669 {
670 event.Skip(false);
671 return;
672 }
673 }
674 else if ( evtType == wxEVT_LEFT_UP )
675 {
676 if ( !m_combo->IsPopupShown() )
677 {
678 event.Skip(false);
679 return;
680 }
681
682 if ( !m_beenInside )
683 {
684 if ( isInside )
685 {
686 m_beenInside = true;
687 }
688 else
689 {
690 //
691 // Some mouse events to popup that happen outside it, before cursor
692 // has been inside the popu, need to be ignored by it but relayed to
693 // the dropbutton.
694 //
695 wxWindow* btn = m_combo->GetButton();
696 if ( btn )
697 btn->GetEventHandler()->AddPendingEvent(event);
698 else
699 m_combo->GetEventHandler()->AddPendingEvent(event);
700
701 return;
702 }
703
704 event.Skip();
705 }
706 }
707
708 event.Skip();
709 }
710
711 // ----------------------------------------------------------------------------
712 // wxComboCtrlBase
713 // ----------------------------------------------------------------------------
714
715
716 BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl)
717 EVT_TEXT(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
718 EVT_SIZE(wxComboCtrlBase::OnSizeEvent)
719 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent)
720 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent)
721 EVT_IDLE(wxComboCtrlBase::OnIdleEvent)
722 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
723 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent)
724 EVT_TEXT_ENTER(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent)
725 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged)
726 END_EVENT_TABLE()
727
728
729 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl)
730
731 void wxComboCtrlBase::Init()
732 {
733 m_winPopup = (wxWindow *)NULL;
734 m_popup = (wxWindow *)NULL;
735 m_popupWinState = Hidden;
736 m_btn = (wxWindow*) NULL;
737 m_text = (wxTextCtrl*) NULL;
738 m_popupInterface = (wxComboPopup*) NULL;
739
740 m_popupExtraHandler = (wxEvtHandler*) NULL;
741 m_textEvtHandler = (wxEvtHandler*) NULL;
742
743 #if INSTALL_TOPLEV_HANDLER
744 m_toplevEvtHandler = (wxEvtHandler*) NULL;
745 #endif
746
747 m_mainCtrlWnd = this;
748
749 m_heightPopup = -1;
750 m_widthMinPopup = -1;
751 m_anchorSide = 0;
752 m_widthCustomPaint = 0;
753 m_widthCustomBorder = 0;
754
755 m_btnState = 0;
756 m_btnWidDefault = 0;
757 m_blankButtonBg = false;
758 m_ignoreEvtText = 0;
759 m_popupWinType = POPUPWIN_NONE;
760 m_btnWid = m_btnHei = -1;
761 m_btnSide = wxRIGHT;
762 m_btnSpacingX = 0;
763
764 m_extLeft = 0;
765 m_extRight = 0;
766 m_absIndent = -1;
767 m_iFlags = 0;
768 m_timeCanAcceptClick = 0;
769
770 m_resetFocus = false;
771 }
772
773 bool wxComboCtrlBase::Create(wxWindow *parent,
774 wxWindowID id,
775 const wxString& value,
776 const wxPoint& pos,
777 const wxSize& size,
778 long style,
779 const wxValidator& validator,
780 const wxString& name)
781 {
782 if ( !wxControl::Create(parent,
783 id,
784 pos,
785 size,
786 style | wxWANTS_CHARS,
787 validator,
788 name) )
789 return false;
790
791 m_valueString = value;
792
793 // Get colours
794 OnThemeChange();
795 m_absIndent = GetNativeTextIndent();
796
797 m_iFlags |= wxCC_IFLAG_CREATED;
798
799 // If x and y indicate valid size, wxSizeEvent won't be
800 // emitted automatically, so we need to add artifical one.
801 if ( size.x > 0 && size.y > 0 )
802 {
803 wxSizeEvent evt(size,GetId());
804 GetEventHandler()->AddPendingEvent(evt);
805 }
806
807 return true;
808 }
809
810 void wxComboCtrlBase::InstallInputHandlers()
811 {
812 if ( m_text )
813 {
814 m_textEvtHandler = new wxComboBoxExtraInputHandler(this);
815 m_text->PushEventHandler(m_textEvtHandler);
816 }
817 }
818
819 void
820 wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
821 {
822 if ( !(m_windowStyle & wxCB_READONLY) )
823 {
824 if ( m_text )
825 m_text->Destroy();
826
827 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
828 // not used by the wxPropertyGrid and therefore the tab is processed by
829 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
830 // navigation event is then sent to the wrong window.
831 style |= wxTE_PROCESS_TAB;
832
833 if ( HasFlag(wxTE_PROCESS_ENTER) )
834 style |= wxTE_PROCESS_ENTER;
835
836 // Ignore EVT_TEXT generated by the constructor (but only
837 // if the event redirector already exists)
838 // NB: This must be " = 1" instead of "++";
839 if ( m_textEvtHandler )
840 m_ignoreEvtText = 1;
841 else
842 m_ignoreEvtText = 0;
843
844 m_text = new wxTextCtrl(this, wxID_ANY, m_valueString,
845 wxDefaultPosition, wxSize(10,-1),
846 style, validator);
847 }
848 }
849
850 void wxComboCtrlBase::OnThemeChange()
851 {
852 // Leave the default bg on the Mac so the area used by the focus ring will
853 // be the correct colour and themed brush. Instead we'll use
854 // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
855 #ifndef __WXMAC__
856 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
857 #endif
858 }
859
860 wxComboCtrlBase::~wxComboCtrlBase()
861 {
862 if ( HasCapture() )
863 ReleaseMouse();
864
865 #if INSTALL_TOPLEV_HANDLER
866 delete ((wxComboFrameEventHandler*)m_toplevEvtHandler);
867 m_toplevEvtHandler = (wxEvtHandler*) NULL;
868 #endif
869
870 DestroyPopup();
871
872 if ( m_text )
873 m_text->RemoveEventHandler(m_textEvtHandler);
874
875 delete m_textEvtHandler;
876 }
877
878
879 // ----------------------------------------------------------------------------
880 // geometry stuff
881 // ----------------------------------------------------------------------------
882
883 // Recalculates button and textctrl areas
884 void wxComboCtrlBase::CalculateAreas( int btnWidth )
885 {
886 wxSize sz = GetClientSize();
887 int customBorder = m_widthCustomBorder;
888 int btnBorder; // border for button only
889
890 // check if button should really be outside the border: we'll do it it if
891 // its platform default or bitmap+pushbutton background is used, but not if
892 // there is vertical size adjustment or horizontal spacing.
893 if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
894 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
895 m_btnSpacingX == 0 &&
896 m_btnHei <= 0 )
897 {
898 m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
899 btnBorder = 0;
900 }
901 else
902 {
903 m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE);
904 btnBorder = customBorder;
905 }
906
907 // Defaul indentation
908 if ( m_absIndent < 0 )
909 m_absIndent = GetNativeTextIndent();
910
911 int butWidth = btnWidth;
912
913 if ( butWidth <= 0 )
914 butWidth = m_btnWidDefault;
915 else
916 m_btnWidDefault = butWidth;
917
918 if ( butWidth <= 0 )
919 return;
920
921 int butHeight = sz.y - btnBorder*2;
922
923 // Adjust button width
924 if ( m_btnWid > 0 )
925 butWidth = m_btnWid;
926 else
927 {
928 // Adjust button width to match aspect ratio
929 // (but only if control is smaller than best size).
930 int bestHeight = GetBestSize().y;
931 int height = GetSize().y;
932
933 if ( height < bestHeight )
934 {
935 // Make very small buttons square, as it makes
936 // them accommodate arrow image better and still
937 // looks decent.
938 if ( height > 18 )
939 butWidth = (height*butWidth)/bestHeight;
940 else
941 butWidth = butHeight;
942 }
943 }
944
945 // Adjust button height
946 if ( m_btnHei > 0 )
947 butHeight = m_btnHei;
948
949 // Use size of normal bitmap if...
950 // It is larger
951 // OR
952 // button width is set to default and blank button bg is not drawn
953 if ( m_bmpNormal.Ok() )
954 {
955 int bmpReqWidth = m_bmpNormal.GetWidth();
956 int bmpReqHeight = m_bmpNormal.GetHeight();
957
958 // If drawing blank button background, we need to add some margin.
959 if ( m_blankButtonBg )
960 {
961 bmpReqWidth += BMP_BUTTON_MARGIN*2;
962 bmpReqHeight += BMP_BUTTON_MARGIN*2;
963 }
964
965 if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) )
966 butWidth = bmpReqWidth;
967 if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) )
968 butHeight = bmpReqHeight;
969
970 // Need to fix height?
971 if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 )
972 {
973 int newY = butHeight+(customBorder*2);
974 SetClientSize(wxDefaultCoord,newY);
975 sz.y = newY;
976 }
977 }
978
979 int butAreaWid = butWidth + (m_btnSpacingX*2);
980
981 m_btnSize.x = butWidth;
982 m_btnSize.y = butHeight;
983
984 m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder );
985 m_btnArea.y = btnBorder + FOCUS_RING;
986 m_btnArea.width = butAreaWid;
987 m_btnArea.height = sz.y - ((btnBorder+FOCUS_RING)*2);
988
989 m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder + FOCUS_RING;
990 m_tcArea.y = customBorder + FOCUS_RING;
991 m_tcArea.width = sz.x - butAreaWid - (customBorder*2) - (FOCUS_RING*2);
992 m_tcArea.height = sz.y - ((customBorder+FOCUS_RING)*2);
993
994 /*
995 if ( m_text )
996 {
997 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
998 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
999 }
1000 */
1001 }
1002
1003 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust )
1004 {
1005 if ( !m_text )
1006 return;
1007
1008 #if !TEXTCTRL_TEXT_CENTERED
1009
1010 wxSize sz = GetClientSize();
1011
1012 int customBorder = m_widthCustomBorder;
1013 if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER )
1014 {
1015 // Centre textctrl
1016 int tcSizeY = m_text->GetBestSize().y;
1017 int diff = sz.y - tcSizeY;
1018 int y = textCtrlYAdjust + (diff/2);
1019
1020 if ( y < customBorder )
1021 y = customBorder;
1022
1023 m_text->SetSize( m_tcArea.x + m_widthCustomPaint + m_absIndent + textCtrlXAdjust,
1024 y,
1025 m_tcArea.width - COMBO_MARGIN -
1026 (textCtrlXAdjust + m_widthCustomPaint + m_absIndent),
1027 -1 );
1028
1029 // Make sure textctrl doesn't exceed the bottom custom border
1030 wxSize tsz = m_text->GetSize();
1031 diff = (y + tsz.y) - (sz.y - customBorder);
1032 if ( diff >= 0 )
1033 {
1034 tsz.y = tsz.y - diff - 1;
1035 m_text->SetSize(tsz);
1036 }
1037 }
1038 else
1039 #else // TEXTCTRL_TEXT_CENTERED
1040 wxUnusedVar(textCtrlXAdjust);
1041 wxUnusedVar(textCtrlYAdjust);
1042 #endif // !TEXTCTRL_TEXT_CENTERED/TEXTCTRL_TEXT_CENTERED
1043 {
1044 // If it has border, have textctrl will the entire text field.
1045 m_text->SetSize( m_tcArea.x + m_widthCustomPaint,
1046 m_tcArea.y,
1047 m_tcArea.width - m_widthCustomPaint,
1048 m_tcArea.height );
1049 }
1050 }
1051
1052 wxSize wxComboCtrlBase::DoGetBestSize() const
1053 {
1054 wxSize sizeText(150,0);
1055
1056 if ( m_text )
1057 sizeText = m_text->GetBestSize();
1058
1059 // TODO: Better method to calculate close-to-native control height.
1060
1061 int fhei;
1062 if ( m_font.Ok() )
1063 fhei = (m_font.GetPointSize()*2) + 5;
1064 else if ( wxNORMAL_FONT->Ok() )
1065 fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5;
1066 else
1067 fhei = sizeText.y + 4;
1068
1069 // Need to force height to accomodate bitmap?
1070 int btnSizeY = m_btnSize.y;
1071 if ( m_bmpNormal.Ok() && fhei < btnSizeY )
1072 fhei = btnSizeY;
1073
1074 // Control height doesn't depend on border
1075 /*
1076 // Add border
1077 int border = m_windowStyle & wxBORDER_MASK;
1078 if ( border == wxSIMPLE_BORDER )
1079 fhei += 2;
1080 else if ( border == wxNO_BORDER )
1081 fhei += (m_widthCustomBorder*2);
1082 else
1083 // Sunken etc.
1084 fhei += 4;
1085 */
1086
1087 // Final adjustments
1088 #ifdef __WXGTK__
1089 fhei += 1;
1090 #endif
1091
1092 #ifdef __WXMAC__
1093 // these are the numbers from the HIG:
1094 switch ( m_windowVariant )
1095 {
1096 case wxWINDOW_VARIANT_NORMAL:
1097 default :
1098 fhei = 22;
1099 break;
1100 case wxWINDOW_VARIANT_SMALL:
1101 fhei = 19;
1102 break;
1103 case wxWINDOW_VARIANT_MINI:
1104 fhei = 15;
1105 break;
1106 }
1107 #endif
1108
1109 fhei += 2 * FOCUS_RING;
1110 int width = sizeText.x + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH;
1111
1112 wxSize ret(width, fhei);
1113 CacheBestSize(ret);
1114 return ret;
1115 }
1116
1117 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event )
1118 {
1119 if ( !IsCreated() )
1120 return;
1121
1122 // defined by actual wxComboCtrls
1123 OnResize();
1124
1125 event.Skip();
1126 }
1127
1128 // ----------------------------------------------------------------------------
1129 // standard operations
1130 // ----------------------------------------------------------------------------
1131
1132 bool wxComboCtrlBase::Enable(bool enable)
1133 {
1134 if ( !wxControl::Enable(enable) )
1135 return false;
1136
1137 if ( m_btn )
1138 m_btn->Enable(enable);
1139 if ( m_text )
1140 m_text->Enable(enable);
1141
1142 Refresh();
1143
1144 return true;
1145 }
1146
1147 bool wxComboCtrlBase::Show(bool show)
1148 {
1149 if ( !wxControl::Show(show) )
1150 return false;
1151
1152 if (m_btn)
1153 m_btn->Show(show);
1154
1155 if (m_text)
1156 m_text->Show(show);
1157
1158 return true;
1159 }
1160
1161 bool wxComboCtrlBase::SetFont ( const wxFont& font )
1162 {
1163 if ( !wxControl::SetFont(font) )
1164 return false;
1165
1166 if (m_text)
1167 m_text->SetFont(font);
1168
1169 return true;
1170 }
1171
1172 #if wxUSE_TOOLTIPS
1173 void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
1174 {
1175 wxControl::DoSetToolTip(tooltip);
1176
1177 // Set tool tip for button and text box
1178 if ( tooltip )
1179 {
1180 const wxString &tip = tooltip->GetTip();
1181 if ( m_text ) m_text->SetToolTip(tip);
1182 if ( m_btn ) m_btn->SetToolTip(tip);
1183 }
1184 else
1185 {
1186 if ( m_text ) m_text->SetToolTip( (wxToolTip*) NULL );
1187 if ( m_btn ) m_btn->SetToolTip( (wxToolTip*) NULL );
1188 }
1189 }
1190 #endif // wxUSE_TOOLTIPS
1191
1192 #if wxUSE_VALIDATORS
1193 void wxComboCtrlBase::SetValidator(const wxValidator& validator)
1194 {
1195 wxTextCtrl* textCtrl = GetTextCtrl();
1196
1197 if ( textCtrl )
1198 textCtrl->SetValidator( validator );
1199 else
1200 wxControl::SetValidator( validator );
1201 }
1202
1203 wxValidator* wxComboCtrlBase::GetValidator()
1204 {
1205 wxTextCtrl* textCtrl = GetTextCtrl();
1206
1207 return textCtrl ? textCtrl->GetValidator() : wxControl::GetValidator();
1208 }
1209 #endif // wxUSE_VALIDATORS
1210
1211 // ----------------------------------------------------------------------------
1212 // painting
1213 // ----------------------------------------------------------------------------
1214
1215 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1216 // prepare combo box background on area in a way typical on platform
1217 void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
1218 {
1219 wxSize sz = GetClientSize();
1220 bool isEnabled;
1221 bool isFocused; // also selected
1222
1223 // For smaller size control (and for disabled background) use less spacing
1224 int focusSpacingX;
1225 int focusSpacingY;
1226
1227 if ( !(flags & wxCONTROL_ISSUBMENU) )
1228 {
1229 // Drawing control
1230 isEnabled = IsEnabled();
1231 isFocused = ShouldDrawFocus();
1232
1233 // Windows-style: for smaller size control (and for disabled background) use less spacing
1234 focusSpacingX = isEnabled ? 2 : 1;
1235 focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1;
1236 }
1237 else
1238 {
1239 // Drawing a list item
1240 isEnabled = true; // they are never disabled
1241 isFocused = flags & wxCONTROL_SELECTED ? true : false;
1242
1243 focusSpacingX = 0;
1244 focusSpacingY = 0;
1245 }
1246
1247 // Set the background sub-rectangle for selection, disabled etc
1248 wxRect selRect(rect);
1249 selRect.y += focusSpacingY;
1250 selRect.height -= (focusSpacingY*2);
1251
1252 int wcp = 0;
1253
1254 if ( !(flags & wxCONTROL_ISSUBMENU) )
1255 wcp += m_widthCustomPaint;
1256
1257 selRect.x += wcp + focusSpacingX;
1258 selRect.width -= wcp + (focusSpacingX*2);
1259
1260 wxColour bgCol;
1261
1262 if ( isEnabled )
1263 {
1264 // If popup is hidden and this control is focused,
1265 // then draw the focus-indicator (selbgcolor background etc.).
1266 if ( isFocused )
1267 {
1268 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
1269 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
1270 }
1271 else
1272 {
1273 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
1274 #ifndef __WXMAC__ // see note in OnThemeChange
1275 bgCol = GetBackgroundColour();
1276 #else
1277 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1278 #endif
1279 }
1280 }
1281 else
1282 {
1283 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
1284 #ifndef __WXMAC__ // see note in OnThemeChange
1285 bgCol = GetBackgroundColour();
1286 #else
1287 bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1288 #endif
1289 }
1290
1291 dc.SetBrush( bgCol );
1292 dc.SetPen( bgCol );
1293 dc.DrawRectangle( selRect );
1294
1295 // Don't clip exactly to the selection rectangle so we can draw
1296 // to the non-selected area in front of it.
1297 wxRect clipRect(rect.x,rect.y,
1298 (selRect.x+selRect.width)-rect.x,rect.height);
1299 dc.SetClippingRegion(clipRect);
1300 }
1301 #else
1302 // Save the library size a bit for platforms that re-implement this.
1303 void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const
1304 {
1305 }
1306 #endif
1307
1308 void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int paintBg )
1309 {
1310 int drawState = m_btnState;
1311
1312 #ifdef __WXGTK__
1313 if ( GetPopupWindowState() >= Animating )
1314 drawState |= wxCONTROL_PRESSED;
1315 #endif
1316
1317 wxRect drawRect(rect.x+m_btnSpacingX,
1318 rect.y+((rect.height-m_btnSize.y)/2),
1319 m_btnSize.x,
1320 m_btnSize.y);
1321
1322 // Make sure area is not larger than the control
1323 if ( drawRect.y < rect.y )
1324 drawRect.y = rect.y;
1325 if ( drawRect.height > rect.height )
1326 drawRect.height = rect.height;
1327
1328 bool enabled = IsEnabled();
1329
1330 if ( !enabled )
1331 drawState |= wxCONTROL_DISABLED;
1332
1333 if ( !m_bmpNormal.Ok() )
1334 {
1335 // Need to clear button background even if m_btn is present
1336 if ( paintBg )
1337 {
1338 wxColour bgCol;
1339
1340 if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE )
1341 bgCol = GetParent()->GetBackgroundColour();
1342 else
1343 bgCol = GetBackgroundColour();
1344
1345 dc.SetBrush(bgCol);
1346 dc.SetPen(bgCol);
1347 dc.DrawRectangle(rect);
1348 }
1349
1350 // Draw standard button
1351 wxRendererNative::Get().DrawComboBoxDropButton(this,
1352 dc,
1353 drawRect,
1354 drawState);
1355 }
1356 else
1357 {
1358 // Draw bitmap
1359
1360 wxBitmap* pBmp;
1361
1362 if ( !enabled )
1363 pBmp = &m_bmpDisabled;
1364 else if ( m_btnState & wxCONTROL_PRESSED )
1365 pBmp = &m_bmpPressed;
1366 else if ( m_btnState & wxCONTROL_CURRENT )
1367 pBmp = &m_bmpHover;
1368 else
1369 pBmp = &m_bmpNormal;
1370
1371 if ( m_blankButtonBg )
1372 {
1373 // If using blank button background, we need to clear its background
1374 // with button face colour instead of colour for rest of the control.
1375 if ( paintBg )
1376 {
1377 wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1378 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1379 dc.SetPen(bgCol);
1380 dc.SetBrush(bgCol);
1381 dc.DrawRectangle(rect);
1382 }
1383
1384 wxRendererNative::Get().DrawPushButton(this,
1385 dc,
1386 drawRect,
1387 drawState);
1388
1389 }
1390 else
1391
1392 {
1393 // Need to clear button background even if m_btn is present
1394 // (assume non-button background was cleared just before this call so brushes are good)
1395 if ( paintBg )
1396 dc.DrawRectangle(rect);
1397 }
1398
1399 // Draw bitmap centered in drawRect
1400 dc.DrawBitmap(*pBmp,
1401 drawRect.x + (drawRect.width-pBmp->GetWidth())/2,
1402 drawRect.y + (drawRect.height-pBmp->GetHeight())/2,
1403 true);
1404 }
1405 }
1406
1407 void wxComboCtrlBase::RecalcAndRefresh()
1408 {
1409 if ( IsCreated() )
1410 {
1411 wxSizeEvent evt(GetSize(),GetId());
1412 GetEventHandler()->ProcessEvent(evt);
1413 Refresh();
1414 }
1415 }
1416
1417 // ----------------------------------------------------------------------------
1418 // miscellaneous event handlers
1419 // ----------------------------------------------------------------------------
1420
1421 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event)
1422 {
1423 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
1424 {
1425 if ( m_ignoreEvtText > 0 )
1426 {
1427 m_ignoreEvtText--;
1428 return;
1429 }
1430 }
1431
1432 // Change event id, object and string before relaying it forward
1433 event.SetId(GetId());
1434 wxString s = event.GetString();
1435 event.SetEventObject(this);
1436 event.SetString(s);
1437 event.Skip();
1438 }
1439
1440 // call if cursor is on button area or mouse is captured for the button
1441 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event,
1442 int flags )
1443 {
1444 int type = event.GetEventType();
1445
1446 if ( type == wxEVT_MOTION )
1447 {
1448 if ( flags & wxCC_MF_ON_BUTTON )
1449 {
1450 if ( !(m_btnState & wxCONTROL_CURRENT) )
1451 {
1452 // Mouse hover begins
1453 m_btnState |= wxCONTROL_CURRENT;
1454 if ( HasCapture() ) // Retain pressed state.
1455 m_btnState |= wxCONTROL_PRESSED;
1456 Refresh();
1457 }
1458 }
1459 else if ( (m_btnState & wxCONTROL_CURRENT) )
1460 {
1461 // Mouse hover ends
1462 m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED);
1463 Refresh();
1464 }
1465 }
1466 else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK )
1467 {
1468 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1469 {
1470 m_btnState |= wxCONTROL_PRESSED;
1471 Refresh();
1472
1473 if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) )
1474 OnButtonClick();
1475 else
1476 // If showing popup now, do not capture mouse or there will be interference
1477 CaptureMouse();
1478 }
1479 }
1480 else if ( type == wxEVT_LEFT_UP )
1481 {
1482
1483 // Only accept event if mouse was left-press was previously accepted
1484 if ( HasCapture() )
1485 ReleaseMouse();
1486
1487 if ( m_btnState & wxCONTROL_PRESSED )
1488 {
1489 // If mouse was inside, fire the click event.
1490 if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP )
1491 {
1492 if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) )
1493 OnButtonClick();
1494 }
1495
1496 m_btnState &= ~(wxCONTROL_PRESSED);
1497 Refresh();
1498 }
1499 }
1500 else if ( type == wxEVT_LEAVE_WINDOW )
1501 {
1502 if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) )
1503 {
1504 m_btnState &= ~(wxCONTROL_CURRENT);
1505
1506 // Mouse hover ends
1507 if ( IsPopupWindowState(Hidden) )
1508 {
1509 m_btnState &= ~(wxCONTROL_PRESSED);
1510 Refresh();
1511 }
1512 }
1513 }
1514 else
1515 return false;
1516
1517 return true;
1518 }
1519
1520 // returns true if event was consumed or filtered
1521 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event,
1522 int WXUNUSED(flags) )
1523 {
1524 wxLongLong t = ::wxGetLocalTimeMillis();
1525 int evtType = event.GetEventType();
1526
1527 #if USES_WXPOPUPWINDOW || USES_WXDIALOG
1528 if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW )
1529 {
1530 if ( IsPopupWindowState(Visible) &&
1531 ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) )
1532 {
1533 HidePopup();
1534 return true;
1535 }
1536 }
1537 #endif
1538
1539 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1540 if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick )
1541 {
1542 event.SetEventType(0);
1543 return true;
1544 }
1545
1546 return false;
1547 }
1548
1549 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event )
1550 {
1551 int evtType = event.GetEventType();
1552
1553 if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) &&
1554 (m_windowStyle & wxCB_READONLY) )
1555 {
1556 if ( GetPopupWindowState() >= Animating )
1557 {
1558 #if USES_WXPOPUPWINDOW
1559 // Click here always hides the popup.
1560 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1561 HidePopup();
1562 #endif
1563 }
1564 else
1565 {
1566 if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) )
1567 {
1568 // In read-only mode, clicking the text is the
1569 // same as clicking the button.
1570 OnButtonClick();
1571 }
1572 else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK )
1573 {
1574 //if ( m_popupInterface->CycleValue() )
1575 // Refresh();
1576 if ( m_popupInterface )
1577 m_popupInterface->OnComboDoubleClick();
1578 }
1579 }
1580 }
1581 else
1582 if ( IsPopupShown() )
1583 {
1584 // relay (some) mouse events to the popup
1585 if ( evtType == wxEVT_MOUSEWHEEL )
1586 m_popup->AddPendingEvent(event);
1587 }
1588 else if ( evtType )
1589 event.Skip();
1590 }
1591
1592 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
1593 {
1594 if ( IsPopupShown() )
1595 {
1596 // pass it to the popped up control
1597 GetPopupControl()->GetControl()->AddPendingEvent(event);
1598 }
1599 else // no popup
1600 {
1601 int keycode = event.GetKeyCode();
1602
1603 if ( keycode == WXK_TAB )
1604 {
1605 wxNavigationKeyEvent evt;
1606
1607 wxWindow* mainCtrl = GetMainWindowOfCompositeControl();
1608
1609 evt.SetFlags(wxNavigationKeyEvent::FromTab|
1610 (!event.ShiftDown() ? wxNavigationKeyEvent::IsForward
1611 : wxNavigationKeyEvent::IsBackward));
1612 evt.SetEventObject(mainCtrl);
1613 evt.SetCurrentFocus(mainCtrl);
1614 mainCtrl->GetParent()->GetEventHandler()->AddPendingEvent(evt);
1615 return;
1616 }
1617
1618 if ( IsKeyPopupToggle(event) )
1619 {
1620 OnButtonClick();
1621 return;
1622 }
1623
1624 int comboStyle = GetWindowStyle();
1625 wxComboPopup* popupInterface = GetPopupControl();
1626
1627 if ( !popupInterface )
1628 {
1629 event.Skip();
1630 return;
1631 }
1632
1633 if ( (comboStyle & wxCB_READONLY) ||
1634 (keycode != WXK_RIGHT && keycode != WXK_LEFT) )
1635 {
1636 popupInterface->OnComboKeyEvent(event);
1637 }
1638 else
1639 event.Skip();
1640 }
1641 }
1642
1643 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event )
1644 {
1645 if ( event.GetEventType() == wxEVT_SET_FOCUS )
1646 {
1647 wxWindow* tc = GetTextCtrl();
1648 if ( tc && tc != DoFindFocus() )
1649 #ifdef __WXMAC__
1650 m_resetFocus = true;
1651 #else
1652 tc->SetFocus();
1653 #endif
1654 }
1655
1656 Refresh();
1657 }
1658
1659 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) )
1660 {
1661 if ( m_resetFocus )
1662 {
1663 m_resetFocus = false;
1664 wxWindow* tc = GetTextCtrl();
1665 if ( tc )
1666 tc->SetFocus();
1667 }
1668 }
1669
1670 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
1671 {
1672 OnThemeChange();
1673 // indentation may also have changed
1674 if ( !(m_iFlags & wxCC_IFLAG_INDENT_SET) )
1675 m_absIndent = GetNativeTextIndent();
1676 RecalcAndRefresh();
1677 }
1678
1679 // ----------------------------------------------------------------------------
1680 // popup handling
1681 // ----------------------------------------------------------------------------
1682
1683 // Create popup window and the child control
1684 void wxComboCtrlBase::CreatePopup()
1685 {
1686 wxComboPopup* popupInterface = m_popupInterface;
1687 wxWindow* popup;
1688
1689 if ( !m_winPopup )
1690 {
1691 #ifdef wxComboPopupWindowBase2
1692 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP )
1693 {
1694 #if !USES_WXDIALOG
1695 m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER );
1696 #else
1697 m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString,
1698 wxPoint(-21,-21), wxSize(20, 20),
1699 wxNO_BORDER );
1700 #endif
1701 m_popupWinType = SECONDARY_POPUP_TYPE;
1702 }
1703 else
1704 #endif
1705 {
1706 m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER );
1707 m_popupWinType = PRIMARY_POPUP_TYPE;
1708 }
1709 m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this);
1710 m_winPopup->PushEventHandler(m_popupWinEvtHandler);
1711 }
1712
1713 popupInterface->Create(m_winPopup);
1714 m_popup = popup = popupInterface->GetControl();
1715
1716 m_popupExtraHandler = new wxComboPopupExtraEventHandler(this);
1717 popup->PushEventHandler( m_popupExtraHandler );
1718
1719 // This may be helpful on some platforms
1720 // (eg. it bypasses a wxGTK popupwindow bug where
1721 // window is not initially hidden when it should be)
1722 m_winPopup->Hide();
1723
1724 popupInterface->m_iFlags |= wxCP_IFLAG_CREATED;
1725 }
1726
1727 // Destroy popup window and the child control
1728 void wxComboCtrlBase::DestroyPopup()
1729 {
1730 HidePopup();
1731
1732 if ( m_popup )
1733 m_popup->RemoveEventHandler(m_popupExtraHandler);
1734
1735 delete m_popupExtraHandler;
1736
1737 delete m_popupInterface;
1738
1739 if ( m_winPopup )
1740 {
1741 m_winPopup->RemoveEventHandler(m_popupWinEvtHandler);
1742 delete m_popupWinEvtHandler;
1743 m_popupWinEvtHandler = NULL;
1744 m_winPopup->Destroy();
1745 }
1746
1747 m_popupExtraHandler = (wxEvtHandler*) NULL;
1748 m_popupInterface = (wxComboPopup*) NULL;
1749 m_winPopup = (wxWindow*) NULL;
1750 m_popup = (wxWindow*) NULL;
1751 }
1752
1753 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface)
1754 {
1755 wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") );
1756
1757 DestroyPopup();
1758
1759 iface->InitBase(this);
1760 iface->Init();
1761
1762 m_popupInterface = iface;
1763
1764 if ( !iface->LazyCreate() )
1765 {
1766 CreatePopup();
1767 }
1768 else
1769 {
1770 m_popup = (wxWindow*) NULL;
1771 }
1772
1773 // This must be done after creation
1774 if ( m_valueString.length() )
1775 {
1776 iface->SetStringValue(m_valueString);
1777 //Refresh();
1778 }
1779 }
1780
1781 // Ensures there is atleast the default popup
1782 void wxComboCtrlBase::EnsurePopupControl()
1783 {
1784 if ( !m_popupInterface )
1785 SetPopupControl(NULL);
1786 }
1787
1788 void wxComboCtrlBase::OnButtonClick()
1789 {
1790 // Derived classes can override this method for totally custom
1791 // popup action
1792 ShowPopup();
1793 }
1794
1795 void wxComboCtrlBase::ShowPopup()
1796 {
1797 EnsurePopupControl();
1798 wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") );
1799
1800 if ( IsPopupWindowState(Animating) )
1801 return;
1802
1803 SetFocus();
1804
1805 // Space above and below
1806 int screenHeight;
1807 wxPoint scrPos;
1808 int spaceAbove;
1809 int spaceBelow;
1810 int maxHeightPopup;
1811 wxSize ctrlSz = GetSize();
1812
1813 screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
1814 scrPos = GetParent()->ClientToScreen(GetPosition());
1815
1816 spaceAbove = scrPos.y;
1817 spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
1818
1819 maxHeightPopup = spaceBelow;
1820 if ( spaceAbove > spaceBelow )
1821 maxHeightPopup = spaceAbove;
1822
1823 // Width
1824 int widthPopup = ctrlSz.x + m_extLeft + m_extRight;
1825
1826 if ( widthPopup < m_widthMinPopup )
1827 widthPopup = m_widthMinPopup;
1828
1829 wxWindow* winPopup = m_winPopup;
1830 wxWindow* popup;
1831
1832 // Need to disable tab traversal of parent
1833 //
1834 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1835 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1836 // that if transient popup is open, then tab traversal is to be ignored.
1837 // However, I think this code would still be needed for cases where
1838 // transient popup doesn't work yet (wxWinCE?).
1839 wxWindow* parent = GetParent();
1840 int parentFlags = parent->GetWindowStyle();
1841 if ( parentFlags & wxTAB_TRAVERSAL )
1842 {
1843 parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) );
1844 m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL;
1845 }
1846
1847 if ( !winPopup )
1848 {
1849 CreatePopup();
1850 winPopup = m_winPopup;
1851 popup = m_popup;
1852 }
1853 else
1854 {
1855 popup = m_popup;
1856 }
1857
1858 winPopup->Enable();
1859
1860 wxASSERT( !m_popup || m_popup == popup ); // Consistency check.
1861
1862 wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup,
1863 m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup,
1864 maxHeightPopup);
1865
1866 popup->SetSize(adjustedSize);
1867 popup->Move(0,0);
1868 m_popupInterface->OnPopup();
1869
1870 //
1871 // Reposition and resize popup window
1872 //
1873
1874 wxSize szp = popup->GetSize();
1875
1876 int popupX;
1877 int popupY = scrPos.y + ctrlSz.y;
1878
1879 // Default anchor is wxLEFT
1880 int anchorSide = m_anchorSide;
1881 if ( !anchorSide )
1882 anchorSide = wxLEFT;
1883
1884 int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
1885 int leftX = scrPos.x - m_extLeft;
1886
1887 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
1888 leftX -= ctrlSz.x;
1889
1890 int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
1891
1892 // If there is not enough horizontal space, anchor on the other side.
1893 // If there is no space even then, place the popup at x 0.
1894 if ( anchorSide == wxRIGHT )
1895 {
1896 if ( rightX < 0 )
1897 {
1898 if ( (leftX+szp.x) < screenWidth )
1899 anchorSide = wxLEFT;
1900 else
1901 anchorSide = 0;
1902 }
1903 }
1904 else
1905 {
1906 if ( (leftX+szp.x) >= screenWidth )
1907 {
1908 if ( rightX >= 0 )
1909 anchorSide = wxRIGHT;
1910 else
1911 anchorSide = 0;
1912 }
1913 }
1914
1915 // Select x coordinate according to the anchor side
1916 if ( anchorSide == wxRIGHT )
1917 popupX = rightX;
1918 else if ( anchorSide == wxLEFT )
1919 popupX = leftX;
1920 else
1921 popupX = 0;
1922
1923 int showFlags = CanDeferShow;
1924
1925 if ( spaceBelow < szp.y )
1926 {
1927 popupY = scrPos.y - szp.y;
1928 showFlags |= ShowAbove;
1929 }
1930
1931 #if INSTALL_TOPLEV_HANDLER
1932 // Put top level window event handler into place
1933 if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW )
1934 {
1935 if ( !m_toplevEvtHandler )
1936 m_toplevEvtHandler = new wxComboFrameEventHandler(this);
1937
1938 wxWindow* toplev = ::wxGetTopLevelParent( this );
1939 wxASSERT( toplev );
1940 ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup();
1941 toplev->PushEventHandler( m_toplevEvtHandler );
1942 }
1943 #endif
1944
1945 // Set string selection (must be this way instead of SetStringSelection)
1946 if ( m_text )
1947 {
1948 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
1949 m_text->SelectAll();
1950
1951 m_popupInterface->SetStringValue( m_text->GetValue() );
1952 }
1953 else
1954 {
1955 // This is neede since focus/selection indication may change when popup is shown
1956 Refresh();
1957 }
1958
1959 // This must be after SetStringValue
1960 m_popupWinState = Animating;
1961
1962 wxRect popupWinRect( popupX, popupY, szp.x, szp.y );
1963
1964 m_popup = popup;
1965 if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) ||
1966 AnimateShow( popupWinRect, showFlags ) )
1967 {
1968 DoShowPopup( popupWinRect, showFlags );
1969 }
1970 }
1971
1972 bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) )
1973 {
1974 return true;
1975 }
1976
1977 void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) )
1978 {
1979 wxWindow* winPopup = m_winPopup;
1980
1981 if ( IsPopupWindowState(Animating) )
1982 {
1983 // Make sure the popup window is shown in the right position.
1984 // Should not matter even if animation already did this.
1985
1986 // Some platforms (GTK) may like SetSize and Move to be separate
1987 // (though the bug was probably fixed).
1988 winPopup->SetSize( rect );
1989
1990 winPopup->Show();
1991
1992 m_popupWinState = Visible;
1993 }
1994 else if ( IsPopupWindowState(Hidden) )
1995 {
1996 // Animation was aborted
1997
1998 wxASSERT( !winPopup->IsShown() );
1999
2000 m_popupWinState = Hidden;
2001 }
2002 }
2003
2004 void wxComboCtrlBase::OnPopupDismiss()
2005 {
2006 // Just in case, avoid double dismiss
2007 if ( IsPopupWindowState(Hidden) )
2008 return;
2009
2010 // This must be set before focus - otherwise there will be recursive
2011 // OnPopupDismisses.
2012 m_popupWinState = Hidden;
2013
2014 //SetFocus();
2015 m_winPopup->Disable();
2016
2017 // Inform popup control itself
2018 m_popupInterface->OnDismiss();
2019
2020 if ( m_popupExtraHandler )
2021 ((wxComboPopupExtraEventHandler*)m_popupExtraHandler)->OnPopupDismiss();
2022
2023 #if INSTALL_TOPLEV_HANDLER
2024 // Remove top level window event handler
2025 if ( m_toplevEvtHandler )
2026 {
2027 wxWindow* toplev = ::wxGetTopLevelParent( this );
2028 if ( toplev )
2029 toplev->RemoveEventHandler( m_toplevEvtHandler );
2030 }
2031 #endif
2032
2033 m_timeCanAcceptClick = ::wxGetLocalTimeMillis();
2034
2035 if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW )
2036 m_timeCanAcceptClick += 150;
2037
2038 // If cursor not on dropdown button, then clear its state
2039 // (technically not required by all ports, but do it for all just in case)
2040 if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) )
2041 m_btnState = 0;
2042
2043 // Return parent's tab traversal flag.
2044 // See ShowPopup for notes.
2045 if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL )
2046 {
2047 wxWindow* parent = GetParent();
2048 parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL );
2049 m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL);
2050 }
2051
2052 // refresh control (necessary even if m_text)
2053 Refresh();
2054
2055 SetFocus();
2056 }
2057
2058 void wxComboCtrlBase::HidePopup()
2059 {
2060 // Should be able to call this without popup interface
2061 if ( IsPopupWindowState(Hidden) )
2062 return;
2063
2064 // transfer value and show it in textctrl, if any
2065 if ( !IsPopupWindowState(Animating) )
2066 SetValue( m_popupInterface->GetStringValue() );
2067
2068 m_winPopup->Hide();
2069
2070 OnPopupDismiss();
2071 }
2072
2073 // ----------------------------------------------------------------------------
2074 // customization methods
2075 // ----------------------------------------------------------------------------
2076
2077 void wxComboCtrlBase::SetButtonPosition( int width, int height,
2078 int side, int spacingX )
2079 {
2080 m_btnWid = width;
2081 m_btnHei = height;
2082 m_btnSide = side;
2083 m_btnSpacingX = spacingX;
2084
2085 RecalcAndRefresh();
2086 }
2087
2088 wxSize wxComboCtrlBase::GetButtonSize()
2089 {
2090 if ( m_btnSize.x > 0 )
2091 return m_btnSize;
2092
2093 wxSize retSize(m_btnWid,m_btnHei);
2094
2095 // Need to call CalculateAreas now if button size is
2096 // is not explicitly specified.
2097 if ( retSize.x <= 0 || retSize.y <= 0)
2098 {
2099 OnResize();
2100
2101 retSize = m_btnSize;
2102 }
2103
2104 return retSize;
2105 }
2106
2107 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
2108 bool blankButtonBg,
2109 const wxBitmap& bmpPressed,
2110 const wxBitmap& bmpHover,
2111 const wxBitmap& bmpDisabled )
2112 {
2113 m_bmpNormal = bmpNormal;
2114 m_blankButtonBg = blankButtonBg;
2115
2116 if ( bmpPressed.Ok() )
2117 m_bmpPressed = bmpPressed;
2118 else
2119 m_bmpPressed = bmpNormal;
2120
2121 if ( bmpHover.Ok() )
2122 m_bmpHover = bmpHover;
2123 else
2124 m_bmpHover = bmpNormal;
2125
2126 if ( bmpDisabled.Ok() )
2127 m_bmpDisabled = bmpDisabled;
2128 else
2129 m_bmpDisabled = bmpNormal;
2130
2131 RecalcAndRefresh();
2132 }
2133
2134 void wxComboCtrlBase::SetCustomPaintWidth( int width )
2135 {
2136 if ( m_text )
2137 {
2138 // move textctrl accordingly
2139 wxRect r = m_text->GetRect();
2140 int inc = width - m_widthCustomPaint;
2141 r.x += inc;
2142 r.width -= inc;
2143 m_text->SetSize( r );
2144 }
2145
2146 m_widthCustomPaint = width;
2147
2148 RecalcAndRefresh();
2149 }
2150
2151 void wxComboCtrlBase::SetTextIndent( int indent )
2152 {
2153 if ( indent < 0 )
2154 {
2155 m_absIndent = GetNativeTextIndent();
2156 m_iFlags &= ~(wxCC_IFLAG_INDENT_SET);
2157 }
2158 else
2159 {
2160 m_absIndent = indent;
2161 m_iFlags |= wxCC_IFLAG_INDENT_SET;
2162 }
2163
2164 RecalcAndRefresh();
2165 }
2166
2167 wxCoord wxComboCtrlBase::GetNativeTextIndent() const
2168 {
2169 return DEFAULT_TEXT_INDENT;
2170 }
2171
2172 // ----------------------------------------------------------------------------
2173 // methods forwarded to wxTextCtrl
2174 // ----------------------------------------------------------------------------
2175
2176 wxString wxComboCtrlBase::GetValue() const
2177 {
2178 if ( m_text )
2179 return m_text->GetValue();
2180 return m_valueString;
2181 }
2182
2183 void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent)
2184 {
2185 if ( m_text )
2186 {
2187 if ( !withEvent )
2188 m_ignoreEvtText++;
2189
2190 m_text->SetValue(value);
2191 if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) )
2192 m_text->SelectAll();
2193 }
2194
2195 // Since wxComboPopup may want to paint the combo as well, we need
2196 // to set the string value here (as well as sometimes in ShowPopup).
2197 if ( m_valueString != value )
2198 {
2199 m_valueString = value;
2200
2201 EnsurePopupControl();
2202
2203 if (m_popupInterface)
2204 m_popupInterface->SetStringValue(value);
2205 }
2206
2207 Refresh();
2208 }
2209
2210 void wxComboCtrlBase::SetValue(const wxString& value)
2211 {
2212 SetValueWithEvent(value, false);
2213 }
2214
2215 // In this SetValue variant wxComboPopup::SetStringValue is not called
2216 void wxComboCtrlBase::SetText(const wxString& value)
2217 {
2218 // Unlike in SetValue(), this must be called here or
2219 // the behaviour will no be consistent in readonlys.
2220 EnsurePopupControl();
2221
2222 m_valueString = value;
2223
2224 if ( m_text )
2225 {
2226 m_ignoreEvtText++;
2227 m_text->SetValue( value );
2228 }
2229
2230 Refresh();
2231 }
2232
2233 void wxComboCtrlBase::Copy()
2234 {
2235 if ( m_text )
2236 m_text->Copy();
2237 }
2238
2239 void wxComboCtrlBase::Cut()
2240 {
2241 if ( m_text )
2242 m_text->Cut();
2243 }
2244
2245 void wxComboCtrlBase::Paste()
2246 {
2247 if ( m_text )
2248 m_text->Paste();
2249 }
2250
2251 void wxComboCtrlBase::SetInsertionPoint(long pos)
2252 {
2253 if ( m_text )
2254 m_text->SetInsertionPoint(pos);
2255 }
2256
2257 void wxComboCtrlBase::SetInsertionPointEnd()
2258 {
2259 if ( m_text )
2260 m_text->SetInsertionPointEnd();
2261 }
2262
2263 long wxComboCtrlBase::GetInsertionPoint() const
2264 {
2265 if ( m_text )
2266 return m_text->GetInsertionPoint();
2267
2268 return 0;
2269 }
2270
2271 long wxComboCtrlBase::GetLastPosition() const
2272 {
2273 if ( m_text )
2274 return m_text->GetLastPosition();
2275
2276 return 0;
2277 }
2278
2279 void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
2280 {
2281 if ( m_text )
2282 m_text->Replace(from, to, value);
2283 }
2284
2285 void wxComboCtrlBase::Remove(long from, long to)
2286 {
2287 if ( m_text )
2288 m_text->Remove(from, to);
2289 }
2290
2291 void wxComboCtrlBase::SetSelection(long from, long to)
2292 {
2293 if ( m_text )
2294 m_text->SetSelection(from, to);
2295 }
2296
2297 void wxComboCtrlBase::Undo()
2298 {
2299 if ( m_text )
2300 m_text->Undo();
2301 }
2302
2303 #endif // wxUSE_COMBOCTRL

  ViewVC Help
Powered by ViewVC 1.1.22