Re: Still some question about row & column number. (Re: How to get the row & column number of cursor in GtkTextView?)



> To: gtk-list gnome org
> Subject: Still some question about row & column number. (Re: How to get the 
row & column number of cursor in GtkTextView?)
> User-Agent: KMail/1.4.1
> Cc: Padraig Obriain Sun COM
> MIME-Version: 1.0
> Content-Transfer-Encoding: 8bit
> X-MIME-Autoconverted: from quoted-printable to 8bit by 
dub-mail1.Ireland.Sun.COM id g7PGRVW09583
> 
> Hello, Padraig
> 
>   I tested your code piece. There's still two questions:
>   1. The resulted rect is a GdkRectangle, it's members x,y is pixel, so how 
> can I convert it to line number and column number?

I am not sure what you mean by column number as each character may have a 
different width. If you are asling how many characters are on the line before 
the current position, you could call gtk_text_iter_get_offset(), 
gtk_text_view_backward_display_line_start() and then call 
gtk_text_iter_get_offset() again.

The determine the line number you could call 
gtk_text_view_backward_display_line() until gtk_text_iter_is_start() is TRUE 
counting the number of times you call the function. I am not sure whether there 
is a better way.

>   2. I should put this code piece into a callback function, but which signal 
> should I connect the function with? I connected it with "move-cursor" event 
> of textview or "changed" event of a textbuffer, but it sames that the 
> returned number is always somewhat later than the key action.
> 

These signal are RUN_LAST signals so perhaps you want to call 
g_signal_connect_after().

Padraig

>   Thank you very much!
>   Yours,
>   mili
> 
> >I have not tried it but something along these lines ought to work.
> 
> >Padraig
> 
> >GtkTextIter *cursor_itr;
> >GtkTextBuffer *buffer;
> >GdkRectangle rect;
> 
> >buffer = gtk_text_view_get_buffer (text_view);
> >cursor_iter = gtk_text_buffer_get_iter_at_mark (buffer, 
> >gtk_text_buffer_get_insert (buffer));
> >gtk_text_view_get_iter_location (text_view, cursor_iter, &rect);
> 
> >> Hello, Everybody
> >>   Can anybody tell me that how I can get the row & column number of cursor 
> in
> >> GtkTextView? I didn't find any function call to implement this.
> 




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