Submenu patch



I've cleaned up my minor submenu patch, and just wished to post it in
improved form for review.

This patch does:

* Makes submenu indicator arrows point in the direction that the submenu
  will pop up (left or right), rather than always right.

* Makes the submenu offset (the vertical offset of each sucessive submenu)
  a #define'd quantity, instead of magic in the middle.
  Someone should make this be user-customizable via .gtkrc etc.

* Removes hard-coding of submenus cascade right, and #define's it.
  This should also be user settable (i18n issues? tfel-ot-thgir languages
  probably should default to cascade left).

* Minor code clean up (moved an assignment that sometimes gets immediately
  overriden by an 'if ...' into the 'else').

-- 
  -nils
Public key: http://www.fas.harvard.edu/~nbarth/pub-key.txt
Index: gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.39
diff -u -r1.39 gtkmenuitem.c
--- gtkmenuitem.c	2000/05/12 15:25:45	1.39
+++ gtkmenuitem.c	2000/05/24 18:15:18
@@ -35,6 +35,14 @@
 
 #define BORDER_SPACING  3
 #define SELECT_TIMEOUT  75
+/* SUBMENU_OFFSET specifies by what percent of a menuitem height
+ * a submenu is vertically offset. Should vary between 0 and 1.0.
+ * (I guess -1.0 to 0 range is okay).
+ * GTK currently defaults to 0.25 -- other windowing systems default
+ * to 0.
+ */
+#define GTK_SUBMENU_OFFSET 0.25
+#define GTK_DIRECTION_DEFAULT  GTK_DIRECTION_RIGHT;
 
 #define MENU_ITEM_CLASS(w)  GTK_MENU_ITEM_CLASS (GTK_OBJECT (w)->klass)
 
@@ -171,8 +179,8 @@
   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_placement = GTK_TOP_BOTTOM;
+  menu_item->submenu_direction = GTK_DIRECTION_DEFAULT;
+  menu_item->submenu_placement = GTK_LEFT_RIGHT;
   menu_item->right_justify = FALSE;
 
   menu_item->timer = 0;
@@ -423,6 +431,7 @@
   GtkMenuItem *menu_item;
   GtkStateType state_type;
   GtkShadowType shadow_type;
+  GtkArrowType arrow_direction;
   gint width, height;
   gint x, y;
 
@@ -456,14 +465,38 @@
 
       if (menu_item->submenu && menu_item->show_submenu_indicator)
 	{
+	  gint dummy_a=0;
+	  gint dummy_b=0;
+	  GtkRequisition requisition;
+
 	  shadow_type = GTK_SHADOW_OUT;
 	  if (state_type == GTK_STATE_PRELIGHT)
 	    shadow_type = GTK_SHADOW_IN;
 
+	  /* Similarly to in gtk_menu_position(), we need to figure out
+	   * where the menu will pop up to figure out the arrow direction
+	   */
+	  gtk_widget_size_request (GTK_WIDGET (menu_item->submenu),
+	                          &requisition);
+	  /* The temporary requisition var is so that gtk_widget_size_request
+	   * doesn't whine; otherwise we'd just have
+	   * &(GTK_WIDGET (menu_item->submenu)->requisition) above.
+	   */
+	  GTK_WIDGET (menu_item->submenu)->requisition.width  = requisition.width;
+	  GTK_WIDGET (menu_item->submenu)->requisition.height = requisition.height;
+	  gtk_menu_item_position_menu (GTK_MENU (menu_item->submenu),
+	                               &dummy_a, &dummy_b, menu_item);
+	  /* FIXME: This should be a general GTK_DIRECTION->GTK_ARROW
+	   * macro.
+	   */
+	  arrow_direction = (menu_item->submenu_direction ==
+	      GTK_DIRECTION_RIGHT)
+	    ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT;
+	  
 	  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)
@@ -708,10 +741,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)
 	{
@@ -736,7 +769,8 @@
 	  break;
 	}
 
-      ty += GTK_WIDGET (menu_item)->allocation.height / 4;
+      if (GTK_SUBMENU_OFFSET)
+	ty += (GTK_WIDGET (menu_item)->allocation.height * GTK_SUBMENU_OFFSET);
 
       break;
     }


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