home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <UL>
-
- <LI><A HREF="#defining the configspecs for a class.">Defining the ConfigSpecs for a class.</A></LI>
- <LI><A HREF="#default values">Default Values</A></LI>
- <LI><A HREF="#new()time configure">New()-time Configure</A></LI>
- <LI><A HREF="#configuring composites">Configuring composites</A></LI>
- <LI><A HREF="#inquiring attributes of composites">Inquiring attributes of composites</A></LI>
- </UL>
-
- <LI><A HREF="#caveats">CAVEATS</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- sub Populate
- {
- my ($composite,$args) = @_;
- ...
- $composite->ConfigSpecs('-attribute' => [ where,dbName,dbClass,default ]);
- $composite->ConfigSpecs('-alias' => '-otherattribute');
- $composite->ConfigSpecs('DEFAULT' => [ where ]);
- ...
- }</PRE>
- <PRE>
- $composite->configure(-attribute => value);</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>The aim is to make the composite widget configure method look as much like
- a regular Tk widget's configure as possible.
- (See <A HREF="../../../site/lib/Tk/options.html">the Tk::options manpage</A> for a description of this behaviour.)
- To enable this the attributes that the composite as a whole accepts
- needs to be defined.</P>
- <P>
- <H2><A NAME="defining the configspecs for a class.">Defining the ConfigSpecs for a class.</A></H2>
- <P>Typically a widget will have one or more calls like the following</P>
- <PRE>
- $composite->ConfigSpecs(-attribute => [where,dbName,dbClass,default]);</PRE>
- <P>in its <STRONG>Populate</STRONG> method. When <STRONG>ConfigSpecs</STRONG> is called this way
- (with arguments) the arguments are used to construct or augment/replace
- a hash table for the widget. (More than one <EM>-option</EM>=><EM>value</EM>
- pair can be specified to a single call.)</P>
- <P><STRONG>dbName</STRONG>, <STRONG>dbClass</STRONG> and default are only used by <STRONG>ConfigDefault</STRONG> described
- below, or to respond to 'inquiry' configure commands.</P>
- <P>It may be either one of the values below, or a list of such values
- enclosed in <STRONG>[]</STRONG>.</P>
- <P>The currently permitted values of <STRONG>where</STRONG> are:</P>
- <DL>
- <DT><STRONG><A NAME="item_%27ADVERTISED%27"><STRONG>'ADVERTISED'</STRONG></A></STRONG><BR>
- <DD>
- apply <STRONG>configure</STRONG> to <EM>advertised</EM> subwidgets.
- <P></P>
- <DT><STRONG><A NAME="item_%27DESCENDANTS%27"><STRONG>'DESCENDANTS'</STRONG></A></STRONG><BR>
- <DD>
- apply <STRONG>configure</STRONG> recursively to all descendants.
- <P></P>
- <DT><STRONG><A NAME="item_%27CALLBACK%27"><STRONG>'CALLBACK'</STRONG></A></STRONG><BR>
- <DD>
- Setting the attribute does <CODE>Tk::Callback->new($value)</CODE> before storing
- in <CODE>$composite->{Configure}{-attribute}</CODE>. This is appropriate for
- <CODE>-command => ...</CODE> attributes that are handled by the composite and not
- forwarded to a subwidget. (E.g. <STRONG>Tk::Tiler</STRONG> has <CODE>-yscrollcommand</CODE> to
- allow it to have scrollbar attached.)
- <P>This may be the first of several 'validating' keywords (e.g. font, cursor,
- anchor etc.) that core Tk makes special for C code.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27CHILDREN%27"><STRONG>'CHILDREN'</STRONG></A></STRONG><BR>
- <DD>
- apply <STRONG>configure</STRONG> to all children. (Children are the immediate
- descendants of a widget.)
- <P></P>
- <DT><STRONG><A NAME="item_%27METHOD%27"><STRONG>'METHOD'</STRONG></A></STRONG><BR>
- <DD>
- Call <CODE>$cw->attribute(value)</CODE>
- <P>This is the most general case. Simply have a method of the composite
- class with the same name as the attribute. The method may do any
- validation and have whatever side-effects you like. (It is probably
- worth 'queueing' using <STRONG>afterIdle</STRONG> for more complex side-effects.)</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27PASSIVE%27"><STRONG>'PASSIVE'</STRONG></A></STRONG><BR>
- <DD>
- Simply store value in <CODE>$composite->{Configure}{-attribute}</CODE>.
- <P>This form is also a useful placeholder for attributes which you
- currently only handle at create time.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27SELF%27"><STRONG>'SELF'</STRONG></A></STRONG><BR>
- <DD>
- Apply <STRONG>configure</STRONG> to the core widget (e.g. <STRONG>Frame</STRONG>) that is the basis of
- the composite. (This is the default behaviour for most attributes which
- makes a simple Frame behave the way you would expect.) Note that once
- you have specified <STRONG>ConfigSpecs</STRONG> for an attribute you must explicitly
- include <A HREF="#item_%27SELF%27"><CODE>'SELF'</CODE></A> in the list if you want the attribute to apply to the
- composite itself (this avoids nasty infinite recursion problems).
- <P></P>
- <DT><STRONG><A NAME="item_reference"><STRONG>$reference</STRONG> (blessed)</A></STRONG><BR>
- <DD>
- Call <STRONG>$reference</STRONG>->configure(-attribute => value)
- <P>A common case is where <STRONG>$reference</STRONG> is a subwidget.</P>
- <P>$reference may also be result of</P>
- <PRE>
- Tk::Config->new(setmethod,getmethod,args,...);</PRE>
- <P><STRONG>Tk::Config</STRONG> class is used to implement all the above keyword types. The
- class has <CODE>configure</CODE> and <CODE>cget</CODE> methods so allows higher level code to
- <EM>always</EM> just call one of those methods on an <EM>object</EM> of some kind.</P>
- <P></P>
- <DT><STRONG><A NAME="item_hash_reference"><STRONG>hash reference</STRONG></A></STRONG><BR>
- <DD>
- Defining:
- <PRE>
- $cw->ConfigSpecs(
- ...
- -option => [ { -optionX=>$w1, -optionY=>[$w2, $w3] },
- dbname dbclass default ],
- ...
- );</PRE>
- <P>So <CODE>$cw->configure(-option => value)</CODE> actually does</P>
- <PRE>
- $w1->configure(-optionX => value);
- $w2->configure(-optionY => value);
- $w3->configure(-optionY => value);</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%27otherstring%27"><STRONG>'otherstring'</STRONG></A></STRONG><BR>
- <DD>
- Call
- <PRE>
- $composite->Subwidget('otherstring')->configure( -attribute => value );</PRE>
- <P>While this is here for backward compatibility with Tk-b5, it is probably
- better just to use the subwidget reference directly. The only
- case for retaining this form is to allow an additional layer of
- abstraction - perhaps having a 'current' subwidget - this is unproven.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Aliases"><STRONG>Aliases</STRONG></A></STRONG><BR>
- <DD>
- <CODE>ConfigSpecs( -alias => '-otherattribute' )</CODE> is used to make <CODE>-alias</CODE>
- equivalent to <CODE>-otherattribute</CODE>. For example the aliases
- <PRE>
- -fg => '-foreground',
- -bg => '-background'</PRE>
- <P>are provided automatically (if not already specified).</P>
- <P></P></DL>
- <P>
- <H2><A NAME="default values">Default Values</A></H2>
- <P>When the <STRONG>Populate</STRONG> method returns <STRONG>ConfigDefault</STRONG> is called. This calls</P>
- <PRE>
- $composite->ConfigSpecs;</PRE>
- <P>(with no arguments) to return a reference to a hash. Entries in the hash
- take the form:</P>
- <PRE>
- '-attribute' => [ where, dbName, dbClass, default ]</PRE>
- <P><STRONG>ConfigDefault</STRONG> ignores 'where' completely (and also the DEFAULT entry) and
- checks the 'options' database on the widget's behalf, and if an entry is
- present matching dbName/dbClass</P>
- <PRE>
- -attribute => value</PRE>
- <P>is added to the list of options that <STRONG>new</STRONG> will eventually apply to the
- widget. Likewise if there is not a match and default is defined this
- default value will be added.</P>
- <P>Alias entries in the hash are used to convert user-specified values for the
- alias into values for the real attribute.</P>
- <P>
- <H2><A NAME="new()time configure">New()-time Configure</A></H2>
- <P>Once control returns to <STRONG>new</STRONG>, the list of user-supplied options
- augmented by those from <STRONG>ConfigDefault</STRONG> are applied to the widget using the
- <STRONG>configure</STRONG> method below.</P>
- <P>Widgets are most flexible and most Tk-like if they handle the majority of
- their attributes this way.</P>
- <P>
- <H2><A NAME="configuring composites">Configuring composites</A></H2>
- <P>Once the above have occurred calls of the form:</P>
- <PRE>
- $composite->configure( -attribute => value );</PRE>
- <P>should behave like any other widget as far as end-user code is concerned.
- <STRONG>configure</STRONG> will be handled by <STRONG>Tk::Derived::configure</STRONG> as follows:</P>
- <PRE>
- $composite->ConfigSpecs;</PRE>
- <P>is called (with no arguments) to return a reference to a hash <STRONG>-attribute</STRONG> is
- looked up in this hash, if <STRONG>-attribute</STRONG> is not present in the hash then
- <STRONG>'DEFAULT'</STRONG> is looked for instead. (Aliases are tried as well and cause
- redirection to the aliased attribute). The result should be a reference to a
- list like:</P>
- <PRE>
- [ where, dbName, dbClass, default ]</PRE>
- <P>at this stage only <EM>where</EM> is of interest, it maps to a list of object
- references (maybe only one) foreach one</P>
- <PRE>
- $object->configure( -attribute => value );</PRE>
- <P>is <STRONG>eval</STRONG>ed.</P>
- <P>
- <H2><A NAME="inquiring attributes of composites">Inquiring attributes of composites</A></H2>
- <PRE>
- $composite->cget( '-attribute' );</PRE>
- <P>This is handled by <STRONG>Tk::Derived::cget</STRONG> in a similar manner to configure. At
- present if <EM>where</EM> is a list of more than one object it is ignored completely
- and the ``cached'' value in</P>
- <PRE>
- $composite->{Configure}{-attribute}.</PRE>
- <P>is returned.</P>
- <P>
- <HR>
- <H1><A NAME="caveats">CAVEATS</A></H1>
- <P>It is the author's intention to port as many of the ``Tix'' composite widgets
- as make sense. The mechanism described above may have to evolve in order to
- make this possible, although now aliases are handled I think the above is
- sufficient.</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/Tk/composite.html">Tk::composite</A>,
- <A HREF="../../../site/lib/Tk/options.html">Tk::options</A></P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-