1 \section{\class{wxTreeLayout
}}\label{wxtreelayout
}
3 wxTreeLayout provides layout of simple trees with one root node, drawn left-to-right,
4 with user-defined spacing between nodes.
6 wxTreeLayout is an abstract class that must be subclassed. The programmer
7 defines various member functions which will access whatever data structures
8 are appropriate for the application, and wxTreeLayout uses these when laying
11 Nodes are identified by long integer identifiers. The derived class
12 communicates the actual tree structure to wxTreeLayout by defining
\helpref{wxTreeLayout::GetChildren
}{wxtreelayoutgetchildren
}\rtfsp
13 and
\helpref{wxTreeLayout::GetNodeParent
}{wxtreelayoutgetnodeparent
} functions.
15 The application should call
\helpref{wxTreeLayout::DoLayout
}{wxtreelayoutdolayout
} to do the tree
16 layout. Depending on how the derived class has been defined, either
17 \rtfsp\helpref{wxTreeLayout::Draw
}{wxtreelayoutdraw
} must be called (for example by the OnPaint member
18 of a wxScrolledWindow) or the application-defined drawing code should be called
21 For example, if you have an image drawing system already defined, you
22 may want wxTreeLayout to position existing node images in that system. So you
23 just need a way for wxTreeLayout to set the node image positions according to
24 the layout algorithm, and the rest will be done by your own image drawing
27 The algorithm is due to Gabriel Robins
\cite{robins87
}, a linear-time
28 algorithm originally implemented in LISP for AI applications.
30 The original algorithm has been modified so that both X and Y planes
31 are calculated simultaneously, increasing efficiency slightly. The basic
32 code is only a page or so long.
34 \helponly{Below is the example tree generated by the program test.cc.
37 $$
\image{11cm;
0cm
}{treetst.ps
}$$
38 \caption{Example tree
}\label{exampletree
}
42 \wxheading{Derived from
}
48 \helpref{wxTreeLayoutStored
}{wxtreelayoutstored
}
50 \latexignore{\rtfignore{\wxheading{Members
}}}
52 \membersection{wxTreeLayout::wxTreeLayout
}
54 \func{}{wxTreeLayout
}{\void}
58 \membersection{wxTreeLayout::ActivateNode
}\label{wxtreelayoutactivatenode
}
60 \func{void
}{ActivateNode
}{\param{long
}{ id
},
\param{bool
}{active
}}
62 Define this so wxTreeLayout can turn nodes on and off for drawing purposes
63 (not all nodes may be connected in the tree). See also
\helpref{wxTreeLayout::NodeActive
}{wxtreelayoutnodeactive
}.
65 \membersection{wxTreeLayout::CalcLayout
}
67 \func{void
}{CalcLayout
}{\param{long
}{ id
},
\param{int
}{ level
}}
69 Private function for laying out a branch.
71 \membersection{wxTreeLayout::DoLayout
}\label{wxtreelayoutdolayout
}
73 \func{void
}{DoLayout
}{\param{wxDC\&
}{ dc
},
\param{long
}{ topNode = -
1}}
75 Calculates the layout for the tree, optionally specifying the top node.
77 \membersection{wxTreeLayout::Draw
}\label{wxtreelayoutdraw
}
79 \func{void
}{Draw
}{\param{wxDC\&
}{ dc
}}
81 Call this to let wxTreeLayout draw the tree itself, once the layout has been
82 calculated with
\helpref{wxTreeLayout::DoLayout
}{wxtreelayoutdolayout
}.
84 \membersection{wxTreeLayout::DrawBranch
}
86 \func{void
}{DrawBranch
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{wxDC\&
}{ dc
}}
88 Defined by wxTreeLayout to draw an arc between two nodes.
90 \membersection{wxTreeLayout::DrawBranches
}
92 \func{void
}{DrawBranches
}{\param{wxDC\&
}{ dc
}}
94 Defined by wxTreeLayout to draw the arcs between nodes.
96 \membersection{wxTreeLayout::DrawNode
}
98 \func{void
}{DrawNode
}{\param{long
}{ id
},
\param{wxDC\&
}{ dc
}}
100 Defined by wxTreeLayout to draw a node.
102 \membersection{wxTreeLayout::DrawNodes
}
104 \func{void
}{DrawNodes
}{\param{wxDC\&
}{ dc
}}
106 Defined by wxTreeLayout to draw the nodes.
108 \membersection{wxTreeLayout::GetChildren
}\label{wxtreelayoutgetchildren
}
110 \func{void
}{GetChildren
}{\param{long
}{ id
},
\param{wxList \&
}{list
}}
112 Must be defined to return the children of node
{\it id
} in the given list
115 \membersection{wxTreeLayout::GetNextNode
}\label{wxtreelayoutgetnextnode
}
117 \func{long
}{GetNextNode
}{\param{long
}{ id
}}
119 Must be defined to return the next node after
{\it id
}, so that wxTreeLayout can
120 iterate through all relevant nodes. The ordering is not important.
121 The function should return -
1 if there are no more nodes.
123 \membersection{wxTreeLayout::GetNodeName
}
125 \constfunc{wxString
}{GetNodeName
}{\param{long
}{ id
}}
127 May optionally be defined to get a node's name (for example if leaving
128 the drawing to wxTreeLayout).
130 \membersection{wxTreeLayout::GetNodeSize
}
132 \constfunc{void
}{GetNodeSize
}{\param{long
}{ id
},
\param{long*
}{ x
},
\param{long*
}{ y
}}
134 Can be defined to indicate a node's size, or left to wxTreeLayout to use the
135 name as an indication of size.
137 \membersection{wxTreeLayout::GetNodeParent
}\label{wxtreelayoutgetnodeparent
}
139 \constfunc{long
}{GetNodeParent
}{\param{long
}{ id
}}
141 Must be defined to return the parent node of
{\it id
}.
142 The function should return -
1 if there is no parent.
144 \membersection{wxTreeLayout::GetNodeX
}
146 \constfunc{long
}{GetNodeX
}{\param{long
}{ id
}}
148 Must be defined to return the current X position of the node. Note that
149 coordinates are assumed to be at the top-left of the node so some conversion
150 may be necessary for your application.
152 \membersection{wxTreeLayout::GetNodeY
}
154 \constfunc{long
}{GetNodeY
}{\param{long
}{ id
}}
156 Must be defined to return the current Y position of the node. Note that
157 coordinates are assumed to be at the top-left of the node so some conversion
158 may be necessary for your application.
160 \membersection{wxTreeLayout::GetLeftMargin
}
162 \constfunc{long
}{GetLeftMargin
}{\void}
164 Gets the left margin set with
\helpref{wxTreeLayout::SetMargins
}{wxtreelayoutsetmargins
}.
166 \membersection{wxTreeLayout::GetOrientation
}
168 \constfunc{bool
}{GetOrientation
}{\void}
170 Gets the orientation: TRUE means top-to-bottom, FALSE means left-to-right (the default).
172 \membersection{wxTreeLayout::GetTopMargin
}
174 \constfunc{long
}{GetTopMargin
}{\void}
176 Gets the top margin set with
\helpref{wxTreeLayout::SetMargins
}{wxtreelayoutsetmargins
}.
178 \membersection{wxTreeLayout::GetTopNode
}
180 \constfunc{long
}{GetTopNode
}{\void}
182 wxTreeLayout calls this to get the top of the tree. Don't redefine this; call
183 \rtfsp\helpref{wxTreeLayout::SetTopNode
}{wxtreelayoutsettopnode
} instead before calling
\helpref{wxTreeLayout::DoLayout
}{wxtreelayoutdolayout
}.
185 \membersection{wxTreeLayout::GetXSpacing
}
187 \constfunc{long
}{GetXSpacing
}{\void}
189 Gets the horizontal spacing between nodes.
191 \membersection{wxTreeLayout::GetYSpacing
}
193 \constfunc{long
}{GetYSpacing
}{\void}
195 Gets the vertical spacing between nodes.
197 \membersection{wxTreeLayout::Initialize
}
199 \func{void
}{Initialize
}{\void}
201 Initializes wxTreeLayout. Call from application or overridden
{\bf Initialize
}
204 \membersection{wxTreeLayout::NodeActive
}\label{wxtreelayoutnodeactive
}
206 \func{bool
}{NodeActive
}{\param{long
}{ id
}}
208 Define this so wxTreeLayout can know which nodes are to be drawn (not all
209 nodes may be connected in the tree). See also
\helpref{wxTreeLayout::ActivateNode
}{wxtreelayoutactivatenode
}.
211 \membersection{wxTreeLayout::SetNodeName
}
213 \func{void
}{SetNodeName
}{\param{long
}{ id
},
\param{const wxString\&
}{ name
}}
215 May optionally be defined to set a node's name.
217 \membersection{wxTreeLayout::SetNodeX
}
219 \func{void
}{SetNodeX
}{\param{long
}{ id
},
\param{long
}{ x
}}
221 Must be defined to set the current X position of the node. Note that
222 coordinates are assumed to be at the top-left of the node so some conversion
223 may be necessary for your application.
225 \membersection{wxTreeLayout::SetNodeY
}
227 \func{void
}{SetNodeY
}{\param{long
}{ id
},
\param{long
}{ y
}}
229 Must be defined to set the current Y position of the node. Note that
230 coordinates are assumed to be at the top-left of the node so some conversion
231 may be necessary for your application.
233 \membersection{wxTreeLayout::SetOrientation
}
235 \func{void
}{SetOrientation
}{\param{bool
}{ orientation
}}
237 Sets the tree orientation: TRUE means top-to-bottom, FALSE means left-to-right (the default).
239 \membersection{wxTreeLayout::SetTopNode
}\label{wxtreelayoutsettopnode
}
241 \func{void
}{SetTopNode
}{\param{long
}{ id
}}
243 Call this to identify the top of the tree to wxTreeLayout.
245 \membersection{wxTreeLayout::SetSpacing
}
247 \func{void
}{SetSpacing
}{\param{long
}{ x
},
\param{long
}{ y
}}
249 Sets the horizontal and vertical spacing between nodes in the tree.
251 \membersection{wxTreeLayout::SetMargins
}\label{wxtreelayoutsetmargins
}
253 \func{void
}{SetMargins
}{\param{long
}{ x
},
\param{long
}{ y
}}
255 Sets the left and top margins of the whole tree.
257 \section{\class{wxTreeLayoutStored
}}\label{wxtreelayoutstored
}
259 wxTreeLayoutStored provides storage for node labels, position and client data. It also provides hit-testing
260 (which node a mouse event occurred on). It is usually a more convenient class to use than wxTreeLayout.
262 \wxheading{Derived from
}
264 \helpref{wxTreeLayout
}{wxtreelayout
}\\
265 \helpref{wxObject
}{wxobject
}
269 \helpref{wxTreeLayout
}{wxtreelayout
}
271 \latexignore{\rtfignore{\wxheading{Members
}}}
273 \membersection{wxTreeLayoutStored::wxTreeLayoutStored
}
275 \func{}{wxTreeLayoutStored
}{\param{int
}{noNodes =
200}}
277 Constructor. Specify the maximum number of nodes to be allocated.
279 \membersection{wxTreeLayoutStored::AddChild
}\label{wxtreelayoutstoredaddchild
}
281 \func{long
}{AddChild
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ parent = ""
}}
283 Adds a child with a given parent, returning the node id.
285 \membersection{wxTreeLayoutStored::GetClientData
}\label{wxtreelayoutstoredgetclientdata
}
287 \constfunc{long
}{GetClientData
}{\param{long
}{ id
}}
289 Gets the client data for the given node.
291 \membersection{wxTreeLayoutStored::GetNode
}\label{wxtreelayoutstoredgetnode
}
293 \constfunc{wxStoredNode*
}{GetNode
}{\param{long
}{ id
}}
295 Returns the wxStoredNode object for the given node id.
297 \membersection{wxTreeLayoutStored::GetNodeCount
}\label{wxtreelayoutstoredgetnodecount
}
299 \constfunc{int
}{GetNodeCount
}{\void}
301 Returns the current number of nodes.
303 \membersection{wxTreeLayoutStored::GetNumNodes
}\label{wxtreelayoutstoredgetnumnodes
}
305 \constfunc{int
}{GetNumNodes
}{\void}
307 Returns the maximum number of nodes.
309 \membersection{wxTreeLayoutStored::HitTest
}\label{wxtreelayoutstoredhittest
}
311 \func{wxString
}{HitTest
}{\param{wxMouseEvent\&
}{ event
},
\param{wxDC\&
}{dc
}}
313 Returns a string with the node name corresponding to the position of the mouse event, or the empty string if no node
316 \membersection{wxTreeLayoutStored::NameToId
}\label{wxtreelayoutstorednametoid
}
318 \func{long
}{NameToId
}{\param{const wxString\&
}{ name
}}
320 Returns the id for the given node name, or -
1 if there was no such node.
322 \membersection{wxTreeLayoutStored::SetClientData
}\label{wxtreelayoutstoredsetclientdata
}
324 \func{void
}{SetClientData
}{\param{long
}{ id
},
\param{long
}{ clientData
}}
326 Sets client data for the given node.