From 1237e932ad25181d1b2c79934fd042c23ece2556 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 30 Jan 2016 19:09:33 +0100 Subject: [PATCH] Fix setting wxBK_HITTEST_xxx flags in wxNotebook::HitTest The state represented by TCHT_ONITEM Win API flag is not a superposition TCHT_ONITEMICON and TCHT_ONITLABEL states but it represents a separate state. The fact that binary value of TCHT_ONITEM is bitwise-OR operation on TCHT_ONITEMICON and TCHT_ONITEMLABEL doesn't matter here. The same applies to wxBK_HITTEST_xxx flags where state represented by wxBK_HITTEST_ONITEM is not a superposition of wxBK_HITTEST_ONICON and wxBK_HITTEST_ONLABEL. Add note to wxBookCtrl::HitTest documentation that wxBK_HITTEST_ONICON, wxBK_HITTEST_ONLABEL, wxBK_HITTEST_ONITEM are mutually exclusive bits. See https://github.com/wxWidgets/wxWidgets/pull/159 --- include/wx/bookctrl.h | 2 +- interface/wx/bookctrl.h | 4 +++- src/msw/notebook.cpp | 13 ++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/wx/bookctrl.h b/include/wx/bookctrl.h index 2564e9c617..35d7bb45e9 100644 --- a/include/wx/bookctrl.h +++ b/include/wx/bookctrl.h @@ -38,7 +38,7 @@ enum wxBK_HITTEST_NOWHERE = 1, // not on tab wxBK_HITTEST_ONICON = 2, // on icon wxBK_HITTEST_ONLABEL = 4, // on label - wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL, + wxBK_HITTEST_ONITEM = 16, // on tab control but not on its icon or label wxBK_HITTEST_ONPAGE = 8 // not on tab control, but over the selected page }; diff --git a/interface/wx/bookctrl.h b/interface/wx/bookctrl.h index 8545629faa..7789496765 100644 --- a/interface/wx/bookctrl.h +++ b/interface/wx/bookctrl.h @@ -8,6 +8,8 @@ /** Bit flags returned by wxBookCtrl::HitTest(). + Only one of wxBK_HITTEST_ONICON, wxBK_HITTEST_ONLABEL, wxBK_HITTEST_ONITEM + bits is set if point is over a tab. Notice that wxOSX currently only returns wxBK_HITTEST_ONLABEL or wxBK_HITTEST_NOWHERE and never the other values, so you should only test for these two in the code that should be portable under OS X. @@ -24,7 +26,7 @@ enum wxBK_HITTEST_ONLABEL = 4, /// The point if over a tab item but not over its icon or label. - wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL, + wxBK_HITTEST_ONITEM = 16, /// The point is over the page area. wxBK_HITTEST_ONPAGE = 8 diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index e5282afdb6..67e5fa2f7f 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -750,15 +750,18 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const *flags = 0; if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) + { + wxASSERT( item == wxNOT_FOUND ); *flags |= wxBK_HITTEST_NOWHERE; - if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) + if ( GetPageSize().Contains(pt) ) + *flags |= wxBK_HITTEST_ONPAGE; + } + else if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) *flags |= wxBK_HITTEST_ONITEM; - if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) + else if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) *flags |= wxBK_HITTEST_ONICON; - if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) + else if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) *flags |= wxBK_HITTEST_ONLABEL; - if ( item == wxNOT_FOUND && GetPageSize().Contains(pt) ) - *flags |= wxBK_HITTEST_ONPAGE; } return item;