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 wxListBox::wxListBox(wxWindow
*parent
,
163 const wxString choices
[],
165 const wxValidator
& validator
,
166 const wxString
& name
)
168 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
171 bool wxListBox::Create(wxWindow
*parent
,
175 int n
, const wxString choices
[],
177 const wxValidator
& wxVALIDATOR_PARAM(validator
),
178 const wxString
& name
)
186 SetValidator(validator
);
187 #endif // wxUSE_VALIDATORS
190 parent
->AddChild(this);
192 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
193 SetForegroundColour(parent
->GetForegroundColour());
195 m_windowId
= ( id
== -1 ) ? (int)NewControlId() : id
;
201 m_windowStyle
= style
;
203 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_VSCROLL
| WS_TABSTOP
|
204 LBS_NOTIFY
| LBS_HASSTRINGS
;
206 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
207 _T("only one of listbox selection modes can be specified") );
209 if ( (m_windowStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
210 m_windowStyle
|= wxBORDER_SUNKEN
;
212 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
213 wstyle
|= WS_CLIPSIBLINGS
;
215 if (m_windowStyle
& wxLB_MULTIPLE
)
216 wstyle
|= LBS_MULTIPLESEL
;
217 else if (m_windowStyle
& wxLB_EXTENDED
)
218 wstyle
|= LBS_EXTENDEDSEL
;
220 if (m_windowStyle
& wxLB_ALWAYS_SB
)
221 wstyle
|= LBS_DISABLENOSCROLL
;
222 if (m_windowStyle
& wxLB_HSCROLL
)
223 wstyle
|= WS_HSCROLL
;
224 if (m_windowStyle
& wxLB_SORT
)
227 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
228 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
229 // we don't support LBS_OWNERDRAWVARIABLE yet
230 wstyle
|= LBS_OWNERDRAWFIXED
;
234 // Without this style, you get unexpected heights, so e.g. constraint layout
235 // doesn't work properly
236 wstyle
|= LBS_NOINTEGRALHEIGHT
;
239 (void) MSWGetStyle(m_windowStyle
, & exStyle
) ;
241 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, wxT("LISTBOX"), NULL
,
244 (HWND
)parent
->GetHWND(), (HMENU
)m_windowId
,
245 wxGetInstance(), NULL
);
247 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create listbox") );
249 // Subclass again to catch messages
253 for (ui
= 0; ui
< (size_t)n
; ui
++) {
257 if ( (m_windowStyle
& wxLB_MULTIPLE
) == 0 )
258 SendMessage(GetHwnd(), LB_SETCURSEL
, 0, 0);
260 SetFont(parent
->GetFont());
262 SetSize(x
, y
, width
, height
);
267 wxListBox::~wxListBox()
272 void wxListBox::SetupColours()
274 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
275 SetForegroundColour(GetParent()->GetForegroundColour());
278 // ----------------------------------------------------------------------------
279 // implementation of wxListBoxBase methods
280 // ----------------------------------------------------------------------------
282 void wxListBox::DoSetFirstItem(int N
)
284 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
285 wxT("invalid index in wxListBox::SetFirstItem") );
287 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
290 void wxListBox::Delete(int N
)
292 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
293 wxT("invalid index in wxListBox::Delete") );
295 // for owner drawn objects, the data is used for storing wxOwnerDrawn
296 // pointers and we shouldn't touch it
297 #if !wxUSE_OWNER_DRAWN
298 if ( !(m_windowStyle
& wxLB_OWNERDRAW
) )
299 #endif // !wxUSE_OWNER_DRAWN
300 if ( HasClientObjectData() )
302 delete GetClientObject(N
);
305 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
308 SetHorizontalExtent(wxEmptyString
);
311 int wxListBox::DoAppend(const wxString
& item
)
313 int index
= ListBox_AddString(GetHwnd(), item
);
316 #if wxUSE_OWNER_DRAWN
317 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
318 wxOwnerDrawn
*pNewItem
= CreateLboxItem(index
); // dummy argument
319 pNewItem
->SetName(item
);
320 m_aItems
.Insert(pNewItem
, index
);
321 ListBox_SetItemData(GetHwnd(), index
, pNewItem
);
322 pNewItem
->SetFont(GetFont());
324 #endif // wxUSE_OWNER_DRAWN
326 SetHorizontalExtent(item
);
331 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
333 // avoid flicker - but don't need to do this for a hidden listbox
334 bool hideAndShow
= IsShown();
337 ShowWindow(GetHwnd(), SW_HIDE
);
340 ListBox_ResetContent(GetHwnd());
342 m_noItems
= choices
.GetCount();
344 for (i
= 0; i
< m_noItems
; i
++)
346 ListBox_AddString(GetHwnd(), choices
[i
]);
349 SetClientData(i
, clientData
[i
]);
353 #if wxUSE_OWNER_DRAWN
354 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
355 // first delete old items
356 WX_CLEAR_ARRAY(m_aItems
);
358 // then create new ones
359 for ( size_t ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
360 wxOwnerDrawn
*pNewItem
= CreateLboxItem(ui
);
361 pNewItem
->SetName(choices
[ui
]);
362 m_aItems
.Add(pNewItem
);
363 ListBox_SetItemData(GetHwnd(), ui
, pNewItem
);
366 #endif // wxUSE_OWNER_DRAWN
368 SetHorizontalExtent();
372 // show the listbox back if we hid it
373 ShowWindow(GetHwnd(), SW_SHOW
);
377 int wxListBox::FindString(const wxString
& s
) const
379 int pos
= ListBox_FindStringExact(GetHwnd(), (WPARAM
)-1, s
);
386 void wxListBox::Clear()
390 ListBox_ResetContent(GetHwnd());
393 SetHorizontalExtent();
396 void wxListBox::Free()
398 #if wxUSE_OWNER_DRAWN
399 if ( m_windowStyle
& wxLB_OWNERDRAW
)
401 WX_CLEAR_ARRAY(m_aItems
);
404 #endif // wxUSE_OWNER_DRAWN
405 if ( HasClientObjectData() )
407 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
409 delete GetClientObject(n
);
414 void wxListBox::SetSelection(int N
, bool select
)
416 wxCHECK_RET( N
== wxNOT_FOUND
||
417 (N
>= 0 && N
< m_noItems
),
418 wxT("invalid index in wxListBox::SetSelection") );
420 if ( HasMultipleSelection() )
422 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
426 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
430 bool wxListBox::IsSelected(int N
) const
432 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
433 wxT("invalid index in wxListBox::Selected") );
435 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? FALSE
: TRUE
;
438 wxClientData
* wxListBox::DoGetItemClientObject(int n
) const
440 return (wxClientData
*)DoGetItemClientData(n
);
443 void *wxListBox::DoGetItemClientData(int n
) const
445 wxCHECK_MSG( n
>= 0 && n
< m_noItems
, NULL
,
446 wxT("invalid index in wxListBox::GetClientData") );
448 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
451 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
453 DoSetItemClientData(n
, clientData
);
456 void wxListBox::DoSetItemClientData(int n
, void *clientData
)
458 wxCHECK_RET( n
>= 0 && n
< m_noItems
,
459 wxT("invalid index in wxListBox::SetClientData") );
461 #if wxUSE_OWNER_DRAWN
462 if ( m_windowStyle
& wxLB_OWNERDRAW
)
464 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
465 // in OnMeasure/OnDraw.
466 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
468 #endif // wxUSE_OWNER_DRAWN
470 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
471 wxLogDebug(wxT("LB_SETITEMDATA failed"));
474 // Return number of selections and an array of selected integers
475 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
479 if ( HasMultipleSelection() )
481 int countSel
= ListBox_GetSelCount(GetHwnd());
482 if ( countSel
== LB_ERR
)
484 wxLogDebug(_T("ListBox_GetSelCount failed"));
486 else if ( countSel
!= 0 )
488 int *selections
= new int[countSel
];
490 if ( ListBox_GetSelItems(GetHwnd(),
491 countSel
, selections
) == LB_ERR
)
493 wxLogDebug(wxT("ListBox_GetSelItems failed"));
498 aSelections
.Alloc(countSel
);
499 for ( int n
= 0; n
< countSel
; n
++ )
500 aSelections
.Add(selections
[n
]);
503 delete [] selections
;
508 else // single-selection listbox
510 if (ListBox_GetCurSel(GetHwnd()) > -1)
511 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
513 return aSelections
.Count();
517 // Get single selection, for single choice list items
518 int wxListBox::GetSelection() const
520 wxCHECK_MSG( !HasMultipleSelection(),
522 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
524 return ListBox_GetCurSel(GetHwnd());
527 // Find string for position
528 wxString
wxListBox::GetString(int N
) const
530 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
531 wxT("invalid index in wxListBox::GetClientData") );
533 int len
= ListBox_GetTextLen(GetHwnd(), N
);
535 // +1 for terminating NUL
537 ListBox_GetText(GetHwnd(), N
, wxStringBuffer(result
, len
+ 1));
543 wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
545 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
546 wxT("invalid index in wxListBox::InsertItems") );
548 int nItems
= items
.GetCount();
549 for ( int i
= 0; i
< nItems
; i
++ )
551 int idx
= ListBox_InsertString(GetHwnd(), i
+ pos
, items
[i
]);
553 #if wxUSE_OWNER_DRAWN
554 if ( m_windowStyle
& wxLB_OWNERDRAW
)
556 wxOwnerDrawn
*pNewItem
= CreateLboxItem(idx
);
557 pNewItem
->SetName(items
[i
]);
558 pNewItem
->SetFont(GetFont());
559 m_aItems
.Insert(pNewItem
, idx
);
561 ListBox_SetItemData(GetHwnd(), idx
, pNewItem
);
563 #endif // wxUSE_OWNER_DRAWN
568 SetHorizontalExtent();
571 void wxListBox::SetString(int N
, const wxString
& s
)
573 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
574 wxT("invalid index in wxListBox::SetString") );
576 // remember the state of the item
577 bool wasSelected
= IsSelected(N
);
579 void *oldData
= NULL
;
580 wxClientData
*oldObjData
= NULL
;
581 if ( m_clientDataItemsType
== wxClientData_Void
)
582 oldData
= GetClientData(N
);
583 else if ( m_clientDataItemsType
== wxClientData_Object
)
584 oldObjData
= GetClientObject(N
);
586 // delete and recreate it
587 SendMessage(GetHwnd(), LB_DELETESTRING
, N
, 0);
590 if ( N
== m_noItems
- 1 )
593 ListBox_InsertString(GetHwnd(), newN
, s
);
595 // restore the client data
597 SetClientData(N
, oldData
);
598 else if ( oldObjData
)
599 SetClientObject(N
, oldObjData
);
601 // we may have lost the selection
605 #if wxUSE_OWNER_DRAWN
606 if ( m_windowStyle
& wxLB_OWNERDRAW
)
608 // update item's text
609 m_aItems
[N
]->SetName(s
);
611 // reassign the item's data
612 ListBox_SetItemData(GetHwnd(), N
, m_aItems
[N
]);
614 #endif //USE_OWNER_DRAWN
617 int wxListBox::GetCount() const
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
626 // Windows-specific code to set the horizontal extent of the listbox, if
627 // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
628 // Otherwise, all strings are used.
629 void wxListBox::SetHorizontalExtent(const wxString
& s
)
631 // Only necessary if we want a horizontal scrollbar
632 if (!(m_windowStyle
& wxHSCROLL
))
634 TEXTMETRIC lpTextMetric
;
638 int existingExtent
= (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT
, 0, 0L);
639 HDC dc
= GetWindowDC(GetHwnd());
641 if (GetFont().Ok() && GetFont().GetResourceHandle())
642 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
644 GetTextMetrics(dc
, &lpTextMetric
);
646 ::GetTextExtentPoint(dc
, (LPTSTR
) (const wxChar
*)s
, s
.Length(), &extentXY
);
647 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
650 ::SelectObject(dc
, oldFont
);
652 ReleaseDC(GetHwnd(), dc
);
653 if (extentX
> existingExtent
)
654 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(extentX
), 0L);
658 int largestExtent
= 0;
659 HDC dc
= GetWindowDC(GetHwnd());
661 if (GetFont().Ok() && GetFont().GetResourceHandle())
662 oldFont
= (HFONT
) ::SelectObject(dc
, (HFONT
) GetFont().GetResourceHandle());
664 GetTextMetrics(dc
, &lpTextMetric
);
666 // FIXME: buffer overflow!!
668 for (int i
= 0; i
< m_noItems
; i
++)
670 int len
= (int)SendMessage(GetHwnd(), LB_GETTEXT
, i
, (LPARAM
)buf
);
673 ::GetTextExtentPoint(dc
, buf
, len
, &extentXY
);
674 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
675 if (extentX
> largestExtent
)
676 largestExtent
= extentX
;
679 ::SelectObject(dc
, oldFont
);
681 ReleaseDC(GetHwnd(), dc
);
682 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
686 wxSize
wxListBox::DoGetBestSize() const
688 // find the widest string
691 for ( int i
= 0; i
< m_noItems
; i
++ )
693 wxString
str(GetString(i
));
694 GetTextExtent(str
, &wLine
, NULL
);
695 if ( wLine
> wListbox
)
699 // give it some reasonable default value if there are no strings in the
704 // the listbox should be slightly larger than the widest string
706 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
710 // don't make the listbox too tall (limit height to 10 items) but don't
711 // make it too small neither
712 int hListbox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
)*
713 wxMin(wxMax(m_noItems
, 3), 10);
715 return wxSize(wListbox
, hListbox
);
718 // ----------------------------------------------------------------------------
720 // ----------------------------------------------------------------------------
722 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
725 if ( param
== LBN_SELCHANGE
)
727 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
729 else if ( param
== LBN_DBLCLK
)
731 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
735 // some event we're not interested in
739 wxCommandEvent
event(evtType
, m_windowId
);
740 event
.SetEventObject( this );
742 // retrieve the affected item
743 int n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
746 if ( HasClientObjectData() )
747 event
.SetClientObject( GetClientObject(n
) );
748 else if ( HasClientUntypedData() )
749 event
.SetClientData( GetClientData(n
) );
751 event
.SetString( GetString(n
) );
752 event
.SetExtraLong( HasMultipleSelection() ? IsSelected(n
) : TRUE
);
755 event
.m_commandInt
= n
;
757 return GetEventHandler()->ProcessEvent(event
);
760 // ----------------------------------------------------------------------------
761 // wxCheckListBox support
762 // ----------------------------------------------------------------------------
764 #if wxUSE_OWNER_DRAWN
769 // space beneath/above each row in pixels
770 // "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
771 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
773 // the height is the same for all items
774 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
776 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
777 // message is not yet sent when we get here!
778 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
780 // only owner-drawn control should receive this message
781 wxCHECK( ((m_windowStyle
& wxLB_OWNERDRAW
) == wxLB_OWNERDRAW
), FALSE
);
783 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
786 HDC hdc
= GetDC(NULL
);
788 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
792 dc
.SetHDC((WXHDC
)hdc
);
793 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT
));
795 pStruct
->itemHeight
= dc
.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE
;
796 pStruct
->itemWidth
= dc
.GetCharWidth();
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 wxRect
rect(wxPoint(pStruct
->rcItem
.left
, pStruct
->rcItem
.top
),
826 wxPoint(pStruct
->rcItem
.right
, pStruct
->rcItem
.bottom
));
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