[ 1506733 ] wxOwnerDrawnComboBox::SetPopupControl argument type check.
[wxWidgets.git] / src / generic / odcombo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/odcombo.cpp
3 // Purpose: wxOwnerDrawnComboBox, wxVListBoxComboPopup
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: Apr-30-2006
7 // RCS-ID: $Id$
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_ODCOMBOBOX
27
28 #include "wx/odcombo.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/log.h"
32 #include "wx/combobox.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/dialog.h"
36 #endif
37
38 #include "wx/combo.h"
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44
45 // ----------------------------------------------------------------------------
46 // wxVListBoxComboPopup is a wxVListBox customized to act as a popup control
47 //
48 // ----------------------------------------------------------------------------
49
50
51 BEGIN_EVENT_TABLE(wxVListBoxComboPopup, wxVListBox)
52 EVT_MOTION(wxVListBoxComboPopup::OnMouseMove)
53 EVT_KEY_DOWN(wxVListBoxComboPopup::OnKey)
54 EVT_LEFT_UP(wxVListBoxComboPopup::OnLeftClick)
55 END_EVENT_TABLE()
56
57
58 void wxVListBoxComboPopup::Init()
59 {
60 m_widestWidth = 0;
61 m_avgCharWidth = 0;
62 m_baseImageWidth = 0;
63 m_itemHeight = 0;
64 m_value = -1;
65 m_itemHover = -1;
66 m_clientDataItemsType = wxClientData_None;
67 }
68
69 bool wxVListBoxComboPopup::Create(wxWindow* parent)
70 {
71 if ( !wxVListBox::Create(parent,
72 wxID_ANY,
73 wxDefaultPosition,
74 wxDefaultSize,
75 wxBORDER_SIMPLE | wxLB_INT_HEIGHT | wxWANTS_CHARS) )
76 return false;
77
78 m_useFont = m_combo->GetFont();
79
80 wxVListBox::SetItemCount(m_strings.GetCount());
81
82 // TODO: Move this to SetFont
83 m_itemHeight = GetCharHeight() + 0;
84
85 return true;
86 }
87
88 wxVListBoxComboPopup::~wxVListBoxComboPopup()
89 {
90 Clear();
91 }
92
93 bool wxVListBoxComboPopup::LazyCreate()
94 {
95 // NB: There is a bug with wxVListBox that can be avoided by creating
96 // it later (bug causes empty space to be shown if initial selection
97 // is at the end of a list longer than the control can show at once).
98 return true;
99 }
100
101 // paint the control itself
102 void wxVListBoxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect )
103 {
104 if ( !(m_combo->GetWindowStyle() & wxODCB_STD_CONTROL_PAINT) )
105 {
106 OnDrawBg(dc,rect,m_value,wxODCB_PAINTING_CONTROL);
107 if ( m_value >= 0 )
108 {
109 OnDrawItem(dc,rect,m_value,wxODCB_PAINTING_CONTROL);
110 return;
111 }
112 }
113
114 wxComboPopup::PaintComboControl(dc,rect);
115 }
116
117 void wxVListBoxComboPopup::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
118 {
119 // TODO: Maybe this code could be moved to wxVListBox::OnPaint?
120 dc.SetFont(m_useFont);
121
122 // Set correct text colour for selected items
123 if ( wxVListBox::GetSelection() == (int) n )
124 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) );
125 else
126 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
127
128 OnDrawItem(dc,rect,(int)n,0);
129 }
130
131 wxCoord wxVListBoxComboPopup::OnMeasureItem(size_t n) const
132 {
133 wxOwnerDrawnComboBox* combo = (wxOwnerDrawnComboBox*) m_combo;
134
135 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)),
136 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
137
138 wxCoord h = combo->OnMeasureItem(n);
139 if ( h < 0 )
140 h = m_itemHeight;
141 return h;
142 }
143
144 wxCoord wxVListBoxComboPopup::OnMeasureItemWidth(size_t n) const
145 {
146 wxOwnerDrawnComboBox* combo = (wxOwnerDrawnComboBox*) m_combo;
147
148 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)),
149 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
150
151 return combo->OnMeasureItemWidth(n);
152 }
153
154 void wxVListBoxComboPopup::OnDrawBg( wxDC& dc,
155 const wxRect& rect,
156 int item,
157 int flags ) const
158 {
159 wxOwnerDrawnComboBox* combo = (wxOwnerDrawnComboBox*) m_combo;
160
161 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)),
162 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
163
164 combo->OnDrawBackground(dc,rect,item,flags);
165 }
166
167 void wxVListBoxComboPopup::OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const
168 {
169 OnDrawBg(dc,rect,(int)n,0);
170 }
171
172 // This is called from wxVListBoxComboPopup::OnDrawItem, with text colour and font prepared
173 void wxVListBoxComboPopup::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const
174 {
175 wxOwnerDrawnComboBox* combo = (wxOwnerDrawnComboBox*) m_combo;
176
177 wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)),
178 wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") );
179
180 combo->OnDrawItem(dc,rect,item,flags);
181 }
182
183 void wxVListBoxComboPopup::DismissWithEvent()
184 {
185 int selection = wxVListBox::GetSelection();
186
187 Dismiss();
188
189 wxString valStr;
190 if ( selection != wxNOT_FOUND )
191 valStr = m_strings[selection];
192 else
193 valStr = wxEmptyString;
194
195 m_value = selection;
196
197 if ( valStr != m_combo->GetValue() )
198 m_combo->SetValue(valStr);
199
200 SendComboBoxEvent(selection);
201 }
202
203 void wxVListBoxComboPopup::SendComboBoxEvent( int selection )
204 {
205 wxCommandEvent evt(wxEVT_COMMAND_COMBOBOX_SELECTED,m_combo->GetId());
206
207 evt.SetEventObject(m_combo);
208
209 evt.SetInt(selection);
210
211 // Set client data, if any
212 if ( selection >= 0 && (int)m_clientDatas.GetCount() > selection )
213 {
214 void* clientData = m_clientDatas[selection];
215 if ( m_clientDataItemsType == wxClientData_Object )
216 evt.SetClientObject((wxClientData*)clientData);
217 else
218 evt.SetClientData(clientData);
219 }
220
221 m_combo->GetEventHandler()->AddPendingEvent(evt);
222 }
223
224 // returns true if key was consumed
225 bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate )
226 {
227 int value = m_value;
228 int itemCount = GetCount();
229
230 if ( keycode == WXK_DOWN || keycode == WXK_RIGHT )
231 {
232 value++;
233 }
234 else if ( keycode == WXK_UP || keycode == WXK_LEFT )
235 {
236 value--;
237 }
238 else if ( keycode == WXK_PAGEDOWN )
239 {
240 value+=10;
241 }
242 else if ( keycode == WXK_PAGEUP )
243 {
244 value-=10;
245 }
246 else
247 return false;
248
249 if ( saturate )
250 {
251 if ( value >= itemCount )
252 value = itemCount - 1;
253 else if ( value < 0 )
254 value = 0;
255 }
256 else
257 {
258 if ( value >= itemCount )
259 value -= itemCount;
260 else if ( value < 0 )
261 value += itemCount;
262 }
263
264 if ( value == m_value )
265 // Even if value was same, don't skip the event
266 // (good for consistency)
267 return true;
268
269 m_value = value;
270
271 if ( value >= 0 )
272 m_combo->SetValue(m_strings[value]);
273
274 SendComboBoxEvent(m_value);
275
276 return true;
277 }
278
279 void wxVListBoxComboPopup::OnComboDoubleClick()
280 {
281 // Cycle on dclick (disable saturation to allow true cycling).
282 if ( !::wxGetKeyState(WXK_SHIFT) )
283 HandleKey(WXK_DOWN,false);
284 else
285 HandleKey(WXK_UP,false);
286 }
287
288 void wxVListBoxComboPopup::OnComboKeyEvent( wxKeyEvent& event )
289 {
290 // Saturated key movement on
291 if ( !HandleKey(event.GetKeyCode(),true) )
292 event.Skip();
293 }
294
295 void wxVListBoxComboPopup::OnPopup()
296 {
297 // *must* set value after size is set (this is because of a vlbox bug)
298 wxVListBox::SetSelection(m_value);
299 }
300
301 void wxVListBoxComboPopup::OnMouseMove(wxMouseEvent& event)
302 {
303 // Move selection to cursor if it is inside the popup
304 int itemHere = GetItemAtPosition(event.GetPosition());
305 if ( itemHere >= 0 )
306 wxVListBox::SetSelection(itemHere);
307
308 event.Skip();
309 }
310
311 void wxVListBoxComboPopup::OnLeftClick(wxMouseEvent& WXUNUSED(event))
312 {
313 DismissWithEvent();
314 }
315
316 void wxVListBoxComboPopup::OnKey(wxKeyEvent& event)
317 {
318 // Select item if ENTER is pressed
319 if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER )
320 {
321 DismissWithEvent();
322 }
323 // Hide popup if ESC is pressed
324 else if ( event.GetKeyCode() == WXK_ESCAPE )
325 Dismiss();
326 else
327 event.Skip();
328 }
329
330 void wxVListBoxComboPopup::CheckWidth( int pos )
331 {
332 wxCoord x = OnMeasureItemWidth(pos);
333
334 if ( x < 0 )
335 {
336 if ( !m_useFont.Ok() )
337 m_useFont = m_combo->GetFont();
338
339 wxCoord y;
340 m_combo->GetTextExtent(m_strings[pos], &x, &y, 0, 0, &m_useFont);
341 x += 4;
342 }
343
344 if ( m_widestWidth < x )
345 {
346 m_widestWidth = x;
347 }
348 }
349
350 void wxVListBoxComboPopup::Insert( const wxString& item, int pos )
351 {
352 // Need to change selection?
353 wxString strValue;
354 if ( !(m_combo->GetWindowStyle() & wxCB_READONLY) &&
355 m_combo->GetValue() == item )
356 {
357 m_value = pos;
358 }
359
360 m_strings.Insert(item,pos);
361
362 if ( IsCreated() )
363 wxVListBox::SetItemCount( wxVListBox::GetItemCount()+1 );
364
365 // Calculate width
366 CheckWidth(pos);
367 }
368
369 int wxVListBoxComboPopup::Append(const wxString& item)
370 {
371 int pos = (int)m_strings.GetCount();
372
373 if ( m_combo->GetWindowStyle() & wxCB_SORT )
374 {
375 // Find position
376 // TODO: Could be optimized with binary search
377 wxArrayString strings = m_strings;
378 unsigned int i;
379
380 for ( i=0; i<strings.GetCount(); i++ )
381 {
382 if ( item.Cmp(strings.Item(i)) < 0 )
383 {
384 pos = (int)i;
385 break;
386 }
387 }
388 }
389
390 Insert(item,pos);
391
392 return pos;
393 }
394
395 void wxVListBoxComboPopup::Clear()
396 {
397 wxASSERT(m_combo);
398
399 m_strings.Empty();
400
401 ClearClientDatas();
402
403 m_value = wxNOT_FOUND;
404
405 if ( IsCreated() )
406 wxVListBox::SetItemCount(0);
407 }
408
409 void wxVListBoxComboPopup::ClearClientDatas()
410 {
411 if ( m_clientDataItemsType == wxClientData_Object )
412 {
413 size_t i;
414 for ( i=0; i<m_clientDatas.GetCount(); i++ )
415 delete (wxClientData*) m_clientDatas[i];
416 }
417
418 m_clientDatas.Empty();
419 }
420
421 void wxVListBoxComboPopup::SetItemClientData( unsigned int n,
422 void* clientData,
423 wxClientDataType clientDataItemsType )
424 {
425 // It should be sufficient to update this variable only here
426 m_clientDataItemsType = clientDataItemsType;
427
428 m_clientDatas.SetCount(n+1,NULL);
429 m_clientDatas[n] = clientData;
430 }
431
432 void* wxVListBoxComboPopup::GetItemClientData(unsigned int n) const
433 {
434 if ( m_clientDatas.GetCount() > n )
435 return m_clientDatas[n];
436
437 return NULL;
438 }
439
440 void wxVListBoxComboPopup::Delete( unsigned int item )
441 {
442 // Remove client data, if set
443 if ( m_clientDatas.GetCount() )
444 {
445 if ( m_clientDataItemsType == wxClientData_Object )
446 delete (wxClientData*) m_clientDatas[item];
447
448 m_clientDatas.RemoveAt(item);
449 }
450
451 m_strings.RemoveAt(item);
452
453 if ( IsCreated() )
454 wxVListBox::SetItemCount( wxVListBox::GetItemCount()-1 );
455 }
456
457 int wxVListBoxComboPopup::FindString(const wxString& s, bool bCase) const
458 {
459 return m_strings.Index(s, bCase);
460 }
461
462 unsigned int wxVListBoxComboPopup::GetCount() const
463 {
464 return m_strings.GetCount();
465 }
466
467 wxString wxVListBoxComboPopup::GetString( int item ) const
468 {
469 return m_strings[item];
470 }
471
472 void wxVListBoxComboPopup::SetString( int item, const wxString& str )
473 {
474 m_strings[item] = str;
475 }
476
477 wxString wxVListBoxComboPopup::GetStringValue() const
478 {
479 if ( m_value >= 0 )
480 return m_strings[m_value];
481 return wxEmptyString;
482 }
483
484 void wxVListBoxComboPopup::SetSelection( int item )
485 {
486 wxCHECK_RET( item == wxNOT_FOUND || ((unsigned int)item < GetCount()),
487 wxT("invalid index in wxVListBoxComboPopup::SetSelection") );
488
489 m_value = item;
490
491 if ( IsCreated() )
492 wxVListBox::SetSelection(item);
493 }
494
495 int wxVListBoxComboPopup::GetSelection() const
496 {
497 return m_value;
498 }
499
500 void wxVListBoxComboPopup::SetStringValue( const wxString& value )
501 {
502 int index = m_strings.Index(value);
503
504 m_value = index;
505
506 if ( index >= -1 && index < (int)wxVListBox::GetItemCount() )
507 wxVListBox::SetSelection(index);
508 }
509
510 wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
511 {
512 int height = 250;
513
514 if ( m_strings.GetCount() )
515 {
516 if ( prefHeight > 0 )
517 height = prefHeight;
518
519 if ( height > maxHeight )
520 height = maxHeight;
521
522 int totalHeight = GetTotalHeight(); // + 3;
523 if ( height >= totalHeight )
524 {
525 height = totalHeight;
526 }
527 else
528 {
529 // Adjust height to a multiple of the height of the first item
530 // NB: Calculations that take variable height into account
531 // are unnecessary.
532 int fih = GetLineHeight(0);
533 int shown = height/fih;
534 height = shown * fih;
535 }
536 }
537 else
538 height = 50;
539
540 // Take scrollbar into account in width calculations
541 int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
542 return wxSize(minWidth > widestWidth ? minWidth : widestWidth,
543 height+2);
544 }
545
546 //void wxVListBoxComboPopup::Populate( int n, const wxString choices[] )
547 void wxVListBoxComboPopup::Populate( const wxArrayString& choices )
548 {
549 int i;
550
551 int n = choices.GetCount();
552
553 for ( i=0; i<n; i++ )
554 {
555 const wxString& item = choices.Item(i);
556 m_strings.Add(item);
557 CheckWidth(i);
558 }
559
560 if ( IsCreated() )
561 wxVListBox::SetItemCount(n);
562
563 // Sort the initial choices
564 if ( m_combo->GetWindowStyle() & wxCB_SORT )
565 m_strings.Sort();
566
567 // Find initial selection
568 wxString strValue = m_combo->GetValue();
569 if ( strValue.length() )
570 m_value = m_strings.Index(strValue);
571 }
572
573 // ----------------------------------------------------------------------------
574 // wxOwnerDrawnComboBox
575 // ----------------------------------------------------------------------------
576
577
578 BEGIN_EVENT_TABLE(wxOwnerDrawnComboBox, wxComboCtrl)
579 END_EVENT_TABLE()
580
581
582 IMPLEMENT_DYNAMIC_CLASS2(wxOwnerDrawnComboBox, wxComboCtrl, wxControlWithItems)
583
584 void wxOwnerDrawnComboBox::Init()
585 {
586 m_popupInterface = NULL;
587 }
588
589 bool wxOwnerDrawnComboBox::Create(wxWindow *parent,
590 wxWindowID id,
591 const wxString& value,
592 const wxPoint& pos,
593 const wxSize& size,
594 long style,
595 const wxValidator& validator,
596 const wxString& name)
597 {
598 return wxComboCtrl::Create(parent,id,value,pos,size,style,validator,name);
599 }
600
601 wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent,
602 wxWindowID id,
603 const wxString& value,
604 const wxPoint& pos,
605 const wxSize& size,
606 const wxArrayString& choices,
607 long style,
608 const wxValidator& validator,
609 const wxString& name)
610 : wxComboCtrl()
611 {
612 Init();
613
614 Create(parent,id,value,pos,size,choices,style, validator, name);
615 }
616
617 bool wxOwnerDrawnComboBox::Create(wxWindow *parent,
618 wxWindowID id,
619 const wxString& value,
620 const wxPoint& pos,
621 const wxSize& size,
622 const wxArrayString& choices,
623 long style,
624 const wxValidator& validator,
625 const wxString& name)
626 {
627 m_initChs = choices;
628 //wxCArrayString chs(choices);
629
630 //return Create(parent, id, value, pos, size, chs.GetCount(),
631 // chs.GetStrings(), style, validator, name);
632 return Create(parent, id, value, pos, size, 0,
633 NULL, style, validator, name);
634 }
635
636 bool wxOwnerDrawnComboBox::Create(wxWindow *parent,
637 wxWindowID id,
638 const wxString& value,
639 const wxPoint& pos,
640 const wxSize& size,
641 int n,
642 const wxString choices[],
643 long style,
644 const wxValidator& validator,
645 const wxString& name)
646 {
647
648 if ( !Create(parent, id, value, pos, size, style,
649 validator, name) )
650 {
651 return false;
652 }
653
654 int i;
655 for ( i=0; i<n; i++ )
656 m_initChs.Add(choices[i]);
657
658 return true;
659 }
660
661 wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox()
662 {
663 if ( m_popupInterface )
664 m_popupInterface->ClearClientDatas();
665 }
666
667 void wxOwnerDrawnComboBox::DoSetPopupControl(wxComboPopup* popup)
668 {
669 if ( !popup )
670 {
671 popup = new wxVListBoxComboPopup();
672 }
673
674 wxComboCtrl::DoSetPopupControl(popup);
675
676 wxASSERT(popup);
677 m_popupInterface = (wxVListBoxComboPopup*) popup;
678
679 // Add initial choices to the wxVListBox
680 if ( !m_popupInterface->GetCount() )
681 {
682 //m_popupInterface->Populate(m_initChs.GetCount(),m_initChs.GetStrings());
683 m_popupInterface->Populate(m_initChs);
684 m_initChs.Clear();
685 }
686 }
687
688 // ----------------------------------------------------------------------------
689 // wxOwnerDrawnComboBox item manipulation methods
690 // ----------------------------------------------------------------------------
691
692 void wxOwnerDrawnComboBox::Clear()
693 {
694 EnsurePopupControl();
695
696 m_popupInterface->Clear();
697
698 SetValue(wxEmptyString);
699 }
700
701 void wxOwnerDrawnComboBox::Delete(unsigned int n)
702 {
703 wxCHECK_RET( IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::Delete") );
704
705 if ( GetSelection() == (int) n )
706 SetValue(wxEmptyString);
707
708 m_popupInterface->Delete(n);
709 }
710
711 unsigned int wxOwnerDrawnComboBox::GetCount() const
712 {
713 if ( !m_popupInterface )
714 return m_initChs.GetCount();
715
716 return m_popupInterface->GetCount();
717 }
718
719 wxString wxOwnerDrawnComboBox::GetString(unsigned int n) const
720 {
721 wxCHECK_MSG( IsValid(n), wxEmptyString, _T("invalid index in wxOwnerDrawnComboBox::GetString") );
722
723 if ( !m_popupInterface )
724 return m_initChs.Item(n);
725
726 return m_popupInterface->GetString(n);
727 }
728
729 void wxOwnerDrawnComboBox::SetString(unsigned int n, const wxString& s)
730 {
731 EnsurePopupControl();
732
733 wxCHECK_RET( IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::SetString") );
734
735 m_popupInterface->SetString(n,s);
736 }
737
738 int wxOwnerDrawnComboBox::FindString(const wxString& s, bool bCase) const
739 {
740 if ( !m_popupInterface )
741 return m_initChs.Index(s, bCase);
742
743 return m_popupInterface->FindString(s, bCase);
744 }
745
746 void wxOwnerDrawnComboBox::Select(int n)
747 {
748 EnsurePopupControl();
749
750 wxCHECK_RET( (n == wxNOT_FOUND) || IsValid(n), _T("invalid index in wxOwnerDrawnComboBox::Select") );
751
752 m_popupInterface->SetSelection(n);
753
754 wxString str;
755 if ( n >= 0 )
756 str = m_popupInterface->GetString(n);
757
758 // Refresh text portion in control
759 if ( m_text )
760 m_text->SetValue( str );
761 else
762 m_valueString = str;
763
764 Refresh();
765 }
766
767 int wxOwnerDrawnComboBox::GetSelection() const
768 {
769 if ( !m_popupInterface )
770 return m_initChs.Index(m_valueString);
771
772 return m_popupInterface->GetSelection();
773 }
774
775 int wxOwnerDrawnComboBox::DoAppend(const wxString& item)
776 {
777 EnsurePopupControl();
778 wxASSERT(m_popupInterface);
779 return m_popupInterface->Append(item);
780 }
781
782 int wxOwnerDrawnComboBox::DoInsert(const wxString& item, unsigned int pos)
783 {
784 EnsurePopupControl();
785
786 wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
787 wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index"));
788
789 m_popupInterface->Insert(item,pos);
790
791 return pos;
792 }
793
794 void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n, void* clientData)
795 {
796 EnsurePopupControl();
797 m_popupInterface->SetItemClientData(n,clientData,m_clientDataItemsType);
798 }
799
800 void* wxOwnerDrawnComboBox::DoGetItemClientData(unsigned int n) const
801 {
802 if ( !m_popupInterface )
803 return NULL;
804
805 return m_popupInterface->GetItemClientData(n);
806 }
807
808 void wxOwnerDrawnComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
809 {
810 DoSetItemClientData(n, (void*) clientData);
811 }
812
813 wxClientData* wxOwnerDrawnComboBox::DoGetItemClientObject(unsigned int n) const
814 {
815 return (wxClientData*) DoGetItemClientData(n);
816 }
817
818 // ----------------------------------------------------------------------------
819 // wxOwnerDrawnComboBox item drawing and measuring default implementations
820 // ----------------------------------------------------------------------------
821
822 void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc,
823 const wxRect& rect,
824 int item,
825 int flags ) const
826 {
827 if ( flags & wxODCB_PAINTING_CONTROL )
828 {
829 dc.DrawText( GetValue(),
830 rect.x + GetTextIndent(),
831 (rect.height-dc.GetCharHeight())/2 + rect.y );
832 }
833 else
834 {
835 dc.DrawText( m_popupInterface->GetString(item), rect.x + 2, rect.y );
836 }
837 }
838
839 wxCoord wxOwnerDrawnComboBox::OnMeasureItem( size_t WXUNUSED(item) ) const
840 {
841 return -1;
842 }
843
844 wxCoord wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item) ) const
845 {
846 return -1;
847 }
848
849 void wxOwnerDrawnComboBox::OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const
850 {
851 // we need to render selected and current items differently
852 if ( m_popupInterface->IsCurrent((size_t)item) )
853 {
854 DrawFocusBackground(dc,
855 rect,
856 (flags&wxODCB_PAINTING_CONTROL?0:wxCONTROL_ISSUBMENU) |
857 wxCONTROL_SELECTED);
858 }
859 //else: do nothing for the normal items
860 }
861
862 #endif // wxUSE_ODCOMBOBOX