scrolling window freezes



Ok, I have been looking at old archives for quite a while and found some
good examples on continuous scrolling of a text window.  However, I have ran
into difficulties.  I am trying to write a log viewing utility that simply
spits our log messages to the viewer whenever they are received.  The
problem is my window freezes after two iterations of the function on the
call to:

gtk_adjustment_set_value(adj, adj->upper - adj->lower - adj->page_size);



Basically, this is the code: - taken from some previous archives:

void go_to_bottom(void)
{
    GtkAdjustment *adj;

    adj = GTK_ADJUSTMENT(GTK_TEXT(textWindow)->vadj);

    gtk_adjustment_set_value(adj, adj->upper - adj->lower - adj->page_size);
}

int scroll_mode(void)
{
    int value, page_size, upper;

    value = GTK_ADJUSTMENT(GTK_TEXT(textWindow)->vadj)->value;
    page_size = GTK_ADJUSTMENT(GTK_TEXT(textWindow)->vadj)->page_size;
    upper = GTK_ADJUSTMENT(GTK_TEXT(textWindow)->vadj)->upper;

    if(value + page_size < upper)
        return 0;
    else
        return 1;

}

void updateText(const char *buff)
{
    GtkAdjustment *adj;
    int snap;

    gtk_text_freeze(GTK_TEXT(textWindow));

    snap = scroll_mode();

    gtk_text_insert(GTK_TEXT(textWindow), NULL, NULL, NULL,
                    buff, strlen(buff));

    gtk_text_thaw(GTK_TEXT(textWindow));

    if(snap)
        go_to_bottom();
}

Whenever new log messages come in, updateText is called with the message.
textWindow is a GtkWidget that is created by a call to CreateText:

static GtkWidget *CreateText (GtkWidget *window)
{
    GtkWidget *text;

    scr_win = gtk_scrolled_window_new(NULL, NULL);
    gtk_box_pack_start(GTK_BOX(window), scr_win, TRUE, TRUE, 0);
    text = gtk_text_new (NULL, NULL);

    gtk_text_set_editable(GTK_TEXT (text), FALSE);
    gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);

    gtk_container_add(GTK_CONTAINER(scr_win), text);

    return text;
}

main calls create text:

    GtkWidget *textWindow - actually declared globally before main.

    textWindow = CreateText (vbox_main);

    gtk_widget_show(textWindow);

This code is far from complete or clean, but I need to get around the whole
freezing problem before I can really do anything else.  Any suggestions or
help would be greatly appreciated!!!  Possibly I am just doing something
extremely stupid in my initialization, but I am just not seeing it.

THANKS!!!




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