Re: gtktext/popup menu problem




Timo Sirainen <a@sicom.fi> writes:

> I'm trying to create a popup menu which items depends of what word in
> text
> widget I clicked, but there's a problem:
 
> After creating popup menu when clicking text widget with right mouse
> button, selecting text doesn't work anymore (it shows as gray).
> That's because I use gtk_signal_connect_after() to grab
> button_press_event.  And I need to use that to make
> gtk_editable_get_position() return the right position (where I just
> clicked in text widget). I could handle all this in
> button_release_event, but creating menus in button_release_event
> works a bit weird.. I really can't think of any way to fix this.

If you are going to do a popup menu on a text widget, then
you have the responsibility to make sure that either the text widget
sees both the press and the release, or neither.

Since you are popping up the menu, it isn't going to see the
release - which is why you are leaving it in an inconsistent
state.

So you want to:

 1) gtk_signal_connect (not after) to the button_press_signal
 2a) if event->button != 3, return FALSE
 2b) if event->button == 3, call
       gtksignal_emit_stop_by_name (widget, "button_press_event");
     pop up the menu and return TRUE.

This is the only correct way to handle popups on a widget
that also handles events itself. Now, the question is how do 
you map from cursor position to character in the buffer.

This is one of the many things that _should_ be in the Text
widget API, and would be, if the code was half maintainable.

As a hack, you can probably do pretty much what you are
doing now - synthesize a (button 1) press/release pair
a the position of button 3 click to move the cursor, then
check where the cursor is. (You can send them with
gtk_widget_event())

The main thing to note here is that button presses that
a widget sees _must_ be paired.

Regards,
                                        Owen



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