Re: Caret position of a GtkTextView



The insert position is a special mark called "insert". Just move it and you will move the insert position.

Here's an example of how to move the insert position to the end of the buffer:

void insert_to_end_of_buffer()
{
    GtkTextIter iter_end;
    GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w_text_v
iew));
    gtk_text_buffer_get_end_iter(text_buffer,
                                 &iter_end);

    gtk_text_buffer_move_mark_by_name(text_buffer, "insert", &iter_end);
    gtk_text_buffer_move_mark_by_name(text_buffer, "selection_bound", &iter_end);
   
}

Note that you will also need to scroll the buffer manually if you want to see the caret. This may e.g. be done through the followin code:

void scroll_insert_into_viewer()
{
    GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w_text_view));
    GtkTextMark *mark = gtk_text_buffer_get_insert(text_buffer);

    // Get the complete line on screen
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(w_text_view),
                                 mark,
                                 0.3,
                                 FALSE,
                                 0,
                                 1);
}

Hope this helps.
Dov

2008/4/24 Felipe Monteiro de Carvalho <felipemonteiro carvalho gmail com>:

Hello,

I have a GtkTextView. How can I set and get the caret position in the
GtkTextView? And for a GtkEntry?

The caret is the blinking cursor that appears when writing text.

thanks,
--
Felipe Monteiro de Carvalho
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list




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