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/listbox.h"
23 #include "wx/settings.h"
30 #include "wx/window.h"
31 #include "wx/msw/private.h"
35 #include "wx/dynarray.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( N
>= 0 && N
< m_noItems
,
254 wxT("invalid index in wxListBox::SetFirstItem") );
256 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
259 void wxListBox::Delete(int N
)
261 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
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 ( size_t ui
= 0; ui
< (size_t)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 ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
389 delete GetClientObject(n
);
394 void wxListBox::DoSetSelection(int N
, bool select
)
396 wxCHECK_RET( N
== wxNOT_FOUND
||
397 (N
>= 0 && N
< m_noItems
),
398 wxT("invalid index in wxListBox::SetSelection") );
400 if ( HasMultipleSelection() )
402 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
406 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
410 bool wxListBox::IsSelected(int N
) const
412 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, false,
413 wxT("invalid index in wxListBox::Selected") );
415 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
418 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
420 return (wxClientData
*)DoGetItemClientData(n
);
423 void *wxListBox::DoGetItemClientData(int n
) const
425 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
426 wxT("invalid index in wxListBox::GetClientData") );
428 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
431 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
433 DoSetItemClientData(n
, clientData
);
436 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
438 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
439 wxT("invalid index in wxListBox::SetClientData") );
441 #if wxUSE_OWNER_DRAWN
442 if ( m_windowStyle
& wxLB_OWNERDRAW
)
444 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
445 // in OnMeasure/OnDraw.
446 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
448 #endif // wxUSE_OWNER_DRAWN
450 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
451 wxLogDebug(wxT("LB_SETITEMDATA failed"));
454 // Return number of selections and an array of selected integers
455 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
459 if ( HasMultipleSelection() )
461 int countSel
= ListBox_GetSelCount(GetHwnd());
462 if ( countSel
== LB_ERR
)
464 wxLogDebug(_T("ListBox_GetSelCount failed"));
466 else if ( countSel
!= 0 )
468 int *selections
= new int[countSel
];
470 if ( ListBox_GetSelItems(GetHwnd(),
471 countSel
, selections
) == LB_ERR
)
473 wxLogDebug(wxT("ListBox_GetSelItems failed"));
478 aSelections
.Alloc(countSel
);
479 for ( int n
= 0; n
< countSel
; n
++ )
480 aSelections
.Add(selections
[n
]);
483 delete [] selections
;
488 else // single-selection listbox
490 if (ListBox_GetCurSel(GetHwnd()) > -1)
491 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
493 return aSelections
.Count();
497 // Get single selection, for single choice list items
498 int wxListBox::GetSelection() const
500 wxCHECK_MSG( !HasMultipleSelection(),
502 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
504 return ListBox_GetCurSel(GetHwnd());
507 // Find string for position
508 wxString
wxListBox::GetString(int N
) const
510 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
511 wxT("invalid index in wxListBox::GetString") );
513 int len
= ListBox_GetTextLen(GetHwnd(), N
);
515 // +1 for terminating NUL
517 ListBox_GetText(GetHwnd(), N
, (wxChar
*)wxStringBuffer(result
, len
+ 1));
523 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
525 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
526 wxT("invalid index in wxListBox::InsertItems") );
528 int nItems
= items
.GetCount();
529 for ( int i
= 0; i
< nItems
; i
++ )
531 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
533 #if wxUSE_OWNER_DRAWN
534 if ( m_windowStyle
& wxLB_OWNERDRAW
)
536 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
537 pNewItem
->SetName(items
[i
]);
538 pNewItem
->SetFont(GetFont());
539 m_aItems
.Insert(pNewItem
, idx
);
541 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
545 #endif // wxUSE_OWNER_DRAWN
550 SetHorizontalExtent();
552 InvalidateBestSize();
555 int wxListBox::DoListHitTest(const wxPoint
& point
) const
557 LRESULT lRes
= ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT
,
558 0L, MAKELONG(point
.x
, point
.y
));
560 // non zero high-order word means that this item is outside of the client
561 // area, IOW the point is outside of the listbox
562 return HIWORD(lRes
) ? wxNOT_FOUND
: lRes
;
565 void wxListBox::SetString(int N
, const wxString
& s
)
567 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
568 wxT("invalid index in wxListBox::SetString") );
570 // remember the state of the item
571 bool wasSelected
= IsSelected(N
);
573 void *oldData
= NULL
;
574 wxClientData
*oldObjData
= NULL
;
575 if ( m_clientDataItemsType
== wxClientData_Void
)
576 oldData
= GetClientData(N
);
577 else if ( m_clientDataItemsType
== wxClientData_Object
)
578 oldObjData
= GetClientObject(N
);
580 // delete and recreate it
581 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
584 if ( N
== m_noItems
- 1 )
587 ListBox_InsertString(GetHwnd(), newN
, s
);
589 // restore the client data
591 SetClientData(N
, oldData
);
592 else if ( oldObjData
)
593 SetClientObject(N
, oldObjData
);
595 #if wxUSE_OWNER_DRAWN
596 if ( m_windowStyle
& wxLB_OWNERDRAW
)
598 // update item's text
599 m_aItems
[N
]->SetName(s
);
601 // reassign the item's data
602 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
604 #endif //USE_OWNER_DRAWN
606 // we may have lost the selection
610 InvalidateBestSize();
613 int wxListBox::GetCount() const
618 // ----------------------------------------------------------------------------
620 // ----------------------------------------------------------------------------
622 // Windows-specific code to set the horizontal extent of the listbox, if
623 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
624 // Otherwise, all strings are used.
625 void wxListBox::SetHorizontalExtent(const wxString
& s
)
627 // Only necessary if we want a horizontal scrollbar
628 if (!(m_windowStyle
& wxHSCROLL
))
630 TEXTMETRIC lpTextMetric
;
634 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
635 HDC dc
= GetWindowDC(GetHwnd());
637 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
638 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
640 GetTextMetrics(dc
, &lpTextMetric
);
642 ::GetTextExtentPoint32(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
643 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
646 ::SelectObject(dc
, oldFont
);
648 ReleaseDC(GetHwnd(), dc
);
649 if (extentX
> existingExtent
)
650 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
654 int largestExtent
= 0;
655 HDC dc
= GetWindowDC(GetHwnd());
657 if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
658 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
660 GetTextMetrics(dc
, &lpTextMetric
);
662 for (int i
= 0; i
< m_noItems
; i
++)
664 wxString str
= GetString(i
);
666 ::GetTextExtentPoint32(dc
, str
.c_str(), str
.length(), &extentXY
);
667 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
668 if (extentX
> largestExtent
)
669 largestExtent
= extentX
;
672 ::SelectObject(dc
, oldFont
);
674 ReleaseDC(GetHwnd(), dc
);
675 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
679 wxSize
wxListBox::DoGetBestSize() const
681 // find the widest string
684 for ( int i
= 0; i
< m_noItems
; i
++ )
686 wxString
str(GetString(i
));
687 GetTextExtent(str
, &wLine
, NULL
);
688 if ( wLine
> wListbox
)
692 // give it some reasonable default value if there are no strings in the
697 // the listbox should be slightly larger than the widest string
699 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
703 // Add room for the scrollbar
704 wListbox
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
706 // don't make the listbox too tall (limit height to 10 items) but don't
707 // make it too small neither
708 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
709 wxMin(wxMax(m_noItems
, 3), 10);
711 wxSize
best(wListbox
, hListbox
);
716 // ----------------------------------------------------------------------------
718 // ----------------------------------------------------------------------------
720 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
723 if ( param
== LBN_SELCHANGE
)
725 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
727 else if ( param
== LBN_DBLCLK
)
729 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
733 // some event we're not interested in
737 wxCommandEvent
event(evtType
, m_windowId
);
738 event
.SetEventObject( this );
740 // retrieve the affected item
741 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
744 if ( HasClientObjectData() )
745 event
.SetClientObject( GetClientObject(n
) );
746 else if ( HasClientUntypedData() )
747 event
.SetClientData( GetClientData(n
) );
749 event
.SetString( GetString(n
) );
750 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : true );
755 return GetEventHandler()->ProcessEvent(event
);
758 // ----------------------------------------------------------------------------
759 // wxCheckListBox support
760 // ----------------------------------------------------------------------------
762 #if wxUSE_OWNER_DRAWN
767 // space beneath/above each row in pixels
768 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
769 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
771 // the height is the same for all items
772 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
774 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
775 // message is not yet sent when we get here!
776 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
778 // only owner-drawn control should receive this message
779 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
781 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
784 HDC hdc
= GetDC(NULL
);
786 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
790 wxDCTemp
dc((WXHDC
)hdc
);
791 dc
.SetFont(GetFont());
793 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
794 pStruct
->itemWidth
= dc
.GetCharWidth();
798 ReleaseDC(NULL
, hdc
);
806 // forward the message to the appropriate item
807 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
809 // only owner-drawn control should receive this message
810 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), false );
812 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
813 UINT itemID
= pStruct
->itemID
;
815 // the item may be -1 for an empty listbox
816 if ( itemID
== (UINT
)-1 )
819 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
821 wxCHECK( data
&& (data
!= LB_ERR
), false );
823 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
825 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
826 wxPoint
pt1(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
);
827 wxPoint
pt2(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
);
828 wxRect
rect(pt1
, pt2
);
830 return pItem
->OnDrawItem(dc
, rect
,
831 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
832 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
835 #endif // wxUSE_OWNER_DRAWN
837 #endif // wxUSE_LISTBOX