treebook.h

Go to the documentation of this file.
00001 // $Id: treebook.h 1089 2006-05-16 17:57:54Z alex $
00002 /* @@tag:xara-cn-tp@@ THIRD PARTY COPYRIGHT */
00003 // The following line makes normalize.pl skip type fixing
00004 /* SKIPFIXTYPES: START */
00005 
00007 // Name:        wx/treebook.h
00008 // Purpose:     wxTreebook: wxNotebook-like control presenting pages in a tree
00009 // Author:      Evgeniy Tarassov, Vadim Zeitlin
00010 // Modified by:
00011 // Created:     2005-09-15
00012 // RCS-ID:      $Id: treebook.h,v 1.5 2006/02/08 21:44:23 VZ Exp $
00013 // Copyright:   (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
00014 // Licence:     wxWindows licence
00016 
00017 #ifndef _WXXTRA_TREEBOOK_H_
00018 #define _WXXTRA_TREEBOOK_H_
00019 
00020 #include <wx/defs.h>
00021 
00022 #if wxUSE_TREEBOOK
00023 #define wxXTRA_TREEBOOK 0
00024 #else
00025 #define wxXTRA_TREEBOOK 1
00026 
00027 #include <wx/bookctrl.h>
00028 #include <wx/treectrl.h>        // for wxArrayTreeItemIds
00029 
00030 #define wxBK_TOP        wxBC_TOP
00031 #define wxBK_BOTTOM     wxBC_BOTTOM
00032 #define wxBK_LEFT       wxBC_LEFT
00033 #define wxBK_RIGHT      wxBC_RIGHT
00034 #define wxBK_DEFAULT    wxBC_DEFAULT
00035 #define wxBK_ALIGN_MASK (wxBK_LEFT | wxBK_RIGHT | wxBK_TOP | wxBK_BOTTOM)
00036 
00037 class wxTreeCtrl;
00038 typedef wxWindow wxTreebookPage;
00039 
00040 class WXDLLEXPORT wxTreeEvent;
00041 
00042 // ----------------------------------------------------------------------------
00043 // wxTreebook
00044 // ----------------------------------------------------------------------------
00045 
00046 class WXDLLEXPORT wxTreebook : public wxBookCtrlBase
00047 {
00048 public:
00049     // Constructors and such
00050     // ---------------------
00051 
00052     // Default ctor doesn't create the control, use Create() afterwards
00053     wxTreebook()
00054     {
00055         Init();
00056     }
00057 
00058     // This ctor creates the tree book control
00059     wxTreebook(wxWindow *parent,
00060                wxWindowID id,
00061                const wxPoint& pos = wxDefaultPosition,
00062                const wxSize& size = wxDefaultSize,
00063                long style = wxBK_DEFAULT,
00064                const wxString& name = wxEmptyString)
00065     {
00066         Init();
00067 
00068         (void)Create(parent, id, pos, size, style, name);
00069     }
00070 
00071     // Really creates the control
00072     bool Create(wxWindow *parent,
00073                 wxWindowID id,
00074                 const wxPoint& pos = wxDefaultPosition,
00075                 const wxSize& size = wxDefaultSize,
00076                 long style = wxBK_DEFAULT,
00077                 const wxString& name = wxEmptyString);
00078 
00079 
00080     // Page insertion operations
00081     // -------------------------
00082 
00083     // Notice that page pointer may be NULL in which case the next non NULL
00084     // page (usually the first child page of a node) is shown when this page is
00085     // selected
00086 
00087     // Inserts a new page just before the page indicated by page.
00088     // The new page is placed on the same level as page.
00089     virtual bool InsertPage(size_t pos,
00090                             wxWindow *page,
00091                             const wxString& text,
00092                             bool bSelect = false,
00093                             int imageId = wxNOT_FOUND);
00094 
00095     // Inserts a new sub-page to the end of children of the page at given pos.
00096     virtual bool InsertSubPage(size_t pos,
00097                                wxWindow *page,
00098                                const wxString& text,
00099                                bool bSelect = false,
00100                                int imageId = wxNOT_FOUND);
00101 
00102     // Adds a new page at top level after all other pages.
00103     virtual bool AddPage(wxWindow *page,
00104                          const wxString& text,
00105                          bool bSelect = false,
00106                          int imageId = wxNOT_FOUND);
00107 
00108     // Adds a new child-page to the last top-level page inserted.
00109     // Useful when constructing 1 level tree structure.
00110     virtual bool AddSubPage(wxWindow *page,
00111                             const wxString& text,
00112                             bool bSelect = false,
00113                             int imageId = wxNOT_FOUND);
00114 
00115     // Deletes the page and ALL its children. Could trigger page selection
00116     // change in a case when selected page is removed. In that case its parent
00117     // is selected (or the next page if no parent).
00118     virtual bool DeletePage(size_t pos);
00119 
00120 
00121     // Tree operations
00122     // ---------------
00123 
00124     // Gets the page node state -- node is expanded or collapsed
00125     virtual bool IsNodeExpanded(size_t pos) const;
00126 
00127     // Expands or collapses the page node. Returns the previous state.
00128     // May generate page changing events (if selected page
00129     // is under the collapsed branch, then parent is autoselected).
00130     virtual bool ExpandNode(size_t pos, bool expand = true);
00131 
00132     // shortcut for ExpandNode(pos, false)
00133     bool CollapseNode(size_t pos) { return ExpandNode(pos, false); }
00134 
00135     // get the parent page or wxNOT_FOUND if this is a top level page
00136     int GetPageParent(size_t pos) const;
00137 
00138     // the tree control we use for showing the pages index tree
00139     wxTreeCtrl* GetTreeCtrl() const { return (wxTreeCtrl*)m_bookctrl; }
00140 
00141 
00142     // Standard operations inherited from wxBookCtrlBase
00143     // -------------------------------------------------
00144 
00145     virtual int GetSelection() const;
00146     virtual bool SetPageText(size_t n, const wxString& strText);
00147     virtual wxString GetPageText(size_t n) const;
00148     virtual int GetPageImage(size_t n) const;
00149     virtual bool SetPageImage(size_t n, int imageId);
00150     virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
00151     virtual int SetSelection(size_t n);
00152     virtual void SetImageList(wxImageList *imageList);
00153     virtual void AssignImageList(wxImageList *imageList);
00154     virtual bool DeleteAllPages();
00155 
00156 protected:
00157     // Implementation of a page removal. See DeletPage for comments.
00158     wxTreebookPage *DoRemovePage(size_t pos);
00159 
00160     // This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages)
00161     virtual bool AllowNullPage() const { return true; }
00162 
00163     // event handlers
00164     void OnTreeSelectionChange(wxTreeEvent& event);
00165     void OnTreeNodeExpandedCollapsed(wxTreeEvent& event);
00166 
00167     // array of page ids and page windows
00168     wxArrayTreeItemIds m_treeIds;
00169 
00170     // the currently selected page or wxNOT_FOUND if none
00171     int m_selection;
00172 
00173     // in the situation when m_selection page is not wxNOT_FOUND but page is
00174     // NULL this is the first (sub)child that has a non-NULL page
00175     int m_actualSelection;
00176 
00177     // Some functions imported from the base class in 2.7
00178     wxSize GetControllerSize() const;
00179     virtual void DoSize();
00180     void OnSize(wxSizeEvent& event);
00181     wxRect GetPageRect() const;
00182     // get/set size of area between book control area and page area
00183     inline unsigned int GetInternalBorder() const
00184     {
00185         return m_internalBorder;
00186     }
00187     void SetInternalBorder(unsigned int internalBorder)
00188     {
00189         m_internalBorder = internalBorder;
00190     }
00191 
00192     unsigned int m_internalBorder;
00193 
00194 private:
00195     // common part of all constructors
00196     void Init();
00197 
00198     // The real implementations of page insertion functions
00199     // ------------------------------------------------------
00200     // All DoInsert/Add(Sub)Page functions add the page into :
00201     // - the base class
00202     // - the tree control
00203     // - update the index/TreeItemId corespondance array
00204     bool DoInsertPage(size_t pos,
00205                       wxWindow *page,
00206                       const wxString& text,
00207                       bool bSelect = false,
00208                       int imageId = wxNOT_FOUND);
00209     bool DoInsertSubPage(size_t pos,
00210                          wxWindow *page,
00211                          const wxString& text,
00212                          bool bSelect = false,
00213                          int imageId = wxNOT_FOUND);
00214     bool DoAddSubPage(wxWindow *page,
00215                          const wxString& text,
00216                          bool bSelect = false,
00217                          int imageId = wxNOT_FOUND);
00218 
00219     // Sets selection in the tree control and updates the page being shown.
00220     int DoSetSelection(size_t pos);
00221 
00222     // Returns currently shown page. In a case when selected the node
00223     // has empty (NULL) page finds first (sub)child with not-empty page.
00224     wxTreebookPage *DoGetCurrentPage();
00225 
00226     // Does the selection update. Called from page insertion functions
00227     // to update selection if the selected page was pushed by the newly inserted
00228     void DoUpdateSelection(bool bSelect, int page);
00229 
00230 
00231     // Operations on the internal private members of the class
00232     // -------------------------------------------------------
00233     // Returns the page TreeItemId for the page.
00234     // Or, if the page index is incorrect, a fake one (fakePage.IsOk() == false)
00235     wxTreeItemId DoInternalGetPage(size_t pos) const;
00236 
00237     // Linear search for a page with the id specified. If no page
00238     // found wxNOT_FOUND is returned. The function is used when we catch an event
00239     // from m_tree (wxTreeCtrl) component.
00240     int DoInternalFindPageById(wxTreeItemId page) const;
00241 
00242     // Updates page and wxTreeItemId correspondance.
00243     void DoInternalAddPage(size_t newPos, wxWindow *page, wxTreeItemId pageId);
00244 
00245     // Removes the page from internal structure.
00246     void DoInternalRemovePage(size_t pos)
00247         { DoInternalRemovePageRange(pos, 0); }
00248 
00249     // Removes the page and all its children designated by subCount
00250     // from internal structures of the control.
00251     void DoInternalRemovePageRange(size_t pos, size_t subCount);
00252 
00253     // Returns internal number of pages which can be different from
00254     // GetPageCount() while performing a page insertion or removal.
00255     size_t DoInternalGetPageCount() const { return m_treeIds.Count(); }
00256 
00257 
00258     DECLARE_EVENT_TABLE()
00259     DECLARE_DYNAMIC_CLASS_NO_COPY(wxTreebook)
00260 
00261     wxTreeCtrl * m_bookctrl;
00262 };
00263 
00264 
00265 // ----------------------------------------------------------------------------
00266 // treebook event class and related stuff
00267 // ----------------------------------------------------------------------------
00268 
00269 class WXDLLEXPORT wxTreebookEvent : public wxBookCtrlBaseEvent
00270 {
00271 public:
00272     wxTreebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
00273                     int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND)
00274         : wxBookCtrlBaseEvent(commandType, id, nSel, nOldSel)
00275     {
00276     }
00277 
00278     wxTreebookEvent(const wxTreebookEvent& event)
00279         : wxBookCtrlBaseEvent(event)
00280     {
00281     }
00282 
00283     virtual wxEvent *Clone() const { return new wxTreebookEvent(*this); }
00284 
00285 private:
00286     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTreebookEvent)
00287 };
00288 
00289 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED;
00290 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING;
00291 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED;
00292 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED;
00293 
00294 typedef void (wxEvtHandler::*wxTreebookEventFunction)(wxTreebookEvent&);
00295 
00296 #define wxTreebookEventHandler(func) \
00297     (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxTreebookEventFunction, &func)
00298 
00299 #define EVT_TREEBOOK_PAGE_CHANGED(winid, fn) \
00300     wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, winid, wxTreebookEventHandler(fn))
00301 
00302 #define EVT_TREEBOOK_PAGE_CHANGING(winid, fn) \
00303     wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, winid, wxTreebookEventHandler(fn))
00304 
00305 #define EVT_TREEBOOK_NODE_COLLAPSED(winid, fn) \
00306     wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, winid, wxTreebookEventHandler(fn))
00307 
00308 #define EVT_TREEBOOK_NODE_EXPANDED(winid, fn) \
00309     wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, winid, wxTreebookEventHandler(fn))
00310 
00311 
00312 #endif // wxUSE_TREEBOOK
00313 
00314 #endif // _WX_TREEBOOK_H_

Generated on Sat Nov 10 03:49:02 2007 for Camelot by  doxygen 1.4.4