]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't send selection events for an already selected item in wxMSW wxListBox.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 5 Jun 2010 22:58:13 +0000 (22:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 5 Jun 2010 22:58:13 +0000 (22:58 +0000)
Remember the last item for which a listbox notification event had been sent
and don't send it again if the user clicks on an already selected item. This
is consistent with wxGTK behaviour and generally makes more sense: why should
we send an event if the selection didn't really change?

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

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

index cd4c0fa6f824476dc8360759fe42960bb69509bf..01f64a7ab1caea3bcfc78bb8d98a3085ab2169c2 100644 (file)
@@ -101,9 +101,6 @@ public:
     // send the appropriate event if they differ, otherwise just return false.
     bool CalcAndSendEvent();
 
-    wxArrayInt m_oldSelections;
-    void UpdateOldSelections();
-
 protected:
     virtual void DoSetFirstItem(int n) = 0;
 
@@ -118,6 +115,16 @@ protected:
     // Returns true if the event was processed.
     bool SendEvent(wxEventType evtType, int item, bool selected);
 
+    // Array storing the indices of all selected items that we already notified
+    // the user code about for multi selection list boxes.
+    //
+    // TODO-OPT: wxSelectionStore would be more efficient for big list boxes.
+    wxArrayInt m_oldSelections;
+
+    // Update m_oldSelections with currently selected items (does nothing in
+    // single selection mode).
+    void UpdateOldSelections();
+
 private:
     wxDECLARE_NO_COPY_CLASS(wxListBoxBase);
 };
index 3e19b2a9f2d94d014000bdc1a61b6c825589e22f..53d60ce89bc54ed8f04e3c967ccb71a9d84f29dc 100644 (file)
@@ -686,7 +686,27 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 
     // We get events even when mouse is clicked outside of any valid item from
     // Windows, just ignore them.
-    return n != wxNOT_FOUND && SendEvent(evtType, n, true /* selection */);
+    if ( n == wxNOT_FOUND )
+       return false;
+
+    // As we don't use m_oldSelections in single selection mode, we store the
+    // last item that we notified the user about in it in this case because we
+    // need to remember it to be able to filter out the dummy LBN_SELCHANGE
+    // messages that we get when the user clicks on an already selected item.
+    if ( param == LBN_SELCHANGE )
+    {
+        if ( !m_oldSelections.empty() && *m_oldSelections.begin() == n )
+        {
+            // Same item as the last time.
+            return false;
+        }
+
+        m_oldSelections.clear();
+        m_oldSelections.push_back(n);
+    }
+
+    // Do generate an event otherwise.
+    return SendEvent(evtType, n, true /* selection */);
 }
 
 WXLRESULT