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 WX_BEGIN_FLAGS( wxListBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 WX_FLAGS_MEMBER(wxBORDER_SIMPLE
)
57 WX_FLAGS_MEMBER(wxBORDER_SUNKEN
)
58 WX_FLAGS_MEMBER(wxBORDER_DOUBLE
)
59 WX_FLAGS_MEMBER(wxBORDER_RAISED
)
60 WX_FLAGS_MEMBER(wxBORDER_STATIC
)
61 WX_FLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 WX_FLAGS_MEMBER(wxSIMPLE_BORDER
)
65 WX_FLAGS_MEMBER(wxSUNKEN_BORDER
)
66 WX_FLAGS_MEMBER(wxDOUBLE_BORDER
)
67 WX_FLAGS_MEMBER(wxRAISED_BORDER
)
68 WX_FLAGS_MEMBER(wxSTATIC_BORDER
)
69 WX_FLAGS_MEMBER(wxNO_BORDER
)
71 // standard window styles
72 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 WX_FLAGS_MEMBER(wxCLIP_CHILDREN
)
74 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 WX_FLAGS_MEMBER(wxWANTS_CHARS
)
76 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
77 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 WX_FLAGS_MEMBER(wxVSCROLL
)
79 WX_FLAGS_MEMBER(wxHSCROLL
)
81 WX_FLAGS_MEMBER(wxLB_SINGLE
)
82 WX_FLAGS_MEMBER(wxLB_MULTIPLE
)
83 WX_FLAGS_MEMBER(wxLB_EXTENDED
)
84 WX_FLAGS_MEMBER(wxLB_HSCROLL
)
85 WX_FLAGS_MEMBER(wxLB_ALWAYS_SB
)
86 WX_FLAGS_MEMBER(wxLB_NEEDED_SB
)
87 WX_FLAGS_MEMBER(wxLB_SORT
)
89 WX_END_FLAGS( wxListBoxStyle
)
91 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControl
,"wx/listbox.h")
93 WX_BEGIN_PROPERTIES_TABLE(wxListBox
)
95 WX_PROPERTY( Font
, wxFont
, SetFont
, GetFont
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
96 WX_PROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
97 WX_PROPERTY( Selection
,int, SetSelection
, GetSelection
,, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
98 WX_PROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99 WX_END_PROPERTIES_TABLE()
101 WX_BEGIN_HANDLERS_TABLE(wxListBox
)
102 WX_END_HANDLERS_TABLE()
104 WX_CONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
106 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
116 // ============================================================================
117 // list box item declaration and implementation
118 // ============================================================================
120 #if wxUSE_OWNER_DRAWN
122 class wxListBoxItem
: public wxOwnerDrawn
125 wxListBoxItem(const wxString
& str
= wxEmptyString
);
128 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
130 // no bitmaps/checkmarks
134 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
136 return new wxListBoxItem();
139 #endif //USE_OWNER_DRAWN
141 // ============================================================================
142 // list box control implementation
143 // ============================================================================
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
150 wxListBox::wxListBox()
156 bool wxListBox::Create(wxWindow
*parent
,
160 int n
, const wxString choices
[],
162 const wxValidator
& validator
,
163 const wxString
& name
)
171 SetValidator(validator
);
172 #endif // wxUSE_VALIDATORS
175 parent
->AddChild(this);
177 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
178 SetForegroundColour(parent
->GetForegroundColour());
180 m_windowId
= ( id
== -1 ) ? (int)NewControlId() : id
;
186 m_windowStyle
= style
;
188 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_VSCROLL
| WS_TABSTOP
|
189 LBS_NOTIFY
| LBS_HASSTRINGS
;
191 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
192 _T("only one of listbox selection modes can be specified") );
194 if ( (m_windowStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
195 m_windowStyle
|= wxBORDER_SUNKEN
;
197 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
198 wstyle
|= WS_CLIPSIBLINGS
;
200 if (m_windowStyle
& wxLB_MULTIPLE
)
201 wstyle
|= LBS_MULTIPLESEL
;
202 else if (m_windowStyle
& wxLB_EXTENDED
)
203 wstyle
|= LBS_EXTENDEDSEL
;
205 if (m_windowStyle
& wxLB_ALWAYS_SB
)
206 wstyle
|= LBS_DISABLENOSCROLL
;
207 if (m_windowStyle
& wxLB_HSCROLL
)
208 wstyle
|= WS_HSCROLL
;
209 if (m_windowStyle
& wxLB_SORT
)
212 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
213 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
214 // we don't support LBS_OWNERDRAWVARIABLE yet
215 wstyle
|= LBS_OWNERDRAWFIXED
;
219 // Without this style, you get unexpected heights, so e.g. constraint layout
220 // doesn't work properly
221 wstyle
|= LBS_NOINTEGRALHEIGHT
;
224 (void) MSWGetStyle(m_windowStyle
, & exStyle
) ;
226 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, wxT("LISTBOX"), NULL
,
229 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
230 wxGetInstance(), NULL
);
232 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create listbox") );
234 // Subclass again to catch messages
238 for (ui
= 0; ui
< (size_t)n
; ui
++) {
242 if ( (m_windowStyle
& wxLB_MULTIPLE
) == 0 )
243 SendMessage(GetHwnd(), LB_SETCURSEL
, 0, 0);
245 SetFont(parent
->GetFont());
247 SetSize(x
, y
, width
, height
);
252 wxListBox::~wxListBox()
257 void wxListBox::SetupColours()
259 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
260 SetForegroundColour(GetParent()->GetForegroundColour());
263 // ----------------------------------------------------------------------------
264 // implementation of wxListBoxBase methods
265 // ----------------------------------------------------------------------------
267 void wxListBox::DoSetFirstItem(int N
)
269 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
270 wxT("invalid index in wxListBox::SetFirstItem") );
272 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
275 void wxListBox::Delete(int N
)
277 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
278 wxT("invalid index in wxListBox::Delete") );
280 // for owner drawn objects, the data is used for storing wxOwnerDrawn
281 // pointers and we shouldn't touch it
282 #if !wxUSE_OWNER_DRAWN
283 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
284 #endif // !wxUSE_OWNER_DRAWN
285 if ( HasClientObjectData() )
287 delete GetClientObject(N
);
290 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
293 SetHorizontalExtent(wxEmptyString
);
296 int wxListBox::DoAppend(const wxString
& item
)
298 int index
= ListBox_AddString(GetHwnd(), item
);
301 #if wxUSE_OWNER_DRAWN
302 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
303 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
304 pNewItem
->SetName(item
);
305 m_aItems
.Insert(pNewItem
, index
);
306 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
307 pNewItem
->SetFont(GetFont());
309 #endif // wxUSE_OWNER_DRAWN
311 SetHorizontalExtent(item
);
316 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
318 // avoid flicker - but don't need to do this for a hidden listbox
319 bool hideAndShow
= IsShown();
322 ShowWindow(GetHwnd(), SW_HIDE
);
325 ListBox_ResetContent(GetHwnd());
327 m_noItems
= choices
.GetCount();
329 for (i
= 0; i
< m_noItems
; i
++)
331 ListBox_AddString(GetHwnd(), choices
[i
]);
334 SetClientData(i
, clientData
[i
]);
338 #if wxUSE_OWNER_DRAWN
339 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
340 // first delete old items
341 WX_CLEAR_ARRAY(m_aItems
);
343 // then create new ones
344 for ( size_t ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
345 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
346 pNewItem
->SetName(choices
[ui
]);
347 m_aItems
.Add(pNewItem
);
348 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
351 #endif // wxUSE_OWNER_DRAWN
353 SetHorizontalExtent();
357 // show the listbox back if we hid it
358 ShowWindow(GetHwnd(), SW_SHOW
);
362 int wxListBox::FindString(const wxString
& s
) const
364 int pos
= ListBox_FindStringExact(GetHwnd(), (WPARAM
)-1, s
);
371 void wxListBox::Clear()
375 ListBox_ResetContent(GetHwnd());
378 SetHorizontalExtent();
381 void wxListBox::Free()
383 #if wxUSE_OWNER_DRAWN
384 if ( m_windowStyle
& wxLB_OWNERDRAW
)
386 WX_CLEAR_ARRAY(m_aItems
);
389 #endif // wxUSE_OWNER_DRAWN
390 if ( HasClientObjectData() )
392 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
394 delete GetClientObject(n
);
399 void wxListBox::SetSelection(int N
, bool select
)
401 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
402 wxT("invalid index in wxListBox::SetSelection") );
404 if ( HasMultipleSelection() )
406 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
410 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
414 bool wxListBox::IsSelected(int N
) const
416 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
417 wxT("invalid index in wxListBox::Selected") );
419 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? FALSE
: TRUE
;
422 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
424 return (wxClientData
*)DoGetItemClientData(n
);
427 void *wxListBox::DoGetItemClientData(int n
) const
429 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
430 wxT("invalid index in wxListBox::GetClientData") );
432 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
435 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
437 DoSetItemClientData(n
, clientData
);
440 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
442 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
443 wxT("invalid index in wxListBox::SetClientData") );
445 #if wxUSE_OWNER_DRAWN
446 if ( m_windowStyle
& wxLB_OWNERDRAW
)
448 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
449 // in OnMeasure/OnDraw.
450 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
452 #endif // wxUSE_OWNER_DRAWN
454 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
455 wxLogDebug(wxT("LB_SETITEMDATA failed"));
458 // Return number of selections and an array of selected integers
459 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
463 if ( HasMultipleSelection() )
465 int countSel
= ListBox_GetSelCount(GetHwnd());
466 if ( countSel
== LB_ERR
)
468 wxLogDebug(_T("ListBox_GetSelCount failed"));
470 else if ( countSel
!= 0 )
472 int *selections
= new int[countSel
];
474 if ( ListBox_GetSelItems(GetHwnd(),
475 countSel
, selections
) == LB_ERR
)
477 wxLogDebug(wxT("ListBox_GetSelItems failed"));
482 aSelections
.Alloc(countSel
);
483 for ( int n
= 0; n
< countSel
; n
++ )
484 aSelections
.Add(selections
[n
]);
487 delete [] selections
;
492 else // single-selection listbox
494 if (ListBox_GetCurSel(GetHwnd()) > -1)
495 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
497 return aSelections
.Count();
501 // Get single selection, for single choice list items
502 int wxListBox::GetSelection() const
504 wxCHECK_MSG( !HasMultipleSelection(),
506 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
508 return ListBox_GetCurSel(GetHwnd());
511 // Find string for position
512 wxString
wxListBox::GetString(int N
) const
514 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
515 wxT("invalid index in wxListBox::GetClientData") );
517 int len
= ListBox_GetTextLen(GetHwnd(), N
);
519 // +1 for terminating NUL
521 ListBox_GetText(GetHwnd(), N
, wxStringBuffer(result
, len
+ 1));
527 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
529 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
530 wxT("invalid index in wxListBox::InsertItems") );
532 int nItems
= items
.GetCount();
533 for ( int i
= 0; i
< nItems
; i
++ )
535 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
537 #if wxUSE_OWNER_DRAWN
538 if ( m_windowStyle
& wxLB_OWNERDRAW
)
540 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
541 pNewItem
->SetName(items
[i
]);
542 pNewItem
->SetFont(GetFont());
543 m_aItems
.Insert(pNewItem
, idx
);
545 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
547 #endif // wxUSE_OWNER_DRAWN
552 SetHorizontalExtent();
555 void wxListBox::SetString(int N
, const wxString
& s
)
557 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
558 wxT("invalid index in wxListBox::SetString") );
560 // remember the state of the item
561 bool wasSelected
= IsSelected(N
);
563 void *oldData
= NULL
;
564 wxClientData
*oldObjData
= NULL
;
565 if ( m_clientDataItemsType
== wxClientData_Void
)
566 oldData
= GetClientData(N
);
567 else if ( m_clientDataItemsType
== wxClientData_Object
)
568 oldObjData
= GetClientObject(N
);
570 // delete and recreate it
571 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
574 if ( N
== m_noItems
- 1 )
577 ListBox_InsertString(GetHwnd(), newN
, s
);
579 // restore the client data
581 SetClientData(N
, oldData
);
582 else if ( oldObjData
)
583 SetClientObject(N
, oldObjData
);
585 // we may have lost the selection
589 #if wxUSE_OWNER_DRAWN
590 if ( m_windowStyle
& wxLB_OWNERDRAW
)
592 // update item's text
593 m_aItems
[N
]->SetName(s
);
595 // reassign the item's data
596 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
598 #endif //USE_OWNER_DRAWN
601 int wxListBox::GetCount() const
606 // ----------------------------------------------------------------------------
608 // ----------------------------------------------------------------------------
610 // Windows-specific code to set the horizontal extent of the listbox, if
611 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
612 // Otherwise, all strings are used.
613 void wxListBox::SetHorizontalExtent(const wxString
& s
)
615 // Only necessary if we want a horizontal scrollbar
616 if (!(m_windowStyle
& wxHSCROLL
))
618 TEXTMETRIC lpTextMetric
;
622 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
623 HDC dc
= GetWindowDC(GetHwnd());
625 if (GetFont().Ok() && GetFont().GetResourceHandle())
626 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
628 GetTextMetrics(dc
, &lpTextMetric
);
630 ::GetTextExtentPoint(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
631 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
634 ::SelectObject(dc
, oldFont
);
636 ReleaseDC(GetHwnd(), dc
);
637 if (extentX
> existingExtent
)
638 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
642 int largestExtent
= 0;
643 HDC dc
= GetWindowDC(GetHwnd());
645 if (GetFont().Ok() && GetFont().GetResourceHandle())
646 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
648 GetTextMetrics(dc
, &lpTextMetric
);
650 // FIXME: buffer overflow!!
652 for (int i
= 0; i
< m_noItems
; i
++)
654 int len
= (int)SendMessage(GetHwnd(), LB_GETTEXT
, i
, (LPARAM
)buf
);
657 ::GetTextExtentPoint(dc
, buf
, len
, &extentXY
);
658 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
659 if (extentX
> largestExtent
)
660 largestExtent
= extentX
;
663 ::SelectObject(dc
, oldFont
);
665 ReleaseDC(GetHwnd(), dc
);
666 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
670 wxSize
wxListBox::DoGetBestSize() const
672 // find the widest string
675 for ( int i
= 0; i
< m_noItems
; i
++ )
677 wxString
str(GetString(i
));
678 GetTextExtent(str
, &wLine
, NULL
);
679 if ( wLine
> wListbox
)
683 // give it some reasonable default value if there are no strings in the
688 // the listbox should be slightly larger than the widest string
690 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
694 // don't make the listbox too tall (limit height to 10 items) but don't
695 // make it too small neither
696 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
697 wxMin(wxMax(m_noItems
, 3), 10);
699 return wxSize(wListbox
, hListbox
);
702 // ----------------------------------------------------------------------------
704 // ----------------------------------------------------------------------------
706 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
709 if ( param
== LBN_SELCHANGE
)
711 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
713 else if ( param
== LBN_DBLCLK
)
715 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
719 // some event we're not interested in
723 wxCommandEvent
event(evtType
, m_windowId
);
724 event
.SetEventObject( this );
726 // retrieve the affected item
727 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
730 if ( HasClientObjectData() )
731 event
.SetClientObject( GetClientObject(n
) );
732 else if ( HasClientUntypedData() )
733 event
.SetClientData( GetClientData(n
) );
735 event
.SetString( GetString(n
) );
736 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : TRUE
);
739 event
.m_commandInt
= n
;
741 return GetEventHandler()->ProcessEvent(event
);
744 // ----------------------------------------------------------------------------
745 // wxCheckListBox support
746 // ----------------------------------------------------------------------------
748 #if wxUSE_OWNER_DRAWN
753 // space beneath/above each row in pixels
754 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
755 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
757 // the height is the same for all items
758 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
760 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
761 // message is not yet sent when we get here!
762 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
764 // only owner-drawn control should receive this message
765 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), FALSE
);
767 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
770 HDC hdc
= GetDC(NULL
);
772 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
776 dc
.SetHDC((WXHDC
)hdc
);
777 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT
));
779 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
780 pStruct
->itemWidth
= dc
.GetCharWidth();
789 // forward the message to the appropriate item
790 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
792 // only owner-drawn control should receive this message
793 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), FALSE
);
795 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
796 UINT itemID
= pStruct
->itemID
;
798 // the item may be -1 for an empty listbox
799 if ( itemID
== (UINT
)-1 )
802 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
804 wxCHECK( data
&& (data
!= LB_ERR
), FALSE
);
806 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
808 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
809 wxRect
rect(wxPoint(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
),
810 wxPoint(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
));
812 return pItem
->OnDrawItem(dc
, rect
,
813 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
814 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
817 #endif // wxUSE_OWNER_DRAWN
819 #endif // wxUSE_LISTBOX