Re: gtk_editable_select_region and cursor position
- From: Matt Keenan <Matt Keenan sun com>
- To: Gtk App Devel List <gtk-app-devel-list gnome org>
- Subject: Re: gtk_editable_select_region and cursor position
- Date: Fri, 25 Apr 2003 13:34:01 +0100
Owen,
Thanks for the pointer, I checked out the code and it really didn't have
anything I was looking for, either way I've come up with a way of
solving the issue, I was using gtk_editable_delete_text(), which requires a
two position parameters, and I knew these were wrong, however if I
use gtk_editable_delete_selection() then reget the cursor position I
now have the correct value to work with... cool works now..
Thanks for all the replies
Matt
Owen Taylor wrote:
On Thu, 2003-04-24 at 06:47, Matt Keenan wrote:
Hi,
Came across this problem in gtk and not sure if solveable...
Scenario :
Trying to implement command history within a gtkentry. As you are entering
text I want to be able to display a match from a list of previously entered
strings. I monitor the key_press_event on the GtkEntry widget, and get the
current text position, attempt to make a match and if there is a match
disply this match with the extra text highlighted, however when the user
enters the next key the current position returned from
gdk_editable_get_position()
is the end of the string as opposed to where the next char is typed.
e.g.
List of Previously entered strings :
string1
sring1
sing1
Order of entry
1. type "s"
Within the key_press_event callback
gtk_editable_get_position -> 0
I match the string "sing1"
gtk_entry_set_text("sing1");
gtk_editable_set_position(current_position+1);
gtk_editable_select_region(current_position+1, -1);
This displays the text "s" unhighlighted and the rest "ing1" highlighted.
2, type "i"
The "i" appears directly after the previously typed "s" which is as
i expect however
gtk_editable_get_position -> 5
surely it should return 1....
Can anyone answer me as to why this is happening, or am I doing something
wrong..
Hard to say what's going on without seeing a small standalone test case;
I would suggest that you shouldn't be doing stuff off of key_press_event
(that won't work when you have internationalization and input methods),
but rather off of ::insert_text.
If you look at gtkfilechooser/gtkfilechooser.c, you'll find something
similar. (Though it's certainly a little complex for an example...)
What I ended up doing there was to install an idle handler in
insert_text, where the idle handler checked for completions.
Regards,
Owen
--
__.--'\ \.__./ /'--.__
_.-' '.__.' '.__.' '-._
.' Matt Keenan (mattman) '.
/ Sun Microsystems Ireland \
| |
| E-Mail : Matt Keenan Sun Com |
| mattman iol ie |
| |
| Irish Fantasy League Of American Football |
| http://www.iflaf.com |
| |
| Happy Hookers Golf Society |
| http://www.iol.ie/~mattman/golf/hhgs.htm |
| |
| Phone : +353 1 8199251, Sun Ext : 19251 |
\ .---. .---. /
'._ .' '.''. .''.' '. _.'
'-./ \ / \.-'
''
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]