Implementing mac-style context menus



Hi,

I'm trying to figure out how to implement mac-style context menus where
the menu is displayed when pressing and holding the left mouse button
for a short while.  It seems easy at first:

1. start a timeout in 'button-press-event' handler
2. when the timeout expires, popup the menu

(Of course the timeout needs to be cancelled if the mouse is moved or
the button is released before the timeout expires, but that's not a
problem.)

Now, in practice I'm getting in trouble very quickly.

1.  With the above naive implementation the context menu is popped up
and it grabs the focus before the button-release-event is emitted.  This
apparently makes the widget miss the event and is left in somewhat
inconsistent state.  The effects are visible after dismissing the popup
menu (releasing the grab.)

With GtkButton this means that it's drawn in depressed state the next
time the cursor hovers over the button.  With GtkEntry it starts a drag.


2. If instead I fake a button-release-event before showing the popup
menu GtkButton emits an extra 'clicked' signal, and the GtkEntry still
starts a drag.


Any hints, what am I doing wrong?


-- 
Tommi Komulainen <tommi komulainen nokia com>



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