Text view vertical scroll problem



I am trying to adapt a text view tutorial to a scrolling window
tutorial.  I've learned that horizontal scrolling doesn't work yet, so
I've given up on that.  However, I have a strange problem with vertical
scrolling.  When moving the scrollbar down, the text scrolls up as
expected.  However, a blacked-out region slowly scrolls up with the
text, at something like half its rate.  By the time I scroll to the
bottom of the text, it is completely blacked out.

Just using a window and packing the text view in with a self-created
scrollbar does work, and that is what I plan to use for the time being.
However, I'd like to know what I'm doing wrong.  At this stage, I'm
still gripping with fundamentals, and I need to know where I'm not
paying enough attention.

The code is:

use Gtk;
use strict;

set_locale Gtk;
init Gtk;

my $false = 0;
my $true = 1;

my $window;
my $scrolled_window;
my $text;
my $button;

my $buffer;
my $line;

my $fixed_font;

# Create a new dialog window for the scrolled window
$window = new Gtk::Dialog();
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
$window->set_title( "Scrolled Window Example" );
$window->border_width( 0 );
$window->set_usize( 300, 300 );

# Create the Text widget
$text = new Gtk::Text(undef, undef);
$text->set_editable( $false );

# Load a fixed font
my $name = "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-koi8-r";
$fixed_font = Gtk::Gdk::Font->load( $name );

# Freeze the text widget, ready for multiple updates
$text->freeze();

# Load this file into the text window
open(FILE, "textwidget.pl" );

foreach $line ( <FILE> ) {
 $text->insert( $fixed_font, undef, undef, $line );
}

close( FILE );

# Allow the text to be shown
$text->thaw();
$text->show();

# Create a new scrolled window
$scrolled_window = new Gtk::ScrolledWindow( $text->hadj, $text->vadj );
$scrolled_window->border_width( 5 );
$scrolled_window->set_policy( "automatic", "automatic" );

$window->vbox->pack_start( $scrolled_window, $true, $true, 0 );
$scrolled_window->show();

# Add text view to the scrolled window
$scrolled_window->add_with_viewport( $text );
$text->show();

# Add a close button at the end of the dialog
$button = new Gtk::Button( "Close" );
$button->signal_connect_object( "clicked", \&Gtk::widget_destroy,
$window );

$button->can_default( $true );
$window->action_area->pack_start( $button, $true, $true, 0);

$button->grab_default();

$button->show();
$window->show();

main Gtk;
exit( 0 );





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]