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
,wxODCB_PAINTING_CONTROL
);
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
);
132 // Set correct text colour for selected items
133 if ( wxVListBox::GetSelection() == (int) n
)
134 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
136 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
138 OnDrawItem(dc
,rect
,(int)n
,0);
141 wxCoord
wxVListBoxComboPopup::OnMeasureItem(size_t n
) const
143 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
145 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
146 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
148 wxCoord h
= combo
->OnMeasureItem(n
);
154 wxCoord
wxVListBoxComboPopup::OnMeasureItemWidth(size_t n
) const
156 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
158 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
159 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
161 return combo
->OnMeasureItemWidth(n
);
164 void wxVListBoxComboPopup::OnDrawBg( wxDC
& dc
,
169 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
171 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
172 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
174 if ( IsCurrent((size_t)item
) && !(flags
& wxODCB_PAINTING_CONTROL
) )
175 flags
|= wxODCB_PAINTING_SELECTED
;
177 combo
->OnDrawBackground(dc
,rect
,item
,flags
);
180 void wxVListBoxComboPopup::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
182 OnDrawBg(dc
,rect
,(int)n
,0);
185 // This is called from wxVListBoxComboPopup::OnDrawItem, with text colour and font prepared
186 void wxVListBoxComboPopup::OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
188 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
190 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
191 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
193 combo
->OnDrawItem(dc
,rect
,item
,flags
);
196 void wxVListBoxComboPopup::DismissWithEvent()
198 StopPartialCompletion();
200 int selection
= wxVListBox::GetSelection();
205 if ( selection
!= wxNOT_FOUND
)
206 valStr
= m_strings
[selection
];
208 valStr
= wxEmptyString
;
212 if ( valStr
!= m_combo
->GetValue() )
213 m_combo
->SetValueWithEvent(valStr
);
215 SendComboBoxEvent(selection
);
218 void wxVListBoxComboPopup::SendComboBoxEvent( int selection
)
220 wxCommandEvent
evt(wxEVT_COMMAND_COMBOBOX_SELECTED
,m_combo
->GetId());
222 evt
.SetEventObject(m_combo
);
224 evt
.SetInt(selection
);
226 // Set client data, if any
227 if ( selection
>= 0 && (int)m_clientDatas
.GetCount() > selection
)
229 void* clientData
= m_clientDatas
[selection
];
230 if ( m_clientDataItemsType
== wxClientData_Object
)
231 evt
.SetClientObject((wxClientData
*)clientData
);
233 evt
.SetClientData(clientData
);
236 m_combo
->GetEventHandler()->AddPendingEvent(evt
);
239 // returns true if key was consumed
240 bool wxVListBoxComboPopup::HandleKey( int keycode
, bool saturate
, wxChar unicode
)
243 int itemCount
= GetCount();
244 int comboStyle
= m_combo
->GetWindowStyle();
246 // this is the character equivalent of the code
248 if ((keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
250 keychar
= (wxChar
)keycode
;
257 if ( keycode
== WXK_DOWN
|| keycode
== WXK_RIGHT
)
260 StopPartialCompletion();
262 else if ( keycode
== WXK_UP
|| keycode
== WXK_LEFT
)
265 StopPartialCompletion();
267 else if ( keycode
== WXK_PAGEDOWN
)
270 StopPartialCompletion();
272 else if ( keycode
== WXK_PAGEUP
)
275 StopPartialCompletion();
277 else if ( comboStyle
& wxCB_READONLY
)
279 // Try partial completion
281 // find the new partial completion string
283 if (m_partialCompletionTimer
.IsRunning())
284 m_partialCompletionString
+=wxString(keychar
);
286 #endif // wxUSE_TIMER
287 m_partialCompletionString
=wxString(keychar
);
289 // now search through the values to see if this is found
291 unsigned int length
=m_partialCompletionString
.length();
293 for (i
=0; i
<itemCount
; i
++)
295 wxString item
=GetString(i
);
296 if (( item
.length() >= length
) && (! m_partialCompletionString
.CmpNoCase(item
.Left(length
))))
305 StopPartialCompletion();
307 return true; // to stop the first value being set
313 m_partialCompletionTimer
.Start(wxODCB_PARTIAL_COMPLETION_TIME
, true);
314 #endif // wxUSE_TIMER
322 if ( value
>= itemCount
)
323 value
= itemCount
- 1;
324 else if ( value
< 0 )
329 if ( value
>= itemCount
)
331 else if ( value
< 0 )
335 if ( value
== m_value
)
336 // Even if value was same, don't skip the event
337 // (good for consistency)
343 m_combo
->SetValue(m_strings
[value
]);
345 SendComboBoxEvent(m_value
);
350 // stop partial completion
351 void wxVListBoxComboPopup::StopPartialCompletion()
353 m_partialCompletionString
= wxEmptyString
;
355 m_partialCompletionTimer
.Stop();
356 #endif // wxUSE_TIMER
359 void wxVListBoxComboPopup::OnComboDoubleClick()
361 // Cycle on dclick (disable saturation to allow true cycling).
362 if ( !::wxGetKeyState(WXK_SHIFT
) )
363 HandleKey(WXK_DOWN
,false);
365 HandleKey(WXK_UP
,false);
368 void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
370 // Saturated key movement on
371 if ( !HandleKey(event
.GetKeyCode(),true,
373 event
.GetUnicodeKey()
381 void wxVListBoxComboPopup::OnPopup()
383 // *must* set value after size is set (this is because of a vlbox bug)
384 wxVListBox::SetSelection(m_value
);
387 void wxVListBoxComboPopup::OnMouseMove(wxMouseEvent
& event
)
391 // Move selection to cursor if it is inside the popup
393 int y
= event
.GetPosition().y
;
394 int fromBottom
= GetClientSize().y
- y
;
396 // Since in any case we need to find out if the last item is only
397 // partially visible, we might just as well replicate the HitTest
399 const size_t lineMax
= GetVisibleEnd();
400 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
402 y
-= OnGetLineHeight(line
);
405 // Only change selection if item is fully visible
406 if ( (y
+ fromBottom
) >= 0 )
408 wxVListBox::SetSelection((int)line
);
415 void wxVListBoxComboPopup::OnLeftClick(wxMouseEvent
& WXUNUSED(event
))
420 void wxVListBoxComboPopup::OnKey(wxKeyEvent
& event
)
422 // Hide popup if certain key or key combination was pressed
423 if ( m_combo
->IsKeyPopupToggle(event
) )
425 StopPartialCompletion();
428 else if ( event
.AltDown() )
430 // On both wxGTK and wxMSW, pressing Alt down seems to
431 // completely freeze things in popup (ie. arrow keys and
432 // enter won't work).
435 // Select item if ENTER is pressed
436 else if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
442 int comboStyle
= m_combo
->GetWindowStyle();
443 int keycode
= event
.GetKeyCode();
444 // Process partial completion key codes here, but not the arrow keys as the base class will do that for us
445 if ((comboStyle
& wxCB_READONLY
) &&
446 (keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
448 OnComboKeyEvent(event
);
449 SetSelection(m_value
); // ensure the highlight bar moves
456 void wxVListBoxComboPopup::Insert( const wxString
& item
, int pos
)
458 // Need to change selection?
460 if ( !(m_combo
->GetWindowStyle() & wxCB_READONLY
) &&
461 m_combo
->GetValue() == item
)
466 m_strings
.Insert(item
,pos
);
467 m_widths
.Insert(-1,pos
);
468 m_widthsDirty
= true;
471 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
474 int wxVListBoxComboPopup::Append(const wxString
& item
)
476 int pos
= (int)m_strings
.GetCount();
478 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
481 // TODO: Could be optimized with binary search
482 wxArrayString strings
= m_strings
;
485 for ( i
=0; i
<strings
.GetCount(); i
++ )
487 if ( item
.Cmp(strings
.Item(i
)) < 0 )
500 void wxVListBoxComboPopup::Clear()
512 m_value
= wxNOT_FOUND
;
515 wxVListBox::SetItemCount(0);
518 void wxVListBoxComboPopup::ClearClientDatas()
520 if ( m_clientDataItemsType
== wxClientData_Object
)
523 for ( i
=0; i
<m_clientDatas
.GetCount(); i
++ )
524 delete (wxClientData
*) m_clientDatas
[i
];
527 m_clientDatas
.Empty();
530 void wxVListBoxComboPopup::SetItemClientData( unsigned int n
,
532 wxClientDataType clientDataItemsType
)
534 // It should be sufficient to update this variable only here
535 m_clientDataItemsType
= clientDataItemsType
;
537 m_clientDatas
.SetCount(n
+1,NULL
);
538 m_clientDatas
[n
] = clientData
;
543 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n
) const
545 if ( m_clientDatas
.GetCount() > n
)
546 return m_clientDatas
[n
];
551 void wxVListBoxComboPopup::Delete( unsigned int item
)
553 // Remove client data, if set
554 if ( m_clientDatas
.GetCount() )
556 if ( m_clientDataItemsType
== wxClientData_Object
)
557 delete (wxClientData
*) m_clientDatas
[item
];
559 m_clientDatas
.RemoveAt(item
);
562 m_strings
.RemoveAt(item
);
563 m_widths
.RemoveAt(item
);
565 if ( (int)item
== m_widestItem
)
568 int sel
= GetSelection();
571 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
574 if ( (int)item
< sel
)
576 else if ( (int)item
== sel
)
577 SetSelection(wxNOT_FOUND
);
580 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
582 return m_strings
.Index(s
, bCase
);
585 unsigned int wxVListBoxComboPopup::GetCount() const
587 return m_strings
.GetCount();
590 wxString
wxVListBoxComboPopup::GetString( int item
) const
592 return m_strings
[item
];
595 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
597 m_strings
[item
] = str
;
598 ItemWidthChanged(item
);
601 wxString
wxVListBoxComboPopup::GetStringValue() const
604 return m_strings
[m_value
];
605 return wxEmptyString
;
608 void wxVListBoxComboPopup::SetSelection( int item
)
610 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
611 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
616 wxVListBox::SetSelection(item
);
619 int wxVListBoxComboPopup::GetSelection() const
624 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
626 int index
= m_strings
.Index(value
);
630 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
631 wxVListBox::SetSelection(index
);
634 void wxVListBoxComboPopup::CalcWidths()
636 bool doFindWidest
= m_findWidest
;
638 // Measure items with dirty width.
642 unsigned int n
= m_widths
.GetCount();
643 int dirtyHandled
= 0;
644 wxArrayInt
& widths
= m_widths
;
646 // I think using wxDC::GetTextExtent is faster than
647 // wxWindow::GetTextExtent (assuming same dc is used
648 // for all calls, as we do here).
649 wxClientDC
dc(m_combo
);
650 dc
.SetFont(m_useFont
);
652 for ( i
=0; i
<n
; i
++ )
656 wxCoord x
= OnMeasureItemWidth(i
);
660 const wxString
& text
= m_strings
[i
];
662 // To make sure performance won't suck in extreme scenarios,
663 // we'll estimate length after some arbitrary number of items
664 // have been checked precily.
665 if ( dirtyHandled
< 1024 )
668 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
673 x
= text
.length() * (dc
.GetCharWidth()+1);
679 if ( x
>= m_widestWidth
)
682 m_widestItem
= (int)i
;
684 else if ( (int)i
== m_widestItem
)
686 // Width of previously widest item has been decreased, so
687 // we'll have to check all to find current widest item.
695 m_widthsDirty
= false;
701 unsigned int n
= m_widths
.GetCount();
706 for ( i
=0; i
<n
; i
++ )
716 m_widestWidth
= bestWidth
;
717 m_widestItem
= bestIndex
;
719 m_findWidest
= false;
723 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
727 if ( m_strings
.GetCount() )
729 if ( prefHeight
> 0 )
732 if ( height
> maxHeight
)
735 int totalHeight
= GetTotalHeight(); // + 3;
736 if ( height
>= totalHeight
)
738 height
= totalHeight
;
742 // Adjust height to a multiple of the height of the first item
743 // NB: Calculations that take variable height into account
745 int fih
= GetLineHeight(0);
746 int shown
= height
/fih
;
747 height
= shown
* fih
;
755 // Take scrollbar into account in width calculations
756 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
757 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
761 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
762 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
766 int n
= choices
.GetCount();
768 for ( i
=0; i
<n
; i
++ )
770 const wxString
& item
= choices
.Item(i
);
774 m_widths
.SetCount(n
,-1);
775 m_widthsDirty
= true;
778 wxVListBox::SetItemCount(n
);
780 // Sort the initial choices
781 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
784 // Find initial selection
785 wxString strValue
= m_combo
->GetValue();
786 if ( strValue
.length() )
787 m_value
= m_strings
.Index(strValue
);
790 // ----------------------------------------------------------------------------
791 // wxOwnerDrawnComboBox
792 // ----------------------------------------------------------------------------
795 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
799 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
801 void wxOwnerDrawnComboBox::Init()
805 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
807 const wxString
& value
,
811 const wxValidator
& validator
,
812 const wxString
& name
)
814 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
817 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
819 const wxString
& value
,
822 const wxArrayString
& choices
,
824 const wxValidator
& validator
,
825 const wxString
& name
)
830 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
833 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
835 const wxString
& value
,
838 const wxArrayString
& choices
,
840 const wxValidator
& validator
,
841 const wxString
& name
)
844 //wxCArrayString chs(choices);
846 //return Create(parent, id, value, pos, size, chs.GetCount(),
847 // chs.GetStrings(), style, validator, name);
848 return Create(parent
, id
, value
, pos
, size
, 0,
849 NULL
, style
, validator
, name
);
852 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
854 const wxString
& value
,
858 const wxString choices
[],
860 const wxValidator
& validator
,
861 const wxString
& name
)
864 if ( !Create(parent
, id
, value
, pos
, size
, style
,
871 for ( i
=0; i
<n
; i
++ )
872 m_initChs
.Add(choices
[i
]);
877 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
879 if ( m_popupInterface
)
880 GetVListBoxComboPopup()->ClearClientDatas();
883 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
887 popup
= new wxVListBoxComboPopup();
890 wxComboCtrl::DoSetPopupControl(popup
);
894 // Add initial choices to the wxVListBox
895 if ( !GetVListBoxComboPopup()->GetCount() )
897 GetVListBoxComboPopup()->Populate(m_initChs
);
902 // ----------------------------------------------------------------------------
903 // wxOwnerDrawnComboBox item manipulation methods
904 // ----------------------------------------------------------------------------
906 void wxOwnerDrawnComboBox::Clear()
908 EnsurePopupControl();
910 GetVListBoxComboPopup()->Clear();
912 SetValue(wxEmptyString
);
915 void wxOwnerDrawnComboBox::Delete(unsigned int n
)
917 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
919 if ( GetSelection() == (int) n
)
920 SetValue(wxEmptyString
);
922 GetVListBoxComboPopup()->Delete(n
);
925 unsigned int wxOwnerDrawnComboBox::GetCount() const
927 if ( !m_popupInterface
)
928 return m_initChs
.GetCount();
930 return GetVListBoxComboPopup()->GetCount();
933 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
935 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
937 if ( !m_popupInterface
)
938 return m_initChs
.Item(n
);
940 return GetVListBoxComboPopup()->GetString(n
);
943 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
945 EnsurePopupControl();
947 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
949 GetVListBoxComboPopup()->SetString(n
,s
);
952 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
954 if ( !m_popupInterface
)
955 return m_initChs
.Index(s
, bCase
);
957 return GetVListBoxComboPopup()->FindString(s
, bCase
);
960 void wxOwnerDrawnComboBox::Select(int n
)
962 EnsurePopupControl();
964 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
966 GetVListBoxComboPopup()->SetSelection(n
);
970 str
= GetVListBoxComboPopup()->GetString(n
);
972 // Refresh text portion in control
974 m_text
->SetValue( str
);
981 int wxOwnerDrawnComboBox::GetSelection() const
983 if ( !m_popupInterface
)
984 return m_initChs
.Index(m_valueString
);
986 return GetVListBoxComboPopup()->GetSelection();
989 int wxOwnerDrawnComboBox::DoAppend(const wxString
& item
)
991 EnsurePopupControl();
992 wxASSERT(m_popupInterface
);
994 return GetVListBoxComboPopup()->Append(item
);
997 int wxOwnerDrawnComboBox::DoInsert(const wxString
& item
, unsigned int pos
)
999 EnsurePopupControl();
1001 wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT
), -1, wxT("can't insert into sorted list"));
1002 wxCHECK_MSG(IsValidInsert(pos
), -1, wxT("invalid index"));
1004 GetVListBoxComboPopup()->Insert(item
,pos
);
1009 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
1011 EnsurePopupControl();
1013 GetVListBoxComboPopup()->SetItemClientData(n
,clientData
,m_clientDataItemsType
);
1016 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1018 if ( !m_popupInterface
)
1021 return GetVListBoxComboPopup()->GetItemClientData(n
);
1024 void wxOwnerDrawnComboBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
1026 DoSetItemClientData(n
, (void*) clientData
);
1029 wxClientData
* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n
) const
1031 return (wxClientData
*) DoGetItemClientData(n
);
1034 // ----------------------------------------------------------------------------
1035 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1036 // ----------------------------------------------------------------------------
1038 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1043 if ( flags
& wxODCB_PAINTING_CONTROL
)
1045 dc
.DrawText( GetValue(),
1046 rect
.x
+ GetTextIndent(),
1047 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1051 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1055 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1060 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1065 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
,
1070 // We need only to explicitly draw background for items
1071 // that should have selected background. Also, call PrepareBackground
1072 // always when painting the control so that clipping is done properly.
1074 if ( (flags
& wxODCB_PAINTING_SELECTED
) ||
1075 ((flags
& wxODCB_PAINTING_CONTROL
) && HasFlag(wxCB_READONLY
)) )
1077 int bgFlags
= wxCONTROL_SELECTED
;
1079 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
1080 bgFlags
|= wxCONTROL_ISSUBMENU
;
1082 PrepareBackground(dc
, rect
, bgFlags
);
1086 #endif // wxUSE_ODCOMBOBOX