Re: gtk_editable_select_region and cursor position



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





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