Re: Auto Scrolling



Brian,

I have that code right here. I wonder if you can see anything in it. What I'm trying to do is append the line to the end of the buffer, then set the mark to the end and scroll there. It looks all good to me, but then I have only been programming gtk+ for about a month.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void open_ate_callback( struct Runtime * runtime ) {
  struct AtePane * atepane;
  GtkTextBuffer * buffer;
  GtkTextIter iter;

  atepane = ( struct AtePane * )runtime_arg_get( runtime, 0 );

  buffer = gtk_text_view_get_buffer
         ( GTK_TEXT_VIEW( atepane_buffer_get( atepane ) ) );
  gtk_text_buffer_get_end_iter( buffer, &iter );
  gtk_text_buffer_insert( buffer, &iter,
                          runtime->output_line->str,
                          strlen( runtime->output_line->str ) );
  gtk_text_buffer_get_end_iter( buffer, &iter );
  gtk_text_buffer_move_mark_by_name( buffer, "scroll", &iter );
  gtk_text_view_scroll_mark_onscreen
          ( GTK_TEXT_VIEW( atepane_buffer_get( atepane ) ),
            gtk_text_buffer_get_mark( buffer, "scroll" ) );
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Leo


Brian wrote:

On Sat, 2004-10-30 at 12:02 -0700, Leo Przybylski wrote:
Brian,

I noticed it does actually scroll, it just always goes back to the first line again. Even after appending hundreds, it goes to the first.

Here is the code I'm using to define my TextView and my Iterator.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct AtePane * ate_pane_new( struct ConfigConsole * console, gchar * name ) {
   struct AtePane * retval;
   GtkWidget * text;
   GtkWidget * root;
   GtkTextBuffer * buffer;
   GtkTextIter iter;

   retval = ( struct AtePane * )g_malloc( sizeof( struct AtePane * ) );
   atepane_location_set( retval, name );

   text = gtk_text_view_new();
   buffer = gtk_text_view_get_buffer( text );
   root = gtk_scrolled_window_new( NULL, NULL );

   gtk_widget_show( text );
   gtk_widget_show( root );

   atepane_root_set( retval, root );
   atepane_buffer_set( retval, text );
   gtk_text_buffer_get_end_iter( buffer, &iter );
   gtk_text_buffer_create_mark( buffer, "scroll", &iter, FALSE );

   gtk_text_view_set_editable( GTK_TEXT_VIEW( text ), FALSE );

   gtk_scrolled_window_set_policy
           ( GTK_SCROLLED_WINDOW( atepane_root_get( retval ) ),
             GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );

   gtk_scrolled_window_add_with_viewport
           ( GTK_SCROLLED_WINDOW( atepane_root_get( retval ) ),
             GTK_WIDGET( atepane_buffer_get( retval ) ) );
   return retval;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Leo

It looks OK to me, but I have not done any c coding, especially gtk.  If
it is scrolling like you want but immediately snaps back to the first
line then maybe you have a rogue scroll statement that you missed
deleting from your code???   I had a problem for a long time that the
window would snap back to a certain spot in the buffer every time it
auto scrolled.  It occurred at random it seemed.  It turned out I was
using the cursor position to scroll to, and if a mouse click happened on
the view window it would re-locate the cursor position there.  That is
why I create a mark at the end then scroll to it now.  Works properly
that way.

Post your code that causes it to append text & scroll.   There are
probably lots of experienced gtk gurus here to point out errors.






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