Re: [gtk-list] Re: setting insertion point in GtkText



Thus spoke Thomas Mailund Jensen
>   gtk_text_set_point (GTK_TEXT (text),
> 		      gtk_editable_get_position (GTK_EDITABLE  (text)));

Yep, thats the solution, along with the correct type of signal connection.
This following bit of code will allow me to track when the user clicks 
inside the text widget so I can set the insertion point to follow 
the text cursor.

Thanks for the help Thomas!

> ===File ~/tmp/bar.c=========================================
> #include <gtk/gtk.h>
> 
> static void
> insert_bar (GtkWidget *text)
> {
>   /* jump to cursor mark */
>   gtk_text_set_point (GTK_TEXT (text),
> 		      gtk_editable_get_position (GTK_EDITABLE  (text)));
> 
>   gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,
> 		     "bar", strlen ("bar"));
> }
> 
> int
> main (int argc, char *argv[])
> {
>   GtkWidget *window, *text;
> 
>   gtk_init (&argc, &argv);
> 
>   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>   text = gtk_text_new (NULL, NULL);
>   gtk_text_set_editable (GTK_TEXT (text), TRUE);
>   gtk_container_add (GTK_CONTAINER (window), text);
> 
>   gtk_signal_connect_after (GTK_OBJECT (text), "button_press_event",
> 			    GTK_SIGNAL_FUNC (insert_bar),
> 			    NULL);
> 
>   gtk_widget_show_all (window);
>   gtk_main ();
> 
>   return 0;
> }
> ============================================================

-- 
Michael J. Hammel           |
The Graphics Muse           | Tell me what you need, and I'll tell you how to
mjhammel@graphics-muse.org  | get along without it. -- Dilbert
http://www.graphics-muse.org



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