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 OnDrawBg(dc
,rect
,m_value
,wxODCB_PAINTING_CONTROL
);
113 OnDrawItem(dc
,rect
,m_value
,wxODCB_PAINTING_CONTROL
);
118 wxComboPopup::PaintComboControl(dc
,rect
);
121 void wxVListBoxComboPopup::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
123 // TODO: Maybe this code could be moved to wxVListBox::OnPaint?
124 dc
.SetFont(m_useFont
);
126 // Set correct text colour for selected items
127 if ( wxVListBox::GetSelection() == (int) n
)
128 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
130 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
132 OnDrawItem(dc
,rect
,(int)n
,0);
135 wxCoord
wxVListBoxComboPopup::OnMeasureItem(size_t n
) const
137 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
139 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
140 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
142 wxCoord h
= combo
->OnMeasureItem(n
);
148 wxCoord
wxVListBoxComboPopup::OnMeasureItemWidth(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 return combo
->OnMeasureItemWidth(n
);
158 void wxVListBoxComboPopup::OnDrawBg( wxDC
& dc
,
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 combo
->OnDrawBackground(dc
,rect
,item
,flags
);
171 void wxVListBoxComboPopup::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
173 OnDrawBg(dc
,rect
,(int)n
,0);
176 // This is called from wxVListBoxComboPopup::OnDrawItem, with text colour and font prepared
177 void wxVListBoxComboPopup::OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
179 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
181 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
182 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
184 combo
->OnDrawItem(dc
,rect
,item
,flags
);
187 void wxVListBoxComboPopup::DismissWithEvent()
189 StopPartialCompletion();
191 int selection
= wxVListBox::GetSelection();
196 if ( selection
!= wxNOT_FOUND
)
197 valStr
= m_strings
[selection
];
199 valStr
= wxEmptyString
;
203 if ( valStr
!= m_combo
->GetValue() )
204 m_combo
->SetValue(valStr
);
206 SendComboBoxEvent(selection
);
209 void wxVListBoxComboPopup::SendComboBoxEvent( int selection
)
211 wxCommandEvent
evt(wxEVT_COMMAND_COMBOBOX_SELECTED
,m_combo
->GetId());
213 evt
.SetEventObject(m_combo
);
215 evt
.SetInt(selection
);
217 // Set client data, if any
218 if ( selection
>= 0 && (int)m_clientDatas
.GetCount() > selection
)
220 void* clientData
= m_clientDatas
[selection
];
221 if ( m_clientDataItemsType
== wxClientData_Object
)
222 evt
.SetClientObject((wxClientData
*)clientData
);
224 evt
.SetClientData(clientData
);
227 m_combo
->GetEventHandler()->AddPendingEvent(evt
);
230 // returns true if key was consumed
231 bool wxVListBoxComboPopup::HandleKey( int keycode
, bool saturate
, wxChar unicode
)
234 int itemCount
= GetCount();
235 int comboStyle
= m_combo
->GetWindowStyle();
237 // this is the character equivalent of the code
239 if ((keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
241 keychar
= (wxChar
)keycode
;
248 if ( keycode
== WXK_DOWN
|| keycode
== WXK_RIGHT
)
251 StopPartialCompletion();
253 else if ( keycode
== WXK_UP
|| keycode
== WXK_LEFT
)
256 StopPartialCompletion();
258 else if ( keycode
== WXK_PAGEDOWN
)
261 StopPartialCompletion();
263 else if ( keycode
== WXK_PAGEUP
)
266 StopPartialCompletion();
268 else if ( comboStyle
& wxCB_READONLY
)
270 // Try partial completion
272 // find the new partial completion string
274 if (m_partialCompletionTimer
.IsRunning())
275 m_partialCompletionString
+=wxString(keychar
);
277 #endif // wxUSE_TIMER
278 m_partialCompletionString
=wxString(keychar
);
280 // now search through the values to see if this is found
282 unsigned int length
=m_partialCompletionString
.length();
284 for (i
=0; i
<itemCount
; i
++)
286 wxString item
=GetString(i
);
287 if (( item
.length() >= length
) && (! m_partialCompletionString
.CmpNoCase(item
.Left(length
))))
296 StopPartialCompletion();
298 return true; // to stop the first value being set
304 m_partialCompletionTimer
.Start(wxODCB_PARTIAL_COMPLETION_TIME
, true);
305 #endif // wxUSE_TIMER
313 if ( value
>= itemCount
)
314 value
= itemCount
- 1;
315 else if ( value
< 0 )
320 if ( value
>= itemCount
)
322 else if ( value
< 0 )
326 if ( value
== m_value
)
327 // Even if value was same, don't skip the event
328 // (good for consistency)
334 m_combo
->SetValue(m_strings
[value
]);
336 SendComboBoxEvent(m_value
);
341 // stop partial completion
342 void wxVListBoxComboPopup::StopPartialCompletion()
344 m_partialCompletionString
= wxEmptyString
;
346 m_partialCompletionTimer
.Stop();
347 #endif // wxUSE_TIMER
350 void wxVListBoxComboPopup::OnComboDoubleClick()
352 // Cycle on dclick (disable saturation to allow true cycling).
353 if ( !::wxGetKeyState(WXK_SHIFT
) )
354 HandleKey(WXK_DOWN
,false);
356 HandleKey(WXK_UP
,false);
359 void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
361 // Saturated key movement on
362 if ( !HandleKey(event
.GetKeyCode(),true,
364 event
.GetUnicodeKey()
372 void wxVListBoxComboPopup::OnPopup()
374 // *must* set value after size is set (this is because of a vlbox bug)
375 wxVListBox::SetSelection(m_value
);
378 void wxVListBoxComboPopup::OnMouseMove(wxMouseEvent
& event
)
382 // Move selection to cursor if it is inside the popup
384 int y
= event
.GetPosition().y
;
385 int fromBottom
= GetClientSize().y
- y
;
387 // Since in any case we need to find out if the last item is only
388 // partially visible, we might just as well replicate the HitTest
390 const size_t lineMax
= GetVisibleEnd();
391 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
393 y
-= OnGetLineHeight(line
);
396 // Only change selection if item is fully visible
397 if ( (y
+ fromBottom
) >= 0 )
399 wxVListBox::SetSelection((int)line
);
406 void wxVListBoxComboPopup::OnLeftClick(wxMouseEvent
& WXUNUSED(event
))
411 void wxVListBoxComboPopup::OnKey(wxKeyEvent
& event
)
413 // Hide popup if certain key or key combination was pressed
414 if ( m_combo
->IsKeyPopupToggle(event
) )
416 StopPartialCompletion();
419 else if ( event
.AltDown() )
421 // On both wxGTK and wxMSW, pressing Alt down seems to
422 // completely freeze things in popup (ie. arrow keys and
423 // enter won't work).
426 // Select item if ENTER is pressed
427 else if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
433 int comboStyle
= m_combo
->GetWindowStyle();
434 int keycode
= event
.GetKeyCode();
435 // Process partial completion key codes here, but not the arrow keys as the base class will do that for us
436 if ((comboStyle
& wxCB_READONLY
) &&
437 (keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
439 OnComboKeyEvent(event
);
440 SetSelection(m_value
); // ensure the highlight bar moves
447 void wxVListBoxComboPopup::Insert( const wxString
& item
, int pos
)
449 // Need to change selection?
451 if ( !(m_combo
->GetWindowStyle() & wxCB_READONLY
) &&
452 m_combo
->GetValue() == item
)
457 m_strings
.Insert(item
,pos
);
458 m_widths
.Insert(-1,pos
);
459 m_widthsDirty
= true;
462 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
465 int wxVListBoxComboPopup::Append(const wxString
& item
)
467 int pos
= (int)m_strings
.GetCount();
469 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
472 // TODO: Could be optimized with binary search
473 wxArrayString strings
= m_strings
;
476 for ( i
=0; i
<strings
.GetCount(); i
++ )
478 if ( item
.Cmp(strings
.Item(i
)) < 0 )
491 void wxVListBoxComboPopup::Clear()
503 m_value
= wxNOT_FOUND
;
506 wxVListBox::SetItemCount(0);
509 void wxVListBoxComboPopup::ClearClientDatas()
511 if ( m_clientDataItemsType
== wxClientData_Object
)
514 for ( i
=0; i
<m_clientDatas
.GetCount(); i
++ )
515 delete (wxClientData
*) m_clientDatas
[i
];
518 m_clientDatas
.Empty();
521 void wxVListBoxComboPopup::SetItemClientData( unsigned int n
,
523 wxClientDataType clientDataItemsType
)
525 // It should be sufficient to update this variable only here
526 m_clientDataItemsType
= clientDataItemsType
;
528 m_clientDatas
.SetCount(n
+1,NULL
);
529 m_clientDatas
[n
] = clientData
;
534 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n
) const
536 if ( m_clientDatas
.GetCount() > n
)
537 return m_clientDatas
[n
];
542 void wxVListBoxComboPopup::Delete( unsigned int item
)
544 // Remove client data, if set
545 if ( m_clientDatas
.GetCount() )
547 if ( m_clientDataItemsType
== wxClientData_Object
)
548 delete (wxClientData
*) m_clientDatas
[item
];
550 m_clientDatas
.RemoveAt(item
);
553 m_strings
.RemoveAt(item
);
554 m_widths
.RemoveAt(item
);
556 if ( (int)item
== m_widestItem
)
560 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
563 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
565 return m_strings
.Index(s
, bCase
);
568 unsigned int wxVListBoxComboPopup::GetCount() const
570 return m_strings
.GetCount();
573 wxString
wxVListBoxComboPopup::GetString( int item
) const
575 return m_strings
[item
];
578 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
580 m_strings
[item
] = str
;
581 ItemWidthChanged(item
);
584 wxString
wxVListBoxComboPopup::GetStringValue() const
587 return m_strings
[m_value
];
588 return wxEmptyString
;
591 void wxVListBoxComboPopup::SetSelection( int item
)
593 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
594 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
599 wxVListBox::SetSelection(item
);
602 int wxVListBoxComboPopup::GetSelection() const
607 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
609 int index
= m_strings
.Index(value
);
613 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
614 wxVListBox::SetSelection(index
);
617 void wxVListBoxComboPopup::CalcWidths()
619 bool doFindWidest
= m_findWidest
;
621 // Measure items with dirty width.
625 unsigned int n
= m_widths
.GetCount();
626 int dirtyHandled
= 0;
627 wxArrayInt
& widths
= m_widths
;
629 // I think using wxDC::GetTextExtent is faster than
630 // wxWindow::GetTextExtent (assuming same dc is used
631 // for all calls, as we do here).
632 wxClientDC
dc(m_combo
);
633 dc
.SetFont(m_useFont
);
635 for ( i
=0; i
<n
; i
++ )
639 wxCoord x
= OnMeasureItemWidth(i
);
643 const wxString
& text
= m_strings
[i
];
645 // To make sure performance won't suck in extreme scenarios,
646 // we'll estimate length after some arbitrary number of items
647 // have been checked precily.
648 if ( dirtyHandled
< 1024 )
651 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
656 x
= text
.length() * (dc
.GetCharWidth()+1);
662 if ( x
>= m_widestWidth
)
665 m_widestItem
= (int)i
;
667 else if ( (int)i
== m_widestItem
)
669 // Width of previously widest item has been decreased, so
670 // we'll have to check all to find current widest item.
678 m_widthsDirty
= false;
684 unsigned int n
= m_widths
.GetCount();
689 for ( i
=0; i
<n
; i
++ )
699 m_widestWidth
= bestWidth
;
700 m_widestItem
= bestIndex
;
702 m_findWidest
= false;
706 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
710 if ( m_strings
.GetCount() )
712 if ( prefHeight
> 0 )
715 if ( height
> maxHeight
)
718 int totalHeight
= GetTotalHeight(); // + 3;
719 if ( height
>= totalHeight
)
721 height
= totalHeight
;
725 // Adjust height to a multiple of the height of the first item
726 // NB: Calculations that take variable height into account
728 int fih
= GetLineHeight(0);
729 int shown
= height
/fih
;
730 height
= shown
* fih
;
738 // Take scrollbar into account in width calculations
739 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
740 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
744 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
745 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
749 int n
= choices
.GetCount();
751 for ( i
=0; i
<n
; i
++ )
753 const wxString
& item
= choices
.Item(i
);
757 m_widths
.SetCount(n
,-1);
758 m_widthsDirty
= true;
761 wxVListBox::SetItemCount(n
);
763 // Sort the initial choices
764 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
767 // Find initial selection
768 wxString strValue
= m_combo
->GetValue();
769 if ( strValue
.length() )
770 m_value
= m_strings
.Index(strValue
);
773 // ----------------------------------------------------------------------------
774 // wxOwnerDrawnComboBox
775 // ----------------------------------------------------------------------------
778 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
782 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
784 void wxOwnerDrawnComboBox::Init()
788 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
790 const wxString
& value
,
794 const wxValidator
& validator
,
795 const wxString
& name
)
797 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
800 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
802 const wxString
& value
,
805 const wxArrayString
& choices
,
807 const wxValidator
& validator
,
808 const wxString
& name
)
813 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
816 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
818 const wxString
& value
,
821 const wxArrayString
& choices
,
823 const wxValidator
& validator
,
824 const wxString
& name
)
827 //wxCArrayString chs(choices);
829 //return Create(parent, id, value, pos, size, chs.GetCount(),
830 // chs.GetStrings(), style, validator, name);
831 return Create(parent
, id
, value
, pos
, size
, 0,
832 NULL
, style
, validator
, name
);
835 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
837 const wxString
& value
,
841 const wxString choices
[],
843 const wxValidator
& validator
,
844 const wxString
& name
)
847 if ( !Create(parent
, id
, value
, pos
, size
, style
,
854 for ( i
=0; i
<n
; i
++ )
855 m_initChs
.Add(choices
[i
]);
860 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
862 if ( m_popupInterface
)
863 GetVListBoxComboPopup()->ClearClientDatas();
866 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
870 popup
= new wxVListBoxComboPopup();
873 wxComboCtrl::DoSetPopupControl(popup
);
877 // Add initial choices to the wxVListBox
878 if ( !GetVListBoxComboPopup()->GetCount() )
880 GetVListBoxComboPopup()->Populate(m_initChs
);
885 // ----------------------------------------------------------------------------
886 // wxOwnerDrawnComboBox item manipulation methods
887 // ----------------------------------------------------------------------------
889 void wxOwnerDrawnComboBox::Clear()
891 EnsurePopupControl();
893 GetVListBoxComboPopup()->Clear();
895 SetValue(wxEmptyString
);
898 void wxOwnerDrawnComboBox::Delete(unsigned int n
)
900 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
902 if ( GetSelection() == (int) n
)
903 SetValue(wxEmptyString
);
905 GetVListBoxComboPopup()->Delete(n
);
908 unsigned int wxOwnerDrawnComboBox::GetCount() const
910 if ( !m_popupInterface
)
911 return m_initChs
.GetCount();
913 return GetVListBoxComboPopup()->GetCount();
916 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
918 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
920 if ( !m_popupInterface
)
921 return m_initChs
.Item(n
);
923 return GetVListBoxComboPopup()->GetString(n
);
926 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
928 EnsurePopupControl();
930 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
932 GetVListBoxComboPopup()->SetString(n
,s
);
935 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
937 if ( !m_popupInterface
)
938 return m_initChs
.Index(s
, bCase
);
940 return GetVListBoxComboPopup()->FindString(s
, bCase
);
943 void wxOwnerDrawnComboBox::Select(int n
)
945 EnsurePopupControl();
947 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
949 GetVListBoxComboPopup()->SetSelection(n
);
953 str
= GetVListBoxComboPopup()->GetString(n
);
955 // Refresh text portion in control
957 m_text
->SetValue( str
);
964 int wxOwnerDrawnComboBox::GetSelection() const
966 if ( !m_popupInterface
)
967 return m_initChs
.Index(m_valueString
);
969 return GetVListBoxComboPopup()->GetSelection();
972 int wxOwnerDrawnComboBox::DoAppend(const wxString
& item
)
974 EnsurePopupControl();
975 wxASSERT(m_popupInterface
);
977 return GetVListBoxComboPopup()->Append(item
);
980 int wxOwnerDrawnComboBox::DoInsert(const wxString
& item
, unsigned int pos
)
982 EnsurePopupControl();
984 wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT
), -1, wxT("can't insert into sorted list"));
985 wxCHECK_MSG(IsValidInsert(pos
), -1, wxT("invalid index"));
987 GetVListBoxComboPopup()->Insert(item
,pos
);
992 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
994 EnsurePopupControl();
996 GetVListBoxComboPopup()->SetItemClientData(n
,clientData
,m_clientDataItemsType
);
999 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1001 if ( !m_popupInterface
)
1004 return GetVListBoxComboPopup()->GetItemClientData(n
);
1007 void wxOwnerDrawnComboBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
1009 DoSetItemClientData(n
, (void*) clientData
);
1012 wxClientData
* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n
) const
1014 return (wxClientData
*) DoGetItemClientData(n
);
1017 // ----------------------------------------------------------------------------
1018 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1019 // ----------------------------------------------------------------------------
1021 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1026 if ( flags
& wxODCB_PAINTING_CONTROL
)
1028 dc
.DrawText( GetValue(),
1029 rect
.x
+ GetTextIndent(),
1030 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1034 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1038 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1043 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1048 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
1050 // we need to render selected and current items differently
1051 if ( GetVListBoxComboPopup()->IsCurrent((size_t)item
) ||
1052 (flags
& wxODCB_PAINTING_CONTROL
) )
1054 int focusFlag
= wxCONTROL_SELECTED
;
1056 if ( (flags
& wxODCB_PAINTING_CONTROL
) != wxODCB_PAINTING_CONTROL
)
1057 focusFlag
|= wxCONTROL_ISSUBMENU
;
1059 DrawFocusBackground(dc
, rect
, focusFlag
);
1061 //else: do nothing for the normal items
1064 #endif // wxUSE_ODCOMBOBOX