Re: Text widget scroll



On Mon, Apr 16, 2001 at 05:58:20PM -0400, Marco Quezada wrote:
Hi,

I currently have a simple text widget to which I write an error log from
my program. Unfortunately when the number of lines reaches the  bottom
of the window the text does not scroll automatically so that the most
recent error log is not visible unless the user manually decides to
scroll down. Is there a way to set this behavior so the new error
messages can always be in view?

You have to reposition cursor. Here's what I do:

void
EventsWindow_Text::display (int pri_, const string& app_, const string& msg_)
{
        static const char self[]="EventsWindow_Text::display"; trace(self);

        gtk_text_freeze (GTK_TEXT (m_widget));

        int upd = GTK_TEXT (m_widget)->vadj->upper -
                GTK_TEXT (m_widget)->vadj->page_size ==
                GTK_TEXT (m_widget)->vadj->value;

        const GdkColor* text_color = Config::getInstance ()->get_color (pri_);
        const GdkColor* bg_color =
                Config::getInstance ()->get_color (Config::bg);

        gtk_text_insert (GTK_TEXT (m_widget), m_fixed_font,
                         (GdkColor*) text_color, (GdkColor*) bg_color,
                         msg_.c_str(), -1);

        gtk_text_insert (GTK_TEXT (m_widget), m_fixed_font,
                         NULL, NULL, "\n", -1);

        guint pos = gtk_text_get_length (GTK_TEXT (m_widget));
        gtk_text_set_point (GTK_TEXT (m_widget), pos);

        /*--- If exceeds history, remove extra ---*/

        unsigned int text_memory_current_usage = 0;
        unsigned int delete_length = 0;

        text_memory_current_usage = gtk_text_get_length (GTK_TEXT (m_widget));

        if (text_memory_current_usage > m_history_size) {
                delete_length = text_memory_current_usage - m_history_size;

                while (GTK_TEXT_INDEX (GTK_TEXT (m_widget), delete_length++)
                       != '\n') ;

                gtk_text_set_point (GTK_TEXT (m_widget), 0);
                Assert_exit (gtk_text_forward_delete (GTK_TEXT (m_widget),
                                                      delete_length) == TRUE);
                gtk_text_set_point (GTK_TEXT (m_widget),
                                    gtk_text_get_length (GTK_TEXT (m_widget)));
        }

        gtk_text_thaw (GTK_TEXT (m_widget));

        /*--- Scroll all way up to the bottom ---*/

        if (upd) {
                gtk_adjustment_set_value (
                        GTK_TEXT (m_widget)->vadj,
                        GTK_TEXT (m_widget)->vadj->upper -
                        GTK_TEXT (m_widget)->vadj->page_size);
        }
        fix_display ();

        /*--- Update events count label ---*/

        (*m_events_count_label)++;
}

inline void
EventsWindow_Text::fix_display () const
{
        /*
          Runs a single iteration of the main loop.
          This will check which event sources are ready to be processed,
          and will process the highest priority event sources which are ready.
          If argument is set to FALSE it will return immediately if no
          event source is ready to be processed.
        */
        g_main_iteration (FALSE);
}



Thanks.

--
Marco Quezada
Aerospaceo Engineero
NLX Corporation
22626 Sally Ride Dr.
Sterling, VA, 20164
mquezada nlxcorp com
703-234-2100 x1028
http://www.nlxcorp.com




_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

-- 
_________________________________________________________
Vladislav Grinchenko           e-mail: vgrinche integ com
Integral Systems, Inc.           http: www.integ.com
_________________________________________________________




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