]> git.saurik.com Git - wxWidgets.git/blame - include/wx/treebook.h
fix wxBitmapComboBox Gtk-CRITICAL assertion `GTK_IS_ENTRY (entry)' failed
[wxWidgets.git] / include / wx / treebook.h
CommitLineData
eca15c0d
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/treebook.h
3// Purpose: wxTreebook: wxNotebook-like control presenting pages in a tree
4// Author: Evgeniy Tarassov, Vadim Zeitlin
5// Modified by:
6// Created: 2005-09-15
7// RCS-ID: $Id$
8// Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_TREEBOOK_H_
13#define _WX_TREEBOOK_H_
14
15#include "wx/defs.h"
16
17#if wxUSE_TREEBOOK
18
19#include "wx/bookctrl.h"
28e42e02 20#include "wx/containr.h"
eca15c0d
VZ
21#include "wx/treectrl.h" // for wxArrayTreeItemIds
22
23typedef wxWindow wxTreebookPage;
24
b5dbe15d 25class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
eca15c0d 26
eca15c0d
VZ
27// ----------------------------------------------------------------------------
28// wxTreebook
29// ----------------------------------------------------------------------------
30
28e42e02 31class WXDLLIMPEXP_CORE wxTreebook : public wxNavigationEnabled<wxBookCtrlBase>
eca15c0d
VZ
32{
33public:
34 // Constructors and such
35 // ---------------------
36
37 // Default ctor doesn't create the control, use Create() afterwards
38 wxTreebook()
39 {
40 Init();
41 }
42
43 // This ctor creates the tree book control
44 wxTreebook(wxWindow *parent,
45 wxWindowID id,
46 const wxPoint& pos = wxDefaultPosition,
47 const wxSize& size = wxDefaultSize,
d8fd7acb 48 long style = wxBK_DEFAULT,
eca15c0d
VZ
49 const wxString& name = wxEmptyString)
50 {
51 Init();
52
53 (void)Create(parent, id, pos, size, style, name);
54 }
55
56 // Really creates the control
57 bool Create(wxWindow *parent,
58 wxWindowID id,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
d8fd7acb 61 long style = wxBK_DEFAULT,
eca15c0d
VZ
62 const wxString& name = wxEmptyString);
63
64
65 // Page insertion operations
66 // -------------------------
67
68 // Notice that page pointer may be NULL in which case the next non NULL
69 // page (usually the first child page of a node) is shown when this page is
70 // selected
71
72 // Inserts a new page just before the page indicated by page.
73 // The new page is placed on the same level as page.
74 virtual bool InsertPage(size_t pos,
75 wxWindow *page,
76 const wxString& text,
77 bool bSelect = false,
1871b9fa 78 int imageId = NO_IMAGE);
eca15c0d
VZ
79
80 // Inserts a new sub-page to the end of children of the page at given pos.
9d5371c6
VZ
81 virtual bool InsertSubPage(size_t pos,
82 wxWindow *page,
83 const wxString& text,
84 bool bSelect = false,
1871b9fa 85 int imageId = NO_IMAGE);
eca15c0d
VZ
86
87 // Adds a new page at top level after all other pages.
88 virtual bool AddPage(wxWindow *page,
89 const wxString& text,
90 bool bSelect = false,
1871b9fa 91 int imageId = NO_IMAGE);
eca15c0d
VZ
92
93 // Adds a new child-page to the last top-level page inserted.
94 // Useful when constructing 1 level tree structure.
95 virtual bool AddSubPage(wxWindow *page,
96 const wxString& text,
97 bool bSelect = false,
1871b9fa 98 int imageId = NO_IMAGE);
eca15c0d
VZ
99
100 // Deletes the page and ALL its children. Could trigger page selection
101 // change in a case when selected page is removed. In that case its parent
102 // is selected (or the next page if no parent).
103 virtual bool DeletePage(size_t pos);
104
105
106 // Tree operations
107 // ---------------
108
109 // Gets the page node state -- node is expanded or collapsed
110 virtual bool IsNodeExpanded(size_t pos) const;
111
112 // Expands or collapses the page node. Returns the previous state.
113 // May generate page changing events (if selected page
114 // is under the collapsed branch, then parent is autoselected).
115 virtual bool ExpandNode(size_t pos, bool expand = true);
116
117 // shortcut for ExpandNode(pos, false)
118 bool CollapseNode(size_t pos) { return ExpandNode(pos, false); }
119
120 // get the parent page or wxNOT_FOUND if this is a top level page
121 int GetPageParent(size_t pos) const;
122
d8fd7acb
WS
123 // the tree control we use for showing the pages index tree
124 wxTreeCtrl* GetTreeCtrl() const { return (wxTreeCtrl*)m_bookctrl; }
125
eca15c0d
VZ
126
127 // Standard operations inherited from wxBookCtrlBase
128 // -------------------------------------------------
129
eca15c0d
VZ
130 virtual bool SetPageText(size_t n, const wxString& strText);
131 virtual wxString GetPageText(size_t n) const;
132 virtual int GetPageImage(size_t n) const;
133 virtual bool SetPageImage(size_t n, int imageId);
1d6fcbcc
VZ
134 virtual int SetSelection(size_t n) { return DoSetSelection(n, SetSelection_SendEvent); }
135 virtual int ChangeSelection(size_t n) { return DoSetSelection(n); }
bcbec865 136 virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
eca15c0d
VZ
137 virtual void SetImageList(wxImageList *imageList);
138 virtual void AssignImageList(wxImageList *imageList);
139 virtual bool DeleteAllPages();
140
141protected:
6f02a879
VZ
142 // Implementation of a page removal. See DeletPage for comments.
143 wxTreebookPage *DoRemovePage(size_t pos);
144
eca15c0d
VZ
145 // This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages)
146 virtual bool AllowNullPage() const { return true; }
147
eca15c0d 148 // event handlers
eca15c0d
VZ
149 void OnTreeSelectionChange(wxTreeEvent& event);
150 void OnTreeNodeExpandedCollapsed(wxTreeEvent& event);
151
eca15c0d
VZ
152 // array of page ids and page windows
153 wxArrayTreeItemIds m_treeIds;
154
eca15c0d
VZ
155 // in the situation when m_selection page is not wxNOT_FOUND but page is
156 // NULL this is the first (sub)child that has a non-NULL page
157 int m_actualSelection;
158
159private:
160 // common part of all constructors
161 void Init();
162
163 // The real implementations of page insertion functions
164 // ------------------------------------------------------
165 // All DoInsert/Add(Sub)Page functions add the page into :
166 // - the base class
167 // - the tree control
168 // - update the index/TreeItemId corespondance array
169 bool DoInsertPage(size_t pos,
170 wxWindow *page,
171 const wxString& text,
172 bool bSelect = false,
1871b9fa 173 int imageId = NO_IMAGE);
eca15c0d
VZ
174 bool DoInsertSubPage(size_t pos,
175 wxWindow *page,
176 const wxString& text,
177 bool bSelect = false,
1871b9fa 178 int imageId = NO_IMAGE);
eca15c0d
VZ
179 bool DoAddSubPage(wxWindow *page,
180 const wxString& text,
181 bool bSelect = false,
1871b9fa 182 int imageId = NO_IMAGE);
eca15c0d 183
eca15c0d 184 // Sets selection in the tree control and updates the page being shown.
1d6fcbcc 185 int DoSetSelection(size_t pos, int flags = 0);
eca15c0d
VZ
186
187 // Returns currently shown page. In a case when selected the node
188 // has empty (NULL) page finds first (sub)child with not-empty page.
189 wxTreebookPage *DoGetCurrentPage() const;
190
191 // Does the selection update. Called from page insertion functions
192 // to update selection if the selected page was pushed by the newly inserted
193 void DoUpdateSelection(bool bSelect, int page);
194
195
196 // Operations on the internal private members of the class
197 // -------------------------------------------------------
198 // Returns the page TreeItemId for the page.
199 // Or, if the page index is incorrect, a fake one (fakePage.IsOk() == false)
200 wxTreeItemId DoInternalGetPage(size_t pos) const;
201
202 // Linear search for a page with the id specified. If no page
203 // found wxNOT_FOUND is returned. The function is used when we catch an event
204 // from m_tree (wxTreeCtrl) component.
205 int DoInternalFindPageById(wxTreeItemId page) const;
206
207 // Updates page and wxTreeItemId correspondance.
208 void DoInternalAddPage(size_t newPos, wxWindow *page, wxTreeItemId pageId);
209
210 // Removes the page from internal structure.
211 void DoInternalRemovePage(size_t pos)
212 { DoInternalRemovePageRange(pos, 0); }
213
214 // Removes the page and all its children designated by subCount
215 // from internal structures of the control.
216 void DoInternalRemovePageRange(size_t pos, size_t subCount);
217
218 // Returns internal number of pages which can be different from
219 // GetPageCount() while performing a page insertion or removal.
b4a980f4 220 size_t DoInternalGetPageCount() const { return m_treeIds.GetCount(); }
eca15c0d
VZ
221
222
223 DECLARE_EVENT_TABLE()
224 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTreebook)
225};
226
227
228// ----------------------------------------------------------------------------
229// treebook event class and related stuff
230// ----------------------------------------------------------------------------
231
3e97a905 232// wxTreebookEvent is obsolete and defined for compatibility only
586bed94 233#define wxTreebookEvent wxBookCtrlEvent
3e97a905
VZ
234typedef wxBookCtrlEventFunction wxTreebookEventFunction;
235#define wxTreebookEventHandler(func) wxBookCtrlEventHandler(func)
b2f8e75a 236
eca15c0d 237
9b11752c
VZ
238wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
239wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
240wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, wxBookCtrlEvent );
241wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, wxBookCtrlEvent );
eca15c0d 242
eca15c0d 243#define EVT_TREEBOOK_PAGE_CHANGED(winid, fn) \
3e97a905 244 wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, winid, wxBookCtrlEventHandler(fn))
eca15c0d
VZ
245
246#define EVT_TREEBOOK_PAGE_CHANGING(winid, fn) \
3e97a905 247 wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, winid, wxBookCtrlEventHandler(fn))
eca15c0d
VZ
248
249#define EVT_TREEBOOK_NODE_COLLAPSED(winid, fn) \
3e97a905 250 wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, winid, wxBookCtrlEventHandler(fn))
eca15c0d
VZ
251
252#define EVT_TREEBOOK_NODE_EXPANDED(winid, fn) \
3e97a905 253 wx__DECLARE_EVT1(wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, winid, wxBookCtrlEventHandler(fn))
eca15c0d
VZ
254
255
256#endif // wxUSE_TREEBOOK
257
258#endif // _WX_TREEBOOK_H_