Re: cursor ?



On Mon, Mar 24, 2003 at 12:33:11PM +0530, Viveka Nathan K wrote:
Hi..

We need to provide the support of various encodings in all applications
of linux. So, we need the cursor handling in the Text widgets of Gtk
also. If it is fixed width font, then we can easily calculate the cursor
position for the prev and next characters. But, if it is variable width
font, how can we maintain the positions ?
Can you help me ?
-- 


If you're using GtkTextView, you might be interested in
gtk_text_view_get_iter_location. It gives a rectangle that bounds the
character at a given iter. A GtkTextIter, or text buffer iterator, is a
transient object that you create from the TextBuffer. A TextBuffer has
a number of functions for creating an iter, that you can then pass to
the get_iter_location method of the view.

Keep in mind that you can't hold on to a text iterator. They can become
invalid due to buffer modifications.

A TextIter can be created from a mark, among other things. A Text mark
is not transient, or short lived, like an iterator. You can set a mark
somewhere in the buffer, and it will remain valid. As text is inserted
or removed, the text mark will move so that it remains in the same
logical location in the text. There are a couple of marks that always
exist. One of them is "insert", which is a text mark where the insertion
point is located.

So:
gtk_text_view_get_iter_location(my_tv,
        gtk_text_buffer_get_iter_at_mark(my_tb,
                gtk_text_buffer_get_mark(my_tb, "insert")));

would return a GdkRectangle located at the current cursor location.
(Note: there is a shortcut for gtk_text_buffer_get_mark called
gtk_text_buffer_get_insert, when you specifically want the insertion
cursor.)

You will find a very good overview in the Text Widget Overview section
of the GTK+ docs.

--jkl



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