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"
22 #include "wx/dynarray.h"
23 #include "wx/listbox.h"
24 #include "wx/settings.h"
30 #include "wx/window.h"
33 #include "wx/msw/private.h"
38 #include "wx/ownerdrw.h"
41 #if wxUSE_EXTENDED_RTTI
42 WX_DEFINE_FLAGS( wxListBoxStyle
)
44 wxBEGIN_FLAGS( wxListBoxStyle
)
45 // new style border flags, we put them first to
46 // use them for streaming out
47 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
48 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
49 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
50 wxFLAGS_MEMBER(wxBORDER_RAISED
)
51 wxFLAGS_MEMBER(wxBORDER_STATIC
)
52 wxFLAGS_MEMBER(wxBORDER_NONE
)
54 // old style border flags
55 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
56 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
57 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
58 wxFLAGS_MEMBER(wxRAISED_BORDER
)
59 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
60 wxFLAGS_MEMBER(wxBORDER
)
62 // standard window styles
63 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
64 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
65 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
66 wxFLAGS_MEMBER(wxWANTS_CHARS
)
67 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
68 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
69 wxFLAGS_MEMBER(wxVSCROLL
)
70 wxFLAGS_MEMBER(wxHSCROLL
)
72 wxFLAGS_MEMBER(wxLB_SINGLE
)
73 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
74 wxFLAGS_MEMBER(wxLB_EXTENDED
)
75 wxFLAGS_MEMBER(wxLB_HSCROLL
)
76 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
77 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
78 wxFLAGS_MEMBER(wxLB_SORT
)
80 wxEND_FLAGS( wxListBoxStyle
)
82 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControl
,"wx/listbox.h")
84 wxBEGIN_PROPERTIES_TABLE(wxListBox
)
85 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
86 wxEVENT_PROPERTY( DoubleClick
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
88 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
89 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
90 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
91 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
92 wxEND_PROPERTIES_TABLE()
94 wxBEGIN_HANDLERS_TABLE(wxListBox
)
95 wxEND_HANDLERS_TABLE()
97 wxCONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
99 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
109 // ============================================================================
110 // list box item declaration and implementation
111 // ============================================================================
113 #if wxUSE_OWNER_DRAWN
115 class wxListBoxItem
: public wxOwnerDrawn
118 wxListBoxItem(const wxString
& str
= wxEmptyString
);
121 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
123 // no bitmaps/checkmarks
127 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
129 return new wxListBoxItem();
132 #endif //USE_OWNER_DRAWN
134 // ============================================================================
135 // list box control implementation
136 // ============================================================================
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
143 wxListBox::wxListBox()
149 bool wxListBox::Create(wxWindow
*parent
,
153 int n
, const wxString choices
[],
155 const wxValidator
& validator
,
156 const wxString
& name
)
161 // initialize base class fields
162 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
165 // create the native control
166 if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString
, pos
, size
) )
168 // control creation failed
172 // initialize the contents
173 for ( int i
= 0; i
< n
; i
++ )
178 // now we can compute our best size correctly, so do it if necessary
184 bool wxListBox::Create(wxWindow
*parent
,
188 const wxArrayString
& choices
,
190 const wxValidator
& validator
,
191 const wxString
& name
)
193 wxCArrayString
chs(choices
);
194 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
195 style
, validator
, name
);
198 wxListBox::~wxListBox()
203 WXDWORD
wxListBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
205 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
207 // always show the vertical scrollbar if necessary -- otherwise it is
208 // impossible to use the control with the mouse
209 msStyle
|= WS_VSCROLL
;
211 // we always want to get the notifications
212 msStyle
|= LBS_NOTIFY
;
214 // without this style, you get unexpected heights, so e.g. constraint
215 // layout doesn't work properly
216 msStyle
|= LBS_NOINTEGRALHEIGHT
;
218 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
219 _T("only one of listbox selection modes can be specified") );
221 if ( style
& wxLB_MULTIPLE
)
222 msStyle
|= LBS_MULTIPLESEL
;
223 else if ( style
& wxLB_EXTENDED
)
224 msStyle
|= LBS_EXTENDEDSEL
;
226 if ( m_windowStyle
& wxLB_ALWAYS_SB
)
227 msStyle
|= LBS_DISABLENOSCROLL
;
228 if ( m_windowStyle
& wxLB_HSCROLL
)
229 msStyle
|= WS_HSCROLL
;
230 if ( m_windowStyle
& wxLB_SORT
)
233 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
234 if ( m_windowStyle
& wxLB_OWNERDRAW
)
236 // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put
237 // the strings in the listbox for simplicity even though we could have
238 // avoided it in this case
239 msStyle
|= LBS_OWNERDRAWFIXED
| LBS_HASSTRINGS
;
241 #endif // wxUSE_OWNER_DRAWN
246 // ----------------------------------------------------------------------------
247 // implementation of wxListBoxBase methods
248 // ----------------------------------------------------------------------------
250 void wxListBox::DoSetFirstItem(int N
)
252 wxCHECK_RET( IsValid(N
),
253 wxT("invalid index in wxListBox::SetFirstItem") );
255 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
258 void wxListBox::Delete(unsigned int n
)
260 wxCHECK_RET( IsValid(n
),
261 wxT("invalid index in wxListBox::Delete") );
263 // for owner drawn objects, the data is used for storing wxOwnerDrawn
264 // pointers and we shouldn't touch it
265 #if !wxUSE_OWNER_DRAWN
266 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
267 #endif // !wxUSE_OWNER_DRAWN
268 if ( HasClientObjectData() )
270 delete GetClientObject(n
);
273 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
276 SetHorizontalExtent(wxEmptyString
);
278 InvalidateBestSize();
281 int wxListBox::DoAppend(const wxString
& item
)
283 int index
= ListBox_AddString(GetHwnd(), item
);
286 #if wxUSE_OWNER_DRAWN
287 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
288 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
289 pNewItem
->SetName(item
);
290 m_aItems
.Insert(pNewItem
, index
);
291 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
292 pNewItem
->SetFont(GetFont());
294 #endif // wxUSE_OWNER_DRAWN
296 SetHorizontalExtent(item
);
298 InvalidateBestSize();
302 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
304 // avoid flicker - but don't need to do this for a hidden listbox
305 bool hideAndShow
= IsShown();
308 ShowWindow(GetHwnd(), SW_HIDE
);
311 ListBox_ResetContent(GetHwnd());
313 m_noItems
= choices
.GetCount();
315 for (i
= 0; i
< m_noItems
; i
++)
317 ListBox_AddString(GetHwnd(), choices
[i
]);
320 SetClientData(i
, clientData
[i
]);
324 #if wxUSE_OWNER_DRAWN
325 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
326 // first delete old items
327 WX_CLEAR_ARRAY(m_aItems
);
329 // then create new ones
330 for ( unsigned int ui
= 0; ui
< m_noItems
; ui
++ ) {
331 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
332 pNewItem
->SetName(choices
[ui
]);
333 m_aItems
.Add(pNewItem
);
334 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
337 #endif // wxUSE_OWNER_DRAWN
339 SetHorizontalExtent();
343 // show the listbox back if we hid it
344 ShowWindow(GetHwnd(), SW_SHOW
);
347 InvalidateBestSize();
350 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
352 // back to base class search for not native search type
354 return wxItemContainerImmutable::FindString( s
, bCase
);
356 int pos
= ListBox_FindStringExact(GetHwnd(), -1, s
);
363 void wxListBox::Clear()
367 ListBox_ResetContent(GetHwnd());
370 SetHorizontalExtent();
372 InvalidateBestSize();
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 ( unsigned int n
= 0; n
< m_noItems
; n
++ )
388 delete GetClientObject(n
);
393 void wxListBox::DoSetSelection(int N
, bool select
)
395 wxCHECK_RET( N
== wxNOT_FOUND
|| IsValid(N
),
396 wxT("invalid index in wxListBox::SetSelection") );
398 if ( HasMultipleSelection() )
400 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
404 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
408 bool wxListBox::IsSelected(int N
) const
410 wxCHECK_MSG( IsValid(N
), false,
411 wxT("invalid index in wxListBox::Selected") );
413 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
416 wxClientData
* wxListBox::DoGetItemClientObject(unsigned int n
) const
418 return (wxClientData
*)DoGetItemClientData(n
);
421 void *wxListBox::DoGetItemClientData(unsigned int n
) const
423 wxCHECK_MSG( IsValid(n
), NULL
,
424 wxT("invalid index in wxListBox::GetClientData") );
426 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
429 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
431 DoSetItemClientData(n
, clientData
);
434 void wxListBox::DoSetItemClientData(unsigned int n
, void *clientData
)
436 wxCHECK_RET( IsValid(n
),
437 wxT("invalid index in wxListBox::SetClientData") );
439 #if wxUSE_OWNER_DRAWN
440 if ( m_windowStyle
& wxLB_OWNERDRAW
)
442 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
443 // in OnMeasure/OnDraw.
444 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
446 #endif // wxUSE_OWNER_DRAWN
448 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
449 wxLogDebug(wxT("LB_SETITEMDATA failed"));
452 // Return number of selections and an array of selected integers
453 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
457 if ( HasMultipleSelection() )
459 int countSel
= ListBox_GetSelCount(GetHwnd());
460 if ( countSel
== LB_ERR
)
462 wxLogDebug(_T("ListBox_GetSelCount failed"));
464 else if ( countSel
!= 0 )
466 int *selections
= new int[countSel
];
468 if ( ListBox_GetSelItems(GetHwnd(),
469 countSel
, selections
) == LB_ERR
)
471 wxLogDebug(wxT("ListBox_GetSelItems failed"));
476 aSelections
.Alloc(countSel
);
477 for ( int n
= 0; n
< countSel
; n
++ )
478 aSelections
.Add(selections
[n
]);
481 delete [] selections
;
486 else // single-selection listbox
488 if (ListBox_GetCurSel(GetHwnd()) > -1)
489 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
491 return aSelections
.Count();
495 // Get single selection, for single choice list items
496 int wxListBox::GetSelection() const
498 wxCHECK_MSG( !HasMultipleSelection(),
500 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
502 return ListBox_GetCurSel(GetHwnd());
505 // Find string for position
506 wxString
wxListBox::GetString(unsigned int n
) const
508 wxCHECK_MSG( IsValid(n
), wxEmptyString
,
509 wxT("invalid index in wxListBox::GetString") );
511 int len
= ListBox_GetTextLen(GetHwnd(), n
);
513 // +1 for terminating NUL
515 ListBox_GetText(GetHwnd(), n
, (wxChar
*)wxStringBuffer(result
, len
+ 1));
521 wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
523 wxCHECK_RET( IsValidInsert(pos
),
524 wxT("invalid index in wxListBox::InsertItems") );
526 unsigned int nItems
= items
.GetCount();
527 for ( unsigned int i
= 0; i
< nItems
; i
++ )
529 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
531 #if wxUSE_OWNER_DRAWN
532 if ( m_windowStyle
& wxLB_OWNERDRAW
)
534 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
535 pNewItem
->SetName(items
[i
]);
536 pNewItem
->SetFont(GetFont());
537 m_aItems
.Insert(pNewItem
, idx
);
539 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
543 #endif // wxUSE_OWNER_DRAWN
548 SetHorizontalExtent();
550 InvalidateBestSize();
553 int wxListBox::DoListHitTest(const wxPoint
& point
) const
555 LRESULT lRes
= ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT
,
556 0L, MAKELONG(point
.x
, point
.y
));
558 // non zero high-order word means that this item is outside of the client
559 // area, IOW the point is outside of the listbox
560 return HIWORD(lRes
) ? wxNOT_FOUND
: lRes
;
563 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
565 wxCHECK_RET( IsValid(n
),
566 wxT("invalid index in wxListBox::SetString") );
568 // remember the state of the item
569 bool wasSelected
= IsSelected(n
);
571 void *oldData
= NULL
;
572 wxClientData
*oldObjData
= NULL
;
573 if ( m_clientDataItemsType
== wxClientData_Void
)
574 oldData
= GetClientData(n
);
575 else if ( m_clientDataItemsType
== wxClientData_Object
)
576 oldObjData
= GetClientObject(n
);
578 // delete and recreate it
579 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
582 if ( n
== (m_noItems
- 1) )
585 ListBox_InsertString(GetHwnd(), newN
, s
);
587 // restore the client data
589 SetClientData(n
, oldData
);
590 else if ( oldObjData
)
591 SetClientObject(n
, oldObjData
);
593 #if wxUSE_OWNER_DRAWN
594 if ( m_windowStyle
& wxLB_OWNERDRAW
)
596 // update item's text
597 m_aItems
[n
]->SetName(s
);
599 // reassign the item's data
600 ListBox_SetItemData(GetHwnd(), n
, m_aItems
[n
]);
602 #endif //USE_OWNER_DRAWN
604 // we may have lost the selection
608 InvalidateBestSize();
611 unsigned int wxListBox::GetCount() const
616 // ----------------------------------------------------------------------------
618 // ----------------------------------------------------------------------------
620 // Windows-specific code to set the horizontal extent of the listbox, if
621 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
622 // Otherwise, all strings are used.
623 void wxListBox::SetHorizontalExtent(const wxString
& s
)
625 // Only necessary if we want a horizontal scrollbar
626 if (!(m_windowStyle
& wxHSCROLL
))
628 TEXTMETRIC lpTextMetric
;
632 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
633 HDC dc
= GetWindowDC(GetHwnd());
635 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
636 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
638 GetTextMetrics(dc
, &lpTextMetric
);
640 ::GetTextExtentPoint32(dc
, (LPTSTR
) (const wxChar
*)s
, s
.length(), &extentXY
);
641 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
644 ::SelectObject(dc
, oldFont
);
646 ReleaseDC(GetHwnd(), dc
);
647 if (extentX
> existingExtent
)
648 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
652 int largestExtent
= 0;
653 HDC dc
= GetWindowDC(GetHwnd());
655 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
656 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
658 GetTextMetrics(dc
, &lpTextMetric
);
660 for (unsigned int i
= 0; i
< m_noItems
; i
++)
662 wxString str
= GetString(i
);
664 ::GetTextExtentPoint32(dc
, str
.c_str(), str
.length(), &extentXY
);
665 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
666 if (extentX
> largestExtent
)
667 largestExtent
= extentX
;
670 ::SelectObject(dc
, oldFont
);
672 ReleaseDC(GetHwnd(), dc
);
673 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
677 wxSize
wxListBox::DoGetBestSize() const
679 // find the widest string
682 for (unsigned int i
= 0; i
< m_noItems
; i
++)
684 wxString
str(GetString(i
));
685 GetTextExtent(str
, &wLine
, NULL
);
686 if ( wLine
> wListbox
)
690 // give it some reasonable default value if there are no strings in the
695 // the listbox should be slightly larger than the widest string
697 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
701 // Add room for the scrollbar
702 wListbox
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
704 // don't make the listbox too tall (limit height to 10 items) but don't
705 // make it too small neither
706 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
707 wxMin(wxMax(m_noItems
, 3), 10);
709 wxSize
best(wListbox
, hListbox
);
714 // ----------------------------------------------------------------------------
716 // ----------------------------------------------------------------------------
718 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
721 if ( param
== LBN_SELCHANGE
)
723 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
725 else if ( param
== LBN_DBLCLK
)
727 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
731 // some event we're not interested in
735 wxCommandEvent
event(evtType
, m_windowId
);
736 event
.SetEventObject( this );
738 // retrieve the affected item
739 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
742 if ( HasClientObjectData() )
743 event
.SetClientObject( GetClientObject(n
) );
744 else if ( HasClientUntypedData() )
745 event
.SetClientData( GetClientData(n
) );
747 event
.SetString(GetString(n
));
748 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : true );
753 return GetEventHandler()->ProcessEvent(event
);
756 // ----------------------------------------------------------------------------
757 // wxCheckListBox support
758 // ----------------------------------------------------------------------------
760 #if wxUSE_OWNER_DRAWN
765 // space beneath/above each row in pixels
766 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
767 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
769 // the height is the same for all items
770 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
772 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
773 // message is not yet sent when we get here!
774 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
776 // only owner-drawn control should receive this message
777 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
779 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
782 HDC hdc
= GetDC(NULL
);
784 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
788 wxDCTemp
dc((WXHDC
)hdc
);
789 dc
.SetFont(GetFont());
791 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
792 pStruct
->itemWidth
= dc
.GetCharWidth();
796 ReleaseDC(NULL
, hdc
);
804 // forward the message to the appropriate item
805 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
807 // only owner-drawn control should receive this message
808 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
810 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
811 UINT itemID
= pStruct
->itemID
;
813 // the item may be -1 for an empty listbox
814 if ( itemID
== (UINT
)-1 )
817 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
819 wxCHECK( data
&& (data
!= LB_ERR
), false );
821 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
823 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
824 wxPoint
pt1(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
);
825 wxPoint
pt2(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
);
826 wxRect
rect(pt1
, pt2
);
828 return pItem
->OnDrawItem(dc
, rect
,
829 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
830 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
833 #endif // wxUSE_OWNER_DRAWN
835 #endif // wxUSE_LISTBOX