Setting/style-property enhancements



Here are some additions that I'd find useful for using the style
properties mechanism for themes.

The intent here is to avoid having the 6 properties currently
for the option-menu-tab - left/right/top/bottom/width/height
by combining them into 2 properties - the border and the
size.

	* gtk/gtkwidget.[ch] gtk/gtktypeutils.c gtk/gtk-boxed.defs:
	Add boxed type for GtkRequistion. Use it for ::size-request.

	* gtk/gtkstyle.[ch] gtk/gtktypeutils.c gtk/gtk-boxed.defs:
        Add a new GtkBorder structure useful for geometry properties
	for widgets. Add corresponding GTK_TYPE_BORDER.
	
	* gtk/gtkwidget.c (gtk_widget_class_install_style_property):
	Support automatic parser selection like
	gtk_settings_install_property_parser().

	* gtk/gtksettings.c (_gtk_rc_property_select_parser): Export
	functionality for use by gtk_widget_class_install_style_property.
	Support GTK_TYPE_BORDER, GTK_TYPE_REQUISITION.

One thing I noticed here was that I wanted to make
gtk_rc_parser_border() support '3' as equivalent to { 3, 3, 3, 3 },
but couldn't.

And it doesn't look like gtk_rc_parse_color() supports the "#fffff"
formats for similar reason.

Perhaps the parser functions should take GtkSettingsValue
instead of GValue?

Regards, 
                                   Owen


Sun Apr  1 21:37:22 2001  Owen Taylor  <otaylor redhat com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1870
diff -u -r1.1870 ChangeLog
--- ChangeLog	2001/04/01 07:32:29	1.1870
+++ ChangeLog	2001/04/02 01:40:12
@@ -1,3 +1,25 @@
+Sun Apr  1 21:37:22 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/gtkwidget.[ch] gtk/gtktypeutils.c gtk/gtk-boxed.defs:
+	Add boxed type for GtkRequistion. Use it for ::size-request.
+
+	* gtk/gtkstyle.[ch] gtk/gtktypeutils.c gtk/gtk-boxed.defs:
+        Add a new GtkBorder structure useful for geometry properties
+	for widgets. Add corresponding GTK_TYPE_BORDER.
+	
+	* gtk/gtkwidget.c (gtk_widget_class_install_style_property):
+	Support automatic parser selection like
+	gtk_settings_install_property_parser().
+
+	* gtk/gtksettings.c (_gtk_rc_property_select_parser): Export
+	functionality for use by gtk_widget_class_install_style_property.
+	Support GTK_TYPE_BORDER, GTK_TYPE_REQUISITION.
+
+Sun Apr  1 20:48:59 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/gtkentry.c (gtk_entry_class_init): Make invisible-char
+	g_param_spec_unichar(). 
+
 Sun Apr  1 08:00:13 2001  Tim Janik  <timj gtk org>
 
 	* gtk/gtkwidget.[hc]: got rid of gtk_widget_popup(), a function that
Index: gtk/gtksettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.c,v
retrieving revision 1.4
diff -u -r1.4 gtksettings.c
--- gtk/gtksettings.c	2001/04/01 07:32:40	1.4
+++ gtk/gtksettings.c	2001/04/02 01:40:14
@@ -375,6 +375,23 @@
   return class_n_properties;
 }
 
+GtkRcPropertyParser
+_gtk_rc_property_select_parser (GType type)
+{
+  if (type == GTK_TYPE_GDK_COLOR)
+    return gtk_rc_property_parse_color;
+  else if (type == GTK_TYPE_REQUISITION)
+    return gtk_rc_property_parse_requisition;
+  else if (type == GTK_TYPE_BORDER)
+    return gtk_rc_property_parse_border;
+  else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
+    return gtk_rc_property_parse_enum;
+  else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
+    return gtk_rc_property_parse_flags;
+  else
+    return NULL;
+}
+
 void
 gtk_settings_install_property (GtkSettings *settings,
 			       GParamSpec  *pspec)
@@ -384,17 +401,8 @@
   g_return_if_fail (GTK_IS_SETTINGS (settings));
   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
 
-  /* convenient automatic parser selection
-   */
-  if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GTK_TYPE_GDK_COLOR)
-    parser = gtk_rc_property_parse_color;
-  else if (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)) == G_TYPE_ENUM &&
-	   G_TYPE_IS_DERIVED (G_PARAM_SPEC_VALUE_TYPE (pspec)))
-    parser = gtk_rc_property_parse_enum;
-  else if (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)) == G_TYPE_FLAGS &&
-	   G_TYPE_IS_DERIVED (G_PARAM_SPEC_VALUE_TYPE (pspec)))
-    parser = gtk_rc_property_parse_flags;
-  
+  parser = _gtk_rc_property_select_parser (G_PARAM_SPEC_VALUE_TYPE (pspec));
+
   settings_install_property_parser (GTK_SETTINGS_GET_CLASS (settings), pspec, parser);
 }
 
@@ -685,6 +693,103 @@
 	  success = TRUE;
 	}
     }
+  g_scanner_destroy (scanner);
+
+  return success;
+}
+
+static gboolean
+get_braced_int (GScanner *scanner,
+		gboolean  first,
+		gboolean  last,
+		gint     *value)
+{
+  if (first)
+    {
+      g_scanner_get_next_token (scanner);
+      if (scanner->token != '{')
+	return FALSE;
+    }
+
+  g_scanner_get_next_token (scanner);
+  if (scanner->token != G_TOKEN_INT)
+    return FALSE;
+
+  *value = scanner->value.v_int;
+
+  if (last)
+    {
+      g_scanner_get_next_token (scanner);
+      if (scanner->token != '}')
+	return FALSE;
+    }
+  else
+    {
+      g_scanner_get_next_token (scanner);
+      if (scanner->token != ',')
+	return FALSE;
+    }
+
+  return TRUE;
+}
+
+gboolean
+gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
+				    const GString    *gstring,
+				    GValue           *property_value)
+{
+  GtkRequisition requisition;
+  GScanner *scanner;
+  gboolean success = FALSE;
+
+  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
+  g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
+
+  scanner = gtk_rc_scanner_new ();
+  g_scanner_input_text (scanner, gstring->str, gstring->len);
+
+  if (!get_braced_int (scanner, TRUE, FALSE, &requisition.width))
+    goto out;
+  if (!get_braced_int (scanner, FALSE, TRUE, &requisition.height))
+    goto out;
+
+  g_value_set_boxed (property_value, &requisition);
+  success = TRUE;
+
+ out:
+  g_scanner_destroy (scanner);
+
+  return success;
+}
+
+gboolean
+gtk_rc_property_parse_border (const GParamSpec *pspec,
+			      const GString    *gstring,
+			      GValue           *property_value)
+{
+  GtkBorder border;
+  GScanner *scanner;
+  gboolean success = FALSE;
+
+  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
+  g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
+
+  scanner = gtk_rc_scanner_new ();
+  g_scanner_input_text (scanner, gstring->str, gstring->len);
+
+  if (!get_braced_int (scanner, TRUE, FALSE, &border.left))
+    goto out;
+  if (!get_braced_int (scanner, FALSE, FALSE, &border.right))
+    goto out;
+  if (!get_braced_int (scanner, FALSE, FALSE, &border.top))
+    goto out;
+  if (!get_braced_int (scanner, FALSE, TRUE, &border.bottom))
+    goto out;
+
+  g_value_set_boxed (property_value, &border);
+  success = TRUE;
+
+ out:
   g_scanner_destroy (scanner);
 
   return success;
Index: gtk/gtksettings.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.h,v
retrieving revision 1.1
diff -u -r1.1 gtksettings.h
--- gtk/gtksettings.h	2001/03/18 04:50:33	1.1
+++ gtk/gtksettings.h	2001/04/02 01:40:14
@@ -77,15 +77,21 @@
 						      GtkRcPropertyParser parser);
 
 /* --- precoded parsing functions --- */
-gboolean	gtk_rc_property_parse_color (const GParamSpec *pspec,
-					     const GString    *gstring,
-					     GValue           *property_value);
-gboolean	gtk_rc_property_parse_enum  (const GParamSpec *pspec,
-					     const GString    *gstring,
-					     GValue           *property_value);
-gboolean	gtk_rc_property_parse_flags (const GParamSpec *pspec,
-					     const GString    *gstring,
-					     GValue           *property_value);
+gboolean gtk_rc_property_parse_color       (const GParamSpec *pspec,
+					    const GString    *gstring,
+					    GValue           *property_value);
+gboolean gtk_rc_property_parse_enum        (const GParamSpec *pspec,
+					    const GString    *gstring,
+					    GValue           *property_value);
+gboolean gtk_rc_property_parse_flags       (const GParamSpec *pspec,
+					    const GString    *gstring,
+					    GValue           *property_value);
+gboolean gtk_rc_property_parse_requisition (const GParamSpec *pspec,
+					    const GString    *gstring,
+					    GValue           *property_value);
+gboolean gtk_rc_property_parse_border      (const GParamSpec *pspec,
+					    const GString    *gstring,
+					    GValue           *property_value);
 
 /*< private >*/
 void		gtk_settings_set_property_value	 (GtkSettings	*settings,
@@ -103,6 +109,8 @@
 						  const gchar	*name,
 						  gdouble	 v_double,
 						  const gchar   *origin);
+
+GtkRcPropertyParser _gtk_rc_property_select_parser (GType type);
 
 #ifdef __cplusplus
 }
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.58
diff -u -r1.58 gtkstyle.c
--- gtk/gtkstyle.c	2001/03/29 21:17:45	1.58
+++ gtk/gtkstyle.c	2001/04/02 01:40:14
@@ -4620,3 +4620,15 @@
                                                  edge, x, y, width, height);
 }
 
+GtkBorder *
+gtk_border_copy (const GtkBorder *border)
+{
+  return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
+}
+
+void
+gtk_border_free (GtkBorder *border)
+{
+  g_free (border);
+}
+
Index: gtk/gtkstyle.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.h,v
retrieving revision 1.24
diff -u -r1.24 gtkstyle.h
--- gtk/gtkstyle.h	2001/03/29 21:17:45	1.24
+++ gtk/gtkstyle.h	2001/04/02 01:40:14
@@ -46,6 +46,7 @@
 /* Some forward declarations needed to rationalize the header
  * files.
  */
+typedef struct _GtkBorder      GtkBorder;
 typedef struct _GtkStyle       GtkStyle;
 typedef struct _GtkStyleClass  GtkStyleClass;
 typedef struct _GtkThemeEngine GtkThemeEngine;
@@ -400,6 +401,14 @@
   
 };
 
+struct _GtkBorder
+{
+  gint left;
+  gint right;
+  gint top;
+  gint bottom;
+};
+
 GType     gtk_style_get_type                 (void) G_GNUC_CONST;
 GtkStyle* gtk_style_new			     (void);
 GtkStyle* gtk_style_copy		     (GtkStyle	    *style);
@@ -814,6 +823,9 @@
                             gint                 width,
                             gint           	 height);
 
+
+GtkBorder *gtk_border_copy (const GtkBorder *border);
+void       gtk_border_free (GtkBorder       *border);
 
 /* --- private API --- */
 const GValue* _gtk_style_peek_property_value (GtkStyle           *style,
Index: gtk/gtktypeutils.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktypeutils.c,v
retrieving revision 1.68
diff -u -r1.68 gtktypeutils.c
--- gtk/gtktypeutils.c	2001/03/18 04:50:34	1.68
+++ gtk/gtktypeutils.c	2001/04/02 01:40:14
@@ -170,8 +170,8 @@
 	  else if (builtin_info[i].parent == GTK_TYPE_BOXED)
 	    {
 	      static const gchar *copy_types[] = {
-		"GtkSelectionData", "GdkEvent", "GdkColor", "GtkTextIter", "PangoTabArray",
-		"PangoFontDescription", "GtkTreeIter", "GtkTreePath",
+		"GtkSelectionData", "GdkEvent", "GdkColor", "GtkBorder", "GtkTextIter", "PangoTabArray",
+		"PangoFontDescription", "GtkTreeIter", "GtkTreePath", "GtkRequisition"
 	      };
 	      gboolean ref_counted = TRUE;
 	      guint j;
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.205
diff -u -r1.205 gtkwidget.c
--- gtk/gtkwidget.c	2001/04/01 07:32:40	1.205
+++ gtk/gtkwidget.c	2001/04/02 01:40:14
@@ -569,10 +569,10 @@
 		    GTK_RUN_FIRST,
 		    GTK_CLASS_TYPE (object_class),
 		    GTK_SIGNAL_OFFSET (GtkWidgetClass, size_request),
-		    gtk_marshal_VOID__POINTER,
+		    gtk_marshal_VOID__BOXED,
 		    GTK_TYPE_NONE, 1,
-		    GTK_TYPE_POINTER);
-  widget_signals[SIZE_ALLOCATE] =
+		    GTK_TYPE_REQUISITION | G_VALUE_NOCOPY_CONTENTS);
+  widget_signals[SIZE_ALLOCATE] = 
     gtk_signal_new ("size_allocate",
 		    GTK_RUN_FIRST,
 		    GTK_CLASS_TYPE (object_class),
@@ -5383,7 +5383,14 @@
 gtk_widget_class_install_style_property (GtkWidgetClass *class,
 					 GParamSpec     *pspec)
 {
-  gtk_widget_class_install_style_property_parser (class, pspec, NULL);
+  GtkRcPropertyParser parser;
+
+  g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
+  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
+
+  parser = _gtk_rc_property_select_parser (G_PARAM_SPEC_VALUE_TYPE (pspec));
+
+  gtk_widget_class_install_style_property_parser (class, pspec, parser);
 }
 
 void
@@ -5634,3 +5641,16 @@
       g_strreverse (*path_p);
     }
 }
+
+GtkRequisition *
+gtk_requisition_copy (const GtkRequisition *requisition)
+{
+  return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
+}
+
+void
+gtk_requisition_free (GtkRequisition *requisition)
+{
+  g_free (requisition);
+}
+
Index: gtk/gtkwidget.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.h,v
retrieving revision 1.105
diff -u -r1.105 gtkwidget.h
--- gtk/gtkwidget.h	2001/04/01 07:32:40	1.105
+++ gtk/gtkwidget.h	2001/04/02 01:40:14
@@ -673,6 +673,9 @@
 					    gchar    **path,
 					    gchar    **path_reversed);
 
+GtkRequisition *gtk_requisition_copy (const GtkRequisition *requisition);
+void            gtk_requisition_free (GtkRequisition       *requisition);
+
 #if	defined (GTK_TRACE_OBJECTS) && defined (__GNUC__)
 #  define gtk_widget_ref gtk_object_ref
 #  define gtk_widget_unref gtk_object_unref


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