icon sizing API for 2.2



Hi folks:

I understand that we're trying to finalize 2.2 API pretty soon.  I
myself will be away for a few days, but in the meantime I want to
suggest/request that we agree on at least the API for icon size theming.

There is a bugzilla bug for this:
http://bugzilla.gnome.org/show_bug.cgi?id=70648

Havoc suggested an API for this in his bugzilla comments, in February,
and from IRC discussions and in-person conversations with Owen at GUADEC
it seems that this API was his choice as well.

I have put a patch in bugzilla to implement this API, for instance
re-specifying the icon sizes in an RC file takes a line that looks like
this:

gtk-icon-sizes = "dnd 64,64:menu 32,32:large-toolbar 48,48:small-toolbar
48,48:button 32,32:dialog 64,64"

A line like this is required in order to make use of the new
high-contrast and large-size icon sets which jimmac and tigert have
recently created. 

Even if the specific patch is not acceptable for check-in to gtk+ HEAD
I'd like to make sure we agree on the API as soon as possible, since we
need this for accessibility.  My patch is deficient in one known way; it
doesn't dynamically resize the icons in response to changes in the
setting, partly because I was not 100% clear on the right way to purge
and regenerate the gtkiconset cache; help there would be appreciated. 
In other respects the patch has proved itself to behave well, I've been
using in my builds for months now.

There is one open issue for the future: because of the need to preserve
existing behavior for non-wildcarded icon pixmaps, the scaling in this
patch only applies to icons that are wildcarded.  This presents a
limitation but a good solution may require new gtkiconset API as well. 
The above piece of RC-file API will tide us over until we can allow
scaling of non-wildcarded icons in a way that doesn't break existing
usage (though it's not clear to me what applications rely on this at the
moment, since the pixmap dimensions of the gtk+ stock icons now all
match the default sizes, in the past some gtk+ stock icons were 24x24
pixmaps with empty borders, they are now all 20x20 I believe).   Even if
additional API is desirable in the future, we will need this part of the
solution (RC-file syntax and behavior for wildcarded icons), so I don't
think that's a reason to defer including and implementing the above API.

thanks

Bill


Index: gtk/gtkiconfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkiconfactory.c,v
retrieving revision 1.39
diff -u -r1.39 gtkiconfactory.c
--- gtk/gtkiconfactory.c	18 Apr 2002 22:04:43 -0000	1.39
+++ gtk/gtkiconfactory.c	30 May 2002 06:48:20 -0000
@@ -28,6 +28,7 @@
 #include "stock-icons/gtkstockpixbufs.h"
 #include "gtkstock.h"
 #include "gtkintl.h"
+#include "gtksettings.h"
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
@@ -825,14 +826,85 @@
 static gint      icon_sizes_allocated = 0;
 static gint      icon_sizes_used = 0;
 
+/**
+ * This method reads the gtk-icon-sizes property and
+ *    parses it to determine the default sizes to use for
+ *    gtk icons, both predefined named sizes, and new
+ *    named sizes.  If an icon size name does not appear
+ *    in the style property, the dimensions of that named
+ *    icon size are unchanged.
+ **/
+static void
+restyle_icon_dimensions_from_property (IconSize *sizes)
+{
+#define MAX_ICON_SIZES 24
+  gint i;
+  gint n = icon_sizes_used;
+  gchar *icon_size_prop = NULL;
+  gchar **size_strings;
+  GtkSettings *settings = gtk_settings_get_default ();
+  g_object_get (G_OBJECT (settings), "gtk-icon-sizes", &icon_size_prop, NULL);
+  if (icon_size_prop != NULL)
+    {
+      size_strings = g_strsplit (icon_size_prop, ":", MAX_ICON_SIZES);
+#undef MAX_ICON_SIZES  
+  /* parse by name */
+      i=0;
+      while (size_strings[i])
+        {
+	  gint j;
+	  gint k;
+	  gchar *name = NULL;
+	  gchar **substrings;
+	  substrings = g_strsplit (size_strings[i], " ", 2);
+	  j = 0;
+	  do
+	    {
+	      ++j;
+	      if (j == n) break;
+              if (!strncmp (sizes[j].name, "gtk-", 4))
+	        name = sizes[j].name+4;
+	      else
+	        name = sizes[j].name;
+	    } while (!name || strcmp (substrings[0], name)); 
+          if (j < n)
+            {
+	      gchar **istrings = g_strsplit (substrings[1], ",", 2);	    
+	      sizes[j].width = atoi (istrings [0]);	
+	      sizes[j].height = atoi (istrings [1]);
+	      g_message ("icon %s size set to %d\n", sizes[j].name,
+			 sizes[j].width);
+	      if (istrings[0]) g_free (istrings[0]);
+	      if (istrings[1]) g_free (istrings[1]);
+	      if (istrings) g_free (istrings);
+            }
+          k = 0;
+	  while (substrings[k])
+	    {
+              g_free (substrings[k]);
+	      ++k;
+	    }
+	  g_free (substrings);
+	  ++i;
+	}
+      i = 0;
+      while (size_strings[i])
+        {
+          g_free (size_strings[i]);
+	  ++i;
+	}
+      g_free (size_strings);
+      _gtk_icon_set_invalidate_caches ();
+    }
+}
+
 static void
 init_icon_sizes (void)
 {
   if (icon_sizes == NULL)
     {
-#define NUM_BUILTIN_SIZES 7
       gint i;
-
+#define NUM_BUILTIN_SIZES 7
       icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
       
       icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
@@ -890,8 +962,8 @@
           
           ++i;
         }
-      
 #undef NUM_BUILTIN_SIZES
+      restyle_icon_dimensions_from_property (icon_sizes);
     }
 }
 
Index: gtk/gtkrc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrc.c,v
retrieving revision 1.123
diff -u -r1.123 gtkrc.c
--- gtk/gtkrc.c	14 May 2002 20:55:22 -0000	1.123
+++ gtk/gtkrc.c	30 May 2002 06:48:23 -0000
@@ -1688,7 +1688,6 @@
 	  const gchar *path;
           gchar *path_reversed;
 	  guint path_length;
-
 	  path = g_type_name (type);
 	  path_length = strlen (path);
 	  path_reversed = g_strdup (path);
Index: gtk/gtksettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.c,v
retrieving revision 1.27
diff -u -r1.27 gtksettings.c
--- gtk/gtksettings.c	29 Apr 2002 22:53:37 -0000	1.27
+++ gtk/gtksettings.c	30 May 2002 06:48:23 -0000
@@ -31,7 +31,8 @@
   PROP_KEY_THEME_NAME,
   PROP_MENU_BAR_ACCEL,
   PROP_DND_DRAG_THRESHOLD,
-  PROP_FONT_NAME
+  PROP_FONT_NAME,
+  PROP_ICON_SIZES
 };
 
 
@@ -213,6 +214,15 @@
 								  G_PARAM_READWRITE),
                                              NULL);
   g_assert (result == PROP_FONT_NAME);
+ 
+  result = settings_install_property_parser (class,
+                                             g_param_spec_string ("gtk-icon-sizes",
+								   _("Icon Sized"),
+								   _("Size in pixels of Standard Icon Types (semicolon delimited list)"),
+								  "x",
+								  G_PARAM_READWRITE),
+                                             NULL);
+  g_assert (result == PROP_ICON_SIZES);
  
 }
 
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.117
diff -u -r1.117 gtkstyle.c
--- gtk/gtkstyle.c	29 Apr 2002 22:53:37 -0000	1.117
+++ gtk/gtkstyle.c	30 May 2002 06:48:27 -0000
@@ -1963,7 +1963,7 @@
       return NULL;
     }
 
-  /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
+  /* If we're allowed to scale, then scale; otherwise,
    * leave it alone.
    */
   if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
Index: tests/testgtkrc2
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtkrc2,v
retrieving revision 1.4
diff -u -r1.4 testgtkrc2
--- tests/testgtkrc2	2 Jun 2000 03:14:07 -0000	1.4
+++ tests/testgtkrc2	30 May 2002 06:48:27 -0000
@@ -1,21 +1,6 @@
-# pixmap_path "<dir 1>:<dir 2>:<dir 3>:..."
-#
-# include "rc-file"
-#
-# style <name> [= <name>]
-# {
-#   <option>
-# }
-#
-# widget <widget_set> style <style_name>
-# widget_class <widget_class_set> style <style_name>
-
-# this file gets included from testgtkrc
-
-style 'main_buttons' = 'button'
+style 'panel'
 {
-  font_name = "Monospace 10"
-  bg[PRELIGHT] = { 0, 0, 0.75 }
+  bg[SELECTED] = { 0xe000, 0xe000,  0xe000}
 }
 
-widget "main window.*GtkButton*" style "main_buttons"
+widget "*GtkWidget*" style "panel"


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