]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/treelay.tex
Fixed a couple spelling typos
[wxWidgets.git] / docs / latex / wx / treelay.tex
CommitLineData
4414cc1d
JS
1\section{\class{wxTreeLayout}}\label{wxtreelayout}
2
babc9758
JS
3wxTreeLayout provides layout of simple trees with one root node, drawn left-to-right,
4with user-defined spacing between nodes.
5
6wxTreeLayout is an abstract class that must be subclassed. The programmer
7defines various member functions which will access whatever data structures
8are appropriate for the application, and wxTreeLayout uses these when laying
9out the tree.
4414cc1d
JS
10
11Nodes are identified by long integer identifiers. The derived class
babc9758
JS
12communicates the actual tree structure to wxTreeLayout by defining \helpref{wxTreeLayout::GetChildren}{wxtreelayoutgetchildren}\rtfsp
13and \helpref{wxTreeLayout::GetNodeParent}{wxtreelayoutgetnodeparent} functions.
4414cc1d 14
babc9758 15The application should call \helpref{wxTreeLayout::DoLayout}{wxtreelayoutdolayout} to do the tree
4414cc1d 16layout. Depending on how the derived class has been defined, either
94799627 17\rtfsp\helpref{wxTreeLayout::Draw}{wxtreelayoutdraw} must be called (for example by the OnPaint member
4414cc1d
JS
18of a wxScrolledWindow) or the application-defined drawing code should be called
19as normal.
20
21For example, if you have an image drawing system already defined, you
22may want wxTreeLayout to position existing node images in that system. So you
23just need a way for wxTreeLayout to set the node image positions according to
24the layout algorithm, and the rest will be done by your own image drawing
25system.
26
babc9758
JS
27The algorithm is due to Gabriel Robins \cite{robins87}, a linear-time
28algorithm originally implemented in LISP for AI applications.
29
30The original algorithm has been modified so that both X and Y planes
31are calculated simultaneously, increasing efficiency slightly. The basic
32code is only a page or so long.
33
34\helponly{Below is the example tree generated by the program test.cc.
35
36\begin{figure}
37$$\image{11cm;0cm}{treetst.ps}$$
38\caption{Example tree}\label{exampletree}
39\end{figure}
40}
41
4414cc1d
JS
42\wxheading{Derived from}
43
44wxObject
45
babc9758
JS
46\wxheading{See also}
47
94799627 48\helpref{wxTreeLayoutStored}{wxtreelayoutstored}
babc9758 49
4414cc1d
JS
50\latexignore{\rtfignore{\wxheading{Members}}}
51
52\membersection{wxTreeLayout::wxTreeLayout}
53
54\func{}{wxTreeLayout}{\void}
55
56Constructor.
57
babc9758 58\membersection{wxTreeLayout::ActivateNode}\label{wxtreelayoutactivatenode}
4414cc1d
JS
59
60\func{void}{ActivateNode}{\param{long}{ id}, \param{bool }{active}}
61
62Define this so wxTreeLayout can turn nodes on and off for drawing purposes
94799627 63(not all nodes may be connected in the tree). See also \helpref{wxTreeLayout::NodeActive}{wxtreelayoutnodeactive}.
4414cc1d
JS
64
65\membersection{wxTreeLayout::CalcLayout}
66
67\func{void}{CalcLayout}{\param{long}{ id}, \param{int}{ level}}
68
69Private function for laying out a branch.
70
babc9758 71\membersection{wxTreeLayout::DoLayout}\label{wxtreelayoutdolayout}
4414cc1d
JS
72
73\func{void}{DoLayout}{\param{wxDC\&}{ dc}, \param{long}{ topNode = -1}}
74
75Calculates the layout for the tree, optionally specifying the top node.
76
babc9758 77\membersection{wxTreeLayout::Draw}\label{wxtreelayoutdraw}
4414cc1d
JS
78
79\func{void}{Draw}{\param{wxDC\&}{ dc}}
80
81Call this to let wxTreeLayout draw the tree itself, once the layout has been
94799627 82calculated with \helpref{wxTreeLayout::DoLayout}{wxtreelayoutdolayout}.
4414cc1d
JS
83
84\membersection{wxTreeLayout::DrawBranch}
85
86\func{void}{DrawBranch}{\param{long}{ from}, \param{long}{ to}, \param{wxDC\&}{ dc}}
87
88Defined by wxTreeLayout to draw an arc between two nodes.
89
90\membersection{wxTreeLayout::DrawBranches}
91
92\func{void}{DrawBranches}{\param{wxDC\&}{ dc}}
93
94Defined by wxTreeLayout to draw the arcs between nodes.
95
96\membersection{wxTreeLayout::DrawNode}
97
98\func{void}{DrawNode}{\param{long}{ id}, \param{wxDC\&}{ dc}}
99
100Defined by wxTreeLayout to draw a node.
101
102\membersection{wxTreeLayout::DrawNodes}
103
104\func{void}{DrawNodes}{\param{wxDC\&}{ dc}}
105
106Defined by wxTreeLayout to draw the nodes.
107
babc9758 108\membersection{wxTreeLayout::GetChildren}\label{wxtreelayoutgetchildren}
4414cc1d
JS
109
110\func{void}{GetChildren}{\param{long}{ id}, \param{wxList \&}{list}}
111
112Must be defined to return the children of node {\it id} in the given list
113of integers.
114
babc9758 115\membersection{wxTreeLayout::GetNextNode}\label{wxtreelayoutgetnextnode}
4414cc1d
JS
116
117\func{long}{GetNextNode}{\param{long}{ id}}
118
119Must be defined to return the next node after {\it id}, so that wxTreeLayout can
120iterate through all relevant nodes. The ordering is not important.
121The function should return -1 if there are no more nodes.
122
123\membersection{wxTreeLayout::GetNodeName}
124
125\constfunc{wxString}{GetNodeName}{\param{long}{ id}}
126
127May optionally be defined to get a node's name (for example if leaving
128the drawing to wxTreeLayout).
129
130\membersection{wxTreeLayout::GetNodeSize}
131
132\constfunc{void}{GetNodeSize}{\param{long}{ id}, \param{long*}{ x}, \param{long*}{ y}}
133
134Can be defined to indicate a node's size, or left to wxTreeLayout to use the
135name as an indication of size.
136
babc9758 137\membersection{wxTreeLayout::GetNodeParent}\label{wxtreelayoutgetnodeparent}
4414cc1d
JS
138
139\constfunc{long}{GetNodeParent}{\param{long}{ id}}
140
141Must be defined to return the parent node of {\it id}.
142The function should return -1 if there is no parent.
143
144\membersection{wxTreeLayout::GetNodeX}
145
146\constfunc{long}{GetNodeX}{\param{long}{ id}}
147
148Must be defined to return the current X position of the node. Note that
149coordinates are assumed to be at the top-left of the node so some conversion
150may be necessary for your application.
151
152\membersection{wxTreeLayout::GetNodeY}
153
154\constfunc{long}{GetNodeY}{\param{long}{ id}}
155
156Must be defined to return the current Y position of the node. Note that
157coordinates are assumed to be at the top-left of the node so some conversion
158may be necessary for your application.
159
160\membersection{wxTreeLayout::GetLeftMargin}
161
162\constfunc{long}{GetLeftMargin}{\void}
163
94799627 164Gets the left margin set with \helpref{wxTreeLayout::SetMargins}{wxtreelayoutsetmargins}.
4414cc1d
JS
165
166\membersection{wxTreeLayout::GetOrientation}
167
168\constfunc{bool}{GetOrientation}{\void}
169
170Gets the orientation: TRUE means top-to-bottom, FALSE means left-to-right (the default).
171
172\membersection{wxTreeLayout::GetTopMargin}
173
174\constfunc{long}{GetTopMargin}{\void}
175
94799627 176Gets the top margin set with \helpref{wxTreeLayout::SetMargins}{wxtreelayoutsetmargins}.
4414cc1d
JS
177
178\membersection{wxTreeLayout::GetTopNode}
179
180\constfunc{long}{GetTopNode}{\void}
181
182wxTreeLayout calls this to get the top of the tree. Don't redefine this; call
94799627 183\rtfsp\helpref{wxTreeLayout::SetTopNode}{wxtreelayoutsettopnode} instead before calling \helpref{wxTreeLayout::DoLayout}{wxtreelayoutdolayout}.
4414cc1d
JS
184
185\membersection{wxTreeLayout::GetXSpacing}
186
187\constfunc{long}{GetXSpacing}{\void}
188
189Gets the horizontal spacing between nodes.
190
191\membersection{wxTreeLayout::GetYSpacing}
192
193\constfunc{long}{GetYSpacing}{\void}
194
195Gets the vertical spacing between nodes.
196
197\membersection{wxTreeLayout::Initialize}
198
199\func{void}{Initialize}{\void}
200
201Initializes wxTreeLayout. Call from application or overridden {\bf Initialize}
202or constructor.
203
babc9758 204\membersection{wxTreeLayout::NodeActive}\label{wxtreelayoutnodeactive}
4414cc1d
JS
205
206\func{bool}{NodeActive}{\param{long}{ id}}
207
208Define this so wxTreeLayout can know which nodes are to be drawn (not all
94799627 209nodes may be connected in the tree). See also \helpref{wxTreeLayout::ActivateNode}{wxtreelayoutactivatenode}.
4414cc1d
JS
210
211\membersection{wxTreeLayout::SetNodeName}
212
213\func{void}{SetNodeName}{\param{long}{ id}, \param{const wxString\& }{ name}}
214
215May optionally be defined to set a node's name.
216
217\membersection{wxTreeLayout::SetNodeX}
218
219\func{void}{SetNodeX}{\param{long}{ id}, \param{long}{ x}}
220
221Must be defined to set the current X position of the node. Note that
222coordinates are assumed to be at the top-left of the node so some conversion
223may be necessary for your application.
224
225\membersection{wxTreeLayout::SetNodeY}
226
227\func{void}{SetNodeY}{\param{long}{ id}, \param{long}{ y}}
228
229Must be defined to set the current Y position of the node. Note that
230coordinates are assumed to be at the top-left of the node so some conversion
231may be necessary for your application.
232
233\membersection{wxTreeLayout::SetOrientation}
234
235\func{void}{SetOrientation}{\param{bool}{ orientation}}
236
237Sets the tree orientation: TRUE means top-to-bottom, FALSE means left-to-right (the default).
238
babc9758 239\membersection{wxTreeLayout::SetTopNode}\label{wxtreelayoutsettopnode}
4414cc1d
JS
240
241\func{void}{SetTopNode}{\param{long}{ id}}
242
243Call this to identify the top of the tree to wxTreeLayout.
244
245\membersection{wxTreeLayout::SetSpacing}
246
247\func{void}{SetSpacing}{\param{long}{ x}, \param{long}{ y}}
248
249Sets the horizontal and vertical spacing between nodes in the tree.
250
babc9758 251\membersection{wxTreeLayout::SetMargins}\label{wxtreelayoutsetmargins}
4414cc1d
JS
252
253\func{void}{SetMargins}{\param{long}{ x}, \param{long}{ y}}
254
255Sets the left and top margins of the whole tree.
256
94799627 257\section{\class{wxTreeLayoutStored}}\label{wxtreelayoutstored}
4414cc1d 258
94799627 259wxTreeLayoutStored provides storage for node labels, position and client data. It also provides hit-testing
4414cc1d
JS
260(which node a mouse event occurred on). It is usually a more convenient class to use than wxTreeLayout.
261
262\wxheading{Derived from}
263
babc9758
JS
264\helpref{wxTreeLayout}{wxtreelayout}\\
265\helpref{wxObject}{wxobject}
266
267\wxheading{See also}
268
94799627 269\helpref{wxTreeLayout}{wxtreelayout}
4414cc1d
JS
270
271\latexignore{\rtfignore{\wxheading{Members}}}
272
94799627 273\membersection{wxTreeLayoutStored::wxTreeLayoutStored}
4414cc1d 274
94799627 275\func{}{wxTreeLayoutStored}{\param{int }{noNodes = 200}}
4414cc1d
JS
276
277Constructor. Specify the maximum number of nodes to be allocated.
278
94799627 279\membersection{wxTreeLayoutStored::AddChild}\label{wxtreelayoutstoredaddchild}
4414cc1d
JS
280
281\func{long}{AddChild}{\param{const wxString\&}{ name}, \param{const wxString\&}{ parent = ""}}
282
283Adds a child with a given parent, returning the node id.
284
94799627 285\membersection{wxTreeLayoutStored::GetClientData}\label{wxtreelayoutstoredgetclientdata}
4414cc1d
JS
286
287\constfunc{long}{GetClientData}{\param{long}{ id}}
288
289Gets the client data for the given node.
290
94799627 291\membersection{wxTreeLayoutStored::GetNode}\label{wxtreelayoutstoredgetnode}
4414cc1d
JS
292
293\constfunc{wxStoredNode*}{GetNode}{\param{long}{ id}}
294
295Returns the wxStoredNode object for the given node id.
296
94799627 297\membersection{wxTreeLayoutStored::GetNodeCount}\label{wxtreelayoutstoredgetnodecount}
4414cc1d
JS
298
299\constfunc{int}{GetNodeCount}{\void}
300
301Returns the current number of nodes.
302
94799627 303\membersection{wxTreeLayoutStored::GetNumNodes}\label{wxtreelayoutstoredgetnumnodes}
4414cc1d
JS
304
305\constfunc{int}{GetNumNodes}{\void}
306
307Returns the maximum number of nodes.
308
94799627 309\membersection{wxTreeLayoutStored::HitTest}\label{wxtreelayoutstoredhittest}
4414cc1d
JS
310
311\func{wxString}{HitTest}{\param{wxMouseEvent\&}{ event}, \param{wxDC\& }{dc}}
312
313Returns a string with the node name corresponding to the position of the mouse event, or the empty string if no node
314was detected.
315
94799627 316\membersection{wxTreeLayoutStored::NameToId}\label{wxtreelayoutstorednametoid}
4414cc1d
JS
317
318\func{long}{NameToId}{\param{const wxString\&}{ name}}
319
320Returns the id for the given node name, or -1 if there was no such node.
321
94799627 322\membersection{wxTreeLayoutStored::SetClientData}\label{wxtreelayoutstoredsetclientdata}
4414cc1d
JS
323
324\func{void}{SetClientData}{\param{long}{ id}, \param{long}{ clientData}}
325
326Sets client data for the given node.
327