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_clientDatas
.Insert(NULL
, pos
);
476 m_widths
.Insert(-1,pos
);
477 m_widthsDirty
= true;
480 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
483 int wxVListBoxComboPopup::Append(const wxString
& item
)
485 int pos
= (int)m_strings
.GetCount();
487 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
490 // TODO: Could be optimized with binary search
491 wxArrayString strings
= m_strings
;
494 for ( i
=0; i
<strings
.GetCount(); i
++ )
496 if ( item
.Cmp(strings
.Item(i
)) < 0 )
509 void wxVListBoxComboPopup::Clear()
521 m_value
= wxNOT_FOUND
;
524 wxVListBox::SetItemCount(0);
527 void wxVListBoxComboPopup::ClearClientDatas()
529 if ( m_clientDataItemsType
== wxClientData_Object
)
532 for ( i
=0; i
<m_clientDatas
.GetCount(); i
++ )
533 delete (wxClientData
*) m_clientDatas
[i
];
536 m_clientDatas
.Empty();
539 void wxVListBoxComboPopup::SetItemClientData( unsigned int n
,
541 wxClientDataType clientDataItemsType
)
543 // It should be sufficient to update this variable only here
544 m_clientDataItemsType
= clientDataItemsType
;
546 m_clientDatas
[n
] = clientData
;
551 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n
) const
553 if ( m_clientDatas
.GetCount() > n
)
554 return m_clientDatas
[n
];
559 void wxVListBoxComboPopup::Delete( unsigned int item
)
561 // Remove client data, if set
562 if ( m_clientDatas
.GetCount() )
564 if ( m_clientDataItemsType
== wxClientData_Object
)
565 delete (wxClientData
*) m_clientDatas
[item
];
567 m_clientDatas
.RemoveAt(item
);
570 m_strings
.RemoveAt(item
);
571 m_widths
.RemoveAt(item
);
573 if ( (int)item
== m_widestItem
)
576 int sel
= GetSelection();
579 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
582 if ( (int)item
< sel
)
584 else if ( (int)item
== sel
)
585 SetSelection(wxNOT_FOUND
);
588 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
590 return m_strings
.Index(s
, bCase
);
593 unsigned int wxVListBoxComboPopup::GetCount() const
595 return m_strings
.GetCount();
598 wxString
wxVListBoxComboPopup::GetString( int item
) const
600 return m_strings
[item
];
603 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
605 m_strings
[item
] = str
;
606 ItemWidthChanged(item
);
609 wxString
wxVListBoxComboPopup::GetStringValue() const
612 return m_strings
[m_value
];
613 return wxEmptyString
;
616 void wxVListBoxComboPopup::SetSelection( int item
)
618 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
619 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
624 wxVListBox::SetSelection(item
);
627 int wxVListBoxComboPopup::GetSelection() const
632 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
634 int index
= m_strings
.Index(value
);
638 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
639 wxVListBox::SetSelection(index
);
642 void wxVListBoxComboPopup::CalcWidths()
644 bool doFindWidest
= m_findWidest
;
646 // Measure items with dirty width.
650 unsigned int n
= m_widths
.GetCount();
651 int dirtyHandled
= 0;
652 wxArrayInt
& widths
= m_widths
;
654 // I think using wxDC::GetTextExtent is faster than
655 // wxWindow::GetTextExtent (assuming same dc is used
656 // for all calls, as we do here).
657 wxClientDC
dc(m_combo
);
658 dc
.SetFont(m_useFont
);
660 for ( i
=0; i
<n
; i
++ )
664 wxCoord x
= OnMeasureItemWidth(i
);
668 const wxString
& text
= m_strings
[i
];
670 // To make sure performance won't suck in extreme scenarios,
671 // we'll estimate length after some arbitrary number of items
672 // have been checked precily.
673 if ( dirtyHandled
< 1024 )
676 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
681 x
= text
.length() * (dc
.GetCharWidth()+1);
687 if ( x
>= m_widestWidth
)
690 m_widestItem
= (int)i
;
692 else if ( (int)i
== m_widestItem
)
694 // Width of previously widest item has been decreased, so
695 // we'll have to check all to find current widest item.
703 m_widthsDirty
= false;
709 unsigned int n
= m_widths
.GetCount();
714 for ( i
=0; i
<n
; i
++ )
724 m_widestWidth
= bestWidth
;
725 m_widestItem
= bestIndex
;
727 m_findWidest
= false;
731 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
735 maxHeight
-= 2; // Must take borders into account
737 if ( m_strings
.GetCount() )
739 if ( prefHeight
> 0 )
742 if ( height
> maxHeight
)
745 int totalHeight
= GetTotalHeight(); // + 3;
746 if ( height
>= totalHeight
)
748 height
= totalHeight
;
752 // Adjust height to a multiple of the height of the first item
753 // NB: Calculations that take variable height into account
755 int fih
= GetLineHeight(0);
756 height
-= height
% fih
;
764 // Take scrollbar into account in width calculations
765 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
766 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
770 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
771 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
775 int n
= choices
.GetCount();
777 for ( i
=0; i
<n
; i
++ )
779 const wxString
& item
= choices
.Item(i
);
783 m_widths
.SetCount(n
,-1);
784 m_widthsDirty
= true;
787 wxVListBox::SetItemCount(n
);
789 // Sort the initial choices
790 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
793 // Find initial selection
794 wxString strValue
= m_combo
->GetValue();
795 if ( strValue
.length() )
796 m_value
= m_strings
.Index(strValue
);
799 // ----------------------------------------------------------------------------
800 // wxOwnerDrawnComboBox
801 // ----------------------------------------------------------------------------
804 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
808 #if wxUSE_EXTENDED_RTTI
809 IMPLEMENT_DYNAMIC_CLASS2_XTI(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
, "wx/odcombo.h")
811 wxBEGIN_PROPERTIES_TABLE(wxOwnerDrawnComboBox
)
812 wxEND_PROPERTIES_TABLE()
814 wxBEGIN_HANDLERS_TABLE(wxOwnerDrawnComboBox
)
815 wxEND_HANDLERS_TABLE()
817 wxCONSTRUCTOR_5( wxOwnerDrawnComboBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
819 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
822 void wxOwnerDrawnComboBox::Init()
826 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
828 const wxString
& value
,
832 const wxValidator
& validator
,
833 const wxString
& name
)
835 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
838 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
840 const wxString
& value
,
843 const wxArrayString
& choices
,
845 const wxValidator
& validator
,
846 const wxString
& name
)
851 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
854 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
856 const wxString
& value
,
859 const wxArrayString
& choices
,
861 const wxValidator
& validator
,
862 const wxString
& name
)
865 //wxCArrayString chs(choices);
867 //return Create(parent, id, value, pos, size, chs.GetCount(),
868 // chs.GetStrings(), style, validator, name);
869 return Create(parent
, id
, value
, pos
, size
, 0,
870 NULL
, style
, validator
, name
);
873 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
875 const wxString
& value
,
879 const wxString choices
[],
881 const wxValidator
& validator
,
882 const wxString
& name
)
885 if ( !Create(parent
, id
, value
, pos
, size
, style
,
892 for ( i
=0; i
<n
; i
++ )
893 m_initChs
.Add(choices
[i
]);
898 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
900 if ( m_popupInterface
)
901 GetVListBoxComboPopup()->ClearClientDatas();
904 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
908 popup
= new wxVListBoxComboPopup();
911 wxComboCtrl::DoSetPopupControl(popup
);
915 // Add initial choices to the wxVListBox
916 if ( !GetVListBoxComboPopup()->GetCount() )
918 GetVListBoxComboPopup()->Populate(m_initChs
);
923 // ----------------------------------------------------------------------------
924 // wxOwnerDrawnComboBox item manipulation methods
925 // ----------------------------------------------------------------------------
927 void wxOwnerDrawnComboBox::DoClear()
929 EnsurePopupControl();
931 GetVListBoxComboPopup()->Clear();
933 SetValue(wxEmptyString
);
936 void wxOwnerDrawnComboBox::DoDeleteOneItem(unsigned int n
)
938 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
940 if ( GetSelection() == (int) n
)
941 SetValue(wxEmptyString
);
943 GetVListBoxComboPopup()->Delete(n
);
946 unsigned int wxOwnerDrawnComboBox::GetCount() const
948 if ( !m_popupInterface
)
949 return m_initChs
.GetCount();
951 return GetVListBoxComboPopup()->GetCount();
954 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
956 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
958 if ( !m_popupInterface
)
959 return m_initChs
.Item(n
);
961 return GetVListBoxComboPopup()->GetString(n
);
964 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
966 EnsurePopupControl();
968 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
970 GetVListBoxComboPopup()->SetString(n
,s
);
973 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
975 if ( !m_popupInterface
)
976 return m_initChs
.Index(s
, bCase
);
978 return GetVListBoxComboPopup()->FindString(s
, bCase
);
981 void wxOwnerDrawnComboBox::Select(int n
)
983 EnsurePopupControl();
985 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
987 GetVListBoxComboPopup()->SetSelection(n
);
991 str
= GetVListBoxComboPopup()->GetString(n
);
993 // Refresh text portion in control
995 m_text
->SetValue( str
);
1002 int wxOwnerDrawnComboBox::GetSelection() const
1004 if ( !m_popupInterface
)
1005 return m_initChs
.Index(m_valueString
);
1007 return GetVListBoxComboPopup()->GetSelection();
1010 int wxOwnerDrawnComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
1013 wxClientDataType type
)
1015 EnsurePopupControl();
1017 const unsigned int count
= items
.GetCount();
1018 for( unsigned int i
= 0; i
< count
; ++i
, ++pos
)
1020 GetVListBoxComboPopup()->Insert(items
[i
], pos
);
1021 AssignNewItemClientData(pos
, clientData
, i
, type
);
1027 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
1029 EnsurePopupControl();
1031 GetVListBoxComboPopup()->SetItemClientData(n
,clientData
,m_clientDataItemsType
);
1034 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1036 if ( !m_popupInterface
)
1039 return GetVListBoxComboPopup()->GetItemClientData(n
);
1042 // ----------------------------------------------------------------------------
1043 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1044 // ----------------------------------------------------------------------------
1046 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1051 if ( flags
& wxODCB_PAINTING_CONTROL
)
1053 dc
.DrawText( GetValue(),
1054 rect
.x
+ GetTextIndent(),
1055 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1059 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1063 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1068 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1073 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
,
1078 // We need only to explicitly draw background for items
1079 // that should have selected background. Also, call PrepareBackground
1080 // always when painting the control so that clipping is done properly.
1082 if ( (flags
& wxODCB_PAINTING_SELECTED
) ||
1083 ((flags
& wxODCB_PAINTING_CONTROL
) && HasFlag(wxCB_READONLY
)) )
1085 int bgFlags
= wxCONTROL_SELECTED
;
1087 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
1088 bgFlags
|= wxCONTROL_ISSUBMENU
;
1090 PrepareBackground(dc
, rect
, bgFlags
);
1094 #endif // wxUSE_ODCOMBOBOX