wxNotebook::HitTest() for wxMSW added (patch 748469)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21715 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-07-06 21:02:24 +00:00
parent ae79d31557
commit e450aa692b
6 changed files with 84 additions and 25 deletions

View File

@@ -197,6 +197,36 @@ the platform and so\rtfsp
\helpref{wxNotebookEvent::GetSelection}{wxnotebookeventgetselection} should be \helpref{wxNotebookEvent::GetSelection}{wxnotebookeventgetselection} should be
used instead in this case. 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} \membersection{wxNotebook::InsertPage}\label{wxnotebookinsertpage}
\func{bool}{InsertPage}{\param{int}{ index}, \param{wxNotebookPage*}{ page}, \func{bool}{InsertPage}{\param{int}{ index}, \param{wxNotebookPage*}{ page},

View File

@@ -27,15 +27,6 @@
// wxNotebook // 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 class WXDLLEXPORT wxNotebook : public wxNotebookBase
{ {
public: public:
@@ -103,6 +94,7 @@ public:
// ---------- // ----------
// remove all pages // remove all pages
bool DeleteAllPages(); bool DeleteAllPages();
// inserts a new page to the notebook (it will be deleted ny the notebook, // 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. // don't delete it yourself). If bSelect, this page becomes active.
bool InsertPage(int nPage, bool InsertPage(int nPage,
@@ -118,9 +110,10 @@ public:
// Windows only: attempts to apply the UX theme page background to this page // Windows only: attempts to apply the UX theme page background to this page
void ApplyThemeBackground(wxWindow* window, const wxColour& colour); void ApplyThemeBackground(wxWindow* window, const wxColour& colour);
// Hit test // hit test
int HitTest(const wxPoint& pt, long& flags); virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
// calculate the size of the notebook from the size of its page
// calculate the size of the notebook from the size of its page
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
// callbacks // callbacks

View File

@@ -28,6 +28,19 @@
#include "wx/dynarray.h" #include "wx/dynarray.h"
#include "wx/imaglist.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 // types
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -144,6 +157,13 @@ public:
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
virtual int SetSelection(int nPage) = 0; 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 // cycle thru the tabs
void AdvanceSelection(bool forward = TRUE) void AdvanceSelection(bool forward = TRUE)
{ {

View File

@@ -105,8 +105,7 @@ public:
// hit testing // hit testing
// ----------- // -----------
// return the tab at this position or -1 if none virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
int HitTest(const wxPoint& pt) const;
// input handling // input handling
// -------------- // --------------

View File

@@ -561,25 +561,31 @@ bool wxNotebook::InsertPage(int nPage,
return TRUE; return TRUE;
} }
// Hit test int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
int wxNotebook::HitTest(const wxPoint& pt, long& flags)
{ {
TC_HITTESTINFO hitTestInfo; TC_HITTESTINFO hitTestInfo;
hitTestInfo.pt.x = pt.x; hitTestInfo.pt.x = pt.x;
hitTestInfo.pt.y = pt.y; hitTestInfo.pt.y = pt.y;
int item = TabCtrl_HitTest( (HWND) GetHWND(), & hitTestInfo ) ; int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
flags = 0;
if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) if ( flags )
flags |= wxNB_HITTEST_NOWHERE; {
if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) *flags = 0;
flags |= wxNB_HITTEST_ONICON;
if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
flags |= wxNB_HITTEST_ONLABEL; *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; return item;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxNotebook callbacks // wxNotebook callbacks
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -585,8 +585,11 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
// wxNotebook geometry // 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 // first check that it is in this window at all
if ( !GetClientRect().Inside(pt) ) if ( !GetClientRect().Inside(pt) )
{ {
@@ -627,7 +630,15 @@ int wxNotebook::HitTest(const wxPoint& pt) const
GetTabSize(n, &rectTabs.width, &rectTabs.height); GetTabSize(n, &rectTabs.width, &rectTabs.height);
if ( rectTabs.Inside(pt) ) if ( rectTabs.Inside(pt) )
{
if ( flags )
{
// TODO: be more precise
*flags = wxNB_HITTEST_ONITEM;
}
return n; return n;
}
// move the rectTabs to the next tab // move the rectTabs to the next tab
if ( IsVertical() ) if ( IsVertical() )