[xiph-commits] r12125 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Nov 17 04:35:12 PST 2006


Author: xiphmont
Date: 2006-11-17 04:35:07 -0800 (Fri, 17 Nov 2006)
New Revision: 12125

Modified:
   trunk/sushivision/gtksucks.c
   trunk/sushivision/gtksucks.h
   trunk/sushivision/panel-2d.c
Log:
First of the right-click context menus is active and working



Modified: trunk/sushivision/gtksucks.c
===================================================================
--- trunk/sushivision/gtksucks.c	2006-11-17 12:32:51 UTC (rev 12124)
+++ trunk/sushivision/gtksucks.c	2006-11-17 12:35:07 UTC (rev 12125)
@@ -230,8 +230,26 @@
 /* Not really a fixup; generate menus that declare what the keyboard
    shortcuts are */
 
-GtkWidget *gtk_menu_new_twocol(char **menu_list, char **shortcuts){
+static gint popup_callback (GtkWidget *widget, GdkEvent *event){
 
+  GtkMenu *menu = GTK_MENU (widget);
+  GdkEventButton *event_button = (GdkEventButton *) event;
+
+  if (event_button->button == 3){
+    gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 
+		    event_button->button, event_button->time);
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+GtkWidget *gtk_menu_new_twocol(GtkWidget *bind, 
+			       char **menu_list, 
+			       char **shortcuts,
+			       void (*callbacks[])(void *),
+			       void *callback_data){
+
   char **ptr = menu_list;
   char **sptr = shortcuts;
   GtkWidget *ret = gtk_menu_new();
@@ -262,15 +280,40 @@
 	item = gtk_menu_item_new_with_label(*ptr);
       }
       gtk_menu_shell_append(GTK_MENU_SHELL(ret),item);
+      if(callbacks && *callbacks)
+	g_signal_connect_swapped (G_OBJECT (item), "activate",
+				  G_CALLBACK (*callbacks), callback_data);
     }
     gtk_widget_show_all(item);
-
+    
     ptr++;
     if(sptr)
       sptr++;
+    if(callbacks)
+      callbacks++;
   }
 
+  gtk_widget_add_events(bind, GDK_BUTTON_PRESS_MASK);
+  g_signal_connect_swapped (bind, "button-press-event",
+			    G_CALLBACK (popup_callback), ret);
+
   return ret;
 }
 
+GtkWidget *gtk_menu_get_item(GtkMenu *m, int pos){
+  int i=0;
+  GList *l=gtk_container_get_children (GTK_CONTAINER(m));    
+  
+  while(l){
+    if(i == pos){
+      GtkWidget *ret = (GtkWidget *)l->data;
+      g_list_free (l);
+      return ret;
+    }
 
+    i++;
+    l=l->next;
+  }
+
+  return NULL;
+}

Modified: trunk/sushivision/gtksucks.h
===================================================================
--- trunk/sushivision/gtksucks.h	2006-11-17 12:32:51 UTC (rev 12124)
+++ trunk/sushivision/gtksucks.h	2006-11-17 12:35:07 UTC (rev 12125)
@@ -26,6 +26,11 @@
 extern void gtk_widget_remove_events (GtkWidget *widget, gint events);
 extern void gtk_button3_fixup();
 extern void gtk_mutex_fixup();
-extern GtkWidget *gtk_menu_new_twocol(char **menu_list, char **shortcuts);
+extern GtkWidget *gtk_menu_new_twocol(GtkWidget *bind, 
+				      char **menu_list, 
+				      char **shortcuts,
+				      void (*callbacks[])(void *),
+				      void *callback_data);
+extern GtkWidget *gtk_menu_get_item(GtkMenu *m, int pos);
 
 #endif

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-11-17 12:32:51 UTC (rev 12124)
+++ trunk/sushivision/panel-2d.c	2006-11-17 12:35:07 UTC (rev 12125)
@@ -44,25 +44,8 @@
 static void panel2d_undo_push(sushiv_panel_t *p);
 static void panel2d_undo_suspend(sushiv_panel_t *p);
 static void panel2d_undo_resume(sushiv_panel_t *p);
+static void update_context_menu(sushiv_panel_t *p);
 
-static char *menulist[]={
-  "Undo",
-  "Redo",
-  "Find peaks",
-  "",
-  "Quit",
-  NULL
-};
-
-static char *shortlist[]={
-  "Backspace",
-  "Space",
-  "p",
-  NULL,
-  "q",
-  NULL
-};
-
 static void render_checks(int w, int y, u_int32_t *render){
   int x,j;
   /* default checked background */
@@ -1105,6 +1088,7 @@
   p2->undo_level++;
   p2->undo_stack[p2->undo_level]=0;
   p2->undo_stack[p2->undo_level+1]=0;
+  update_context_menu(p);
 
 }
 
@@ -1119,7 +1103,7 @@
   panel2d_undo_suspend(p);
   panel2d_undo_restore(p);
   panel2d_undo_resume(p);
-
+  update_context_menu(p);
 }
 
 static void panel2d_undo_down(sushiv_panel_t *p){
@@ -1134,6 +1118,7 @@
   panel2d_undo_suspend(p);
   panel2d_undo_restore(p);
   panel2d_undo_resume(p);
+  update_context_menu(p);
 }
 
 // called with lock
@@ -1233,24 +1218,60 @@
     return TRUE;
   }
 
-
   return FALSE;
 }
 
-static gint popup_callback (GtkWidget *widget, GdkEvent *event){
+static void update_context_menu(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  
+  // is undo active?
+  if(!p2->undo_stack ||
+     !p2->undo_level)
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),FALSE);
+  else
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),TRUE);
 
-  GtkMenu *menu = GTK_MENU (widget);
-  GdkEventButton *event_button = (GdkEventButton *) event;
+  // is redo active?
+  if(!p2->undo_stack ||
+     !p2->undo_stack[p2->undo_level] ||
+     !p2->undo_stack[p2->undo_level+1])
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),1),FALSE);
+  else
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),1),TRUE);
+}
 
-  if (event_button->button == 3){
-    gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 
-		    event_button->button, event_button->time);
-    return TRUE;
-  }
-
-  return FALSE;
+void wrap_exit(sushiv_panel_t *dummy){
+  _sushiv_clean_exit(SIGINT);
 }
 
+static char *menulist[]={
+  "Undo",
+  "Redo",
+  "Find peaks",
+  "",
+  "Quit",
+  NULL
+};
+
+static char *shortlist[]={
+  "Backspace",
+  "Space",
+  "p",
+  NULL,
+  "q",
+  NULL
+};
+
+static void (*calllist[])(sushiv_panel_t *)={
+  &panel2d_undo_down,
+  &panel2d_undo_up,
+  &panel2d_find_peak,
+  NULL,
+  &wrap_exit,
+  NULL,
+};
+
+
 void _sushiv_realize_panel2d(sushiv_panel_t *p){
   sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
   int i;
@@ -1398,10 +1419,9 @@
   }
   update_xy_availability(p);
 
-  p2->popmenu = gtk_menu_new_twocol(menulist,shortlist);
-  gtk_widget_add_events(p2->toplevel, GDK_BUTTON_PRESS_MASK);
-  g_signal_connect_swapped (G_OBJECT(p2->toplevel), "button-press-event",
-			    G_CALLBACK (popup_callback), p2->popmenu);
+  p2->popmenu = gtk_menu_new_twocol(p2->toplevel,menulist,shortlist,
+				    (void *)(void *)calllist,p);
+  update_context_menu(p);
 
   g_signal_connect (G_OBJECT (p2->toplevel), "key-press-event",
                     G_CALLBACK (panel2d_keypress), p);



More information about the commits mailing list