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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/listbox.h"
24 #include "wx/dynarray.h"
25 #include "wx/settings.h"
31 #include "wx/window.h"
34 #include "wx/msw/private.h"
39 #include "wx/ownerdrw.h"
42 #if wxUSE_EXTENDED_RTTI
43 WX_DEFINE_FLAGS( wxListBoxStyle
)
45 wxBEGIN_FLAGS( wxListBoxStyle
)
46 // new style border flags, we put them first to
47 // use them for streaming out
48 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
49 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
50 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
51 wxFLAGS_MEMBER(wxBORDER_RAISED
)
52 wxFLAGS_MEMBER(wxBORDER_STATIC
)
53 wxFLAGS_MEMBER(wxBORDER_NONE
)
55 // old style border flags
56 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
57 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
58 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
59 wxFLAGS_MEMBER(wxRAISED_BORDER
)
60 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
61 wxFLAGS_MEMBER(wxBORDER
)
63 // standard window styles
64 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
65 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
66 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
67 wxFLAGS_MEMBER(wxWANTS_CHARS
)
68 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
69 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
70 wxFLAGS_MEMBER(wxVSCROLL
)
71 wxFLAGS_MEMBER(wxHSCROLL
)
73 wxFLAGS_MEMBER(wxLB_SINGLE
)
74 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
75 wxFLAGS_MEMBER(wxLB_EXTENDED
)
76 wxFLAGS_MEMBER(wxLB_HSCROLL
)
77 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
78 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
79 wxFLAGS_MEMBER(wxLB_SORT
)
81 wxEND_FLAGS( wxListBoxStyle
)
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControl
,"wx/listbox.h")
85 wxBEGIN_PROPERTIES_TABLE(wxListBox
)
86 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
87 wxEVENT_PROPERTY( DoubleClick
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
89 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
90 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
91 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
92 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
93 wxEND_PROPERTIES_TABLE()
95 wxBEGIN_HANDLERS_TABLE(wxListBox
)
96 wxEND_HANDLERS_TABLE()
98 wxCONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
100 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
110 // ============================================================================
111 // list box item declaration and implementation
112 // ============================================================================
114 #if wxUSE_OWNER_DRAWN
116 class wxListBoxItem
: public wxOwnerDrawn
119 wxListBoxItem(const wxString
& str
= wxEmptyString
);
122 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
124 // no bitmaps/checkmarks
128 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
130 return new wxListBoxItem();
133 #endif //USE_OWNER_DRAWN
135 // ============================================================================
136 // list box control implementation
137 // ============================================================================
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
144 wxListBox::wxListBox()
150 bool wxListBox::Create(wxWindow
*parent
,
154 int n
, const wxString choices
[],
156 const wxValidator
& validator
,
157 const wxString
& name
)
162 // initialize base class fields
163 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
166 // create the native control
167 if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString
, pos
, size
) )
169 // control creation failed
173 // initialize the contents
174 for ( int i
= 0; i
< n
; i
++ )
179 // now we can compute our best size correctly, so do it if necessary
185 bool wxListBox::Create(wxWindow
*parent
,
189 const wxArrayString
& choices
,
191 const wxValidator
& validator
,
192 const wxString
& name
)
194 wxCArrayString
chs(choices
);
195 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
196 style
, validator
, name
);
199 wxListBox::~wxListBox()
204 WXDWORD
wxListBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
206 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
208 // always show the vertical scrollbar if necessary -- otherwise it is
209 // impossible to use the control with the mouse
210 msStyle
|= WS_VSCROLL
;
212 // we always want to get the notifications
213 msStyle
|= LBS_NOTIFY
;
215 // without this style, you get unexpected heights, so e.g. constraint
216 // layout doesn't work properly
217 msStyle
|= LBS_NOINTEGRALHEIGHT
;
219 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
220 _T("only one of listbox selection modes can be specified") );
222 if ( style
& wxLB_MULTIPLE
)
223 msStyle
|= LBS_MULTIPLESEL
;
224 else if ( style
& wxLB_EXTENDED
)
225 msStyle
|= LBS_EXTENDEDSEL
;
227 if ( m_windowStyle
& wxLB_ALWAYS_SB
)
228 msStyle
|= LBS_DISABLENOSCROLL
;
229 if ( m_windowStyle
& wxLB_HSCROLL
)
230 msStyle
|= WS_HSCROLL
;
231 if ( m_windowStyle
& wxLB_SORT
)
234 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
235 if ( m_windowStyle
& wxLB_OWNERDRAW
)
237 // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put
238 // the strings in the listbox for simplicity even though we could have
239 // avoided it in this case
240 msStyle
|= LBS_OWNERDRAWFIXED
| LBS_HASSTRINGS
;
242 #endif // wxUSE_OWNER_DRAWN
247 // ----------------------------------------------------------------------------
248 // implementation of wxListBoxBase methods
249 // ----------------------------------------------------------------------------
251 void wxListBox::DoSetFirstItem(int N
)
253 wxCHECK_RET( IsValid(N
),
254 wxT("invalid index in wxListBox::SetFirstItem") );
256 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
259 void wxListBox::Delete(unsigned int n
)
261 wxCHECK_RET( IsValid(n
),
262 wxT("invalid index in wxListBox::Delete") );
264 // for owner drawn objects, the data is used for storing wxOwnerDrawn
265 // pointers and we shouldn't touch it
266 #if !wxUSE_OWNER_DRAWN
267 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
268 #endif // !wxUSE_OWNER_DRAWN
269 if ( HasClientObjectData() )
271 delete GetClientObject(n
);
274 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
277 SetHorizontalExtent(wxEmptyString
);
279 InvalidateBestSize();
282 int wxListBox::DoAppend(const wxString
& item
)
284 int index
= ListBox_AddString(GetHwnd(), item
);
287 #if wxUSE_OWNER_DRAWN
288 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
289 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
290 pNewItem
->SetName(item
);
291 m_aItems
.Insert(pNewItem
, index
);
292 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
293 pNewItem
->SetFont(GetFont());
295 #endif // wxUSE_OWNER_DRAWN
297 SetHorizontalExtent(item
);
299 InvalidateBestSize();
303 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
305 // avoid flicker - but don't need to do this for a hidden listbox
306 bool hideAndShow
= IsShown();
309 ShowWindow(GetHwnd(), SW_HIDE
);
312 ListBox_ResetContent(GetHwnd());
314 m_noItems
= choices
.GetCount();
316 for (i
= 0; i
< m_noItems
; i
++)
318 ListBox_AddString(GetHwnd(), choices
[i
]);
321 SetClientData(i
, clientData
[i
]);
325 #if wxUSE_OWNER_DRAWN
326 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
327 // first delete old items
328 WX_CLEAR_ARRAY(m_aItems
);
330 // then create new ones
331 for ( unsigned int ui
= 0; ui
< m_noItems
; ui
++ ) {
332 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
333 pNewItem
->SetName(choices
[ui
]);
334 m_aItems
.Add(pNewItem
);
335 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
338 #endif // wxUSE_OWNER_DRAWN
340 SetHorizontalExtent();
344 // show the listbox back if we hid it
345 ShowWindow(GetHwnd(), SW_SHOW
);
348 InvalidateBestSize();
351 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
353 // back to base class search for not native search type
355 return wxItemContainerImmutable::FindString( s
, bCase
);
357 int pos
= ListBox_FindStringExact(GetHwnd(), -1, s
);
364 void wxListBox::Clear()
368 ListBox_ResetContent(GetHwnd());
371 SetHorizontalExtent();
373 InvalidateBestSize();
376 void wxListBox::Free()
378 #if wxUSE_OWNER_DRAWN
379 if ( m_windowStyle
& wxLB_OWNERDRAW
)
381 WX_CLEAR_ARRAY(m_aItems
);
384 #endif // wxUSE_OWNER_DRAWN
385 if ( HasClientObjectData() )
387 for ( unsigned int n
= 0; n
< m_noItems
; n
++ )
389 delete GetClientObject(n
);
394 void wxListBox::DoSetSelection(int N
, bool select
)
396 wxCHECK_RET( N
== wxNOT_FOUND
|| IsValid(N
),
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( IsValid(N
), false,
412 wxT("invalid index in wxListBox::Selected") );
414 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
417 wxClientData
* wxListBox::DoGetItemClientObject(unsigned int n
) const
419 return (wxClientData
*)DoGetItemClientData(n
);
422 void *wxListBox::DoGetItemClientData(unsigned int n
) const
424 wxCHECK_MSG( IsValid(n
), NULL
,
425 wxT("invalid index in wxListBox::GetClientData") );
427 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
430 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
432 DoSetItemClientData(n
, clientData
);
435 void wxListBox::DoSetItemClientData(unsigned int n
, void *clientData
)
437 wxCHECK_RET( IsValid(n
),
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(unsigned int n
) const
509 wxCHECK_MSG( IsValid(n
), 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
, unsigned int pos
)
524 wxCHECK_RET( IsValidInsert(pos
),
525 wxT("invalid index in wxListBox::InsertItems") );
527 unsigned int nItems
= items
.GetCount();
528 for ( unsigned int i
= 0; i
< nItems
; i
++ )
530 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
532 #if wxUSE_OWNER_DRAWN
533 if ( m_windowStyle
& wxLB_OWNERDRAW
)
535 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
536 pNewItem
->SetName(items
[i
]);
537 pNewItem
->SetFont(GetFont());
538 m_aItems
.Insert(pNewItem
, idx
);
540 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
544 #endif // wxUSE_OWNER_DRAWN
549 SetHorizontalExtent();
551 InvalidateBestSize();
554 int wxListBox::DoListHitTest(const wxPoint
& point
) const
556 LRESULT lRes
= ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT
,
557 0L, MAKELONG(point
.x
, point
.y
));
559 // non zero high-order word means that this item is outside of the client
560 // area, IOW the point is outside of the listbox
561 return HIWORD(lRes
) ? wxNOT_FOUND
: lRes
;
564 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
566 wxCHECK_RET( IsValid(n
),
567 wxT("invalid index in wxListBox::SetString") );
569 // remember the state of the item
570 bool wasSelected
= IsSelected(n
);
572 void *oldData
= NULL
;
573 wxClientData
*oldObjData
= NULL
;
574 if ( m_clientDataItemsType
== wxClientData_Void
)
575 oldData
= GetClientData(n
);
576 else if ( m_clientDataItemsType
== wxClientData_Object
)
577 oldObjData
= GetClientObject(n
);
579 // delete and recreate it
580 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
583 if ( n
== (m_noItems
- 1) )
586 ListBox_InsertString(GetHwnd(), newN
, s
);
588 // restore the client data
590 SetClientData(n
, oldData
);
591 else if ( oldObjData
)
592 SetClientObject(n
, oldObjData
);
594 #if wxUSE_OWNER_DRAWN
595 if ( m_windowStyle
& wxLB_OWNERDRAW
)
597 // update item's text
598 m_aItems
[n
]->SetName(s
);
600 // reassign the item's data
601 ListBox_SetItemData(GetHwnd(), n
, m_aItems
[n
]);
603 #endif //USE_OWNER_DRAWN
605 // we may have lost the selection
609 InvalidateBestSize();
612 unsigned int wxListBox::GetCount() const
617 // ----------------------------------------------------------------------------
619 // ----------------------------------------------------------------------------
621 // Windows-specific code to set the horizontal extent of the listbox, if
622 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
623 // Otherwise, all strings are used.
624 void wxListBox::SetHorizontalExtent(const wxString
& s
)
626 // Only necessary if we want a horizontal scrollbar
627 if (!(m_windowStyle
& wxHSCROLL
))
629 TEXTMETRIC lpTextMetric
;
633 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
634 HDC dc
= GetWindowDC(GetHwnd());
636 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
637 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
639 GetTextMetrics(dc
, &lpTextMetric
);
641 ::GetTextExtentPoint32(dc
, (LPTSTR
) (const wxChar
*)s
, s
.length(), &extentXY
);
642 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
645 ::SelectObject(dc
, oldFont
);
647 ReleaseDC(GetHwnd(), dc
);
648 if (extentX
> existingExtent
)
649 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
653 int largestExtent
= 0;
654 HDC dc
= GetWindowDC(GetHwnd());
656 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
657 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
659 GetTextMetrics(dc
, &lpTextMetric
);
661 for (unsigned int i
= 0; i
< m_noItems
; i
++)
663 wxString str
= GetString(i
);
665 ::GetTextExtentPoint32(dc
, str
.c_str(), str
.length(), &extentXY
);
666 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
667 if (extentX
> largestExtent
)
668 largestExtent
= extentX
;
671 ::SelectObject(dc
, oldFont
);
673 ReleaseDC(GetHwnd(), dc
);
674 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
678 wxSize
wxListBox::DoGetBestSize() const
680 // find the widest string
683 for (unsigned int i
= 0; i
< m_noItems
; i
++)
685 wxString
str(GetString(i
));
686 GetTextExtent(str
, &wLine
, NULL
);
687 if ( wLine
> wListbox
)
691 // give it some reasonable default value if there are no strings in the
696 // the listbox should be slightly larger than the widest string
698 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
702 // Add room for the scrollbar
703 wListbox
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
705 // don't make the listbox too tall (limit height to 10 items) but don't
706 // make it too small neither
707 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
708 wxMin(wxMax(m_noItems
, 3), 10);
710 wxSize
best(wListbox
, hListbox
);
715 // ----------------------------------------------------------------------------
717 // ----------------------------------------------------------------------------
719 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
722 if ( param
== LBN_SELCHANGE
)
724 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
726 else if ( param
== LBN_DBLCLK
)
728 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
732 // some event we're not interested in
736 wxCommandEvent
event(evtType
, m_windowId
);
737 event
.SetEventObject( this );
739 // retrieve the affected item
740 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
743 if ( HasClientObjectData() )
744 event
.SetClientObject( GetClientObject(n
) );
745 else if ( HasClientUntypedData() )
746 event
.SetClientData( GetClientData(n
) );
748 event
.SetString(GetString(n
));
749 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : true );
754 return GetEventHandler()->ProcessEvent(event
);
757 // ----------------------------------------------------------------------------
758 // wxCheckListBox support
759 // ----------------------------------------------------------------------------
761 #if wxUSE_OWNER_DRAWN
766 // space beneath/above each row in pixels
767 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
768 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
770 // the height is the same for all items
771 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
773 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
774 // message is not yet sent when we get here!
775 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
777 // only owner-drawn control should receive this message
778 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
780 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
783 HDC hdc
= GetDC(NULL
);
785 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
789 wxDCTemp
dc((WXHDC
)hdc
);
790 dc
.SetFont(GetFont());
792 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
793 pStruct
->itemWidth
= dc
.GetCharWidth();
797 ReleaseDC(NULL
, hdc
);
805 // forward the message to the appropriate item
806 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
808 // only owner-drawn control should receive this message
809 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
811 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
812 UINT itemID
= pStruct
->itemID
;
814 // the item may be -1 for an empty listbox
815 if ( itemID
== (UINT
)-1 )
818 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
820 wxCHECK( data
&& (data
!= LB_ERR
), false );
822 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
824 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
825 wxPoint
pt1(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
);
826 wxPoint
pt2(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
);
827 wxRect
rect(pt1
, pt2
);
829 return pItem
->OnDrawItem(dc
, rect
,
830 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
831 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
834 #endif // wxUSE_OWNER_DRAWN
836 #endif // wxUSE_LISTBOX