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
)
559 int sel
= GetSelection();
562 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
565 if ( (int)item
< sel
)
567 else if ( (int)item
== sel
)
568 SetSelection(wxNOT_FOUND
);
571 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
573 return m_strings
.Index(s
, bCase
);
576 unsigned int wxVListBoxComboPopup::GetCount() const
578 return m_strings
.GetCount();
581 wxString
wxVListBoxComboPopup::GetString( int item
) const
583 return m_strings
[item
];
586 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
588 m_strings
[item
] = str
;
589 ItemWidthChanged(item
);
592 wxString
wxVListBoxComboPopup::GetStringValue() const
595 return m_strings
[m_value
];
596 return wxEmptyString
;
599 void wxVListBoxComboPopup::SetSelection( int item
)
601 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
602 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
607 wxVListBox::SetSelection(item
);
610 int wxVListBoxComboPopup::GetSelection() const
615 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
617 int index
= m_strings
.Index(value
);
621 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
622 wxVListBox::SetSelection(index
);
625 void wxVListBoxComboPopup::CalcWidths()
627 bool doFindWidest
= m_findWidest
;
629 // Measure items with dirty width.
633 unsigned int n
= m_widths
.GetCount();
634 int dirtyHandled
= 0;
635 wxArrayInt
& widths
= m_widths
;
637 // I think using wxDC::GetTextExtent is faster than
638 // wxWindow::GetTextExtent (assuming same dc is used
639 // for all calls, as we do here).
640 wxClientDC
dc(m_combo
);
641 dc
.SetFont(m_useFont
);
643 for ( i
=0; i
<n
; i
++ )
647 wxCoord x
= OnMeasureItemWidth(i
);
651 const wxString
& text
= m_strings
[i
];
653 // To make sure performance won't suck in extreme scenarios,
654 // we'll estimate length after some arbitrary number of items
655 // have been checked precily.
656 if ( dirtyHandled
< 1024 )
659 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
664 x
= text
.length() * (dc
.GetCharWidth()+1);
670 if ( x
>= m_widestWidth
)
673 m_widestItem
= (int)i
;
675 else if ( (int)i
== m_widestItem
)
677 // Width of previously widest item has been decreased, so
678 // we'll have to check all to find current widest item.
686 m_widthsDirty
= false;
692 unsigned int n
= m_widths
.GetCount();
697 for ( i
=0; i
<n
; i
++ )
707 m_widestWidth
= bestWidth
;
708 m_widestItem
= bestIndex
;
710 m_findWidest
= false;
714 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
718 if ( m_strings
.GetCount() )
720 if ( prefHeight
> 0 )
723 if ( height
> maxHeight
)
726 int totalHeight
= GetTotalHeight(); // + 3;
727 if ( height
>= totalHeight
)
729 height
= totalHeight
;
733 // Adjust height to a multiple of the height of the first item
734 // NB: Calculations that take variable height into account
736 int fih
= GetLineHeight(0);
737 int shown
= height
/fih
;
738 height
= shown
* fih
;
746 // Take scrollbar into account in width calculations
747 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
748 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
752 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
753 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
757 int n
= choices
.GetCount();
759 for ( i
=0; i
<n
; i
++ )
761 const wxString
& item
= choices
.Item(i
);
765 m_widths
.SetCount(n
,-1);
766 m_widthsDirty
= true;
769 wxVListBox::SetItemCount(n
);
771 // Sort the initial choices
772 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
775 // Find initial selection
776 wxString strValue
= m_combo
->GetValue();
777 if ( strValue
.length() )
778 m_value
= m_strings
.Index(strValue
);
781 // ----------------------------------------------------------------------------
782 // wxOwnerDrawnComboBox
783 // ----------------------------------------------------------------------------
786 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
790 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
792 void wxOwnerDrawnComboBox::Init()
796 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
798 const wxString
& value
,
802 const wxValidator
& validator
,
803 const wxString
& name
)
805 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
808 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
810 const wxString
& value
,
813 const wxArrayString
& choices
,
815 const wxValidator
& validator
,
816 const wxString
& name
)
821 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
824 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
826 const wxString
& value
,
829 const wxArrayString
& choices
,
831 const wxValidator
& validator
,
832 const wxString
& name
)
835 //wxCArrayString chs(choices);
837 //return Create(parent, id, value, pos, size, chs.GetCount(),
838 // chs.GetStrings(), style, validator, name);
839 return Create(parent
, id
, value
, pos
, size
, 0,
840 NULL
, style
, validator
, name
);
843 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
845 const wxString
& value
,
849 const wxString choices
[],
851 const wxValidator
& validator
,
852 const wxString
& name
)
855 if ( !Create(parent
, id
, value
, pos
, size
, style
,
862 for ( i
=0; i
<n
; i
++ )
863 m_initChs
.Add(choices
[i
]);
868 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
870 if ( m_popupInterface
)
871 GetVListBoxComboPopup()->ClearClientDatas();
874 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
878 popup
= new wxVListBoxComboPopup();
881 wxComboCtrl::DoSetPopupControl(popup
);
885 // Add initial choices to the wxVListBox
886 if ( !GetVListBoxComboPopup()->GetCount() )
888 GetVListBoxComboPopup()->Populate(m_initChs
);
893 // ----------------------------------------------------------------------------
894 // wxOwnerDrawnComboBox item manipulation methods
895 // ----------------------------------------------------------------------------
897 void wxOwnerDrawnComboBox::Clear()
899 EnsurePopupControl();
901 GetVListBoxComboPopup()->Clear();
903 SetValue(wxEmptyString
);
906 void wxOwnerDrawnComboBox::Delete(unsigned int n
)
908 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
910 if ( GetSelection() == (int) n
)
911 SetValue(wxEmptyString
);
913 GetVListBoxComboPopup()->Delete(n
);
916 unsigned int wxOwnerDrawnComboBox::GetCount() const
918 if ( !m_popupInterface
)
919 return m_initChs
.GetCount();
921 return GetVListBoxComboPopup()->GetCount();
924 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
926 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
928 if ( !m_popupInterface
)
929 return m_initChs
.Item(n
);
931 return GetVListBoxComboPopup()->GetString(n
);
934 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
936 EnsurePopupControl();
938 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
940 GetVListBoxComboPopup()->SetString(n
,s
);
943 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
945 if ( !m_popupInterface
)
946 return m_initChs
.Index(s
, bCase
);
948 return GetVListBoxComboPopup()->FindString(s
, bCase
);
951 void wxOwnerDrawnComboBox::Select(int n
)
953 EnsurePopupControl();
955 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
957 GetVListBoxComboPopup()->SetSelection(n
);
961 str
= GetVListBoxComboPopup()->GetString(n
);
963 // Refresh text portion in control
965 m_text
->SetValue( str
);
972 int wxOwnerDrawnComboBox::GetSelection() const
974 if ( !m_popupInterface
)
975 return m_initChs
.Index(m_valueString
);
977 return GetVListBoxComboPopup()->GetSelection();
980 int wxOwnerDrawnComboBox::DoAppend(const wxString
& item
)
982 EnsurePopupControl();
983 wxASSERT(m_popupInterface
);
985 return GetVListBoxComboPopup()->Append(item
);
988 int wxOwnerDrawnComboBox::DoInsert(const wxString
& item
, unsigned int pos
)
990 EnsurePopupControl();
992 wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT
), -1, wxT("can't insert into sorted list"));
993 wxCHECK_MSG(IsValidInsert(pos
), -1, wxT("invalid index"));
995 GetVListBoxComboPopup()->Insert(item
,pos
);
1000 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
1002 EnsurePopupControl();
1004 GetVListBoxComboPopup()->SetItemClientData(n
,clientData
,m_clientDataItemsType
);
1007 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1009 if ( !m_popupInterface
)
1012 return GetVListBoxComboPopup()->GetItemClientData(n
);
1015 void wxOwnerDrawnComboBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
1017 DoSetItemClientData(n
, (void*) clientData
);
1020 wxClientData
* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n
) const
1022 return (wxClientData
*) DoGetItemClientData(n
);
1025 // ----------------------------------------------------------------------------
1026 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1027 // ----------------------------------------------------------------------------
1029 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1034 if ( flags
& wxODCB_PAINTING_CONTROL
)
1036 dc
.DrawText( GetValue(),
1037 rect
.x
+ GetTextIndent(),
1038 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1042 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1046 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1051 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1056 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
1058 // we need to render selected and current items differently
1059 if ( GetVListBoxComboPopup()->IsCurrent((size_t)item
) ||
1060 (flags
& wxODCB_PAINTING_CONTROL
) )
1062 int bgFlags
= wxCONTROL_SELECTED
;
1064 if ( (flags
& wxODCB_PAINTING_CONTROL
) != wxODCB_PAINTING_CONTROL
)
1066 bgFlags
|= wxCONTROL_ISSUBMENU
;
1067 PrepareBackground(dc
, rect
, bgFlags
);
1069 else if ( HasFlag(wxCB_READONLY
) )
1070 PrepareBackground(dc
, rect
, bgFlags
);
1072 //else: do nothing for the normal items
1075 #endif // wxUSE_ODCOMBOBOX