\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.}
+\twocolitem{{\bf wxNB\_HITTEST\_ONPAGE}}{The point was over a currently selected page, not over any tab. Note that this flag is present only if {\tt wxNOT\_FOUND} is returned.}
\end{twocollist}
}
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
+ wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL,
+ wxNB_HITTEST_ONPAGE = 8 // not on tab control, but over the selected page
};
typedef wxWindow wxNotebookPage; // so far, any window can be a page
const wxString& name = wxEmptyString);
+ // implement base class virtuals
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const;
virtual void SetImageList(wxImageList *imageList);
virtual bool DeleteAllPages();
+ virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
+
+ // methods which are not part of base wxBookctrl API
+
+ // get the underlying toolbar
wxToolBarBase* GetToolBar() const { return (wxToolBarBase*)m_bookctrl; }
- // Not part of the wxBookctrl API, but must be called in OnIdle or
- // by application to realize the toolbar and select the initial page.
+ // must be called in OnIdle or by application to realize the toolbar and
+ // select the initial page.
void Realize();
protected:
bool m_needsRealizing;
// maximum bitmap size
- wxSize m_maxBitmapSize;
+ wxSize m_maxBitmapSize;
private:
// common part of all constructors
#include "wx/imaglist.h"
#include "wx/artprov.h"
+#include "wx/cshelp.h"
+#include "wx/utils.h"
#include "notebook.h"
#if !defined(__WXMSW__) && !defined(__WXPM__)
}
MyFrame::MyFrame()
- : wxFrame(NULL, wxID_ANY, wxString(wxT("wxWidgets book controls sample")))
+ : wxFrame(NULL, wxID_ANY, wxString(wxT("wxWidgets book controls sample")))
{
#if wxUSE_NOTEBOOK
m_type = Type_Notebook;
menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-8"));
menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-9"));
- wxMenu *menuOperations = new wxMenu;
- menuOperations->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
- menuOperations->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
- menuOperations->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
- menuOperations->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
- menuOperations->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
+ wxMenu *menuPageOperations = new wxMenu;
+ menuPageOperations->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
+ menuPageOperations->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
+ menuPageOperations->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
+ menuPageOperations->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
+ menuPageOperations->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
#if wxUSE_TREEBOOK
- menuOperations->AppendSeparator();
- menuOperations->Append(ID_ADD_PAGE_BEFORE, wxT("Insert page &before\tAlt-B"));
- menuOperations->Append(ID_ADD_SUB_PAGE, wxT("Add s&ub page\tAlt-U"));
+ menuPageOperations->AppendSeparator();
+ menuPageOperations->Append(ID_ADD_PAGE_BEFORE, wxT("Insert page &before\tAlt-B"));
+ menuPageOperations->Append(ID_ADD_SUB_PAGE, wxT("Add s&ub page\tAlt-U"));
#endif
+ wxMenu *menuOperations = new wxMenu;
+ menuOperations->Append(ID_HITTEST, wxT("&Hit test\tCtrl-H"));
+
wxMenu *menuFile = new wxMenu;
menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, wxT("&File"));
+ menuBar->Append(menuPageOperations, wxT("&Pages"));
menuBar->Append(menuOperations, wxT("&Operations"));
SetMenuBar(menuBar);
EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage)
EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
+ EVT_MENU(ID_HITTEST, MyFrame::OnHitTest)
+
// Book controls
#if wxUSE_NOTEBOOK
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnNotebook)
EVT_IDLE(MyFrame::OnIdle)
END_EVENT_TABLE()
+void MyFrame::AddFlagStrIfFlagPresent(wxString & flagStr, long flags, long flag, const wxChar * flagName) const
+{
+ if( (flags & flag) == flag )
+ {
+ if( !flagStr.empty() )
+ flagStr += _T(" | ");
+ flagStr += flagName;
+ }
+}
+
+void MyFrame::OnHitTest(wxCommandEvent& WXUNUSED(event))
+{
+ wxBookCtrlBase * book = GetCurrentBook();
+ const wxPoint pt = ::wxGetMousePosition();
+
+ long flags;
+ int pagePos = book->HitTest( book->ScreenToClient(pt), &flags );
+
+ wxString flagsStr;
+
+ AddFlagStrIfFlagPresent( flagsStr, flags, wxNB_HITTEST_NOWHERE, _T("wxNB_HITTEST_NOWHERE") );
+ AddFlagStrIfFlagPresent( flagsStr, flags, wxNB_HITTEST_ONICON, _T("wxNB_HITTEST_ONICON") );
+ AddFlagStrIfFlagPresent( flagsStr, flags, wxNB_HITTEST_ONLABEL, _T("wxNB_HITTEST_ONLABEL") );
+ AddFlagStrIfFlagPresent( flagsStr, flags, wxNB_HITTEST_ONPAGE, _T("wxNB_HITTEST_ONPAGE") );
+
+ wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
+ pt.x,
+ pt.y,
+ pagePos,
+ flagsStr.c_str());
+}
+
void MyFrame::OnType(wxCommandEvent& event)
{
m_type = wx_static_cast(BookType, event.GetId() - ID_BOOK_NOTEBOOK);
wxPanel *MyFrame::CreateNewPage() const
{
wxPanel *panel = new wxPanel(m_bookCtrl, wxID_ANY );
+
(void) new wxButton(panel, wxID_ANY, wxT("First button"), wxPoint(10, 10));
(void) new wxButton(panel, wxID_ANY, wxT("Second button"), wxPoint(50, 100));
void OnAddSubPage(wxCommandEvent& event);
void OnAddPageBefore(wxCommandEvent& event);
+ void OnHitTest(wxCommandEvent& event);
+
void OnBookCtrl(wxBookCtrlBaseEvent& event);
#if wxUSE_NOTEBOOK
void OnNotebook(wxNotebookEvent& event) { OnBookCtrl(event); }
void RecreateBook();
wxPanel *CreateNewPage() const;
int TranslateBookFlag(int nb, int lb, int chb, int tbk, int toolbk) const;
+ void AddFlagStrIfFlagPresent(wxString & flagStr, long flags, long flag, const wxChar * flagName) const;
// Sample setup
enum BookType
ID_DELETE_LAST_PAGE,
ID_NEXT_PAGE,
ID_ADD_PAGE_BEFORE,
- ID_ADD_SUB_PAGE
+ ID_ADD_SUB_PAGE,
+
+ ID_HITTEST
};
/*
page = GetPage((size_t)pagePos);
}
}
-
- if ( !page )
+ else // event.GetOrigin() != wxHelpEvent::Origin_HelpButton
{
+ // if event came from keyboard then show the current page help
page = GetCurrentPage();
}
wxBookCtrlBase::OnSize(event);
}
-int wxListbook::HitTest(const wxPoint& pt, long * WXUNUSED(flags)) const
+int wxListbook::HitTest(const wxPoint& pt, long *flags) const
{
int pagePos = wxNOT_FOUND;
- const wxPoint clientPt = ClientToScreen(GetListView()->ScreenToClient(pt));
+ if ( flags )
+ *flags = wxNB_HITTEST_NOWHERE;
- if ( wxRect(GetListView()->GetSize()).Inside(clientPt) )
+ // convert from listbook control coordinates to list control coordinates
+ const wxListView * const list = GetListView();
+ const wxPoint listPt = list->ScreenToClient(ClientToScreen(pt));
+
+ // is the point inside list control?
+ if ( wxRect(list->GetSize()).Inside(listPt) )
{
int flagsList;
- pagePos = GetListView()->HitTest(clientPt, flagsList);
+ pagePos = list->HitTest(listPt, flagsList);
- if ( !(flagsList & wxLIST_HITTEST_ONITEM) )
+ if ( flags )
{
- pagePos = wxNOT_FOUND;
+ if ( pagePos != wxNOT_FOUND )
+ *flags = 0;
+
+ if ( flagsList & (wxLIST_HITTEST_ONITEMICON |
+ wxLIST_HITTEST_ONITEMSTATEICON ) )
+ *flags |= wxNB_HITTEST_ONICON;
+
+ if ( flagsList & wxLIST_HITTEST_ONITEMLABEL )
+ *flags |= wxNB_HITTEST_ONLABEL;
}
}
+ else // not over list control at all
+ {
+ if ( flags && GetPageRect().Inside(pt) )
+ *flags |= wxNB_HITTEST_ONPAGE;
+ }
return pagePos;
}
DoSize();
}
+int wxToolbook::HitTest(const wxPoint& pt, long *flags) const
+{
+ int pagePos = wxNOT_FOUND;
+
+ if ( flags )
+ *flags = wxNB_HITTEST_NOWHERE;
+
+ // convert from wxToolbook coordinates to wxToolBar ones
+ const wxToolBarBase * const tbar = GetToolBar();
+ const wxPoint tbarPt = tbar->ScreenToClient(ClientToScreen(pt));
+
+ // is the point over the toolbar?
+ if ( wxRect(tbar->GetSize()).Inside(tbarPt) )
+ {
+ const wxToolBarToolBase * const
+ tool = tbar->FindToolForPosition(tbarPt.x, tbarPt.y);
+
+ if ( tool )
+ {
+ pagePos = tbar->GetToolPos(tool->GetId());
+ if ( flags )
+ *flags = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL;
+ }
+ }
+ else // not over the toolbar
+ {
+ if ( flags && GetPageRect().Inside(pt) )
+ *flags |= wxNB_HITTEST_ONPAGE;
+ }
+
+ return pagePos;
+}
+
void wxToolbook::OnIdle(wxIdleEvent& event)
{
if (m_needsRealizing)
// wxTreebook geometry management
// ----------------------------------------------------------------------------
-int wxTreebook::HitTest(wxPoint const & pt, long * WXUNUSED(flags)) const
+int wxTreebook::HitTest(wxPoint const & pt, long * flags) const
{
int pagePos = wxNOT_FOUND;
- wxTreeCtrl * const tree = GetTreeCtrl();
- const wxPoint treePt = ClientToScreen(tree->ScreenToClient(pt));
+ if ( flags )
+ *flags = wxNB_HITTEST_NOWHERE;
+ // convert from wxTreebook coorindates to wxTreeCtrl ones
+ const wxTreeCtrl * const tree = GetTreeCtrl();
+ const wxPoint treePt = tree->ScreenToClient(ClientToScreen(pt));
+
+ // is it over the tree?
if ( wxRect(tree->GetSize()).Inside(treePt) )
{
int flagsTree;
{
pagePos = DoInternalFindPageById(id);
}
+
+ if ( flags )
+ {
+ if ( pagePos != wxNOT_FOUND )
+ *flags = 0;
+
+ if ( flagsTree & (wxTREE_HITTEST_ONITEMBUTTON |
+ wxTREE_HITTEST_ONITEMICON |
+ wxTREE_HITTEST_ONITEMSTATEICON) )
+ *flags |= wxNB_HITTEST_ONICON;
+
+ if ( flagsTree & wxTREE_HITTEST_ONITEMLABEL )
+ *flags |= wxNB_HITTEST_ONLABEL;
+ }
+ }
+ else // not over the tree
+ {
+ if ( flags && GetPageRect().Inside( pt ) )
+ *flags |= wxNB_HITTEST_ONPAGE;
}
return pagePos;
}
if ( flags )
+ {
*flags = wxNB_HITTEST_NOWHERE;
+ wxWindowBase * page = GetCurrentPage();
+ if ( page )
+ {
+ // rect origin is in notebook's parent coordinates
+ wxRect rect = page->GetRect();
+
+ // adjust it to the notebook's coordinates
+ wxPoint pos = GetPosition();
+ rect.x -= pos.x;
+ rect.y -= pos.y;
+ if ( rect.Inside( pt ) )
+ *flags |= wxNB_HITTEST_ONPAGE;
+ }
+ }
return wxNOT_FOUND;
}
*flags |= wxNB_HITTEST_ONICON;
if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
*flags |= wxNB_HITTEST_ONLABEL;
+ if ( item == wxNOT_FOUND && GetPageSize().Inside(pt) )
+ *flags |= wxNB_HITTEST_ONPAGE;
}
return item;