Re: pop up menu right clicking on a tree item



Hi, no, I've not used GtkTree :-( 

It should be pretty easy though, look at the source for gtk_tree_button_press(),
it does almost what you want. Something like this (untested):

   gtk_signal_connect( GTK_OBJECT( tree ), "event",
      GTK_SIGNAL_FUNC( my_tree_event ), stuff );

static gboolean
my_tree_event( GtkTree *tree, GdkEvent *ev, Mystuff *stuff )
{
   GtkWidget *item;

   if( ev->type == GDK_BUTTON_PRESS && ev->button.button == 3 &&
      (item = gtk_get_event_widget( ev )) ) {
      gtk_signal_emit_stop_by_name( GTK_OBJECT( tree ), "event" );

      ... popup menu

      return( TRUE );		
   }

   return( FALSE );
}

You need the signal_emit_stop to prevent the right-button-expands-nodes
behaviour.

Giovanni Masullo wrote:
> 
> no! i'm working with a tree.
> (i.e. i'm using gtk_create_tree instead of gtk_create_ctree).
> can you help me in thiz case?
> more, i'm working with gtk 1.2 (not 2.0)
> 
> John Cupitt wrote:
> 
> > Giovanni Masullo wrote:
> > > can anyone tell me how i can capture the mouse
> > > right click on a tree item?
> > > i would like to do that to putting up a popup menu
> > > related to that item.
> >
> > Hi Giovanni, for CTree (I guess you are using this?) attach to the "event"
> > signal, use gtk_clist_get_selection_info() to find the row and column, then use
> > gtk_ctree_get_node_nth() to find the node the user clicked on.
> >
> > static gboolean
> > my_tree_event( GtkCTree *ctree, GdkEvent *ev, Mystuff *stuff )
> > {
> >         int row, column;
> >
> >         if( ev->type == GDK_BUTTON_PRESS && ev->button.button == 3 &&
> >                 gtk_clist_get_selection_info( GTK_CLIST( ctree ),
> >                         ev->button.x, ev->button.y, &row, &column ) ) {
> >                 GtkCTreeNode *node = gtk_ctree_node_nth( ctree, row );
> >
> >                 ... popup menu for node
> >         }
> >
> >         return( FALSE );
> > }
> >
> >         gtk_signal_connect( GTK_OBJECT( ctree ), "event",
> >                 GTK_SIGNAL_FUNC( my_tree_event ), stuff );
> >
> > John
> > _______________________________________________
> > gtk-list mailing list
> > gtk-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtk-list

-- 
John Cupitt, john cupitt ng-london org uk, +44 (0)20 7747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN



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