summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-09-08 17:55:02 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-09-08 17:55:02 +0000
commitfd97e93165ed58427f7d442b90e3ce992d37eb3a (patch)
tree36657ef5fa192ccccd63d8990a60da4e149bedbb
parent372853b107d752cdb5e8d180be9b6a1c9a752f36 (diff)
downloadgtk+-fd97e93165ed58427f7d442b90e3ce992d37eb3a.tar.gz
Replace uses of GBSearchArray with GArray and bsearch(), to remove
Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com> * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray with GArray and bsearch(), to remove dependency on a still evolving interface that we want to keep private to glib/gobject.
-rw-r--r--ChangeLog6
-rw-r--r--ChangeLog.pre-2-06
-rw-r--r--ChangeLog.pre-2-106
-rw-r--r--ChangeLog.pre-2-26
-rw-r--r--ChangeLog.pre-2-46
-rw-r--r--ChangeLog.pre-2-66
-rw-r--r--ChangeLog.pre-2-86
-rw-r--r--gtk/gtkrc.c144
-rw-r--r--gtk/gtkrc.h2
-rw-r--r--gtk/gtkstyle.c83
-rw-r--r--gtk/gtkstyle.h2
11 files changed, 154 insertions, 119 deletions
diff --git a/ChangeLog b/ChangeLog
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index b42579edb3..fff88df6c1 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,9 @@
+Sat Sep 8 13:53:09 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkrc.[ch] gtk/gtkstyle.[ch]: Replace uses of GBSearchArray
+ with GArray and bsearch(), to remove dependency on a still
+ evolving interface that we want to keep private to glib/gobject.
+
2001-09-08 Havoc Pennington <hp@pobox.com>
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_add_attribute):
diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c
index 70c3fd019d..6a13c2ffd3 100644
--- a/gtk/gtkrc.c
+++ b/gtk/gtkrc.c
@@ -1070,14 +1070,14 @@ gtk_rc_style_finalize (GObject *object)
{
guint i;
- for (i = 0; i < rc_style->rc_properties->n_nodes; i++)
+ for (i = 0; i < rc_style->rc_properties->len; i++)
{
- GtkRcProperty *node = g_bsearch_array_get_nth (rc_style->rc_properties, i);
+ GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
g_free (node->origin);
g_value_unset (&node->value);
}
- g_bsearch_array_destroy (rc_style->rc_properties);
+ g_array_free (rc_style->rc_properties, TRUE);
rc_style->rc_properties = NULL;
}
@@ -1154,13 +1154,63 @@ gtk_rc_properties_cmp (gconstpointer bsearch_node1,
{
const GtkRcProperty *prop1 = bsearch_node1;
const GtkRcProperty *prop2 = bsearch_node2;
- gint cmp;
- cmp = G_BSEARCH_ARRAY_CMP (prop1->type_name, prop2->type_name);
- if (cmp == 0)
- cmp = G_BSEARCH_ARRAY_CMP (prop1->property_name, prop2->property_name);
+ if (prop1->type_name == prop2->type_name)
+ return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
+ else
+ return prop1->type_name < prop2->type_name ? -1 : 1;
+}
+
+static void
+insert_rc_property (GtkRcStyle *style,
+ GtkRcProperty *property,
+ gboolean replace)
+{
+ guint i;
+ GtkRcProperty *new_property = NULL;
+ GtkRcProperty key = { 0, 0, NULL, { 0, }, };
+
+ key.type_name = property->type_name;
+ key.property_name = property->property_name;
+
+ if (!style->rc_properties)
+ style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
+
+ i = 0;
+ while (i < style->rc_properties->len)
+ {
+ gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
+ if (cmp == 0)
+
+ {
+ if (replace)
+ {
+ new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
+
+ g_free (new_property->origin);
+ g_value_unset (&new_property->value);
+
+ *new_property = key;
+ break;
+ }
+ else
+ return;
+ }
+ else if (cmp > 0)
+ break;
- return cmp;
+ i++;
+ }
+
+ if (!new_property)
+ {
+ g_array_insert_val (style->rc_properties, i, key);
+ new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
+ }
+
+ new_property->origin = g_strdup (property->origin);
+ g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
+ g_value_copy (&property->value, &new_property->value);
}
static void
@@ -1212,25 +1262,10 @@ gtk_rc_style_real_merge (GtkRcStyle *dest,
{
guint i;
- if (!dest->rc_properties)
- dest->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
- gtk_rc_properties_cmp,
- 0);
- for (i = 0; i < src->rc_properties->n_nodes; i++)
- {
- GtkRcProperty *node = g_bsearch_array_get_nth (src->rc_properties, i);
- GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
-
- key.type_name = node->type_name;
- key.property_name = node->property_name;
- prop = g_bsearch_array_insert (dest->rc_properties, &key, FALSE);
- if (!prop->origin)
- {
- prop->origin = g_strdup (node->origin);
- g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
- g_value_copy (&node->value, &prop->value);
- }
- }
+ for (i = 0; i < src->rc_properties->len; i++)
+ insert_rc_property (dest,
+ &g_array_index (src->rc_properties, GtkRcProperty, i),
+ FALSE);
}
}
@@ -2317,27 +2352,10 @@ gtk_rc_parse_style (GtkRcContext *context,
{
guint i;
- if (!rc_style->rc_properties)
- rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
- gtk_rc_properties_cmp,
- 0);
- for (i = 0; i < parent_style->rc_properties->n_nodes; i++)
- {
- GtkRcProperty *node = g_bsearch_array_get_nth (parent_style->rc_properties, i);
- GtkRcProperty *prop, key = { 0, 0, NULL, { 0, }, };
-
- key.type_name = node->type_name;
- key.property_name = node->property_name;
- prop = g_bsearch_array_insert (rc_style->rc_properties, &key, FALSE);
- if (prop->origin)
- {
- g_free (prop->origin);
- g_value_unset (&prop->value);
- }
- prop->origin = g_strdup (node->origin);
- g_value_init (&prop->value, G_VALUE_TYPE (&node->value));
- g_value_copy (&node->value, &prop->value);
- }
+ for (i = 0; i < parent_style->rc_properties->len; i++)
+ insert_rc_property (rc_style,
+ &g_array_index (parent_style->rc_properties, GtkRcProperty, i),
+ TRUE);
}
for (i = 0; i < 5; i++)
@@ -2463,29 +2481,13 @@ gtk_rc_parse_style (GtkRcContext *context,
token = gtk_rc_parse_assignment (scanner, &prop);
if (token == G_TOKEN_NONE)
{
- GtkRcProperty *tmp;
-
g_return_val_if_fail (prop.origin != NULL && G_VALUE_TYPE (&prop.value) != 0, G_TOKEN_ERROR);
-
- if (!rc_style->rc_properties)
- rc_style->rc_properties = g_bsearch_array_new (sizeof (GtkRcProperty),
- gtk_rc_properties_cmp,
- 0);
- tmp = g_bsearch_array_insert (rc_style->rc_properties, &prop, FALSE);
- if (prop.origin != tmp->origin)
- {
- g_free (tmp->origin);
- g_value_unset (&tmp->value);
- tmp->origin = prop.origin;
- memcpy (&tmp->value, &prop.value, sizeof (prop.value));
- }
- }
- else
- {
- g_free (prop.origin);
- if (G_VALUE_TYPE (&prop.value))
- g_value_unset (&prop.value);
+ insert_rc_property (rc_style, &prop, TRUE);
}
+
+ g_free (prop.origin);
+ if (G_VALUE_TYPE (&prop.value))
+ g_value_unset (&prop.value);
}
else
{
@@ -2554,7 +2556,9 @@ _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
key.type_name = type_name;
key.property_name = property_name;
- node = g_bsearch_array_lookup (rc_style->rc_properties, &key);
+ node = bsearch (&key,
+ rc_style->rc_properties->data, rc_style->rc_properties->len,
+ sizeof (GtkRcProperty), gtk_rc_properties_cmp);
}
return node;
diff --git a/gtk/gtkrc.h b/gtk/gtkrc.h
index d655ca2b00..b62db65bb1 100644
--- a/gtk/gtkrc.h
+++ b/gtk/gtkrc.h
@@ -76,7 +76,7 @@ struct _GtkRcStyle
gint ythickness;
/*< private >*/
- GBSearchArray *rc_properties;
+ GArray *rc_properties;
/* list of RC style lists including this RC style */
GSList *rc_style_lists;
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 89abbe191f..8461e4d4d3 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -25,6 +25,7 @@
*/
#include <math.h>
+#include <stdlib.h>
#include <string.h>
#include "gtkgc.h"
#include "gtkrc.h"
@@ -563,26 +564,32 @@ gtk_style_class_init (GtkStyleClass *klass)
}
static void
-gtk_style_finalize (GObject *object)
+clear_property_cache (GtkStyle *style)
{
- GtkStyle *style = GTK_STYLE (object);
-
- g_return_if_fail (style->attach_count == 0);
-
if (style->property_cache)
{
guint i;
- for (i = 0; i < style->property_cache->n_nodes; i++)
+ for (i = 0; i < style->property_cache->len; i++)
{
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
+ PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
- g_bsearch_array_destroy (style->property_cache);
+ g_array_free (style->property_cache, TRUE);
style->property_cache = NULL;
}
+}
+
+static void
+gtk_style_finalize (GObject *object)
+{
+ GtkStyle *style = GTK_STYLE (object);
+
+ g_return_if_fail (style->attach_count == 0);
+
+ clear_property_cache (style);
if (style->styles)
{
@@ -1206,20 +1213,7 @@ gtk_style_real_copy (GtkStyle *style,
gtk_rc_style_ref (src->rc_style);
/* don't copy, just clear cache */
- if (style->property_cache)
- {
- guint i;
-
- for (i = 0; i < style->property_cache->n_nodes; i++)
- {
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
-
- g_param_spec_unref (node->pspec);
- g_value_unset (&node->value);
- }
- g_bsearch_array_destroy (style->property_cache);
- style->property_cache = NULL;
- }
+ clear_property_cache (style);
}
static void
@@ -1230,20 +1224,7 @@ gtk_style_real_init_from_rc (GtkStyle *style,
gint i;
/* cache _should_ be still empty */
- if (style->property_cache)
- {
- guint i;
-
- for (i = 0; i < style->property_cache->n_nodes; i++)
- {
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
-
- g_param_spec_unref (node->pspec);
- g_value_unset (&node->value);
- }
- g_bsearch_array_destroy (style->property_cache);
- style->property_cache = NULL;
- }
+ clear_property_cache (style);
if (rc_style->font_desc)
{
@@ -1297,13 +1278,11 @@ style_property_values_cmp (gconstpointer bsearch_node1,
{
const PropertyValue *val1 = bsearch_node1;
const PropertyValue *val2 = bsearch_node2;
- gint cmp;
- cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
- if (cmp == 0)
- cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
-
- return cmp;
+ if (val1->widget_type == val2->widget_type)
+ return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
+ else
+ return val1->widget_type < val2->widget_type ? -1 : 1;
}
const GValue*
@@ -1314,6 +1293,7 @@ _gtk_style_peek_property_value (GtkStyle *style,
{
PropertyValue *pcache, key = { 0, NULL, { 0, } };
const GtkRcProperty *rcprop = NULL;
+ guint i;
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
@@ -1322,16 +1302,25 @@ _gtk_style_peek_property_value (GtkStyle *style,
/* need value cache array */
if (!style->property_cache)
- style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
- style_property_values_cmp,
- 0);
+ style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
+
/* lookup, or insert value if not yet present */
key.widget_type = widget_type;
key.pspec = pspec;
- pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
- if (G_VALUE_TYPE (&pcache->value))
+ pcache = bsearch (&key,
+ style->property_cache->data, style->property_cache->len,
+ sizeof (PropertyValue), style_property_values_cmp);
+ if (pcache)
return &pcache->value;
+ i = 0;
+ while (i < style->property_cache->len &&
+ style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
+ i++;
+
+ g_array_insert_val (style->property_cache, i, key);
+ pcache = &g_array_index (style->property_cache, PropertyValue, i);
+
/* cache miss, initialize value type, then set contents */
g_param_spec_ref (pcache->pspec);
g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 4335e0bb87..8c2a0c5b4c 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -117,7 +117,7 @@ struct _GtkStyle
GtkRcStyle *rc_style;
GSList *styles; /* of type GtkStyle* */
- GBSearchArray *property_cache;
+ GArray *property_cache;
GSList *icon_factories; /* of type GtkIconFactory* */
};