Compare commits
7 Commits
stop-blink
...
otte/for-m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6b0a34a04 | ||
|
|
05ca59bfcf | ||
|
|
e44e752c0d | ||
|
|
ff677c3054 | ||
|
|
d0066e76d7 | ||
|
|
c9fa3d2e3b | ||
|
|
96ffd6a923 |
@@ -173,7 +173,6 @@
|
||||
<file>fishbowl.c</file>
|
||||
<file>fixed.c</file>
|
||||
<file>flowbox.c</file>
|
||||
<file>foreigndrawing.c</file>
|
||||
<file>font_features.c</file>
|
||||
<file>fontplane.c</file>
|
||||
<file>fontrendering.c</file>
|
||||
|
||||
@@ -1,984 +0,0 @@
|
||||
/* Foreign drawing
|
||||
*
|
||||
* Many applications can't use GTK widgets, for a variety of reasons,
|
||||
* but still want their user interface to appear integrated with the
|
||||
* rest of the desktop, and follow GTK themes. This demo shows how to
|
||||
* use GtkStyleContext and the gtk_render_ APIs to achieve this.
|
||||
*
|
||||
* Note that this is a very simple, non-interactive example.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
append_element (GtkWidgetPath *path,
|
||||
const char *selector)
|
||||
{
|
||||
static const struct {
|
||||
const char *name;
|
||||
GtkStateFlags state_flag;
|
||||
} pseudo_classes[] = {
|
||||
{ "active", GTK_STATE_FLAG_ACTIVE },
|
||||
{ "hover", GTK_STATE_FLAG_PRELIGHT },
|
||||
{ "selected", GTK_STATE_FLAG_SELECTED },
|
||||
{ "disabled", GTK_STATE_FLAG_INSENSITIVE },
|
||||
{ "indeterminate", GTK_STATE_FLAG_INCONSISTENT },
|
||||
{ "focus", GTK_STATE_FLAG_FOCUSED },
|
||||
{ "backdrop", GTK_STATE_FLAG_BACKDROP },
|
||||
{ "dir(ltr)", GTK_STATE_FLAG_DIR_LTR },
|
||||
{ "dir(rtl)", GTK_STATE_FLAG_DIR_RTL },
|
||||
{ "link", GTK_STATE_FLAG_LINK },
|
||||
{ "visited", GTK_STATE_FLAG_VISITED },
|
||||
{ "checked", GTK_STATE_FLAG_CHECKED },
|
||||
{ "drop(active)", GTK_STATE_FLAG_DROP_ACTIVE }
|
||||
};
|
||||
const char *next;
|
||||
char *name;
|
||||
char type;
|
||||
guint i;
|
||||
|
||||
next = strpbrk (selector, "#.:");
|
||||
if (next == NULL)
|
||||
next = selector + strlen (selector);
|
||||
|
||||
name = g_strndup (selector, next - selector);
|
||||
if (g_ascii_isupper (selector[0]))
|
||||
{
|
||||
GType gtype;
|
||||
gtype = g_type_from_name (name);
|
||||
if (gtype == G_TYPE_INVALID)
|
||||
{
|
||||
g_critical ("Unknown type name `%s'", name);
|
||||
g_free (name);
|
||||
return;
|
||||
}
|
||||
gtk_widget_path_append_type (path, gtype);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Omit type, we're using name */
|
||||
gtk_widget_path_append_type (path, G_TYPE_NONE);
|
||||
gtk_widget_path_iter_set_object_name (path, -1, name);
|
||||
}
|
||||
g_free (name);
|
||||
|
||||
while (*next != '\0')
|
||||
{
|
||||
type = *next;
|
||||
selector = next + 1;
|
||||
next = strpbrk (selector, "#.:");
|
||||
if (next == NULL)
|
||||
next = selector + strlen (selector);
|
||||
name = g_strndup (selector, next - selector);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case '#':
|
||||
gtk_widget_path_iter_set_name (path, -1, name);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
gtk_widget_path_iter_add_class (path, -1, name);
|
||||
break;
|
||||
|
||||
case ':':
|
||||
for (i = 0; i < G_N_ELEMENTS (pseudo_classes); i++)
|
||||
{
|
||||
if (g_str_equal (pseudo_classes[i].name, name))
|
||||
{
|
||||
gtk_widget_path_iter_set_state (path,
|
||||
-1,
|
||||
gtk_widget_path_iter_get_state (path, -1)
|
||||
| pseudo_classes[i].state_flag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == G_N_ELEMENTS (pseudo_classes))
|
||||
g_critical ("Unknown pseudo-class :%s", name);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
}
|
||||
}
|
||||
|
||||
static GtkStyleContext *
|
||||
create_context_for_path (GtkWidgetPath *path,
|
||||
GtkStyleContext *parent)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
|
||||
context = gtk_style_context_new ();
|
||||
gtk_style_context_set_path (context, path);
|
||||
gtk_style_context_set_parent (context, parent);
|
||||
/* Unfortunately, we have to explicitly set the state again here
|
||||
* for it to take effect
|
||||
*/
|
||||
gtk_style_context_set_state (context, gtk_widget_path_iter_get_state (path, -1));
|
||||
gtk_widget_path_unref (path);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static GtkStyleContext *
|
||||
get_style (GtkStyleContext *parent,
|
||||
const char *selector)
|
||||
{
|
||||
GtkWidgetPath *path;
|
||||
|
||||
if (parent)
|
||||
path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
|
||||
else
|
||||
path = gtk_widget_path_new ();
|
||||
|
||||
append_element (path, selector);
|
||||
|
||||
return create_context_for_path (path, parent);
|
||||
}
|
||||
|
||||
static GtkStyleContext *
|
||||
get_style_with_siblings (GtkStyleContext *parent,
|
||||
const char *selector,
|
||||
const char **siblings,
|
||||
gint position)
|
||||
{
|
||||
GtkWidgetPath *path, *siblings_path;
|
||||
guint i;
|
||||
|
||||
if (parent)
|
||||
path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
|
||||
else
|
||||
path = gtk_widget_path_new ();
|
||||
|
||||
siblings_path = gtk_widget_path_new ();
|
||||
for (i = 0; siblings[i]; i++)
|
||||
append_element (siblings_path, siblings[i]);
|
||||
|
||||
gtk_widget_path_append_with_siblings (path, siblings_path, position);
|
||||
gtk_widget_path_unref (siblings_path);
|
||||
|
||||
return create_context_for_path (path, parent);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_style_common (GtkStyleContext *context,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint height,
|
||||
gint *contents_x,
|
||||
gint *contents_y,
|
||||
gint *contents_width,
|
||||
gint *contents_height)
|
||||
{
|
||||
GtkBorder margin, border, padding;
|
||||
int min_width, min_height;
|
||||
|
||||
gtk_style_context_get_margin (context, &margin);
|
||||
gtk_style_context_get_border (context, &border);
|
||||
gtk_style_context_get_padding (context, &padding);
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"min-width", &min_width,
|
||||
"min-height", &min_height,
|
||||
NULL);
|
||||
x += margin.left;
|
||||
y += margin.top;
|
||||
width -= margin.left + margin.right;
|
||||
height -= margin.top + margin.bottom;
|
||||
|
||||
width = MAX (width, min_width);
|
||||
height = MAX (height, min_height);
|
||||
|
||||
gtk_render_background (context, cr, x, y, width, height);
|
||||
gtk_render_frame (context, cr, x, y, width, height);
|
||||
|
||||
if (contents_x)
|
||||
*contents_x = x + border.left + padding.left;
|
||||
if (contents_y)
|
||||
*contents_y = y + border.top + padding.top;
|
||||
if (contents_width)
|
||||
*contents_width = width - border.left - border.right - padding.left - padding.right;
|
||||
if (contents_height)
|
||||
*contents_height = height - border.top - border.bottom - padding.top - padding.bottom;
|
||||
}
|
||||
|
||||
static void
|
||||
query_size (GtkStyleContext *context,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GtkBorder margin, border, padding;
|
||||
int min_width, min_height;
|
||||
|
||||
gtk_style_context_get_margin (context, &margin);
|
||||
gtk_style_context_get_border (context, &border);
|
||||
gtk_style_context_get_padding (context, &padding);
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"min-width", &min_width,
|
||||
"min-height", &min_height,
|
||||
NULL);
|
||||
|
||||
min_width += margin.left + margin.right + border.left + border.right + padding.left + padding.right;
|
||||
min_height += margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom;
|
||||
|
||||
if (width)
|
||||
*width = MAX (*width, min_width);
|
||||
if (height)
|
||||
*height = MAX (*height, min_height);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_menu (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *menu_context;
|
||||
GtkStyleContext *menuitem_context;
|
||||
GtkStyleContext *hovermenuitem_context;
|
||||
GtkStyleContext *hoveredarrowmenuitem_context;
|
||||
GtkStyleContext *arrowmenuitem_context;
|
||||
GtkStyleContext *checkmenuitem_context;
|
||||
GtkStyleContext *disabledarrowmenuitem_context;
|
||||
GtkStyleContext *disabledcheckmenuitem_context;
|
||||
GtkStyleContext *radiomenuitem_context;
|
||||
GtkStyleContext *disablemenuitem_context;
|
||||
GtkStyleContext *disabledradiomenuitem_context;
|
||||
GtkStyleContext *separatormenuitem_context;
|
||||
gint menuitem1_height, menuitem2_height, menuitem3_height, menuitem4_height, menuitem5_height;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
gint menu_x, menu_y, menu_width, menu_height;
|
||||
gint arrow_width, arrow_height, arrow_size;
|
||||
gint toggle_x, toggle_y, toggle_width, toggle_height;
|
||||
|
||||
/* This information is taken from the GtkMenu docs, see "CSS nodes" */
|
||||
menu_context = get_style (NULL, "menu");
|
||||
hovermenuitem_context = get_style (menu_context, "menuitem:hover");
|
||||
hoveredarrowmenuitem_context = get_style (hovermenuitem_context, "arrow.right:dir(ltr)");
|
||||
menuitem_context = get_style (menu_context, "menuitem");
|
||||
arrowmenuitem_context = get_style (menuitem_context, "arrow:dir(rtl)");
|
||||
disablemenuitem_context = get_style (menu_context, "menuitem:disabled");
|
||||
disabledarrowmenuitem_context = get_style (disablemenuitem_context, "arrow:dir(rtl)");
|
||||
checkmenuitem_context = get_style (menuitem_context, "check:checked");
|
||||
disabledcheckmenuitem_context = get_style (disablemenuitem_context, "check");
|
||||
separatormenuitem_context = get_style (menu_context, "separator:disabled");
|
||||
radiomenuitem_context = get_style (menuitem_context, "radio:checked");
|
||||
disabledradiomenuitem_context = get_style (disablemenuitem_context, "radio");
|
||||
|
||||
*height = 0;
|
||||
query_size (menu_context, NULL, height);
|
||||
menuitem1_height = 0;
|
||||
query_size (hovermenuitem_context, NULL, &menuitem1_height);
|
||||
query_size (hoveredarrowmenuitem_context, NULL, &menuitem1_height);
|
||||
*height += menuitem1_height;
|
||||
menuitem2_height = 0;
|
||||
query_size (menu_context, NULL, &menuitem5_height);
|
||||
query_size (menuitem_context, NULL, &menuitem2_height);
|
||||
query_size (arrowmenuitem_context, NULL, &menuitem2_height);
|
||||
query_size (disabledarrowmenuitem_context, NULL, &menuitem2_height);
|
||||
*height += menuitem2_height;
|
||||
menuitem3_height = 0;
|
||||
query_size (menu_context, NULL, &menuitem5_height);
|
||||
query_size (menuitem_context, NULL, &menuitem3_height);
|
||||
query_size (checkmenuitem_context, NULL, &menuitem3_height);
|
||||
query_size (disabledcheckmenuitem_context, NULL, &menuitem3_height);
|
||||
*height += menuitem3_height;
|
||||
menuitem4_height = 0;
|
||||
query_size (menu_context, NULL, &menuitem5_height);
|
||||
query_size (separatormenuitem_context, NULL, &menuitem4_height);
|
||||
*height += menuitem4_height;
|
||||
menuitem5_height = 0;
|
||||
query_size (menu_context, NULL, &menuitem5_height);
|
||||
query_size (menuitem_context, NULL, &menuitem5_height);
|
||||
query_size (radiomenuitem_context, NULL, &menuitem5_height);
|
||||
query_size (disabledradiomenuitem_context, NULL, &menuitem5_height);
|
||||
*height += menuitem5_height;
|
||||
|
||||
draw_style_common (menu_context, cr, x, y, width, *height,
|
||||
&menu_x, &menu_y, &menu_width, &menu_height);
|
||||
|
||||
/* Hovered with right arrow */
|
||||
gtk_style_context_get (hoveredarrowmenuitem_context,
|
||||
"min-width", &arrow_width, "min-height", &arrow_height, NULL);
|
||||
arrow_size = MIN (arrow_width, arrow_height);
|
||||
draw_style_common (hovermenuitem_context, cr, menu_x, menu_y, menu_width, menuitem1_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_render_arrow (hoveredarrowmenuitem_context, cr, G_PI / 2,
|
||||
contents_x + contents_width - arrow_size,
|
||||
contents_y + (contents_height - arrow_size) / 2, arrow_size);
|
||||
|
||||
/* Left arrow sensitive, and right arrow insensitive */
|
||||
draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height, menu_width, menuitem2_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_style_context_get (arrowmenuitem_context,
|
||||
"min-width", &arrow_width, "min-height", &arrow_height, NULL);
|
||||
arrow_size = MIN (arrow_width, arrow_height);
|
||||
gtk_render_arrow (arrowmenuitem_context, cr, G_PI / 2,
|
||||
contents_x,
|
||||
contents_y + (contents_height - arrow_size) / 2, arrow_size);
|
||||
gtk_style_context_get (disabledarrowmenuitem_context,
|
||||
"min-width", &arrow_width, "min-height", &arrow_height, NULL);
|
||||
arrow_size = MIN (arrow_width, arrow_height);
|
||||
gtk_render_arrow (disabledarrowmenuitem_context, cr, G_PI / 2,
|
||||
contents_x + contents_width - arrow_size,
|
||||
contents_y + (contents_height - arrow_size) / 2, arrow_size);
|
||||
|
||||
|
||||
/* Left check enabled, sensitive, and right check unchecked, insensitive */
|
||||
draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height, menu_width, menuitem3_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_style_context_get (checkmenuitem_context,
|
||||
"min-width", &toggle_width, "min-height", &toggle_height, NULL);
|
||||
draw_style_common (checkmenuitem_context, cr,
|
||||
contents_x,
|
||||
contents_y,
|
||||
toggle_width, toggle_height,
|
||||
&toggle_x, &toggle_y, &toggle_width, &toggle_height);
|
||||
gtk_render_check (checkmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height);
|
||||
gtk_style_context_get (disabledcheckmenuitem_context,
|
||||
"min-width", &toggle_width, "min-height", &toggle_height, NULL);
|
||||
draw_style_common (disabledcheckmenuitem_context, cr,
|
||||
contents_x + contents_width - toggle_width,
|
||||
contents_y,
|
||||
toggle_width, toggle_height,
|
||||
&toggle_x, &toggle_y, &toggle_width, &toggle_height);
|
||||
gtk_render_check (disabledcheckmenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height);
|
||||
|
||||
/* Separator */
|
||||
draw_style_common (separatormenuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height,
|
||||
menu_width, menuitem4_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
/* Left check enabled, sensitive, and right check unchecked, insensitive */
|
||||
draw_style_common (menuitem_context, cr, menu_x, menu_y + menuitem1_height + menuitem2_height + menuitem3_height + menuitem4_height,
|
||||
menu_width, menuitem5_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_style_context_get (radiomenuitem_context,
|
||||
"min-width", &toggle_width, "min-height", &toggle_height, NULL);
|
||||
draw_style_common (radiomenuitem_context, cr,
|
||||
contents_x,
|
||||
contents_y,
|
||||
toggle_width, toggle_height,
|
||||
&toggle_x, &toggle_y, &toggle_width, &toggle_height);
|
||||
gtk_render_check (radiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height);
|
||||
gtk_style_context_get (disabledradiomenuitem_context,
|
||||
"min-width", &toggle_width, "min-height", &toggle_height, NULL);
|
||||
draw_style_common (disabledradiomenuitem_context, cr,
|
||||
contents_x + contents_width - toggle_width,
|
||||
contents_y,
|
||||
toggle_width, toggle_height,
|
||||
&toggle_x, &toggle_y, &toggle_width, &toggle_height);
|
||||
gtk_render_check (disabledradiomenuitem_context, cr, toggle_x, toggle_y, toggle_width, toggle_height);
|
||||
|
||||
g_object_unref (menu_context);
|
||||
g_object_unref (menuitem_context);
|
||||
g_object_unref (hovermenuitem_context);
|
||||
g_object_unref (hoveredarrowmenuitem_context);
|
||||
g_object_unref (arrowmenuitem_context);
|
||||
g_object_unref (checkmenuitem_context);
|
||||
g_object_unref (disabledarrowmenuitem_context);
|
||||
g_object_unref (disabledcheckmenuitem_context);
|
||||
g_object_unref (radiomenuitem_context);
|
||||
g_object_unref (disablemenuitem_context);
|
||||
g_object_unref (disabledradiomenuitem_context);
|
||||
g_object_unref (separatormenuitem_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_menubar (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *frame_context;
|
||||
GtkStyleContext *border_context;
|
||||
GtkStyleContext *menubar_context;
|
||||
GtkStyleContext *hovered_menuitem_context;
|
||||
GtkStyleContext *menuitem_context;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
gint item_width;
|
||||
|
||||
/* Menubar background is the same color as our base background, so use a frame */
|
||||
frame_context = get_style (NULL, "frame");
|
||||
border_context = get_style (frame_context, "border");
|
||||
|
||||
/* This information is taken from the GtkPopoverMenuBar docs, see "CSS nodes" */
|
||||
menubar_context = get_style (NULL, "menubar");
|
||||
hovered_menuitem_context = get_style (menubar_context, "menuitem:hover");
|
||||
menuitem_context = get_style (menubar_context, "menuitem");
|
||||
|
||||
*height = 0;
|
||||
query_size (frame_context, NULL, height);
|
||||
query_size (border_context, NULL, height);
|
||||
query_size (menubar_context, NULL, height);
|
||||
query_size (hovered_menuitem_context, NULL, height);
|
||||
query_size (menuitem_context, NULL, height);
|
||||
|
||||
draw_style_common (frame_context, cr, x, y, width, *height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
draw_style_common (border_context, cr, x, y, width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
draw_style_common (menubar_context, cr, contents_x, contents_y, contents_width, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
item_width = contents_width / 3;
|
||||
draw_style_common (hovered_menuitem_context, cr, contents_x, contents_y, item_width, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
draw_style_common (menuitem_context, cr, contents_x + item_width * 2, contents_y, item_width, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (menuitem_context);
|
||||
g_object_unref (hovered_menuitem_context);
|
||||
g_object_unref (menubar_context);
|
||||
g_object_unref (border_context);
|
||||
g_object_unref (frame_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_notebook (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
GtkStyleContext *notebook_context;
|
||||
GtkStyleContext *header_context;
|
||||
GtkStyleContext *tabs_context;
|
||||
GtkStyleContext *tab1_context, *tab2_context;
|
||||
GtkStyleContext *stack_context;
|
||||
gint header_height;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
|
||||
/* This information is taken from the GtkNotebook docs, see "CSS nodes" */
|
||||
notebook_context = get_style (NULL, "notebook.frame");
|
||||
header_context = get_style (notebook_context, "header.top");
|
||||
tabs_context = get_style (header_context, "tabs");
|
||||
tab1_context = get_style (tabs_context, "tab:checked");
|
||||
tab2_context = get_style (tabs_context, "tab:hover");
|
||||
stack_context = get_style (notebook_context, "stack");
|
||||
|
||||
header_height = 0;
|
||||
query_size (notebook_context, NULL, &header_height);
|
||||
query_size (header_context, NULL, &header_height);
|
||||
query_size (tabs_context, NULL, &header_height);
|
||||
query_size (tab1_context, NULL, &header_height);
|
||||
query_size (tab2_context, NULL, &header_height);
|
||||
|
||||
draw_style_common (notebook_context, cr, x, y, width, height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (header_context, cr, x, y, width, header_height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (tabs_context, cr, x, y, width, header_height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (tab1_context, cr, x, y, width / 2, header_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
draw_style_common (tab2_context, cr, x + width / 2, y, width / 2, header_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
draw_style_common (stack_context, cr, x, y + header_height, width,height - header_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (stack_context);
|
||||
g_object_unref (tabs_context);
|
||||
g_object_unref (tab1_context);
|
||||
g_object_unref (tab2_context);
|
||||
g_object_unref (header_context);
|
||||
g_object_unref (notebook_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_horizontal_scrollbar (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint position,
|
||||
GtkStateFlags state,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *scrollbar_context;
|
||||
GtkStyleContext *contents_context;
|
||||
GtkStyleContext *trough_context;
|
||||
GtkStyleContext *slider_context;
|
||||
gint slider_width;
|
||||
|
||||
/* This information is taken from the GtkScrollbar docs, see "CSS nodes" */
|
||||
scrollbar_context = get_style (NULL, "scrollbar.horizontal.bottom");
|
||||
contents_context = get_style (scrollbar_context, "contents");
|
||||
trough_context = get_style (contents_context, "trough");
|
||||
slider_context = get_style (trough_context, "slider");
|
||||
|
||||
gtk_style_context_set_state (scrollbar_context, state);
|
||||
gtk_style_context_set_state (contents_context, state);
|
||||
gtk_style_context_set_state (trough_context, state);
|
||||
gtk_style_context_set_state (slider_context, state);
|
||||
|
||||
*height = 0;
|
||||
query_size (scrollbar_context, NULL, height);
|
||||
query_size (contents_context, NULL, height);
|
||||
query_size (trough_context, NULL, height);
|
||||
query_size (slider_context, NULL, height);
|
||||
|
||||
gtk_style_context_get (slider_context,
|
||||
"min-width", &slider_width, NULL);
|
||||
|
||||
draw_style_common (scrollbar_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (contents_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (trough_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (slider_context, cr, x + position, y, slider_width, *height, NULL, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (slider_context);
|
||||
g_object_unref (trough_context);
|
||||
g_object_unref (contents_context);
|
||||
g_object_unref (scrollbar_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_text (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint height,
|
||||
const gchar *text,
|
||||
GtkStateFlags state)
|
||||
{
|
||||
GtkStyleContext *label_context;
|
||||
GtkStyleContext *selection_context;
|
||||
GtkStyleContext *context;
|
||||
PangoLayout *layout;
|
||||
|
||||
/* This information is taken from the GtkLabel docs, see "CSS nodes" */
|
||||
label_context = get_style (NULL, "label.view");
|
||||
selection_context = get_style (label_context, "selection");
|
||||
|
||||
gtk_style_context_set_state (label_context, state);
|
||||
|
||||
if (state & GTK_STATE_FLAG_SELECTED)
|
||||
context = selection_context;
|
||||
else
|
||||
context = label_context;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, text);
|
||||
|
||||
gtk_render_background (context, cr, x, y, width, height);
|
||||
gtk_render_frame (context, cr, x, y, width, height);
|
||||
gtk_render_layout (context, cr, x, y, layout);
|
||||
|
||||
g_object_unref (layout);
|
||||
|
||||
g_object_unref (selection_context);
|
||||
g_object_unref (label_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_check (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
GtkStateFlags state,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *button_context;
|
||||
GtkStyleContext *check_context;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
|
||||
/* This information is taken from the GtkCheckButton docs, see "CSS nodes" */
|
||||
button_context = get_style (NULL, "checkbutton");
|
||||
check_context = get_style (button_context, "check");
|
||||
|
||||
gtk_style_context_set_state (check_context, state);
|
||||
|
||||
*width = *height = 0;
|
||||
query_size (button_context, width, height);
|
||||
query_size (check_context, width, height);
|
||||
|
||||
draw_style_common (button_context, cr, x, y, *width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (check_context, cr, x, y, *width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_render_check (check_context, cr, contents_x, contents_y, contents_width, contents_height);
|
||||
|
||||
g_object_unref (check_context);
|
||||
g_object_unref (button_context);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
draw_radio (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
GtkStateFlags state,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *button_context;
|
||||
GtkStyleContext *check_context;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
|
||||
/* This information is taken from the GtkRadioButton docs, see "CSS nodes" */
|
||||
button_context = get_style (NULL, "radiobutton");
|
||||
check_context = get_style (button_context, "radio");
|
||||
|
||||
gtk_style_context_set_state (check_context, state);
|
||||
|
||||
*width = *height = 0;
|
||||
query_size (button_context, width, height);
|
||||
query_size (check_context, width, height);
|
||||
|
||||
draw_style_common (button_context, cr, x, y, *width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (check_context, cr, x, y, *width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_render_check (check_context, cr, contents_x, contents_y, contents_width, contents_height);
|
||||
|
||||
g_object_unref (check_context);
|
||||
g_object_unref (button_context);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
draw_progress (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint position,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *bar_context;
|
||||
GtkStyleContext *trough_context;
|
||||
GtkStyleContext *progress_context;
|
||||
|
||||
/* This information is taken from the GtkProgressBar docs, see "CSS nodes" */
|
||||
bar_context = get_style (NULL, "progressbar.horizontal");
|
||||
trough_context = get_style (bar_context, "trough");
|
||||
progress_context = get_style (trough_context, "progress.left");
|
||||
|
||||
*height = 0;
|
||||
query_size (bar_context, NULL, height);
|
||||
query_size (trough_context, NULL, height);
|
||||
query_size (progress_context, NULL, height);
|
||||
|
||||
draw_style_common (bar_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (trough_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (progress_context, cr, x, y, position, *height, NULL, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (progress_context);
|
||||
g_object_unref (trough_context);
|
||||
g_object_unref (bar_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_scale (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint position,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *scale_context;
|
||||
GtkStyleContext *contents_context;
|
||||
GtkStyleContext *trough_context;
|
||||
GtkStyleContext *slider_context;
|
||||
GtkStyleContext *highlight_context;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
gint trough_height, slider_height;
|
||||
|
||||
scale_context = get_style (NULL, "scale.horizontal");
|
||||
contents_context = get_style (scale_context, "contents");
|
||||
trough_context = get_style (contents_context, "trough");
|
||||
slider_context = get_style (trough_context, "slider");
|
||||
highlight_context = get_style (trough_context, "highlight.top");
|
||||
|
||||
*height = 0;
|
||||
query_size (scale_context, NULL, height);
|
||||
query_size (contents_context, NULL, height);
|
||||
query_size (trough_context, NULL, height);
|
||||
query_size (slider_context, NULL, height);
|
||||
query_size (highlight_context, NULL, height);
|
||||
|
||||
draw_style_common (scale_context, cr, x, y, width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
draw_style_common (contents_context, cr, contents_x, contents_y, contents_width, contents_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
/* Scale trough defines its size querying slider and highlight */
|
||||
trough_height = 0;
|
||||
query_size (trough_context, NULL, &trough_height);
|
||||
slider_height = 0;
|
||||
query_size (slider_context, NULL, &slider_height);
|
||||
query_size (highlight_context, NULL, &slider_height);
|
||||
trough_height += slider_height;
|
||||
draw_style_common (trough_context, cr, contents_x, contents_y, contents_width, trough_height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
draw_style_common (highlight_context, cr, contents_x, contents_y,
|
||||
contents_width / 2, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
draw_style_common (slider_context, cr, contents_x + position, contents_y, contents_height, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
g_object_unref (scale_context);
|
||||
g_object_unref (contents_context);
|
||||
g_object_unref (trough_context);
|
||||
g_object_unref (slider_context);
|
||||
g_object_unref (highlight_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_combobox (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gboolean has_entry,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *combo_context;
|
||||
GtkStyleContext *box_context;
|
||||
GtkStyleContext *button_context;
|
||||
GtkStyleContext *button_box_context;
|
||||
GtkStyleContext *entry_context;
|
||||
GtkStyleContext *arrow_context;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
gint button_width;
|
||||
gint arrow_width, arrow_height, arrow_size;
|
||||
|
||||
/* This information is taken from the GtkComboBox docs, see "CSS nodes" */
|
||||
combo_context = get_style (NULL, "combobox:focus");
|
||||
box_context = get_style (combo_context, "box.horizontal.linked");
|
||||
if (has_entry)
|
||||
{
|
||||
const char *siblings[3] = { "entry.combo:focus", "button.combo" , NULL };
|
||||
|
||||
entry_context = get_style_with_siblings (box_context, "entry.combo:focus", siblings, 0);
|
||||
button_context = get_style_with_siblings (box_context, "button.combo", siblings, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *siblings[2] = { "button.combo" , NULL };
|
||||
|
||||
button_context = get_style_with_siblings (box_context, "button.combo", siblings, 0);
|
||||
}
|
||||
button_box_context = get_style (button_context, "box.horizontal");
|
||||
arrow_context = get_style (button_box_context, "arrow");
|
||||
|
||||
*height = 0;
|
||||
query_size (combo_context, NULL, height);
|
||||
query_size (box_context, NULL, height);
|
||||
if (has_entry)
|
||||
query_size (entry_context, NULL, height);
|
||||
query_size (button_context, NULL, height);
|
||||
query_size (button_box_context, NULL, height);
|
||||
query_size (arrow_context, NULL, height);
|
||||
|
||||
gtk_style_context_get (arrow_context,
|
||||
"min-width", &arrow_width, "min-height", &arrow_height, NULL);
|
||||
arrow_size = MIN (arrow_width, arrow_height);
|
||||
|
||||
draw_style_common (combo_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (box_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
if (has_entry)
|
||||
{
|
||||
button_width = *height;
|
||||
draw_style_common (entry_context, cr, x, y, width - button_width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (button_context, cr, x + width - button_width, y, button_width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
button_width = width;
|
||||
draw_style_common (button_context, cr, x, y, width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
}
|
||||
|
||||
draw_style_common (button_box_context, cr, contents_x, contents_y, contents_width, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
draw_style_common (arrow_context, cr, contents_x, contents_y, contents_width, contents_height,
|
||||
NULL, NULL, NULL, NULL);
|
||||
gtk_render_arrow (arrow_context, cr, G_PI / 2,
|
||||
contents_x + contents_width - arrow_size,
|
||||
contents_y + (contents_height - arrow_size) / 2, arrow_size);
|
||||
|
||||
g_object_unref (arrow_context);
|
||||
if (has_entry)
|
||||
g_object_unref (entry_context);
|
||||
g_object_unref (button_context);
|
||||
g_object_unref (combo_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_spinbutton (GtkWidget *widget,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y,
|
||||
gint width,
|
||||
gint *height)
|
||||
{
|
||||
GtkStyleContext *spin_context;
|
||||
GtkStyleContext *entry_context;
|
||||
GtkStyleContext *up_context;
|
||||
GtkStyleContext *down_context;
|
||||
GtkIconTheme *icon_theme;
|
||||
GtkIconInfo *icon_info;
|
||||
GdkTexture *texture;
|
||||
gint icon_width, icon_height, icon_size;
|
||||
gint button_width;
|
||||
gint contents_x, contents_y, contents_width, contents_height;
|
||||
|
||||
/* This information is taken from the GtkSpinButton docs, see "CSS nodes" */
|
||||
spin_context = get_style (NULL, "spinbutton.horizontal:focus");
|
||||
entry_context = get_style (spin_context, "entry:focus");
|
||||
up_context = get_style (spin_context, "button.up:focus:active");
|
||||
down_context = get_style (spin_context, "button.down:focus");
|
||||
|
||||
*height = 0;
|
||||
query_size (spin_context, NULL, height);
|
||||
query_size (entry_context, NULL, height);
|
||||
query_size (up_context, NULL, height);
|
||||
query_size (down_context, NULL, height);
|
||||
button_width = *height;
|
||||
|
||||
draw_style_common (spin_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
draw_style_common (entry_context, cr, x, y, width, *height, NULL, NULL, NULL, NULL);
|
||||
|
||||
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
|
||||
|
||||
gtk_style_context_get (up_context,
|
||||
"min-width", &icon_width, "min-height", &icon_height, NULL);
|
||||
icon_size = MIN (icon_width, icon_height);
|
||||
icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-add-symbolic", icon_size, 0);
|
||||
texture = GDK_TEXTURE (gtk_icon_info_load_symbolic_for_context (icon_info, up_context, NULL, NULL));
|
||||
g_object_unref (icon_info);
|
||||
draw_style_common (up_context, cr, x + width - button_width, y, button_width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_render_icon (up_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2);
|
||||
g_object_unref (texture);
|
||||
|
||||
gtk_style_context_get (down_context,
|
||||
"min-width", &icon_width, "min-height", &icon_height, NULL);
|
||||
icon_size = MIN (icon_width, icon_height);
|
||||
icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-remove-symbolic", icon_size, 0);
|
||||
texture = GDK_TEXTURE (gtk_icon_info_load_symbolic_for_context (icon_info, down_context, NULL, NULL));
|
||||
g_object_unref (icon_info);
|
||||
draw_style_common (down_context, cr, x + width - 2 * button_width, y, button_width, *height,
|
||||
&contents_x, &contents_y, &contents_width, &contents_height);
|
||||
gtk_render_icon (down_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2);
|
||||
g_object_unref (texture);
|
||||
|
||||
g_object_unref (down_context);
|
||||
g_object_unref (up_context);
|
||||
g_object_unref (entry_context);
|
||||
g_object_unref (spin_context);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_func (GtkDrawingArea *da,
|
||||
cairo_t *cr,
|
||||
int width,
|
||||
int height,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (da);
|
||||
gint panewidth;
|
||||
gint x, y;
|
||||
|
||||
panewidth = width / 2;
|
||||
|
||||
cairo_rectangle (cr, 0, 0, width, height);
|
||||
cairo_set_source_rgb (cr, 0.9, 0.9, 0.9);
|
||||
cairo_fill (cr);
|
||||
|
||||
x = y = 10;
|
||||
draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 30, GTK_STATE_FLAG_NORMAL, &height);
|
||||
y += height + 8;
|
||||
draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 40, GTK_STATE_FLAG_PRELIGHT, &height);
|
||||
y += height + 8;
|
||||
draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 50, GTK_STATE_FLAG_ACTIVE|GTK_STATE_FLAG_PRELIGHT, &height);
|
||||
|
||||
y += height + 8;
|
||||
draw_text (widget, cr, x, y, panewidth - 20, 20, "Not selected", GTK_STATE_FLAG_NORMAL);
|
||||
y += 20 + 10;
|
||||
draw_text (widget, cr, x, y, panewidth - 20, 20, "Selected", GTK_STATE_FLAG_SELECTED);
|
||||
|
||||
x = 10;
|
||||
y += 20 + 10;
|
||||
draw_check (widget, cr, x, y, GTK_STATE_FLAG_NORMAL, &width, &height);
|
||||
x += width + 10;
|
||||
draw_check (widget, cr, x, y, GTK_STATE_FLAG_CHECKED, &width, &height);
|
||||
x += width + 10;
|
||||
draw_radio (widget, cr, x, y, GTK_STATE_FLAG_NORMAL, &width, &height);
|
||||
x += width + 10;
|
||||
draw_radio (widget, cr, x, y, GTK_STATE_FLAG_CHECKED, &width, &height);
|
||||
x = 10;
|
||||
|
||||
y += height + 10;
|
||||
draw_progress (widget, cr, x, y, panewidth - 20, 50, &height);
|
||||
|
||||
y += height + 10;
|
||||
draw_scale (widget, cr, x, y, panewidth - 20, 75, &height);
|
||||
|
||||
y += height + 20;
|
||||
draw_notebook (widget, cr, x, y, panewidth - 20, 160);
|
||||
|
||||
/* Second column */
|
||||
x += panewidth;
|
||||
y = 10;
|
||||
draw_menu (widget, cr, x, y, panewidth - 20, &height);
|
||||
|
||||
y += height + 10;
|
||||
draw_menubar (widget, cr, x, y, panewidth - 20, &height);
|
||||
|
||||
y += height + 20;
|
||||
draw_spinbutton (widget, cr, x, y, panewidth - 20, &height);
|
||||
|
||||
y += height + 30;
|
||||
draw_combobox (widget, cr, x, y, panewidth - 20, FALSE, &height);
|
||||
|
||||
y += height + 10;
|
||||
draw_combobox (widget, cr, 10 + panewidth, y, panewidth - 20, TRUE, &height);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
do_foreigndrawing (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *box;
|
||||
GtkWidget *da;
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Foreign drawing");
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (do_widget));
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
||||
gtk_container_add (GTK_CONTAINER (window), box);
|
||||
da = gtk_drawing_area_new ();
|
||||
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 400);
|
||||
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 400);
|
||||
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), draw_func, NULL, NULL);
|
||||
gtk_widget_set_hexpand (da, TRUE);
|
||||
gtk_widget_set_vexpand (da, TRUE);
|
||||
gtk_container_add (GTK_CONTAINER (box), da);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show (window);
|
||||
else
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
return window;
|
||||
}
|
||||
@@ -28,7 +28,6 @@ demos = files([
|
||||
'fishbowl.c',
|
||||
'fixed.c',
|
||||
'fontrendering.c',
|
||||
'foreigndrawing.c',
|
||||
'gestures.c',
|
||||
'glarea.c',
|
||||
'headerbar.c',
|
||||
|
||||
@@ -374,7 +374,6 @@
|
||||
<xi:include href="xml/gtkstylecontext.xml" />
|
||||
<xi:include href="xml/gtkcssprovider.xml" />
|
||||
<xi:include href="xml/gtkstyleprovider.xml" />
|
||||
<xi:include href="xml/gtkwidgetpath.xml" />
|
||||
<xi:include href="xml/gtkicontheme.xml" />
|
||||
</part>
|
||||
|
||||
|
||||
@@ -4689,50 +4689,6 @@ GTK_INTERFACE_AGE
|
||||
GTK_CHECK_VERSION
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkwidgetpath</FILE>
|
||||
<TITLE>GtkWidgetPath</TITLE>
|
||||
GtkWidgetPath
|
||||
gtk_widget_path_append_type
|
||||
gtk_widget_path_append_with_siblings
|
||||
gtk_widget_path_append_for_widget
|
||||
gtk_widget_path_copy
|
||||
gtk_widget_path_ref
|
||||
gtk_widget_path_unref
|
||||
gtk_widget_path_free
|
||||
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_clear_classes
|
||||
gtk_widget_path_iter_get_name
|
||||
gtk_widget_path_iter_get_object_name
|
||||
gtk_widget_path_iter_get_object_type
|
||||
gtk_widget_path_iter_get_siblings
|
||||
gtk_widget_path_iter_get_sibling_index
|
||||
gtk_widget_path_iter_get_state
|
||||
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_list_classes
|
||||
gtk_widget_path_iter_remove_class
|
||||
gtk_widget_path_iter_set_name
|
||||
gtk_widget_path_iter_set_object_name
|
||||
gtk_widget_path_iter_set_object_type
|
||||
gtk_widget_path_iter_set_state
|
||||
gtk_widget_path_length
|
||||
gtk_widget_path_new
|
||||
gtk_widget_path_prepend_type
|
||||
gtk_widget_path_to_string
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_WIDGET_PATH
|
||||
|
||||
<SUBSECTION Private>
|
||||
gtk_widget_path_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkstyleprovider</FILE>
|
||||
<TITLE>GtkStyleProvider</TITLE>
|
||||
@@ -4857,7 +4813,6 @@ gtk_style_context_add_provider
|
||||
gtk_style_context_add_provider_for_display
|
||||
gtk_style_context_get
|
||||
gtk_style_context_get_parent
|
||||
gtk_style_context_get_path
|
||||
gtk_style_context_get_property
|
||||
gtk_style_context_get_display
|
||||
gtk_style_context_get_state
|
||||
@@ -4874,7 +4829,6 @@ gtk_style_context_reset_widgets
|
||||
gtk_style_context_restore
|
||||
gtk_style_context_save
|
||||
gtk_style_context_set_parent
|
||||
gtk_style_context_set_path
|
||||
gtk_style_context_add_class
|
||||
gtk_style_context_remove_class
|
||||
gtk_style_context_has_class
|
||||
|
||||
@@ -178,6 +178,5 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTextIter, gtk_text_iter_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreeIter, gtk_tree_iter_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreePath, gtk_tree_path_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreeRowReference, gtk_tree_row_reference_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidgetPath, gtk_widget_path_unref)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -253,7 +253,6 @@
|
||||
#include <gtk/gtkvolumebutton.h>
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkwidgetpaintable.h>
|
||||
#include <gtk/gtkwidgetpath.h>
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gtk/gtkwindowgroup.h>
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtksizerequest.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "a11y/gtkcontaineraccessible.h"
|
||||
|
||||
|
||||
@@ -1,400 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2012 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcssmatcherprivate.h"
|
||||
|
||||
#include "gtkcssnodedeclarationprivate.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
|
||||
void
|
||||
gtk_css_matcher_print (const GtkCssMatcher *matcher,
|
||||
GString *string)
|
||||
{
|
||||
matcher->klass->print (matcher, string);
|
||||
}
|
||||
|
||||
char *
|
||||
gtk_css_matcher_to_string (const GtkCssMatcher *matcher)
|
||||
{
|
||||
GString *string = g_string_new ("");
|
||||
gtk_css_matcher_print (matcher, string);
|
||||
return g_string_free (string, FALSE);
|
||||
}
|
||||
|
||||
/* GTK_CSS_MATCHER_WIDGET_PATH */
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_get_parent (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *child)
|
||||
{
|
||||
if (child->path.index == 0)
|
||||
return FALSE;
|
||||
|
||||
matcher->path.klass = child->path.klass;
|
||||
matcher->path.decl = NULL;
|
||||
matcher->path.path = child->path.path;
|
||||
matcher->path.index = child->path.index - 1;
|
||||
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *next)
|
||||
{
|
||||
if (next->path.sibling_index == 0)
|
||||
return FALSE;
|
||||
|
||||
matcher->path.klass = next->path.klass;
|
||||
matcher->path.decl = NULL;
|
||||
matcher->path.path = next->path.path;
|
||||
matcher->path.index = next->path.index;
|
||||
matcher->path.sibling_index = next->path.sibling_index - 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_has_state (const GtkCssMatcher *matcher,
|
||||
GtkStateFlags state)
|
||||
{
|
||||
GtkStateFlags path_state;
|
||||
|
||||
if (matcher->path.decl)
|
||||
path_state = gtk_css_node_declaration_get_state (matcher->path.decl);
|
||||
else
|
||||
{
|
||||
const GtkWidgetPath *siblings;
|
||||
|
||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
||||
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
|
||||
path_state = gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index);
|
||||
else
|
||||
path_state = gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
|
||||
}
|
||||
|
||||
return (path_state & state) == state;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_has_name (const GtkCssMatcher *matcher,
|
||||
/*interned*/ const char *name)
|
||||
{
|
||||
const GtkWidgetPath *siblings;
|
||||
|
||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
||||
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
|
||||
{
|
||||
const char *path_name = gtk_widget_path_iter_get_object_name (siblings, matcher->path.sibling_index);
|
||||
|
||||
if (path_name == NULL)
|
||||
path_name = g_type_name (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index));
|
||||
|
||||
return path_name == name;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *path_name = gtk_widget_path_iter_get_object_name (matcher->path.path, matcher->path.index);
|
||||
|
||||
if (path_name == NULL)
|
||||
path_name = g_type_name (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index));
|
||||
|
||||
return path_name == name;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_has_class (const GtkCssMatcher *matcher,
|
||||
GQuark class_name)
|
||||
{
|
||||
const GtkWidgetPath *siblings;
|
||||
|
||||
if (matcher->path.decl &&
|
||||
gtk_css_node_declaration_has_class (matcher->path.decl, class_name))
|
||||
return TRUE;
|
||||
|
||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
||||
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
|
||||
return gtk_widget_path_iter_has_qclass (siblings, matcher->path.sibling_index, class_name);
|
||||
else
|
||||
return gtk_widget_path_iter_has_qclass (matcher->path.path, matcher->path.index, class_name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_has_id (const GtkCssMatcher *matcher,
|
||||
const char *id)
|
||||
{
|
||||
const GtkWidgetPath *siblings;
|
||||
|
||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
||||
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
|
||||
return gtk_widget_path_iter_has_name (siblings, matcher->path.sibling_index, id);
|
||||
else
|
||||
return gtk_widget_path_iter_has_name (matcher->path.path, matcher->path.index, id);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
|
||||
gboolean forward,
|
||||
int a,
|
||||
int b)
|
||||
{
|
||||
const GtkWidgetPath *siblings;
|
||||
int x;
|
||||
|
||||
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
|
||||
if (!siblings)
|
||||
return FALSE;
|
||||
|
||||
if (forward)
|
||||
x = matcher->path.sibling_index + 1;
|
||||
else
|
||||
x = gtk_widget_path_length (siblings) - matcher->path.sibling_index;
|
||||
|
||||
x -= b;
|
||||
|
||||
if (a == 0)
|
||||
return x == 0;
|
||||
|
||||
if (x % a)
|
||||
return FALSE;
|
||||
|
||||
return x / a >= 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_matcher_widget_path_print (const GtkCssMatcher *matcher,
|
||||
GString *string)
|
||||
{
|
||||
char *s = gtk_widget_path_to_string (matcher->path.path);
|
||||
g_string_append (string, s);
|
||||
g_free (s);
|
||||
}
|
||||
|
||||
static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
|
||||
GTK_CSS_MATCHER_TYPE_WIDGET_PATH,
|
||||
gtk_css_matcher_widget_path_get_parent,
|
||||
gtk_css_matcher_widget_path_get_previous,
|
||||
gtk_css_matcher_widget_path_has_state,
|
||||
gtk_css_matcher_widget_path_has_name,
|
||||
gtk_css_matcher_widget_path_has_class,
|
||||
gtk_css_matcher_widget_path_has_id,
|
||||
gtk_css_matcher_widget_path_has_position,
|
||||
gtk_css_matcher_widget_path_print
|
||||
};
|
||||
|
||||
gboolean
|
||||
_gtk_css_matcher_init (GtkCssMatcher *matcher,
|
||||
const GtkWidgetPath *path,
|
||||
const GtkCssNodeDeclaration *decl)
|
||||
{
|
||||
if (gtk_widget_path_length (path) == 0)
|
||||
return FALSE;
|
||||
|
||||
matcher->path.klass = >K_CSS_MATCHER_WIDGET_PATH;
|
||||
matcher->path.decl = decl;
|
||||
matcher->path.path = path;
|
||||
matcher->path.index = gtk_widget_path_length (path) - 1;
|
||||
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* GTK_CSS_MATCHER_NODE */
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_get_parent (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *child)
|
||||
{
|
||||
GtkCssNode *node;
|
||||
|
||||
node = gtk_css_node_get_parent (child->node.node);
|
||||
if (node == NULL)
|
||||
return FALSE;
|
||||
|
||||
return gtk_css_node_init_matcher (node, matcher);
|
||||
}
|
||||
|
||||
static GtkCssNode *
|
||||
get_previous_visible_sibling (GtkCssNode *node)
|
||||
{
|
||||
do {
|
||||
node = gtk_css_node_get_previous_sibling (node);
|
||||
} while (node && !gtk_css_node_get_visible (node));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static GtkCssNode *
|
||||
get_next_visible_sibling (GtkCssNode *node)
|
||||
{
|
||||
do {
|
||||
node = gtk_css_node_get_next_sibling (node);
|
||||
} while (node && !gtk_css_node_get_visible (node));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_get_previous (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *next)
|
||||
{
|
||||
GtkCssNode *node;
|
||||
|
||||
node = get_previous_visible_sibling (next->node.node);
|
||||
if (node == NULL)
|
||||
return FALSE;
|
||||
|
||||
return gtk_css_node_init_matcher (node, matcher);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_has_state (const GtkCssMatcher *matcher,
|
||||
GtkStateFlags state)
|
||||
{
|
||||
return (matcher->node.node_state & state) == state;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_has_name (const GtkCssMatcher *matcher,
|
||||
/*interned*/ const char *name)
|
||||
{
|
||||
return matcher->node.node_name == name;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
|
||||
GQuark class_name)
|
||||
{
|
||||
const GQuark *classes = matcher->node.classes;
|
||||
|
||||
switch (matcher->node.n_classes)
|
||||
{
|
||||
case 3:
|
||||
if (classes[2] == class_name)
|
||||
return TRUE;
|
||||
G_GNUC_FALLTHROUGH;
|
||||
|
||||
case 2:
|
||||
if (classes[1] == class_name)
|
||||
return TRUE;
|
||||
G_GNUC_FALLTHROUGH;
|
||||
|
||||
case 1:
|
||||
if (classes[0] == class_name)
|
||||
return TRUE;
|
||||
G_GNUC_FALLTHROUGH;
|
||||
|
||||
case 0:
|
||||
return FALSE;
|
||||
|
||||
default:
|
||||
return gtk_css_node_has_class (matcher->node.node, class_name);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_has_id (const GtkCssMatcher *matcher,
|
||||
const char *id)
|
||||
{
|
||||
/* assume all callers pass an interned string */
|
||||
return matcher->node.node_id == id;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_nth_child (GtkCssNode *node,
|
||||
GtkCssNode *(* prev_node_func) (GtkCssNode *),
|
||||
int a,
|
||||
int b)
|
||||
{
|
||||
int pos, x;
|
||||
|
||||
/* special-case the common "first-child" and "last-child" */
|
||||
if (a == 0)
|
||||
{
|
||||
while (b > 0 && node != NULL)
|
||||
{
|
||||
b--;
|
||||
node = prev_node_func (node);
|
||||
}
|
||||
|
||||
return b == 0 && node == NULL;
|
||||
}
|
||||
|
||||
/* count nodes */
|
||||
for (pos = 0; node != NULL; pos++)
|
||||
node = prev_node_func (node);
|
||||
|
||||
/* solve pos = a * X + b
|
||||
* and return TRUE if X is integer >= 0 */
|
||||
x = pos - b;
|
||||
|
||||
if (x % a)
|
||||
return FALSE;
|
||||
|
||||
return x / a >= 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
|
||||
gboolean forward,
|
||||
int a,
|
||||
int b)
|
||||
{
|
||||
return gtk_css_matcher_node_nth_child (matcher->node.node,
|
||||
forward ? get_previous_visible_sibling
|
||||
: get_next_visible_sibling,
|
||||
a, b);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_matcher_node_print (const GtkCssMatcher *matcher,
|
||||
GString *string)
|
||||
{
|
||||
gtk_css_node_print (matcher->node.node, 0, string, 0);
|
||||
}
|
||||
|
||||
static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
|
||||
GTK_CSS_MATCHER_TYPE_NODE,
|
||||
gtk_css_matcher_node_get_parent,
|
||||
gtk_css_matcher_node_get_previous,
|
||||
gtk_css_matcher_node_has_state,
|
||||
gtk_css_matcher_node_has_name,
|
||||
gtk_css_matcher_node_has_class,
|
||||
gtk_css_matcher_node_has_id,
|
||||
gtk_css_matcher_node_has_position,
|
||||
gtk_css_matcher_node_print
|
||||
};
|
||||
|
||||
void
|
||||
_gtk_css_matcher_node_init (GtkCssMatcher *matcher,
|
||||
GtkCssNode *node)
|
||||
{
|
||||
matcher->node.klass = >K_CSS_MATCHER_NODE;
|
||||
matcher->node.node = node;
|
||||
matcher->node.node_state = gtk_css_node_get_state (node);
|
||||
matcher->node.node_name = gtk_css_node_get_name (node);
|
||||
matcher->node.node_id = gtk_css_node_get_id (node);
|
||||
matcher->node.classes = gtk_css_node_declaration_get_classes (gtk_css_node_get_declaration (node),
|
||||
&matcher->node.n_classes);
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2012 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CSS_MATCHER_PRIVATE_H__
|
||||
#define __GTK_CSS_MATCHER_PRIVATE_H__
|
||||
|
||||
#include <gtk/gtkenums.h>
|
||||
#include <gtk/gtktypes.h>
|
||||
#include "gtk/gtkcsstypesprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GtkCssMatcherNode GtkCssMatcherNode;
|
||||
typedef struct _GtkCssMatcherSuperset GtkCssMatcherSuperset;
|
||||
typedef struct _GtkCssMatcherWidgetPath GtkCssMatcherWidgetPath;
|
||||
typedef struct _GtkCssMatcherClass GtkCssMatcherClass;
|
||||
|
||||
typedef enum {
|
||||
GTK_CSS_MATCHER_TYPE_NODE,
|
||||
GTK_CSS_MATCHER_TYPE_WIDGET_PATH
|
||||
} GtkCssMatcherType;
|
||||
|
||||
struct _GtkCssMatcherClass {
|
||||
GtkCssMatcherType type;
|
||||
gboolean (* get_parent) (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *child);
|
||||
gboolean (* get_previous) (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *next);
|
||||
|
||||
gboolean (* has_state) (const GtkCssMatcher *matcher,
|
||||
GtkStateFlags state);
|
||||
gboolean (* has_name) (const GtkCssMatcher *matcher,
|
||||
/*interned*/const char*name);
|
||||
gboolean (* has_class) (const GtkCssMatcher *matcher,
|
||||
GQuark class_name);
|
||||
gboolean (* has_id) (const GtkCssMatcher *matcher,
|
||||
const char *id);
|
||||
gboolean (* has_position) (const GtkCssMatcher *matcher,
|
||||
gboolean forward,
|
||||
int a,
|
||||
int b);
|
||||
void (* print) (const GtkCssMatcher *matcher,
|
||||
GString *string);
|
||||
};
|
||||
|
||||
struct _GtkCssMatcherWidgetPath {
|
||||
const GtkCssMatcherClass *klass;
|
||||
const GtkCssNodeDeclaration *decl;
|
||||
const GtkWidgetPath *path;
|
||||
guint index;
|
||||
guint sibling_index;
|
||||
};
|
||||
|
||||
struct _GtkCssMatcherNode {
|
||||
const GtkCssMatcherClass *klass;
|
||||
GtkCssNode *node;
|
||||
GtkStateFlags node_state;
|
||||
const char *node_name;
|
||||
const char *node_id;
|
||||
const GQuark *classes;
|
||||
guint n_classes;
|
||||
};
|
||||
|
||||
union _GtkCssMatcher {
|
||||
const GtkCssMatcherClass *klass;
|
||||
GtkCssMatcherWidgetPath path;
|
||||
GtkCssMatcherNode node;
|
||||
};
|
||||
|
||||
gboolean _gtk_css_matcher_init (GtkCssMatcher *matcher,
|
||||
const GtkWidgetPath *path,
|
||||
const GtkCssNodeDeclaration *decl) G_GNUC_WARN_UNUSED_RESULT;
|
||||
void _gtk_css_matcher_node_init (GtkCssMatcher *matcher,
|
||||
GtkCssNode *node);
|
||||
|
||||
void gtk_css_matcher_print (const GtkCssMatcher *matcher,
|
||||
GString *string);
|
||||
char * gtk_css_matcher_to_string (const GtkCssMatcher *matcher);
|
||||
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_get_parent (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *child)
|
||||
{
|
||||
return child->klass->get_parent (matcher, child);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_get_previous (GtkCssMatcher *matcher,
|
||||
const GtkCssMatcher *next)
|
||||
{
|
||||
return next->klass->get_previous (matcher, next);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_has_state (const GtkCssMatcher *matcher,
|
||||
GtkStateFlags state)
|
||||
{
|
||||
return matcher->klass->has_state (matcher, state);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_has_name (const GtkCssMatcher *matcher,
|
||||
/*interned*/ const char *name)
|
||||
{
|
||||
return matcher->klass->has_name (matcher, name);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_has_class (const GtkCssMatcher *matcher,
|
||||
GQuark class_name)
|
||||
{
|
||||
return matcher->klass->has_class (matcher, class_name);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
_gtk_css_matcher_has_id (const GtkCssMatcher *matcher,
|
||||
const char *id)
|
||||
{
|
||||
return matcher->klass->has_id (matcher, id);
|
||||
}
|
||||
|
||||
static inline guint
|
||||
_gtk_css_matcher_has_position (const GtkCssMatcher *matcher,
|
||||
gboolean forward,
|
||||
int a,
|
||||
int b)
|
||||
{
|
||||
return matcher->klass->has_position (matcher, forward, a, b);
|
||||
}
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_MATCHER_PRIVATE_H__ */
|
||||
@@ -110,7 +110,6 @@ enum {
|
||||
PROP_NAME,
|
||||
PROP_STATE,
|
||||
PROP_VISIBLE,
|
||||
PROP_WIDGET_TYPE,
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
@@ -187,10 +186,6 @@ gtk_css_node_get_property (GObject *object,
|
||||
g_value_set_boolean (value, gtk_css_node_get_visible (cssnode));
|
||||
break;
|
||||
|
||||
case PROP_WIDGET_TYPE:
|
||||
g_value_set_gtype (value, gtk_css_node_get_widget_type (cssnode));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
@@ -226,10 +221,6 @@ gtk_css_node_set_property (GObject *object,
|
||||
gtk_css_node_set_visible (cssnode, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_WIDGET_TYPE:
|
||||
gtk_css_node_set_widget_type (cssnode, g_value_get_gtype (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
@@ -367,8 +358,6 @@ gtk_css_node_create_style (GtkCssNode *cssnode,
|
||||
GtkCssChange change)
|
||||
{
|
||||
const GtkCssNodeDeclaration *decl;
|
||||
GtkCssMatcher matcher;
|
||||
GtkCssStyle *parent;
|
||||
GtkCssStyle *style;
|
||||
GtkCssChange style_change;
|
||||
|
||||
@@ -380,8 +369,6 @@ gtk_css_node_create_style (GtkCssNode *cssnode,
|
||||
|
||||
created_styles++;
|
||||
|
||||
parent = cssnode->parent ? cssnode->parent->style : NULL;
|
||||
|
||||
if (change & GTK_CSS_CHANGE_NEEDS_RECOMPUTE)
|
||||
{
|
||||
/* Need to recompute the change flags */
|
||||
@@ -392,16 +379,9 @@ gtk_css_node_create_style (GtkCssNode *cssnode,
|
||||
style_change = gtk_css_static_style_get_change (gtk_css_style_get_static_style (cssnode->style));
|
||||
}
|
||||
|
||||
if (gtk_css_node_init_matcher (cssnode, &matcher))
|
||||
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
|
||||
&matcher,
|
||||
parent,
|
||||
style_change);
|
||||
else
|
||||
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
|
||||
NULL,
|
||||
parent,
|
||||
style_change);
|
||||
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
|
||||
cssnode,
|
||||
style_change);
|
||||
|
||||
store_in_global_parent_cache (cssnode, decl, style);
|
||||
|
||||
@@ -497,15 +477,6 @@ gtk_css_node_real_validate (GtkCssNode *node)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_node_real_init_matcher (GtkCssNode *cssnode,
|
||||
GtkCssMatcher *matcher)
|
||||
{
|
||||
_gtk_css_matcher_node_init (matcher, cssnode);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GtkStyleProvider *
|
||||
gtk_css_node_real_get_style_provider (GtkCssNode *cssnode)
|
||||
{
|
||||
@@ -585,7 +556,6 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
|
||||
klass->validate = gtk_css_node_real_validate;
|
||||
klass->queue_validate = gtk_css_node_real_queue_validate;
|
||||
klass->dequeue_validate = gtk_css_node_real_dequeue_validate;
|
||||
klass->init_matcher = gtk_css_node_real_init_matcher;
|
||||
klass->get_style_provider = gtk_css_node_real_get_style_provider;
|
||||
klass->get_frame_clock = gtk_css_node_real_get_frame_clock;
|
||||
|
||||
@@ -655,11 +625,6 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
|
||||
TRUE,
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
cssnode_properties[PROP_WIDGET_TYPE] =
|
||||
g_param_spec_gtype ("widget-type", P_("Widget type"), P_("GType of the widget"),
|
||||
G_TYPE_NONE,
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, NUM_PROPERTIES, cssnode_properties);
|
||||
|
||||
@@ -1121,23 +1086,6 @@ gtk_css_node_get_name (GtkCssNode *cssnode)
|
||||
return gtk_css_node_declaration_get_name (cssnode->decl);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_node_set_widget_type (GtkCssNode *cssnode,
|
||||
GType widget_type)
|
||||
{
|
||||
if (gtk_css_node_declaration_set_type (&cssnode->decl, widget_type))
|
||||
{
|
||||
gtk_css_node_invalidate (cssnode, GTK_CSS_CHANGE_NAME);
|
||||
g_object_notify_by_pspec (G_OBJECT (cssnode), cssnode_properties[PROP_WIDGET_TYPE]);
|
||||
}
|
||||
}
|
||||
|
||||
GType
|
||||
gtk_css_node_get_widget_type (GtkCssNode *cssnode)
|
||||
{
|
||||
return gtk_css_node_declaration_get_type (cssnode->decl);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_node_set_id (GtkCssNode *cssnode,
|
||||
/* interned */ const char *id)
|
||||
@@ -1402,13 +1350,6 @@ gtk_css_node_validate (GtkCssNode *cssnode)
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_css_node_init_matcher (GtkCssNode *cssnode,
|
||||
GtkCssMatcher *matcher)
|
||||
{
|
||||
return GTK_CSS_NODE_GET_CLASS (cssnode)->init_matcher (cssnode, matcher);
|
||||
}
|
||||
|
||||
GtkStyleProvider *
|
||||
gtk_css_node_get_style_provider (GtkCssNode *cssnode)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcssnodedeclarationprivate.h"
|
||||
#include "gtkwidgetpathprivate.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -407,30 +406,6 @@ gtk_css_node_declaration_equal (gconstpointer elem1,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
|
||||
GtkWidgetPath *path,
|
||||
guint pos)
|
||||
{
|
||||
GQuark *classes;
|
||||
guint i;
|
||||
|
||||
/* Set name and id */
|
||||
gtk_widget_path_iter_set_object_name (path, pos, decl->name);
|
||||
if (decl->id)
|
||||
gtk_widget_path_iter_set_name (path, pos, decl->id);
|
||||
|
||||
/* Set widget classes */
|
||||
classes = get_classes (decl);
|
||||
for (i = 0; i < decl->n_classes; i++)
|
||||
{
|
||||
gtk_widget_path_iter_add_qclass (path, pos, classes[i]);
|
||||
}
|
||||
|
||||
/* Set widget state */
|
||||
gtk_widget_path_iter_set_state (path, pos, decl->state);
|
||||
}
|
||||
|
||||
static int
|
||||
cmpstr (gconstpointer a,
|
||||
gconstpointer b,
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gtkenums.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -55,10 +54,6 @@ guint gtk_css_node_declaration_hash (gconstp
|
||||
gboolean gtk_css_node_declaration_equal (gconstpointer elem1,
|
||||
gconstpointer elem2);
|
||||
|
||||
void gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
|
||||
GtkWidgetPath *path,
|
||||
guint pos);
|
||||
|
||||
void gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl,
|
||||
GString *string);
|
||||
|
||||
|
||||
@@ -76,8 +76,6 @@ struct _GtkCssNodeClass
|
||||
void (* style_changed) (GtkCssNode *cssnode,
|
||||
GtkCssStyleChange *style_change);
|
||||
|
||||
gboolean (* init_matcher) (GtkCssNode *cssnode,
|
||||
GtkCssMatcher *matcher);
|
||||
/* get style provider to use or NULL to use parent's */
|
||||
GtkStyleProvider * (* get_style_provider) (GtkCssNode *cssnode);
|
||||
/* get frame clock or NULL (only relevant for root node) */
|
||||
@@ -118,9 +116,6 @@ gboolean gtk_css_node_get_visible (GtkCssNode *
|
||||
void gtk_css_node_set_name (GtkCssNode *cssnode,
|
||||
/*interned*/const char*name);
|
||||
/*interned*/const char *gtk_css_node_get_name (GtkCssNode *cssnode) G_GNUC_PURE;
|
||||
void gtk_css_node_set_widget_type (GtkCssNode *cssnode,
|
||||
GType widget_type);
|
||||
GType gtk_css_node_get_widget_type (GtkCssNode *cssnode) G_GNUC_PURE;
|
||||
void gtk_css_node_set_id (GtkCssNode *cssnode,
|
||||
/*interned*/const char*id);
|
||||
/*interned*/const char *gtk_css_node_get_id (GtkCssNode *cssnode) G_GNUC_PURE;
|
||||
@@ -153,8 +148,6 @@ void gtk_css_node_invalidate (GtkCssNode *
|
||||
GtkCssChange change);
|
||||
void gtk_css_node_validate (GtkCssNode *cssnode);
|
||||
|
||||
gboolean gtk_css_node_init_matcher (GtkCssNode *cssnode,
|
||||
GtkCssMatcher *matcher);
|
||||
GtkStyleProvider * gtk_css_node_get_style_provider (GtkCssNode *cssnode) G_GNUC_PURE;
|
||||
|
||||
void gtk_css_node_print (GtkCssNode *cssnode,
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2014 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcsspathnodeprivate.h"
|
||||
#include "gtkcssstylepropertyprivate.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
|
||||
G_DEFINE_TYPE (GtkCssPathNode, gtk_css_path_node, GTK_TYPE_CSS_NODE)
|
||||
|
||||
static void
|
||||
gtk_css_path_node_finalize (GObject *object)
|
||||
{
|
||||
GtkCssPathNode *node = GTK_CSS_PATH_NODE (object);
|
||||
|
||||
if (node->path)
|
||||
gtk_widget_path_unref (node->path);
|
||||
|
||||
G_OBJECT_CLASS (gtk_css_path_node_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_path_node_invalidate (GtkCssNode *node)
|
||||
{
|
||||
GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
|
||||
|
||||
if (path_node->context)
|
||||
gtk_style_context_validate (path_node->context, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_path_node_real_init_matcher (GtkCssNode *node,
|
||||
GtkCssMatcher *matcher)
|
||||
{
|
||||
GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
|
||||
|
||||
if (path_node->path == NULL ||
|
||||
gtk_widget_path_length (path_node->path) == 0)
|
||||
return FALSE;
|
||||
|
||||
return _gtk_css_matcher_init (matcher,
|
||||
path_node->path,
|
||||
gtk_css_node_get_declaration (node));
|
||||
}
|
||||
|
||||
static GtkCssStyle *
|
||||
gtk_css_path_node_update_style (GtkCssNode *cssnode,
|
||||
GtkCssChange change,
|
||||
gint64 timestamp,
|
||||
GtkCssStyle *style)
|
||||
{
|
||||
/* This should get rid of animations */
|
||||
return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->update_style (cssnode, change, 0, style);
|
||||
}
|
||||
|
||||
static GtkStyleProvider *
|
||||
gtk_css_path_node_get_style_provider (GtkCssNode *node)
|
||||
{
|
||||
GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
|
||||
|
||||
if (path_node->context == NULL)
|
||||
return NULL;
|
||||
|
||||
return gtk_style_context_get_style_provider (path_node->context);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
|
||||
{
|
||||
GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gtk_css_path_node_finalize;
|
||||
|
||||
node_class->invalidate = gtk_css_path_node_invalidate;
|
||||
node_class->update_style = gtk_css_path_node_update_style;
|
||||
node_class->init_matcher = gtk_css_path_node_real_init_matcher;
|
||||
node_class->get_style_provider = gtk_css_path_node_get_style_provider;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_path_node_init (GtkCssPathNode *cssnode)
|
||||
{
|
||||
}
|
||||
|
||||
GtkCssNode *
|
||||
gtk_css_path_node_new (GtkStyleContext *context)
|
||||
{
|
||||
GtkCssPathNode *node;
|
||||
|
||||
g_return_val_if_fail (context == NULL || GTK_IS_STYLE_CONTEXT (context), NULL);
|
||||
|
||||
node = g_object_new (GTK_TYPE_CSS_PATH_NODE, NULL);
|
||||
node->context = context;
|
||||
|
||||
return GTK_CSS_NODE (node);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_path_node_unset_context (GtkCssPathNode *node)
|
||||
{
|
||||
gtk_internal_return_if_fail (GTK_IS_CSS_PATH_NODE (node));
|
||||
gtk_internal_return_if_fail (node->context != NULL);
|
||||
|
||||
node->context = NULL;
|
||||
|
||||
gtk_css_node_invalidate_style_provider (GTK_CSS_NODE (node));
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_path_node_set_widget_path (GtkCssPathNode *node,
|
||||
GtkWidgetPath *path)
|
||||
{
|
||||
gtk_internal_return_if_fail (GTK_IS_CSS_PATH_NODE (node));
|
||||
|
||||
if (node->path == path)
|
||||
return;
|
||||
|
||||
if (node->path)
|
||||
gtk_widget_path_unref (node->path);
|
||||
|
||||
if (path)
|
||||
gtk_widget_path_ref (path);
|
||||
|
||||
node->path = path;
|
||||
|
||||
gtk_css_node_invalidate (GTK_CSS_NODE (node), GTK_CSS_CHANGE_ANY);
|
||||
}
|
||||
|
||||
GtkWidgetPath *
|
||||
gtk_css_path_node_get_widget_path (GtkCssPathNode *node)
|
||||
{
|
||||
gtk_internal_return_val_if_fail (GTK_IS_CSS_PATH_NODE (node), NULL);
|
||||
|
||||
return node->path;
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2014 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CSS_PATH_NODE_PRIVATE_H__
|
||||
#define __GTK_CSS_PATH_NODE_PRIVATE_H__
|
||||
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_CSS_PATH_NODE (gtk_css_path_node_get_type ())
|
||||
#define GTK_CSS_PATH_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_PATH_NODE, GtkCssPathNode))
|
||||
#define GTK_CSS_PATH_NODE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_PATH_NODE, GtkCssPathNodeClass))
|
||||
#define GTK_IS_CSS_PATH_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_PATH_NODE))
|
||||
#define GTK_IS_CSS_PATH_NODE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_PATH_NODE))
|
||||
#define GTK_CSS_PATH_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_PATH_NODE, GtkCssPathNodeClass))
|
||||
|
||||
typedef struct _GtkCssPathNode GtkCssPathNode;
|
||||
typedef struct _GtkCssPathNodeClass GtkCssPathNodeClass;
|
||||
|
||||
struct _GtkCssPathNode
|
||||
{
|
||||
GtkCssNode node;
|
||||
|
||||
GtkStyleContext *context;
|
||||
GtkWidgetPath *path;
|
||||
};
|
||||
|
||||
struct _GtkCssPathNodeClass
|
||||
{
|
||||
GtkCssNodeClass node_class;
|
||||
};
|
||||
|
||||
GType gtk_css_path_node_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkCssNode * gtk_css_path_node_new (GtkStyleContext *context);
|
||||
|
||||
void gtk_css_path_node_unset_context (GtkCssPathNode *node);
|
||||
|
||||
void gtk_css_path_node_set_widget_path (GtkCssPathNode *node,
|
||||
GtkWidgetPath *path);
|
||||
GtkWidgetPath * gtk_css_path_node_get_widget_path (GtkCssPathNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_PATH_NODE_PRIVATE_H__ */
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtkstylepropertyprivate.h"
|
||||
#include "gtkstyleproviderprivate.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkbindings.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkprivate.h"
|
||||
@@ -390,8 +389,8 @@ gtk_css_provider_init (GtkCssProvider *css_provider)
|
||||
|
||||
static void
|
||||
verify_tree_match_results (GtkCssProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GPtrArray *tree_rules)
|
||||
GtkCssNode *node,
|
||||
GPtrArray *tree_rules)
|
||||
{
|
||||
#ifdef VERIFY_TREE
|
||||
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
||||
@@ -413,7 +412,7 @@ verify_tree_match_results (GtkCssProvider *provider,
|
||||
break;
|
||||
}
|
||||
}
|
||||
should_match = _gtk_css_selector_matches (ruleset->selector, matcher);
|
||||
should_match = _gtk_css_selector_matches (ruleset->selector, node);
|
||||
if (found != !!should_match)
|
||||
{
|
||||
g_error ("expected rule '%s' to %s, but it %s",
|
||||
@@ -447,7 +446,7 @@ gtk_css_style_provider_get_keyframes (GtkStyleProvider *provider,
|
||||
|
||||
static void
|
||||
gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *change)
|
||||
{
|
||||
@@ -461,10 +460,10 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
||||
if (_gtk_css_selector_tree_is_empty (priv->tree))
|
||||
return;
|
||||
|
||||
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, matcher);
|
||||
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, node);
|
||||
if (tree_rules)
|
||||
{
|
||||
verify_tree_match_results (css_provider, matcher, tree_rules);
|
||||
verify_tree_match_results (css_provider, node, tree_rules);
|
||||
|
||||
for (i = tree_rules->len - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -495,7 +494,7 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
||||
}
|
||||
|
||||
if (change)
|
||||
*change = _gtk_css_selector_tree_get_change_all (priv->tree, matcher);
|
||||
*change = _gtk_css_selector_tree_get_change_all (priv->tree, node);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -49,7 +49,7 @@ typedef enum {
|
||||
|
||||
typedef struct _GtkCssSelectorClass GtkCssSelectorClass;
|
||||
typedef gboolean (* GtkCssSelectorForeachFunc) (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
gpointer data);
|
||||
|
||||
struct _GtkCssSelectorClass {
|
||||
@@ -58,18 +58,18 @@ struct _GtkCssSelectorClass {
|
||||
|
||||
void (* print) (const GtkCssSelector *selector,
|
||||
GString *string);
|
||||
/* NULL or an iterator that calls func with each submatcher of @matcher.
|
||||
* Potentially no submatcher exists.
|
||||
/* NULL or an iterator that calls func with each subnode of @node.
|
||||
* Potentially no subnode exists.
|
||||
* If any @invocation of @func returns %TRUE, the function will immediately
|
||||
* return %TRUE itself. If @func never returns %TRUE (or isn't called at all),
|
||||
* %FALSE will be returned.
|
||||
*/
|
||||
gboolean (* foreach_matcher) (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data);
|
||||
gboolean (* match_one) (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher);
|
||||
GtkCssNode *node);
|
||||
GtkCssChange (* get_change) (const GtkCssSelector *selector,
|
||||
GtkCssChange previous_change);
|
||||
void (* add_specificity) (const GtkCssSelector *selector,
|
||||
@@ -188,18 +188,18 @@ gtk_css_selector_tree_found_match (const GtkCssSelectorTree *tree,
|
||||
|
||||
static inline gboolean
|
||||
gtk_css_selector_match (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return selector->class->match_one (selector, matcher);
|
||||
return selector->class->match_one (selector, node);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gtk_css_selector_foreach (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
return selector->class->foreach_matcher (selector, matcher, func, data);
|
||||
return selector->class->foreach_matcher (selector, node, func, data);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -260,16 +260,16 @@ gtk_css_selector_default_add_specificity (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_default_foreach_matcher (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
return func (selector, matcher, data);
|
||||
return func (selector, node, data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_default_match_one (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -298,17 +298,17 @@ gtk_css_selector_descendant_print (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_descendant_foreach_matcher (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
GtkCssMatcher ancestor;
|
||||
GtkCssNode *parent;
|
||||
|
||||
while (_gtk_css_matcher_get_parent (&ancestor, matcher))
|
||||
for (parent = gtk_css_node_get_parent (node);
|
||||
parent;
|
||||
parent = gtk_css_node_get_parent (parent))
|
||||
{
|
||||
matcher = &ancestor;
|
||||
|
||||
if (func (selector, &ancestor, data))
|
||||
if (func (selector, parent, data))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -344,16 +344,17 @@ gtk_css_selector_child_print (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_child_foreach_matcher (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
GtkCssMatcher parent;
|
||||
GtkCssNode *parent;
|
||||
|
||||
if (!_gtk_css_matcher_get_parent (&parent, matcher))
|
||||
parent = gtk_css_node_get_parent (node);
|
||||
if (parent == NULL)
|
||||
return FALSE;
|
||||
|
||||
return func (selector, &parent, data);
|
||||
return func (selector, parent, data);
|
||||
}
|
||||
|
||||
static GtkCssChange
|
||||
@@ -383,19 +384,39 @@ gtk_css_selector_sibling_print (const GtkCssSelector *selector,
|
||||
g_string_append (string, " ~ ");
|
||||
}
|
||||
|
||||
static GtkCssNode *
|
||||
get_previous_visible_sibling (GtkCssNode *node)
|
||||
{
|
||||
do {
|
||||
node = gtk_css_node_get_previous_sibling (node);
|
||||
} while (node && !gtk_css_node_get_visible (node));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static GtkCssNode *
|
||||
get_next_visible_sibling (GtkCssNode *node)
|
||||
{
|
||||
do {
|
||||
node = gtk_css_node_get_next_sibling (node);
|
||||
} while (node && !gtk_css_node_get_visible (node));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_sibling_foreach_matcher (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
GtkCssMatcher previous;
|
||||
GtkCssNode *prev;
|
||||
|
||||
while (_gtk_css_matcher_get_previous (&previous, matcher))
|
||||
for (prev = get_previous_visible_sibling (node);
|
||||
prev;
|
||||
prev = get_previous_visible_sibling (prev))
|
||||
{
|
||||
matcher = &previous;
|
||||
|
||||
if (func (selector, matcher, data))
|
||||
if (func (selector, prev, data))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -431,16 +452,17 @@ gtk_css_selector_adjacent_print (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_adjacent_foreach_matcher (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssSelectorForeachFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
GtkCssMatcher previous;
|
||||
GtkCssNode *prev;
|
||||
|
||||
if (!_gtk_css_matcher_get_previous (&previous, matcher))
|
||||
prev = get_previous_visible_sibling (node);
|
||||
if (prev == NULL)
|
||||
return FALSE;
|
||||
|
||||
return func (selector, &previous, data);
|
||||
|
||||
return func (selector, prev, data);
|
||||
}
|
||||
|
||||
static GtkCssChange
|
||||
@@ -491,9 +513,9 @@ gtk_css_selector_not_ ## n ## _print (const GtkCssSelector *selector, \
|
||||
\
|
||||
static gboolean \
|
||||
gtk_css_selector_not_ ## n ## _match_one (const GtkCssSelector *selector, \
|
||||
const GtkCssMatcher *matcher) \
|
||||
GtkCssNode *node) \
|
||||
{ \
|
||||
return !match_func (selector, matcher); \
|
||||
return !match_func (selector, node); \
|
||||
} \
|
||||
\
|
||||
static GtkCssChange \
|
||||
@@ -557,7 +579,7 @@ print_any (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
match_any (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -580,9 +602,9 @@ print_name (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
match_name (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return _gtk_css_matcher_has_name (matcher, selector->name.name);
|
||||
return gtk_css_node_get_name (node) == selector->name.name;
|
||||
}
|
||||
|
||||
static guint
|
||||
@@ -613,9 +635,9 @@ print_class (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
match_class (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return _gtk_css_matcher_has_class (matcher, selector->style_class.style_class);
|
||||
return gtk_css_node_has_class (node, selector->style_class.style_class);
|
||||
}
|
||||
|
||||
static guint
|
||||
@@ -650,9 +672,9 @@ print_id (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
match_id (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return _gtk_css_matcher_has_id (matcher, selector->id.name);
|
||||
return gtk_css_node_get_id (node) == selector->id.name;
|
||||
}
|
||||
|
||||
static guint
|
||||
@@ -716,9 +738,9 @@ print_pseudoclass_state (const GtkCssSelector *selector,
|
||||
|
||||
static gboolean
|
||||
match_pseudoclass_state (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
return _gtk_css_matcher_has_state (matcher, selector->state.state);
|
||||
return (gtk_css_node_get_state (node) & selector->state.state) == selector->state.state;
|
||||
}
|
||||
|
||||
static guint
|
||||
@@ -839,23 +861,57 @@ print_pseudoclass_position (const GtkCssSelector *selector,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_position (GtkCssNode *node,
|
||||
GtkCssNode *(* prev_node_func) (GtkCssNode *),
|
||||
int a,
|
||||
int b)
|
||||
{
|
||||
int pos, x;
|
||||
|
||||
/* special-case the common "first-child" and "last-child" */
|
||||
if (a == 0)
|
||||
{
|
||||
while (b > 0 && node != NULL)
|
||||
{
|
||||
b--;
|
||||
node = prev_node_func (node);
|
||||
}
|
||||
|
||||
return b == 0 && node == NULL;
|
||||
}
|
||||
|
||||
/* count nodes */
|
||||
for (pos = 0; node != NULL; pos++)
|
||||
node = prev_node_func (node);
|
||||
|
||||
/* solve pos = a * X + b
|
||||
* and return TRUE if X is integer >= 0 */
|
||||
x = pos - b;
|
||||
|
||||
if (x % a)
|
||||
return FALSE;
|
||||
|
||||
return x / a >= 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_pseudoclass_position (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
switch (selector->position.type)
|
||||
{
|
||||
case POSITION_FORWARD:
|
||||
if (!_gtk_css_matcher_has_position (matcher, TRUE, selector->position.a, selector->position.b))
|
||||
if (!match_position (node, get_previous_visible_sibling, selector->position.a, selector->position.b))
|
||||
return FALSE;
|
||||
break;
|
||||
case POSITION_BACKWARD:
|
||||
if (!_gtk_css_matcher_has_position (matcher, FALSE, selector->position.a, selector->position.b))
|
||||
if (!match_position (node, get_next_visible_sibling, selector->position.a, selector->position.b))
|
||||
return FALSE;
|
||||
break;
|
||||
case POSITION_ONLY:
|
||||
if (!_gtk_css_matcher_has_position (matcher, TRUE, 0, 1) ||
|
||||
!_gtk_css_matcher_has_position (matcher, FALSE, 0, 1))
|
||||
if (get_previous_visible_sibling (node) ||
|
||||
get_next_visible_sibling (node))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
@@ -1675,7 +1731,7 @@ _gtk_css_selector_to_string (const GtkCssSelector *selector)
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_foreach_match (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
gpointer unused)
|
||||
{
|
||||
selector = gtk_css_selector_previous (selector);
|
||||
@@ -1683,38 +1739,33 @@ gtk_css_selector_foreach_match (const GtkCssSelector *selector,
|
||||
if (selector == NULL)
|
||||
return TRUE;
|
||||
|
||||
if (!gtk_css_selector_match (selector, matcher))
|
||||
if (!gtk_css_selector_match (selector, node))
|
||||
return FALSE;
|
||||
|
||||
return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match, NULL);
|
||||
return gtk_css_selector_foreach (selector, node, gtk_css_selector_foreach_match, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* _gtk_css_selector_matches:
|
||||
* @selector: the selector
|
||||
* @path: the path to check
|
||||
* @state: The state to match
|
||||
* @node: The node to match
|
||||
*
|
||||
* Checks if the @selector matches the given @path. If @length is
|
||||
* smaller than the number of elements in @path, it is assumed that
|
||||
* only the first @length element of @path are valid and the rest
|
||||
* does not exist. This is useful for doing parent matches for the
|
||||
* 'inherit' keyword.
|
||||
* Checks if the @selector matches the given @node.
|
||||
*
|
||||
* Returns: %TRUE if the selector matches @path
|
||||
* Returns: %TRUE if the selector matches @node
|
||||
**/
|
||||
gboolean
|
||||
_gtk_css_selector_matches (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
|
||||
g_return_val_if_fail (selector != NULL, FALSE);
|
||||
g_return_val_if_fail (matcher != NULL, FALSE);
|
||||
g_return_val_if_fail (node != NULL, FALSE);
|
||||
|
||||
if (!gtk_css_selector_match (selector, matcher))
|
||||
if (!gtk_css_selector_match (selector, node))
|
||||
return FALSE;
|
||||
|
||||
return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match, NULL);
|
||||
return gtk_css_selector_foreach (selector, node, gtk_css_selector_foreach_match, NULL);
|
||||
}
|
||||
|
||||
/* Computes specificity according to CSS 2.1.
|
||||
@@ -1851,13 +1902,13 @@ gtk_css_selectors_skip_initial_selector (GtkCssSelector *selector, const GtkCssS
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_tree_match_foreach (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
gpointer res)
|
||||
{
|
||||
const GtkCssSelectorTree *tree = (const GtkCssSelectorTree *) selector;
|
||||
const GtkCssSelectorTree *prev;
|
||||
|
||||
if (!gtk_css_selector_match (selector, matcher))
|
||||
if (!gtk_css_selector_match (selector, node))
|
||||
return FALSE;
|
||||
|
||||
gtk_css_selector_tree_found_match (tree, res);
|
||||
@@ -1865,20 +1916,20 @@ gtk_css_selector_tree_match_foreach (const GtkCssSelector *selector,
|
||||
for (prev = gtk_css_selector_tree_get_previous (tree);
|
||||
prev != NULL;
|
||||
prev = gtk_css_selector_tree_get_sibling (prev))
|
||||
gtk_css_selector_foreach (&prev->selector, matcher, gtk_css_selector_tree_match_foreach, res);
|
||||
gtk_css_selector_foreach (&prev->selector, node, gtk_css_selector_tree_match_foreach, res);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
_gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
GPtrArray *array = NULL;
|
||||
|
||||
for (; tree != NULL;
|
||||
tree = gtk_css_selector_tree_get_sibling (tree))
|
||||
gtk_css_selector_foreach (&tree->selector, matcher, gtk_css_selector_tree_match_foreach, &array);
|
||||
gtk_css_selector_foreach (&tree->selector, node, gtk_css_selector_tree_match_foreach, &array);
|
||||
|
||||
return array;
|
||||
}
|
||||
@@ -1890,12 +1941,12 @@ _gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
|
||||
static gboolean
|
||||
gtk_css_selector_match_for_change (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
if (selector->class->category != GTK_CSS_SELECTOR_CATEGORY_SIMPLE_RADICAL)
|
||||
return TRUE;
|
||||
|
||||
return selector->class->match_one (selector, matcher);
|
||||
return selector->class->match_one (selector, node);
|
||||
}
|
||||
|
||||
/* When checking for changes via the tree we need to know if a rule further
|
||||
@@ -1927,12 +1978,12 @@ gtk_css_selector_tree_collect_change (const GtkCssSelectorTree *tree)
|
||||
|
||||
static GtkCssChange
|
||||
gtk_css_selector_tree_get_change (const GtkCssSelectorTree *tree,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
GtkCssChange change = 0;
|
||||
const GtkCssSelectorTree *prev;
|
||||
|
||||
if (!gtk_css_selector_match_for_change (&tree->selector, matcher))
|
||||
if (!gtk_css_selector_match_for_change (&tree->selector, node))
|
||||
return 0;
|
||||
|
||||
if (!gtk_css_selector_is_simple (&tree->selector))
|
||||
@@ -1941,7 +1992,7 @@ gtk_css_selector_tree_get_change (const GtkCssSelectorTree *tree,
|
||||
for (prev = gtk_css_selector_tree_get_previous (tree);
|
||||
prev != NULL;
|
||||
prev = gtk_css_selector_tree_get_sibling (prev))
|
||||
change |= gtk_css_selector_tree_get_change (prev, matcher);
|
||||
change |= gtk_css_selector_tree_get_change (prev, node);
|
||||
|
||||
if (change || gtk_css_selector_tree_get_matches (tree))
|
||||
change = tree->selector.class->get_change (&tree->selector, change & ~GTK_CSS_CHANGE_GOT_MATCH) | GTK_CSS_CHANGE_GOT_MATCH;
|
||||
@@ -1957,7 +2008,7 @@ _gtk_css_selector_tree_is_empty (const GtkCssSelectorTree *tree)
|
||||
|
||||
GtkCssChange
|
||||
_gtk_css_selector_tree_get_change_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCssMatcher *matcher)
|
||||
GtkCssNode *node)
|
||||
{
|
||||
GtkCssChange change;
|
||||
|
||||
@@ -1966,7 +2017,7 @@ _gtk_css_selector_tree_get_change_all (const GtkCssSelectorTree *tree,
|
||||
/* no need to foreach here because we abort for non-simple selectors */
|
||||
for (; tree != NULL;
|
||||
tree = gtk_css_selector_tree_get_sibling (tree))
|
||||
change |= gtk_css_selector_tree_get_change (tree, matcher);
|
||||
change |= gtk_css_selector_tree_get_change (tree, node);
|
||||
|
||||
/* Never return reserved bit set */
|
||||
return change & ~GTK_CSS_CHANGE_RESERVED_BIT;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#ifndef __GTK_CSS_SELECTOR_PRIVATE_H__
|
||||
#define __GTK_CSS_SELECTOR_PRIVATE_H__
|
||||
|
||||
#include "gtk/gtkcssmatcherprivate.h"
|
||||
#include "gtk/gtkcsstypesprivate.h"
|
||||
#include "gtk/gtkcssparserprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -35,16 +35,16 @@ void _gtk_css_selector_print (const GtkCssSelector *sel
|
||||
GString *str);
|
||||
|
||||
gboolean _gtk_css_selector_matches (const GtkCssSelector *selector,
|
||||
const GtkCssMatcher *matcher);
|
||||
GtkCssNode *node);
|
||||
GtkCssChange _gtk_css_selector_get_change (const GtkCssSelector *selector);
|
||||
int _gtk_css_selector_compare (const GtkCssSelector *a,
|
||||
const GtkCssSelector *b);
|
||||
|
||||
void _gtk_css_selector_tree_free (GtkCssSelectorTree *tree);
|
||||
GPtrArray * _gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCssMatcher *matcher);
|
||||
GtkCssNode *node);
|
||||
GtkCssChange _gtk_css_selector_tree_get_change_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCssMatcher *matcher);
|
||||
GtkCssNode *node);
|
||||
void _gtk_css_selector_tree_match_print (const GtkCssSelectorTree *tree,
|
||||
GString *str);
|
||||
gboolean _gtk_css_selector_tree_is_empty (const GtkCssSelectorTree *tree) G_GNUC_CONST;
|
||||
@@ -59,6 +59,8 @@ void _gtk_css_selector_tree_builder_add (GtkCssSelectorT
|
||||
GtkCssSelectorTree * _gtk_css_selector_tree_builder_build (GtkCssSelectorTreeBuilder *builder);
|
||||
void _gtk_css_selector_tree_builder_free (GtkCssSelectorTreeBuilder *builder);
|
||||
|
||||
#include "gtkenums.h"
|
||||
|
||||
const char *gtk_css_pseudoclass_name (GtkStateFlags flags);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -166,8 +166,7 @@ gtk_css_static_style_get_default (void)
|
||||
settings = gtk_settings_get_default ();
|
||||
default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER (settings),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE);
|
||||
0);
|
||||
g_object_set_data_full (G_OBJECT (settings), I_("gtk-default-style"),
|
||||
default_style, clear_default_style);
|
||||
}
|
||||
@@ -177,18 +176,18 @@ gtk_css_static_style_get_default (void)
|
||||
|
||||
GtkCssStyle *
|
||||
gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssStyle *parent,
|
||||
GtkCssNode *node,
|
||||
GtkCssChange change)
|
||||
{
|
||||
GtkCssStaticStyle *result;
|
||||
GtkCssLookup lookup;
|
||||
GtkCssNode *parent;
|
||||
|
||||
_gtk_css_lookup_init (&lookup);
|
||||
|
||||
if (matcher)
|
||||
if (node)
|
||||
gtk_style_provider_lookup (provider,
|
||||
matcher,
|
||||
node,
|
||||
&lookup,
|
||||
change == 0 ? &change : NULL);
|
||||
|
||||
@@ -196,10 +195,15 @@ gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
|
||||
result->change = change;
|
||||
|
||||
if (node)
|
||||
parent = gtk_css_node_get_parent (node);
|
||||
else
|
||||
parent = NULL;
|
||||
|
||||
_gtk_css_lookup_resolve (&lookup,
|
||||
provider,
|
||||
result,
|
||||
parent);
|
||||
parent ? gtk_css_node_get_style (parent) : NULL);
|
||||
|
||||
_gtk_css_lookup_destroy (&lookup);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#ifndef __GTK_CSS_STATIC_STYLE_PRIVATE_H__
|
||||
#define __GTK_CSS_STATIC_STYLE_PRIVATE_H__
|
||||
|
||||
#include "gtk/gtkcssmatcherprivate.h"
|
||||
#include "gtk/gtkcssstyleprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -53,8 +52,7 @@ GType gtk_css_static_style_get_type (void) G_GNUC_CO
|
||||
|
||||
GtkCssStyle * gtk_css_static_style_get_default (void);
|
||||
GtkCssStyle * gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssStyle *parent,
|
||||
GtkCssNode *node,
|
||||
GtkCssChange change);
|
||||
|
||||
void gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef union _GtkCssMatcher GtkCssMatcher;
|
||||
typedef struct _GtkCssNode GtkCssNode;
|
||||
typedef struct _GtkCssNodeDeclaration GtkCssNodeDeclaration;
|
||||
typedef struct _GtkCssStyle GtkCssStyle;
|
||||
|
||||
@@ -107,18 +107,6 @@ gtk_css_widget_node_validate (GtkCssNode *node)
|
||||
gtk_css_style_change_finish (&change);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_widget_node_init_matcher (GtkCssNode *node,
|
||||
GtkCssMatcher *matcher)
|
||||
{
|
||||
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
||||
|
||||
if (widget_node->widget == NULL)
|
||||
return FALSE;
|
||||
|
||||
return GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->init_matcher (node, matcher);
|
||||
}
|
||||
|
||||
static GtkStyleProvider *
|
||||
gtk_css_widget_node_get_style_provider (GtkCssNode *node)
|
||||
{
|
||||
@@ -162,7 +150,6 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
|
||||
node_class->validate = gtk_css_widget_node_validate;
|
||||
node_class->queue_validate = gtk_css_widget_node_queue_validate;
|
||||
node_class->dequeue_validate = gtk_css_widget_node_dequeue_validate;
|
||||
node_class->init_matcher = gtk_css_widget_node_init_matcher;
|
||||
node_class->get_style_provider = gtk_css_widget_node_get_style_provider;
|
||||
node_class->get_frame_clock = gtk_css_widget_node_get_frame_clock;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkbuildable.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkcontainerprivate.h"
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkstack.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkdragsource.h"
|
||||
#include "gtkwidgetpaintable.h"
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtksettings.h"
|
||||
#include "gtktogglebutton.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkeventcontrollerscroll.h"
|
||||
#include "gtkdragsource.h"
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include "gtksettings.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkboxlayout.h"
|
||||
#include "gtktextprivate.h"
|
||||
|
||||
@@ -180,7 +180,7 @@ gtk_style_cascade_get_keyframes (GtkStyleProvider *provider,
|
||||
|
||||
static void
|
||||
gtk_style_cascade_lookup (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssNode *node,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *change)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ gtk_style_cascade_lookup (GtkStyleProvider *provider,
|
||||
item;
|
||||
item = gtk_style_cascade_iter_next (cascade, &iter))
|
||||
{
|
||||
gtk_style_provider_lookup (item, matcher, lookup,
|
||||
gtk_style_provider_lookup (item, node, lookup,
|
||||
change ? &iter_change : NULL);
|
||||
if (change)
|
||||
*change |= iter_change;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "gtkcssnodedeclarationprivate.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkcsspathnodeprivate.h"
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkcssstylepropertyprivate.h"
|
||||
@@ -46,7 +45,6 @@
|
||||
#include "gtkstylecascadeprivate.h"
|
||||
#include "gtkstyleproviderprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
|
||||
|
||||
@@ -56,7 +54,7 @@
|
||||
* @Title: GtkStyleContext
|
||||
*
|
||||
* #GtkStyleContext is an object that stores styling information affecting
|
||||
* a widget defined by #GtkWidgetPath.
|
||||
* a widget.
|
||||
*
|
||||
* In order to construct the final style information, #GtkStyleContext
|
||||
* queries information from all attached #GtkStyleProviders. Style providers
|
||||
@@ -66,9 +64,9 @@
|
||||
* combination of all providers’ information in priority order.
|
||||
*
|
||||
* For GTK+ widgets, any #GtkStyleContext returned by
|
||||
* gtk_widget_get_style_context() will already have a #GtkWidgetPath, a
|
||||
* #GdkDisplay and RTL/LTR information set. The style context will also be
|
||||
* updated automatically if any of these settings change on the widget.
|
||||
* gtk_widget_get_style_context() will already have a #GdkDisplay and
|
||||
* RTL/LTR information set. The style context will also be updated
|
||||
* automatically if any of these settings change on the widget.
|
||||
*
|
||||
* If you are using the theming layer standalone, you will need to set a
|
||||
* widget path and a display yourself to the created style context through
|
||||
@@ -308,9 +306,6 @@ gtk_style_context_finalize (GObject *object)
|
||||
while (priv->saved_nodes)
|
||||
gtk_style_context_pop_style_node (context);
|
||||
|
||||
if (GTK_IS_CSS_PATH_NODE (priv->cssnode))
|
||||
gtk_css_path_node_unset_context (GTK_CSS_PATH_NODE (priv->cssnode));
|
||||
|
||||
gtk_style_context_clear_parent (context);
|
||||
gtk_style_context_set_cascade (context, NULL);
|
||||
|
||||
@@ -445,7 +440,7 @@ gtk_style_context_new (void)
|
||||
|
||||
|
||||
/* Create default info store */
|
||||
priv->cssnode = gtk_css_path_node_new (context);
|
||||
priv->cssnode = gtk_css_node_new ();
|
||||
gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR);
|
||||
|
||||
return context;
|
||||
@@ -924,74 +919,6 @@ gtk_style_context_get_scale (GtkStyleContext *context)
|
||||
return _gtk_style_cascade_get_scale (priv->cascade);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_set_path:
|
||||
* @context: a #GtkStyleContext
|
||||
* @path: a #GtkWidgetPath
|
||||
*
|
||||
* Sets the #GtkWidgetPath used for style matching. As a
|
||||
* consequence, the style will be regenerated to match
|
||||
* the new given path.
|
||||
*
|
||||
* If you are using a #GtkStyleContext returned from
|
||||
* gtk_widget_get_style_context(), you do not need to call
|
||||
* this yourself.
|
||||
**/
|
||||
void
|
||||
gtk_style_context_set_path (GtkStyleContext *context,
|
||||
GtkWidgetPath *path)
|
||||
{
|
||||
GtkCssNode *root;
|
||||
|
||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
root = gtk_style_context_get_root (context);
|
||||
g_return_if_fail (GTK_IS_CSS_PATH_NODE (root));
|
||||
|
||||
if (path && gtk_widget_path_length (path) > 0)
|
||||
{
|
||||
GtkWidgetPath *copy = gtk_widget_path_copy (path);
|
||||
gtk_css_path_node_set_widget_path (GTK_CSS_PATH_NODE (root), copy);
|
||||
gtk_css_node_set_widget_type (root,
|
||||
gtk_widget_path_iter_get_object_type (copy, -1));
|
||||
gtk_css_node_set_name (root, gtk_widget_path_iter_get_object_name (copy, -1));
|
||||
gtk_widget_path_unref (copy);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_css_path_node_set_widget_path (GTK_CSS_PATH_NODE (root), NULL);
|
||||
gtk_css_node_set_widget_type (root, G_TYPE_NONE);
|
||||
gtk_css_node_set_name (root, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_get_path:
|
||||
* @context: a #GtkStyleContext
|
||||
*
|
||||
* Returns the widget path used for style matching set via
|
||||
* gtk_style_context_set_path().
|
||||
*
|
||||
* If no path has been set - in particular if this style context
|
||||
* was returned from a #GtkWidget - this function returns %NULL.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): A #GtkWidgetPath or %NULL
|
||||
**/
|
||||
const GtkWidgetPath *
|
||||
gtk_style_context_get_path (GtkStyleContext *context)
|
||||
{
|
||||
GtkCssNode *root;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
|
||||
|
||||
root = gtk_style_context_get_root (context);
|
||||
if (!GTK_IS_CSS_PATH_NODE (root))
|
||||
return NULL;
|
||||
|
||||
return gtk_css_path_node_get_widget_path (GTK_CSS_PATH_NODE (root));
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_style_context_set_parent:
|
||||
* @context: a #GtkStyleContext
|
||||
|
||||
@@ -988,11 +988,6 @@ void gtk_style_context_set_scale (GtkStyleContext *context,
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_style_context_get_scale (GtkStyleContext *context);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_set_path (GtkStyleContext *context,
|
||||
GtkWidgetPath *path);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const GtkWidgetPath * gtk_style_context_get_path (GtkStyleContext *context);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_style_context_set_parent (GtkStyleContext *context,
|
||||
GtkStyleContext *parent);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkstyleprovider
|
||||
@@ -93,15 +92,15 @@ gtk_style_provider_get_keyframes (GtkStyleProvider *provider,
|
||||
}
|
||||
|
||||
void
|
||||
gtk_style_provider_lookup (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *out_change)
|
||||
gtk_style_provider_lookup (GtkStyleProvider *provider,
|
||||
GtkCssNode *node,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *out_change)
|
||||
{
|
||||
GtkStyleProviderInterface *iface;
|
||||
|
||||
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
|
||||
gtk_internal_return_if_fail (matcher != NULL);
|
||||
gtk_internal_return_if_fail (GTK_IS_CSS_NODE (node));
|
||||
gtk_internal_return_if_fail (lookup != NULL);
|
||||
|
||||
if (out_change)
|
||||
@@ -112,7 +111,7 @@ gtk_style_provider_lookup (GtkStyleProvider *provider,
|
||||
if (!iface->lookup)
|
||||
return;
|
||||
|
||||
iface->lookup (provider, matcher, lookup, out_change);
|
||||
iface->lookup (provider, node, lookup, out_change);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <glib-object.h>
|
||||
#include "gtk/gtkcsskeyframesprivate.h"
|
||||
#include "gtk/gtkcsslookupprivate.h"
|
||||
#include "gtk/gtkcssmatcherprivate.h"
|
||||
#include "gtk/gtkcssnodeprivate.h"
|
||||
#include "gtk/gtkcssvalueprivate.h"
|
||||
#include <gtk/gtktypes.h>
|
||||
|
||||
@@ -35,37 +35,37 @@ struct _GtkStyleProviderInterface
|
||||
{
|
||||
GTypeInterface g_iface;
|
||||
|
||||
GtkCssValue * (* get_color) (GtkStyleProvider *provider,
|
||||
GtkCssValue * (* get_color) (GtkStyleProvider *provider,
|
||||
const char *name);
|
||||
GtkSettings * (* get_settings) (GtkStyleProvider *provider);
|
||||
GtkCssKeyframes * (* get_keyframes) (GtkStyleProvider *provider,
|
||||
GtkSettings * (* get_settings) (GtkStyleProvider *provider);
|
||||
GtkCssKeyframes * (* get_keyframes) (GtkStyleProvider *provider,
|
||||
const char *name);
|
||||
int (* get_scale) (GtkStyleProvider *provider);
|
||||
void (* lookup) (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
int (* get_scale) (GtkStyleProvider *provider);
|
||||
void (* lookup) (GtkStyleProvider *provider,
|
||||
GtkCssNode *node,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *out_change);
|
||||
void (* emit_error) (GtkStyleProvider *provider,
|
||||
void (* emit_error) (GtkStyleProvider *provider,
|
||||
GtkCssSection *section,
|
||||
const GError *error);
|
||||
/* signal */
|
||||
void (* changed) (GtkStyleProvider *provider);
|
||||
void (* changed) (GtkStyleProvider *provider);
|
||||
};
|
||||
|
||||
GtkSettings * gtk_style_provider_get_settings (GtkStyleProvider *provider);
|
||||
GtkCssValue * gtk_style_provider_get_color (GtkStyleProvider *provider,
|
||||
GtkSettings * gtk_style_provider_get_settings (GtkStyleProvider *provider);
|
||||
GtkCssValue * gtk_style_provider_get_color (GtkStyleProvider *provider,
|
||||
const char *name);
|
||||
GtkCssKeyframes * gtk_style_provider_get_keyframes (GtkStyleProvider *provider,
|
||||
GtkCssKeyframes * gtk_style_provider_get_keyframes (GtkStyleProvider *provider,
|
||||
const char *name);
|
||||
int gtk_style_provider_get_scale (GtkStyleProvider *provider);
|
||||
void gtk_style_provider_lookup (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
int gtk_style_provider_get_scale (GtkStyleProvider *provider);
|
||||
void gtk_style_provider_lookup (GtkStyleProvider *provider,
|
||||
GtkCssNode *node,
|
||||
GtkCssLookup *lookup,
|
||||
GtkCssChange *out_change);
|
||||
|
||||
void gtk_style_provider_changed (GtkStyleProvider *provider);
|
||||
void gtk_style_provider_changed (GtkStyleProvider *provider);
|
||||
|
||||
void gtk_style_provider_emit_error (GtkStyleProvider *provider,
|
||||
void gtk_style_provider_emit_error (GtkStyleProvider *provider,
|
||||
GtkCssSection *section,
|
||||
GError *error);
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
#include "gtkseparatortoolitem.h"
|
||||
#include "gtktoolshell.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkwindowprivate.h"
|
||||
#include "gtkgestureclick.h"
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
#include "gtktreemodelsort.h"
|
||||
#include "gtktreeprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetpath.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkwindowgroup.h"
|
||||
#include "gtknative.h"
|
||||
|
||||
@@ -67,7 +67,6 @@
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkversion.h"
|
||||
#include "gtkwidgetpaintableprivate.h"
|
||||
#include "gtkwidgetpathprivate.h"
|
||||
#include "gtkwindowgroup.h"
|
||||
#include "gtkwindowprivate.h"
|
||||
#include "gtknativeprivate.h"
|
||||
@@ -2442,7 +2441,6 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
|
||||
gtk_css_node_set_visible (priv->cssnode, priv->visible);
|
||||
/* need to set correct name here, and only class has the correct type here */
|
||||
gtk_css_node_set_name (priv->cssnode, GTK_WIDGET_CLASS (g_class)->priv->css_name);
|
||||
gtk_css_node_set_widget_type (priv->cssnode, G_TYPE_FROM_CLASS (g_class));
|
||||
|
||||
if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_ROOT))
|
||||
priv->root = (GtkRoot *) widget;
|
||||
@@ -11179,46 +11177,6 @@ _gtk_widget_remove_attached_window (GtkWidget *widget,
|
||||
priv->attached_windows = g_list_remove (priv->attached_windows, window);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_path_append_for_widget:
|
||||
* @path: a widget path
|
||||
* @widget: the widget to append to the widget path
|
||||
*
|
||||
* Appends the data from @widget to the widget hierarchy represented
|
||||
* by @path. This function is a shortcut for adding information from
|
||||
* @widget to the given @path. This includes setting the name or
|
||||
* adding the style classes from @widget.
|
||||
*
|
||||
* Returns: the position where the data was inserted
|
||||
*/
|
||||
gint
|
||||
gtk_widget_path_append_for_widget (GtkWidgetPath *path,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
|
||||
const GQuark *classes;
|
||||
guint n_classes, i;
|
||||
gint pos;
|
||||
|
||||
g_return_val_if_fail (path != NULL, 0);
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
|
||||
|
||||
pos = gtk_widget_path_append_type (path, gtk_css_node_get_widget_type (priv->cssnode));
|
||||
gtk_widget_path_iter_set_object_name (path, pos, gtk_css_node_get_name (priv->cssnode));
|
||||
|
||||
if (priv->name)
|
||||
gtk_widget_path_iter_set_name (path, pos, priv->name);
|
||||
|
||||
gtk_widget_path_iter_set_state (path, pos, priv->state_flags);
|
||||
|
||||
classes = gtk_css_node_list_classes (priv->cssnode, &n_classes);
|
||||
|
||||
for (i = n_classes; i-- > 0;)
|
||||
gtk_widget_path_iter_add_qclass (path, pos, classes[i]);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_class_set_css_name:
|
||||
* @widget_class: class to set the name on
|
||||
|
||||
1023
gtk/gtkwidgetpath.c
1023
gtk/gtkwidgetpath.c
File diff suppressed because it is too large
Load Diff
@@ -1,149 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_WIDGET_PATH_H__
|
||||
#define __GTK_WIDGET_PATH_H__
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkenums.h>
|
||||
#include <gtk/gtktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_WIDGET_PATH (gtk_widget_path_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_widget_path_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidgetPath * gtk_widget_path_new (void);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidgetPath * gtk_widget_path_copy (const GtkWidgetPath *path);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidgetPath * gtk_widget_path_ref (GtkWidgetPath *path);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_unref (GtkWidgetPath *path);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_free (GtkWidgetPath *path);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
char * gtk_widget_path_to_string (const GtkWidgetPath *path);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_widget_path_length (const GtkWidgetPath *path);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_widget_path_append_type (GtkWidgetPath *path,
|
||||
GType type);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_prepend_type (GtkWidgetPath *path,
|
||||
GType type);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_widget_path_append_with_siblings(GtkWidgetPath *path,
|
||||
GtkWidgetPath *siblings,
|
||||
guint sibling_index);
|
||||
/* gtk_widget_path_append_for_widget() is declared in gtkwidget.c */
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_widget_path_append_for_widget (GtkWidgetPath *path,
|
||||
GtkWidget *widget);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_set_object_type (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
GType type);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const char * gtk_widget_path_iter_get_object_name (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_set_object_name (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const char *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const GtkWidgetPath *
|
||||
gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
guint gtk_widget_path_iter_get_sibling_index(const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const gchar * gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_set_name (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
|
||||
gint pos,
|
||||
GQuark qname);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkStateFlags gtk_widget_path_iter_get_state (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_set_state (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
GtkStateFlags state);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_add_class (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_remove_class (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_path_iter_clear_classes (GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList * gtk_widget_path_iter_list_classes (const GtkWidgetPath *path,
|
||||
gint pos);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_iter_has_class (const GtkWidgetPath *path,
|
||||
gint pos,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path,
|
||||
gint pos,
|
||||
GQuark qname);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_widget_path_get_object_type (const GtkWidgetPath *path);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_is_type (const GtkWidgetPath *path,
|
||||
GType type);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_widget_path_has_parent (const GtkWidgetPath *path,
|
||||
GType type);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_WIDGET_PATH_H__ */
|
||||
@@ -1,31 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_WIDGET_PATH_PRIVATE_H__
|
||||
#define __GTK_WIDGET_PATH_PRIVATE_H__
|
||||
|
||||
#include <gtk/gtkwidgetpath.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void gtk_widget_path_iter_add_qclass (GtkWidgetPath *path,
|
||||
gint pos,
|
||||
GQuark qname);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_WIDGET_PATH_PRIVATE_H__ */
|
||||
@@ -72,14 +72,12 @@ gtk_private_sources = files([
|
||||
'gtkcssinitialvalue.c',
|
||||
'gtkcsskeyframes.c',
|
||||
'gtkcsslookup.c',
|
||||
'gtkcssmatcher.c',
|
||||
'gtkcssnode.c',
|
||||
'gtkcssnodedeclaration.c',
|
||||
'gtkcssnodestylecache.c',
|
||||
'gtkcssnumbervalue.c',
|
||||
'gtkcsspalettevalue.c',
|
||||
'gtkcssparser.c',
|
||||
'gtkcsspathnode.c',
|
||||
'gtkcsspositionvalue.c',
|
||||
'gtkcssrepeatvalue.c',
|
||||
'gtkcssselector.c',
|
||||
@@ -398,7 +396,6 @@ gtk_public_sources = files([
|
||||
'gtkwidget.c',
|
||||
'gtkwidgetfocus.c',
|
||||
'gtkwidgetpaintable.c',
|
||||
'gtkwidgetpath.c',
|
||||
'gtkwindow.c',
|
||||
'gtkwindowgroup.c',
|
||||
])
|
||||
@@ -631,7 +628,6 @@ gtk_public_headers = files([
|
||||
'gtkvolumebutton.h',
|
||||
'gtkwidget.h',
|
||||
'gtkwidgetpaintable.h',
|
||||
'gtkwidgetpath.h',
|
||||
'gtkwindow.h',
|
||||
'gtkwindowgroup.h',
|
||||
'gtk-a11y.h',
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static void
|
||||
test_init_of_theme (void)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkCssProvider *provider;
|
||||
GtkWidgetPath *path;
|
||||
GdkRGBA before, after;
|
||||
char *css;
|
||||
|
||||
/* Test that a style context actually uses the theme loaded for the
|
||||
* screen it is using. If no screen is set, it's the default one.
|
||||
*/
|
||||
context = gtk_style_context_new ();
|
||||
path = gtk_widget_path_new ();
|
||||
|
||||
/* Set a path that will have a color set.
|
||||
* (This could actually fail if style classes change, so if this test
|
||||
* fails, make sure to have this path represent something sane.)
|
||||
*/
|
||||
gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
|
||||
gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND);
|
||||
gtk_style_context_set_path (context, path);
|
||||
gtk_widget_path_free (path);
|
||||
|
||||
/* Get the color. This should be initialized by the theme and not be
|
||||
* the default. */
|
||||
gtk_style_context_get_color (context, &before);
|
||||
|
||||
/* Add a style that sets a different color for this widget.
|
||||
* This style has a higher priority than fallback, but a lower
|
||||
* priority than the theme. */
|
||||
css = g_strdup_printf (".background { color: %s; }",
|
||||
before.alpha < 0.5 ? "black" : "transparent");
|
||||
provider = gtk_css_provider_new ();
|
||||
gtk_css_provider_load_from_data (provider, css, -1);
|
||||
gtk_style_context_add_provider (context,
|
||||
GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1);
|
||||
g_object_unref (provider);
|
||||
|
||||
/* Get the color again. */
|
||||
gtk_style_context_get_color (context, &after);
|
||||
|
||||
/* Because the style we added does not influence the color,
|
||||
* the before and after colors should be identical. */
|
||||
g_assert (gdk_rgba_equal (&before, &after));
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/style/init_of_theme", test_init_of_theme);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -28,7 +28,6 @@ tests = [
|
||||
['entry'],
|
||||
['filterlistmodel'],
|
||||
['flattenlistmodel'],
|
||||
['firefox-stylecontext'],
|
||||
['floating'],
|
||||
['focus'],
|
||||
['gestures'],
|
||||
|
||||
@@ -64,198 +64,6 @@ test_parse_selectors (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_path (void)
|
||||
{
|
||||
GtkWidgetPath *path;
|
||||
GtkWidgetPath *path2;
|
||||
gint pos;
|
||||
|
||||
path = gtk_widget_path_new ();
|
||||
g_assert_cmpint (gtk_widget_path_length (path), ==, 0);
|
||||
|
||||
pos = gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
|
||||
g_assert_cmpint (pos, ==, 0);
|
||||
g_assert_cmpint (gtk_widget_path_length (path), ==, 1);
|
||||
g_assert (gtk_widget_path_iter_get_object_type (path, 0) == GTK_TYPE_WINDOW);
|
||||
g_assert (gtk_widget_path_is_type (path, GTK_TYPE_WIDGET));
|
||||
g_assert (gtk_widget_path_iter_get_name (path, 0) == NULL);
|
||||
|
||||
pos = gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
|
||||
g_assert_cmpint (pos, ==, 1);
|
||||
g_assert_cmpint (gtk_widget_path_length (path), ==, 2);
|
||||
gtk_widget_path_iter_set_object_type (path, pos, GTK_TYPE_BUTTON);
|
||||
g_assert (gtk_widget_path_is_type (path, GTK_TYPE_BUTTON));
|
||||
g_assert (gtk_widget_path_has_parent (path, GTK_TYPE_WIDGET));
|
||||
g_assert (gtk_widget_path_has_parent (path, GTK_TYPE_WINDOW));
|
||||
g_assert (!gtk_widget_path_has_parent (path, GTK_TYPE_DIALOG));
|
||||
g_assert (gtk_widget_path_iter_get_name (path, 1) == NULL);
|
||||
|
||||
gtk_widget_path_iter_set_name (path, 1, "name");
|
||||
g_assert (gtk_widget_path_iter_has_name (path, 1, "name"));
|
||||
|
||||
gtk_widget_path_iter_add_class (path, 1, "class1");
|
||||
gtk_widget_path_iter_add_class (path, 1, "class2");
|
||||
g_assert (gtk_widget_path_iter_has_class (path, 1, "class1"));
|
||||
g_assert (gtk_widget_path_iter_has_class (path, 1, "class2"));
|
||||
g_assert (!gtk_widget_path_iter_has_class (path, 1, "class3"));
|
||||
|
||||
path2 = gtk_widget_path_copy (path);
|
||||
g_assert (gtk_widget_path_iter_has_class (path2, 1, "class1"));
|
||||
g_assert (gtk_widget_path_iter_has_class (path2, 1, "class2"));
|
||||
g_assert (!gtk_widget_path_iter_has_class (path2, 1, "class3"));
|
||||
gtk_widget_path_free (path2);
|
||||
|
||||
gtk_widget_path_iter_remove_class (path, 1, "class2");
|
||||
g_assert (gtk_widget_path_iter_has_class (path, 1, "class1"));
|
||||
g_assert (!gtk_widget_path_iter_has_class (path, 1, "class2"));
|
||||
gtk_widget_path_iter_clear_classes (path, 1);
|
||||
g_assert (!gtk_widget_path_iter_has_class (path, 1, "class1"));
|
||||
|
||||
|
||||
gtk_widget_path_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_match (void)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkWidgetPath *path;
|
||||
GtkCssProvider *provider;
|
||||
const gchar *data;
|
||||
GdkRGBA color;
|
||||
GdkRGBA expected;
|
||||
|
||||
provider = gtk_css_provider_new ();
|
||||
|
||||
gdk_rgba_parse (&expected, "#fff");
|
||||
|
||||
context = gtk_style_context_new ();
|
||||
|
||||
path = gtk_widget_path_new ();
|
||||
gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
|
||||
gtk_widget_path_append_type (path, GTK_TYPE_BOX);
|
||||
gtk_widget_path_append_type (path, GTK_TYPE_BUTTON);
|
||||
gtk_widget_path_iter_set_object_name (path, 0, "window");
|
||||
gtk_widget_path_iter_set_name (path, 0, "mywindow");
|
||||
gtk_widget_path_iter_set_object_name (path, 2, "button");
|
||||
gtk_widget_path_iter_add_class (path, 2, "button");
|
||||
gtk_widget_path_iter_set_state (path, 0, GTK_STATE_FLAG_ACTIVE);
|
||||
gtk_style_context_set_path (context, path);
|
||||
gtk_widget_path_free (path);
|
||||
|
||||
gtk_style_context_add_provider (context,
|
||||
GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
data = "* { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"button { color: #fff; }\n"
|
||||
"window > button { color: #000; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
".button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"button { color: #000; }\n"
|
||||
".button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"button { color: #000; }\n"
|
||||
"window button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
".button { color: #000; }\n"
|
||||
"window .button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"* .button { color: #000; }\n"
|
||||
"#mywindow .button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"window .button { color: #000; }\n"
|
||||
"window#mywindow .button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"window .button { color: #000; }\n"
|
||||
"window button.button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
data = "* { color: #f00; }\n"
|
||||
"window:backdrop .button { color: #000; }\n"
|
||||
"window .button { color: #111; }\n"
|
||||
"window:active .button { color: #fff; }";
|
||||
gtk_css_provider_load_from_data (provider, data, -1);
|
||||
gtk_style_context_get_color (context, &color);
|
||||
g_assert (gdk_rgba_equal (&color, &expected));
|
||||
|
||||
g_object_unref (provider);
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
test_basic_properties (void)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkWidgetPath *path;
|
||||
GdkRGBA *color;
|
||||
GdkRGBA *bg_color;
|
||||
PangoFontDescription *font;
|
||||
|
||||
context = gtk_style_context_new ();
|
||||
path = gtk_widget_path_new ();
|
||||
gtk_style_context_set_path (context, path);
|
||||
gtk_widget_path_free (path);
|
||||
|
||||
gtk_style_context_get (context,
|
||||
"color", &color,
|
||||
"background-color", &bg_color,
|
||||
"font", &font,
|
||||
NULL);
|
||||
g_assert (color != NULL);
|
||||
g_assert (bg_color != NULL);
|
||||
g_assert (font != NULL);
|
||||
|
||||
gdk_rgba_free (color);
|
||||
gdk_rgba_free (bg_color);
|
||||
pango_font_description_free (font);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
void
|
||||
test_widget_path_parent (void)
|
||||
{
|
||||
@@ -310,200 +118,6 @@ test_style_classes (void)
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_setup (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
f->blue_provider = gtk_css_provider_new ();
|
||||
f->red_provider = gtk_css_provider_new ();
|
||||
f->green_provider = gtk_css_provider_new ();
|
||||
f->context = gtk_style_context_new ();
|
||||
GtkWidgetPath *path = gtk_widget_path_new ();
|
||||
|
||||
gtk_css_provider_load_from_data (f->blue_provider, "* { color: blue; }", -1);
|
||||
gtk_css_provider_load_from_data (f->red_provider, "* { color: red; }", -1);
|
||||
gtk_css_provider_load_from_data (f->green_provider, "* { color: green; }", -1);
|
||||
|
||||
gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
|
||||
gtk_style_context_set_path (f->context, path);
|
||||
|
||||
gtk_widget_path_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_teardown (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
g_object_unref (f->blue_provider);
|
||||
g_object_unref (f->red_provider);
|
||||
g_object_unref (f->green_provider);
|
||||
g_object_unref (f->context);
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_equal (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
/* When style providers are added to the display as well as the style context
|
||||
the one specific to the style context should take priority */
|
||||
gdk_rgba_parse (&ref_color, "red");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_display_only (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "blue");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_context_only (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "red");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_display_higher (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "blue");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_context_higher (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "red");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_two_display (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "red");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_two_context (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "red");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_three_display_higher (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->green_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "green");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
static void
|
||||
test_style_priorities_three_context_higher (PrioritiesFixture *f,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GdkRGBA color, ref_color;
|
||||
|
||||
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||
GTK_STYLE_PROVIDER (f->blue_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->red_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
gtk_style_context_add_provider (f->context, GTK_STYLE_PROVIDER (f->green_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
|
||||
|
||||
gdk_rgba_parse (&ref_color, "green");
|
||||
gtk_style_context_get_color (f->context, &color);
|
||||
|
||||
g_assert_true (gdk_rgba_equal (&ref_color, &color));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@@ -511,26 +125,8 @@ main (int argc, char *argv[])
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/style/parse/selectors", test_parse_selectors);
|
||||
g_test_add_func ("/style/path", test_path);
|
||||
g_test_add_func ("/style/match", test_match);
|
||||
g_test_add_func ("/style/basic", test_basic_properties);
|
||||
g_test_add_func ("/style/widget-path-parent", test_widget_path_parent);
|
||||
g_test_add_func ("/style/classes", test_style_classes);
|
||||
|
||||
#define ADD_PRIORITIES_TEST(path, func) \
|
||||
g_test_add ("/style/priorities/" path, PrioritiesFixture, NULL, test_style_priorities_setup, \
|
||||
(func), test_style_priorities_teardown)
|
||||
|
||||
ADD_PRIORITIES_TEST ("equal", test_style_priorities_equal);
|
||||
ADD_PRIORITIES_TEST ("display-only", test_style_priorities_display_only);
|
||||
ADD_PRIORITIES_TEST ("context-only", test_style_priorities_context_only);
|
||||
ADD_PRIORITIES_TEST ("display-higher", test_style_priorities_display_higher);
|
||||
ADD_PRIORITIES_TEST ("context-higher", test_style_priorities_context_higher);
|
||||
ADD_PRIORITIES_TEST ("two-display", test_style_priorities_two_display);
|
||||
ADD_PRIORITIES_TEST ("two-context", test_style_priorities_two_context);
|
||||
ADD_PRIORITIES_TEST ("three-display-higher", test_style_priorities_three_display_higher);
|
||||
ADD_PRIORITIES_TEST ("three-context-higher", test_style_priorities_three_context_higher);
|
||||
|
||||
#undef ADD_PRIORITIES_TEST
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user