Re: GtkTextView problem



On Tue, 2002-06-11 at 02:59, Janus N. Tøndering wrote:
Unfortunately, that did not solve the problem. I am writing a small
demonstration app. Is it allowed to post the source on the list or
should I provide a link? It will be <10k I beleive.


Using snippet of my current code instead:

void textview_highlight_viewable(GtkTextView *view) {
        GtkTextIter s1, s2;
        GdkRectangle rect;
        GtkTextBuffer *buf;
        int start, end;
        
        buf =
        GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)));
        
        gtk_text_view_get_visible_rect(view, &rect);
        
        gtk_text_view_get_iter_at_location(view, &s1, rect.x, rect.y);
        gtk_text_view_get_iter_at_location(view, &s2, 
                        rect.x+rect.width, 
                        rect.y+rect.height);

        start = gtk_text_iter_get_offset(&s1);
        end = gtk_text_iter_get_offset(&s2);
        
        gtk_text_buffer_remove_all_tags(buf, &s1, &s2);
        syntax_highlight(buf, start, end);
}

[snip]
creating of textview:

        textbuffer = gtk_text_buffer_new(tagtable);
        textview = gtk_text_view_new_with_buffer(textbuffer);
        scroll_window = gtk_scrolled_window_new(NULL, NULL);
        
        gtk_container_add(GTK_CONTAINER(scroll_window), textview);
        adjust = gtk_scrolled_window_get_vadjustment(
                        GTK_SCROLLED_WINDOW(scroll_window));

        /* connect signals */
        g_signal_connect_after(G_OBJECT(textbuffer), "changed",
                        G_CALLBACK(textbuffer_changed), textview);
        g_signal_connect(G_OBJECT(adjust), "value-changed",
                        G_CALLBACK(textview_adjust_value_changed), textview);


[snip]

void textview_adjust_value_changed(GtkAdjustment *w, gpointer data) {
        GtkTextView *view = GTK_TEXT_VIEW(data);
        textview_highlight_viewable(view);
}


void textbuffer_changed(GtkTextBuffer *buf, gpointer data) {
        GtkTextView *view;
        view = GTK_TEXT_VIEW(data);
        textview_highlight_viewable(view);
}

syntax_highlight uses integer offsets (converting them to GtkTextIter's)
to iterate the buffer from "start" to "end". It does not change the
contents of the buffer. It only applies tags to different parts of the
buffer.

Hope someone can see what is going wrong here. If I comment out the
textview_highlight_viewable line in textview_adjust_value_changed the
error is gone.

Regards,
Janus N. Tøndering

-- 
Janus Nørgaard Tøndering        
email: j nus person dk or u011014 daimi au dk

"Would you buy a car with the hood welded shut?"
-Phil Hughes, Linux Journal Magazine





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