]> git.saurik.com Git - wxWidgets.git/commitdiff
make wxTreeCtrl::SelectItem(false) work in single selection controls under MSW (fixin...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Jun 2009 22:56:57 +0000 (22:56 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Jun 2009 22:56:57 +0000 (22:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60921 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/treectrl.cpp

index 1d49469169c793e2a7af9d12c299b710c0e8046b..6f49c3f857b6eaa61646b89ef0ca764d7766be53 100644 (file)
@@ -1878,8 +1878,9 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
 {
     wxCHECK_RET( !IsHiddenRoot(item), _T("can't select hidden root item") );
 
-    if ( IsSelected(item) == select )
+    if ( select == IsSelected(item) )
     {
+        // nothing to do, the item is already in the requested state
         return;
     }
 
@@ -1902,20 +1903,31 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
             (void)HandleTreeEvent(changedEvent);
         }
     }
-    else
+    else // single selection
     {
-        wxASSERT_MSG( select,
-                      _T("SelectItem(false) works only for multiselect") );
+        wxTreeItemId itemOld, itemNew;
+        if ( select )
+        {
+            itemOld = GetSelection();
+            itemNew = item;
+        }
+        else // deselecting the currently selected item
+        {
+            itemOld = item;
+            // leave itemNew invalid
+        }
 
         // in spite of the docs (MSDN Jan 99 edition), we don't seem to receive
         // the notification from the control (i.e. TVN_SELCHANG{ED|ING}), so
         // send them ourselves
 
-        wxTreeEvent changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this, item);
+        wxTreeEvent
+            changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this, itemNew);
+        changingEvent.SetOldItem(itemOld);
 
         if ( IsTreeEventAllowed(changingEvent) )
         {
-            if ( !TreeView_SelectItem(GetHwnd(), HITEM(item)) )
+            if ( !TreeView_SelectItem(GetHwnd(), HITEM(itemNew)) )
             {
                 wxLogLastError(wxT("TreeView_SelectItem"));
             }
@@ -1924,7 +1936,8 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
                 SetFocusedItem(item);
 
                 wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED,
-                                         this, item);
+                                         this, itemNew);
+                changedEvent.SetOldItem(itemOld);
                 (void)HandleTreeEvent(changedEvent);
             }
         }