diff options
-rw-r--r-- | demos/gtk-demo/demo.gresource.xml | 1 | ||||
-rw-r--r-- | demos/gtk-demo/foreigndrawing.c | 984 | ||||
-rw-r--r-- | demos/gtk-demo/meson.build | 1 | ||||
-rw-r--r-- | docs/reference/gtk/gtk4-docs.xml | 1 | ||||
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 46 | ||||
-rw-r--r-- | gtk/gtk-autocleanups.h | 1 | ||||
-rw-r--r-- | gtk/gtk.h | 1 | ||||
-rw-r--r-- | gtk/gtkcssmatcher.c | 181 | ||||
-rw-r--r-- | gtk/gtkcssmatcherprivate.h | 12 | ||||
-rw-r--r-- | gtk/gtkcssnodedeclaration.c | 25 | ||||
-rw-r--r-- | gtk/gtkcssnodedeclarationprivate.h | 5 | ||||
-rw-r--r-- | gtk/gtkcsspathnode.c | 153 | ||||
-rw-r--r-- | gtk/gtkcsspathnodeprivate.h | 61 | ||||
-rw-r--r-- | gtk/gtkstylecontext.c | 83 | ||||
-rw-r--r-- | gtk/gtkstylecontext.h | 5 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 41 | ||||
-rw-r--r-- | gtk/gtkwidgetpath.c | 1023 | ||||
-rw-r--r-- | gtk/gtkwidgetpath.h | 149 | ||||
-rw-r--r-- | gtk/gtkwidgetpathprivate.h | 31 | ||||
-rw-r--r-- | gtk/meson.build | 3 | ||||
-rw-r--r-- | testsuite/gtk/firefox-stylecontext.c | 62 | ||||
-rw-r--r-- | testsuite/gtk/meson.build | 1 | ||||
-rw-r--r-- | testsuite/gtk/stylecontext.c | 404 |
23 files changed, 5 insertions, 3269 deletions
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml index 3a58d42011..a60a21721b 100644 --- a/demos/gtk-demo/demo.gresource.xml +++ b/demos/gtk-demo/demo.gresource.xml @@ -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> diff --git a/demos/gtk-demo/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c deleted file mode 100644 index 447d895487..0000000000 --- a/demos/gtk-demo/foreigndrawing.c +++ /dev/null @@ -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; -} diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build index 4f5209d6d9..eee93be78e 100644 --- a/demos/gtk-demo/meson.build +++ b/demos/gtk-demo/meson.build @@ -28,7 +28,6 @@ demos = files([ 'fishbowl.c', 'fixed.c', 'fontrendering.c', - 'foreigndrawing.c', 'gestures.c', 'glarea.c', 'headerbar.c', diff --git a/docs/reference/gtk/gtk4-docs.xml b/docs/reference/gtk/gtk4-docs.xml index 4b2625a7b5..a85bbd80e4 100644 --- a/docs/reference/gtk/gtk4-docs.xml +++ b/docs/reference/gtk/gtk4-docs.xml @@ -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> diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index b65c83fde4..d798189773 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4690,50 +4690,6 @@ 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> GtkStyleProvider @@ -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 diff --git a/gtk/gtk-autocleanups.h b/gtk/gtk-autocleanups.h index 91889b0bdb..7c81374af0 100644 --- a/gtk/gtk-autocleanups.h +++ b/gtk/gtk-autocleanups.h @@ -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> diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c index 9876747153..b1fb4fe404 100644 --- a/gtk/gtkcssmatcher.c +++ b/gtk/gtkcssmatcher.c @@ -21,7 +21,6 @@ #include "gtkcssnodedeclarationprivate.h" #include "gtkcssnodeprivate.h" -#include "gtkwidgetpath.h" void gtk_css_matcher_print (const GtkCssMatcher *matcher, @@ -38,186 +37,6 @@ gtk_css_matcher_to_string (const GtkCssMatcher *matcher) 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 diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h index ca9d34c8fc..c5744dc469 100644 --- a/gtk/gtkcssmatcherprivate.h +++ b/gtk/gtkcssmatcherprivate.h @@ -57,14 +57,6 @@ struct _GtkCssMatcherClass { 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; @@ -72,13 +64,9 @@ struct _GtkCssMatcherNode { 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); diff --git a/gtk/gtkcssnodedeclaration.c b/gtk/gtkcssnodedeclaration.c index 63a9cb40ee..cd9dd4f47b 100644 --- a/gtk/gtkcssnodedeclaration.c +++ b/gtk/gtkcssnodedeclaration.c @@ -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, diff --git a/gtk/gtkcssnodedeclarationprivate.h b/gtk/gtkcssnodedeclarationprivate.h index 79c000fcb6..de79209052 100644 --- a/gtk/gtkcssnodedeclarationprivate.h +++ b/gtk/gtkcssnodedeclarationprivate.h @@ -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); diff --git a/gtk/gtkcsspathnode.c b/gtk/gtkcsspathnode.c deleted file mode 100644 index 164487e4e8..0000000000 --- a/gtk/gtkcsspathnode.c +++ /dev/null @@ -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; -} - diff --git a/gtk/gtkcsspathnodeprivate.h b/gtk/gtkcsspathnodeprivate.h deleted file mode 100644 index 4c7d60e5bd..0000000000 --- a/gtk/gtkcsspathnodeprivate.h +++ /dev/null @@ -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__ */ diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 717dce8437..11134cf6fc 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -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; @@ -925,74 +920,6 @@ gtk_style_context_get_scale (GtkStyleContext *context) } /** - * 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 * @parent: (allow-none): the new parent or %NULL diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h index c7c5b78c59..66544ccab6 100644 --- a/gtk/gtkstylecontext.h +++ b/gtk/gtkstylecontext.h @@ -989,11 +989,6 @@ 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); GDK_AVAILABLE_IN_ALL diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 92ef2fec36..38a6adde99 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -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" @@ -11181,46 +11180,6 @@ _gtk_widget_remove_attached_window (GtkWidget *widget, } /** - * 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 * @name: name to use diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c deleted file mode 100644 index c82f1704b0..0000000000 --- a/gtk/gtkwidgetpath.c +++ /dev/null @@ -1,1023 +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/>. - */ - -#include "config.h" - -#include "gtkwidgetpath.h" - -#include <string.h> - -#include "gtkcssnodedeclarationprivate.h" -#include "gtkprivate.h" -#include "gtkstylecontextprivate.h" -#include "gtktypebuiltins.h" -#include "gtkwidget.h" -#include "gtkwidgetpathprivate.h" - -/** - * SECTION:gtkwidgetpath - * @Short_description: Widget path abstraction - * @Title: GtkWidgetPath - * @See_also: #GtkStyleContext - * - * GtkWidgetPath is a boxed type that represents a widget hierarchy from - * the topmost widget, typically a toplevel, to any child. This widget - * path abstraction is used in #GtkStyleContext on behalf of the real - * widget in order to query style information. - * - * If you are using GTK+ widgets, you probably will not need to use - * this API directly, as there is gtk_widget_get_path(), and the style - * context returned by gtk_widget_get_style_context() will be automatically - * updated on widget hierarchy changes. - * - * The widget path generation is generally simple: - * - * ## Defining a button within a window - * - * |[<!-- language="C" --> - * { - * GtkWidgetPath *path; - * - * path = gtk_widget_path_new (); - * gtk_widget_path_append_type (path, GTK_TYPE_WINDOW); - * gtk_widget_path_append_type (path, GTK_TYPE_BUTTON); - * } - * ]| - * - * Although more complex information, such as widget names, or - * different classes (property that may be used by other widget - * types) and intermediate regions may be included: - * - * ## Defining the first tab widget in a notebook - * - * |[<!-- language="C" --> - * { - * GtkWidgetPath *path; - * guint pos; - * - * path = gtk_widget_path_new (); - * - * pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK); - * gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST); - * - * pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL); - * gtk_widget_path_iter_set_name (path, pos, "first tab label"); - * } - * ]| - * - * All this information will be used to match the style information - * that applies to the described widget. - **/ - -G_DEFINE_BOXED_TYPE (GtkWidgetPath, gtk_widget_path, - gtk_widget_path_ref, gtk_widget_path_unref) - - -typedef struct GtkPathElement GtkPathElement; - -struct GtkPathElement -{ - GtkCssNodeDeclaration *decl; - guint sibling_index; - GtkWidgetPath *siblings; -}; - -struct _GtkWidgetPath -{ - guint ref_count; - - GArray *elems; /* First element contains the described widget */ -}; - -/** - * gtk_widget_path_new: - * - * Returns an empty widget path. - * - * Returns: (transfer full): A newly created, empty, #GtkWidgetPath - **/ -GtkWidgetPath * -gtk_widget_path_new (void) -{ - GtkWidgetPath *path; - - path = g_slice_new0 (GtkWidgetPath); - path->elems = g_array_new (FALSE, TRUE, sizeof (GtkPathElement)); - path->ref_count = 1; - - return path; -} - -static void -gtk_path_element_copy (GtkPathElement *dest, - const GtkPathElement *src) -{ - memset (dest, 0, sizeof (GtkPathElement)); - - dest->decl = gtk_css_node_declaration_ref (src->decl); - if (src->siblings) - dest->siblings = gtk_widget_path_ref (src->siblings); - dest->sibling_index = src->sibling_index; -} - -/** - * gtk_widget_path_copy: - * @path: a #GtkWidgetPath - * - * Returns a copy of @path - * - * Returns: (transfer full): a copy of @path - **/ -GtkWidgetPath * -gtk_widget_path_copy (const GtkWidgetPath *path) -{ - GtkWidgetPath *new_path; - guint i; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - - new_path = gtk_widget_path_new (); - - g_array_set_size (new_path->elems, path->elems->len); - - for (i = 0; i < path->elems->len; i++) - { - GtkPathElement *elem, *dest; - - elem = &g_array_index (path->elems, GtkPathElement, i); - dest = &g_array_index (new_path->elems, GtkPathElement, i); - - gtk_path_element_copy (dest, elem); - } - - return new_path; -} - -/** - * gtk_widget_path_ref: - * @path: a #GtkWidgetPath - * - * Increments the reference count on @path. - * - * Returns: @path itself. - **/ -GtkWidgetPath * -gtk_widget_path_ref (GtkWidgetPath *path) -{ - gtk_internal_return_val_if_fail (path != NULL, path); - - path->ref_count += 1; - - return path; -} - -/** - * gtk_widget_path_unref: - * @path: a #GtkWidgetPath - * - * Decrements the reference count on @path, freeing the structure - * if the reference count reaches 0. - **/ -void -gtk_widget_path_unref (GtkWidgetPath *path) -{ - guint i; - - gtk_internal_return_if_fail (path != NULL); - - path->ref_count -= 1; - if (path->ref_count > 0) - return; - - for (i = 0; i < path->elems->len; i++) - { - GtkPathElement *elem; - - elem = &g_array_index (path->elems, GtkPathElement, i); - - gtk_css_node_declaration_unref (elem->decl); - if (elem->siblings) - gtk_widget_path_unref (elem->siblings); - } - - g_array_free (path->elems, TRUE); - g_slice_free (GtkWidgetPath, path); -} - -/** - * gtk_widget_path_free: - * @path: a #GtkWidgetPath - * - * Decrements the reference count on @path, freeing the structure - * if the reference count reaches 0. - **/ -void -gtk_widget_path_free (GtkWidgetPath *path) -{ - gtk_internal_return_if_fail (path != NULL); - - gtk_widget_path_unref (path); -} - -/** - * gtk_widget_path_length: - * @path: a #GtkWidgetPath - * - * Returns the number of #GtkWidget #GTypes between the represented - * widget and its topmost container. - * - * Returns: the number of elements in the path - **/ -gint -gtk_widget_path_length (const GtkWidgetPath *path) -{ - gtk_internal_return_val_if_fail (path != NULL, 0); - - return path->elems->len; -} - -/** - * gtk_widget_path_to_string: - * @path: the path - * - * Dumps the widget path into a string representation. It tries to match - * the CSS style as closely as possible (Note that there might be paths - * that cannot be represented in CSS). - * - * The main use of this code is for debugging purposes, so that you can - * g_print() the path or dump it in a gdb session. - * - * Returns: A new string describing @path. - **/ -char * -gtk_widget_path_to_string (const GtkWidgetPath *path) -{ - GString *string; - guint i, j, n; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - - string = g_string_new (""); - - for (i = 0; i < path->elems->len; i++) - { - GtkPathElement *elem; - GtkStateFlags state; - const GQuark *classes; - - elem = &g_array_index (path->elems, GtkPathElement, i); - - if (i > 0) - g_string_append_c (string, ' '); - - if (gtk_css_node_declaration_get_name (elem->decl)) - g_string_append (string, gtk_css_node_declaration_get_name (elem->decl)); - else - g_string_append (string, g_type_name (gtk_css_node_declaration_get_type (elem->decl))); - - if (gtk_css_node_declaration_get_id (elem->decl)) - { - g_string_append_c (string, '('); - g_string_append (string, gtk_css_node_declaration_get_id (elem->decl)); - g_string_append_c (string, ')'); - } - - state = gtk_css_node_declaration_get_state (elem->decl); - if (state) - { - GFlagsClass *fclass; - - fclass = g_type_class_ref (GTK_TYPE_STATE_FLAGS); - for (j = 0; j < fclass->n_values; j++) - { - if (state & fclass->values[j].value) - { - g_string_append_c (string, ':'); - g_string_append (string, fclass->values[j].value_nick); - } - } - g_type_class_unref (fclass); - } - - if (elem->siblings) - g_string_append_printf (string, "[%d/%d]", - elem->sibling_index + 1, - gtk_widget_path_length (elem->siblings)); - - classes = gtk_css_node_declaration_get_classes (elem->decl, &n); - for (j = 0; j < n; j++) - { - g_string_append_c (string, '.'); - g_string_append (string, g_quark_to_string (classes[j])); - } - } - - return g_string_free (string, FALSE); -} - -/** - * gtk_widget_path_prepend_type: - * @path: a #GtkWidgetPath - * @type: widget type to prepend - * - * Prepends a widget type to the widget hierachy represented by @path. - **/ -void -gtk_widget_path_prepend_type (GtkWidgetPath *path, - GType type) -{ - GtkPathElement new = { NULL }; - - gtk_internal_return_if_fail (path != NULL); - - new.decl = gtk_css_node_declaration_new (); - gtk_css_node_declaration_set_type (&new.decl, type); - - g_array_prepend_val (path->elems, new); -} - -/** - * gtk_widget_path_append_type: - * @path: a #GtkWidgetPath - * @type: widget type to append - * - * Appends a widget type to the widget hierarchy represented by @path. - * - * Returns: the position where the element was inserted - **/ -gint -gtk_widget_path_append_type (GtkWidgetPath *path, - GType type) -{ - GtkPathElement new = { NULL }; - - gtk_internal_return_val_if_fail (path != NULL, 0); - - new.decl = gtk_css_node_declaration_new (); - gtk_css_node_declaration_set_type (&new.decl, type); - g_array_append_val (path->elems, new); - - return path->elems->len - 1; -} - -/** - * gtk_widget_path_append_with_siblings: - * @path: the widget path to append to - * @siblings: a widget path describing a list of siblings. This path - * may not contain any siblings itself and it must not be modified - * afterwards. - * @sibling_index: index into @siblings for where the added element is - * positioned. - * - * Appends a widget type with all its siblings to the widget hierarchy - * represented by @path. Using this function instead of - * gtk_widget_path_append_type() will allow the CSS theming to use - * sibling matches in selectors and apply :nth-child() pseudo classes. - * In turn, it requires a lot more care in widget implementations as - * widgets need to make sure to call gtk_widget_reset_style() on all - * involved widgets when the @siblings path changes. - * - * Returns: the position where the element was inserted. - **/ -gint -gtk_widget_path_append_with_siblings (GtkWidgetPath *path, - GtkWidgetPath *siblings, - guint sibling_index) -{ - GtkPathElement new; - - gtk_internal_return_val_if_fail (path != NULL, 0); - gtk_internal_return_val_if_fail (siblings != NULL, 0); - gtk_internal_return_val_if_fail (sibling_index < gtk_widget_path_length (siblings), 0); - - gtk_path_element_copy (&new, &g_array_index (siblings->elems, GtkPathElement, sibling_index)); - new.siblings = gtk_widget_path_ref (siblings); - new.sibling_index = sibling_index; - g_array_append_val (path->elems, new); - - return path->elems->len - 1; -} - -/** - * gtk_widget_path_iter_get_siblings: - * @path: a #GtkWidgetPath - * @pos: position to get the siblings for, -1 for the path head - * - * Returns the list of siblings for the element at @pos. If the element - * was not added with siblings, %NULL is returned. - * - * Returns: %NULL or the list of siblings for the element at @pos. - **/ -const GtkWidgetPath * -gtk_widget_path_iter_get_siblings (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - gtk_internal_return_val_if_fail (path->elems->len != 0, NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return elem->siblings; -} - -/** - * gtk_widget_path_iter_get_sibling_index: - * @path: a #GtkWidgetPath - * @pos: position to get the sibling index for, -1 for the path head - * - * Returns the index into the list of siblings for the element at @pos as - * returned by gtk_widget_path_iter_get_siblings(). If that function would - * return %NULL because the element at @pos has no siblings, this function - * will return 0. - * - * Returns: 0 or the index into the list of siblings for the element at @pos. - **/ -guint -gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, G_TYPE_INVALID); - gtk_internal_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return elem->sibling_index; -} - -/** - * gtk_widget_path_iter_get_object_name: - * @path: a #GtkWidgetPath - * @pos: position to get the object name for, -1 for the path head - * - * Returns the object name that is at position @pos in the widget - * hierarchy defined in @path. - * - * Returns: (nullable): the name or %NULL - **/ -const char * -gtk_widget_path_iter_get_object_name (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - gtk_internal_return_val_if_fail (path->elems->len != 0, NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return gtk_css_node_declaration_get_name (elem->decl); -} - -/** - * gtk_widget_path_iter_set_object_name: - * @path: a #GtkWidgetPath - * @pos: position to modify, -1 for the path head - * @name: (allow-none): object name to set or %NULL to unset - * - * Sets the object name for a given position in the widget hierarchy - * defined by @path. - * - * When set, the object name overrides the object type when matching - * CSS. - **/ -void -gtk_widget_path_iter_set_object_name (GtkWidgetPath *path, - gint pos, - const char *name) -{ - GtkPathElement *elem; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - gtk_css_node_declaration_set_name (&elem->decl, g_intern_string (name)); -} - -/** - * gtk_widget_path_iter_get_object_type: - * @path: a #GtkWidgetPath - * @pos: position to get the object type for, -1 for the path head - * - * Returns the object #GType that is at position @pos in the widget - * hierarchy defined in @path. - * - * Returns: a widget type - **/ -GType -gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, G_TYPE_INVALID); - gtk_internal_return_val_if_fail (path->elems->len != 0, G_TYPE_INVALID); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return gtk_css_node_declaration_get_type (elem->decl); -} - -/** - * gtk_widget_path_iter_set_object_type: - * @path: a #GtkWidgetPath - * @pos: position to modify, -1 for the path head - * @type: object type to set - * - * Sets the object type for a given position in the widget hierarchy - * defined by @path. - **/ -void -gtk_widget_path_iter_set_object_type (GtkWidgetPath *path, - gint pos, - GType type) -{ - GtkPathElement *elem; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - gtk_css_node_declaration_set_type (&elem->decl, type); -} - -/** - * gtk_widget_path_iter_get_state: - * @path: a #GtkWidgetPath - * @pos: position to get the state for, -1 for the path head - * - * Returns the state flags corresponding to the widget found at - * the position @pos in the widget hierarchy defined by - * @path - * - * Returns: The state flags - **/ -GtkStateFlags -gtk_widget_path_iter_get_state (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, 0); - gtk_internal_return_val_if_fail (path->elems->len != 0, 0); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return gtk_css_node_declaration_get_state (elem->decl); -} - -/** - * gtk_widget_path_iter_set_state: - * @path: a #GtkWidgetPath - * @pos: position to modify, -1 for the path head - * @state: state flags - * - * Sets the widget name for the widget found at position @pos - * in the widget hierarchy defined by @path. - * - * If you want to update just a single state flag, you need to do - * this manually, as this function updates all state flags. - * - * ## Setting a flag - * - * |[<!-- language="C" --> - * gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) | flag); - * ]| - * - * ## Unsetting a flag - * - * |[<!-- language="C" --> - * gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) & ~flag); - * ]| - **/ -void -gtk_widget_path_iter_set_state (GtkWidgetPath *path, - gint pos, - GtkStateFlags state) -{ - GtkPathElement *elem; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - - gtk_css_node_declaration_set_state (&elem->decl, state); -} - -/** - * gtk_widget_path_iter_get_name: - * @path: a #GtkWidgetPath - * @pos: position to get the widget name for, -1 for the path head - * - * Returns the name corresponding to the widget found at - * the position @pos in the widget hierarchy defined by - * @path - * - * Returns: (nullable): The widget name, or %NULL if none was set. - **/ -const gchar * -gtk_widget_path_iter_get_name (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - gtk_internal_return_val_if_fail (path->elems->len != 0, NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - return gtk_css_node_declaration_get_id (elem->decl); -} - -/** - * gtk_widget_path_iter_set_name: - * @path: a #GtkWidgetPath - * @pos: position to modify, -1 for the path head - * @name: widget name - * - * Sets the widget name for the widget found at position @pos - * in the widget hierarchy defined by @path. - **/ -void -gtk_widget_path_iter_set_name (GtkWidgetPath *path, - gint pos, - const gchar *name) -{ - GtkPathElement *elem; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - gtk_internal_return_if_fail (name != NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - - gtk_css_node_declaration_set_id (&elem->decl, g_intern_string (name)); -} - -/** - * gtk_widget_path_iter_has_qname: - * @path: a #GtkWidgetPath - * @pos: position to query, -1 for the path head - * @qname: widget name as a #GQuark - * - * See gtk_widget_path_iter_has_name(). This is a version - * that operates on #GQuarks. - * - * Returns: %TRUE if the widget at @pos has this name - **/ -gboolean -gtk_widget_path_iter_has_qname (const GtkWidgetPath *path, - gint pos, - GQuark qname) -{ - gtk_internal_return_val_if_fail (path != NULL, FALSE); - gtk_internal_return_val_if_fail (path->elems->len != 0, FALSE); - gtk_internal_return_val_if_fail (qname != 0, FALSE); - - return gtk_widget_path_iter_has_name (path, pos, g_quark_to_string (qname)); -} - -/** - * gtk_widget_path_iter_has_name: - * @path: a #GtkWidgetPath - * @pos: position to query, -1 for the path head - * @name: a widget name - * - * Returns %TRUE if the widget at position @pos has the name @name, - * %FALSE otherwise. - * - * Returns: %TRUE if the widget at @pos has this name - **/ -gboolean -gtk_widget_path_iter_has_name (const GtkWidgetPath *path, - gint pos, - const gchar *name) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, FALSE); - gtk_internal_return_val_if_fail (path->elems->len != 0, FALSE); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - name = g_intern_string (name); - elem = &g_array_index (path->elems, GtkPathElement, pos); - - return gtk_css_node_declaration_get_id (elem->decl) == name; -} - -/** - * gtk_widget_path_iter_add_class: - * @path: a #GtkWidget - * @pos: position to modify, -1 for the path head - * @name: a class name - * - * Adds the class @name to the widget at position @pos in - * the hierarchy defined in @path. See - * gtk_style_context_add_class(). - **/ -void -gtk_widget_path_iter_add_class (GtkWidgetPath *path, - gint pos, - const gchar *name) -{ - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - gtk_internal_return_if_fail (name != NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - gtk_widget_path_iter_add_qclass (path, pos, g_quark_from_string (name)); -} - -void -gtk_widget_path_iter_add_qclass (GtkWidgetPath *path, - gint pos, - GQuark qname) -{ - GtkPathElement *elem; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - - gtk_css_node_declaration_add_class (&elem->decl, qname); -} - -/** - * gtk_widget_path_iter_remove_class: - * @path: a #GtkWidgetPath - * @pos: position to modify, -1 for the path head - * @name: class name - * - * Removes the class @name from the widget at position @pos in - * the hierarchy defined in @path. - **/ -void -gtk_widget_path_iter_remove_class (GtkWidgetPath *path, - gint pos, - const gchar *name) -{ - GtkPathElement *elem; - GQuark qname; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - gtk_internal_return_if_fail (name != NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - qname = g_quark_try_string (name); - if (qname == 0) - return; - - gtk_css_node_declaration_remove_class (&elem->decl, qname); -} - -/** - * gtk_widget_path_iter_clear_classes: - * @path: a #GtkWidget - * @pos: position to modify, -1 for the path head - * - * Removes all classes from the widget at position @pos in the - * hierarchy defined in @path. - **/ -void -gtk_widget_path_iter_clear_classes (GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - - gtk_internal_return_if_fail (path != NULL); - gtk_internal_return_if_fail (path->elems->len != 0); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - - gtk_css_node_declaration_clear_classes (&elem->decl); -} - -/** - * gtk_widget_path_iter_list_classes: - * @path: a #GtkWidgetPath - * @pos: position to query, -1 for the path head - * - * Returns a list with all the class names defined for the widget - * at position @pos in the hierarchy defined in @path. - * - * Returns: (transfer container) (element-type utf8): The list of - * classes, This is a list of strings, the #GSList contents - * are owned by GTK+, but you should use g_slist_free() to - * free the list itself. - **/ -GSList * -gtk_widget_path_iter_list_classes (const GtkWidgetPath *path, - gint pos) -{ - GtkPathElement *elem; - GSList *list = NULL; - const GQuark *classes; - guint i, n; - - gtk_internal_return_val_if_fail (path != NULL, NULL); - gtk_internal_return_val_if_fail (path->elems->len != 0, NULL); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - classes = gtk_css_node_declaration_get_classes (elem->decl, &n); - - for (i = 0; i < n; i++) - { - list = g_slist_prepend (list, (gchar *) g_quark_to_string (classes[i])); - } - - return g_slist_reverse (list); -} - -/** - * gtk_widget_path_iter_has_qclass: - * @path: a #GtkWidgetPath - * @pos: position to query, -1 for the path head - * @qname: class name as a #GQuark - * - * See gtk_widget_path_iter_has_class(). This is a version that operates - * with GQuarks. - * - * Returns: %TRUE if the widget at @pos has the class defined. - **/ -gboolean -gtk_widget_path_iter_has_qclass (const GtkWidgetPath *path, - gint pos, - GQuark qname) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, FALSE); - gtk_internal_return_val_if_fail (path->elems->len != 0, FALSE); - gtk_internal_return_val_if_fail (qname != 0, FALSE); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - elem = &g_array_index (path->elems, GtkPathElement, pos); - - return gtk_css_node_declaration_has_class (elem->decl, qname); -} - -/** - * gtk_widget_path_iter_has_class: - * @path: a #GtkWidgetPath - * @pos: position to query, -1 for the path head - * @name: class name - * - * Returns %TRUE if the widget at position @pos has the class @name - * defined, %FALSE otherwise. - * - * Returns: %TRUE if the class @name is defined for the widget at @pos - **/ -gboolean -gtk_widget_path_iter_has_class (const GtkWidgetPath *path, - gint pos, - const gchar *name) -{ - GQuark qname; - - gtk_internal_return_val_if_fail (path != NULL, FALSE); - gtk_internal_return_val_if_fail (path->elems->len != 0, FALSE); - gtk_internal_return_val_if_fail (name != NULL, FALSE); - - if (pos < 0 || pos >= path->elems->len) - pos = path->elems->len - 1; - - qname = g_quark_try_string (name); - - if (qname == 0) - return FALSE; - - return gtk_widget_path_iter_has_qclass (path, pos, qname); -} - -/** - * gtk_widget_path_get_object_type: - * @path: a #GtkWidget - * - * Returns the topmost object type, that is, the object type this path - * is representing. - * - * Returns: The object type - **/ -GType -gtk_widget_path_get_object_type (const GtkWidgetPath *path) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, G_TYPE_INVALID); - - elem = &g_array_index (path->elems, GtkPathElement, - path->elems->len - 1); - return gtk_css_node_declaration_get_type (elem->decl); -} - -/** - * gtk_widget_path_is_type: - * @path: a #GtkWidgetPath - * @type: widget type to match - * - * Returns %TRUE if the widget type represented by this path - * is @type, or a subtype of it. - * - * Returns: %TRUE if the widget represented by @path is of type @type - **/ -gboolean -gtk_widget_path_is_type (const GtkWidgetPath *path, - GType type) -{ - GtkPathElement *elem; - - gtk_internal_return_val_if_fail (path != NULL, FALSE); - - elem = &g_array_index (path->elems, GtkPathElement, - path->elems->len - 1); - - return g_type_is_a (gtk_css_node_declaration_get_type (elem->decl), type); -} - -/** - * gtk_widget_path_has_parent: - * @path: a #GtkWidgetPath - * @type: widget type to check in parents - * - * Returns %TRUE if any of the parents of the widget represented - * in @path is of type @type, or any subtype of it. - * - * Returns: %TRUE if any parent is of type @type - **/ -gboolean -gtk_widget_path_has_parent (const GtkWidgetPath *path, - GType type) -{ - guint i; - - gtk_internal_return_val_if_fail (path != NULL, FALSE); - - for (i = 0; i < path->elems->len - 1; i++) - { - GtkPathElement *elem; - - elem = &g_array_index (path->elems, GtkPathElement, i); - - if (g_type_is_a (gtk_css_node_declaration_get_type (elem->decl), type)) - return TRUE; - } - - return FALSE; -} diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h deleted file mode 100644 index 5a03775985..0000000000 --- a/gtk/gtkwidgetpath.h +++ /dev/null @@ -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__ */ diff --git a/gtk/gtkwidgetpathprivate.h b/gtk/gtkwidgetpathprivate.h deleted file mode 100644 index 5a7bfb5388..0000000000 --- a/gtk/gtkwidgetpathprivate.h +++ /dev/null @@ -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__ */ diff --git a/gtk/meson.build b/gtk/meson.build index 374d0128c7..99b8b5cda3 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -79,7 +79,6 @@ gtk_private_sources = files([ 'gtkcssnumbervalue.c', 'gtkcsspalettevalue.c', 'gtkcssparser.c', - 'gtkcsspathnode.c', 'gtkcsspositionvalue.c', 'gtkcssrepeatvalue.c', 'gtkcssselector.c', @@ -397,7 +396,6 @@ gtk_public_sources = files([ 'gtkwidget.c', 'gtkwidgetfocus.c', 'gtkwidgetpaintable.c', - 'gtkwidgetpath.c', 'gtkwindow.c', 'gtkwindowgroup.c', ]) @@ -630,7 +628,6 @@ gtk_public_headers = files([ 'gtkvolumebutton.h', 'gtkwidget.h', 'gtkwidgetpaintable.h', - 'gtkwidgetpath.h', 'gtkwindow.h', 'gtkwindowgroup.h', 'gtk-a11y.h', diff --git a/testsuite/gtk/firefox-stylecontext.c b/testsuite/gtk/firefox-stylecontext.c deleted file mode 100644 index f02cb3aaf5..0000000000 --- a/testsuite/gtk/firefox-stylecontext.c +++ /dev/null @@ -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 (); -} diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index 9f67fbea71..e721ceaf49 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -28,7 +28,6 @@ tests = [ ['entry'], ['filterlistmodel'], ['flattenlistmodel'], - ['firefox-stylecontext'], ['floating'], ['focus'], ['gestures'], diff --git a/testsuite/gtk/stylecontext.c b/testsuite/gtk/stylecontext.c index 5bdfadfc56..a4d4d44435 100644 --- a/testsuite/gtk/stylecontext.c +++ b/testsuite/gtk/stylecontext.c @@ -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 (); } |