home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _23216029b0b5e7c5c0169bddd874e27f < prev    next >
Encoding:
Text File  |  2004-06-01  |  12.4 KB  |  440 lines

  1. =head1 NAME
  2.  
  3. Tk::DItem - Tix Display Items
  4.  
  5. =for category Tix Extensions
  6.  
  7. =head1 SYNOPSIS
  8.  
  9. =head1 DESCRIPTION
  10.  
  11. The Tix B<Display Items> and B<Display Types> are devised to
  12. solve a general problem: many Tix widgets (both existing and planned
  13. ones) display many items of many types simultaneously.
  14.  
  15. For example, a hierarchical listbox widget (see L<Tk::HList>) can display
  16. items
  17. of images, plain text and subwindows in the form of a
  18. hierarchy. Another widget, the tabular listbox widget (see L<Tk::TList>)
  19. also displays items of the
  20. same types, although it arranges the items in a tabular form. Yet
  21. another widget, the spreadsheet widget (see L<Tk::TixGrid>),
  22. also displays similar types
  23. items, but in yet another format.
  24.  
  25. In these examples, the display items in different widgets are only
  26. different in how they are arranged by the B<host widget>. In Tix,
  27. display items are clearly separated from the host widgets. The
  28. advantage is two-fold: first, the creation and configuration of
  29. display items become uniform across different host widgets. Second,
  30. new display item types can be added without the need to modify the
  31. existing host widgets.
  32.  
  33. In a way, Tix display items are similar to the items inside Tk
  34. the canvas widget. However, unlike the Tix display items, the canvas
  35. items are not independent of the canvas widget; this makes it
  36. impossible to use the canvas items inside other types of TK widgets.
  37.  
  38. The appearance of a display item is controlled by a set of
  39. I<attributes>. It is observed that each the attributes usually fall
  40. into one of two categroies: ``I<individual>'' or
  41. ``I<collective>''. For example, the text items inside a HList widget
  42. may all display a different text string; however, in most cases, the
  43. text items share the same color, font and spacing. Instead of keeping
  44. a duplicated version of the same attributes inside each display item,
  45. it will be advantageous to put the collective attributes in a
  46. special object called a B<display style>. First, there is the space
  47. concern: a host widget may have many thousands of items; keeping
  48. dupilcated attributes will be very wasteful. Second, when it becomes
  49. necessary to change a collective attribute, such as changing all the
  50. text items' foreground color to red, it will be more efficient to
  51. change only the display style object than to modify all the text
  52. items one by one.
  53.  
  54. The attributes of the a display item are thus stored in two places: it
  55. has a set of B<item options> to store its individual attributes. Each
  56. display item is also associated with a I<display style>, which specifies
  57. the collective attributes of all items associated with itself.
  58.  
  59. The division between the individual and collective attributes are
  60. fixed and cannot be changed. Thus, when it becomes necessary for some
  61. items to differ in their collective attributes, two or more B<display styles>
  62. can be used. For example, suppose you want to display two
  63. columns of text items inside an HList widget, one column in red and
  64. the other in blue. You can create a TextStyle object called ``$red''
  65. which defines a red foreground, and another called ``$blue'', which
  66. defines a blue foreground. You can then associate all text items of
  67. the first column to ``$red'' and the second column to ``$blue''
  68.  
  69. =head1 DISPLAY ITEM TYPES AND OPTIONS
  70.  
  71. Currently there are three types of display items: B<text>,
  72. B<imagetext> and I<window>.
  73.  
  74. =head1 IMAGETEXT ITEMS
  75.  
  76. Display items of the type B<imagetext> are used to display an image
  77. together 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.  
  89. Specifies 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.  
  97. Specifies the image to display in the item. When both the
  98. B<-bitmap> and B<-image> options are specified, only the image
  99. will be displayed.
  100.  
  101. =item Name:    B<imageTextStyle>
  102.  
  103. =item Class:    B<ImageTextStyle>
  104.  
  105. =item Switch:    B<-style>
  106.  
  107. Specifies the display style to use for this item. Must be the
  108. name of a B<imagetext> display style that has already be created with
  109. B<ItemStyle>.
  110.  
  111. =item Name:    B<showImage>
  112.  
  113. =item Class:    B<ShowImage>
  114.  
  115. =item Switch:    B<-showimage>
  116.  
  117. A Boolean value that specifies whether the image/bitmap should be
  118. displayed.
  119.  
  120. =item Name:    B<showText>
  121.  
  122. =item Class:    B<ShowText>
  123.  
  124. =item Switch:    B<-showtext>
  125.  
  126. A Boolean value that specifies whether the text string should be
  127. displayed.
  128.  
  129. =item Name:    B<text>
  130.  
  131. =item Class:    B<Text>
  132.  
  133. =item Switch:    B<-text>
  134.  
  135. Specifies 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.  
  143. Specifies the integer index of a character to underline in the text
  144. string in the item.  0 corresponds to the first character of the text
  145. displayed in the widget, 1 to the next character, and so on.
  146.  
  147. =back
  148.  
  149. =head2 Imagetext Style Options
  150.  
  151. The style information of B<imagetext> items are stored in the
  152. B<imagetext> display style. The following options are supported:
  153.  
  154. B<STANDARD OPTIONS>
  155.  
  156. B<-activebackground>    B<-activeforeground>
  157. B<-anchor>    B<-background>
  158. B<-disabledbackground>    B<-disabledforeground>
  159. B<-foreground>    B<-font>
  160. B<-justify>    B<-padx>
  161. B<-pady>    B<-selectbackground>
  162. B<-selectforeground>    B<-wraplength>
  163.  
  164. See L<Tk::options> for details of the standard options.
  165.  
  166. B<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.  
  176. Specifies the distance between the bitmap/image and the text string,
  177. in number of pixels.
  178.  
  179. =item Name:    B<textAnchor>
  180.  
  181. =item Class:    B<TextAnchor>
  182.  
  183. =item Switch:    B<-textanchor>
  184.  
  185. The anchor position on the image to which text part is attached.
  186. This is a perl/Tk addition. Defaults to B<e> for compatibility with standard
  187. Tix. The interesting cases are
  188.  
  189. =over 8
  190.  
  191. =item B<n>
  192.  
  193. Text is centred above the image.
  194.  
  195. =item B<s>
  196.  
  197. Text is centred below the image
  198.  
  199. =item B<e>
  200.  
  201. Text is centred to right of the image.
  202.  
  203. =item B<w>
  204.  
  205. Text is centred to left of the image.
  206.  
  207. =item B<c>
  208.  
  209. Text is centred over the image.
  210.  
  211. =back
  212.  
  213. The B<sw>, B<se>, B<ne>, and b<nw> cases look rather odd.
  214.  
  215. To get items to line up correctly it will usually be necessary
  216. to specify B<-anchor> as well. e.g. with default B<e> then anchoring
  217. item 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.  
  223. Display items of the type B<text> are used to display a text string
  224. in 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.  
  236. Specifies the display style to use for this text item. Must be the
  237. name of a B<text> display style that has already be created with
  238. B<ItemStyle>.
  239.  
  240. =item Name:    B<text>
  241.  
  242. =item Class:    B<Text>
  243.  
  244. =item Switch:    B<-text>
  245.  
  246. Specifies 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.  
  254. Specifies the integer index of a character to underline in the item.
  255. 0 corresponds to the first character of the text displayed in the
  256. widget, 1 to the next character, and so on.
  257.  
  258. =back
  259.  
  260. =head2 Text Style Options
  261.  
  262. B<STANDARD OPTIONS>
  263.  
  264. B<-activebackground>    B<-activeforeground>
  265. B<-anchor>    B<-background>
  266. B<-disabledbackground>    B<-disabledforeground>
  267. B<-foreground>    B<-font>
  268. B<-justify>    B<-padx>
  269. B<-pady>    B<-selectbackground>
  270. B<-selectforeground>    B<-wraplength>
  271.  
  272. See L<Tk::options> for details of the standard options.
  273.  
  274. =head1 WINDOW ITEMS
  275.  
  276. Display items of the type I<window> are used to display a
  277. sub-window in a widget. B<Window> items support the following
  278. options:
  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.  
  290. Specifies the display style to use for this window item. Must be the
  291. name of a I<window> display style that has already be created with
  292. the 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.  
  302. Specifies the sub-window to display in the item.
  303.  
  304. =back
  305.  
  306. =head2 Window Style Options
  307.  
  308. B<STYLE STANDARD OPTIONS>
  309.  
  310. B<-anchor>    B<-padx>    B<-pady>
  311.  
  312. See L<Tk::options> for details of the standard options.
  313.  
  314. =head1 CREATING DISPLAY ITEMS
  315.  
  316. Display items do not exist on their and thus they cannot be created
  317. independently of the widgets they reside in. As a rule, display items
  318. are created by special methods of their ``host'' widgets. For
  319. example, the HList widgets has a method B<item> which can be used
  320. to create new display items. The following code creates a new text
  321. item 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.  
  327. The B<itemCreate> method of the HList widget accepts a variable
  328. number of arguments. The special argument B<-itemtype> specifies
  329. which type of display item to create. Options that are valid for this
  330. type of display items can then be specified by one or more
  331. I<option-value> pairs.
  332.  
  333. After the display item is created, they can then be configured or
  334. destroyed using the methods provided by the host widget. For example,
  335. the HList widget has the methods B<itemConfigure>, B<itemCget>
  336. and B<itemDelete> for accessing the display items.
  337.  
  338. =head1 CREATING AND MANIPULATING ITEM STYLES
  339.  
  340. Item styles are created with B<ItemStyle>:
  341.  
  342. =head1 SYNOPSIS
  343.  
  344. S<   >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.  
  346. I<itemType> must be one of the existing display items types such as
  347. B<text>, B<imagetext>, B<window> or any new types added by
  348. the user. Additional arguments can be given in one or more
  349. I<option-value> pairs. I<option> can be any of the valid option
  350. for this display style or any of the following:
  351.  
  352. =over 4
  353.  
  354. =item B<-stylename> =E<gt> I<name>
  355.  
  356. Specifies a name for this style. If unspecified, then a default name
  357. will be chosen for this style.
  358.  
  359. =item B<-refwindow> =E<gt> I<$otherwidget>
  360.  
  361. Specifies a window to use for determine the default values of the
  362. display type. If unspecified, the I<$widget> will be used. Default
  363. values for the display types can be set via the options database. The
  364. following example sets the B<-disablebackground> and
  365. B<-disabledforeground> options of a B<text> display style via
  366. the 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.  
  372. By using the option database to set the options of the display styles,
  373. we can advoid hard-coding the option values and give the user more
  374. flexibility in customization. See L<Tk::option> for a detailed description
  375. of the option database.
  376.  
  377. =back
  378.  
  379. =head1 STYLE METHODS
  380.  
  381. The B<ItemStyle> method creates an object.
  382. This object supports the B<configure> and B<cget> methods
  383. described in L<Tk::options> which can be used to enquire and
  384. modify the options described above.
  385.  
  386. The following additional methods are available for item styles:
  387.  
  388. =over 4
  389.  
  390. =item I<$style>-E<gt>B<delete>
  391.  
  392. Destroy this display style object.
  393.  
  394. =back
  395.  
  396. =head1 EXAMPLE
  397.  
  398. The following example creates two columns of data in a HList
  399. widget. The first column is in red and the second column in blue. The
  400. colors of the columns are controlled by two different B<text>
  401. styles. Also, the anchor and font of the second column is chosen so
  402. that 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.  
  430. L<Tk::HList|Tk::HList>
  431. L<Tk::TixGrid|Tk::TixGrid>
  432. L<Tk::TList|Tk::TList>
  433.  
  434. =head1 KEYWORDS
  435.  
  436. display item, display style, item style
  437.  
  438. =cut
  439.  
  440.