#!/usr/local/bin/perl

require Exporter;

# hmmmm; are all these really needed >?<
use Tk;
require Tk::Web;
require Tk::LabEntry;
require URI::URL;
require Tk::Menubar;

@document::ISA = qw(Exporter);
@document::EXPORT = qw(document);

package document;

# DN1
############################# 
# A hacked version of tkweb #
#############################
# Supply the module with the url of the document to display.
# Supply the module with the mainWindow of the main-application.

sub document {

    # Divert printing (pretty useless output)
    open(SAVESTDOUT, ">&STDOUT") || die "Can't save STDOUT, $!\n";
    open(SAVESTDERR, ">&STDERR") || die "Can't save STDERR, $!\n";
    open(STDOUT, "> /dev/null") || die "Can't redirect STDOUT\n";
    open(STDERR, "> /dev/null") || die "Can't redirect STDERR\n";
    
    my ($urltxt,$mainWindow) = @_;
    my $showlink;

    my $mw = $mainWindow->Toplevel;
    my $but = $mw->Frame->pack(-fill => 'x');
# Where are we going ?
    
    my $w   = Tk::Web->new($mw,-showlink => sub { $showlink = shift }, -urlcommand => sub { $urltxt = shift} );
    my $e   = $mw->LabEntry(-label => 'Location:',-labelPack => [-side => 'left',-anchor => 'e'],-textvariable => \$urltxt )->pack(-fill => 'x');
#$e->bind('<Return>',[$w,'url',Tk::Ev(['get'])]);

    $w->url($urltxt);

    $w->{'-header'} = {'Accept' => join(',','text/html', 'text/plain', 'image/gif', 
					'image/x-xbitmap', 'image/x-pixmap', '*/*'),
		       'User-Agent' => 'tkweb/.xx'};

    $w->pack(-expand => 1, -fill => 'both');

    $but->Button(-text => 'Close', -command => [$mw,'destroy'])->pack(-side => 'left');
    
    $mw->AddScrollbars($w);
    my $show = $mw->Frame(-label => 'URL : ',-labelPack => [-side => 'left'])->pack(-fill => 'x');
    $show->Label(-textvariable => \$showlink, -anchor => 'w')->pack(-fill => 'y',-anchor => 'w', -expand => 1, -side => 'left');
    $show->Frame(-height => '3m', -width => '60m', -borderwidth => 3, -background => 'cyan', -relief => 'sunken')
	->pack(-side => 'right', -padx => '3m');
    my %args = (-scrollbars => 'w');
    $mw->ConfigDefault(\%args);
    $mw->configure(%args);
    $w->url($ARGV[0]) if (@ARGV);
    $w->focus;
    
    # Redirect output
    open (STDOUT, ">&SAVESTDOUT");
    open (STDERR, ">&SAVESTDERR");

}


1;






