Debian Codegraph @

pod/Tree.pod

raw
1
2 =head1 NAME
3
4 Tk::Tree - Create and manipulate Tree widgets
5
6 =for pm Tixish/Tree.pm
7
8 =for category Tix Extensions
9
10 =head1 SYNOPSIS
11
12 S< >B<use Tk::Tree;>
13
14 S< >I<$tree> = I<$parent>-E<gt>B<Tree>(?I<options>?);
15
16 =head1 SUPER-CLASS
17
18 The B<Tree> class is derived from the L<HList|Tk::HList> class and inherits all
19 the methods, options and subwidgets of its super-class. A B<Tree> widget is
20 not scrolled by default.
21
22 =head1 STANDARD OPTIONS
23
24 B<Tree> supports all the standard options of an HList widget.
25 See L<Tk::options> for details on the standard options.
26
27 =head1 WIDGET-SPECIFIC OPTIONS
28
29 =over 4
30
31 =item Name: B<browseCmd>
32
33 =item Class: B<BrowseCmd>
34
35 =item Switch: B<-browsecmd>
36
37 Specifies a L<callback|Tk::callbacks> to call whenever the user browses on an entry
38 (usually by single-clicking on the entry). The callback is called with
39 one argument, the pathname of the entry.
40
41 =item Name: B<closeCmd>
42
43 =item Class: B<CloseCmd>
44
45 =item Switch: B<-closecmd>
46
47 Specifies a L<callback|Tk::callbacks> to call whenever an entry needs to be closed (See
48 L<"BINDINGS"> below). This method is called with one argument,
49 the pathname of the entry. This method should perform appropriate
50 actions to close the specified entry. If the B<-closecmd> option
51 is not specified, the default closing action is to hide all child
52 entries of the specified entry.
53
54 =item Name: B<command>
55
56 =item Class: B<Command>
57
58 =item Switch: B<-command>
59
60 Specifies a L<callback|Tk::callbacks> to call whenever the user activates an entry
61 (usually by double-clicking on the entry). The callback
62 is called with one argument, the pathname of the entry.
63
64 =item Name: B<ignoreInvoke>
65
66 =item Class: B<IgnoreInvoke>
67
68 =item Switch: B<-ignoreinvoke>
69
70 A Boolean value that specifies when a branch should be opened or
71 closed. A branch will always be opened or closed when the user presses
72 the (+) and (-) indicators. However, when the user invokes a branch
73 (by doublc-clicking or pressing E<lt>ReturnE<gt>), the branch will be opened
74 or closed only if B<-ignoreinvoke> is set to false (the default
75 setting).
76
77 =item Name: B<openCmd>
78
79 =item Class: B<OpenCmd>
80
81 =item Switch: B<-opencmd>
82
83 Specifies a L<callback|Tk::callbacks> to call whenever an entry needs to be opened (See
84 L<"BINDINGS"> below). This method is called with one argument,
85 the pathname of the entry. This method should perform appropriate
86 actions to open the specified entry. If the B<-opencmd> option
87 is not specified, the default opening action is to show all the child
88 entries of the specified entry.
89
90 =back
91
92 =head1 DESCRIPTION
93
94 The B<Tree> method creates a new window and makes it into a Tree widget
95 and return a reference to it. Additional options, described above, may
96 be specified on the command line or in the option database to configure
97 aspects of the Tree widget such as its cursor and relief.
98
99 The Tree widget can be used to display hierarchical data in a tree
100 form. The user can adjust the view of the tree by opening or closing
101 parts of the tree.
102
103 To display a static tree structure, you can add the entries into the
104 Tree widget and hide any entries as desired. Then you can call
105 the B<autosetmode> method. This will set up the Tree widget so that it
106 handles all the I<open> and I<close> events automatically.
107 the demonstration program F<Tixish/examples/perl-tix-tree>).
108
109 The above method is not applicable if you want to maintain a dynamic tree
110 structure, i.e, you do not know all the entries in the tree and you need
111 to add or delete entries subsequently. To do this, you should first create
112 the entries in the Tree widget. Then, use the B<setmode> method to
113 indicate the entries that can be opened or closed, and use the B<-opencmd>
114 and B<-closecmd> options to handle the opening and closing events. (Please
115 see the demonstration program F<Tixish/examples/perl-tix-dyntree>).
116
117 Use either
118
119 S< >I<$parent>-E<gt>B<Scrolled>(B<'Tree'>, ... );
120
121 or
122
123 S< >I<$parent>-E<gt>B<ScrlTree>( ... );
124
125 to create a scrolled B<Tree>. See L<Tk::Scrolled> for details.
126
127 =head1 WIDGET METHODS
128
129 The B<Tree> method creates a widget object.
130 This object supports the B<configure> and B<cget> methods
131 described in L<Tk::options> which can be used to enquire and
132 modify the options described above.
133 The widget also inherits all the methods provided by the generic
134 L<Tk::Widget|Tk::Widget> class.
135
136 The following additional methods are available for Tree widgets:
137
138 =over 4
139
140 =item I<$tree-E<gt>>B<add_pathimage>(I<treeRegExp [, openImg, closeImg]>)
141
142 This method defines images for a given path (images must be in xpm
143 format). The path can be determined by a simplified regular
144 expression. There are just three metasymbols:
145
146 =over
147
148 =item ^
149
150 at the beginning of the C<treeRegExp> same as in Perl regular
151 expressions
152
153 =item Z<>*
154
155 anything
156
157 =item $
158
159 at the end of the C<TreeRegExp>, the same as in Perl regular
160 expressions
161
162 =back
163
164 Examples:
165
166 $tree->add_pathimage('^root','openfolder','folder');
167
168 matches C<root>, C<root.foo>, C<root.bar>, but not C<foo.root>
169
170 $tree->add_pathimage('root.*.class','openfolder','folder');
171
172 matches all paths containing C<< root.<anything>.class >>, but not
173 C<< root.<anything>.<anything>.class >> C<*> is one part of the path. If
174 you want to use a wildcard for two steps, you have to use C<*.*>.
175
176 $tree->add_pathimage('class$','openfolder','folder');
177
178 This matches all path with C<class> at the end.
179
180 =item I<$tree>-E<gt>B<autosetmode>
181
182 This method calls the B<setmode> method for all the entries in
183 this Tree widget: if an entry has no child entries, its mode is set to
184 B<none>. Otherwise, if the entry has any hidden child entries, its
185 mode is set to B<open>; otherwise its mode is set to B<close>.
186
187 =item I<$tree-E<gt>>B<child_entries>([$path][,$depth])
188
189 This method returns in list context an array that contains all
190 pathnames of subentries within the given path. In scalar context it
191 returns the number of subentries in the given path.
192
193 Example:
194 root
195 | foo
196 | bar
197 | | bar1
198 | | bar2
199
200 my @childentries = $tree->child_entries('root.bar');
201 # returns (root.bar.bar1, root.bar.bar2)
202
203 my $nr_of_subentries = $tree->child_entries('root',2);
204 # returns 4
205
206 If C<$path> is omitted, all it is assumed, that the entry above
207 'root' is meant. C<$depth> defines the numbers of levels.
208
209 =item I<$tree>-E<gt>B<close>(I<entryPath>)
210
211 Close the entry given by I<entryPath> if its I<mode> is B<close>.
212
213 =item I<$tree>-E<gt>B<getmode>(I<entryPath>)
214
215 Returns the current I<mode> of the entry given by I<entryPath>.
216
217 =item I<$tree>-E<gt>B<open>(I<entryPath>)
218
219 Open the entry given by I<entryPath> if its I<mode> is B<open>.
220
221 =item I<$tree>-E<gt>B<setmode>(I<entryPath, mode>)
222
223 This method is used to indicate whether the entry given by
224 I<entryPath> has children entries and whether the children are
225 visible. I<mode> must be one of B<open>,
226 B<close> or B<none>. If I<mode> is set to B<open>, a (+)
227 indicator is drawn next to the entry. If I<mode> is set to
228 B<close>, a (-) indicator is drawn next to the entry. If
229 I<mode> is set to B<none>, no indicators will be drawn for this
230 entry. The default I<mode> is none. The B<open> mode indicates
231 the entry has hidden children and this entry can be opened by the
232 user. The B<close> mode indicates that all the children of the entry
233 are now visible and the entry can be closed by the user.
234
235 =back
236
237 =head1 BINDINGS
238
239 The basic mouse and keyboard bindings of the Tree widget are the same
240 as the L<bindings of the HList|Tk::HList/"BINDINGS"> widget.
241 In addition, the entries can be opened or closed under the following
242 conditions:
243
244 =over 4
245
246 =item [1]
247
248 If the I<mode> of the entry is B<open>, it can be opened by clicking
249 on its (+) indicator.
250
251 =item [2]
252
253 If the I<mode> of the entry is B<close>, it can be closed by clicking
254 on its (-) indicator.
255
256 =back
257
258 =head1 SEE ALSO
259
260 L<Tk::HList|Tk::HList>
261
262 =head1 AUTHOR
263
264 Perl/TK version by Chris Dean <[email protected]>. Original Tcl/Tix
265 version by Ioi Kim Lam.
266
267 Additions by Renee Baecker <[email protected]>
268
269 =head1 ACKNOWLEDGEMENTS
270
271 Thanks to Achim Bohnet <[email protected]> for all his help.
272
273 =cut
274