1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listbox.cpp
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (owner drawn stuff)
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "listbox.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/listbox.h"
27 #include "wx/settings.h"
34 #include "wx/window.h"
35 #include "wx/msw/private.h"
39 #include "wx/dynarray.h"
43 #include "wx/ownerdrw.h"
46 #if wxUSE_EXTENDED_RTTI
47 WX_DEFINE_FLAGS( wxListBoxStyle
)
49 wxBEGIN_FLAGS( wxListBoxStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
55 wxFLAGS_MEMBER(wxBORDER_RAISED
)
56 wxFLAGS_MEMBER(wxBORDER_STATIC
)
57 wxFLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
63 wxFLAGS_MEMBER(wxRAISED_BORDER
)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
65 wxFLAGS_MEMBER(wxBORDER
)
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 wxFLAGS_MEMBER(wxWANTS_CHARS
)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 wxFLAGS_MEMBER(wxVSCROLL
)
75 wxFLAGS_MEMBER(wxHSCROLL
)
77 wxFLAGS_MEMBER(wxLB_SINGLE
)
78 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
79 wxFLAGS_MEMBER(wxLB_EXTENDED
)
80 wxFLAGS_MEMBER(wxLB_HSCROLL
)
81 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
82 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
83 wxFLAGS_MEMBER(wxLB_SORT
)
85 wxEND_FLAGS( wxListBoxStyle
)
87 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControl
,"wx/listbox.h")
89 wxBEGIN_PROPERTIES_TABLE(wxListBox
)
90 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
91 wxEVENT_PROPERTY( DoubleClick
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
93 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
94 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
95 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
96 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
97 wxEND_PROPERTIES_TABLE()
99 wxBEGIN_HANDLERS_TABLE(wxListBox
)
100 wxEND_HANDLERS_TABLE()
102 wxCONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
104 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
114 // ============================================================================
115 // list box item declaration and implementation
116 // ============================================================================
118 #if wxUSE_OWNER_DRAWN
120 class wxListBoxItem
: public wxOwnerDrawn
123 wxListBoxItem(const wxString
& str
= wxEmptyString
);
126 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
128 // no bitmaps/checkmarks
132 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
134 return new wxListBoxItem();
137 #endif //USE_OWNER_DRAWN
139 // ============================================================================
140 // list box control implementation
141 // ============================================================================
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
148 wxListBox::wxListBox()
154 bool wxListBox::Create(wxWindow
*parent
,
158 int n
, const wxString choices
[],
160 const wxValidator
& validator
,
161 const wxString
& name
)
166 // initialize base class fields
167 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
170 // create the native control
171 if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString
, pos
, size
) )
173 // control creation failed
177 // initialize the contents
178 for ( int i
= 0; i
< n
; i
++ )
183 // now we can compute our best size correctly, so do it if necessary
189 bool wxListBox::Create(wxWindow
*parent
,
193 const wxArrayString
& choices
,
195 const wxValidator
& validator
,
196 const wxString
& name
)
198 wxCArrayString
chs(choices
);
199 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
200 style
, validator
, name
);
203 wxListBox::~wxListBox()
208 WXDWORD
wxListBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
210 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
212 // always show the vertical scrollbar if necessary -- otherwise it is
213 // impossible to use the control with the mouse
214 msStyle
|= WS_VSCROLL
;
216 // we always want to get the notifications
217 msStyle
|= LBS_NOTIFY
;
219 // without this style, you get unexpected heights, so e.g. constraint
220 // layout doesn't work properly
221 msStyle
|= LBS_NOINTEGRALHEIGHT
;
223 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
224 _T("only one of listbox selection modes can be specified") );
226 if ( style
& wxLB_MULTIPLE
)
227 msStyle
|= LBS_MULTIPLESEL
;
228 else if ( style
& wxLB_EXTENDED
)
229 msStyle
|= LBS_EXTENDEDSEL
;
231 if ( m_windowStyle
& wxLB_ALWAYS_SB
)
232 msStyle
|= LBS_DISABLENOSCROLL
;
233 if ( m_windowStyle
& wxLB_HSCROLL
)
234 msStyle
|= WS_HSCROLL
;
235 if ( m_windowStyle
& wxLB_SORT
)
238 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
239 if ( m_windowStyle
& wxLB_OWNERDRAW
)
241 // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put
242 // the strings in the listbox for simplicity even though we could have
243 // avoided it in this case
244 msStyle
|= LBS_OWNERDRAWFIXED
| LBS_HASSTRINGS
;
246 #endif // wxUSE_OWNER_DRAWN
251 // ----------------------------------------------------------------------------
252 // implementation of wxListBoxBase methods
253 // ----------------------------------------------------------------------------
255 void wxListBox::DoSetFirstItem(int N
)
257 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
258 wxT("invalid index in wxListBox::SetFirstItem") );
260 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
263 void wxListBox::Delete(int N
)
265 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
266 wxT("invalid index in wxListBox::Delete") );
268 // for owner drawn objects, the data is used for storing wxOwnerDrawn
269 // pointers and we shouldn't touch it
270 #if !wxUSE_OWNER_DRAWN
271 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
272 #endif // !wxUSE_OWNER_DRAWN
273 if ( HasClientObjectData() )
275 delete GetClientObject(N
);
278 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
281 SetHorizontalExtent(wxEmptyString
);
284 int wxListBox::DoAppend(const wxString
& item
)
286 InvalidateBestSize();
288 int index
= ListBox_AddString(GetHwnd(), item
);
291 #if wxUSE_OWNER_DRAWN
292 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
293 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
294 pNewItem
->SetName(item
);
295 m_aItems
.Insert(pNewItem
, index
);
296 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
297 pNewItem
->SetFont(GetFont());
299 #endif // wxUSE_OWNER_DRAWN
301 SetHorizontalExtent(item
);
306 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
308 // avoid flicker - but don't need to do this for a hidden listbox
309 bool hideAndShow
= IsShown();
312 ShowWindow(GetHwnd(), SW_HIDE
);
315 ListBox_ResetContent(GetHwnd());
317 m_noItems
= choices
.GetCount();
319 for (i
= 0; i
< m_noItems
; i
++)
321 ListBox_AddString(GetHwnd(), choices
[i
]);
324 SetClientData(i
, clientData
[i
]);
328 #if wxUSE_OWNER_DRAWN
329 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
330 // first delete old items
331 WX_CLEAR_ARRAY(m_aItems
);
333 // then create new ones
334 for ( size_t ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
335 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
336 pNewItem
->SetName(choices
[ui
]);
337 m_aItems
.Add(pNewItem
);
338 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
341 #endif // wxUSE_OWNER_DRAWN
343 SetHorizontalExtent();
347 // show the listbox back if we hid it
348 ShowWindow(GetHwnd(), SW_SHOW
);
352 int wxListBox::FindString(const wxString
& s
) const
354 int pos
= ListBox_FindStringExact(GetHwnd(), (WPARAM
)-1, s
);
361 void wxListBox::Clear()
365 ListBox_ResetContent(GetHwnd());
368 SetHorizontalExtent();
371 void wxListBox::Free()
373 #if wxUSE_OWNER_DRAWN
374 if ( m_windowStyle
& wxLB_OWNERDRAW
)
376 WX_CLEAR_ARRAY(m_aItems
);
379 #endif // wxUSE_OWNER_DRAWN
380 if ( HasClientObjectData() )
382 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
384 delete GetClientObject(n
);
389 void wxListBox::DoSetSelection(int N
, bool select
)
391 wxCHECK_RET( N
== wxNOT_FOUND
||
392 (N
>= 0 && N
< m_noItems
),
393 wxT("invalid index in wxListBox::SetSelection") );
395 if ( HasMultipleSelection() )
397 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
401 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
405 bool wxListBox::IsSelected(int N
) const
407 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, false,
408 wxT("invalid index in wxListBox::Selected") );
410 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
413 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
415 return (wxClientData
*)DoGetItemClientData(n
);
418 void *wxListBox::DoGetItemClientData(int n
) const
420 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
421 wxT("invalid index in wxListBox::GetClientData") );
423 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
426 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
428 DoSetItemClientData(n
, clientData
);
431 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
433 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
434 wxT("invalid index in wxListBox::SetClientData") );
436 #if wxUSE_OWNER_DRAWN
437 if ( m_windowStyle
& wxLB_OWNERDRAW
)
439 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
440 // in OnMeasure/OnDraw.
441 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
443 #endif // wxUSE_OWNER_DRAWN
445 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
446 wxLogDebug(wxT("LB_SETITEMDATA failed"));
449 // Return number of selections and an array of selected integers
450 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
454 if ( HasMultipleSelection() )
456 int countSel
= ListBox_GetSelCount(GetHwnd());
457 if ( countSel
== LB_ERR
)
459 wxLogDebug(_T("ListBox_GetSelCount failed"));
461 else if ( countSel
!= 0 )
463 int *selections
= new int[countSel
];
465 if ( ListBox_GetSelItems(GetHwnd(),
466 countSel
, selections
) == LB_ERR
)
468 wxLogDebug(wxT("ListBox_GetSelItems failed"));
473 aSelections
.Alloc(countSel
);
474 for ( int n
= 0; n
< countSel
; n
++ )
475 aSelections
.Add(selections
[n
]);
478 delete [] selections
;
483 else // single-selection listbox
485 if (ListBox_GetCurSel(GetHwnd()) > -1)
486 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
488 return aSelections
.Count();
492 // Get single selection, for single choice list items
493 int wxListBox::GetSelection() const
495 wxCHECK_MSG( !HasMultipleSelection(),
497 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
499 return ListBox_GetCurSel(GetHwnd());
502 // Find string for position
503 wxString
wxListBox::GetString(int N
) const
505 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
506 wxT("invalid index in wxListBox::GetString") );
508 int len
= ListBox_GetTextLen(GetHwnd(), N
);
510 // +1 for terminating NUL
512 ListBox_GetText(GetHwnd(), N
, (wxChar
*)wxStringBuffer(result
, len
+ 1));
518 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
520 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
521 wxT("invalid index in wxListBox::InsertItems") );
523 InvalidateBestSize();
525 int nItems
= items
.GetCount();
526 for ( int i
= 0; i
< nItems
; i
++ )
528 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
530 #if wxUSE_OWNER_DRAWN
531 if ( m_windowStyle
& wxLB_OWNERDRAW
)
533 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
534 pNewItem
->SetName(items
[i
]);
535 pNewItem
->SetFont(GetFont());
536 m_aItems
.Insert(pNewItem
, idx
);
538 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
542 #endif // wxUSE_OWNER_DRAWN
547 SetHorizontalExtent();
550 void wxListBox::SetString(int N
, const wxString
& s
)
552 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
553 wxT("invalid index in wxListBox::SetString") );
555 // remember the state of the item
556 bool wasSelected
= IsSelected(N
);
558 void *oldData
= NULL
;
559 wxClientData
*oldObjData
= NULL
;
560 if ( m_clientDataItemsType
== wxClientData_Void
)
561 oldData
= GetClientData(N
);
562 else if ( m_clientDataItemsType
== wxClientData_Object
)
563 oldObjData
= GetClientObject(N
);
565 // delete and recreate it
566 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
569 if ( N
== m_noItems
- 1 )
572 ListBox_InsertString(GetHwnd(), newN
, s
);
574 // restore the client data
576 SetClientData(N
, oldData
);
577 else if ( oldObjData
)
578 SetClientObject(N
, oldObjData
);
580 #if wxUSE_OWNER_DRAWN
581 if ( m_windowStyle
& wxLB_OWNERDRAW
)
583 // update item's text
584 m_aItems
[N
]->SetName(s
);
586 // reassign the item's data
587 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
589 #endif //USE_OWNER_DRAWN
591 // we may have lost the selection
596 int wxListBox::GetCount() const
601 // ----------------------------------------------------------------------------
603 // ----------------------------------------------------------------------------
605 // Windows-specific code to set the horizontal extent of the listbox, if
606 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
607 // Otherwise, all strings are used.
608 void wxListBox::SetHorizontalExtent(const wxString
& s
)
610 // Only necessary if we want a horizontal scrollbar
611 if (!(m_windowStyle
& wxHSCROLL
))
613 TEXTMETRIC lpTextMetric
;
617 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
618 HDC dc
= GetWindowDC(GetHwnd());
620 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
621 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
623 GetTextMetrics(dc
, &lpTextMetric
);
625 ::GetTextExtentPoint(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
626 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
629 ::SelectObject(dc
, oldFont
);
631 ReleaseDC(GetHwnd(), dc
);
632 if (extentX
> existingExtent
)
633 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
637 int largestExtent
= 0;
638 HDC dc
= GetWindowDC(GetHwnd());
640 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
641 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
643 GetTextMetrics(dc
, &lpTextMetric
);
645 for (int i
= 0; i
< m_noItems
; i
++)
647 wxString str
= GetString(i
);
649 ::GetTextExtentPoint(dc
, str
.c_str(), str
.length(), &extentXY
);
650 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
651 if (extentX
> largestExtent
)
652 largestExtent
= extentX
;
655 ::SelectObject(dc
, oldFont
);
657 ReleaseDC(GetHwnd(), dc
);
658 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
662 wxSize
wxListBox::DoGetBestSize() const
664 // find the widest string
667 for ( int i
= 0; i
< m_noItems
; i
++ )
669 wxString
str(GetString(i
));
670 GetTextExtent(str
, &wLine
, NULL
);
671 if ( wLine
> wListbox
)
675 // give it some reasonable default value if there are no strings in the
680 // the listbox should be slightly larger than the widest string
682 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
686 // Add room for the scrollbar
687 wListbox
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
689 // don't make the listbox too tall (limit height to 10 items) but don't
690 // make it too small neither
691 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
692 wxMin(wxMax(m_noItems
, 3), 10);
694 return wxSize(wListbox
, hListbox
);
697 // ----------------------------------------------------------------------------
699 // ----------------------------------------------------------------------------
701 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
704 if ( param
== LBN_SELCHANGE
)
706 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
708 else if ( param
== LBN_DBLCLK
)
710 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
714 // some event we're not interested in
718 wxCommandEvent
event(evtType
, m_windowId
);
719 event
.SetEventObject( this );
721 // retrieve the affected item
722 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
725 if ( HasClientObjectData() )
726 event
.SetClientObject( GetClientObject(n
) );
727 else if ( HasClientUntypedData() )
728 event
.SetClientData( GetClientData(n
) );
730 event
.SetString( GetString(n
) );
731 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : true );
736 return GetEventHandler()->ProcessEvent(event
);
739 // ----------------------------------------------------------------------------
740 // wxCheckListBox support
741 // ----------------------------------------------------------------------------
743 #if wxUSE_OWNER_DRAWN
748 // space beneath/above each row in pixels
749 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
750 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
752 // the height is the same for all items
753 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
755 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
756 // message is not yet sent when we get here!
757 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
759 // only owner-drawn control should receive this message
760 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
762 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
765 HDC hdc
= GetDC(NULL
);
767 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
771 dc
.SetHDC((WXHDC
)hdc
);
772 dc
.SetFont(GetFont());
774 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
775 pStruct
->itemWidth
= dc
.GetCharWidth();
784 // forward the message to the appropriate item
785 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
787 // only owner-drawn control should receive this message
788 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
790 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
791 UINT itemID
= pStruct
->itemID
;
793 // the item may be -1 for an empty listbox
794 if ( itemID
== (UINT
)-1 )
797 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
799 wxCHECK( data
&& (data
!= LB_ERR
), false );
801 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
803 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
804 wxPoint
pt1(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
);
805 wxPoint
pt2(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
);
806 wxRect
rect(pt1
, pt2
);
808 return pItem
->OnDrawItem(dc
, rect
,
809 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
810 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
813 #endif // wxUSE_OWNER_DRAWN
815 #endif // wxUSE_LISTBOX