]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix multiple bugs in non-ownerdrawn wxListBox after recent merge.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 25 Feb 2010 00:03:44 +0000 (00:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 25 Feb 2010 00:03:44 +0000 (00:03 +0000)
Changes done in ownerdraw-refactor branch have broken non-ownerdrawn list
boxes as the code was now using m_aItems array even for them but it's not used
in this case.

Also remove unnecessarily overridden Delete() method which didn't add anything
to the base class implementation but just deleted the same m_aItems pointer
twice.

Also use HasFlag(wxLB_OWNERDRAW) everywhere consistently instead of testing
for it manually.

Closes #11729.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63551 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/listbox.h
src/msw/listbox.cpp

index d8572170ab87ef45da4c1dd440d53dec1a534360..4a78e165a22cb97f30b47d44e55f785cce425f6c 100644 (file)
@@ -93,7 +93,6 @@ public:
     // ownerdrawn wxListBox and wxCheckListBox support
 #if wxUSE_OWNER_DRAWN
     // override base class virtuals
-    virtual void Delete(unsigned int n);
     virtual bool SetFont(const wxFont &font);
 
     bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
index 29e2e7440136ae32d729d25b129cc84667066e91..78d76fdfabcd4c679d343f1b584f83feb25b9416 100644 (file)
@@ -287,8 +287,11 @@ void wxListBox::DoDeleteOneItem(unsigned int n)
                  wxT("invalid index in wxListBox::Delete") );
 
 #if wxUSE_OWNER_DRAWN
-    delete m_aItems[n];
-    m_aItems.RemoveAt(n);
+    if ( HasFlag(wxLB_OWNERDRAW) )
+    {
+        delete m_aItems[n];
+        m_aItems.RemoveAt(n);
+    }
 #endif // wxUSE_OWNER_DRAWN
 
     SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
@@ -316,7 +319,7 @@ int wxListBox::FindString(const wxString& s, bool bCase) const
 void wxListBox::DoClear()
 {
 #if wxUSE_OWNER_DRAWN
-    if ( m_windowStyle & wxLB_OWNERDRAW )
+    if ( HasFlag(wxLB_OWNERDRAW) )
     {
         WX_CLEAR_ARRAY(m_aItems);
     }
@@ -678,7 +681,7 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 }
 
 // ----------------------------------------------------------------------------
-// wxCheckListBox support
+// owner-drawn list boxes support
 // ----------------------------------------------------------------------------
 
 #if wxUSE_OWNER_DRAWN
@@ -686,23 +689,14 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 // misc overloaded methods
 // -----------------------
 
-void wxListBox::Delete(unsigned int n)
-{
-    wxCHECK_RET( IsValid(n),
-                 wxT("invalid index in wxListBox::Delete") );
-
-    wxListBoxBase::Delete(n);
-
-    // free memory
-    delete m_aItems[n];
-    m_aItems.RemoveAt(n);
-}
-
 bool wxListBox::SetFont(const wxFont &font)
 {
-    unsigned int i;
-    for ( i = 0; i < m_aItems.GetCount(); i++ )
-        m_aItems[i]->SetFont(font);
+    if ( HasFlag(wxLB_OWNERDRAW) )
+    {
+        const unsigned count = m_aItems.GetCount();
+        for ( unsigned i = 0; i < count; i++ )
+            m_aItems[i]->SetFont(font);
+    }
 
     wxListBoxBase::SetFont(font);
 
@@ -759,7 +753,7 @@ namespace
 bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
 {
     // only owner-drawn control should receive this message
-    wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
+    wxCHECK( HasFlag(wxLB_OWNERDRAW), false );
 
     MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
 
@@ -790,7 +784,7 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
 bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
 {
     // only owner-drawn control should receive this message
-    wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
+    wxCHECK( HasFlag(wxLB_OWNERDRAW), false );
 
     DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;