Re: [gtk-list] menu popup




Hi,

> I'm looking for a way to popup a menu inside of 
> a text widget when the user click with the right mouse button.
> 
> i don't want the menu to show up on any other event.
> 

I use a popup menu attached to right mouse button click on GtkButton. 
To achieve this I attach a signal handler to that button and in that 
handler I use this piece of code:

/* create the popup menu - variable GtkWidget *popmenu */

/* this connects a handler needed to relase a pointer grab after 
destroying a popup menu */

gtk_signal_connect( GTK_OBJECT( popmenu ), "deactivate",
                GTK_SIGNAL_FUNC( wsPopOut ), NULL );            

/* this actually popups the menu - all the parameters are results 
of experiments... */

gtk_menu_popup( GTK_MENU( popmenu ), NULL, NULL, NULL, NULL, 
                0, time(0) );
                
/* this adds the pointer grab to popup menu */

gdk_pointer_grab( popmenu->window, TRUE,
  (GdkEventMask)(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELASE_MASK |
  GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK), NULL, NULL, 
  GDK_CURRENT_TIME );


> i would also like the menu to go away if the user clicks with
> any mouse button inside or outside the popup menu.
>

this does the trick, but you have to ungrab the pointer in callback 
function wsPopOut()... call gdk_pointer_ungrab( GDK_CURRENT_TIME ) 
there

> a howto on this would be great.
>

I have come to this piece of code by consulting my friend and gimp 
code... but now there is some example in tutorial, I think. 

> matt wimer
> 
                                                Hynek



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