The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Defining a new composite widget class

SYNOPSIS

  package Whatever;
  @ISA = qw(Tk::Frame);  # or Tk::Toplevel
         
  Tk::Widget->Construct('Whatever'); 
         
  sub Poplulate 
  {      
   my ($cw,$args) = @_;
         
   my $flag = delete $args->{-flag};
   if (defined $flag)
    {    
     # handle -flag => xxx which can only be done at create time
     # the delete above ensures that new() does not try and
     # do $cw->configure(-flag => xxx)
    }    
         
   $w = $cw->Component(...);
         
   $cw->Delegates(...);
   $cw->ConfigSpecs('-cursor' =>     [SELF,cursor,Cursor,undef],
                    '-something'  => [METHOD,dbName,dbClass,'default'],
                    '-text'       => [$label,dbName,dbClass,'default'],
                    '-heading'    => [Tk::Config->new($head,-text),heading,Heading,'My Heading']
                   ); 
  }      
         
  sub something
  {      
   my ($cw,$value) = @_;
   if (@_ > 1)
    {    
     # set it 
    }    
   return # current value
  }      
         
  1;     
  __END__

DESCRIPTION

A composite should normaly inherit new() from Tk::Widget. Tk::Widget::new() will call $cw-InitObject(\%args)> which a compoiste will normally inherit from Tk::Frame.

Tk::Frame::InitObject() will call Populate(), which should be defined to create the characteristic subwidgets of the class.

Populate may call Delegates to direct calls to methods to subwidgets. Typically most of not all methods are directed to a single subwidget - e.g. ScrolledListbox directs all methods to the core Listbox so that $composite->get(...) calls $listbox->get(...).

Populate should also call ConfigSpecs() once Populate returns Tk::Frame::ConfigDefault walks through the ConfigSpecs entries and populates %$args hash with defaults for options from .Xdefaults etc. When InitObject() returns to Tk::Widget::new(), a call to $cw->configure(%$args) and sets *all* the options.