From 3c8cbc12caeab51f2b483cf7d419417801679670 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Jan 2010 13:16:01 +0000 Subject: [PATCH] Improve hit detection in wxMSW wxTreeCtrl with wxTR_FULL_ROW_HIGHLIGHT style. When wxTR_FULL_ROW_HIGHLIGHT is used, the item visually takes up the entire breadth of the window so clicking both to the left or to the right of the item should have the same effect as clicking on it. So add a MSWIsOnItem() helper which tests for whether a point is above the item correctly and use it in order to: 1. In multi selection mode, allow clicking anywhere to select the item(s) when Ctrl or Shift is pressed (Closes #11598). 2. Generate activation event when clicking to the right of the item too (Closes #11602). 3. Detect item bounds correctly in WM_LBUTTONUP handler (although it's not really clear what does this code do and hence what problem does this fix...). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63089 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/treectrl.h | 8 ++++++++ src/msw/treectrl.cpp | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index e2b76ae601..4c621980ef 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -287,6 +287,14 @@ private: void ClearFocusedItem(); void SetFocusedItem(const wxTreeItemId& item); + // check if the given flags (taken from TV_HITTESTINFO structure) + // indicate a position "on item": this is less trivial than just checking + // for TVHT_ONITEM because we consider that points to the left and right of + // item text are also "on item" when wxTR_FULL_ROW_HIGHLIGHT is used as the + // item visually spans the entire breadth of the window then + bool MSWIsOnItem(unsigned flags) const; + + // the hash storing the items attributes (indexed by item ids) wxMapTreeAttr m_attrs; diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index b408ac740d..6b854a8c84 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -2215,6 +2215,15 @@ bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id_) return true; } +bool wxTreeCtrl::MSWIsOnItem(unsigned flags) const +{ + unsigned mask = TVHT_ONITEM; + if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT) ) + mask |= TVHT_ONITEMINDENT | TVHT_ONITEMRIGHT; + + return (flags & mask) != 0; +} + bool wxTreeCtrl::MSWHandleSelectionKey(unsigned vkey) { const bool bCtrl = wxIsCtrlDown(); @@ -2716,7 +2725,7 @@ wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) m_htClickedItem.Unset(); - if ( !(tvht.flags & TVHT_ONITEM) ) + if ( !MSWIsOnItem(tvht.flags) ) { if ( tvht.flags & TVHT_ONITEMBUTTON ) { @@ -3067,10 +3076,7 @@ wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } } - if ( !m_dragStarted && - (tvht.flags & TVHT_ONITEMSTATEICON || - tvht.flags & TVHT_ONITEMICON || - tvht.flags & TVHT_ONITEM) ) + if ( !m_dragStarted && MSWIsOnItem(tvht.flags) ) { processed = true; } @@ -3652,7 +3658,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) ::ScreenToClient(GetHwnd(), &tvhti.pt); if ( TreeView_HitTest(GetHwnd(), &tvhti) ) { - if ( tvhti.flags & TVHT_ONITEM ) + if ( MSWIsOnItem(tvhti.flags) ) { event.m_item = tvhti.hItem; eventType = (int)hdr->code == NM_DBLCLK -- 2.45.2