Re: How to create a scrolled text window with GTK 2.x?



On Mon, 21 Jun 2004, Frank Naumann wrote:

> In gtkmm I use:
>
>  	info_display->insert(info_display->end(), msg);
>
>  	/* scroll to the end */
>  	info_display->move_mark(info_display->get_insert(), info_display->end());
>  	textView.scroll_to_mark(info_display->get_insert(), 0.0);
>
> With info_display as Glib::RefPtr<Gtk::TextBuffer> and
> textView as Gtk::TextView.
>
> Just replace with the gtk+ Functions. Hope it helps.

  I tried it like this, but it doesn't scroll to the end...

    GtkWidget* textWindow = gtk_text_view_new();
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textWindow), GTK_WRAP_WORD);
    gtk_text_view_set_editable(GTK_TEXT_VIEW(textWindow), FALSE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textWindow), FALSE);

    GtkWidget* scrolledTextWindow = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledTextWindow),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_container_add(GTK_CONTAINER(scrolledTextWindow), textWindow);


    GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textWindow));
    GtkTextIter iter;
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert(buffer, &iter, "a\nb\nc\nd\ne\nf\ng\nh\ni\nj", -1);

    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_move_mark(buffer, gtk_text_buffer_get_insert(buffer),
                              &iter);
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textWindow),
                                 gtk_text_buffer_get_insert(buffer),
                                 0, FALSE, 0, 0);

  (Btw, is that move_mark call really necessary? Doesn't adding text to
the buffer automatically move the insert-mark to the end of the added
text?)

							- Juha Nieminen




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