2005-10-09 18:40:36 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/treebook.h
|
|
|
|
// Purpose: wxTreebook: wxNotebook-like control presenting pages in a tree
|
|
|
|
// Author: Evgeniy Tarassov, Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2005-09-15
|
|
|
|
// Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_TREEBOOK_H_
|
|
|
|
#define _WX_TREEBOOK_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
|
|
|
|
#include "wx/bookctrl.h"
|
2012-05-15 10:03:57 +00:00
|
|
|
#include "wx/containr.h"
|
2018-03-24 18:21:57 +00:00
|
|
|
#include "wx/treebase.h" // for wxTreeItemId
|
2018-03-24 18:18:29 +00:00
|
|
|
#include "wx/vector.h"
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
typedef wxWindow wxTreebookPage;
|
|
|
|
|
2018-03-24 18:21:57 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTreebook
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-05-15 10:03:57 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxTreebook : public wxNavigationEnabled<wxBookCtrlBase>
|
2005-10-09 18:40:36 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructors and such
|
|
|
|
// ---------------------
|
|
|
|
|
|
|
|
// Default ctor doesn't create the control, use Create() afterwards
|
|
|
|
wxTreebook()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ctor creates the tree book control
|
|
|
|
wxTreebook(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2005-10-21 18:53:51 +00:00
|
|
|
long style = wxBK_DEFAULT,
|
2005-10-09 18:40:36 +00:00
|
|
|
const wxString& name = wxEmptyString)
|
|
|
|
{
|
|
|
|
(void)Create(parent, id, pos, size, style, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Really creates the control
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2005-10-21 18:53:51 +00:00
|
|
|
long style = wxBK_DEFAULT,
|
2005-10-09 18:40:36 +00:00
|
|
|
const wxString& name = wxEmptyString);
|
|
|
|
|
|
|
|
|
|
|
|
// Page insertion operations
|
|
|
|
// -------------------------
|
|
|
|
|
|
|
|
// Notice that page pointer may be NULL in which case the next non NULL
|
|
|
|
// page (usually the first child page of a node) is shown when this page is
|
|
|
|
// selected
|
|
|
|
|
|
|
|
// Inserts a new page just before the page indicated by page.
|
|
|
|
// The new page is placed on the same level as page.
|
|
|
|
virtual bool InsertPage(size_t pos,
|
|
|
|
wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2014-03-30 00:02:23 +00:00
|
|
|
int imageId = NO_IMAGE) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Inserts a new sub-page to the end of children of the page at given pos.
|
2006-02-05 12:27:20 +00:00
|
|
|
virtual bool InsertSubPage(size_t pos,
|
|
|
|
wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2011-08-21 14:08:49 +00:00
|
|
|
int imageId = NO_IMAGE);
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Adds a new page at top level after all other pages.
|
|
|
|
virtual bool AddPage(wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2014-03-30 00:02:23 +00:00
|
|
|
int imageId = NO_IMAGE) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Adds a new child-page to the last top-level page inserted.
|
|
|
|
// Useful when constructing 1 level tree structure.
|
|
|
|
virtual bool AddSubPage(wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2011-08-21 14:08:49 +00:00
|
|
|
int imageId = NO_IMAGE);
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Deletes the page and ALL its children. Could trigger page selection
|
|
|
|
// change in a case when selected page is removed. In that case its parent
|
|
|
|
// is selected (or the next page if no parent).
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool DeletePage(size_t pos) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Tree operations
|
|
|
|
// ---------------
|
|
|
|
|
|
|
|
// Gets the page node state -- node is expanded or collapsed
|
|
|
|
virtual bool IsNodeExpanded(size_t pos) const;
|
|
|
|
|
|
|
|
// Expands or collapses the page node. Returns the previous state.
|
|
|
|
// May generate page changing events (if selected page
|
|
|
|
// is under the collapsed branch, then parent is autoselected).
|
|
|
|
virtual bool ExpandNode(size_t pos, bool expand = true);
|
|
|
|
|
|
|
|
// shortcut for ExpandNode(pos, false)
|
|
|
|
bool CollapseNode(size_t pos) { return ExpandNode(pos, false); }
|
|
|
|
|
|
|
|
// get the parent page or wxNOT_FOUND if this is a top level page
|
|
|
|
int GetPageParent(size_t pos) const;
|
|
|
|
|
2005-10-21 18:53:51 +00:00
|
|
|
// the tree control we use for showing the pages index tree
|
|
|
|
wxTreeCtrl* GetTreeCtrl() const { return (wxTreeCtrl*)m_bookctrl; }
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Standard operations inherited from wxBookCtrlBase
|
|
|
|
// -------------------------------------------------
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool SetPageText(size_t n, const wxString& strText) wxOVERRIDE;
|
|
|
|
virtual wxString GetPageText(size_t n) const wxOVERRIDE;
|
|
|
|
virtual int GetPageImage(size_t n) const wxOVERRIDE;
|
|
|
|
virtual bool SetPageImage(size_t n, int imageId) wxOVERRIDE;
|
|
|
|
virtual int SetSelection(size_t n) wxOVERRIDE { return DoSetSelection(n, SetSelection_SendEvent); }
|
|
|
|
virtual int ChangeSelection(size_t n) wxOVERRIDE { return DoSetSelection(n); }
|
|
|
|
virtual int HitTest(const wxPoint& pt, long *flags = NULL) const wxOVERRIDE;
|
|
|
|
virtual void SetImageList(wxImageList *imageList) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
virtual void AssignImageList(wxImageList *imageList);
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool DeleteAllPages() wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
protected:
|
2006-02-08 21:47:09 +00:00
|
|
|
// Implementation of a page removal. See DeletPage for comments.
|
2014-03-30 00:02:23 +00:00
|
|
|
wxTreebookPage *DoRemovePage(size_t pos) wxOVERRIDE;
|
2006-02-08 21:47:09 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
// This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages)
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool AllowNullPage() const wxOVERRIDE { return true; }
|
2018-03-24 23:13:15 +00:00
|
|
|
virtual wxWindow *DoGetNonNullPage(size_t page) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void OnTreeSelectionChange(wxTreeEvent& event);
|
|
|
|
void OnTreeNodeExpandedCollapsed(wxTreeEvent& event);
|
|
|
|
|
2018-03-24 23:13:15 +00:00
|
|
|
// array of tree item ids corresponding to the page indices
|
2018-03-24 18:18:29 +00:00
|
|
|
wxVector<wxTreeItemId> m_treeIds;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// The real implementations of page insertion functions
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// All DoInsert/Add(Sub)Page functions add the page into :
|
|
|
|
// - the base class
|
|
|
|
// - the tree control
|
|
|
|
// - update the index/TreeItemId corespondance array
|
|
|
|
bool DoInsertPage(size_t pos,
|
|
|
|
wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2011-08-21 14:08:49 +00:00
|
|
|
int imageId = NO_IMAGE);
|
2005-10-09 18:40:36 +00:00
|
|
|
bool DoInsertSubPage(size_t pos,
|
|
|
|
wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2011-08-21 14:08:49 +00:00
|
|
|
int imageId = NO_IMAGE);
|
2005-10-09 18:40:36 +00:00
|
|
|
bool DoAddSubPage(wxWindow *page,
|
|
|
|
const wxString& text,
|
|
|
|
bool bSelect = false,
|
2011-08-21 14:08:49 +00:00
|
|
|
int imageId = NO_IMAGE);
|
2005-10-09 18:40:36 +00:00
|
|
|
|
2018-03-24 23:13:15 +00:00
|
|
|
// Overridden methods used by the base class DoSetSelection()
|
|
|
|
// implementation.
|
|
|
|
void UpdateSelectedPage(size_t newsel) wxOVERRIDE;
|
|
|
|
wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE;
|
|
|
|
void MakeChangedEvent(wxBookCtrlEvent &event) wxOVERRIDE;
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// Does the selection update. Called from page insertion functions
|
|
|
|
// to update selection if the selected page was pushed by the newly inserted
|
|
|
|
void DoUpdateSelection(bool bSelect, int page);
|
|
|
|
|
|
|
|
|
|
|
|
// Operations on the internal private members of the class
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// Returns the page TreeItemId for the page.
|
|
|
|
// Or, if the page index is incorrect, a fake one (fakePage.IsOk() == false)
|
|
|
|
wxTreeItemId DoInternalGetPage(size_t pos) const;
|
|
|
|
|
|
|
|
// Linear search for a page with the id specified. If no page
|
|
|
|
// found wxNOT_FOUND is returned. The function is used when we catch an event
|
|
|
|
// from m_tree (wxTreeCtrl) component.
|
|
|
|
int DoInternalFindPageById(wxTreeItemId page) const;
|
|
|
|
|
|
|
|
// Updates page and wxTreeItemId correspondance.
|
|
|
|
void DoInternalAddPage(size_t newPos, wxWindow *page, wxTreeItemId pageId);
|
|
|
|
|
|
|
|
// Removes the page from internal structure.
|
|
|
|
void DoInternalRemovePage(size_t pos)
|
|
|
|
{ DoInternalRemovePageRange(pos, 0); }
|
|
|
|
|
|
|
|
// Removes the page and all its children designated by subCount
|
|
|
|
// from internal structures of the control.
|
|
|
|
void DoInternalRemovePageRange(size_t pos, size_t subCount);
|
|
|
|
|
|
|
|
// Returns internal number of pages which can be different from
|
|
|
|
// GetPageCount() while performing a page insertion or removal.
|
2018-03-24 18:18:29 +00:00
|
|
|
size_t DoInternalGetPageCount() const { return m_treeIds.size(); }
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTreebook);
|
2005-10-09 18:40:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// treebook event class and related stuff
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-08-01 13:46:46 +00:00
|
|
|
// wxTreebookEvent is obsolete and defined for compatibility only
|
2012-04-28 22:25:15 +00:00
|
|
|
#define wxTreebookEvent wxBookCtrlEvent
|
2008-08-01 13:46:46 +00:00
|
|
|
typedef wxBookCtrlEventFunction wxTreebookEventFunction;
|
|
|
|
#define wxTreebookEventHandler(func) wxBookCtrlEventHandler(func)
|
2005-11-10 11:24:19 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
|
2013-04-25 10:11:03 +00:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_TREEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_TREEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_TREEBOOK_NODE_COLLAPSED, wxBookCtrlEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_TREEBOOK_NODE_EXPANDED, wxBookCtrlEvent );
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
#define EVT_TREEBOOK_PAGE_CHANGED(winid, fn) \
|
2013-04-25 10:11:03 +00:00
|
|
|
wx__DECLARE_EVT1(wxEVT_TREEBOOK_PAGE_CHANGED, winid, wxBookCtrlEventHandler(fn))
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
#define EVT_TREEBOOK_PAGE_CHANGING(winid, fn) \
|
2013-04-25 10:11:03 +00:00
|
|
|
wx__DECLARE_EVT1(wxEVT_TREEBOOK_PAGE_CHANGING, winid, wxBookCtrlEventHandler(fn))
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
#define EVT_TREEBOOK_NODE_COLLAPSED(winid, fn) \
|
2013-04-25 10:11:03 +00:00
|
|
|
wx__DECLARE_EVT1(wxEVT_TREEBOOK_NODE_COLLAPSED, winid, wxBookCtrlEventHandler(fn))
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
#define EVT_TREEBOOK_NODE_EXPANDED(winid, fn) \
|
2013-04-25 10:11:03 +00:00
|
|
|
wx__DECLARE_EVT1(wxEVT_TREEBOOK_NODE_EXPANDED, winid, wxBookCtrlEventHandler(fn))
|
|
|
|
|
|
|
|
// old wxEVT_COMMAND_* constants
|
|
|
|
#define wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED wxEVT_TREEBOOK_PAGE_CHANGED
|
|
|
|
#define wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING wxEVT_TREEBOOK_PAGE_CHANGING
|
|
|
|
#define wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED wxEVT_TREEBOOK_NODE_COLLAPSED
|
|
|
|
#define wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED wxEVT_TREEBOOK_NODE_EXPANDED
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_TREEBOOK
|
|
|
|
|
|
|
|
#endif // _WX_TREEBOOK_H_
|