Re: [gtkmm] Flickering TextView in ScrolledWindow



Hi Morten,

On Tue, 2002-07-09 at 16:23, Morten Brix Pedersen wrote:
> I'm porting my application to gtkmm2, which means that I'm replacing
> Gtk::Text with Gtk::TextView. However, the code used to scroll down
> automatically flickers the screen.
> 
> It didn't happen when a Gtk::Text was used instead. Simple case below.

> ...
>     // finally scroll down; this causes the widget to flicker
>     if (scroll)
>           _swin.get_vadjustment()->set_value(_swin.get_vadjustment()->get_upper());
> ...

Gtk::TextView only allows adjustment values from "lower" to
"upper - page_size". It flickers because the text is scrolled offscreen
first and then automatically corrected by Gtk::TextView.

You can do
1. _swin.get_vadjustment()->set_value(
             _swin.get_vadjustment()->get_upper()
             - _swin.get_vadjustment()->get_page_size())
2. Gtk::TextIter iter = buffer->end();
   _textview.scroll_to_iter(iter, 0.0);

But these solutions have problems if the inserted text contains multiple
lines. See
<http://mail.gnome.org/archives/gtk-devel-list/2001-April/msg00392.html>

The following should work in the right way:

void AppWindow::insertText()
{
    // see if the scrollbar is located in the bottom, then we need to scroll
    // after insert 
    bool scroll = false;
    if (_swin.get_vadjustment()->get_value() >= (_swin.get_vadjustment()->get_upper() - _swin.get_vadjustment()->get_page_size() - 1e-12))
          scroll = true;

    // insert the text at the end
    Glib::RefPtr<Gtk::TextBuffer> buffer = _textview.get_buffer();
    Gtk::TextIter iter = buffer->end();
    buffer->insert(iter, "Hello World - this is a test to see how inserted text flickers in the scrolledwindow!\n");

    // finally scroll down; this causes the widget to flicker
    if (scroll)
        _textview.scroll_to_mark (buffer->create_mark("end", buffer->end()), 0.0);
}



 Andreas




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