home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _23b90f6a5b166920c010a1312fef4e85 < prev    next >
Text File  |  2000-03-23  |  12KB  |  258 lines

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