Hi,
The problem is with the way callbacks work in TK. They like to receive an anonymous array with the first element being the sub to be called and subsequent elements are passed to that sub. Here is your code, modified to work.
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::ROText;
my $mw; # Main Window
my $fview; # Text box (Read only)
# Create Main Window and textbox
$mw = new MainWindow;
$fview = $mw->Scrolled( 'ROText',
-scrollbars => "oe",
-cursor => "hand2"
);
$fview->pack;
# Print "Root" Folder
$fview->insert('end', "\n");
$fview->insert('end', "Root" , "Root");
$fview->insert("Root.last", "\n", "Root_newline");
# Hover over
$fview->tagBind("Root", "<Enter>" =>
[ \&hover, "Root", 1 ]);
# Hover out
$fview->tagBind("Root", "<Leave>" =>
[ \&hover, "Root", 0 ]);
# Double click
$fview->tagBind("Root", "<Double-Button-1>" =>
[ \&dclick, "Root", 0 ]);
# Wait For Christmas!
MainLoop;
# make folder hot!
sub hover
{
shift;
my $tag = shift;
my $do = shift;
if ($do == 1) {
$fview->tagConfigure($tag,
-foreground => "red"
);
}
elsif ($do == 0) {
$fview->tagConfigure($tag,
-foreground => "black"
);
}
}
# expand folder
sub dclick
{
shift;
my $tag = shift;
my @folders;
my $fullpath;
@folders = ( "Linux", "Mail", "Perl" );
foreach my $folder (@folders) {
$fullpath = "/$folder";
# Hover over
$fview->tagBind($fullpath, "<Enter>" =>
[ \&hover, $fullpath, 1 ]);
# Hover out
$fview->tagBind($fullpath, "<Leave>" =>
[ \&hover, $fullpath, 0 ]);
# Diplay the folder link
$fview->insert( 'Root_newline.last',
$folder, $fullpath
);
$fview->insert( $fullpath.".last",
"\n",
$fullpath."_newline"
);
}
}
I got ride of the sub prototypes ('cause I don't like them. :) ) and change the callbacks to the way that TK expects them. Note that I have to shift the first element off because it passes the ref of the widget performing the callback.
I conceptually understand why this behaves this way, but words fail me when I try to explain it. Hopefully one of our fellow monks will step up to the plate here. To experiment with callbacks I suggest you do a callback to a sub in this manner (Tk::Canvas style shown here) and have that sub just do this:
$w->bind("tag", '<1>', [ \&bind, "one", "two" ]);
sub stuff
{
my @a = @_;
my $i = 0;
print "Callback received this stuff:\n";
for (@a) { print "\targ($i) : $_\n"; $i++ }
}
Hope this helps - sorry if it's not terribly clear,
{NULE}
--
http://www.nule.org