.\" -*- 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 "DItem 3pm" .TH DItem 3pm 2024-03-07 "perl v5.38.2" "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::DItem \- Tix Display Items .SH SYNOPSIS .IX Header "SYNOPSIS" .SH DESCRIPTION .IX Header "DESCRIPTION" The Tix \fBDisplay Items\fR and \fBDisplay Types\fR are devised to solve a general problem: many Tix widgets (both existing and planned ones) display many items of many types simultaneously. .PP For example, a hierarchical listbox widget (see Tk::HList) can display items of images, plain text and subwindows in the form of a hierarchy. Another widget, the tabular listbox widget (see Tk::TList) also displays items of the same types, although it arranges the items in a tabular form. Yet another widget, the spreadsheet widget (see Tk::TixGrid), also displays similar types items, but in yet another format. .PP In these examples, the display items in different widgets are only different in how they are arranged by the \fBhost widget\fR. In Tix, display items are clearly separated from the host widgets. The advantage is two-fold: first, the creation and configuration of display items become uniform across different host widgets. Second, new display item types can be added without the need to modify the existing host widgets. .PP In a way, Tix display items are similar to the items inside Tk the canvas widget. However, unlike the Tix display items, the canvas items are not independent of the canvas widget; this makes it impossible to use the canvas items inside other types of TK widgets. .PP The appearance of a display item is controlled by a set of \&\fIattributes\fR. It is observed that each the attributes usually fall into one of two categroies: ``\fIindividual\fR'' or ``\fIcollective\fR''. For example, the text items inside a HList widget may all display a different text string; however, in most cases, the text items share the same color, font and spacing. Instead of keeping a duplicated version of the same attributes inside each display item, it will be advantageous to put the collective attributes in a special object called a \fBdisplay style\fR. First, there is the space concern: a host widget may have many thousands of items; keeping dupilcated attributes will be very wasteful. Second, when it becomes necessary to change a collective attribute, such as changing all the text items' foreground color to red, it will be more efficient to change only the display style object than to modify all the text items one by one. .PP The attributes of the a display item are thus stored in two places: it has a set of \fBitem options\fR to store its individual attributes. Each display item is also associated with a \fIdisplay style\fR, which specifies the collective attributes of all items associated with itself. .PP The division between the individual and collective attributes are fixed and cannot be changed. Thus, when it becomes necessary for some items to differ in their collective attributes, two or more \fBdisplay styles\fR can be used. For example, suppose you want to display two columns of text items inside an HList widget, one column in red and the other in blue. You can create a TextStyle object called ``$red'' which defines a red foreground, and another called ``$blue'', which defines a blue foreground. You can then associate all text items of the first column to ``$red'' and the second column to ``$blue'' .SH "DISPLAY ITEM TYPES AND OPTIONS" .IX Header "DISPLAY ITEM TYPES AND OPTIONS" Currently there are three types of display items: \fBtext\fR, \&\fBimagetext\fR and \fIwindow\fR. .SH "IMAGETEXT ITEMS" .IX Header "IMAGETEXT ITEMS" Display items of the type \fBimagetext\fR are used to display an image together with a text string. Imagetext items support the following options: .SS "Imagetext Item Options" .IX Subsection "Imagetext Item Options" .IP "Name: \fBbitmap\fR" 4 .IX Item "Name: bitmap" .PD 0 .IP "Class: \fBBitmap\fR" 4 .IX Item "Class: Bitmap" .IP "Switch: \fB\-bitmap\fR" 4 .IX Item "Switch: -bitmap" .PD Specifies the bitmap to display in the item. .IP "Name: \fBimage\fR" 4 .IX Item "Name: image" .PD 0 .IP "Class: \fBImage\fR" 4 .IX Item "Class: Image" .IP "Switch: \fB\-image\fR" 4 .IX Item "Switch: -image" .PD Specifies the image to display in the item. When both the \&\fB\-bitmap\fR and \fB\-image\fR options are specified, only the image will be displayed. .IP "Name: \fBimageTextStyle\fR" 4 .IX Item "Name: imageTextStyle" .PD 0 .IP "Class: \fBImageTextStyle\fR" 4 .IX Item "Class: ImageTextStyle" .IP "Switch: \fB\-style\fR" 4 .IX Item "Switch: -style" .PD Specifies the display style to use for this item. Must be the name of a \fBimagetext\fR display style that has already be created with \&\fBItemStyle\fR. .IP "Name: \fBshowImage\fR" 4 .IX Item "Name: showImage" .PD 0 .IP "Class: \fBShowImage\fR" 4 .IX Item "Class: ShowImage" .IP "Switch: \fB\-showimage\fR" 4 .IX Item "Switch: -showimage" .PD A Boolean value that specifies whether the image/bitmap should be displayed. .IP "Name: \fBshowText\fR" 4 .IX Item "Name: showText" .PD 0 .IP "Class: \fBShowText\fR" 4 .IX Item "Class: ShowText" .IP "Switch: \fB\-showtext\fR" 4 .IX Item "Switch: -showtext" .PD A Boolean value that specifies whether the text string should be displayed. .IP "Name: \fBtext\fR" 4 .IX Item "Name: text" .PD 0 .IP "Class: \fBText\fR" 4 .IX Item "Class: Text" .IP "Switch: \fB\-text\fR" 4 .IX Item "Switch: -text" .PD Specifies the text string to display in the item. .IP "Name: \fBunderline\fR" 4 .IX Item "Name: underline" .PD 0 .IP "Class: \fBUnderline\fR" 4 .IX Item "Class: Underline" .IP "Switch: \fB\-underline\fR" 4 .IX Item "Switch: -underline" .PD Specifies the integer index of a character to underline in the text string in the item. 0 corresponds to the first character of the text displayed in the widget, 1 to the next character, and so on. .SS "Imagetext Style Options" .IX Subsection "Imagetext Style Options" The style information of \fBimagetext\fR items are stored in the \&\fBimagetext\fR display style. The following options are supported: .PP \&\fBSTANDARD OPTIONS\fR .PP \&\fB\-activebackground\fR \fB\-activeforeground\fR \&\fB\-anchor\fR \fB\-background\fR \&\fB\-disabledbackground\fR \fB\-disabledforeground\fR \&\fB\-foreground\fR \fB\-font\fR \&\fB\-justify\fR \fB\-padx\fR \&\fB\-pady\fR \fB\-selectbackground\fR \&\fB\-selectforeground\fR \fB\-wraplength\fR .PP See Tk::options for details of the standard options. .PP \&\fBSTYLE-SPECIFIC OPTIONS\fR .IP "Name: \fBgap\fR" 4 .IX Item "Name: gap" .PD 0 .IP "Class: \fBGap\fR" 4 .IX Item "Class: Gap" .IP "Switch: \fB\-gap\fR" 4 .IX Item "Switch: -gap" .PD Specifies the distance between the bitmap/image and the text string, in number of pixels. .IP "Name: \fBtextAnchor\fR" 4 .IX Item "Name: textAnchor" .PD 0 .IP "Class: \fBTextAnchor\fR" 4 .IX Item "Class: TextAnchor" .IP "Switch: \fB\-textanchor\fR" 4 .IX Item "Switch: -textanchor" .PD The anchor position on the image to which text part is attached. This is a perl/Tk addition. Defaults to \fBe\fR for compatibility with standard Tix. The interesting cases are .RS 4 .IP \fBn\fR 8 .IX Item "n" Text is centred above the image. .IP \fBs\fR 8 .IX Item "s" Text is centred below the image .IP \fBe\fR 8 .IX Item "e" Text is centred to right of the image. .IP \fBw\fR 8 .IX Item "w" Text is centred to left of the image. .IP \fBc\fR 8 .IX Item "c" Text is centred over the image. .RE .RS 4 .Sp The \fBsw\fR, \fBse\fR, \fBne\fR, and b cases look rather odd. .Sp To get items to line up correctly it will usually be necessary to specify \fB\-anchor\fR as well. e.g. with default \fBe\fR then anchoring item as a whole \fBw\fR lines images up down left with text stuck to right side. .RE .SH "TEXT ITEMS" .IX Header "TEXT ITEMS" Display items of the type \fBtext\fR are used to display a text string in a widget. Text items support the following options: .SS "Text Item Options" .IX Subsection "Text Item Options" .IP "Name: \fBtextStyle\fR" 4 .IX Item "Name: textStyle" .PD 0 .IP "Class: \fBTextStyle\fR" 4 .IX Item "Class: TextStyle" .IP "Switch: \fB\-style\fR" 4 .IX Item "Switch: -style" .PD Specifies the display style to use for this text item. Must be the name of a \fBtext\fR display style that has already be created with \&\fBItemStyle\fR. .IP "Name: \fBtext\fR" 4 .IX Item "Name: text" .PD 0 .IP "Class: \fBText\fR" 4 .IX Item "Class: Text" .IP "Switch: \fB\-text\fR" 4 .IX Item "Switch: -text" .PD Specifies the text string to display in the item. .IP "Name: \fBunderline\fR" 4 .IX Item "Name: underline" .PD 0 .IP "Class: \fBUnderline\fR" 4 .IX Item "Class: Underline" .IP "Switch: \fB\-underline\fR" 4 .IX Item "Switch: -underline" .PD Specifies the integer index of a character to underline in the item. 0 corresponds to the first character of the text displayed in the widget, 1 to the next character, and so on. .SS "Text Style Options" .IX Subsection "Text Style Options" \&\fBSTANDARD OPTIONS\fR .PP \&\fB\-activebackground\fR \fB\-activeforeground\fR \&\fB\-anchor\fR \fB\-background\fR \&\fB\-disabledbackground\fR \fB\-disabledforeground\fR \&\fB\-foreground\fR \fB\-font\fR \&\fB\-justify\fR \fB\-padx\fR \&\fB\-pady\fR \fB\-selectbackground\fR \&\fB\-selectforeground\fR \fB\-wraplength\fR .PP See Tk::options for details of the standard options. .SH "WINDOW ITEMS" .IX Header "WINDOW ITEMS" Display items of the type \fIwindow\fR are used to display a sub-window in a widget. \fBWindow\fR items support the following options: .SS "Window Item Options" .IX Subsection "Window Item Options" .IP "Name: \fBwindowStyle\fR" 4 .IX Item "Name: windowStyle" .PD 0 .IP "Class: \fBWindowStyle\fR" 4 .IX Item "Class: WindowStyle" .IP "Switch: \fB\-style\fR" 4 .IX Item "Switch: -style" .PD Specifies the display style to use for this window item. Must be the name of a \fIwindow\fR display style that has already be created with the \fBItemStyle\fR method. .IP "Name: \fBwindow\fR" 4 .IX Item "Name: window" .PD 0 .IP "Class: \fBWindow\fR" 4 .IX Item "Class: Window" .IP "Switch: \fB\-window\fR" 4 .IX Item "Switch: -window" .IP "Alias: \fB\-widget\fR" 4 .IX Item "Alias: -widget" .PD Specifies the sub-window to display in the item. .SS "Window Style Options" .IX Subsection "Window Style Options" \&\fBSTYLE STANDARD OPTIONS\fR .PP \&\fB\-anchor\fR \fB\-padx\fR \fB\-pady\fR .PP See Tk::options for details of the standard options. .SH "CREATING DISPLAY ITEMS" .IX Header "CREATING DISPLAY ITEMS" Display items do not exist on their and thus they cannot be created independently of the widgets they reside in. As a rule, display items are created by special methods of their ``host'' widgets. For example, the HList widgets has a method \fBitem\fR which can be used to create new display items. The following code creates a new text item at the third column of the entry foo inside an HList widget: .PP .Vb 3 \& my $hlist = $parent\->HList(\-columns=>3); \& $hlist\->add(\*(Aqfoo\*(Aq); \& $hlist\->itemCreate(\*(Aqfoo\*(Aq, 2, \-itemtype=>\*(Aqtext\*(Aq, \-text=>\*(AqHello\*(Aq); .Ve .PP The \fBitemCreate\fR method of the HList widget accepts a variable number of arguments. The special argument \fB\-itemtype\fR specifies which type of display item to create. Options that are valid for this type of display items can then be specified by one or more \&\fIoption-value\fR pairs. .PP After the display item is created, they can then be configured or destroyed using the methods provided by the host widget. For example, the HList widget has the methods \fBitemConfigure\fR, \fBitemCget\fR and \fBitemDelete\fR for accessing the display items. .SH "CREATING AND MANIPULATING ITEM STYLES" .IX Header "CREATING AND MANIPULATING ITEM STYLES" Item styles are created with \fBItemStyle\fR: .SH SYNOPSIS .IX Header "SYNOPSIS" \ \ \ \fR\f(CI$widget\fR\fI\fR\->\fBItemStyle\fR(\fIitemType\fR ?,\fB\-stylename\fR=>\fIname\fR? ?,\fB\-refwindow\fR=>\fIpathName\fR? ?,\fIoption\fR=>\fIvalue\fR, ...>?); .PP \&\fIitemType\fR must be one of the existing display items types such as \&\fBtext\fR, \fBimagetext\fR, \fBwindow\fR or any new types added by the user. Additional arguments can be given in one or more \&\fIoption-value\fR pairs. \fIoption\fR can be any of the valid option for this display style or any of the following: .IP "\fB\-stylename\fR => \fIname\fR" 4 .IX Item "-stylename => name" Specifies a name for this style. If unspecified, then a default name will be chosen for this style. .ie n .IP "\fB\-refwindow\fR => \fR\fI$otherwidget\fR\fI\fR" 4 .el .IP "\fB\-refwindow\fR => \fR\f(CI$otherwidget\fR\fI\fR" 4 .IX Item "-refwindow => $otherwidget" Specifies a window to use for determine the default values of the display type. If unspecified, the \fR\f(CI$widget\fR\fI\fR will be used. Default values for the display types can be set via the options database. The following example sets the \fB\-disablebackground\fR and \&\fB\-disabledforeground\fR options of a \fBtext\fR display style via the option database: .Sp .Vb 3 \& $widget\->optionAdd(\*(Aq*table.list*disabledForeground\*(Aq => \*(Aqblue\*(Aq); \& $widget\->optionAdd(\*(Aq*table.list*disabledBackground\*(Aq => \*(Aqdarkgray\*(Aq); \& $widget\->ItemStyle(\*(Aqtext\*(Aq, \-refwindow => $table_list, \-fg => \*(Aqred\*(Aq); .Ve .Sp By using the option database to set the options of the display styles, we can advoid hard-coding the option values and give the user more flexibility in customization. See Tk::option for a detailed description of the option database. .SH "STYLE METHODS" .IX Header "STYLE METHODS" The \fBItemStyle\fR method creates an 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. .PP The following additional methods are available for item styles: .ie n .IP \fR\fI$style\fR\fI\fR\->\fBdelete\fR 4 .el .IP \fR\f(CI$style\fR\fI\fR\->\fBdelete\fR 4 .IX Item "$style->delete" Destroy this display style object. .SH EXAMPLE .IX Header "EXAMPLE" The following example creates two columns of data in a HList widget. The first column is in red and the second column in blue. The colors of the columns are controlled by two different \fBtext\fR styles. Also, the anchor and font of the second column is chosen so that the income data is aligned properly. .PP .Vb 4 \& use strict; \& use Tk; \& use Tk::HList; \& use Tk::ItemStyle; \& \& my $mw = MainWindow\->new(); \& \& my $hlist = $mw\->HList(\-columns=>2)\->pack; \& \& my $red = $hlist\->ItemStyle(\*(Aqtext\*(Aq, \-foreground=>\*(Aq#800000\*(Aq); \& my $blue = $hlist\->ItemStyle(\*(Aqtext\*(Aq, \-foreground=>\*(Aq#000080\*(Aq, \-anchor=>\*(Aqe\*(Aq); \& \& my $e; \& foreach ([Joe => \*(Aq$10,000\*(Aq], [Peter => \*(Aq$20,000\*(Aq], \& [Raj => \*(Aq$90,000\*(Aq], [Zinh => \*(Aq$0\*(Aq]) { \& $e = $hlist\->addchild(""); \& $hlist\->itemCreate($e, 0, \-itemtype=>\*(Aqtext\*(Aq, \& \-text=>$_\->[0], \-style=>$red ); \& $hlist\->itemCreate($e, 1, \-itemtype=>\*(Aqtext\*(Aq, \& \-text=>$_\->[1], \-style=>$blue); \& } \& \& Tk::MainLoop; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Tk::HList Tk::TixGrid Tk::TList .SH KEYWORDS .IX Header "KEYWORDS" display item, display style, item style