]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/listbox.cpp
Committing in .
[wxWidgets.git] / src / msw / listbox.cpp
index 067fc11d9099b88a701f949a118d3eb7643ad822..98d9b64dd4751fce5c7cab926ca2e47e9f782199 100644 (file)
@@ -156,7 +156,7 @@ bool wxListBox::Create(wxWindow *parent,
     m_windowStyle = style;
 
     DWORD wstyle = WS_VISIBLE | WS_VSCROLL | WS_TABSTOP |
     m_windowStyle = style;
 
     DWORD wstyle = WS_VISIBLE | WS_VSCROLL | WS_TABSTOP |
-                   LBS_NOTIFY | LBS_HASSTRINGS;
+                   LBS_NOTIFY | LBS_HASSTRINGS /* | WS_CLIPSIBLINGS */;
     if (m_windowStyle & wxLB_MULTIPLE)
         wstyle |= LBS_MULTIPLESEL;
     else if (m_windowStyle & wxLB_EXTENDED)
     if (m_windowStyle & wxLB_MULTIPLE)
         wstyle |= LBS_MULTIPLESEL;
     else if (m_windowStyle & wxLB_EXTENDED)
@@ -221,8 +221,6 @@ bool wxListBox::Create(wxWindow *parent,
 
     SetSize(x, y, width, height);
 
 
     SetSize(x, y, width, height);
 
-    Show(TRUE);
-
     return TRUE;
 }
 
     return TRUE;
 }
 
@@ -292,7 +290,12 @@ int wxListBox::DoAppend(const wxString& item)
 
 void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
 {
 
 void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
 {
-    ShowWindow(GetHwnd(), SW_HIDE);
+    // avoid flicker - but don't need to do this for a hidden listbox
+    bool hideAndShow = IsShown();
+    if ( hideAndShow )
+    {
+        ShowWindow(GetHwnd(), SW_HIDE);
+    }
 
     ListBox_ResetContent(GetHwnd());
 
 
     ListBox_ResetContent(GetHwnd());
 
@@ -304,8 +307,12 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
         if ( clientData )
         {
 #if wxUSE_OWNER_DRAWN
         if ( clientData )
         {
 #if wxUSE_OWNER_DRAWN
-            wxASSERT_MSG(clientData[i] == NULL,
-                         wxT("Can't use client data with owner-drawn listboxes"));
+            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
 #else // !wxUSE_OWNER_DRAWN
             ListBox_SetItemData(GetHwnd(), i, clientData[i]);
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
@@ -333,7 +340,11 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
 
     SetHorizontalExtent();
 
 
     SetHorizontalExtent();
 
-    ShowWindow(GetHwnd(), SW_SHOW);
+    if ( hideAndShow )
+    {
+        // show the listbox back if we hid it
+        ShowWindow(GetHwnd(), SW_SHOW);
+    }
 }
 
 int wxListBox::FindString(const wxString& s) const
 }
 
 int wxListBox::FindString(const wxString& s) const
@@ -467,9 +478,10 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
     }
     else  // single-selection listbox
     {
     }
     else  // single-selection listbox
     {
-        aSelections.Add(ListBox_GetCurSel(GetHwnd()));
+        if (ListBox_GetCurSel(GetHwnd()) > -1)
+            aSelections.Add(ListBox_GetCurSel(GetHwnd()));
 
 
-        return 1;
+        return aSelections.Count();
     }
 }
 
     }
 }
 
@@ -478,8 +490,7 @@ int wxListBox::GetSelection() const
 {
     wxCHECK_MSG( !HasMultipleSelection(),
                  -1,
 {
     wxCHECK_MSG( !HasMultipleSelection(),
                  -1,
-                 wxT("GetSelection() can't be used with multiple-selection "
-                    "listboxes, use GetSelections() instead.") );
+                 wxT("GetSelection() can't be used with multiple-selection listboxes, use GetSelections() instead.") );
 
     return ListBox_GetCurSel(GetHwnd());
 }
 
     return ListBox_GetCurSel(GetHwnd());
 }
@@ -742,6 +753,11 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
     wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
 
     DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
     wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
 
     DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
+    UINT itemID = pStruct->itemID;
+
+    // the item may be -1 for an empty listbox
+    if ( itemID == (UINT)-1 )
+        return FALSE;
 
     long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID);
 
 
     long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID);
 
@@ -752,7 +768,7 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
     wxDC dc;
     dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
     wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
     wxDC dc;
     dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
     wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
-            wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom));
+                wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom));
 
     return pItem->OnDrawItem(dc, rect,
             (wxOwnerDrawn::wxODAction)pStruct->itemAction,
 
     return pItem->OnDrawItem(dc, rect,
             (wxOwnerDrawn::wxODAction)pStruct->itemAction,