Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / DItem.pod
CommitLineData
86530b38
AT
1=head1 NAME
2
3Tk::DItem - Tix Display Items
4
5=for category Tix Extensions
6
7=head1 SYNOPSIS
8
9=head1 DESCRIPTION
10
11The Tix B<Display Items> and B<Display Types> are devised to
12solve a general problem: many Tix widgets (both existing and planned
13ones) display many items of many types simultaneously.
14
15For example, a hierarchical listbox widget (see L<Tk::HList>) can display
16items
17of images, plain text and subwindows in the form of a
18hierarchy. Another widget, the tabular listbox widget (see L<Tk::TList>)
19also displays items of the
20same types, although it arranges the items in a tabular form. Yet
21another widget, the spreadsheet widget (see L<Tk::TixGrid>),
22also displays similar types
23items, but in yet another format.
24
25In these examples, the display items in different widgets are only
26different in how they are arranged by the B<host widget>. In Tix,
27display items are clearly separated from the host widgets. The
28advantage is two-fold: first, the creation and configuration of
29display items become uniform across different host widgets. Second,
30new display item types can be added without the need to modify the
31existing host widgets.
32
33In a way, Tix display items are similar to the items inside Tk
34the canvas widget. However, unlike the Tix display items, the canvas
35items are not independent of the canvas widget; this makes it
36impossible to use the canvas items inside other types of TK widgets.
37
38The appearance of a display item is controlled by a set of
39I<attributes>. It is observed that each the attributes usually fall
40into one of two categroies: ``I<individual>'' or
41``I<collective>''. For example, the text items inside a HList widget
42may all display a different text string; however, in most cases, the
43text items share the same color, font and spacing. Instead of keeping
44a duplicated version of the same attributes inside each display item,
45it will be advantageous to put the collective attributes in a
46special object called a B<display style>. First, there is the space
47concern: a host widget may have many thousands of items; keeping
48dupilcated attributes will be very wasteful. Second, when it becomes
49necessary to change a collective attribute, such as changing all the
50text items' foreground color to red, it will be more efficient to
51change only the display style object than to modify all the text
52items one by one.
53
54The attributes of the a display item are thus stored in two places: it
55has a set of B<item options> to store its individual attributes. Each
56display item is also associated with a I<display style>, which specifies
57the collective attributes of all items associated with itself.
58
59The division between the individual and collective attributes are
60fixed and cannot be changed. Thus, when it becomes necessary for some
61items to differ in their collective attributes, two or more B<display styles>
62can be used. For example, suppose you want to display two
63columns of text items inside an HList widget, one column in red and
64the other in blue. You can create a TextStyle object called ``$red''
65which defines a red foreground, and another called ``$blue'', which
66defines a blue foreground. You can then associate all text items of
67the first column to ``$red'' and the second column to ``$blue''
68
69=head1 DISPLAY ITEM TYPES AND OPTIONS
70
71Currently there are three types of display items: B<text>,
72B<imagetext> and I<window>.
73
74=head1 IMAGETEXT ITEMS
75
76Display items of the type B<imagetext> are used to display an image
77together with a text string. Imagetext items support the following options:
78
79=head2 Imagetext Item Options
80
81=over 4
82
83=item Name: B<bitmap>
84
85=item Class: B<Bitmap>
86
87=item Switch: B<-bitmap>
88
89Specifies the bitmap to display in the item.
90
91=item Name: B<image>
92
93=item Class: B<Image>
94
95=item Switch: B<-image>
96
97Specifies the image to display in the item. When both the
98B<-bitmap> and B<-image> options are specified, only the image
99will be displayed.
100
101=item Name: B<imageTextStyle>
102
103=item Class: B<ImageTextStyle>
104
105=item Switch: B<-style>
106
107Specifies the display style to use for this item. Must be the
108name of a B<imagetext> display style that has already be created with
109B<ItemStyle>.
110
111=item Name: B<showImage>
112
113=item Class: B<ShowImage>
114
115=item Switch: B<-showimage>
116
117A Boolean value that specifies whether the image/bitmap should be
118displayed.
119
120=item Name: B<showText>
121
122=item Class: B<ShowText>
123
124=item Switch: B<-showtext>
125
126A Boolean value that specifies whether the text string should be
127displayed.
128
129=item Name: B<text>
130
131=item Class: B<Text>
132
133=item Switch: B<-text>
134
135Specifies the text string to display in the item.
136
137=item Name: B<underline>
138
139=item Class: B<Underline>
140
141=item Switch: B<-underline>
142
143Specifies the integer index of a character to underline in the text
144string in the item. 0 corresponds to the first character of the text
145displayed in the widget, 1 to the next character, and so on.
146
147=back
148
149=head2 Imagetext Style Options
150
151The style information of B<imagetext> items are stored in the
152B<imagetext> display style. The following options are supported:
153
154B<STANDARD OPTIONS>
155
156B<-activebackground> B<-activeforeground>
157B<-anchor> B<-background>
158B<-disabledbackground> B<-disabledforeground>
159B<-foreground> B<-font>
160B<-justify> B<-padx>
161B<-pady> B<-selectbackground>
162B<-selectforeground> B<-wraplength>
163
164See L<Tk::options> for details of the standard options.
165
166B<STYLE-SPECIFIC OPTIONS>
167
168=over 4
169
170=item Name: B<gap>
171
172=item Class: B<Gap>
173
174=item Switch: B<-gap>
175
176Specifies the distance between the bitmap/image and the text string,
177in number of pixels.
178
179=item Name: B<textAnchor>
180
181=item Class: B<TextAnchor>
182
183=item Switch: B<-textanchor>
184
185The anchor position on the image to which text part is attached.
186This is a perl/Tk addition. Defaults to B<e> for compatibility with standard
187Tix. The interesting cases are
188
189=over 8
190
191=item B<n>
192
193Text is centred above the image.
194
195=item B<s>
196
197Text is centred below the image
198
199=item B<e>
200
201Text is centred to right of the image.
202
203=item B<w>
204
205Text is centred to left of the image.
206
207=item B<c>
208
209Text is centred over the image.
210
211=back
212
213The B<sw>, B<se>, B<ne>, and b<nw> cases look rather odd.
214
215To get items to line up correctly it will usually be necessary
216to specify B<-anchor> as well. e.g. with default B<e> then anchoring
217item as a whole B<w> lines images up down left with text stuck to right side.
218
219=back
220
221=head1 TEXT ITEMS
222
223Display items of the type B<text> are used to display a text string
224in a widget. Text items support the following options:
225
226=head2 Text Item Options
227
228=over 4
229
230=item Name: B<textStyle>
231
232=item Class: B<TextStyle>
233
234=item Switch: B<-style>
235
236Specifies the display style to use for this text item. Must be the
237name of a B<text> display style that has already be created with
238B<ItemStyle>.
239
240=item Name: B<text>
241
242=item Class: B<Text>
243
244=item Switch: B<-text>
245
246Specifies the text string to display in the item.
247
248=item Name: B<underline>
249
250=item Class: B<Underline>
251
252=item Switch: B<-underline>
253
254Specifies the integer index of a character to underline in the item.
2550 corresponds to the first character of the text displayed in the
256widget, 1 to the next character, and so on.
257
258=back
259
260=head2 Text Style Options
261
262B<STANDARD OPTIONS>
263
264B<-activebackground> B<-activeforeground>
265B<-anchor> B<-background>
266B<-disabledbackground> B<-disabledforeground>
267B<-foreground> B<-font>
268B<-justify> B<-padx>
269B<-pady> B<-selectbackground>
270B<-selectforeground> B<-wraplength>
271
272See L<Tk::options> for details of the standard options.
273
274=head1 WINDOW ITEMS
275
276Display items of the type I<window> are used to display a
277sub-window in a widget. B<Window> items support the following
278options:
279
280=head2 Window Item Options
281
282=over 4
283
284=item Name: B<windowStyle>
285
286=item Class: B<WindowStyle>
287
288=item Switch: B<-style>
289
290Specifies the display style to use for this window item. Must be the
291name of a I<window> display style that has already be created with
292the B<ItemStyle> method.
293
294=item Name: B<window>
295
296=item Class: B<Window>
297
298=item Switch: B<-window>
299
300=item Alias: B<-widget>
301
302Specifies the sub-window to display in the item.
303
304=back
305
306=head2 Window Style Options
307
308B<STYLE STANDARD OPTIONS>
309
310B<-anchor> B<-padx> B<-pady>
311
312See L<Tk::options> for details of the standard options.
313
314=head1 CREATING DISPLAY ITEMS
315
316Display items do not exist on their and thus they cannot be created
317independently of the widgets they reside in. As a rule, display items
318are created by special methods of their ``host'' widgets. For
319example, the HList widgets has a method B<item> which can be used
320to create new display items. The following code creates a new text
321item at the third column of the entry foo inside an HList widget:
322
323 my $hlist = $parent->HList(-columns=>3);
324 $hlist->add('foo');
325 $hlist->itemCreate('foo', 2, -itemtype=>'text', -text=>'Hello');
326
327The B<itemCreate> method of the HList widget accepts a variable
328number of arguments. The special argument B<-itemtype> specifies
329which type of display item to create. Options that are valid for this
330type of display items can then be specified by one or more
331I<option-value> pairs.
332
333After the display item is created, they can then be configured or
334destroyed using the methods provided by the host widget. For example,
335the HList widget has the methods B<itemConfigure>, B<itemCget>
336and B<itemDelete> for accessing the display items.
337
338=head1 CREATING AND MANIPULATING ITEM STYLES
339
340Item styles are created with B<ItemStyle>:
341
342=head1 SYNOPSIS
343
344S< >I<$widget>-E<gt>B<ItemStyle>(I<itemType> ?,B<-stylename>=E<gt>I<name>? ?,B<-refwindow>=E<gt>I<pathName>? ?,I<option>=E<gt>I<value>, ...>?);
345
346I<itemType> must be one of the existing display items types such as
347B<text>, B<imagetext>, B<window> or any new types added by
348the user. Additional arguments can be given in one or more
349I<option-value> pairs. I<option> can be any of the valid option
350for this display style or any of the following:
351
352=over 4
353
354=item B<-stylename> =E<gt> I<name>
355
356Specifies a name for this style. If unspecified, then a default name
357will be chosen for this style.
358
359=item B<-refwindow> =E<gt> I<$otherwidget>
360
361Specifies a window to use for determine the default values of the
362display type. If unspecified, the I<$widget> will be used. Default
363values for the display types can be set via the options database. The
364following example sets the B<-disablebackground> and
365B<-disabledforeground> options of a B<text> display style via
366the option database:
367
368 $widget->optionAdd('*table.list*disabledForeground' => 'blue');
369 $widget->optionAdd('*table.list*disabledBackground' => 'darkgray');
370 $widget->ItemStyle('text', -refwindow => $table_list, -fg => 'red');
371
372By using the option database to set the options of the display styles,
373we can advoid hard-coding the option values and give the user more
374flexibility in customization. See L<Tk::option> for a detailed description
375of the option database.
376
377=back
378
379=head1 STYLE METHODS
380
381The B<ItemStyle> method creates an object.
382This object supports the B<configure> and B<cget> methods
383described in L<Tk::options> which can be used to enquire and
384modify the options described above.
385
386The following additional methods are available for item styles:
387
388=over 4
389
390=item I<$style>-E<gt>B<delete>
391
392Destroy this display style object.
393
394=back
395
396=head1 EXAMPLE
397
398The following example creates two columns of data in a HList
399widget. The first column is in red and the second column in blue. The
400colors of the columns are controlled by two different B<text>
401styles. Also, the anchor and font of the second column is chosen so
402that the income data is aligned properly.
403
404 use strict;
405 use Tk;
406 use Tk::HList;
407 use Tk::ItemStyle;
408
409 my $mw = MainWindow->new();
410
411 my $hlist = $mw->HList(-columns=>2)->pack;
412
413 my $red = $hlist->ItemStyle('text', -foreground=>'#800000');
414 my $blue = $hlist->ItemStyle('text', -foreground=>'#000080', -anchor=>'e');
415
416 my $e;
417 foreach ([Joe => '$10,000'], [Peter => '$20,000'],
418 [Raj => '$90,000'], [Zinh => '$0']) {
419 $e = $hlist->addchild("");
420 $hlist->itemCreate($e, 0, -itemtype=>'text',
421 -text=>$_->[0], -style=>$red );
422 $hlist->itemCreate($e, 1, -itemtype=>'text',
423 -text=>$_->[1], -style=>$blue);
424 }
425
426 Tk::MainLoop;
427
428=head1 SEE ALSO
429
430L<Tk::HList|Tk::HList>
431L<Tk::TixGrid|Tk::TixGrid>
432L<Tk::TList|Tk::TList>
433
434=head1 KEYWORDS
435
436display item, display style, item style
437
438=cut
439