]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/listbox.cpp
reset virtual root to NULL in DeleteAllItems()
[wxWidgets.git] / src / msw / listbox.cpp
index 6d1f05a55615149acb49198fcf6ecb19590a3a88..d74a1e4acb2c7ca3d2252146ca07414b1f648257 100644 (file)
@@ -93,7 +93,7 @@
 class wxListBoxItem : public wxOwnerDrawn
 {
 public:
 class wxListBoxItem : public wxOwnerDrawn
 {
 public:
-    wxListBoxItem(const wxString& str = "");
+    wxListBoxItem(const wxString& str = wxEmptyString);
 };
 
 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
 };
 
 wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
@@ -102,7 +102,7 @@ wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
     SetMarginWidth(0);
 }
 
     SetMarginWidth(0);
 }
 
-wxOwnerDrawn *wxListBox::CreateItem(size_t WXUNUSED(n))
+wxOwnerDrawn *wxListBox::CreateLboxItem(size_t WXUNUSED(n))
 {
     return new wxListBoxItem();
 }
 {
     return new wxListBoxItem();
 }
@@ -272,7 +272,7 @@ void wxListBox::Delete(int N)
     SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
     m_noItems--;
 
     SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
     m_noItems--;
 
-    SetHorizontalExtent("");
+    SetHorizontalExtent(wxEmptyString);
 }
 
 int wxListBox::DoAppend(const wxString& item)
 }
 
 int wxListBox::DoAppend(const wxString& item)
@@ -282,7 +282,7 @@ int wxListBox::DoAppend(const wxString& item)
 
 #if wxUSE_OWNER_DRAWN
     if ( m_windowStyle & wxLB_OWNERDRAW ) {
 
 #if wxUSE_OWNER_DRAWN
     if ( m_windowStyle & wxLB_OWNERDRAW ) {
-        wxOwnerDrawn *pNewItem = CreateItem(index); // dummy argument
+        wxOwnerDrawn *pNewItem = CreateLboxItem(index); // dummy argument
         pNewItem->SetName(item);
         m_aItems.Insert(pNewItem, index);
         ListBox_SetItemData(GetHwnd(), index, pNewItem);
         pNewItem->SetName(item);
         m_aItems.Insert(pNewItem, index);
         ListBox_SetItemData(GetHwnd(), index, pNewItem);
@@ -313,16 +313,7 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
         ListBox_AddString(GetHwnd(), choices[i]);
         if ( clientData )
         {
         ListBox_AddString(GetHwnd(), choices[i]);
         if ( clientData )
         {
-#if wxUSE_OWNER_DRAWN
-            if ( m_windowStyle & wxLB_OWNERDRAW )
-            {
-                wxASSERT_MSG(clientData[i] == NULL,
-                             wxT("Can't use client data with owner-drawn listboxes"));
-            }
-            ListBox_SetItemData(GetHwnd(), i, clientData[i]);
-#else // !wxUSE_OWNER_DRAWN
-            ListBox_SetItemData(GetHwnd(), i, clientData[i]);
-#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
+            SetClientData(i, clientData[i]);
         }
     }
 
         }
     }
 
@@ -333,7 +324,7 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
 
         // then create new ones
         for ( size_t ui = 0; ui < (size_t)m_noItems; ui++ ) {
 
         // then create new ones
         for ( size_t ui = 0; ui < (size_t)m_noItems; ui++ ) {
-            wxOwnerDrawn *pNewItem = CreateItem(ui);
+            wxOwnerDrawn *pNewItem = CreateLboxItem(ui);
             pNewItem->SetName(choices[ui]);
             m_aItems.Add(pNewItem);
             ListBox_SetItemData(GetHwnd(), ui, pNewItem);
             pNewItem->SetName(choices[ui]);
             m_aItems.Add(pNewItem);
             ListBox_SetItemData(GetHwnd(), ui, pNewItem);
@@ -453,21 +444,32 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
 
     if ( HasMultipleSelection() )
     {
 
     if ( HasMultipleSelection() )
     {
-        int no_sel = ListBox_GetSelCount(GetHwnd());
-        if (no_sel != 0) {
-            int *selections = new int[no_sel];
-            int rc = ListBox_GetSelItems(GetHwnd(), no_sel, selections);
-
-            wxCHECK_MSG(rc != LB_ERR, -1, wxT("ListBox_GetSelItems failed"));
+        int countSel = ListBox_GetSelCount(GetHwnd());
+        if ( countSel == LB_ERR )
+        {
+            wxLogDebug(_T("ListBox_GetSelCount failed"));
+        }
+        else if ( countSel != 0 )
+        {
+            int *selections = new int[countSel];
 
 
-            aSelections.Alloc(no_sel);
-            for ( int n = 0; n < no_sel; n++ )
-                aSelections.Add(selections[n]);
+            if ( ListBox_GetSelItems(GetHwnd(),
+                                     countSel, selections) == LB_ERR )
+            {
+                wxLogDebug(wxT("ListBox_GetSelItems failed"));
+                countSel = -1;
+            }
+            else
+            {
+                aSelections.Alloc(countSel);
+                for ( int n = 0; n < countSel; n++ )
+                    aSelections.Add(selections[n]);
+            }
 
             delete [] selections;
         }
 
 
             delete [] selections;
         }
 
-        return no_sel;
+        return countSel;
     }
     else  // single-selection listbox
     {
     }
     else  // single-selection listbox
     {
@@ -491,7 +493,7 @@ int wxListBox::GetSelection() const
 // Find string for position
 wxString wxListBox::GetString(int N) const
 {
 // Find string for position
 wxString wxListBox::GetString(int N) const
 {
-    wxCHECK_MSG( N >= 0 && N < m_noItems, "",
+    wxCHECK_MSG( N >= 0 && N < m_noItems, wxEmptyString,
                  wxT("invalid index in wxListBox::GetClientData") );
 
     int len = ListBox_GetTextLen(GetHwnd(), N);
                  wxT("invalid index in wxListBox::GetClientData") );
 
     int len = ListBox_GetTextLen(GetHwnd(), N);
@@ -516,12 +518,15 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos)
         int idx = ListBox_InsertString(GetHwnd(), i + pos, items[i]);
 
 #if wxUSE_OWNER_DRAWN
         int idx = ListBox_InsertString(GetHwnd(), i + pos, items[i]);
 
 #if wxUSE_OWNER_DRAWN
-        wxOwnerDrawn *pNewItem = CreateItem(idx);
-        pNewItem->SetName(items[i]);
-        pNewItem->SetFont(GetFont());
-        m_aItems.Insert(pNewItem, idx);
+        if ( m_windowStyle & wxLB_OWNERDRAW )
+        {
+            wxOwnerDrawn *pNewItem = CreateLboxItem(idx);
+            pNewItem->SetName(items[i]);
+            pNewItem->SetFont(GetFont());
+            m_aItems.Insert(pNewItem, idx);
 
 
-        ListBox_SetItemData(GetHwnd(), idx, pNewItem);
+            ListBox_SetItemData(GetHwnd(), idx, pNewItem);
+        }
 #endif // wxUSE_OWNER_DRAWN
     }
 
 #endif // wxUSE_OWNER_DRAWN
     }