From e450aa692b887adbae4350896f6c90ec8e1368e3 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sun, 6 Jul 2003 21:02:24 +0000
Subject: [PATCH] wxNotebook::HitTest() for wxMSW added (patch 748469)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21715 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/notebook.tex | 30 ++++++++++++++++++++++++++++++
 include/wx/msw/notebook.h  | 17 +++++------------
 include/wx/notebook.h      | 20 ++++++++++++++++++++
 include/wx/univ/notebook.h |  3 +--
 src/msw/notebook.cpp       | 26 ++++++++++++++++----------
 src/univ/notebook.cpp      | 13 ++++++++++++-
 6 files changed, 84 insertions(+), 25 deletions(-)

diff --git a/docs/latex/wx/notebook.tex b/docs/latex/wx/notebook.tex
index 29e87d94c6..332f441a63 100644
--- a/docs/latex/wx/notebook.tex
+++ b/docs/latex/wx/notebook.tex
@@ -197,6 +197,36 @@ the platform and so\rtfsp
 \helpref{wxNotebookEvent::GetSelection}{wxnotebookeventgetselection} should be
 used instead in this case.
 
+\membersection{wxNotebook::HitTest}\label{wxnotebookhittest}
+
+\func{int}{HitTest}{\param{const wxPoint\&}{ pt}, \param{long}{ *flags = {\tt NULL}}}
+
+Returns the index of the tab at the specified position or {\tt wxNOT\_FOUND} 
+if none. If {\it flags} parameter is non {\tt NULL}, the position of the point
+inside the tab is returned as well.
+
+{\bf NB: } This method is currently only implemented under wxMSW and wxUniv.
+
+\wxheading{Parameters}
+
+\docparam{pt}{Specifies the point for the hit test.}
+
+\docparam{flags}{Return value for detailed information. One of the following values:
+\twocolwidtha{7cm}
+\begin{twocollist}\itemsep=0pt
+\twocolitem{{\bf wxNB\_HITTEST\_NOWHERE}}{There was no tab under this point.}
+\twocolitem{{\bf wxNB\_HITTEST\_ONICON}}{The point was over an icon (currently wxMSW only).}
+\twocolitem{{\bf wxNB\_HITTEST\_ONLABEL}}{The point was over a label (currently wxMSW only).}
+\twocolitem{{\bf wxNB\_HITTEST\_ONITEM}}{The point was over an item, but not on the label or icon.}
+\end{twocollist}
+}
+
+\wxheading{Return value}
+
+Returns the zero-based tab index or {\tt wxNOT\_FOUND} if there is no tab is at
+the specified position.
+
+
 \membersection{wxNotebook::InsertPage}\label{wxnotebookinsertpage}
 
 \func{bool}{InsertPage}{\param{int}{ index}, \param{wxNotebookPage*}{ page},
diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h
index 714f15cda7..d85e7ce96c 100644
--- a/include/wx/msw/notebook.h
+++ b/include/wx/msw/notebook.h
@@ -27,15 +27,6 @@
 // wxNotebook
 // ----------------------------------------------------------------------------
 
-/*
- * Flags returned by HitTest
- */
-
-#define wxNB_HITTEST_NOWHERE           1
-#define wxNB_HITTEST_ONICON            2
-#define wxNB_HITTEST_ONLABEL           4
-#define wxNB_HITTEST_ONITEM            6
-
 class WXDLLEXPORT wxNotebook : public wxNotebookBase
 {
 public:
@@ -103,6 +94,7 @@ public:
   // ----------
     // remove all pages
   bool DeleteAllPages();
+
     // inserts a new page to the notebook (it will be deleted ny the notebook,
     // don't delete it yourself). If bSelect, this page becomes active.
   bool InsertPage(int nPage,
@@ -118,9 +110,10 @@ public:
     // Windows only: attempts to apply the UX theme page background to this page
   void ApplyThemeBackground(wxWindow* window, const wxColour& colour);
 
-  // Hit test
-  int HitTest(const wxPoint& pt, long& flags);
-  // calculate the size of the notebook from the size of its page
+    // hit test
+  virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
+
+    // calculate the size of the notebook from the size of its page
   virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
 
   // callbacks
diff --git a/include/wx/notebook.h b/include/wx/notebook.h
index 03fb928e88..ec0dfa5ba3 100644
--- a/include/wx/notebook.h
+++ b/include/wx/notebook.h
@@ -28,6 +28,19 @@
 #include "wx/dynarray.h"
 #include "wx/imaglist.h"
 
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// wxNotebook hit results
+enum
+{
+    wxNB_HITTEST_NOWHERE = 1,   // not on tab
+    wxNB_HITTEST_ONICON  = 2,   // on icon
+    wxNB_HITTEST_ONLABEL = 4,   // on label
+    wxNB_HITTEST_ONITEM  = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL
+};
+
 // ----------------------------------------------------------------------------
 // types
 // ----------------------------------------------------------------------------
@@ -144,6 +157,13 @@ public:
     // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
     virtual int SetSelection(int nPage) = 0;
 
+    // hit test, returns which tab is hit and, optionally, where (icon, label)
+    // (not implemented on all platforms)
+    virtual int HitTest(const wxPoint& pt, long *flags = NULL) const
+    {
+        return wxNOT_FOUND;
+    }
+
     // cycle thru the tabs
     void AdvanceSelection(bool forward = TRUE)
     {
diff --git a/include/wx/univ/notebook.h b/include/wx/univ/notebook.h
index e5742ddc0f..3b3ef0c0c7 100644
--- a/include/wx/univ/notebook.h
+++ b/include/wx/univ/notebook.h
@@ -105,8 +105,7 @@ public:
     // hit testing
     // -----------
 
-    // return the tab at this position or -1 if none
-    int HitTest(const wxPoint& pt) const;
+    virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
 
     // input handling
     // --------------
diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp
index dbca8ed2d2..1b82f24ba1 100644
--- a/src/msw/notebook.cpp
+++ b/src/msw/notebook.cpp
@@ -561,25 +561,31 @@ bool wxNotebook::InsertPage(int nPage,
     return TRUE;
 }
 
-// Hit test
-int wxNotebook::HitTest(const wxPoint& pt, long& flags)
+int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 {
     TC_HITTESTINFO hitTestInfo;
     hitTestInfo.pt.x = pt.x;
     hitTestInfo.pt.y = pt.y;
-    int item = TabCtrl_HitTest( (HWND) GetHWND(), & hitTestInfo ) ;
-    flags = 0;
+    int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
 
-    if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
-        flags |= wxNB_HITTEST_NOWHERE;
-    if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
-        flags |= wxNB_HITTEST_ONICON;
-    if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
-        flags |= wxNB_HITTEST_ONLABEL;
+    if ( flags )
+    {
+        *flags = 0;
+
+        if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
+            *flags |= wxNB_HITTEST_NOWHERE;
+        if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
+            *flags |= wxNB_HITTEST_ONITEM;
+        if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
+            *flags |= wxNB_HITTEST_ONICON;
+        if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
+            *flags |= wxNB_HITTEST_ONLABEL;
+    }
 
     return item;
 }
 
+
 // ----------------------------------------------------------------------------
 // wxNotebook callbacks
 // ----------------------------------------------------------------------------
diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp
index c1d4f7fdc0..84c4761c5f 100644
--- a/src/univ/notebook.cpp
+++ b/src/univ/notebook.cpp
@@ -585,8 +585,11 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
 // wxNotebook geometry
 // ----------------------------------------------------------------------------
 
-int wxNotebook::HitTest(const wxPoint& pt) const
+int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 {
+    if ( flags )
+        *flags = wxNB_HITTEST_NOWHERE;
+
     // first check that it is in this window at all
     if ( !GetClientRect().Inside(pt) )
     {
@@ -627,7 +630,15 @@ int wxNotebook::HitTest(const wxPoint& pt) const
         GetTabSize(n, &rectTabs.width, &rectTabs.height);
 
         if ( rectTabs.Inside(pt) )
+        {
+            if ( flags )
+            {
+                // TODO: be more precise
+                *flags = wxNB_HITTEST_ONITEM;
+            }
+
             return n;
+        }
 
         // move the rectTabs to the next tab
         if ( IsVertical() )
-- 
2.50.0

