From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Tue, 13 Nov 2007 17:18:58 +0000 (+0000)
Subject: unselect all selected items, not just the currently focused one, when the mouse is... 
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e0bf68d697a37d75ac9439745a3a2ac55bd25ddf

unselect all selected items, not just the currently focused one, when the mouse is right clicked outside of selection to minimize user confusion (patch 1702201, bug 1676471)

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

diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp
index 631b4ebce3..d705b7e6a8 100644
--- a/src/msw/treectrl.cpp
+++ b/src/msw/treectrl.cpp
@@ -2147,6 +2147,38 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                 }
                 break;
 
+            case WM_RBUTTONDOWN:
+                // default handler removes the highlight from the currently
+                // focused item when right mouse button is pressed on another
+                // one but keeps the remaining items highlighted, which is
+                // confusing, so override this default behaviour for tree with
+                // multiple selections
+                if ( isMultiple )
+                {
+                    if ( !IsItemSelected(GetHwnd(), htItem) )
+                    {
+                        UnselectAll();
+                        SelectItem(htItem);
+                        ::SetFocus(GetHwnd(), htItem);
+                    }
+
+                    // fire EVT_RIGHT_DOWN
+                    HandleMouseEvent(nMsg, x, y, wParam);
+                    
+                    // send NM_RCLICK
+                    NMHDR nmhdr;
+                    nmhdr.hwndFrom = GetHwnd();
+                    nmhdr.idFrom = ::GetWindowLong(GetHwnd(), GWL_ID);
+                    nmhdr.code = NM_RCLICK;
+                    ::SendMessage(::GetParent(GetHwnd()), WM_NOTIFY,
+                                  nmhdr.idFrom, (LPARAM)&nmhdr);
+
+                    // prevent tree control default processing, as we've
+                    // already done everything                   
+                    processed = true;
+                }
+                break;
+
             case WM_MOUSEMOVE:
 #ifndef __WXWINCE__
                 if ( m_htClickedItem )