RE: prevent scrolling in GtkText



Here's How I implement "auto_scrolling" of a gtktext widget... (Note: This
algorithm uses a GLOBAL variable called "auto_scroll" feel free to improve upon
it as you see fit!)

/* Connect to gtktext widget's vertical adjustment - do this during widget
creation */
gtk_signal_connect(GTK_OBJECT(GTK_ADJUSTMENT(GTK_TEXT(text)->vadj)),
"value_changed",
                         GTK_SIGNAL_FUNC(set_scroll_mode), NULL);


...


/* Freezing gtktext widget for updating */
gtk_text_freeze(GTK_TEXT(text));


/* insert text and/or delete text and/or move cursor here */


/* Updating gtktext widget */
gtk_text_thaw(GTK_TEXT(text));


...


/* Setting text to display within text widget */
if ( auto_scroll == TRUE )
        snap_to_bottom(GTK_WIDGET(text), GTK_OBJECT(GTK_TEXT(text)->vadj));



/* Function to set global variable auto_scroll */
void set_scroll_mode(GtkWidget *calling_widget, gboolean state)
{
        if ( GTK_ADJUSTMENT(GTK_TEXT(text)->vadj)->value
                + GTK_ADJUSTMENT(GTK_TEXT(text)->vadj)->page_size
                < GTK_ADJUSTMENT(GTK_TEXT(text)->vadj)->upper )
                auto_scroll = FALSE;
        else
                auto_scroll = TRUE;
}
/* End of set_scroll_mode() */



/* Function to snap text widget to end */
void snap_to_bottom(GtkWidget *calling_widget, GtkObject *vertical_adjustment)
{
        gtk_adjustment_set_value(GTK_ADJUSTMENT(vertical_adjustment),
                                 GTK_ADJUSTMENT(vertical_adjustment)->upper 
                                 - GTK_ADJUSTMENT(vertical_adjustment)->lower
                                 -
GTK_ADJUSTMENT(vertical_adjustment)->page_size);
}
/* End of snap_to_bottom() */

Hope this helps.



                                -- Stupid Genius


----------
From:         Javier Ros Ganuza[SMTP:jros unavarra es]
Sent:         Tuesday, January 09, 2001 7:27 AM
To:   Dugas, Alan; gtk-app-devel-list gnome org
Subject:      Re: prevent scrolling in GtkText

"Dugas, Alan" wrote: 

      Are you inserting your text, and/or moving the cursor, and/or deleting
text 
      while frozen?  When I do so, I am able to "auto scroll" by checking if
the 
      scrollbar is at it's limit prior to inserting addtional text.  If it is,

      then after thawing the text widget I reset the vertical scrollbar
adjustment 
      attached to the gtktext to display the new text at the bottom.
Otherwise 
      the text is left alone displaying the same text as it did prior to
inserting 
      the addtional text.  Basically do everything while frozen.  Hope this
helps. 

                                      -- Stupid Genius

Hello :) 

Please , can you be more explicit, I'm inserting text in a freezed gtktex, and
thawing 
it doesn't scroll the window towards the insertesd position, so how do you 

'...reset the vertical scrollbar adjustment 
attached to the gtktext to display the new text ...' 

I suppouse some action over, once the text is unthaw 

GTK_ADJUSTMENT(GTK_TEXT(text)->vadj) 

but which action, 

Also, it is needed to proccess pending events related to insetion, before the
above 
described action is performed??? 
  

Thanks 
-- 
Javier Ros Ganuza.
Dpto. Ingeniería Mecánica.
Univ. Pública de Navarra. Campus de Arrosadia s/n. 31006 Pamplona.
Tel. 34 948169307 Fax. 34 948169099
 





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