Re: Table menu patch for GtkMenu



Am Sam, 2003-07-12 um 17.22 schrieb Kristian Rietveld:
> Hello,
> 
> Before I can land the new combo box in gtk+ HEAD, I need to get my happy
> fun table menu patch for GtkMenu approved. So I attached this patch. A
> good chunk of the code is based on the GtkTable size
> allocation/requisition code. I guess it's a pretty sane patch, but maybe
> some won't like the proposed API.

Kristian, after getting your patch to apply after the introduction of
vertical-padding, I wrote added a table menu to testgtk (patch
appended).  In general, the table menu seems to work well, but there are
a few problems:

- while scrolling the table menu with the mouse works nicely, but moving
the focus with the keyboard doesn't scroll like it does for ordinary
menus.

- the tearoff menuitem doesn't seem to extend over more than one column.

Matthias

Index: testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.334
diff -u -p -r1.334 testgtk.c
--- testgtk.c	1 Jul 2003 20:02:31 -0000	1.334
+++ testgtk.c	15 Jul 2003 22:31:57 -0000
@@ -3465,6 +3465,44 @@ create_menu (GdkScreen *screen, gint dep
   return menu;
 }
 
+static GtkWidget*
+create_table_menu (GdkScreen *screen, gint cols, gint rows, gboolean tearoff)
+{
+  GtkWidget *menu;
+  GtkWidget *menuitem;
+  char buf[32];
+  int i, j;
+
+  menu = gtk_menu_new ();
+  gtk_menu_set_screen (GTK_MENU (menu), screen);
+
+  j = 0;
+  if (tearoff)
+    {
+      menuitem = gtk_tearoff_menu_item_new ();
+      gtk_menu_attach (GTK_MENU (menu), menuitem, j, j + 1, 0, cols);
+      gtk_widget_show (menuitem);
+      j++;
+    }
+  
+  sprintf (buf, "fullwidth");
+  menuitem = gtk_menu_item_new_with_label (buf);
+  gtk_menu_attach (GTK_MENU (menu), menuitem, 0, cols, j, j + 1);
+  gtk_widget_show (menuitem);
+  j++;
+  
+  for (; j < rows; j++)
+      for (i = 0; i < cols; i++)
+      {
+	sprintf (buf, "(%d %d)", i, j);
+	menuitem = gtk_menu_item_new_with_label (buf);
+	gtk_menu_attach (GTK_MENU (menu), menuitem, i, i + 1, j, j + 1);
+	gtk_widget_show (menuitem);
+      }
+  
+  return menu;
+}
+
 static void
 create_menus (GtkWidget *widget)
 {
@@ -3513,6 +3551,13 @@ create_menus (GtkWidget *widget)
       menu = create_menu (screen, 2, 50, TRUE);
       
       menuitem = gtk_menu_item_new_with_label ("test\nline2");
+      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
+      gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
+      gtk_widget_show (menuitem);
+
+      menu = create_table_menu (screen, 2, 50, TRUE);
+      
+      menuitem = gtk_menu_item_new_with_label ("table");
       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
       gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
       gtk_widget_show (menuitem);


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