<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Tue May 21 19:22:32 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='180'>
<header><title>Add a Megawidget Support Core Package</title><author address="mailto:damon@unreality.com">Damon Courtney</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.5 $</status><history></history><created day='22' month='mar' year='2003' /><keyword>Tk</keyword></header>
<abstract>This TIP proposes the addition of a &quot;megawidget&quot; package to Tk as a core package which contains a set of functions useful for building megawidgets with standard script-level behaviour in Tk.</abstract>
<body><section title="Rationale">
<para>It&apos;s obvious (to me at least) from the (growing) number of pure-Tcl megawidget packages that it would be very helpful for Tk to provide some mechanism to help all these various packages do things in some standard way.</para>
<para>For example, there is a base set of options and commands that are supported by all Tk core widgets that should also be supported in any megawidget. Now, most of the packages do their job at supporting these, but I think a lot of it could be done very easily through a common method that would ensure that any megawidget created in this manor has not only a standard set of options and commands, but those commands will also produce standard error messages and the like.</para>
<para>Though I am not opposed to this TIP being added to Tk&apos;s core, I propose it as a core package only because the only time its functions are really needed is when working with a megawidget library. These functions don&apos;t do much to help the average Tk developer and are mostly meant for the developer&apos;s developer.</para>
<para>This TIP does not seek to tell megawidget extension writers how they should write their widgets. Eveyone has their own ideas of how that should be done. This package merely provides some helper functions to try and speed up the most common widget functions.</para>
</section>
<section title="Specification">
<para>The commands for this package are all written in C for speed reasons. After testing different megawidget packages, I find that most of them are very slow at the most basic widget functions like <emph style="bold">cget</emph> and <emph style="bold">configure</emph>. That was why I set out to write all of the standard functions in C and provide the hooks for various packages to use them instead of all the homegrown solutions that have been used.</para>
<para>The following commands would be part of the package:</para>
<para><emph style="bold">::megawidget::class</emph> <emph style="italic">widgetClass</emph></para>
<quote>Define a new megawidget class.</quote>
<para><emph style="bold">::megawidget::commands</emph> <emph style="italic">widgetClass</emph> ?<emph style="italic">command ...</emph>?</para>
<quote>Define a list of subcommands available to widgets of <emph style="italic">widgetClass</emph>.</quote>
<para><emph style="bold">::megawidget::options</emph> <emph style="italic">widgetClass</emph> ?<emph style="italic">optionList ...</emph>?</para>
<quote>Define the options available to widgets of <emph style="italic">widgetClass</emph>. An <emph style="italic">optionList</emph> is a list describing the option:</quote>
<quote><emph style="italic">type option dbClass dbName defValue</emph></quote>
<quote>The <emph style="italic">type</emph> value can be <emph style="bold">boolean</emph>, <emph style="bold">int</emph>, <emph style="bold">double</emph>, <emph style="bold">string</emph>, <emph style="bold">enum</emph>, <emph style="bold">color</emph>, <emph style="bold">font</emph>, <emph style="bold">bitmap</emph>, <emph style="bold">border</emph>, <emph style="bold">relief</emph>, <emph style="bold">cursor</emph>, <emph style="bold">justify</emph>, <emph style="bold">anchor</emph>, <emph style="bold">synonym</emph>, <emph style="bold">pixels</emph>, or <emph style="bold">window</emph>. The other values should be familiar to users of Tk&apos;s standard <emph style="bold">configure</emph> subcommand.</quote>
<para><emph style="bold">::megawidget::create</emph> <emph style="italic">widgetName widgetClass commandName</emph></para>
<quote>Create a new megawidget of class <emph style="italic">widgetClass</emph> from <emph style="italic">widgetName</emph>. <emph style="italic">widgetName</emph> must already exist as a widget, and its widget command will be renamed to <emph style="italic">commandName</emph> and replaced by a new command that will handle the defined subcommands for the widget class.</quote>
<para><emph style="bold">::megawidget::cget</emph> <emph style="italic">pathName option</emph></para>
<quote>Get the value of a megawidget option for <emph style="italic">pathName</emph>. This function is also called as a result of [<emph style="italic">pathName</emph> <emph style="bold">cget</emph>].</quote>
<para><emph style="bold">::megawidget::configure</emph> <emph style="italic">pathName</emph> ?<emph style="italic">option</emph>? ?<emph style="italic">value option value ...</emph>?</para>
<quote>Configure or query option values for the megawidget <emph style="italic">pathName</emph>. This function is also called as a result of [<emph style="italic">pathName</emph> <emph style="bold">configure</emph>].</quote>
<para>The options of a widget are stored and retrieved in dictionaries. The <emph style="bold">configure</emph> and <emph style="bold">cget</emph> commands are handled by the widget command after a widget is created, and all other commands are passed to the author to handle.</para>
<para>Some options (like <emph style="bold">-cursor</emph>, <emph style="bold">-background</emph>, <emph style="bold">-borderwidth</emph>, <emph style="bold">-bg</emph>, <emph style="bold">-bd</emph>) should probably be created for all megawidgets, but that has yet to be decided and is open for discussion.</para>
</section>
<section title="Author&apos;s Note">
<para>I have completed work on this package with all the functions written in C and with great care to keep them as fast and efficient as possible.</para>
<para>Porting the BWidget ButtonBox to SNIT and doing some test is what got me to this point. I was simply trying to create a widget and do a <emph style="bold">cget</emph>. The results were pretty disappointing considering the very basic <emph style="bold">cget</emph> command.</para>
<verbatim><vline encoding='base64'>IE5hdGl2ZSBUayB3aWRnZXQ6IDIgbWljcm9zZWNvbmRz</vline><vline encoding='base64'>IEJXaWRnZXQgd2lkZ2V0OiAgIDYwIG1pY3Jvc2Vjb25kcw==</vline><vline encoding='base64'>IFNOSVQgd2lkZ2V0OiAgICAgIDI2MCBtaWNyb3NlY29uZHM=</vline></verbatim>
<para>With <emph style="bold">::megawidget::cget</emph>, I get around 4 microseconds, which is pretty close to native Tk widgets.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
