Tk-MK
view release on metacpan or search on metacpan
lib/Tk/DTree.pm view on Meta::CPAN
######################################## SOH ###########################################
## Function : Additional Tk Class for List-type Trees with Data per Item, Sorting
##
## Copyright (c) 2002-2004 Michael Krause. All rights reserved.
## This program is free software; you can redistribute it and/or modify it
## under the same terms as Perl itself.
##
## History : V1.00 15-Dec-2002 Class adopted from DHList. MK
## V1.01 19-Jan-2004 Added numeric sorting for column 2. MK
##
######################################## EOH ###########################################
package Tk::DTree;
##############################################
### Use
##############################################
use Tk::Tree;
use Tk::ItemStyle;
use Tk qw(Ev);
use strict;
use Carp;
use vars qw ($VERSION);
$VERSION = '1.01';
use base qw (Tk::Derived Tk::Tree);
########################################################################
Construct Tk::Widget 'DTree';
#---------------------------------------------
# internal Setup function
#---------------------------------------------
sub ClassInit
{
my ($class, $window) = @_;
$class->SUPER::ClassInit($window);
# Note these keyboard-Keys are only usable, if the widget gets 'focus'
$window->bind ($class, '<Control-Key-bracketleft>', [\&viewtype, 'withdata']);
$window->bind ($class, '<Control-Key-bracketright>', [\&viewtype, 'normal']);
# Update the view after mapping
$window->bind ($class, '<Map>', \&map_cb);
}
#---------------------------------------------
# internal Setup function
#---------------------------------------------
sub CreateArgs
{
my ($class, $window, $args) = @_;
# Necessarily Patch Columns
my %args;
(%args) = ( -columns => '2') unless defined $args->{-columns};
($class->SUPER::CreateArgs($window, $args), %args);
}
#---------------------------------------------
# internal Setup function
#---------------------------------------------
sub Populate
{
my ($this, $args) = @_;
my $data_background = delete $args->{-databackground};
$data_background = $this->cget ('-background') unless defined $data_background;
my $style = delete $args->{-datastyle};
$style = $this->toplevel->ItemStyle ('text' ,
-anchor => 'e',
-background => $data_background,
) unless defined $style;
# Check whether we want numeric sorting
$this->{m_numeric_primary_sort} = delete $args->{-numeric_primary_sort} || 0;
$this->{m_numeric_secondary_sort} = delete $args->{-numeric_secondary_sort} || 0;
# Reroute any size_call_back
my $sizecmd = delete $args->{-sizecmd};
$sizecmd = sub { return 1 } unless defined $sizecmd;
$args->{-sizecmd} = [\&resize_cb, $this ];
#INvoke Superclass fill func
$this->SUPER::Populate($args);
( run in 0.719 second using v1.01-cache-2.11-cpan-804bf51f3ce )