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 #ifdef __GNUWIN32_OLD__
47 #include "wx/msw/gnuwin32/extra.h"
50 #if wxUSE_EXTENDED_RTTI
51 WX_DEFINE_FLAGS( wxListBoxStyle
)
53 wxBEGIN_FLAGS( wxListBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
57 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
58 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
59 wxFLAGS_MEMBER(wxBORDER_RAISED
)
60 wxFLAGS_MEMBER(wxBORDER_STATIC
)
61 wxFLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
65 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
66 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
67 wxFLAGS_MEMBER(wxRAISED_BORDER
)
68 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
69 wxFLAGS_MEMBER(wxBORDER
)
71 // standard window styles
72 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
74 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 wxFLAGS_MEMBER(wxWANTS_CHARS
)
76 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
77 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 wxFLAGS_MEMBER(wxVSCROLL
)
79 wxFLAGS_MEMBER(wxHSCROLL
)
81 wxFLAGS_MEMBER(wxLB_SINGLE
)
82 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
83 wxFLAGS_MEMBER(wxLB_EXTENDED
)
84 wxFLAGS_MEMBER(wxLB_HSCROLL
)
85 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
86 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
87 wxFLAGS_MEMBER(wxLB_SORT
)
89 wxEND_FLAGS( wxListBoxStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControl
,"wx/listbox.h")
93 wxBEGIN_PROPERTIES_TABLE(wxListBox
)
94 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
95 wxEVENT_PROPERTY( DoubleClick
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
97 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
98 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
99 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
100 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
101 wxEND_PROPERTIES_TABLE()
103 wxBEGIN_HANDLERS_TABLE(wxListBox
)
104 wxEND_HANDLERS_TABLE()
106 wxCONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
108 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
118 // ============================================================================
119 // list box item declaration and implementation
120 // ============================================================================
122 #if wxUSE_OWNER_DRAWN
124 class wxListBoxItem
: public wxOwnerDrawn
127 wxListBoxItem(const wxString
& str
= wxEmptyString
);
130 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
132 // no bitmaps/checkmarks
136 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
138 return new wxListBoxItem();
141 #endif //USE_OWNER_DRAWN
143 // ============================================================================
144 // list box control implementation
145 // ============================================================================
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
152 wxListBox::wxListBox()
158 bool wxListBox::Create(wxWindow
*parent
,
162 int n
, const wxString choices
[],
164 const wxValidator
& validator
,
165 const wxString
& name
)
170 // initialize base class fields
171 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
174 // create the native control
175 if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString
, pos
, size
) )
177 // control creation failed
181 // initialize the contents
182 for ( int i
= 0; i
< n
; i
++ )
187 // now we can compute our best size correctly, so do it if necessary
193 bool wxListBox::Create(wxWindow
*parent
,
197 const wxArrayString
& choices
,
199 const wxValidator
& validator
,
200 const wxString
& name
)
202 wxCArrayString
chs(choices
);
203 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
204 style
, validator
, name
);
207 wxListBox::~wxListBox()
212 WXDWORD
wxListBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
214 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
216 // always show the vertical scrollbar if necessary -- otherwise it is
217 // impossible to use the control with the mouse
218 msStyle
|= WS_VSCROLL
;
220 // we always want to get the notifications
221 msStyle
|= LBS_NOTIFY
;
223 // without this style, you get unexpected heights, so e.g. constraint
224 // layout doesn't work properly
225 msStyle
|= LBS_NOINTEGRALHEIGHT
;
227 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
228 _T("only one of listbox selection modes can be specified") );
230 if ( style
& wxLB_MULTIPLE
)
231 msStyle
|= LBS_MULTIPLESEL
;
232 else if ( style
& wxLB_EXTENDED
)
233 msStyle
|= LBS_EXTENDEDSEL
;
235 if ( m_windowStyle
& wxLB_ALWAYS_SB
)
236 msStyle
|= LBS_DISABLENOSCROLL
;
237 if ( m_windowStyle
& wxLB_HSCROLL
)
238 msStyle
|= WS_HSCROLL
;
239 if ( m_windowStyle
& wxLB_SORT
)
242 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
243 if ( m_windowStyle
& wxLB_OWNERDRAW
)
245 // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put
246 // the strings in the listbox for simplicity even though we could have
247 // avoided it in this case
248 msStyle
|= LBS_OWNERDRAWFIXED
| LBS_HASSTRINGS
;
250 #endif // wxUSE_OWNER_DRAWN
255 // ----------------------------------------------------------------------------
256 // implementation of wxListBoxBase methods
257 // ----------------------------------------------------------------------------
259 void wxListBox::DoSetFirstItem(int N
)
261 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
262 wxT("invalid index in wxListBox::SetFirstItem") );
264 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
267 void wxListBox::Delete(int N
)
269 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
270 wxT("invalid index in wxListBox::Delete") );
272 // for owner drawn objects, the data is used for storing wxOwnerDrawn
273 // pointers and we shouldn't touch it
274 #if !wxUSE_OWNER_DRAWN
275 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
276 #endif // !wxUSE_OWNER_DRAWN
277 if ( HasClientObjectData() )
279 delete GetClientObject(N
);
282 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
285 SetHorizontalExtent(wxEmptyString
);
288 int wxListBox::DoAppend(const wxString
& item
)
290 InvalidateBestSize();
292 int index
= ListBox_AddString(GetHwnd(), item
);
295 #if wxUSE_OWNER_DRAWN
296 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
297 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
298 pNewItem
->SetName(item
);
299 m_aItems
.Insert(pNewItem
, index
);
300 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
301 pNewItem
->SetFont(GetFont());
303 #endif // wxUSE_OWNER_DRAWN
305 SetHorizontalExtent(item
);
310 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
312 // avoid flicker - but don't need to do this for a hidden listbox
313 bool hideAndShow
= IsShown();
316 ShowWindow(GetHwnd(), SW_HIDE
);
319 ListBox_ResetContent(GetHwnd());
321 m_noItems
= choices
.GetCount();
323 for (i
= 0; i
< m_noItems
; i
++)
325 ListBox_AddString(GetHwnd(), choices
[i
]);
328 SetClientData(i
, clientData
[i
]);
332 #if wxUSE_OWNER_DRAWN
333 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
334 // first delete old items
335 WX_CLEAR_ARRAY(m_aItems
);
337 // then create new ones
338 for ( size_t ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
339 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
340 pNewItem
->SetName(choices
[ui
]);
341 m_aItems
.Add(pNewItem
);
342 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
345 #endif // wxUSE_OWNER_DRAWN
347 SetHorizontalExtent();
351 // show the listbox back if we hid it
352 ShowWindow(GetHwnd(), SW_SHOW
);
356 int wxListBox::FindString(const wxString
& s
) const
358 int pos
= ListBox_FindStringExact(GetHwnd(), (WPARAM
)-1, s
);
365 void wxListBox::Clear()
369 ListBox_ResetContent(GetHwnd());
372 SetHorizontalExtent();
375 void wxListBox::Free()
377 #if wxUSE_OWNER_DRAWN
378 if ( m_windowStyle
& wxLB_OWNERDRAW
)
380 WX_CLEAR_ARRAY(m_aItems
);
383 #endif // wxUSE_OWNER_DRAWN
384 if ( HasClientObjectData() )
386 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
388 delete GetClientObject(n
);
393 void wxListBox::DoSetSelection(int N
, bool select
)
395 wxCHECK_RET( N
== wxNOT_FOUND
||
396 (N
>= 0 && N
< m_noItems
),
397 wxT("invalid index in wxListBox::SetSelection") );
399 if ( HasMultipleSelection() )
401 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
405 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
409 bool wxListBox::IsSelected(int N
) const
411 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, false,
412 wxT("invalid index in wxListBox::Selected") );
414 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
417 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
419 return (wxClientData
*)DoGetItemClientData(n
);
422 void *wxListBox::DoGetItemClientData(int n
) const
424 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
425 wxT("invalid index in wxListBox::GetClientData") );
427 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
430 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
432 DoSetItemClientData(n
, clientData
);
435 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
437 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
438 wxT("invalid index in wxListBox::SetClientData") );
440 #if wxUSE_OWNER_DRAWN
441 if ( m_windowStyle
& wxLB_OWNERDRAW
)
443 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
444 // in OnMeasure/OnDraw.
445 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
447 #endif // wxUSE_OWNER_DRAWN
449 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
450 wxLogDebug(wxT("LB_SETITEMDATA failed"));
453 // Return number of selections and an array of selected integers
454 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
458 if ( HasMultipleSelection() )
460 int countSel
= ListBox_GetSelCount(GetHwnd());
461 if ( countSel
== LB_ERR
)
463 wxLogDebug(_T("ListBox_GetSelCount failed"));
465 else if ( countSel
!= 0 )
467 int *selections
= new int[countSel
];
469 if ( ListBox_GetSelItems(GetHwnd(),
470 countSel
, selections
) == LB_ERR
)
472 wxLogDebug(wxT("ListBox_GetSelItems failed"));
477 aSelections
.Alloc(countSel
);
478 for ( int n
= 0; n
< countSel
; n
++ )
479 aSelections
.Add(selections
[n
]);
482 delete [] selections
;
487 else // single-selection listbox
489 if (ListBox_GetCurSel(GetHwnd()) > -1)
490 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
492 return aSelections
.Count();
496 // Get single selection, for single choice list items
497 int wxListBox::GetSelection() const
499 wxCHECK_MSG( !HasMultipleSelection(),
501 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
503 return ListBox_GetCurSel(GetHwnd());
506 // Find string for position
507 wxString
wxListBox::GetString(int N
) const
509 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
510 wxT("invalid index in wxListBox::GetString") );
512 int len
= ListBox_GetTextLen(GetHwnd(), N
);
514 // +1 for terminating NUL
516 ListBox_GetText(GetHwnd(), N
, (wxChar
*)wxStringBuffer(result
, len
+ 1));
522 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
524 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
525 wxT("invalid index in wxListBox::InsertItems") );
527 InvalidateBestSize();
529 int nItems
= items
.GetCount();
530 for ( int i
= 0; i
< nItems
; i
++ )
532 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
534 #if wxUSE_OWNER_DRAWN
535 if ( m_windowStyle
& wxLB_OWNERDRAW
)
537 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
538 pNewItem
->SetName(items
[i
]);
539 pNewItem
->SetFont(GetFont());
540 m_aItems
.Insert(pNewItem
, idx
);
542 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
546 #endif // wxUSE_OWNER_DRAWN
551 SetHorizontalExtent();
554 void wxListBox::SetString(int N
, const wxString
& s
)
556 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
557 wxT("invalid index in wxListBox::SetString") );
559 // remember the state of the item
560 bool wasSelected
= IsSelected(N
);
562 void *oldData
= NULL
;
563 wxClientData
*oldObjData
= NULL
;
564 if ( m_clientDataItemsType
== wxClientData_Void
)
565 oldData
= GetClientData(N
);
566 else if ( m_clientDataItemsType
== wxClientData_Object
)
567 oldObjData
= GetClientObject(N
);
569 // delete and recreate it
570 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
573 if ( N
== m_noItems
- 1 )
576 ListBox_InsertString(GetHwnd(), newN
, s
);
578 // restore the client data
580 SetClientData(N
, oldData
);
581 else if ( oldObjData
)
582 SetClientObject(N
, oldObjData
);
584 #if wxUSE_OWNER_DRAWN
585 if ( m_windowStyle
& wxLB_OWNERDRAW
)
587 // update item's text
588 m_aItems
[N
]->SetName(s
);
590 // reassign the item's data
591 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
593 #endif //USE_OWNER_DRAWN
595 // we may have lost the selection
600 int wxListBox::GetCount() const
605 // ----------------------------------------------------------------------------
607 // ----------------------------------------------------------------------------
609 // Windows-specific code to set the horizontal extent of the listbox, if
610 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
611 // Otherwise, all strings are used.
612 void wxListBox::SetHorizontalExtent(const wxString
& s
)
614 // Only necessary if we want a horizontal scrollbar
615 if (!(m_windowStyle
& wxHSCROLL
))
617 TEXTMETRIC lpTextMetric
;
621 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
622 HDC dc
= GetWindowDC(GetHwnd());
624 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
625 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
627 GetTextMetrics(dc
, &lpTextMetric
);
629 ::GetTextExtentPoint(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
630 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
633 ::SelectObject(dc
, oldFont
);
635 ReleaseDC(GetHwnd(), dc
);
636 if (extentX
> existingExtent
)
637 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
641 int largestExtent
= 0;
642 HDC dc
= GetWindowDC(GetHwnd());
644 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
645 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
647 GetTextMetrics(dc
, &lpTextMetric
);
649 for (int i
= 0; i
< m_noItems
; i
++)
651 wxString str
= GetString(i
);
653 ::GetTextExtentPoint(dc
, str
.c_str(), str
.length(), &extentXY
);
654 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
655 if (extentX
> largestExtent
)
656 largestExtent
= extentX
;
659 ::SelectObject(dc
, oldFont
);
661 ReleaseDC(GetHwnd(), dc
);
662 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
666 wxSize
wxListBox::DoGetBestSize() const
668 // find the widest string
671 for ( int i
= 0; i
< m_noItems
; i
++ )
673 wxString
str(GetString(i
));
674 GetTextExtent(str
, &wLine
, NULL
);
675 if ( wLine
> wListbox
)
679 // give it some reasonable default value if there are no strings in the
684 // the listbox should be slightly larger than the widest string
686 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
690 // don't make the listbox too tall (limit height to 10 items) but don't
691 // make it too small neither
692 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
693 wxMin(wxMax(m_noItems
, 3), 10);
695 return wxSize(wListbox
, hListbox
);
698 // ----------------------------------------------------------------------------
700 // ----------------------------------------------------------------------------
702 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
705 if ( param
== LBN_SELCHANGE
)
707 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
709 else if ( param
== LBN_DBLCLK
)
711 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
715 // some event we're not interested in
719 wxCommandEvent
event(evtType
, m_windowId
);
720 event
.SetEventObject( this );
722 // retrieve the affected item
723 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
726 if ( HasClientObjectData() )
727 event
.SetClientObject( GetClientObject(n
) );
728 else if ( HasClientUntypedData() )
729 event
.SetClientData( GetClientData(n
) );
731 event
.SetString( GetString(n
) );
732 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : true );
737 return GetEventHandler()->ProcessEvent(event
);
740 // ----------------------------------------------------------------------------
741 // wxCheckListBox support
742 // ----------------------------------------------------------------------------
744 #if wxUSE_OWNER_DRAWN
749 // space beneath/above each row in pixels
750 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
751 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
753 // the height is the same for all items
754 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
756 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
757 // message is not yet sent when we get here!
758 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
760 // only owner-drawn control should receive this message
761 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
763 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
766 HDC hdc
= GetDC(NULL
);
768 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
772 dc
.SetHDC((WXHDC
)hdc
);
773 dc
.SetFont(GetFont());
775 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
776 pStruct
->itemWidth
= dc
.GetCharWidth();
785 // forward the message to the appropriate item
786 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
788 // only owner-drawn control should receive this message
789 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
791 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
792 UINT itemID
= pStruct
->itemID
;
794 // the item may be -1 for an empty listbox
795 if ( itemID
== (UINT
)-1 )
798 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
800 wxCHECK( data
&& (data
!= LB_ERR
), false );
802 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
804 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
805 wxPoint
pt1(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
);
806 wxPoint
pt2(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
);
807 wxRect
rect(pt1
, pt2
);
809 return pItem
->OnDrawItem(dc
, rect
,
810 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
811 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
814 #endif // wxUSE_OWNER_DRAWN
816 #endif // wxUSE_LISTBOX