Esempio n. 1
0
void
gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
                                             GtkWidgetPath               *path,
                                             guint                        pos)
{
  GQuark *classes;
  GtkRegion *regions;
  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 regions */
  regions = get_regions (decl);
  for (i = 0; i < decl->n_regions; i++)
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      gtk_widget_path_iter_add_region (path, pos,
                                       g_quark_to_string (regions[i].class_quark),
                                       regions[i].flags);
G_GNUC_END_IGNORE_DEPRECATIONS
    }

  /* Set widget classes */
  classes = get_classes (decl);
  for (i = 0; i < decl->n_classes; i++)
    {
      gtk_widget_path_iter_add_qclass (path, pos, classes[i]);
    }

  /* Set widget state */
  gtk_widget_path_iter_set_state (path, pos, decl->state);
}
Esempio n. 2
0
static GtkStyleContext* StyleContext(
    GtkStyleContext* parent,
    GtkWidgetPath* path,
    GType type,
    const char* objectName,
    const char* className1 = NULL,
    const char* className2 = NULL)
{
    gtk_widget_path_append_type(path, type);
#if GTK_CHECK_VERSION(3,20,0)
    if (gtk_check_version(3,20,0) == NULL)
        gtk_widget_path_iter_set_object_name(path, -1, objectName);
#endif
    if (className1)
        gtk_widget_path_iter_add_class(path, -1, className1);
    if (className2)
        gtk_widget_path_iter_add_class(path, -1, className2);
    GtkStyleContext* sc = gtk_style_context_new();
    gtk_style_context_set_path(sc, path);
    if (parent)
    {
#if GTK_CHECK_VERSION(3,4,0)
        if (gtk_check_version(3,4,0) == NULL)
            gtk_style_context_set_parent(sc, parent);
#endif
        g_object_unref(parent);
    }
    return sc;
}
Esempio n. 3
0
void
plank_compat_gtk_widget_path_iter_set_object_name (GtkWidgetPath *path, gint pos, const char *name)
{
	if (gtk_widget_path_iter_set_object_name) {
		gtk_widget_path_iter_set_object_name (path, pos, name);
	}
}
void getTooltipColors_GtkWidgetPath()
{
#if GTK_CHECK_VERSION(3,20,0)
	if (0 != gtk_check_version(3, 20, 0))
	{
		// 'gtk_widget_path_iter_set_object_name' was introduced in 3.20.0
		printf("With GtkWidgetPath:    Requires 3.20.0\n");
		return;
	}

	// Foreground color is taken from 'tooltip label' css node
	GtkStyleContext* styleContextLabel = gtk_style_context_new();
	{
		GtkWidgetPath* widgetPath = gtk_widget_path_new();
		gtk_widget_path_append_type(widgetPath, 0);
		gtk_widget_path_iter_set_object_name(widgetPath, -1, "tooltip");
		gtk_widget_path_iter_add_class(widgetPath, -1, GTK_STYLE_CLASS_BACKGROUND);
		gtk_widget_path_append_type(widgetPath, GTK_TYPE_LABEL);
		gtk_style_context_set_path(styleContextLabel, widgetPath);
		gtk_widget_path_free(widgetPath);
	}

	// Background color is taken from 'tooltip.background' css node
	GtkStyleContext* styleContextTooltip = gtk_style_context_new();
	{
		GtkWidgetPath* widgetPath = gtk_widget_path_new();
		gtk_widget_path_append_type(widgetPath, 0);
		gtk_widget_path_iter_set_object_name(widgetPath, -1, "tooltip");
		gtk_widget_path_iter_add_class(widgetPath, -1, GTK_STYLE_CLASS_BACKGROUND);
		gtk_style_context_set_path(styleContextTooltip, widgetPath);
		gtk_widget_path_free(widgetPath);
	}

	// Print
	printTooltipColors(styleContextLabel, styleContextTooltip, "GtkWidgetPath");

	// Destroy temporary style contexts
	g_object_unref(styleContextLabel);
	g_object_unref(styleContextTooltip);
#endif // GTK_CHECK_VERSION(3,20,0)
}
Esempio n. 5
0
static GtkStyleContext* TooltipContext(GtkWidgetPath* path)
{
    gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
#if GTK_CHECK_VERSION(3,20,0)
    if (gtk_check_version(3,20,0) == NULL)
        gtk_widget_path_iter_set_object_name(path, -1, "tooltip");
#endif
    gtk_widget_path_iter_add_class(path, -1, "background");
    gtk_widget_path_iter_add_class(path, -1, "tooltip");
    gtk_widget_path_iter_set_name(path, -1, "gtk-tooltip");
    GtkStyleContext* sc = gtk_style_context_new();
    gtk_style_context_set_path(sc, path);
    return sc;
}
void testColors()
{
	for (int testBits = 0; testBits < (1 << 4); testBits++)
	{
		GdkRGBA colorFore;
		{
			GtkWidgetPath* widgetPath = gtk_widget_path_new();
			gint pathPos = gtk_widget_path_append_type(widgetPath, gtk_tooltip_get_type());

			#if GTK_CHECK_VERSION(3,20,0)
			if (testBits & 1)
				gtk_widget_path_iter_set_object_name(widgetPath, pathPos, "tooltip");
			#else
			// Silence the warning
			(void)pathPos;
			#endif

			if (testBits & 2)
				gtk_widget_path_append_type(widgetPath, gtk_label_get_type());

			GtkStyleContext* styleContext = gtk_style_context_new();
			gtk_style_context_set_path(styleContext, widgetPath);
			gtk_widget_path_free(widgetPath);

			if (testBits & 4)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BACKGROUND);

			if (testBits & 8)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TOOLTIP);

			gtk_style_context_get_color(styleContext, GTK_STATE_FLAG_NORMAL, &colorFore);

			g_object_unref(styleContext);
		}

		GdkRGBA colorBack;
		{
			GtkWidgetPath* widgetPath = gtk_widget_path_new();
			gint pathPos = gtk_widget_path_append_type(widgetPath, gtk_tooltip_get_type());

			#if GTK_CHECK_VERSION(3,20,0)
			if (testBits & 1)
				gtk_widget_path_iter_set_object_name(widgetPath, pathPos, "tooltip");
			#else
			// Silence the warning
			(void)pathPos;
			#endif

			if (testBits & 2)
				gtk_widget_path_append_type(widgetPath, gtk_label_get_type());

			GtkStyleContext* styleContext = gtk_style_context_new();
			gtk_style_context_set_path(styleContext, widgetPath);
			gtk_widget_path_free(widgetPath);

			if (testBits & 4)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BACKGROUND);

			if (testBits & 8)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TOOLTIP);

			gtk_style_context_get_background_color(styleContext, GTK_STATE_FLAG_NORMAL, &colorBack);

			g_object_unref(styleContext);
		}

		printf
		(
			"%c%c%c%c fore=%s back=%s\n",
			(testBits & 1) ? '1' : '-',
			(testBits & 2) ? '2' : '-',
			(testBits & 4) ? '3' : '-',
			(testBits & 8) ? '4' : '-',
			format_GdkRGBA(colorFore).c_str(),
			format_GdkRGBA(colorBack).c_str()
		);
	}
}
Esempio n. 7
0
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);
    }
}