## Author: Achim Bohnet ## ## Copyright (c) 1997-1998 Achim Bohnet. All rights reserved. ## You can redistribute this document and/or modify it under the ## same terms as Perl itself. ## ## Update for Tk804.025, Steve Lidie, 2004/01/11. =head1 NAME Tk::mega - Perl/Tk support for writing widgets in pure Perl =for category Derived Widgets =head1 SYNOPSIS Define the widget's new class name: S< >BI; For composite widget classes: S< >B; # where B is I or I For derived widget classes: S< >B Install the new widget in Tk's namespace and establish class and instance constructors. S< >BI I<'MyNewWidget'>; S< >B { I } S< >B { I } =head1 DESCRIPTION The goal of the mega-widget support of Perl/Tk is to make it easy to write mega-widgets that obey the same protocol and interface that the Tk core widgets support. I demonstration program and go to the section B.> There are two kinds of mega-widgets: =over 4 =item * Composite Widgets A composite widget is composed with one or more existing widgets. The composite widget looks to the user like a simple single widget. A well known example is the file selection box. =item * Derived Widgets A derived widget adds/modifies/removes properties and methods from a single widget (this widget may itself be a mega-widget). =back =head1 MEGA-WIDGET SUPPORT =head2 Advertise Give a subwidget a symbolic name. Usage: S< >I<$self>-EB(B=EI<$widget>); Gives a subwidget I<$widget> of the mega-widget I<$self> the name B. One can retrieve the reference of an advertised subwidget with the L method. B Mega-Widget Writers: Please make sure to document the advertised widgets that are intended for I use. If there are none, document this fact, e.g.: =head1 ADVERTISED WIDGETS None. =head2 Callback Invoke a callback specified with an option. Usage: S< >I<$self>-EB(I<-option> ?,I ...?); B executes the L defined with I<$self>-EB(I<-option>, [B, ...]); If I are given they are passed to the callback. If I<-option> is not defined it does nothing. =head2 ClassInit Initialization of the mega-widget class. Usage: S< >B { I ... } B is called once for I L just before the first widget instance of a class is created in the widget tree of B. B is often used to define bindings and/or other resources shared by all instances, e.g., images. Examples: $mw->bind($class,"", sub { my $w = shift; $w->Insert("\t"); $w->focus; $w->break}); $mw->bind($class,"", ['Insert',"\n"]); $mw->bind($class,"",'Delete'); Notice that I<$class> is the class name (e.g. B) and I<$mw> is the mainwindow. Don't forget to call I<$class>-EB in B. =head2 Component Convenience function to create subwidgets. Usage: $cw->Component('Whatever', 'AdvertisedName', -delegate => ['method1', 'method2', ...], ... more widget options ..., ); B does several things for you with one call: =over 4 o Creates the widget o Advertises it with a given name (overridden by 'Name' option) o Delegates a set of methods to this widget (optional) =back Example: $cw->Component('Button', 'quitButton', -command => sub{$mw->'destroy'}); =head2 ConfigSpecs Defines options and their treatment Usage: $cw->ConfigSpecs( -option => [ where, dbname, dbclass, default], ..., DEFAULT => [where], ); Defines the options of a mega-widget and what actions are triggered by configure/cget of an option (see L and L for details). =head2 Construct Make the new mega-widget known to B. Usage: S< >B I B<'Name'>; B declares the new widget class so that your mega-widget works like normal Perl/Tk widgets. Examples: S< >B I<'Whatever'>; S< >B I<'MyItem'>; First example lets one use I<$widget>-EB to create new B widget. The second example restricts the usage of the B constructor method to widgets that are derived from B: I<$isamenu>-EI. =head2 CreateArgs Process options before any widget is created: S< >B { I } I<$package> is the package of the mega-widget (e.g., B, I<$parent> the parent of the widget to be created and $args the hash reference to the options specified in the widget constructor call. Don't forget to call I<$package>-EB(I<$parent>, I<$args>) in B. =head2 Delegates Redirect a method of the mega-widget to a subwidget of the composite widget Usage: $cw->Delegates( 'method1' => $subwidget1, 'method2' => 'advertived_name', ..., 'Construct' => $subwidget2, 'DEFAULT' => $subwidget3, ); The B<'Construct'> delegation has a special meaning. After 'Construct' is delegated all Widget constructors are redirected. E.g. after S< >I<$self>-EB(B<'Construct'>=EI<$subframe>); a I<$self>-EB