.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Tree 3" .TH Tree 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Tk::Tree \- Create and manipulate Tree widgets .SH SYNOPSIS .IX Header "SYNOPSIS" \ \ \ \ \fBuse Tk::Tree;\fR .PP \ \ \ \ \fR\f(CI$tree\fR\fI\fR = \fI\fR\f(CI$parent\fR\fI\fR\->\fBTree\fR(?\fIoptions\fR?); .SH SUPER-CLASS .IX Header "SUPER-CLASS" The \fBTree\fR class is derived from the HList class and inherits all the methods, options and subwidgets of its super-class. A \fBTree\fR widget is not scrolled by default. .SH "STANDARD OPTIONS" .IX Header "STANDARD OPTIONS" \&\fBTree\fR supports all the standard options of an HList widget. See Tk::options for details on the standard options. .SH "WIDGET-SPECIFIC OPTIONS" .IX Header "WIDGET-SPECIFIC OPTIONS" .IP "Name: \fBbrowseCmd\fR" 4 .IX Item "Name: browseCmd" .PD 0 .IP "Class: \fBBrowseCmd\fR" 4 .IX Item "Class: BrowseCmd" .IP "Switch: \fB\-browsecmd\fR" 4 .IX Item "Switch: -browsecmd" .PD Specifies a callback to call whenever the user browses on an entry (usually by single-clicking on the entry). The callback is called with one argument, the pathname of the entry. .IP "Name: \fBcloseCmd\fR" 4 .IX Item "Name: closeCmd" .PD 0 .IP "Class: \fBCloseCmd\fR" 4 .IX Item "Class: CloseCmd" .IP "Switch: \fB\-closecmd\fR" 4 .IX Item "Switch: -closecmd" .PD Specifies a callback to call whenever an entry needs to be closed (See "BINDINGS" below). This method is called with one argument, the pathname of the entry. This method should perform appropriate actions to close the specified entry. If the \fB\-closecmd\fR option is not specified, the default closing action is to hide all child entries of the specified entry. .IP "Name: \fBcommand\fR" 4 .IX Item "Name: command" .PD 0 .IP "Class: \fBCommand\fR" 4 .IX Item "Class: Command" .IP "Switch: \fB\-command\fR" 4 .IX Item "Switch: -command" .PD Specifies a callback to call whenever the user activates an entry (usually by double-clicking on the entry). The callback is called with one argument, the pathname of the entry. .IP "Name: \fBignoreInvoke\fR" 4 .IX Item "Name: ignoreInvoke" .PD 0 .IP "Class: \fBIgnoreInvoke\fR" 4 .IX Item "Class: IgnoreInvoke" .IP "Switch: \fB\-ignoreinvoke\fR" 4 .IX Item "Switch: -ignoreinvoke" .PD A Boolean value that specifies when a branch should be opened or closed. A branch will always be opened or closed when the user presses the (+) and (\-) indicators. However, when the user invokes a branch (by doublc-clicking or pressing ), the branch will be opened or closed only if \fB\-ignoreinvoke\fR is set to false (the default setting). .IP "Name: \fBopenCmd\fR" 4 .IX Item "Name: openCmd" .PD 0 .IP "Class: \fBOpenCmd\fR" 4 .IX Item "Class: OpenCmd" .IP "Switch: \fB\-opencmd\fR" 4 .IX Item "Switch: -opencmd" .PD Specifies a callback to call whenever an entry needs to be opened (See "BINDINGS" below). This method is called with one argument, the pathname of the entry. This method should perform appropriate actions to open the specified entry. If the \fB\-opencmd\fR option is not specified, the default opening action is to show all the child entries of the specified entry. .SH DESCRIPTION .IX Header "DESCRIPTION" The \fBTree\fR method creates a new window and makes it into a Tree widget and return a reference to it. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the Tree widget such as its cursor and relief. .PP The Tree widget can be used to display hierarchical data in a tree form. The user can adjust the view of the tree by opening or closing parts of the tree. .PP To display a static tree structure, you can add the entries into the Tree widget and hide any entries as desired. Then you can call the \fBautosetmode\fR method. This will set up the Tree widget so that it handles all the \fIopen\fR and \fIclose\fR events automatically. the demonstration program \fITixish/examples/perl\-tix\-tree\fR). .PP The above method is not applicable if you want to maintain a dynamic tree structure, i.e, you do not know all the entries in the tree and you need to add or delete entries subsequently. To do this, you should first create the entries in the Tree widget. Then, use the \fBsetmode\fR method to indicate the entries that can be opened or closed, and use the \fB\-opencmd\fR and \fB\-closecmd\fR options to handle the opening and closing events. (Please see the demonstration program \fITixish/examples/perl\-tix\-dyntree\fR). .PP Use either .PP \ \ \ \ \fR\f(CI$parent\fR\fI\fR\->\fBScrolled\fR(\fB'Tree'\fR, ... ); .PP or .PP \ \ \ \ \fR\f(CI$parent\fR\fI\fR\->\fBScrlTree\fR( ... ); .PP to create a scrolled \fBTree\fR. See Tk::Scrolled for details. .SH "WIDGET METHODS" .IX Header "WIDGET METHODS" The \fBTree\fR method creates a widget object. This object supports the \fBconfigure\fR and \fBcget\fR methods described in Tk::options which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic Tk::Widget class. .PP The following additional methods are available for Tree widgets: .ie n .IP "\fR\fI$tree\fR\fI\->\fR\fBadd_pathimage\fR(\fItreeRegExp [, openImg, closeImg]\fR)" 4 .el .IP "\fR\f(CI$tree\fR\fI\->\fR\fBadd_pathimage\fR(\fItreeRegExp [, openImg, closeImg]\fR)" 4 .IX Item "$tree->add_pathimage(treeRegExp [, openImg, closeImg])" This method defines images for a given path (images must be in xpm format). The path can be determined by a simplified regular expression. There are just three metasymbols: .RS 4 .IP ^ 4 at the beginning of the \f(CW\*(C`treeRegExp\*(C'\fR same as in Perl regular expressions .IP * 4 anything .IP $ 4 at the end of the \f(CW\*(C`TreeRegExp\*(C'\fR, the same as in Perl regular expressions .RE .RS 4 .Sp Examples: .Sp .Vb 1 \& $tree\->add_pathimage(\*(Aq^root\*(Aq,\*(Aqopenfolder\*(Aq,\*(Aqfolder\*(Aq); .Ve .Sp matches \f(CW\*(C`root\*(C'\fR, \f(CW\*(C`root.foo\*(C'\fR, \f(CW\*(C`root.bar\*(C'\fR, but not \f(CW\*(C`foo.root\*(C'\fR .Sp .Vb 1 \& $tree\->add_pathimage(\*(Aqroot.*.class\*(Aq,\*(Aqopenfolder\*(Aq,\*(Aqfolder\*(Aq); .Ve .Sp matches all paths containing \f(CW\*(C`root..class\*(C'\fR, but not \&\f(CW\*(C`root...class\*(C'\fR \f(CW\*(C`*\*(C'\fR is one part of the path. If you want to use a wildcard for two steps, you have to use \f(CW\*(C`*.*\*(C'\fR. .Sp .Vb 1 \& $tree\->add_pathimage(\*(Aqclass$\*(Aq,\*(Aqopenfolder\*(Aq,\*(Aqfolder\*(Aq); .Ve .Sp This matches all path with \f(CW\*(C`class\*(C'\fR at the end. .RE .ie n .IP \fR\fI$tree\fR\fI\fR\->\fBautosetmode\fR 4 .el .IP \fR\f(CI$tree\fR\fI\fR\->\fBautosetmode\fR 4 .IX Item "$tree->autosetmode" This method calls the \fBsetmode\fR method for all the entries in this Tree widget: if an entry has no child entries, its mode is set to \&\fBnone\fR. Otherwise, if the entry has any hidden child entries, its mode is set to \fBopen\fR; otherwise its mode is set to \fBclose\fR. .ie n .IP \fR\fI$tree\fR\fI\->\fR\fBchild_entries\fR([$path][,$depth]) 4 .el .IP \fR\f(CI$tree\fR\fI\->\fR\fBchild_entries\fR([$path][,$depth]) 4 .IX Item "$tree->child_entries([$path][,$depth])" This method returns in list context an array that contains all pathnames of subentries within the given path. In scalar context it returns the number of subentries in the given path. .Sp .Vb 6 \& Example: \& root \& | foo \& | bar \& | | bar1 \& | | bar2 \& \& my @childentries = $tree\->child_entries(\*(Aqroot.bar\*(Aq); \& # returns (root.bar.bar1, root.bar.bar2) \& \& my $nr_of_subentries = $tree\->child_entries(\*(Aqroot\*(Aq,2); \& # returns 4 .Ve .Sp If \f(CW$path\fR is omitted, all it is assumed, that the entry above \&'root' is meant. \f(CW$depth\fR defines the numbers of levels. .ie n .IP \fR\fI$tree\fR\fI\fR\->\fBclose\fR(\fIentryPath\fR) 4 .el .IP \fR\f(CI$tree\fR\fI\fR\->\fBclose\fR(\fIentryPath\fR) 4 .IX Item "$tree->close(entryPath)" Close the entry given by \fIentryPath\fR if its \fImode\fR is \fBclose\fR. .ie n .IP \fR\fI$tree\fR\fI\fR\->\fBgetmode\fR(\fIentryPath\fR) 4 .el .IP \fR\f(CI$tree\fR\fI\fR\->\fBgetmode\fR(\fIentryPath\fR) 4 .IX Item "$tree->getmode(entryPath)" Returns the current \fImode\fR of the entry given by \fIentryPath\fR. .ie n .IP \fR\fI$tree\fR\fI\fR\->\fBopen\fR(\fIentryPath\fR) 4 .el .IP \fR\f(CI$tree\fR\fI\fR\->\fBopen\fR(\fIentryPath\fR) 4 .IX Item "$tree->open(entryPath)" Open the entry given by \fIentryPath\fR if its \fImode\fR is \fBopen\fR. .ie n .IP "\fR\fI$tree\fR\fI\fR\->\fBsetmode\fR(\fIentryPath, mode\fR)" 4 .el .IP "\fR\f(CI$tree\fR\fI\fR\->\fBsetmode\fR(\fIentryPath, mode\fR)" 4 .IX Item "$tree->setmode(entryPath, mode)" This method is used to indicate whether the entry given by \&\fIentryPath\fR has children entries and whether the children are visible. \fImode\fR must be one of \fBopen\fR, \&\fBclose\fR or \fBnone\fR. If \fImode\fR is set to \fBopen\fR, a (+) indicator is drawn next to the entry. If \fImode\fR is set to \&\fBclose\fR, a (\-) indicator is drawn next to the entry. If \&\fImode\fR is set to \fBnone\fR, no indicators will be drawn for this entry. The default \fImode\fR is none. The \fBopen\fR mode indicates the entry has hidden children and this entry can be opened by the user. The \fBclose\fR mode indicates that all the children of the entry are now visible and the entry can be closed by the user. .SH BINDINGS .IX Header "BINDINGS" The basic mouse and keyboard bindings of the Tree widget are the same as the bindings of the HList widget. In addition, the entries can be opened or closed under the following conditions: .IP [1] 4 .IX Item "[1]" If the \fImode\fR of the entry is \fBopen\fR, it can be opened by clicking on its (+) indicator. .IP [2] 4 .IX Item "[2]" If the \fImode\fR of the entry is \fBclose\fR, it can be closed by clicking on its (\-) indicator. .SH "SEE ALSO" .IX Header "SEE ALSO" Tk::HList .SH AUTHOR .IX Header "AUTHOR" Perl/TK version by Chris Dean . Original Tcl/Tix version by Ioi Kim Lam. .PP Additions by Renee Baecker .SH ACKNOWLEDGEMENTS .IX Header "ACKNOWLEDGEMENTS" Thanks to Achim Bohnet for all his help.