diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2005-08-31 15:54:05 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2005-08-31 15:54:05 +0000 |
commit | fd771f8a0ff1cbdcfdb0640206cf927251c899be (patch) | |
tree | 382041b791e419e7fe97bf9619ec25e92673e64f /perl-install/mygtk2.pm | |
parent | 22f21bc9e0d0172b383fb70ccdb4457652c0cffd (diff) | |
download | drakx-fd771f8a0ff1cbdcfdb0640206cf927251c899be.tar drakx-fd771f8a0ff1cbdcfdb0640206cf927251c899be.tar.gz drakx-fd771f8a0ff1cbdcfdb0640206cf927251c899be.tar.bz2 drakx-fd771f8a0ff1cbdcfdb0640206cf927251c899be.tar.xz drakx-fd771f8a0ff1cbdcfdb0640206cf927251c899be.zip |
allow ScrolledWindow around TextView to be automatically scrolled down on new text insert
Diffstat (limited to 'perl-install/mygtk2.pm')
-rw-r--r-- | perl-install/mygtk2.pm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/perl-install/mygtk2.pm b/perl-install/mygtk2.pm index d8120240d..74a8921c7 100644 --- a/perl-install/mygtk2.pm +++ b/perl-install/mygtk2.pm @@ -414,6 +414,8 @@ sub _gtk__ScrolledWindow { $w->set_policy(delete $opts->{h_policy} || 'automatic', delete $opts->{v_policy} || 'automatic'); } + my $faked_w = $w; + if (my $child = delete $opts->{child}) { if (member(ref($child), qw(Gtk2::Layout Gtk2::Text Gtk2::TextView Gtk2::TreeView))) { $w->add($child); @@ -426,11 +428,15 @@ sub _gtk__ScrolledWindow { $w->child->set_shadow_type(delete $opts->{shadow_type}) if exists $opts->{shadow_type}; + if (ref($child) eq 'Gtk2::TextView' && delete $opts->{to_bottom}) { + $child->{to_bottom} = _allow_scroll_TextView_to_bottom($w, $child); + } + if ($action eq 'gtknew' && ref($child) =~ /Gtk2::TextView|Gtk2::TreeView/) { - $w = gtknew('Frame', shadow_type => 'in', child => $w); + $faked_w = gtknew('Frame', shadow_type => 'in', child => $w); } } - $w; + $faked_w; } sub _gtk__Frame { @@ -881,6 +887,8 @@ sub _text_insert { $buffer->set_text($t); } } + $textview->{to_bottom}->() if $textview->{to_bottom}; + #- the following line is needed to move the cursor to the beginning, so that if the #- textview has a scrollbar, it will not scroll to the bottom when focusing (#3633) $buffer->place_cursor($buffer->get_start_iter); @@ -890,6 +898,20 @@ sub _text_insert { $textview; } +sub _allow_scroll_TextView_to_bottom { + my ($scrolledWindow, $textView) = @_; + + $textView->get_buffer->create_mark('end', $textView->get_buffer->get_end_iter, 0); + sub { + my $new_scroll = $scrolledWindow->get_vadjustment->get_value; + $textView->{no_scroll_down} ||= $new_scroll < ($textView->{prev_scroll} || 0); + $textView->{prev_scroll} = $new_scroll; + if (!$textView->{no_scroll_down}) { + $textView->scroll_to_mark($textView->get_buffer->get_mark('end'), 0, 1, 0, 1); + } + }; +} + sub set_main_window_size { my ($window) = @_; my ($width, $height) = $::isInstall ? ($::real_windowwidth, $::real_windowheight) : $::isWizard ? (540, 360) : (600, 400); |