1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/odcombo.cpp
3 // Purpose: wxOwnerDrawnComboBox, wxVListBoxComboPopup
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/odcombo.h"
32 #include "wx/combobox.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/dialog.h"
40 // ============================================================================
42 // ============================================================================
44 // time in milliseconds before partial completion buffer drops
45 #define wxODCB_PARTIAL_COMPLETION_TIME 1000
47 // ----------------------------------------------------------------------------
48 // wxVListBoxComboPopup is a wxVListBox customized to act as a popup control
50 // ----------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(wxVListBoxComboPopup
, wxVListBox
)
54 EVT_MOTION(wxVListBoxComboPopup::OnMouseMove
)
55 EVT_KEY_DOWN(wxVListBoxComboPopup::OnKey
)
56 EVT_LEFT_UP(wxVListBoxComboPopup::OnLeftClick
)
60 void wxVListBoxComboPopup::Init()
64 m_widthsDirty
= false;
69 m_clientDataItemsType
= wxClientData_None
;
70 m_partialCompletionString
= wxEmptyString
;
73 bool wxVListBoxComboPopup::Create(wxWindow
* parent
)
75 if ( !wxVListBox::Create(parent
,
79 wxBORDER_SIMPLE
| wxLB_INT_HEIGHT
| wxWANTS_CHARS
) )
82 m_useFont
= m_combo
->GetFont();
84 wxVListBox::SetItemCount(m_strings
.GetCount());
86 // TODO: Move this to SetFont
87 m_itemHeight
= GetCharHeight() + 0;
92 wxVListBoxComboPopup::~wxVListBoxComboPopup()
97 bool wxVListBoxComboPopup::LazyCreate()
99 // NB: There is a bug with wxVListBox that can be avoided by creating
100 // it later (bug causes empty space to be shown if initial selection
101 // is at the end of a list longer than the control can show at once).
105 // paint the control itself
106 void wxVListBoxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
108 if ( !(m_combo
->GetWindowStyle() & wxODCB_STD_CONTROL_PAINT
) )
110 int flags
= wxODCB_PAINTING_CONTROL
;
112 if ( m_combo
->ShouldDrawFocus() )
113 flags
|= wxODCB_PAINTING_SELECTED
;
115 OnDrawBg(dc
, rect
, m_value
, flags
);
119 OnDrawItem(dc
,rect
,m_value
,flags
);
124 wxComboPopup::PaintComboControl(dc
,rect
);
127 void wxVListBoxComboPopup::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
129 // TODO: Maybe this code could be moved to wxVListBox::OnPaint?
130 dc
.SetFont(m_useFont
);
134 // Set correct text colour for selected items
135 if ( wxVListBox::GetSelection() == (int) n
)
137 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
138 flags
|= wxODCB_PAINTING_SELECTED
;
142 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
145 OnDrawItem(dc
,rect
,(int)n
,flags
);
148 wxCoord
wxVListBoxComboPopup::OnMeasureItem(size_t n
) const
150 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
152 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
153 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
155 wxCoord h
= combo
->OnMeasureItem(n
);
161 wxCoord
wxVListBoxComboPopup::OnMeasureItemWidth(size_t n
) const
163 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
165 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
166 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
168 return combo
->OnMeasureItemWidth(n
);
171 void wxVListBoxComboPopup::OnDrawBg( wxDC
& dc
,
176 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
178 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
179 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
181 if ( IsCurrent((size_t)item
) && !(flags
& wxODCB_PAINTING_CONTROL
) )
182 flags
|= wxODCB_PAINTING_SELECTED
;
184 combo
->OnDrawBackground(dc
,rect
,item
,flags
);
187 void wxVListBoxComboPopup::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
189 OnDrawBg(dc
,rect
,(int)n
,0);
192 // This is called from wxVListBoxComboPopup::OnDrawItem, with text colour and font prepared
193 void wxVListBoxComboPopup::OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
195 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
197 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
198 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
200 combo
->OnDrawItem(dc
,rect
,item
,flags
);
203 void wxVListBoxComboPopup::DismissWithEvent()
205 StopPartialCompletion();
207 int selection
= wxVListBox::GetSelection();
212 if ( selection
!= wxNOT_FOUND
)
213 valStr
= m_strings
[selection
];
215 valStr
= wxEmptyString
;
219 if ( valStr
!= m_combo
->GetValue() )
220 m_combo
->SetValueWithEvent(valStr
);
222 SendComboBoxEvent(selection
);
225 void wxVListBoxComboPopup::SendComboBoxEvent( int selection
)
227 wxCommandEvent
evt(wxEVT_COMMAND_COMBOBOX_SELECTED
,m_combo
->GetId());
229 evt
.SetEventObject(m_combo
);
231 evt
.SetInt(selection
);
233 // Set client data, if any
234 if ( selection
>= 0 && (int)m_clientDatas
.GetCount() > selection
)
236 void* clientData
= m_clientDatas
[selection
];
237 if ( m_clientDataItemsType
== wxClientData_Object
)
238 evt
.SetClientObject((wxClientData
*)clientData
);
240 evt
.SetClientData(clientData
);
243 m_combo
->GetEventHandler()->AddPendingEvent(evt
);
246 // returns true if key was consumed
247 bool wxVListBoxComboPopup::HandleKey( int keycode
, bool saturate
, wxChar unicode
)
250 int itemCount
= GetCount();
251 int comboStyle
= m_combo
->GetWindowStyle();
253 // this is the character equivalent of the code
255 if ((keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
257 keychar
= (wxChar
)keycode
;
264 if ( keycode
== WXK_DOWN
|| keycode
== WXK_RIGHT
)
267 StopPartialCompletion();
269 else if ( keycode
== WXK_UP
|| keycode
== WXK_LEFT
)
272 StopPartialCompletion();
274 else if ( keycode
== WXK_PAGEDOWN
)
277 StopPartialCompletion();
279 else if ( keycode
== WXK_PAGEUP
)
282 StopPartialCompletion();
284 else if ( comboStyle
& wxCB_READONLY
)
286 // Try partial completion
288 // find the new partial completion string
290 if (m_partialCompletionTimer
.IsRunning())
291 m_partialCompletionString
+=wxString(keychar
);
293 #endif // wxUSE_TIMER
294 m_partialCompletionString
=wxString(keychar
);
296 // now search through the values to see if this is found
298 unsigned int length
=m_partialCompletionString
.length();
300 for (i
=0; i
<itemCount
; i
++)
302 wxString item
=GetString(i
);
303 if (( item
.length() >= length
) && (! m_partialCompletionString
.CmpNoCase(item
.Left(length
))))
312 StopPartialCompletion();
314 return true; // to stop the first value being set
320 m_partialCompletionTimer
.Start(wxODCB_PARTIAL_COMPLETION_TIME
, true);
321 #endif // wxUSE_TIMER
329 if ( value
>= itemCount
)
330 value
= itemCount
- 1;
331 else if ( value
< 0 )
336 if ( value
>= itemCount
)
338 else if ( value
< 0 )
342 if ( value
== m_value
)
343 // Even if value was same, don't skip the event
344 // (good for consistency)
350 m_combo
->SetValue(m_strings
[value
]);
352 SendComboBoxEvent(m_value
);
357 // stop partial completion
358 void wxVListBoxComboPopup::StopPartialCompletion()
360 m_partialCompletionString
= wxEmptyString
;
362 m_partialCompletionTimer
.Stop();
363 #endif // wxUSE_TIMER
366 void wxVListBoxComboPopup::OnComboDoubleClick()
368 // Cycle on dclick (disable saturation to allow true cycling).
369 if ( !::wxGetKeyState(WXK_SHIFT
) )
370 HandleKey(WXK_DOWN
,false);
372 HandleKey(WXK_UP
,false);
375 void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
377 // Saturated key movement on
378 if ( !HandleKey(event
.GetKeyCode(),true,
380 event
.GetUnicodeKey()
388 void wxVListBoxComboPopup::OnPopup()
390 // *must* set value after size is set (this is because of a vlbox bug)
391 wxVListBox::SetSelection(m_value
);
394 void wxVListBoxComboPopup::OnMouseMove(wxMouseEvent
& event
)
398 // Move selection to cursor if it is inside the popup
400 int y
= event
.GetPosition().y
;
401 int fromBottom
= GetClientSize().y
- y
;
403 // Since in any case we need to find out if the last item is only
404 // partially visible, we might just as well replicate the HitTest
406 const size_t lineMax
= GetVisibleEnd();
407 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
409 y
-= OnGetRowHeight(line
);
412 // Only change selection if item is fully visible
413 if ( (y
+ fromBottom
) >= 0 )
415 wxVListBox::SetSelection((int)line
);
422 void wxVListBoxComboPopup::OnLeftClick(wxMouseEvent
& WXUNUSED(event
))
427 void wxVListBoxComboPopup::OnKey(wxKeyEvent
& event
)
429 // Hide popup if certain key or key combination was pressed
430 if ( m_combo
->IsKeyPopupToggle(event
) )
432 StopPartialCompletion();
435 else if ( event
.AltDown() )
437 // On both wxGTK and wxMSW, pressing Alt down seems to
438 // completely freeze things in popup (ie. arrow keys and
439 // enter won't work).
442 // Select item if ENTER is pressed
443 else if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
449 int comboStyle
= m_combo
->GetWindowStyle();
450 int keycode
= event
.GetKeyCode();
451 // Process partial completion key codes here, but not the arrow keys as the base class will do that for us
452 if ((comboStyle
& wxCB_READONLY
) &&
453 (keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
455 OnComboKeyEvent(event
);
456 SetSelection(m_value
); // ensure the highlight bar moves
463 void wxVListBoxComboPopup::Insert( const wxString
& item
, int pos
)
465 // Need to change selection?
467 if ( !(m_combo
->GetWindowStyle() & wxCB_READONLY
) &&
468 m_combo
->GetValue() == item
)
473 m_strings
.Insert(item
,pos
);
474 m_widths
.Insert(-1,pos
);
475 m_widthsDirty
= true;
478 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
481 int wxVListBoxComboPopup::Append(const wxString
& item
)
483 int pos
= (int)m_strings
.GetCount();
485 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
488 // TODO: Could be optimized with binary search
489 wxArrayString strings
= m_strings
;
492 for ( i
=0; i
<strings
.GetCount(); i
++ )
494 if ( item
.Cmp(strings
.Item(i
)) < 0 )
507 void wxVListBoxComboPopup::Clear()
519 m_value
= wxNOT_FOUND
;
522 wxVListBox::SetItemCount(0);
525 void wxVListBoxComboPopup::ClearClientDatas()
527 if ( m_clientDataItemsType
== wxClientData_Object
)
530 for ( i
=0; i
<m_clientDatas
.GetCount(); i
++ )
531 delete (wxClientData
*) m_clientDatas
[i
];
534 m_clientDatas
.Empty();
537 void wxVListBoxComboPopup::SetItemClientData( unsigned int n
,
539 wxClientDataType clientDataItemsType
)
541 // It should be sufficient to update this variable only here
542 m_clientDataItemsType
= clientDataItemsType
;
544 m_clientDatas
.SetCount(n
+1,NULL
);
545 m_clientDatas
[n
] = clientData
;
550 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n
) const
552 if ( m_clientDatas
.GetCount() > n
)
553 return m_clientDatas
[n
];
558 void wxVListBoxComboPopup::Delete( unsigned int item
)
560 // Remove client data, if set
561 if ( m_clientDatas
.GetCount() )
563 if ( m_clientDataItemsType
== wxClientData_Object
)
564 delete (wxClientData
*) m_clientDatas
[item
];
566 m_clientDatas
.RemoveAt(item
);
569 m_strings
.RemoveAt(item
);
570 m_widths
.RemoveAt(item
);
572 if ( (int)item
== m_widestItem
)
575 int sel
= GetSelection();
578 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
581 if ( (int)item
< sel
)
583 else if ( (int)item
== sel
)
584 SetSelection(wxNOT_FOUND
);
587 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
589 return m_strings
.Index(s
, bCase
);
592 unsigned int wxVListBoxComboPopup::GetCount() const
594 return m_strings
.GetCount();
597 wxString
wxVListBoxComboPopup::GetString( int item
) const
599 return m_strings
[item
];
602 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
604 m_strings
[item
] = str
;
605 ItemWidthChanged(item
);
608 wxString
wxVListBoxComboPopup::GetStringValue() const
611 return m_strings
[m_value
];
612 return wxEmptyString
;
615 void wxVListBoxComboPopup::SetSelection( int item
)
617 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
618 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
623 wxVListBox::SetSelection(item
);
626 int wxVListBoxComboPopup::GetSelection() const
631 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
633 int index
= m_strings
.Index(value
);
637 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
638 wxVListBox::SetSelection(index
);
641 void wxVListBoxComboPopup::CalcWidths()
643 bool doFindWidest
= m_findWidest
;
645 // Measure items with dirty width.
649 unsigned int n
= m_widths
.GetCount();
650 int dirtyHandled
= 0;
651 wxArrayInt
& widths
= m_widths
;
653 // I think using wxDC::GetTextExtent is faster than
654 // wxWindow::GetTextExtent (assuming same dc is used
655 // for all calls, as we do here).
656 wxClientDC
dc(m_combo
);
657 dc
.SetFont(m_useFont
);
659 for ( i
=0; i
<n
; i
++ )
663 wxCoord x
= OnMeasureItemWidth(i
);
667 const wxString
& text
= m_strings
[i
];
669 // To make sure performance won't suck in extreme scenarios,
670 // we'll estimate length after some arbitrary number of items
671 // have been checked precily.
672 if ( dirtyHandled
< 1024 )
675 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
680 x
= text
.length() * (dc
.GetCharWidth()+1);
686 if ( x
>= m_widestWidth
)
689 m_widestItem
= (int)i
;
691 else if ( (int)i
== m_widestItem
)
693 // Width of previously widest item has been decreased, so
694 // we'll have to check all to find current widest item.
702 m_widthsDirty
= false;
708 unsigned int n
= m_widths
.GetCount();
713 for ( i
=0; i
<n
; i
++ )
723 m_widestWidth
= bestWidth
;
724 m_widestItem
= bestIndex
;
726 m_findWidest
= false;
730 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
734 maxHeight
-= 2; // Must take borders into account
736 if ( m_strings
.GetCount() )
738 if ( prefHeight
> 0 )
741 if ( height
> maxHeight
)
744 int totalHeight
= GetTotalHeight(); // + 3;
745 if ( height
>= totalHeight
)
747 height
= totalHeight
;
751 // Adjust height to a multiple of the height of the first item
752 // NB: Calculations that take variable height into account
754 int fih
= GetLineHeight(0);
755 height
-= height
% fih
;
763 // Take scrollbar into account in width calculations
764 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
765 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
769 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
770 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
774 int n
= choices
.GetCount();
776 for ( i
=0; i
<n
; i
++ )
778 const wxString
& item
= choices
.Item(i
);
782 m_widths
.SetCount(n
,-1);
783 m_widthsDirty
= true;
786 wxVListBox::SetItemCount(n
);
788 // Sort the initial choices
789 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
792 // Find initial selection
793 wxString strValue
= m_combo
->GetValue();
794 if ( strValue
.length() )
795 m_value
= m_strings
.Index(strValue
);
798 // ----------------------------------------------------------------------------
799 // wxOwnerDrawnComboBox
800 // ----------------------------------------------------------------------------
803 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
807 #if wxUSE_EXTENDED_RTTI
808 IMPLEMENT_DYNAMIC_CLASS2_XTI(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
, "wx/odcombo.h")
810 wxBEGIN_PROPERTIES_TABLE(wxOwnerDrawnComboBox
)
811 wxEND_PROPERTIES_TABLE()
813 wxBEGIN_HANDLERS_TABLE(wxOwnerDrawnComboBox
)
814 wxEND_HANDLERS_TABLE()
816 wxCONSTRUCTOR_5( wxOwnerDrawnComboBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
818 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
821 void wxOwnerDrawnComboBox::Init()
825 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
827 const wxString
& value
,
831 const wxValidator
& validator
,
832 const wxString
& name
)
834 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
837 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
839 const wxString
& value
,
842 const wxArrayString
& choices
,
844 const wxValidator
& validator
,
845 const wxString
& name
)
850 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
853 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
855 const wxString
& value
,
858 const wxArrayString
& choices
,
860 const wxValidator
& validator
,
861 const wxString
& name
)
864 //wxCArrayString chs(choices);
866 //return Create(parent, id, value, pos, size, chs.GetCount(),
867 // chs.GetStrings(), style, validator, name);
868 return Create(parent
, id
, value
, pos
, size
, 0,
869 NULL
, style
, validator
, name
);
872 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
874 const wxString
& value
,
878 const wxString choices
[],
880 const wxValidator
& validator
,
881 const wxString
& name
)
884 if ( !Create(parent
, id
, value
, pos
, size
, style
,
891 for ( i
=0; i
<n
; i
++ )
892 m_initChs
.Add(choices
[i
]);
897 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
899 if ( m_popupInterface
)
900 GetVListBoxComboPopup()->ClearClientDatas();
903 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
907 popup
= new wxVListBoxComboPopup();
910 wxComboCtrl::DoSetPopupControl(popup
);
914 // Add initial choices to the wxVListBox
915 if ( !GetVListBoxComboPopup()->GetCount() )
917 GetVListBoxComboPopup()->Populate(m_initChs
);
922 // ----------------------------------------------------------------------------
923 // wxOwnerDrawnComboBox item manipulation methods
924 // ----------------------------------------------------------------------------
926 void wxOwnerDrawnComboBox::Clear()
928 EnsurePopupControl();
930 GetVListBoxComboPopup()->Clear();
932 SetValue(wxEmptyString
);
935 void wxOwnerDrawnComboBox::Delete(unsigned int n
)
937 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
939 if ( GetSelection() == (int) n
)
940 SetValue(wxEmptyString
);
942 GetVListBoxComboPopup()->Delete(n
);
945 unsigned int wxOwnerDrawnComboBox::GetCount() const
947 if ( !m_popupInterface
)
948 return m_initChs
.GetCount();
950 return GetVListBoxComboPopup()->GetCount();
953 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
955 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
957 if ( !m_popupInterface
)
958 return m_initChs
.Item(n
);
960 return GetVListBoxComboPopup()->GetString(n
);
963 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
965 EnsurePopupControl();
967 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
969 GetVListBoxComboPopup()->SetString(n
,s
);
972 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
974 if ( !m_popupInterface
)
975 return m_initChs
.Index(s
, bCase
);
977 return GetVListBoxComboPopup()->FindString(s
, bCase
);
980 void wxOwnerDrawnComboBox::Select(int n
)
982 EnsurePopupControl();
984 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
986 GetVListBoxComboPopup()->SetSelection(n
);
990 str
= GetVListBoxComboPopup()->GetString(n
);
992 // Refresh text portion in control
994 m_text
->SetValue( str
);
1001 int wxOwnerDrawnComboBox::GetSelection() const
1003 if ( !m_popupInterface
)
1004 return m_initChs
.Index(m_valueString
);
1006 return GetVListBoxComboPopup()->GetSelection();
1009 int wxOwnerDrawnComboBox::DoAppend(const wxString
& item
)
1011 EnsurePopupControl();
1012 wxASSERT(m_popupInterface
);
1014 return GetVListBoxComboPopup()->Append(item
);
1017 int wxOwnerDrawnComboBox::DoInsert(const wxString
& item
, unsigned int pos
)
1019 EnsurePopupControl();
1021 wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT
), -1, wxT("can't insert into sorted list"));
1022 wxCHECK_MSG(IsValidInsert(pos
), -1, wxT("invalid index"));
1024 GetVListBoxComboPopup()->Insert(item
,pos
);
1029 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
1031 EnsurePopupControl();
1033 GetVListBoxComboPopup()->SetItemClientData(n
,clientData
,m_clientDataItemsType
);
1036 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1038 if ( !m_popupInterface
)
1041 return GetVListBoxComboPopup()->GetItemClientData(n
);
1044 void wxOwnerDrawnComboBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
1046 DoSetItemClientData(n
, (void*) clientData
);
1049 wxClientData
* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n
) const
1051 return (wxClientData
*) DoGetItemClientData(n
);
1054 // ----------------------------------------------------------------------------
1055 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1056 // ----------------------------------------------------------------------------
1058 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1063 if ( flags
& wxODCB_PAINTING_CONTROL
)
1065 dc
.DrawText( GetValue(),
1066 rect
.x
+ GetTextIndent(),
1067 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1071 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1075 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1080 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1085 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
,
1090 // We need only to explicitly draw background for items
1091 // that should have selected background. Also, call PrepareBackground
1092 // always when painting the control so that clipping is done properly.
1094 if ( (flags
& wxODCB_PAINTING_SELECTED
) ||
1095 ((flags
& wxODCB_PAINTING_CONTROL
) && HasFlag(wxCB_READONLY
)) )
1097 int bgFlags
= wxCONTROL_SELECTED
;
1099 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
1100 bgFlags
|= wxCONTROL_ISSUBMENU
;
1102 PrepareBackground(dc
, rect
, bgFlags
);
1106 #endif // wxUSE_ODCOMBOBOX