Re: [gtk-list] CList: Menu on right-click



>    On a CList I can (de)select with the mouse, but what if I
> want to be able to popup a dropdown menu (just like in
> root windows) when I press the right eye (:-) of the mouse
> on a CList item? is that possible? (1.0.5? or 1.1?)

Here's a code snippet from what I'm working on.. HTH..

BTW, does anyone know how to handle the selection in a GtkCList? 
Unfortunately, the following code doesn't really know what's been
selected, it just pops up a menu..

  GtkWidget *list;
   .
   .
   .
  list = gtk_clist_new (5);
  gtk_signal_connect_object (GTK_OBJECT (list), "button_press_event",
    GTK_SIGNAL_FUNC (item_press), GTK_OBJECT (list));
   .
   .
   .


gint item_press (GtkWidget *widget, GdkEvent *event)
{
  GtkWidget *menu, *item1, *item2, *item3;
  GtkWidget *first;
  GtkCListRow *row_start, *row_end;
  GList *selection, *selection_end;
  printf ("item_press called\n");
  printf ("rows %d\n", GTK_CLIST (widget)->rows);
       
  menu = gtk_menu_new ();
  item1 = gtk_menu_item_new_with_label ("This");
  item2 = gtk_menu_item_new_with_label ("That");
  item3 = gtk_menu_item_new_with_label ("The other thing");
      
  gtk_menu_append (GTK_MENU (menu), item1);
  gtk_menu_append (GTK_MENU (menu), item2);
  gtk_menu_append (GTK_MENU (menu), item3);
      
  gtk_widget_show (GTK_WIDGET (item1));
  gtk_widget_show (GTK_WIDGET (item2));
  gtk_widget_show (GTK_WIDGET (item3));
     
  if (event->type == GDK_BUTTON_PRESS) {
    /* convert GdkEvent to GdkEventButton */
    GdkEventButton *bevent = (GdkEventButton *) event;
    printf ("GDK_BUTTON_PRESS\n");
    selection = GTK_CLIST (widget)->selection;
    selection_end = GTK_CLIST (widget)->selection_end;
    
    if (selection != NULL) {
      printf ("selection != NULL\n");
      if (selection->data  != NULL) {
        printf ("selection->data != NULL\n");
        row_start = (GtkCListRow *) selection->data;
        row_end = (GtkCListRow *) selection_end->data;
        /* Is that correct?  Am I totally wrong? */
        /* some stuff involving getting the names of the selected
files... */
        /* Anyone know how to do this? */
      }
    }

    if (bevent->button == 3) {
      /* stuff to do when the 3rd button (right button) is pressed */
      printf ("Button 3\n");
      gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                      bevent->button, bevent->time);
    }
    if (bevent->button == 2) {
      /* stuff to do when the 2nd button (middle button) is pressed */
      printf ("Button 2\n");
    }
    if (bevent->button == 1) {
      /* stuff to do when the 1st button (left button) is pressed */
      printf ("Button 1\n");
    }
    return TRUE;
  }
  return FALSE;
}


-- 
                    --== Mike Hicks ==--
http://umn.edu/~hick0088	mailto:hick0088@tc.umn.edu
                        ICQ:6883760
Linux User Since 1.2.13            Current Kernel: 2.1.129



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