]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't send event from wxMSW::wxListCtrl::DeleteAllItems() if it did nothing.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Aug 2010 22:15:17 +0000 (22:15 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Aug 2010 22:15:17 +0000 (22:15 +0000)
wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS should only be sent if the control hadn't
been empty before. Document this behaviour and adjust wxMSW to match the
other platforms.

Also document the return value better.

Closes #12336.

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

interface/wx/listctrl.h
src/msw/listctrl.cpp

index bb6865f7e2e8c83ccd413171cd0ac14f47d522ad..fa380eeb01cd0c73f266dcf2c8e24009cfdb408e 100644 (file)
@@ -214,9 +214,15 @@ public:
     /**
         Deletes all items in the list control.
 
-        @note This function does @e not send the @c wxEVT_COMMAND_LIST_DELETE_ITEM
-              event because deleting many items from the control would be too slow
-              then (unlike wxListCtrl::DeleteItem).
+        This function does @e not send the @c wxEVT_COMMAND_LIST_DELETE_ITEM
+        event because deleting many items from the control would be too slow
+        then (unlike wxListCtrl::DeleteItem) but it does send the special @c
+        wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS event if the control was not empty.
+        If it was already empty, nothing is done and no event is sent.
+
+        @return @true if the items were successfully deleted or if the control
+            was already empty, @false if an error occurred while deleting the
+            items.
     */
     bool DeleteAllItems();
 
index 484443466f86dc586a619bf350308a9f9bfee950..997c3ca9bc5c653dba6ee90d132d11f237d71435 100644 (file)
@@ -1464,7 +1464,9 @@ bool wxListCtrl::DeleteItem(long item)
 // Deletes all items
 bool wxListCtrl::DeleteAllItems()
 {
-    return ListView_DeleteAllItems(GetHwnd()) != 0;
+    // Calling ListView_DeleteAllItems() will always generate an event but we
+    // shouldn't do it if the control is empty 
+    return !GetItemCount() || ListView_DeleteAllItems(GetHwnd()) != 0;
 }
 
 // Deletes all items