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

  1. # $Id: configspec.pod 1.2 Wed, 12 Nov 1997 00:30:45 +0100 ach $
  2.  
  3. =head1 NAME
  4.  
  5. Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.
  6.  
  7. =for category Derived Widgets
  8.  
  9. =head1 SYNOPSIS
  10.  
  11.     sub Populate
  12.     {
  13.      my ($composite,$args) = @_;
  14.      ...
  15.      $composite->ConfigSpecs('-attribute' => [ where,dbName,dbClass,default ]);
  16.      $composite->ConfigSpecs('-alias' => '-otherattribute');
  17.      $composite->ConfigSpecs('DEFAULT' => [ where ]);
  18.      $composite->ConfigSpecs($subwidget->ConfigSpecs);
  19.      ...
  20.     }
  21.  
  22.     $composite->configure(-attribute => value);
  23.  
  24. =head1 DESCRIPTION
  25.  
  26. The aim is to make the composite widget configure method look as much like
  27. a regular Tk widget's configure as possible.
  28. (See L<Tk::options> for a description of this behaviour.)
  29. To enable this the attributes that the composite as a whole accepts
  30. needs to be defined.
  31.  
  32. =head2 Defining the ConfigSpecs for a class.
  33.  
  34. Typically a widget will have one or more calls like the following
  35.  
  36.     $composite->ConfigSpecs(-attribute => [where,dbName,dbClass,default]);
  37.  
  38. in its B<Populate> method. When B<ConfigSpecs> is called this way
  39. (with arguments) the arguments are used to construct or augment/replace
  40. a hash table for the widget. (More than one I<-option>=E<gt>I<value>
  41. pair can be specified to a single call.)
  42.  
  43. B<dbName>, B<dbClass> and default are only used by B<ConfigDefault> described
  44. below, or to respond to 'inquiry' configure commands.
  45.  
  46. It may be either one of the values below, or a list of such values
  47. enclosed in B<[]>.
  48.  
  49. The currently permitted values of B<where> are:
  50.  
  51. =over 4
  52.  
  53. =item B<'ADVERTISED'>
  54.  
  55. Apply B<configure> to I<advertised> subwidgets.
  56.  
  57. =item B<'DESCENDANTS'>
  58.  
  59. Apply B<configure> recursively to all descendants.
  60.  
  61. =item B<'CALLBACK'>
  62.  
  63. Setting the attribute does C<Tk::Callback-E<gt>new($value)> before storing
  64. in C<$composite-E<gt>{Configure}{-attribute}>. This is appropriate for
  65. C<-command =E<gt> ...> attributes that are handled by the composite and not
  66. forwarded to a subwidget. (E.g. B<Tk::Tiler> has C<-yscrollcommand> to
  67. allow it to have scrollbar attached.)
  68.  
  69. This may be the first of several 'validating' keywords (e.g. font, cursor,
  70. anchor etc.) that core Tk makes special for C code.
  71.  
  72. =item B<'CHILDREN'>
  73.  
  74. Apply B<configure> to all children.  (Children are the immediate
  75. descendants of a widget.)
  76.  
  77. =item B<'METHOD'>
  78.  
  79. Call C<$cw-E<gt>attribute(value)>
  80.  
  81. This is the most general case. Simply have a method of the composite
  82. class with the same name as the attribute.  The method may do any
  83. validation and have whatever side-effects you like.  (It is probably
  84. worth 'queueing' using B<afterIdle> for more complex side-effects.)
  85.  
  86. =item B<'PASSIVE'>
  87.  
  88. Simply store value in C<$composite-E<gt>{Configure}{-attribute}>.
  89.  
  90. This form is also a useful placeholder for attributes which you
  91. currently only handle at create time.
  92.  
  93. =item B<'SELF'>
  94.  
  95. Apply B<configure> to the core widget (e.g. B<Frame>) that is the basis of
  96. the composite. (This is the default behaviour for most attributes which
  97. makes a simple Frame behave the way you would expect.) Note that once
  98. you have specified B<ConfigSpecs> for an attribute you must explicitly
  99. include C<'SELF'> in the list if you want the attribute to apply to the
  100. composite itself (this avoids nasty infinite recursion problems).
  101.  
  102. =item B<$reference> (blessed)
  103.  
  104. Call B<$reference>->configure(-attribute => value)
  105.  
  106. A common case is where B<$reference> is a subwidget.
  107.  
  108. $reference may also be result of
  109.  
  110.      Tk::Config->new(setmethod,getmethod,args,...);
  111.  
  112. B<Tk::Config> class is used to implement all the above keyword types.  The
  113. class has C<configure> and C<cget> methods so allows higher level code to
  114. I<always> just call one of those methods on an I<object> of some kind.
  115.  
  116. =item B<hash reference>
  117.  
  118. Defining:
  119.  
  120.     $cw->ConfigSpecs(
  121.         ...
  122.         -option => [ { -optionX=>$w1, -optionY=>[$w2, $w3] },
  123.                 dbname dbclass default ],
  124.         ...
  125.         );
  126.  
  127. So C<$cw-E<gt>configure(-option =E<gt> value)> actually does
  128.  
  129.     $w1->configure(-optionX => value);
  130.     $w2->configure(-optionY => value);
  131.     $w3->configure(-optionY => value);
  132.  
  133. =item B<'otherstring'>
  134.  
  135. Call
  136.  
  137.     $composite->Subwidget('otherstring')->configure( -attribute => value );
  138.  
  139. While this is here for backward compatibility with Tk-b5, it is probably
  140. better just to use the subwidget reference directly.  The only
  141. case for retaining this form is to allow an additional layer of
  142. abstraction - perhaps having a 'current' subwidget - this is unproven.
  143.  
  144. =item B<Aliases>
  145.  
  146. C<ConfigSpecs( -alias =E<gt> '-otherattribute' )> is used to make C<-alias>
  147. equivalent to C<-otherattribute>. For example the aliases
  148.  
  149.     -fg => '-foreground',
  150.     -bg => '-background'
  151.  
  152. are provided automatically (if not already specified).
  153.  
  154. =back
  155.  
  156. =head2 Delegating all options of a widget class to a subwidget
  157.  
  158.     $composite->ConfigSpecs($subwidget->ConfigSpecs);
  159.  
  160. The above generates a list of I<composite> ConfigSpecs arguments, one
  161. for each valid option in $subwidget's class, and delegates said option
  162. to $subwidget.  See L<Tk::Widget> and the I<widget> method
  163. ConfigSpecs.  Duplicating I<composite> ConfigSpecs and I<widget>
  164. ConfigSpecs keys will yield undefined results.
  165.  
  166.  
  167. =head2 Default values
  168.  
  169. When the B<Populate> method returns B<ConfigDefault> is called.  This calls
  170.  
  171.     $composite->ConfigSpecs;
  172.  
  173. (with no arguments) to return a reference to a hash. Entries in the hash
  174. take the form:
  175.  
  176.     '-attribute' => [ where, dbName, dbClass, default ]
  177.  
  178. B<ConfigDefault> ignores 'where' completely (and also the DEFAULT entry) and
  179. checks the 'options' database on the widget's behalf, and if an entry is
  180. present matching dbName/dbClass
  181.  
  182.     -attribute => value
  183.  
  184. is added to the list of options that B<new> will eventually apply to the
  185. widget. Likewise if there is not a match and default is defined this
  186. default value will be added.
  187.  
  188. Alias entries in the hash are used to convert user-specified values for the
  189. alias into values for the real attribute.
  190.  
  191. =head2 B<New()-time configure>
  192.  
  193. Once control returns to B<new>, the list of user-supplied options
  194. augmented by those from B<ConfigDefault> are applied to the widget using the
  195. B<configure> method below.
  196.  
  197. Widgets are most flexible and most Tk-like if they handle the majority of
  198. their attributes this way.
  199.  
  200. =head2 Configuring composites
  201.  
  202. Once the above have occurred calls of the form:
  203.  
  204.     $composite->configure( -attribute => value );
  205.  
  206. should behave like any other widget as far as end-user code is concerned.
  207. B<configure> will be handled by B<Tk::Derived::configure> as follows:
  208.  
  209.     $composite->ConfigSpecs;
  210.  
  211. is called (with no arguments) to return a reference to a hash B<-attribute> is
  212. looked up in this hash, if B<-attribute> is not present in the hash then
  213. B<'DEFAULT'> is looked for instead.  (Aliases are tried as well and cause
  214. redirection to the aliased attribute).  The result should be a reference to a
  215. list like:
  216.  
  217.   [ where, dbName, dbClass, default ]
  218.  
  219. at this stage only I<where> is of interest, it maps to a list of object
  220. references (maybe only one) foreach one
  221.  
  222.    $object->configure( -attribute => value );
  223.  
  224. is B<eval>ed.
  225.  
  226. =head2 Inquiring attributes of composites
  227.  
  228.    $composite->cget( '-attribute' );
  229.  
  230. This is handled by  B<Tk::Derived::cget> in a similar manner to configure. At
  231. present if I<where> is a list of more than one object it is ignored completely
  232. and the "cached" value in
  233.  
  234.    $composite->{Configure}{-attribute}.
  235.  
  236. is returned.
  237.  
  238. =head1 CAVEATS
  239.  
  240. It is the author's intention to port as many of the "Tix" composite widgets
  241. as make sense. The mechanism described above may have to evolve in order to
  242. make this possible, although now aliases are handled I think the above is
  243. sufficient.
  244.  
  245. =head1 SEE ALSO
  246.  
  247. L<Tk::composite|Tk::composite>,
  248. L<Tk::options|Tk::options>,
  249. L<Tk::Widget>
  250.  
  251. =cut
  252.