GTK menu fixing...



Okay, here's my start at improving (sub)menus in GTK:

Starting small, I decided to make it such that the arrow that
indicates a submenu now points in the direction that the menu will
appear, instead of always pointing right.
(I think that this minor usability triumph is a GTk first!)

I'm doing this by calling
gtkmenuitem:gtk_menu_item_position_menu
which sets the submenu direction correctly, and THEN drawing the
arrow.

Notes:
* gtk_menu_item_position_menu is getting called a lot now -- would it
  be preferable to have a separate function for determining arrow
  direction which gets called on arrow redraw, and then have
  gtk_..._position_menu follow what's in menu_item->submenu_direction
  without checking for itself?
  I doubt that this is a problem though.
* I have two dummy variables sent to position_menu -- is there a
  better way of doing this/naming them?
* I have a switch statement for SubMenuDirection -> GtkArrowType; this
  is prolly not the best way of doing things. A macro would probably
  be better. Also, I can image people having/wanting vertical arrows
  for submenus (say, on menubars, to show if the menu will jump up or
  down) -- should we allow this? Say, by combining
  submenu_direction and submenu_placement into submenu_direction, and
  allowing this to be up/down/left/right.

See attached patch (which also has 2 spelng korekshuns).

Also, I noticed that there are /a lot/ of hard-coded values in
gtkmenuitem w/r/t submenu indicator arrow sizes.
It would be nice to make this size (& shape!) themable/resizeable;
should I poke around and extract the magic into some #define's? Can
anyone point me to how I can understand them/not break stuff?

-- 
  -nils
Public key: http://www.fas.harvard.edu/~nbarth/pub-key.txt
Index: gtkmenu.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.h,v
retrieving revision 1.17
diff -u -r1.17 gtkmenu.h
--- gtkmenu.h	2000/03/14 19:57:24	1.17
+++ gtkmenu.h	2000/05/19 04:30:00
@@ -118,7 +118,7 @@
 void	   gtk_menu_set_active		  (GtkMenu	       *menu,
 					   guint		index);
 
-/* set/get the acclerator group that holds global accelerators (should
+/* set/get the accelerator group that holds global accelerators (should
  * be added to the corresponding toplevel with gtk_window_add_accel_group().
  */
 void	       gtk_menu_set_accel_group	  (GtkMenu	       *menu,
Index: gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.38
diff -u -r1.38 gtkmenuitem.c
--- gtkmenuitem.c	2000/04/07 21:36:13	1.38
+++ gtkmenuitem.c	2000/05/19 04:30:00
@@ -35,6 +35,7 @@
 
 #define BORDER_SPACING  3
 #define SELECT_TIMEOUT  75
+#define GTK_DIRECTION_DEFAULT  GTK_DIRECTION_RIGHT;
 
 #define MENU_ITEM_CLASS(w)  GTK_MENU_ITEM_CLASS (GTK_OBJECT (w)->klass)
 
@@ -171,7 +172,7 @@
   menu_item->accelerator_width = 0;
   menu_item->show_toggle_indicator = FALSE;
   menu_item->show_submenu_indicator = FALSE;
-  menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
+  menu_item->submenu_direction = GTK_DIRECTION_DEFAULT;
   menu_item->submenu_placement = GTK_TOP_BOTTOM;
   menu_item->right_justify = FALSE;
 
@@ -423,8 +424,11 @@
   GtkMenuItem *menu_item;
   GtkStateType state_type;
   GtkShadowType shadow_type;
+  GtkArrowType arrow_direction;
   gint width, height;
   gint x, y;
+  gint dummy_a=0;
+  gint dummy_b=0;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_MENU_ITEM (widget));
@@ -459,11 +463,24 @@
 	  shadow_type = GTK_SHADOW_OUT;
 	  if (state_type == GTK_STATE_PRELIGHT)
 	    shadow_type = GTK_SHADOW_IN;
-
+	  
+	  gtk_menu_item_position_menu(GTK_MENU(menu_item->submenu),
+	                              &dummy_a, &dummy_b, menu_item);
+	  switch (menu_item->submenu_direction)
+	    {
+	      case GTK_DIRECTION_LEFT:
+		arrow_direction=GTK_ARROW_LEFT;
+		break;
+	      
+	      case GTK_DIRECTION_RIGHT:
+		arrow_direction=GTK_ARROW_RIGHT;
+		break;
+	    }
+	  
 	  gtk_paint_arrow (widget->style, widget->window,
 			   state_type, shadow_type, 
 			   area, widget, "menuitem", 
-			   GTK_ARROW_RIGHT, TRUE,
+			   arrow_direction, TRUE,
 			   x + width - 15, y + height / 2 - 5, 10, 10);
 	}
       else if (!GTK_BIN (menu_item)->child)
@@ -676,7 +693,7 @@
   gint screen_height;
   gint twidth, theight;
   gint tx, ty;
-
+  
   g_return_if_fail (menu != NULL);
   g_return_if_fail (x != NULL);
   g_return_if_fail (y != NULL);
@@ -708,10 +725,10 @@
       break;
 
     case GTK_LEFT_RIGHT:
-      menu_item->submenu_direction = GTK_DIRECTION_RIGHT;
       parent_menu_item = GTK_MENU (GTK_WIDGET (menu_item)->parent)->parent_menu_item;
       if (parent_menu_item)
 	menu_item->submenu_direction = GTK_MENU_ITEM (parent_menu_item)->submenu_direction;
+      else menu_item->submenu_direction = GTK_DIRECTION_DEFAULT;
 
       switch (menu_item->submenu_direction)
 	{
Index: gtktypeutils.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktypeutils.h,v
retrieving revision 1.47
diff -u -r1.47 gtktypeutils.h
--- gtktypeutils.h	2000/02/13 08:16:47	1.47
+++ gtktypeutils.h	2000/05/19 04:30:00
@@ -279,7 +279,7 @@
 #define GTK_VALUE_C_CALLBACK(a) ((a).d.c_callback_data)
 #define GTK_VALUE_FOREIGN(a)	((a).d.foreign_data)
 
-/* return location macros, these all narow down to
+/* return location macros, these all narrow down to
  * pointer types, because return values need to be
  * passed by reference
  */


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