Commit 9b9b475f authored by Benjamin Otte's avatar Benjamin Otte

API: stylecontext: Remove regions

parent 1a7dcb20
......@@ -5587,9 +5587,7 @@ gtk_widget_path_get_object_type
gtk_widget_path_has_parent
gtk_widget_path_is_type
gtk_widget_path_iter_add_class
gtk_widget_path_iter_add_region
gtk_widget_path_iter_clear_classes
gtk_widget_path_iter_clear_regions
gtk_widget_path_iter_get_name
gtk_widget_path_iter_get_object_name
gtk_widget_path_iter_get_object_type
......@@ -5600,12 +5598,8 @@ gtk_widget_path_iter_has_class
gtk_widget_path_iter_has_name
gtk_widget_path_iter_has_qclass
gtk_widget_path_iter_has_qname
gtk_widget_path_iter_has_qregion
gtk_widget_path_iter_has_region
gtk_widget_path_iter_list_classes
gtk_widget_path_iter_list_regions
gtk_widget_path_iter_remove_class
gtk_widget_path_iter_remove_region
gtk_widget_path_iter_set_name
gtk_widget_path_iter_set_object_name
gtk_widget_path_iter_set_object_type
......@@ -5788,11 +5782,6 @@ gtk_style_context_add_class
gtk_style_context_remove_class
gtk_style_context_has_class
gtk_style_context_list_classes
GtkRegionFlags
gtk_style_context_add_region
gtk_style_context_remove_region
gtk_style_context_has_region
gtk_style_context_list_regions
gtk_style_context_set_screen
gtk_style_context_set_frame_clock
gtk_style_context_set_state
......
......@@ -1266,36 +1266,6 @@ gtk_css_node_list_classes (GtkCssNode *cssnode,
return gtk_css_node_declaration_get_classes (cssnode->decl, n_classes);
}
void
gtk_css_node_add_region (GtkCssNode *cssnode,
GQuark region,
GtkRegionFlags flags)
{
gtk_css_node_declaration_add_region (&cssnode->decl, region, flags);
}
void
gtk_css_node_remove_region (GtkCssNode *cssnode,
GQuark region)
{
gtk_css_node_declaration_remove_region (&cssnode->decl, region);
}
gboolean
gtk_css_node_has_region (GtkCssNode *cssnode,
GQuark region,
GtkRegionFlags *out_flags)
{
return gtk_css_node_declaration_has_region (cssnode->decl, region, out_flags);
}
GList *
gtk_css_node_list_regions (GtkCssNode *cssnode)
{
return gtk_css_node_declaration_list_regions (cssnode->decl);
}
const GtkCssNodeDeclaration *
gtk_css_node_get_declaration (GtkCssNode *cssnode)
{
......
......@@ -22,14 +22,6 @@
#include <string.h>
typedef struct _GtkRegion GtkRegion;
struct _GtkRegion
{
GQuark class_quark;
GtkRegionFlags flags;
};
struct _GtkCssNodeDeclaration {
guint refcount;
GtkJunctionSides junction_sides;
......@@ -38,9 +30,7 @@ struct _GtkCssNodeDeclaration {
const /* interned */ char *id;
GtkStateFlags state;
guint n_classes;
guint n_regions;
/* GQuark classes[n_classes]; */
/* GtkRegion region[n_regions]; */
};
static inline GQuark *
......@@ -49,25 +39,17 @@ get_classes (const GtkCssNodeDeclaration *decl)
return (GQuark *) (decl + 1);
}
static inline GtkRegion *
get_regions (const GtkCssNodeDeclaration *decl)
{
return (GtkRegion *) (get_classes (decl) + decl->n_classes);
}
static inline gsize
sizeof_node (guint n_classes,
guint n_regions)
sizeof_node (guint n_classes)
{
return sizeof (GtkCssNodeDeclaration)
+ sizeof (GQuark) * n_classes
+ sizeof (GtkRegion) * n_regions;
+ sizeof (GQuark) * n_classes;
}
static inline gsize
sizeof_this_node (GtkCssNodeDeclaration *decl)
{
return sizeof_node (decl->n_classes, decl->n_regions);
return sizeof_node (decl->n_classes);
}
static void
......@@ -123,7 +105,6 @@ gtk_css_node_declaration_new (void)
NULL,
NULL,
0,
0,
0
};
......@@ -382,155 +363,11 @@ gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl,
return get_classes (decl);
}
static gboolean
find_region (const GtkCssNodeDeclaration *decl,
GQuark region_quark,
guint *position)
{
gint min, max, mid;
gboolean found = FALSE;
GtkRegion *regions;
guint pos;
if (position)
*position = 0;
if (decl->n_regions == 0)
return FALSE;
min = 0;
max = decl->n_regions - 1;
regions = get_regions (decl);
do
{
GQuark item;
mid = (min + max) / 2;
item = regions[mid].class_quark;
if (region_quark == item)
{
found = TRUE;
pos = mid;
break;
}
else if (region_quark > item)
min = pos = mid + 1;
else
{
max = mid - 1;
pos = mid;
}
}
while (min <= max);
if (position)
*position = pos;
return found;
}
gboolean
gtk_css_node_declaration_add_region (GtkCssNodeDeclaration **decl,
GQuark region_quark,
GtkRegionFlags flags)
{
GtkRegion *regions;
guint pos;
if (find_region (*decl, region_quark, &pos))
return FALSE;
gtk_css_node_declaration_make_writable_resize (decl,
(char *) &get_regions (*decl)[pos] - (char *) *decl,
sizeof (GtkRegion),
0);
(*decl)->n_regions++;
regions = get_regions(*decl);
regions[pos].class_quark = region_quark;
regions[pos].flags = flags;
return TRUE;
}
gboolean
gtk_css_node_declaration_remove_region (GtkCssNodeDeclaration **decl,
GQuark region_quark)
{
guint pos;
if (!find_region (*decl, region_quark, &pos))
return FALSE;
gtk_css_node_declaration_make_writable_resize (decl,
(char *) &get_regions (*decl)[pos] - (char *) *decl,
0,
sizeof (GtkRegion));
(*decl)->n_regions--;
return TRUE;
}
gboolean
gtk_css_node_declaration_clear_regions (GtkCssNodeDeclaration **decl)
{
if ((*decl)->n_regions == 0)
return FALSE;
gtk_css_node_declaration_make_writable_resize (decl,
(char *) get_regions (*decl) - (char *) *decl,
0,
sizeof (GtkRegion) * (*decl)->n_regions);
(*decl)->n_regions = 0;
return TRUE;
}
gboolean
gtk_css_node_declaration_has_region (const GtkCssNodeDeclaration *decl,
GQuark region_quark,
GtkRegionFlags *flags_return)
{
guint pos;
if (!find_region (decl, region_quark, &pos))
{
if (flags_return)
*flags_return = 0;
return FALSE;
}
if (flags_return)
*flags_return = get_regions (decl)[pos].flags;
return TRUE;
}
GList *
gtk_css_node_declaration_list_regions (const GtkCssNodeDeclaration *decl)
{
GtkRegion *regions;
GList *result;
guint i;
regions = get_regions (decl);
result = NULL;
for (i = 0; i < decl->n_regions; i++)
{
result = g_list_prepend (result, GUINT_TO_POINTER (regions[i].class_quark));
}
return result;
}
guint
gtk_css_node_declaration_hash (gconstpointer elem)
{
const GtkCssNodeDeclaration *decl = elem;
GQuark *classes;
GtkRegion *regions;
guint hash, i;
hash = (guint) decl->type;
......@@ -545,14 +382,6 @@ gtk_css_node_declaration_hash (gconstpointer elem)
hash += classes[i];
}
regions = get_regions (decl);
for (i = 0; i < decl->n_regions; i++)
{
hash <<= 5;
hash += regions[i].class_quark;
hash += regions[i].flags;
}
hash ^= ((guint) decl->junction_sides) << (sizeof (guint) * 8 - 5);
hash ^= decl->state;
......@@ -566,7 +395,6 @@ gtk_css_node_declaration_equal (gconstpointer elem1,
const GtkCssNodeDeclaration *decl1 = elem1;
const GtkCssNodeDeclaration *decl2 = elem2;
GQuark *classes1, *classes2;
GtkRegion *regions1, *regions2;
guint i;
if (decl1 == decl2)
......@@ -595,18 +423,6 @@ gtk_css_node_declaration_equal (gconstpointer elem1,
return FALSE;
}
if (decl1->n_regions != decl2->n_regions)
return FALSE;
regions1 = get_regions (decl1);
regions2 = get_regions (decl2);
for (i = 0; i < decl1->n_regions; i++)
{
if (regions1[i].class_quark != regions2[i].class_quark ||
regions1[i].flags != regions2[i].flags)
return FALSE;
}
if (decl1->junction_sides != decl2->junction_sides)
return FALSE;
......@@ -619,7 +435,6 @@ gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
guint pos)
{
GQuark *classes;
GtkRegion *regions;
guint i;
/* Set name and id */
......@@ -627,17 +442,6 @@ gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
if (decl->id)
gtk_widget_path_iter_set_name (path, pos, decl->id);
/* Set widget regions */
regions = get_regions (decl);
for (i = 0; i < decl->n_regions; i++)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_widget_path_iter_add_region (path, pos,
g_quark_to_string (regions[i].class_quark),
regions[i].flags);
G_GNUC_END_IGNORE_DEPRECATIONS
}
/* Set widget classes */
classes = get_classes (decl);
for (i = 0; i < decl->n_classes; i++)
......
......@@ -54,17 +54,6 @@ gboolean gtk_css_node_declaration_has_class (const G
const GQuark * gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl,
guint *n_classes);
gboolean gtk_css_node_declaration_add_region (GtkCssNodeDeclaration **decl,
GQuark region_quark,
GtkRegionFlags flags);
gboolean gtk_css_node_declaration_remove_region (GtkCssNodeDeclaration **decl,
GQuark region_quark);
gboolean gtk_css_node_declaration_clear_regions (GtkCssNodeDeclaration **decl);
gboolean gtk_css_node_declaration_has_region (const GtkCssNodeDeclaration *decl,
GQuark region_quark,
GtkRegionFlags *flags_return);
GList * gtk_css_node_declaration_list_regions (const GtkCssNodeDeclaration *decl);
guint gtk_css_node_declaration_hash (gconstpointer elem);
gboolean gtk_css_node_declaration_equal (gconstpointer elem1,
gconstpointer elem2);
......
......@@ -143,15 +143,6 @@ gboolean gtk_css_node_has_class (GtkCssNode *
GQuark style_class);
const GQuark * gtk_css_node_list_classes (GtkCssNode *cssnode,
guint *n_classes);
void gtk_css_node_add_region (GtkCssNode *cssnode,
GQuark region,
GtkRegionFlags flags);
void gtk_css_node_remove_region (GtkCssNode *cssnode,
GQuark region);
gboolean gtk_css_node_has_region (GtkCssNode *cssnode,
GQuark region,
GtkRegionFlags *out_flags);
GList * gtk_css_node_list_regions (GtkCssNode *cssnode);
const GtkCssNodeDeclaration *
gtk_css_node_get_declaration (GtkCssNode *cssnode);
......
......@@ -80,11 +80,6 @@ union _GtkCssSelector
const GtkCssSelectorClass *class;
const char *name; /* interned */
} id;
struct {
const GtkCssSelectorClass *class;
const char *name; /* interned */
GtkRegionFlags flags;
} region;
struct {
const GtkCssSelectorClass *class;
GQuark style_class;
......
......@@ -881,26 +881,6 @@ typedef enum
GTK_STATE_FLAG_DROP_ACTIVE = 1 << 12
} GtkStateFlags;
/**
* GtkRegionFlags:
* @GTK_REGION_EVEN: Region has an even number within a set.
* @GTK_REGION_ODD: Region has an odd number within a set.
* @GTK_REGION_FIRST: Region is the first one within a set.
* @GTK_REGION_LAST: Region is the last one within a set.
* @GTK_REGION_ONLY: Region is the only one within a set.
* @GTK_REGION_SORTED: Region is part of a sorted area.
*
* Describes a region within a widget.
*/
typedef enum {
GTK_REGION_EVEN = 1 << 0,
GTK_REGION_ODD = 1 << 1,
GTK_REGION_FIRST = 1 << 2,
GTK_REGION_LAST = 1 << 3,
GTK_REGION_ONLY = 1 << 4,
GTK_REGION_SORTED = 1 << 5
} GtkRegionFlags;
/**
* GtkJunctionSides:
* @GTK_JUNCTION_NONE: No junctions.
......
......@@ -97,14 +97,6 @@
*
* GTK+ defines macros for a number of style classes.
*
* # Style Regions
*
* Widgets can also add regions with flags to their context. This feature is
* deprecated and will be removed in a future GTK+ update. Please use style
* classes instead.
*
* GTK+ defines macros for a number of style regions.
*
* # Custom styling in UI libraries and applications
*
* If you are developing a library with custom #GtkWidgets that
......@@ -453,7 +445,7 @@ gtk_style_context_impl_get_property (GObject *object,
/* returns TRUE if someone called gtk_style_context_save() but hasn’t
* called gtk_style_context_restore() yet.
* In those situations we don’t invalidate the context when somebody
* changes state/regions/classes.
* changes state/classes.
*/
static gboolean
gtk_style_context_is_saved (GtkStyleContext *context)
......@@ -1403,167 +1395,6 @@ gtk_style_context_list_classes (GtkStyleContext *context)
return classes_list;
}
/**
* gtk_style_context_list_regions:
* @context: a #GtkStyleContext
*
* Returns the list of regions currently defined in @context.
*
* Returns: (transfer container) (element-type utf8): a #GList of
* strings with the currently defined regions. The contents
* of the list are owned by GTK+, but you must free the list
* itself with g_list_free() when you are done with it.
*
* Since: 3.0
*
* Deprecated: 3.14
**/
GList *
gtk_style_context_list_regions (GtkStyleContext *context)
{
GList *regions, *l;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
regions = gtk_css_node_list_regions (context->priv->cssnode);
for (l = regions; l; l = l->next)
l->data = (char *) g_quark_to_string (GPOINTER_TO_UINT (l->data));
return regions;
}
gboolean
_gtk_style_context_check_region_name (const gchar *str)
{
g_return_val_if_fail (str != NULL, FALSE);
if (!g_ascii_islower (str[0]))
return FALSE;
while (*str)
{
if (*str != '-' &&
!g_ascii_islower (*str))
return FALSE;
str++;
}
return TRUE;
}
/**
* gtk_style_context_add_region:
* @context: a #GtkStyleContext
* @region_name: region name to use in styling
* @flags: flags that apply to the region
*
* Adds a region to @context, so posterior calls to
* gtk_style_context_get() or any of the gtk_render_*()
* functions will make use of this new region for styling.
*
* In the CSS file format, a #GtkTreeView defining a “row”
* region, would be matched by:
*
* |[
* GtkTreeView row { ... }
* ]|
*
* Pseudo-classes are used for matching @flags, so the two
* following rules:
* |[
* GtkTreeView row:nth-child(even) { ... }
* GtkTreeView row:nth-child(odd) { ... }
* ]|
*
* would apply to even and odd rows, respectively.
*
* Region names must only contain lowercase letters
* and “-”, starting always with a lowercase letter.
*
* Since: 3.0
*
* Deprecated: 3.14
**/
void
gtk_style_context_add_region (GtkStyleContext *context,
const gchar *region_name,
GtkRegionFlags flags)
{
GQuark region_quark;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (region_name != NULL);
g_return_if_fail (_gtk_style_context_check_region_name (region_name));
region_quark = g_quark_from_string (region_name);
gtk_css_node_add_region (context->priv->cssnode, region_quark, flags);
}
/**
* gtk_style_context_remove_region:
* @context: a #GtkStyleContext
* @region_name: region name to unset
*
* Removes a region from @context.
*
* Since: 3.0
*
* Deprecated: 3.14
**/
void
gtk_style_context_remove_region (GtkStyleContext *context,
const gchar *region_name)
{
GQuark region_quark;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (region_name != NULL);
region_quark = g_quark_try_string (region_name);
if (!region_quark)
return;
gtk_css_node_remove_region (context->priv->cssnode, region_quark);
}
/**
* gtk_style_context_has_region:
* @context: a #GtkStyleContext
* @region_name: a region name
* @flags_return: (out) (allow-none): return location for region flags
*
* Returns %TRUE if @context has the region defined.
* If @flags_return is not %NULL, it is set to the flags
* affecting the region.
*
* Returns: %TRUE if region is defined
*
* Since: 3.0
*
* Deprecated: 3.14
**/
gboolean
gtk_style_context_has_region (GtkStyleContext *context,
const gchar *region_name,
GtkRegionFlags *flags_return)
{
GQuark region_quark;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (region_name != NULL, FALSE);
if (flags_return)
*flags_return = 0;
region_quark = g_quark_try_string (region_name);
if (!region_quark)
return FALSE;
return gtk_css_node_has_region (context->priv->cssnode, region_quark, flags_return);
}
static gint
style_property_values_cmp (gconstpointer bsearch_node1,
gconstpointer bsearch_node2)
......
......@@ -1060,21 +1060,6 @@ GDK_AVAILABLE_IN_ALL
gboolean gtk_style_context_has_class (GtkStyleContext *context,
const gchar *class_name);
GDK_DEPRECATED_IN_3_14
GList * gtk_style_context_list_regions (GtkStyleContext *context);
GDK_DEPRECATED_IN_3_14
void gtk_style_context_add_region (GtkStyleContext *context,
const gchar *region_name,
GtkRegionFlags flags);
GDK_DEPRECATED_IN_3_14
void gtk_style_context_remove_region (GtkStyleContext *context,
const gchar *region_name);
GDK_DEPRECATED_IN_3_14
gboolean gtk_style_context_has_region (GtkStyleContext *context,
const gchar *region_name,
GtkRegionFlags *flags_return);
GDK_AVAILABLE_IN_ALL
void gtk_style_context_get_style_property (GtkStyleContext *context,
const gchar *property_name,
......
......@@ -292,7 +292,6 @@ gtk_widget_path_to_string (const GtkWidgetPath *path)
GtkPathElement *elem;
GtkStateFlags state;
const GQuark *classes;
GList *list, *regions;
elem = &g_array_index (path->elems, GtkPathElement, i);
......@@ -339,34 +338,6 @@ gtk_widget_path_to_string (const GtkWidgetPath *path)
g_string_append_c (string, '.');
g_string_append (string, g_quark_to_string (classes[j]));
}
regions = gtk_css_node_declaration_list_regions (elem->decl);
for (list = regions; list; list = list->next)
{
static const char *flag_names[] = {
"even",
"odd",
"first",
"last",
"only",
"sorted"
};
GtkRegionFlags flags;
GQuark region = GPOINTER_TO_UINT (regions->data);
gtk_css_node_declaration_has_region (elem->decl, region, &flags);
g_string_append_c (string, ' ');
g_string_append (string, g_quark_to_string (region));
for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
{
if (flags & (1 << j))
{
g_string_append_c (string, ':');
g_string_append (string, flag_names[j]);
}
}
}
g_list_free (regions);
}
return g_string_free (string, FALSE);
......@@ -1026,232 +997,6 @@ gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
return gtk_widget_path_iter_has_qclass (path, pos, qname);
}
/**
* gtk_widget_path_iter_add_region:
* @path: a #GtkWidgetPath
* @pos: position to modify, -1 for the path head
* @name: region name
* @flags: flags affecting the region
*
* Adds the region @name to the widget at position @pos in
* the hierarchy defined in @path. See
* gtk_style_context_add_region().
*
* Region names must only contain lowercase letters
* and “-”, starting always with a lowercase letter.
*
* Since: 3.0
*
* Deprecated: 3.14: The use of regions is deprecated.
**/
void
gtk_widget_path_iter_add_region (GtkWidgetPath *path,
gint pos,
const gchar *name,
GtkRegionFlags flags)
{
GtkPathElement *elem;
GQuark qname;
gtk_internal_return_if_fail (path != NULL);
gtk_internal_return_if_fail (path->elems->len != 0);
gtk_internal_return_if_fail (name != NULL);
gtk_internal_return_if_fail (_gtk_style_context_check_region_name (name));
if (pos < 0 || pos >= path->elems->len)
pos = path->elems->len - 1;
elem = &g_array_index (path->elems, GtkPathElement, pos);
qname = g_quark_from_string (name);
gtk_css_node_declaration_add_region (&elem->decl, qname, flags);
}
/**
* gtk_widget_path_iter_remove_region:
* @path: a #GtkWidgetPath
* @pos: position to modify, -1 for the path head
* @name: region name
*
* Removes the region @name from the widget at position @pos in
* the hierarchy defined in @path.
*
* Since: 3.0
*
* Deprecated: 3.14: The use of regions is deprecated.
**/
void
gtk_widget_path_iter_remove_region (GtkWidgetPath *path,