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"
36 #include "wx/textctrl.h"
41 // ============================================================================
43 // ============================================================================
45 // time in milliseconds before partial completion buffer drops
46 #define wxODCB_PARTIAL_COMPLETION_TIME 1000
48 // ----------------------------------------------------------------------------
49 // wxVListBoxComboPopup is a wxVListBox customized to act as a popup control
51 // ----------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(wxVListBoxComboPopup
, wxVListBox
)
55 EVT_MOTION(wxVListBoxComboPopup::OnMouseMove
)
56 EVT_KEY_DOWN(wxVListBoxComboPopup::OnKey
)
57 EVT_LEFT_UP(wxVListBoxComboPopup::OnLeftClick
)
61 void wxVListBoxComboPopup::Init()
65 m_widthsDirty
= false;
70 m_clientDataItemsType
= wxClientData_None
;
71 m_partialCompletionString
= wxEmptyString
;
74 bool wxVListBoxComboPopup::Create(wxWindow
* parent
)
76 if ( !wxVListBox::Create(parent
,
80 wxBORDER_SIMPLE
| wxLB_INT_HEIGHT
| wxWANTS_CHARS
) )
83 m_useFont
= m_combo
->GetFont();
85 wxVListBox::SetItemCount(m_strings
.GetCount());
87 // TODO: Move this to SetFont
88 m_itemHeight
= GetCharHeight() + 0;
93 wxVListBoxComboPopup::~wxVListBoxComboPopup()
98 bool wxVListBoxComboPopup::LazyCreate()
100 // NB: There is a bug with wxVListBox that can be avoided by creating
101 // it later (bug causes empty space to be shown if initial selection
102 // is at the end of a list longer than the control can show at once).
106 // paint the control itself
107 void wxVListBoxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
109 if ( !(m_combo
->GetWindowStyle() & wxODCB_STD_CONTROL_PAINT
) )
111 int flags
= wxODCB_PAINTING_CONTROL
;
113 if ( m_combo
->ShouldDrawFocus() )
114 flags
|= wxODCB_PAINTING_SELECTED
;
116 OnDrawBg(dc
, rect
, m_value
, flags
);
120 OnDrawItem(dc
,rect
,m_value
,flags
);
125 wxComboPopup::PaintComboControl(dc
,rect
);
128 void wxVListBoxComboPopup::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
130 // TODO: Maybe this code could be moved to wxVListBox::OnPaint?
131 dc
.SetFont(m_useFont
);
135 // Set correct text colour for selected items
136 if ( wxVListBox::GetSelection() == (int) n
)
138 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
139 flags
|= wxODCB_PAINTING_SELECTED
;
143 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
146 OnDrawItem(dc
,rect
,(int)n
,flags
);
149 wxCoord
wxVListBoxComboPopup::OnMeasureItem(size_t n
) const
151 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
153 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
154 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
156 wxCoord h
= combo
->OnMeasureItem(n
);
162 wxCoord
wxVListBoxComboPopup::OnMeasureItemWidth(size_t n
) const
164 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
166 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
167 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
169 return combo
->OnMeasureItemWidth(n
);
172 void wxVListBoxComboPopup::OnDrawBg( wxDC
& dc
,
177 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
179 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
180 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
182 if ( IsCurrent((size_t)item
) && !(flags
& wxODCB_PAINTING_CONTROL
) )
183 flags
|= wxODCB_PAINTING_SELECTED
;
185 combo
->OnDrawBackground(dc
,rect
,item
,flags
);
188 void wxVListBoxComboPopup::OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
190 OnDrawBg(dc
,rect
,(int)n
,0);
193 // This is called from wxVListBoxComboPopup::OnDrawItem, with text colour and font prepared
194 void wxVListBoxComboPopup::OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
196 wxOwnerDrawnComboBox
* combo
= (wxOwnerDrawnComboBox
*) m_combo
;
198 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)),
199 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
201 combo
->OnDrawItem(dc
,rect
,item
,flags
);
204 void wxVListBoxComboPopup::DismissWithEvent()
206 StopPartialCompletion();
208 int selection
= wxVListBox::GetSelection();
213 if ( selection
!= wxNOT_FOUND
)
214 valStr
= m_strings
[selection
];
216 valStr
= wxEmptyString
;
220 if ( valStr
!= m_combo
->GetValue() )
221 m_combo
->SetValueWithEvent(valStr
);
223 SendComboBoxEvent(selection
);
226 void wxVListBoxComboPopup::SendComboBoxEvent( int selection
)
228 wxCommandEvent
evt(wxEVT_COMMAND_COMBOBOX_SELECTED
,m_combo
->GetId());
230 evt
.SetEventObject(m_combo
);
232 evt
.SetInt(selection
);
234 // Set client data, if any
235 if ( selection
>= 0 && (int)m_clientDatas
.GetCount() > selection
)
237 void* clientData
= m_clientDatas
[selection
];
238 if ( m_clientDataItemsType
== wxClientData_Object
)
239 evt
.SetClientObject((wxClientData
*)clientData
);
241 evt
.SetClientData(clientData
);
244 m_combo
->GetEventHandler()->AddPendingEvent(evt
);
247 // returns true if key was consumed
248 bool wxVListBoxComboPopup::HandleKey( int keycode
, bool saturate
, wxChar unicode
)
251 int itemCount
= GetCount();
252 int comboStyle
= m_combo
->GetWindowStyle();
254 // this is the character equivalent of the code
256 if ((keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
258 keychar
= (wxChar
)keycode
;
265 if ( keycode
== WXK_DOWN
|| keycode
== WXK_RIGHT
)
268 StopPartialCompletion();
270 else if ( keycode
== WXK_UP
|| keycode
== WXK_LEFT
)
273 StopPartialCompletion();
275 else if ( keycode
== WXK_PAGEDOWN
)
278 StopPartialCompletion();
280 else if ( keycode
== WXK_PAGEUP
)
283 StopPartialCompletion();
285 else if ( comboStyle
& wxCB_READONLY
)
287 // Try partial completion
289 // find the new partial completion string
291 if (m_partialCompletionTimer
.IsRunning())
292 m_partialCompletionString
+=wxString(keychar
);
294 #endif // wxUSE_TIMER
295 m_partialCompletionString
=wxString(keychar
);
297 // now search through the values to see if this is found
299 unsigned int length
=m_partialCompletionString
.length();
301 for (i
=0; i
<itemCount
; i
++)
303 wxString item
=GetString(i
);
304 if (( item
.length() >= length
) && (! m_partialCompletionString
.CmpNoCase(item
.Left(length
))))
313 StopPartialCompletion();
315 return true; // to stop the first value being set
321 m_partialCompletionTimer
.Start(wxODCB_PARTIAL_COMPLETION_TIME
, true);
322 #endif // wxUSE_TIMER
330 if ( value
>= itemCount
)
331 value
= itemCount
- 1;
332 else if ( value
< 0 )
337 if ( value
>= itemCount
)
339 else if ( value
< 0 )
343 if ( value
== m_value
)
344 // Even if value was same, don't skip the event
345 // (good for consistency)
351 m_combo
->SetValue(m_strings
[value
]);
353 SendComboBoxEvent(m_value
);
358 // stop partial completion
359 void wxVListBoxComboPopup::StopPartialCompletion()
361 m_partialCompletionString
= wxEmptyString
;
363 m_partialCompletionTimer
.Stop();
364 #endif // wxUSE_TIMER
367 void wxVListBoxComboPopup::OnComboDoubleClick()
369 // Cycle on dclick (disable saturation to allow true cycling).
370 if ( !::wxGetKeyState(WXK_SHIFT
) )
371 HandleKey(WXK_DOWN
,false);
373 HandleKey(WXK_UP
,false);
376 void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
378 // Saturated key movement on
379 if ( !HandleKey(event
.GetKeyCode(),true,
381 event
.GetUnicodeKey()
389 void wxVListBoxComboPopup::OnPopup()
391 // *must* set value after size is set (this is because of a vlbox bug)
392 wxVListBox::SetSelection(m_value
);
395 void wxVListBoxComboPopup::OnMouseMove(wxMouseEvent
& event
)
399 // Move selection to cursor if it is inside the popup
401 int y
= event
.GetPosition().y
;
402 int fromBottom
= GetClientSize().y
- y
;
404 // Since in any case we need to find out if the last item is only
405 // partially visible, we might just as well replicate the HitTest
407 const size_t lineMax
= GetVisibleEnd();
408 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
410 y
-= OnGetRowHeight(line
);
413 // Only change selection if item is fully visible
414 if ( (y
+ fromBottom
) >= 0 )
416 wxVListBox::SetSelection((int)line
);
423 void wxVListBoxComboPopup::OnLeftClick(wxMouseEvent
& WXUNUSED(event
))
428 void wxVListBoxComboPopup::OnKey(wxKeyEvent
& event
)
430 // Hide popup if certain key or key combination was pressed
431 if ( m_combo
->IsKeyPopupToggle(event
) )
433 StopPartialCompletion();
436 else if ( event
.AltDown() )
438 // On both wxGTK and wxMSW, pressing Alt down seems to
439 // completely freeze things in popup (ie. arrow keys and
440 // enter won't work).
443 // Select item if ENTER is pressed
444 else if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
450 int comboStyle
= m_combo
->GetWindowStyle();
451 int keycode
= event
.GetKeyCode();
452 // Process partial completion key codes here, but not the arrow keys as the base class will do that for us
453 if ((comboStyle
& wxCB_READONLY
) &&
454 (keycode
>= WXK_SPACE
) && (keycode
<=255) && (keycode
!= WXK_DELETE
) && wxIsprint(keycode
))
456 OnComboKeyEvent(event
);
457 SetSelection(m_value
); // ensure the highlight bar moves
464 void wxVListBoxComboPopup::Insert( const wxString
& item
, int pos
)
466 // Need to change selection?
468 if ( !(m_combo
->GetWindowStyle() & wxCB_READONLY
) &&
469 m_combo
->GetValue() == item
)
474 m_strings
.Insert(item
,pos
);
475 m_clientDatas
.Insert(NULL
, pos
);
477 m_widths
.Insert(-1,pos
);
478 m_widthsDirty
= true;
481 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
484 int wxVListBoxComboPopup::Append(const wxString
& item
)
486 int pos
= (int)m_strings
.GetCount();
488 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
491 // TODO: Could be optimized with binary search
492 wxArrayString strings
= m_strings
;
495 for ( i
=0; i
<strings
.GetCount(); i
++ )
497 if ( item
.Cmp(strings
.Item(i
)) < 0 )
510 void wxVListBoxComboPopup::Clear()
522 m_value
= wxNOT_FOUND
;
525 wxVListBox::SetItemCount(0);
528 void wxVListBoxComboPopup::ClearClientDatas()
530 if ( m_clientDataItemsType
== wxClientData_Object
)
533 for ( i
=0; i
<m_clientDatas
.GetCount(); i
++ )
534 delete (wxClientData
*) m_clientDatas
[i
];
537 m_clientDatas
.Empty();
540 void wxVListBoxComboPopup::SetItemClientData( unsigned int n
,
542 wxClientDataType clientDataItemsType
)
544 // It should be sufficient to update this variable only here
545 m_clientDataItemsType
= clientDataItemsType
;
547 m_clientDatas
[n
] = clientData
;
552 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n
) const
554 if ( m_clientDatas
.GetCount() > n
)
555 return m_clientDatas
[n
];
560 void wxVListBoxComboPopup::Delete( unsigned int item
)
562 // Remove client data, if set
563 if ( m_clientDatas
.GetCount() )
565 if ( m_clientDataItemsType
== wxClientData_Object
)
566 delete (wxClientData
*) m_clientDatas
[item
];
568 m_clientDatas
.RemoveAt(item
);
571 m_strings
.RemoveAt(item
);
572 m_widths
.RemoveAt(item
);
574 if ( (int)item
== m_widestItem
)
577 int sel
= GetSelection();
580 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
583 if ( (int)item
< sel
)
585 else if ( (int)item
== sel
)
586 SetSelection(wxNOT_FOUND
);
589 int wxVListBoxComboPopup::FindString(const wxString
& s
, bool bCase
) const
591 return m_strings
.Index(s
, bCase
);
594 unsigned int wxVListBoxComboPopup::GetCount() const
596 return m_strings
.GetCount();
599 wxString
wxVListBoxComboPopup::GetString( int item
) const
601 return m_strings
[item
];
604 void wxVListBoxComboPopup::SetString( int item
, const wxString
& str
)
606 m_strings
[item
] = str
;
607 ItemWidthChanged(item
);
610 wxString
wxVListBoxComboPopup::GetStringValue() const
613 return m_strings
[m_value
];
614 return wxEmptyString
;
617 void wxVListBoxComboPopup::SetSelection( int item
)
619 wxCHECK_RET( item
== wxNOT_FOUND
|| ((unsigned int)item
< GetCount()),
620 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
625 wxVListBox::SetSelection(item
);
628 int wxVListBoxComboPopup::GetSelection() const
633 void wxVListBoxComboPopup::SetStringValue( const wxString
& value
)
635 int index
= m_strings
.Index(value
);
639 if ( index
>= -1 && index
< (int)wxVListBox::GetItemCount() )
640 wxVListBox::SetSelection(index
);
643 void wxVListBoxComboPopup::CalcWidths()
645 bool doFindWidest
= m_findWidest
;
647 // Measure items with dirty width.
651 unsigned int n
= m_widths
.GetCount();
652 int dirtyHandled
= 0;
653 wxArrayInt
& widths
= m_widths
;
655 // I think using wxDC::GetTextExtent is faster than
656 // wxWindow::GetTextExtent (assuming same dc is used
657 // for all calls, as we do here).
658 wxClientDC
dc(m_combo
);
659 dc
.SetFont(m_useFont
);
661 for ( i
=0; i
<n
; i
++ )
665 wxCoord x
= OnMeasureItemWidth(i
);
669 const wxString
& text
= m_strings
[i
];
671 // To make sure performance won't suck in extreme scenarios,
672 // we'll estimate length after some arbitrary number of items
673 // have been checked precily.
674 if ( dirtyHandled
< 1024 )
677 dc
.GetTextExtent(text
, &x
, &y
, 0, 0);
682 x
= text
.length() * (dc
.GetCharWidth()+1);
688 if ( x
>= m_widestWidth
)
691 m_widestItem
= (int)i
;
693 else if ( (int)i
== m_widestItem
)
695 // Width of previously widest item has been decreased, so
696 // we'll have to check all to find current widest item.
704 m_widthsDirty
= false;
710 unsigned int n
= m_widths
.GetCount();
715 for ( i
=0; i
<n
; i
++ )
725 m_widestWidth
= bestWidth
;
726 m_widestItem
= bestIndex
;
728 m_findWidest
= false;
732 wxSize
wxVListBoxComboPopup::GetAdjustedSize( int minWidth
, int prefHeight
, int maxHeight
)
736 maxHeight
-= 2; // Must take borders into account
738 if ( m_strings
.GetCount() )
740 if ( prefHeight
> 0 )
743 if ( height
> maxHeight
)
746 int totalHeight
= GetTotalHeight(); // + 3;
747 if ( height
>= totalHeight
)
749 height
= totalHeight
;
753 // Adjust height to a multiple of the height of the first item
754 // NB: Calculations that take variable height into account
756 int fih
= GetLineHeight(0);
757 height
-= height
% fih
;
765 // Take scrollbar into account in width calculations
766 int widestWidth
= m_widestWidth
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
767 return wxSize(minWidth
> widestWidth
? minWidth
: widestWidth
,
771 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
772 void wxVListBoxComboPopup::Populate( const wxArrayString
& choices
)
776 int n
= choices
.GetCount();
778 for ( i
=0; i
<n
; i
++ )
780 const wxString
& item
= choices
.Item(i
);
784 m_widths
.SetCount(n
,-1);
785 m_widthsDirty
= true;
788 wxVListBox::SetItemCount(n
);
790 // Sort the initial choices
791 if ( m_combo
->GetWindowStyle() & wxCB_SORT
)
794 // Find initial selection
795 wxString strValue
= m_combo
->GetValue();
796 if ( strValue
.length() )
797 m_value
= m_strings
.Index(strValue
);
800 // ----------------------------------------------------------------------------
801 // wxOwnerDrawnComboBox
802 // ----------------------------------------------------------------------------
805 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox
, wxComboCtrl
)
809 #if wxUSE_EXTENDED_RTTI
810 IMPLEMENT_DYNAMIC_CLASS2_XTI(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
, "wx/odcombo.h")
812 wxBEGIN_PROPERTIES_TABLE(wxOwnerDrawnComboBox
)
813 wxEND_PROPERTIES_TABLE()
815 wxBEGIN_HANDLERS_TABLE(wxOwnerDrawnComboBox
)
816 wxEND_HANDLERS_TABLE()
818 wxCONSTRUCTOR_5( wxOwnerDrawnComboBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
820 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox
, wxComboCtrl
, wxControlWithItems
)
823 void wxOwnerDrawnComboBox::Init()
827 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
829 const wxString
& value
,
833 const wxValidator
& validator
,
834 const wxString
& name
)
836 return wxComboCtrl::Create(parent
,id
,value
,pos
,size
,style
,validator
,name
);
839 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow
*parent
,
841 const wxString
& value
,
844 const wxArrayString
& choices
,
846 const wxValidator
& validator
,
847 const wxString
& name
)
852 Create(parent
,id
,value
,pos
,size
,choices
,style
, validator
, name
);
855 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
857 const wxString
& value
,
860 const wxArrayString
& choices
,
862 const wxValidator
& validator
,
863 const wxString
& name
)
866 //wxCArrayString chs(choices);
868 //return Create(parent, id, value, pos, size, chs.GetCount(),
869 // chs.GetStrings(), style, validator, name);
870 return Create(parent
, id
, value
, pos
, size
, 0,
871 NULL
, style
, validator
, name
);
874 bool wxOwnerDrawnComboBox::Create(wxWindow
*parent
,
876 const wxString
& value
,
880 const wxString choices
[],
882 const wxValidator
& validator
,
883 const wxString
& name
)
886 if ( !Create(parent
, id
, value
, pos
, size
, style
,
893 for ( i
=0; i
<n
; i
++ )
894 m_initChs
.Add(choices
[i
]);
899 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
901 if ( m_popupInterface
)
902 GetVListBoxComboPopup()->ClearClientDatas();
905 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup
* popup
)
909 popup
= new wxVListBoxComboPopup();
912 wxComboCtrl::DoSetPopupControl(popup
);
916 // Add initial choices to the wxVListBox
917 if ( !GetVListBoxComboPopup()->GetCount() )
919 GetVListBoxComboPopup()->Populate(m_initChs
);
924 // ----------------------------------------------------------------------------
925 // wxOwnerDrawnComboBox item manipulation methods
926 // ----------------------------------------------------------------------------
928 void wxOwnerDrawnComboBox::DoClear()
930 EnsurePopupControl();
932 GetVListBoxComboPopup()->Clear();
934 SetValue(wxEmptyString
);
937 void wxOwnerDrawnComboBox::DoDeleteOneItem(unsigned int n
)
939 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
941 if ( GetSelection() == (int) n
)
942 SetValue(wxEmptyString
);
944 GetVListBoxComboPopup()->Delete(n
);
947 unsigned int wxOwnerDrawnComboBox::GetCount() const
949 if ( !m_popupInterface
)
950 return m_initChs
.GetCount();
952 return GetVListBoxComboPopup()->GetCount();
955 wxString
wxOwnerDrawnComboBox::GetString(unsigned int n
) const
957 wxCHECK_MSG( IsValid(n
), wxEmptyString
, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
959 if ( !m_popupInterface
)
960 return m_initChs
.Item(n
);
962 return GetVListBoxComboPopup()->GetString(n
);
965 void wxOwnerDrawnComboBox::SetString(unsigned int n
, const wxString
& s
)
967 EnsurePopupControl();
969 wxCHECK_RET( IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
971 GetVListBoxComboPopup()->SetString(n
,s
);
974 int wxOwnerDrawnComboBox::FindString(const wxString
& s
, bool bCase
) const
976 if ( !m_popupInterface
)
977 return m_initChs
.Index(s
, bCase
);
979 return GetVListBoxComboPopup()->FindString(s
, bCase
);
982 void wxOwnerDrawnComboBox::Select(int n
)
984 EnsurePopupControl();
986 wxCHECK_RET( (n
== wxNOT_FOUND
) || IsValid(n
), _T("invalid index in wxOwnerDrawnComboBox::Select") );
988 GetVListBoxComboPopup()->SetSelection(n
);
992 str
= GetVListBoxComboPopup()->GetString(n
);
994 // Refresh text portion in control
996 m_text
->SetValue( str
);
1003 int wxOwnerDrawnComboBox::GetSelection() const
1005 if ( !m_popupInterface
)
1006 return m_initChs
.Index(m_valueString
);
1008 return GetVListBoxComboPopup()->GetSelection();
1011 int wxOwnerDrawnComboBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
1014 wxClientDataType type
)
1016 EnsurePopupControl();
1018 const unsigned int count
= items
.GetCount();
1019 for( unsigned int i
= 0; i
< count
; ++i
, ++pos
)
1021 GetVListBoxComboPopup()->Insert(items
[i
], pos
);
1022 AssignNewItemClientData(pos
, clientData
, i
, type
);
1028 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n
, void* clientData
)
1030 EnsurePopupControl();
1032 GetVListBoxComboPopup()->SetItemClientData(n
, clientData
,
1033 GetClientDataType());
1036 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n
) const
1038 if ( !m_popupInterface
)
1041 return GetVListBoxComboPopup()->GetItemClientData(n
);
1044 // ----------------------------------------------------------------------------
1045 // wxOwnerDrawnComboBox item drawing and measuring default implementations
1046 // ----------------------------------------------------------------------------
1048 void wxOwnerDrawnComboBox::OnDrawItem( wxDC
& dc
,
1053 if ( flags
& wxODCB_PAINTING_CONTROL
)
1055 dc
.DrawText( GetValue(),
1056 rect
.x
+ GetTextIndent(),
1057 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
1061 dc
.DrawText( GetVListBoxComboPopup()->GetString(item
), rect
.x
+ 2, rect
.y
);
1065 wxCoord
wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item
) ) const
1070 wxCoord
wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
1075 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC
& dc
,
1080 // We need only to explicitly draw background for items
1081 // that should have selected background. Also, call PrepareBackground
1082 // always when painting the control so that clipping is done properly.
1084 if ( (flags
& wxODCB_PAINTING_SELECTED
) ||
1085 ((flags
& wxODCB_PAINTING_CONTROL
) && HasFlag(wxCB_READONLY
)) )
1087 int bgFlags
= wxCONTROL_SELECTED
;
1089 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
1090 bgFlags
|= wxCONTROL_ISSUBMENU
;
1092 PrepareBackground(dc
, rect
, bgFlags
);
1096 #endif // wxUSE_ODCOMBOBOX