Re: [Usability] Re: EggToolbar



Marco Pesenti Gritti <mpeseng tin it> writes:

> Also, if it has been decided that priority text should not be
> supported, does the "Text beside icon" pref in control center make
> sense ? I guess most toolbars would go out of screen.

Note that the new toolbar will unmap items that there aren't room for
and put them on an overflow menu instead, so they won't go out of
screen.

However, I do think interpreting BOTH_HORIZ as priority text probably
makes sense for GtkToolbar. Of Calum's arguments in

   http://mail.gnome.org/archives/gtk-devel-list/2002-September/msg00144.html

only the second one doesn't also apply to labels beside icons, and as
Calum also said there, the HIG already recommends priority text as an
option.

[You can ignore the rest of this message if you don't care about how
 the feature is implemented].

So here is a patch that adds an "is_important" property to
GtkToolItem, which when set will make GtkToolButtons hide their labels
on horizontal toolbars in BOTH_HORIZ mode.

Comments on the patch would be appreciated as I'm not entirely happy
with it myself. If you do comment on the patch, please do so to
gtk-devel-list only; there's no reason to involve the usability list
and other innocent people in the internals of this feature.

Notes on the patch:

        - Just adding a "has_label_horizontally" property to
          GtkToolButton would be a conceptually cleaner solution, but
          that will cause homogeneous priority items to make all other
          items really wide. 

          Hacking around that in gtktoolbar.c would be possible, but
          then the "cleaner" argument doesn't really work.

        - With this patch, the spacing is slightly wrong around icons
          of priority text items. This is because the the other icons
          on the toolbar will all be allocated the same size and
          positioned in the middle of the button. This is not the case
          for priority text items, where the "homogeneous" property is
          ignored.

        - Adding "homogeneous_size_request" and
          "homogeneous_size_allocate", like the toggle_request in
          GtkMenuItem would be a possible fix, but it seems like much
          complication for relatively little gain. It is possible to
          add these methods compatibly later.

        - The patch uses a custom "notify" handler in GtkToolButton to
          get notified when the "is_important" property changes. Is
          this the right way to do it?


Soeren


Index: docs/reference/gtk/tmpl/gtktoolitem.sgml
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/tmpl/gtktoolitem.sgml,v
retrieving revision 1.3
diff -u -p -u -r1.3 gtktoolitem.sgml
--- docs/reference/gtk/tmpl/gtktoolitem.sgml	30 Jul 2003 20:14:54 -0000	1.3
+++ docs/reference/gtk/tmpl/gtktoolitem.sgml	31 Jul 2003 15:35:52 -0000
@@ -229,6 +229,11 @@ GtkToolItem
 
 @toolitem: the object which received the signal.
 
+<!-- ##### ARG GtkToolItem:is-important ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG GtkToolItem:visible-horizontal ##### -->
 <para>
 
Index: gtk/gtktoolbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.c,v
retrieving revision 1.99
diff -u -p -u -r1.99 gtktoolbar.c
--- gtk/gtktoolbar.c	30 Jul 2003 20:14:54 -0000	1.99
+++ gtk/gtktoolbar.c	31 Jul 2003 15:35:56 -0000
@@ -565,9 +565,22 @@ toolbar_item_visible (GtkToolbar  *toolb
 }
 
 static gboolean
-toolbar_item_is_homogeneous (GtkToolItem *item)
+toolbar_item_is_homogeneous (GtkToolbar  *toolbar,
+			     GtkToolItem *item)
 {
-  return (gtk_tool_item_get_homogeneous (item) && !GTK_IS_SEPARATOR_TOOL_ITEM (item));
+  gboolean result = FALSE;
+
+  if ((gtk_tool_item_get_homogeneous (item) && !GTK_IS_SEPARATOR_TOOL_ITEM (item)))
+    result = TRUE;
+
+  if (gtk_tool_item_get_is_important (item) &&
+      toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
+      toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
+    {
+      result = FALSE;
+    }
+
+  return result;
 }
 
 static void
@@ -799,7 +812,7 @@ gtk_toolbar_size_request (GtkWidget     
       max_child_width = MAX (max_child_width, requisition.width);
       max_child_height = MAX (max_child_height, requisition.height);
 
-      if (toolbar_item_is_homogeneous (item))
+      if (toolbar_item_is_homogeneous (toolbar, item))
 	{
 	  max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
 	  max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
@@ -821,7 +834,7 @@ gtk_toolbar_size_request (GtkWidget     
       if (!toolbar_item_visible (toolbar, item))
 	continue;
       
-      if (toolbar_item_is_homogeneous (item))
+      if (toolbar_item_is_homogeneous (toolbar, item))
 	{
 	  size = homogeneous_size;
 	}
@@ -924,14 +937,14 @@ get_item_size (GtkToolbar *toolbar,
   
   if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      if (toolbar_item_is_homogeneous (item))
+      if (toolbar_item_is_homogeneous (toolbar, item))
 	return toolbar->button_maxw;
       else
 	return requisition.width;
     }
   else
     {
-      if (toolbar_item_is_homogeneous (item))
+      if (toolbar_item_is_homogeneous (toolbar, item))
 	return toolbar->button_maxh;
       else
 	return requisition.height;
Index: gtk/gtktoolbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbutton.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 gtktoolbutton.c
--- gtk/gtktoolbutton.c	30 Jul 2003 18:35:07 -0000	1.10
+++ gtk/gtktoolbutton.c	31 Jul 2003 15:35:57 -0000
@@ -62,6 +62,8 @@ static void gtk_tool_button_get_property
 					   guint               prop_id,
 					   GValue             *value,
 					   GParamSpec         *pspec);
+static void gtk_tool_button_property_notify (GObject          *object,
+					     GParamSpec       *pspec);
 static void gtk_tool_button_finalize      (GObject            *object);
 
 static void gtk_tool_button_toolbar_reconfigured (GtkToolItem *tool_item);
@@ -128,6 +130,7 @@ gtk_tool_button_class_init (GtkToolButto
   
   object_class->set_property = gtk_tool_button_set_property;
   object_class->get_property = gtk_tool_button_get_property;
+  object_class->notify = gtk_tool_button_property_notify;
   object_class->finalize = gtk_tool_button_finalize;
 
   tool_item_class->create_menu_proxy = gtk_tool_button_create_menu_proxy;
@@ -278,8 +281,20 @@ gtk_tool_button_construct_contents (GtkT
   
   if (style != GTK_TOOLBAR_TEXT)
     need_icon = TRUE;
+
+  if (style != GTK_TOOLBAR_ICONS && style != GTK_TOOLBAR_BOTH_HORIZ)
+    need_label = TRUE;
+
+  if (style == GTK_TOOLBAR_BOTH_HORIZ &&
+      (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)) ||
+       gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL))
+    {
+      need_label = TRUE;
+    }
   
-  if (style != GTK_TOOLBAR_ICONS)
+  if (style != GTK_TOOLBAR_ICONS &&
+      ((style != GTK_TOOLBAR_BOTH_HORIZ ||
+	gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)))))
     need_label = TRUE;
   
   if (need_label)
@@ -361,8 +376,9 @@ gtk_tool_button_construct_contents (GtkT
 
     case GTK_TOOLBAR_BOTH_HORIZ:
       box = gtk_hbox_new (FALSE, 0);
-      gtk_box_pack_start (GTK_BOX (box), icon, FALSE, TRUE, 0);
-      gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (box), icon, label? FALSE : TRUE, TRUE, 0);
+      if (label)
+	gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
       gtk_container_add (GTK_CONTAINER (button->priv->button), box);
       break;
 
@@ -408,6 +424,14 @@ gtk_tool_button_set_property (GObject   
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
+}
+
+static void
+gtk_tool_button_property_notify (GObject          *object,
+				 GParamSpec       *pspec)
+{
+  if (strcmp (pspec->name, "is_important"))
+    gtk_tool_button_construct_contents (GTK_TOOL_ITEM (object));
 }
 
 static void
Index: gtk/gtktoolitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolitem.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 gtktoolitem.c
--- gtk/gtktoolitem.c	31 Jul 2003 13:09:29 -0000	1.9
+++ gtk/gtktoolitem.c	31 Jul 2003 15:35:57 -0000
@@ -42,6 +42,7 @@ enum {
   PROP_0,
   PROP_VISIBLE_HORIZONTAL,
   PROP_VISIBLE_VERTICAL,
+  PROP_IS_IMPORTANT
 };
 
 struct _GtkToolItemPrivate
@@ -55,6 +56,7 @@ struct _GtkToolItemPrivate
   guint expand : 1;
   guint pack_end : 1;
   guint use_drag_window : 1;
+  guint is_important : 1;
 
   GdkWindow *drag_window;
   
@@ -161,6 +163,13 @@ gtk_tool_item_class_init (GtkToolItemCla
 							 _("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
 							 TRUE,
 							 G_PARAM_READWRITE));
+  g_object_class_install_property (object_class,
+				   PROP_IS_IMPORTANT,
+				   g_param_spec_boolean ("is_important",
+							 _("Is important"),
+							 _("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
+							 FALSE,
+							 G_PARAM_READWRITE));
   toolitem_signals[CREATE_MENU_PROXY] =
     g_signal_new ("create_menu_proxy",
 		  G_OBJECT_CLASS_TYPE (klass),
@@ -240,6 +249,9 @@ gtk_tool_item_set_property (GObject     
     case PROP_VISIBLE_VERTICAL:
       gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
       break;
+    case PROP_IS_IMPORTANT:
+      gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -261,6 +273,9 @@ gtk_tool_item_get_property (GObject    *
     case PROP_VISIBLE_VERTICAL:
       g_value_set_boolean (value, toolitem->priv->visible_vertical);
       break;
+    case PROP_IS_IMPORTANT:
+      g_value_set_boolean (value, toolitem->priv->is_important);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -559,6 +574,31 @@ gtk_tool_item_get_homogeneous (GtkToolIt
   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
 
   return tool_item->priv->homogeneous;
+}
+
+gboolean
+gtk_tool_item_get_is_important (GtkToolItem *tool_item)
+{
+  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
+
+  return tool_item->priv->is_important;
+}
+
+void
+gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
+{
+  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
+
+  is_important = is_important != FALSE;
+
+  if (is_important != tool_item->priv->is_important)
+    {
+      tool_item->priv->is_important = is_important;
+
+      gtk_widget_queue_resize (GTK_WIDGET (tool_item));
+
+      g_object_notify (G_OBJECT (tool_item), "is_important");
+    }
 }
 
 static gboolean
Index: gtk/gtktoolitem.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolitem.h,v
retrieving revision 1.5
diff -u -p -u -r1.5 gtktoolitem.h
--- gtk/gtktoolitem.h	31 Jul 2003 15:26:40 -0000	1.5
+++ gtk/gtktoolitem.h	31 Jul 2003 15:35:58 -0000
@@ -71,7 +71,7 @@ GtkToolItem *gtk_tool_item_new      (voi
 
 void            gtk_tool_item_set_homogeneous          (GtkToolItem *tool_item,
 							gboolean     homogeneous);
-gboolean	gtk_tool_item_get_homogeneous          (GtkToolItem *tool_item);
+gboolean        gtk_tool_item_get_homogeneous          (GtkToolItem *tool_item);
 
 void            gtk_tool_item_set_expand               (GtkToolItem *tool_item,
 							gboolean     expand);
@@ -97,6 +97,10 @@ gboolean        gtk_tool_item_get_visibl
 void            gtk_tool_item_set_visible_vertical     (GtkToolItem *toolitem,
 							gboolean     visible_horizontal);
 gboolean        gtk_tool_item_get_visible_vertical     (GtkToolItem *toolitem);
+
+gboolean        gtk_tool_item_get_is_important         (GtkToolItem *tool_item);
+void            gtk_tool_item_set_is_important         (GtkToolItem *tool_item,
+							gboolean     is_important);
 
 GtkIconSize     gtk_tool_item_get_icon_size            (GtkToolItem *tool_item);
 GtkOrientation  gtk_tool_item_get_orientation          (GtkToolItem *tool_item);


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