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
, , 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
,, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
100 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 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
& wxVALIDATOR_PARAM(validator
),
165 const wxString
& name
)
173 SetValidator(validator
);
174 #endif // wxUSE_VALIDATORS
177 parent
->AddChild(this);
179 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
180 SetForegroundColour(parent
->GetForegroundColour());
182 m_windowId
= ( id
== -1 ) ? (int)NewControlId() : id
;
188 m_windowStyle
= style
;
190 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_VSCROLL
| WS_TABSTOP
|
191 LBS_NOTIFY
| LBS_HASSTRINGS
;
193 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
194 _T("only one of listbox selection modes can be specified") );
196 if ( (m_windowStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
197 m_windowStyle
|= wxBORDER_SUNKEN
;
199 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
200 wstyle
|= WS_CLIPSIBLINGS
;
202 if (m_windowStyle
& wxLB_MULTIPLE
)
203 wstyle
|= LBS_MULTIPLESEL
;
204 else if (m_windowStyle
& wxLB_EXTENDED
)
205 wstyle
|= LBS_EXTENDEDSEL
;
207 if (m_windowStyle
& wxLB_ALWAYS_SB
)
208 wstyle
|= LBS_DISABLENOSCROLL
;
209 if (m_windowStyle
& wxLB_HSCROLL
)
210 wstyle
|= WS_HSCROLL
;
211 if (m_windowStyle
& wxLB_SORT
)
214 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
215 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
216 // we don't support LBS_OWNERDRAWVARIABLE yet
217 wstyle
|= LBS_OWNERDRAWFIXED
;
221 // Without this style, you get unexpected heights, so e.g. constraint layout
222 // doesn't work properly
223 wstyle
|= LBS_NOINTEGRALHEIGHT
;
226 (void) MSWGetStyle(m_windowStyle
, & exStyle
) ;
228 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, wxT("LISTBOX"), NULL
,
231 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
232 wxGetInstance(), NULL
);
234 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create listbox") );
236 // Subclass again to catch messages
240 for (ui
= 0; ui
< (size_t)n
; ui
++) {
244 if ( (m_windowStyle
& wxLB_MULTIPLE
) == 0 )
245 SendMessage(GetHwnd(), LB_SETCURSEL
, 0, 0);
247 SetFont(parent
->GetFont());
249 SetSize(x
, y
, width
, height
);
254 wxListBox::~wxListBox()
259 void wxListBox::SetupColours()
261 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
262 SetForegroundColour(GetParent()->GetForegroundColour());
265 // ----------------------------------------------------------------------------
266 // implementation of wxListBoxBase methods
267 // ----------------------------------------------------------------------------
269 void wxListBox::DoSetFirstItem(int N
)
271 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
272 wxT("invalid index in wxListBox::SetFirstItem") );
274 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
277 void wxListBox::Delete(int N
)
279 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
280 wxT("invalid index in wxListBox::Delete") );
282 // for owner drawn objects, the data is used for storing wxOwnerDrawn
283 // pointers and we shouldn't touch it
284 #if !wxUSE_OWNER_DRAWN
285 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
286 #endif // !wxUSE_OWNER_DRAWN
287 if ( HasClientObjectData() )
289 delete GetClientObject(N
);
292 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
295 SetHorizontalExtent(wxEmptyString
);
298 int wxListBox::DoAppend(const wxString
& item
)
300 int index
= ListBox_AddString(GetHwnd(), item
);
303 #if wxUSE_OWNER_DRAWN
304 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
305 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
306 pNewItem
->SetName(item
);
307 m_aItems
.Insert(pNewItem
, index
);
308 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
309 pNewItem
->SetFont(GetFont());
311 #endif // wxUSE_OWNER_DRAWN
313 SetHorizontalExtent(item
);
318 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
320 // avoid flicker - but don't need to do this for a hidden listbox
321 bool hideAndShow
= IsShown();
324 ShowWindow(GetHwnd(), SW_HIDE
);
327 ListBox_ResetContent(GetHwnd());
329 m_noItems
= choices
.GetCount();
331 for (i
= 0; i
< m_noItems
; i
++)
333 ListBox_AddString(GetHwnd(), choices
[i
]);
336 SetClientData(i
, clientData
[i
]);
340 #if wxUSE_OWNER_DRAWN
341 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
342 // first delete old items
343 WX_CLEAR_ARRAY(m_aItems
);
345 // then create new ones
346 for ( size_t ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
347 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
348 pNewItem
->SetName(choices
[ui
]);
349 m_aItems
.Add(pNewItem
);
350 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
353 #endif // wxUSE_OWNER_DRAWN
355 SetHorizontalExtent();
359 // show the listbox back if we hid it
360 ShowWindow(GetHwnd(), SW_SHOW
);
364 int wxListBox::FindString(const wxString
& s
) const
366 int pos
= ListBox_FindStringExact(GetHwnd(), (WPARAM
)-1, s
);
373 void wxListBox::Clear()
377 ListBox_ResetContent(GetHwnd());
380 SetHorizontalExtent();
383 void wxListBox::Free()
385 #if wxUSE_OWNER_DRAWN
386 if ( m_windowStyle
& wxLB_OWNERDRAW
)
388 WX_CLEAR_ARRAY(m_aItems
);
391 #endif // wxUSE_OWNER_DRAWN
392 if ( HasClientObjectData() )
394 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
396 delete GetClientObject(n
);
401 void wxListBox::SetSelection(int N
, bool select
)
403 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
404 wxT("invalid index in wxListBox::SetSelection") );
406 if ( HasMultipleSelection() )
408 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
412 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
416 bool wxListBox::IsSelected(int N
) const
418 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
419 wxT("invalid index in wxListBox::Selected") );
421 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? FALSE
: TRUE
;
424 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
426 return (wxClientData
*)DoGetItemClientData(n
);
429 void *wxListBox::DoGetItemClientData(int n
) const
431 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
432 wxT("invalid index in wxListBox::GetClientData") );
434 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
437 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
439 DoSetItemClientData(n
, clientData
);
442 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
444 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
445 wxT("invalid index in wxListBox::SetClientData") );
447 #if wxUSE_OWNER_DRAWN
448 if ( m_windowStyle
& wxLB_OWNERDRAW
)
450 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
451 // in OnMeasure/OnDraw.
452 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
454 #endif // wxUSE_OWNER_DRAWN
456 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
457 wxLogDebug(wxT("LB_SETITEMDATA failed"));
460 // Return number of selections and an array of selected integers
461 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
465 if ( HasMultipleSelection() )
467 int countSel
= ListBox_GetSelCount(GetHwnd());
468 if ( countSel
== LB_ERR
)
470 wxLogDebug(_T("ListBox_GetSelCount failed"));
472 else if ( countSel
!= 0 )
474 int *selections
= new int[countSel
];
476 if ( ListBox_GetSelItems(GetHwnd(),
477 countSel
, selections
) == LB_ERR
)
479 wxLogDebug(wxT("ListBox_GetSelItems failed"));
484 aSelections
.Alloc(countSel
);
485 for ( int n
= 0; n
< countSel
; n
++ )
486 aSelections
.Add(selections
[n
]);
489 delete [] selections
;
494 else // single-selection listbox
496 if (ListBox_GetCurSel(GetHwnd()) > -1)
497 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
499 return aSelections
.Count();
503 // Get single selection, for single choice list items
504 int wxListBox::GetSelection() const
506 wxCHECK_MSG( !HasMultipleSelection(),
508 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
510 return ListBox_GetCurSel(GetHwnd());
513 // Find string for position
514 wxString
wxListBox::GetString(int N
) const
516 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
517 wxT("invalid index in wxListBox::GetClientData") );
519 int len
= ListBox_GetTextLen(GetHwnd(), N
);
521 // +1 for terminating NUL
523 ListBox_GetText(GetHwnd(), N
, wxStringBuffer(result
, len
+ 1));
529 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
531 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
532 wxT("invalid index in wxListBox::InsertItems") );
534 int nItems
= items
.GetCount();
535 for ( int i
= 0; i
< nItems
; i
++ )
537 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
539 #if wxUSE_OWNER_DRAWN
540 if ( m_windowStyle
& wxLB_OWNERDRAW
)
542 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
543 pNewItem
->SetName(items
[i
]);
544 pNewItem
->SetFont(GetFont());
545 m_aItems
.Insert(pNewItem
, idx
);
547 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
549 #endif // wxUSE_OWNER_DRAWN
554 SetHorizontalExtent();
557 void wxListBox::SetString(int N
, const wxString
& s
)
559 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
560 wxT("invalid index in wxListBox::SetString") );
562 // remember the state of the item
563 bool wasSelected
= IsSelected(N
);
565 void *oldData
= NULL
;
566 wxClientData
*oldObjData
= NULL
;
567 if ( m_clientDataItemsType
== wxClientData_Void
)
568 oldData
= GetClientData(N
);
569 else if ( m_clientDataItemsType
== wxClientData_Object
)
570 oldObjData
= GetClientObject(N
);
572 // delete and recreate it
573 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
576 if ( N
== m_noItems
- 1 )
579 ListBox_InsertString(GetHwnd(), newN
, s
);
581 // restore the client data
583 SetClientData(N
, oldData
);
584 else if ( oldObjData
)
585 SetClientObject(N
, oldObjData
);
587 // we may have lost the selection
591 #if wxUSE_OWNER_DRAWN
592 if ( m_windowStyle
& wxLB_OWNERDRAW
)
594 // update item's text
595 m_aItems
[N
]->SetName(s
);
597 // reassign the item's data
598 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
600 #endif //USE_OWNER_DRAWN
603 int wxListBox::GetCount() const
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
612 // Windows-specific code to set the horizontal extent of the listbox, if
613 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
614 // Otherwise, all strings are used.
615 void wxListBox::SetHorizontalExtent(const wxString
& s
)
617 // Only necessary if we want a horizontal scrollbar
618 if (!(m_windowStyle
& wxHSCROLL
))
620 TEXTMETRIC lpTextMetric
;
624 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
625 HDC dc
= GetWindowDC(GetHwnd());
627 if (GetFont().Ok() && GetFont().GetResourceHandle())
628 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
630 GetTextMetrics(dc
, &lpTextMetric
);
632 ::GetTextExtentPoint(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
633 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
636 ::SelectObject(dc
, oldFont
);
638 ReleaseDC(GetHwnd(), dc
);
639 if (extentX
> existingExtent
)
640 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
644 int largestExtent
= 0;
645 HDC dc
= GetWindowDC(GetHwnd());
647 if (GetFont().Ok() && GetFont().GetResourceHandle())
648 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
650 GetTextMetrics(dc
, &lpTextMetric
);
652 // FIXME: buffer overflow!!
654 for (int i
= 0; i
< m_noItems
; i
++)
656 int len
= (int)SendMessage(GetHwnd(), LB_GETTEXT
, i
, (LPARAM
)buf
);
659 ::GetTextExtentPoint(dc
, buf
, len
, &extentXY
);
660 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
661 if (extentX
> largestExtent
)
662 largestExtent
= extentX
;
665 ::SelectObject(dc
, oldFont
);
667 ReleaseDC(GetHwnd(), dc
);
668 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
672 wxSize
wxListBox::DoGetBestSize() const
674 // find the widest string
677 for ( int i
= 0; i
< m_noItems
; i
++ )
679 wxString
str(GetString(i
));
680 GetTextExtent(str
, &wLine
, NULL
);
681 if ( wLine
> wListbox
)
685 // give it some reasonable default value if there are no strings in the
690 // the listbox should be slightly larger than the widest string
692 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
696 // don't make the listbox too tall (limit height to 10 items) but don't
697 // make it too small neither
698 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
699 wxMin(wxMax(m_noItems
, 3), 10);
701 return wxSize(wListbox
, hListbox
);
704 // ----------------------------------------------------------------------------
706 // ----------------------------------------------------------------------------
708 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
711 if ( param
== LBN_SELCHANGE
)
713 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
715 else if ( param
== LBN_DBLCLK
)
717 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
721 // some event we're not interested in
725 wxCommandEvent
event(evtType
, m_windowId
);
726 event
.SetEventObject( this );
728 // retrieve the affected item
729 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
732 if ( HasClientObjectData() )
733 event
.SetClientObject( GetClientObject(n
) );
734 else if ( HasClientUntypedData() )
735 event
.SetClientData( GetClientData(n
) );
737 event
.SetString( GetString(n
) );
738 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : TRUE
);
741 event
.m_commandInt
= n
;
743 return GetEventHandler()->ProcessEvent(event
);
746 // ----------------------------------------------------------------------------
747 // wxCheckListBox support
748 // ----------------------------------------------------------------------------
750 #if wxUSE_OWNER_DRAWN
755 // space beneath/above each row in pixels
756 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
757 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
759 // the height is the same for all items
760 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
762 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
763 // message is not yet sent when we get here!
764 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
766 // only owner-drawn control should receive this message
767 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), FALSE
);
769 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
772 HDC hdc
= GetDC(NULL
);
774 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
778 dc
.SetHDC((WXHDC
)hdc
);
779 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT
));
781 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
782 pStruct
->itemWidth
= dc
.GetCharWidth();
791 // forward the message to the appropriate item
792 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
794 // only owner-drawn control should receive this message
795 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), FALSE
);
797 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
798 UINT itemID
= pStruct
->itemID
;
800 // the item may be -1 for an empty listbox
801 if ( itemID
== (UINT
)-1 )
804 long data
= ListBox_GetItemData(GetHwnd(), pStruct
->itemID
);
806 wxCHECK( data
&& (data
!= LB_ERR
), FALSE
);
808 wxListBoxItem
*pItem
= (wxListBoxItem
*)data
;
810 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
811 wxRect
rect(wxPoint(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
),
812 wxPoint(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
));
814 return pItem
->OnDrawItem(dc
, rect
,
815 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
816 (wxOwnerDrawn::wxODStatus
)pStruct
->itemState
);
819 #endif // wxUSE_OWNER_DRAWN
821 #endif // wxUSE_LISTBOX