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"
21 #include "wx/listbox.h"
24 #include "wx/dynarray.h"
25 #include "wx/settings.h"
31 #include "wx/window.h"
34 #include "wx/msw/private.h"
35 #include "wx/msw/dc.h"
40 #include "wx/ownerdrw.h"
43 #if wxUSE_EXTENDED_RTTI
44 WX_DEFINE_FLAGS( wxListBoxStyle
)
46 wxBEGIN_FLAGS( wxListBoxStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxLB_SINGLE
)
75 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
76 wxFLAGS_MEMBER(wxLB_EXTENDED
)
77 wxFLAGS_MEMBER(wxLB_HSCROLL
)
78 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
79 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
80 wxFLAGS_MEMBER(wxLB_NO_SB
)
81 wxFLAGS_MEMBER(wxLB_SORT
)
83 wxEND_FLAGS( wxListBoxStyle
)
85 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox
, wxControlWithItems
,"wx/listbox.h")
87 wxBEGIN_PROPERTIES_TABLE(wxListBox
)
88 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
89 wxEVENT_PROPERTY( DoubleClick
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
91 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
92 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, GetStrings
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
93 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
94 wxPROPERTY_FLAGS( WindowStyle
, wxListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
95 wxEND_PROPERTIES_TABLE()
97 wxBEGIN_HANDLERS_TABLE(wxListBox
)
98 wxEND_HANDLERS_TABLE()
100 wxCONSTRUCTOR_4( wxListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
102 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControlWithItems
)
112 // ============================================================================
113 // list box item declaration and implementation
114 // ============================================================================
116 #if wxUSE_OWNER_DRAWN
118 class wxListBoxItem
: public wxOwnerDrawn
121 wxListBoxItem(wxListBox
*parent
)
122 { m_parent
= parent
; }
124 wxListBox
*GetParent() const
128 { return m_parent
->GetItemIndex(const_cast<wxListBoxItem
*>(this)); }
130 wxString
GetName() const
131 { return m_parent
->GetString(GetIndex()); }
137 wxOwnerDrawn
*wxListBox::CreateLboxItem(size_t WXUNUSED(n
))
139 return new wxListBoxItem(this);
142 #endif //USE_OWNER_DRAWN
144 // ============================================================================
145 // list box control implementation
146 // ============================================================================
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 void wxListBox::Init()
155 m_updateHorizontalExtent
= false;
156 m_selectedByKeyboard
= false;
159 bool wxListBox::Create(wxWindow
*parent
,
163 int n
, const wxString choices
[],
165 const wxValidator
& validator
,
166 const wxString
& name
)
168 // initialize base class fields
169 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
172 // create the native control
173 if ( !MSWCreateControl(wxT("LISTBOX"), wxEmptyString
, pos
, size
) )
175 // control creation failed
179 // initialize the contents
180 for ( int i
= 0; i
< n
; i
++ )
185 // now we can compute our best size correctly, so do it again
186 SetInitialSize(size
);
191 bool wxListBox::Create(wxWindow
*parent
,
195 const wxArrayString
& choices
,
197 const wxValidator
& validator
,
198 const wxString
& name
)
200 wxCArrayString
chs(choices
);
201 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
202 style
, validator
, name
);
205 wxListBox::~wxListBox()
210 WXDWORD
wxListBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
212 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
214 // we always want to get the notifications
215 msStyle
|= LBS_NOTIFY
;
217 // without this style, you get unexpected heights, so e.g. constraint
218 // layout doesn't work properly
219 msStyle
|= LBS_NOINTEGRALHEIGHT
;
221 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
222 wxT("only one of listbox selection modes can be specified") );
224 if ( style
& wxLB_MULTIPLE
)
225 msStyle
|= LBS_MULTIPLESEL
;
226 else if ( style
& wxLB_EXTENDED
)
227 msStyle
|= LBS_EXTENDEDSEL
;
229 wxASSERT_MSG( !(style
& wxLB_ALWAYS_SB
) || !(style
& wxLB_NO_SB
),
230 wxT( "Conflicting styles wxLB_ALWAYS_SB and wxLB_NO_SB." ) );
232 if ( !(style
& wxLB_NO_SB
) )
234 msStyle
|= WS_VSCROLL
;
235 if ( style
& wxLB_ALWAYS_SB
)
236 msStyle
|= LBS_DISABLENOSCROLL
;
239 if ( m_windowStyle
& wxLB_HSCROLL
)
240 msStyle
|= WS_HSCROLL
;
241 if ( m_windowStyle
& wxLB_SORT
)
244 #if wxUSE_OWNER_DRAWN && !defined(__WXWINCE__)
245 if ( m_windowStyle
& wxLB_OWNERDRAW
)
247 // we don't support LBS_OWNERDRAWVARIABLE yet and we also always put
248 // the strings in the listbox for simplicity even though we could have
249 // avoided it in this case
250 msStyle
|= LBS_OWNERDRAWFIXED
| LBS_HASSTRINGS
;
252 #endif // wxUSE_OWNER_DRAWN
257 void wxListBox::OnInternalIdle()
259 wxWindow::OnInternalIdle();
261 if (m_updateHorizontalExtent
)
263 SetHorizontalExtent(wxEmptyString
);
264 m_updateHorizontalExtent
= false;
268 void wxListBox::MSWOnItemsChanged()
270 // we need to do two things when items change: update their max horizontal
271 // extent so that horizontal scrollbar could be shown or hidden as
272 // appropriate and also invlaidate the best size
274 // updating the max extent is slow (it's an O(N) operation) and so we defer
275 // it until the idle time but the best size should be invalidated
276 // immediately doing it in idle time is too late -- layout using incorrect
277 // old best size will have been already done by then
279 m_updateHorizontalExtent
= true;
281 InvalidateBestSize();
284 // ----------------------------------------------------------------------------
285 // implementation of wxListBoxBase methods
286 // ----------------------------------------------------------------------------
288 void wxListBox::DoSetFirstItem(int N
)
290 wxCHECK_RET( IsValid(N
),
291 wxT("invalid index in wxListBox::SetFirstItem") );
293 SendMessage(GetHwnd(), LB_SETTOPINDEX
, (WPARAM
)N
, (LPARAM
)0);
296 void wxListBox::DoDeleteOneItem(unsigned int n
)
298 wxCHECK_RET( IsValid(n
),
299 wxT("invalid index in wxListBox::Delete") );
301 #if wxUSE_OWNER_DRAWN
302 if ( HasFlag(wxLB_OWNERDRAW
) )
305 m_aItems
.RemoveAt(n
);
307 #endif // wxUSE_OWNER_DRAWN
309 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
314 UpdateOldSelections();
317 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
319 // back to base class search for not native search type
321 return wxItemContainerImmutable::FindString( s
, bCase
);
323 int pos
= ListBox_FindStringExact(GetHwnd(), -1, s
.wx_str());
330 void wxListBox::DoClear()
332 #if wxUSE_OWNER_DRAWN
333 if ( HasFlag(wxLB_OWNERDRAW
) )
335 WX_CLEAR_ARRAY(m_aItems
);
337 #endif // wxUSE_OWNER_DRAWN
339 ListBox_ResetContent(GetHwnd());
344 UpdateOldSelections();
347 void wxListBox::DoSetSelection(int N
, bool select
)
349 wxCHECK_RET( N
== wxNOT_FOUND
|| IsValid(N
),
350 wxT("invalid index in wxListBox::SetSelection") );
352 if ( HasMultipleSelection() )
354 SendMessage(GetHwnd(), LB_SETSEL
, select
, N
);
358 SendMessage(GetHwnd(), LB_SETCURSEL
, select
? N
: -1, 0);
361 UpdateOldSelections();
364 bool wxListBox::IsSelected(int N
) const
366 wxCHECK_MSG( IsValid(N
), false,
367 wxT("invalid index in wxListBox::Selected") );
369 return SendMessage(GetHwnd(), LB_GETSEL
, N
, 0) == 0 ? false : true;
372 void *wxListBox::DoGetItemClientData(unsigned int n
) const
374 wxCHECK_MSG( IsValid(n
), NULL
,
375 wxT("invalid index in wxListBox::GetClientData") );
377 return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA
, n
, 0);
380 void wxListBox::DoSetItemClientData(unsigned int n
, void *clientData
)
382 wxCHECK_RET( IsValid(n
),
383 wxT("invalid index in wxListBox::SetClientData") );
385 if ( ListBox_SetItemData(GetHwnd(), n
, clientData
) == LB_ERR
)
387 wxLogDebug(wxT("LB_SETITEMDATA failed"));
391 // Return number of selections and an array of selected integers
392 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
396 if ( HasMultipleSelection() )
398 int countSel
= ListBox_GetSelCount(GetHwnd());
399 if ( countSel
== LB_ERR
)
401 wxLogDebug(wxT("ListBox_GetSelCount failed"));
403 else if ( countSel
!= 0 )
405 int *selections
= new int[countSel
];
407 if ( ListBox_GetSelItems(GetHwnd(),
408 countSel
, selections
) == LB_ERR
)
410 wxLogDebug(wxT("ListBox_GetSelItems failed"));
415 aSelections
.Alloc(countSel
);
416 for ( int n
= 0; n
< countSel
; n
++ )
417 aSelections
.Add(selections
[n
]);
420 delete [] selections
;
425 else // single-selection listbox
427 if (ListBox_GetCurSel(GetHwnd()) > -1)
428 aSelections
.Add(ListBox_GetCurSel(GetHwnd()));
430 return aSelections
.Count();
434 // Get single selection, for single choice list items
435 int wxListBox::GetSelection() const
437 wxCHECK_MSG( !HasMultipleSelection(),
439 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
441 return ListBox_GetCurSel(GetHwnd());
444 // Find string for position
445 wxString
wxListBox::GetString(unsigned int n
) const
447 wxCHECK_MSG( IsValid(n
), wxEmptyString
,
448 wxT("invalid index in wxListBox::GetString") );
450 int len
= ListBox_GetTextLen(GetHwnd(), n
);
452 // +1 for terminating NUL
454 ListBox_GetText(GetHwnd(), n
, (wxChar
*)wxStringBuffer(result
, len
+ 1));
459 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
462 wxClientDataType type
)
464 MSWAllocStorage(items
, LB_INITSTORAGE
);
466 const bool append
= pos
== GetCount();
468 // we must use CB_ADDSTRING when appending as only it works correctly for
469 // the sorted controls
470 const unsigned msg
= append
? LB_ADDSTRING
: LB_INSERTSTRING
;
477 const unsigned int numItems
= items
.GetCount();
478 for ( unsigned int i
= 0; i
< numItems
; i
++ )
480 n
= MSWInsertOrAppendItem(pos
, items
[i
], msg
);
481 if ( n
== wxNOT_FOUND
)
489 #if wxUSE_OWNER_DRAWN
490 if ( HasFlag(wxLB_OWNERDRAW
) )
492 wxOwnerDrawn
*pNewItem
= CreateLboxItem(n
);
493 pNewItem
->SetFont(GetFont());
494 m_aItems
.Insert(pNewItem
, n
);
496 #endif // wxUSE_OWNER_DRAWN
497 AssignNewItemClientData(n
, clientData
, i
, type
);
502 UpdateOldSelections();
507 int wxListBox::DoHitTestList(const wxPoint
& point
) const
509 LRESULT lRes
= ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT
,
510 0, MAKELPARAM(point
.x
, point
.y
));
512 // non zero high-order word means that this item is outside of the client
513 // area, IOW the point is outside of the listbox
514 return HIWORD(lRes
) ? wxNOT_FOUND
: LOWORD(lRes
);
517 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
519 wxCHECK_RET( IsValid(n
),
520 wxT("invalid index in wxListBox::SetString") );
522 // remember the state of the item
523 bool wasSelected
= IsSelected(n
);
525 void *oldData
= NULL
;
526 wxClientData
*oldObjData
= NULL
;
527 if ( HasClientUntypedData() )
528 oldData
= GetClientData(n
);
529 else if ( HasClientObjectData() )
530 oldObjData
= GetClientObject(n
);
532 // delete and recreate it
533 SendMessage(GetHwnd(), LB_DELETESTRING
, n
, 0);
536 if ( n
== (m_noItems
- 1) )
539 ListBox_InsertString(GetHwnd(), newN
, s
.wx_str());
541 // restore the client data
543 SetClientData(n
, oldData
);
544 else if ( oldObjData
)
545 SetClientObject(n
, oldObjData
);
547 // we may have lost the selection
554 unsigned int wxListBox::GetCount() const
559 // ----------------------------------------------------------------------------
560 // size-related stuff
561 // ----------------------------------------------------------------------------
563 void wxListBox::SetHorizontalExtent(const wxString
& s
)
565 // the rest is only necessary if we want a horizontal scrollbar
566 if ( !HasFlag(wxHSCROLL
) )
570 WindowHDC
dc(GetHwnd());
571 SelectInHDC
selFont(dc
, GetHfontOf(GetFont()));
573 TEXTMETRIC lpTextMetric
;
574 ::GetTextMetrics(dc
, &lpTextMetric
);
576 int largestExtent
= 0;
581 // set extent to the max length of all strings
582 for ( unsigned int i
= 0; i
< m_noItems
; i
++ )
584 const wxString str
= GetString(i
);
585 ::GetTextExtentPoint32(dc
, str
.c_str(), str
.length(), &extentXY
);
587 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
588 if ( extentX
> largestExtent
)
589 largestExtent
= extentX
;
592 else // just increase the extent to the length of this string
594 int existingExtent
= (int)SendMessage(GetHwnd(),
595 LB_GETHORIZONTALEXTENT
, 0, 0L);
597 ::GetTextExtentPoint32(dc
, s
.c_str(), s
.length(), &extentXY
);
599 int extentX
= (int)(extentXY
.cx
+ lpTextMetric
.tmAveCharWidth
);
600 if ( extentX
> existingExtent
)
601 largestExtent
= extentX
;
605 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT
, LOWORD(largestExtent
), 0L);
606 //else: it shouldn't change
609 wxSize
wxListBox::DoGetBestClientSize() const
611 // find the widest string
614 for (unsigned int i
= 0; i
< m_noItems
; i
++)
616 wxString
str(GetString(i
));
617 GetTextExtent(str
, &wLine
, NULL
);
618 if ( wLine
> wListbox
)
622 // give it some reasonable default value if there are no strings in the
627 // the listbox should be slightly larger than the widest string
628 wListbox
+= 3*GetCharWidth();
630 // add room for the scrollbar
631 wListbox
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
633 // don't make the listbox too tall (limit height to 10 items) but don't
634 // make it too small neither
635 int hListbox
= SendMessage(GetHwnd(), LB_GETITEMHEIGHT
, 0, 0)*
636 wxMin(wxMax(m_noItems
, 3), 10);
638 return wxSize(wListbox
, hListbox
);
641 // ----------------------------------------------------------------------------
643 // ----------------------------------------------------------------------------
645 bool wxListBox::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
649 if ( param
== LBN_SELCHANGE
)
651 if ( HasMultipleSelection() )
652 return CalcAndSendEvent();
654 evtType
= wxEVT_COMMAND_LISTBOX_SELECTED
;
656 if ( m_selectedByKeyboard
)
658 // We shouldn't use the mouse position to find the item as mouse
659 // can be anywhere, ask the listbox itself. Notice that this can't
660 // be used when the item is selected using the mouse however as
661 // LB_GETCARETINDEX will always return a valid item, even if the
662 // mouse is clicked below all the items, which is why we find the
663 // item ourselves below in this case.
664 n
= SendMessage(GetHwnd(), LB_GETCARETINDEX
, 0, 0);
666 //else: n will be determined below from the mouse position
668 else if ( param
== LBN_DBLCLK
)
670 evtType
= wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
;
674 // some event we're not interested in
678 // Find the item position if it was a mouse-generated selection event or a
679 // double click event (which is always generated using the mouse)
680 if ( n
== wxNOT_FOUND
)
682 const DWORD pos
= ::GetMessagePos();
683 const wxPoint
pt(GET_X_LPARAM(pos
), GET_Y_LPARAM(pos
));
684 n
= HitTest(ScreenToClient(wxPoint(pt
)));
687 // We get events even when mouse is clicked outside of any valid item from
688 // Windows, just ignore them.
689 if ( n
== wxNOT_FOUND
)
692 // As we don't use m_oldSelections in single selection mode, we store the
693 // last item that we notified the user about in it in this case because we
694 // need to remember it to be able to filter out the dummy LBN_SELCHANGE
695 // messages that we get when the user clicks on an already selected item.
696 if ( param
== LBN_SELCHANGE
)
698 if ( !m_oldSelections
.empty() && *m_oldSelections
.begin() == n
)
700 // Same item as the last time.
704 m_oldSelections
.clear();
705 m_oldSelections
.push_back(n
);
708 // Do generate an event otherwise.
709 return SendEvent(evtType
, n
, true /* selection */);
713 wxListBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
715 // Remember whether there was a keyboard or mouse event before
716 // LBN_SELCHANGE: this allows us to correctly determine the item affected
717 // by it in MSWCommand() above in any case.
718 if ( WM_KEYFIRST
<= nMsg
&& nMsg
<= WM_KEYLAST
)
719 m_selectedByKeyboard
= true;
720 else if ( WM_MOUSEFIRST
<= nMsg
&& nMsg
<= WM_MOUSELAST
)
721 m_selectedByKeyboard
= false;
723 return wxListBoxBase::MSWWindowProc(nMsg
, wParam
, lParam
);
726 // ----------------------------------------------------------------------------
727 // owner-drawn list boxes support
728 // ----------------------------------------------------------------------------
730 #if wxUSE_OWNER_DRAWN
732 // misc overloaded methods
733 // -----------------------
735 bool wxListBox::SetFont(const wxFont
&font
)
737 if ( HasFlag(wxLB_OWNERDRAW
) )
739 const unsigned count
= m_aItems
.GetCount();
740 for ( unsigned i
= 0; i
< count
; i
++ )
741 m_aItems
[i
]->SetFont(font
);
744 wxListBoxBase::SetFont(font
);
749 bool wxListBox::GetItemRect(size_t n
, wxRect
& rect
) const
751 wxCHECK_MSG( IsValid(n
), false,
752 wxT("invalid index in wxListBox::GetItemRect") );
756 if ( ListBox_GetItemRect(GetHwnd(), n
, &rc
) != LB_ERR
)
758 rect
= wxRectFromRECT(rc
);
763 // couldn't retrieve rect: for example, item isn't visible
768 bool wxListBox::RefreshItem(size_t n
)
771 if ( !GetItemRect(n
, rect
) )
775 wxCopyRectToRECT(rect
, rc
);
777 return ::InvalidateRect((HWND
)GetHWND(), &rc
, FALSE
) == TRUE
;
786 // space beneath/above each row in pixels
787 static const int LISTBOX_EXTRA_SPACE
= 1;
789 } // anonymous namespace
791 // the height is the same for all items
792 // TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
794 // NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
795 // message is not yet sent when we get here!
796 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
798 // only owner-drawn control should receive this message
799 wxCHECK( HasFlag(wxLB_OWNERDRAW
), false );
801 MEASUREITEMSTRUCT
*pStruct
= (MEASUREITEMSTRUCT
*)item
;
804 HDC hdc
= GetDC(NULL
);
806 HDC hdc
= CreateIC(wxT("DISPLAY"), NULL
, NULL
, 0);
810 wxDCTemp
dc((WXHDC
)hdc
);
811 dc
.SetFont(GetFont());
813 pStruct
->itemHeight
= dc
.GetCharHeight() + 2 * LISTBOX_EXTRA_SPACE
;
814 pStruct
->itemWidth
= dc
.GetCharWidth();
818 ReleaseDC(NULL
, hdc
);
826 // forward the message to the appropriate item
827 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
829 // only owner-drawn control should receive this message
830 wxCHECK( HasFlag(wxLB_OWNERDRAW
), false );
832 DRAWITEMSTRUCT
*pStruct
= (DRAWITEMSTRUCT
*)item
;
834 // the item may be -1 for an empty listbox
835 if ( pStruct
->itemID
== (UINT
)-1 )
838 wxListBoxItem
*pItem
= (wxListBoxItem
*)m_aItems
[pStruct
->itemID
];
840 wxDCTemp
dc((WXHDC
)pStruct
->hDC
);
842 return pItem
->OnDrawItem(dc
, wxRectFromRECT(pStruct
->rcItem
),
843 (wxOwnerDrawn::wxODAction
)pStruct
->itemAction
,
844 (wxOwnerDrawn::wxODStatus
)(pStruct
->itemState
| wxOwnerDrawn::wxODHidePrefix
));
847 #endif // wxUSE_OWNER_DRAWN
849 #endif // wxUSE_LISTBOX