Esempio n. 1
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. 2
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;
}
Esempio n. 3
0
/* FIXME: this doesn't work */
static gboolean
draw_cb_activity (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;
  GtkWidgetPath *path;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_notify_state_change (context,
                                         gtk_widget_get_window (widget),
                                         NULL,
                                         GTK_STATE_FLAG_ACTIVE,
                                         TRUE);

  gtk_style_context_save (context);

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_SPINNER);
  gtk_widget_path_iter_add_class (path, 0, "spinner");
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
  gtk_render_activity (context, cr, 12, 12, 12, 12);

  gtk_style_context_restore (context);

  return TRUE;
}
Esempio n. 4
0
static VALUE
rg_iter_add_class(VALUE self, VALUE pos, VALUE name)
{
    gtk_widget_path_iter_add_class(_SELF(self), NUM2INT(pos), RVAL2CSTR(name));

    return self;
}
 ScrollbarStyleContext()
     : m_context(adoptGRef(gtk_style_context_new()))
 {
     GtkWidgetPath* path = gtk_widget_path_new();
     gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR);
     gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCROLLBAR);
     gtk_style_context_set_path(m_context.get(), path);
     gtk_widget_path_free(path);
 }
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. 7
0
static gboolean
draw_cb_slider (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;
  GtkWidgetPath *path;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save (context);

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_SCALE);
  gtk_widget_path_iter_add_class (path, 0, "slider");
  gtk_widget_path_iter_add_class (path, 0, "scale");
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  gtk_render_slider (context, cr, 12, 22, 30, 10, GTK_ORIENTATION_HORIZONTAL);
  gtk_render_slider (context, cr, 54, 12, 10, 30, GTK_ORIENTATION_VERTICAL);

  gtk_style_context_restore (context);

  return TRUE;
}
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, gtk_style_context_get_state (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, NULL);
  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, gtk_style_context_get_state (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);
}
static GtkStyleContext *
gd_tagged_entry_tag_get_context (GdTaggedEntryTag *tag,
                                 GdTaggedEntry    *entry)
{
    GtkWidget *widget = GTK_WIDGET (entry);
    GtkWidgetPath *path;
    gint pos;
    GtkStyleContext *retval;

    retval = gtk_style_context_new ();
    path = gtk_widget_path_copy (gtk_widget_get_path (widget));

    pos = gtk_widget_path_append_type (path, GD_TYPE_TAGGED_ENTRY);
    gtk_widget_path_iter_add_class (path, pos, tag->style);

    gtk_style_context_set_path (retval, path);

    gtk_widget_path_unref (path);

    return retval;
}
Esempio n. 10
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);
    }
}