Re: GtkTreeView: How do I detect right-click?



Ang Bodhi wrote:
Hi,

Guy Rouillier wrote:

Ang Bodhi wrote:

Hi,

I have a GtkTreeView widget that I would like to detect the mouse
button right-click, how can I do that? In Gtk 1.2, I used to be able
to connect to a button_press_event signal of a GtkTreeItem widget.



Did you search archives before posting?  I just answered this 5 days ago:


Sorry, I did a quick search with bad choice of keywords.

gtk_menu_new();
gtk_menu_popup();

In order to know to kick this off, you'll have to gtk_signal_connect on the "popup_menu" signal.


Thanks, I didn't realize there's a "popup_menu" signal. After trying it, I find
that the signal "popup_menu" does not work with the GtkTreeView widget.

I notice the tests/testiconview program use the popup_menu signal
on GtkIconView widget as well, but its popup menu works only by
connecting to the button_press_event signal of GtkIconView widget.
If I comment out the button_press_event signal connection, the program
would fail to popup the menu. It actually rely on the event's position to
determine which icon is chosen.

Ha! You're right and I'm wrong. I wrote this code over a year ago and obviously I forgot what I did. In order to detect a button press in a GtkTreeView, do this:

gtk_signal_connect (GTK_OBJECT(widget), "button_press_event", GTK_SIGNAL_FUNC(gtktreeviewbuttonpressed), (gpointer)UMAKEINT(GetWidID(), cmd));

Don't worry about the last param, that's just the user_data that's specific to our application.

Here is the code from our app that actually does the popup. This code comes from the gCvs member of the CvsGui family.

void UCvsPopupMenu::DisplayPopupMenu(void* info)
{
   if (menu !=  UMENU_NULL)
   {
        GdkEventButton *event = (GdkEventButton *) info;
        int button, event_time;
        
        if (event)
        {
           button = event->button;
           event_time = event->time;
           // printf("UCvsPopupMenu::DisplayPopupMenu called with event\n");
        }
        else
        {
           button = 0;
           event_time = gtk_get_current_event_time ();
           // printf("UCvsPopupMenu::DisplayPopupMenu called without event\n");
        }
                        
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                                button, event_time);
   }
}

--
Guy Rouillier



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