From 851b88c310ac064e826dfd011d02c6dc5301fc35 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 May 2006 02:09:44 +0000 Subject: [PATCH] moved wxNotebook::HitTest() to the base book control class; implemented it for wxList/Treebook git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/bookctrl.h | 17 +++++++++-------- include/wx/listbook.h | 3 +++ include/wx/treebook.h | 3 +++ src/generic/listbkg.cpp | 20 ++++++++++++++++++++ src/generic/treebkg.cpp | 35 ++++++++++++++++++++++++++++------- 5 files changed, 63 insertions(+), 15 deletions(-) diff --git a/include/wx/bookctrl.h b/include/wx/bookctrl.h index 02ad3f6f5e..2bdf599224 100644 --- a/include/wx/bookctrl.h +++ b/include/wx/bookctrl.h @@ -119,14 +119,8 @@ public: virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; // get/set size of area between book control area and page area - inline unsigned int GetInternalBorder() const - { - return m_internalBorder; - } - void SetInternalBorder(unsigned int internalBorder) - { - m_internalBorder = internalBorder; - } + unsigned int GetInternalBorder() const { return m_internalBorder; } + void SetInternalBorder(unsigned int border) { m_internalBorder = border; } // Sets/gets the margin around the controller void SetControlMargin(int margin) { m_controlMargin = margin; } @@ -198,6 +192,13 @@ public: } } + // hit test: returns which page is hit and, optionally, where (icon, label) + virtual int HitTest(const wxPoint& WXUNUSED(pt), + long * WXUNUSED(flags) = NULL) const + { + return wxNOT_FOUND; + } + protected: // Should we accept NULL page pointers in Add/InsertPage()? // diff --git a/include/wx/listbook.h b/include/wx/listbook.h index 61f06d5731..b8022730f7 100644 --- a/include/wx/listbook.h +++ b/include/wx/listbook.h @@ -78,6 +78,9 @@ protected: // get the size which the list control should have virtual wxSize GetControllerSize() const; + // return the page corresponding to the tab at the specified position + virtual int HitTest(const wxPoint& pt, long *flags = NULL) const; + // event handlers void OnListSelected(wxListEvent& event); void OnSize(wxSizeEvent& event); diff --git a/include/wx/treebook.h b/include/wx/treebook.h index c7db5c2477..325aaa3521 100644 --- a/include/wx/treebook.h +++ b/include/wx/treebook.h @@ -144,6 +144,9 @@ protected: // This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages) virtual bool AllowNullPage() const { return true; } + // return the page corresponding to the tab at the specified position + virtual int HitTest(const wxPoint& pt, long *flags = NULL) const; + // event handlers void OnTreeSelectionChange(wxTreeEvent& event); void OnTreeNodeExpandedCollapsed(wxTreeEvent& event); diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index d3b9771817..f096095e55 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -161,6 +161,26 @@ void wxListbook::OnSize(wxSizeEvent& event) wxBookCtrlBase::OnSize(event); } +int wxListbook::HitTest(const wxPoint& pt, long * WXUNUSED(flags)) const +{ + int pagePos = wxNOT_FOUND; + + const wxPoint clientPt = ClientToScreen(GetListView()->ScreenToClient(pt)); + + if ( wxRect(GetListView()->GetSize()).Inside(clientPt) ) + { + int flagsList; + pagePos = GetListView()->HitTest(clientPt, flagsList); + + if ( !(flagsList & wxLIST_HITTEST_ONITEM) ) + { + pagePos = wxNOT_FOUND; + } + } + + return pagePos; +} + wxSize wxListbook::CalcSizeFromPage(const wxSize& sizePage) const { // we need to add the size of the list control and the border between diff --git a/src/generic/treebkg.cpp b/src/generic/treebkg.cpp index 4bce15eca2..57593a5bb1 100644 --- a/src/generic/treebkg.cpp +++ b/src/generic/treebkg.cpp @@ -650,6 +650,20 @@ int wxTreebook::DoSetSelection(size_t pagePos) return oldSel; } +wxTreebookPage *wxTreebook::DoGetCurrentPage() const +{ + if ( m_selection == wxNOT_FOUND ) + return NULL; + + wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection); + if ( !page && m_actualSelection != wxNOT_FOUND ) + { + page = wxBookCtrlBase::GetPage(m_actualSelection); + } + + return page; +} + void wxTreebook::SetImageList(wxImageList *imageList) { wxBookCtrlBase::SetImageList(imageList); @@ -709,18 +723,25 @@ void wxTreebook::OnTreeNodeExpandedCollapsed(wxTreeEvent & event) // wxTreebook geometry management // ---------------------------------------------------------------------------- -wxTreebookPage * wxTreebook::DoGetCurrentPage() const +int wxTreebook::HitTest(wxPoint const & pt, long * WXUNUSED(flags)) const { - if ( m_selection == wxNOT_FOUND ) - return NULL; + int pagePos = wxNOT_FOUND; - wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection); - if ( !page && m_actualSelection != wxNOT_FOUND ) + wxTreeCtrl * const tree = GetTreeCtrl(); + const wxPoint treePt = ClientToScreen(tree->ScreenToClient(pt)); + + if ( wxRect(tree->GetSize()).Inside(treePt) ) { - page = wxBookCtrlBase::GetPage(m_actualSelection); + int flagsTree; + wxTreeItemId id = tree->HitTest(treePt, flagsTree); + + if ( id.IsOk() && (flagsTree & wxTREE_HITTEST_ONITEM) ) + { + pagePos = DoInternalFindPageById(id); + } } - return page; + return pagePos; } #endif // wxUSE_TREEBOOK -- 2.45.2