Exemplo n.º 1
0
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 = &GTK_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;
}
Exemplo n.º 2
0
gboolean
_gtk_css_matcher_init (GtkCssMatcher       *matcher,
                       const GtkWidgetPath *path,
                       GtkStateFlags        state)
{
  if (gtk_widget_path_length (path) == 0)
    return FALSE;

  matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
  matcher->path.path = path;
  matcher->path.state_flags = state;
  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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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));
}
Exemplo n.º 5
0
static GtkWidgetPath*
anjuta_tabber_get_path_for_child (GtkContainer* container,
                                  GtkWidget* widget)
{
	AnjutaTabber* tabber = ANJUTA_TABBER (container);

	GtkWidgetPath* path;
	gint page_num;;
	gint tabber_pos;

	path = GTK_CONTAINER_CLASS (anjuta_tabber_parent_class)->get_path_for_child (container, widget);

	page_num = g_list_index (tabber->priv->children, widget);
	if (page_num == -1)
		return path;

	tabber_pos = gtk_widget_path_length (path) - 2;
	gtk_widget_path_iter_add_region (path, tabber_pos, GTK_STYLE_REGION_TAB,
	                                 anjuta_tabber_get_region_flags (tabber, page_num));
	return path;
}
Exemplo n.º 6
0
static GtkWidgetPath *
gtk_css_path_node_real_create_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (path_node->path == NULL)
    path = gtk_widget_path_new ();
  else
    path = gtk_widget_path_copy (path_node->path);

  length = gtk_widget_path_length (path);
  if (length > 0)
    {
      gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
                                                   path,
                                                   length - 1);
    }

  return path;
}
Exemplo n.º 7
0
static GtkWidgetPath *
gtk_css_widget_node_create_widget_path (GtkCssNode *node)
{
  GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (widget_node->widget == NULL)
    path = gtk_widget_path_new ();
  else
    path = _gtk_widget_create_path (widget_node->widget);
  
  length = gtk_widget_path_length (path);
  if (length > 0)
    {
      gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
                                                   path,
                                                   length - 1);
    }

  return path;
}
Exemplo n.º 8
0
static VALUE
rg_length(VALUE self)
{
    return INT2NUM(gtk_widget_path_length(_SELF(self)));
}
Exemplo n.º 9
0
/**
 * 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.
 *
 * Since: 3.2
 **/
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;
      GList *list, *regions;

      elem = &g_array_index (path->elems, GtkPathElement, i);

      if (i > 0)
        g_string_append_c (string, ' ');

      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]));
        }

      regions = gtk_css_node_declaration_list_regions (elem->decl);
      for (list = regions; list; list = list->next)
        {
          static const char *flag_names[] = {
            "even",
            "odd",
            "first",
            "last",
            "only",
            "sorted"
          };
          GtkRegionFlags flags;
          GQuark region = GPOINTER_TO_UINT (regions->data);

          gtk_css_node_declaration_has_region (elem->decl, region, &flags);
          g_string_append_c (string, ' ');
          g_string_append (string, g_quark_to_string (region));
          for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
            {
              if (flags & (1 << j))
                {
                  g_string_append_c (string, ':');
                  g_string_append (string, flag_names[j]);
                }
            }
        }
      g_list_free (regions);
    }

  return g_string_free (string, FALSE);
}
Exemplo n.º 10
0
/**
 * 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.
 *
 * Since: 3.2
 **/
char *
gtk_widget_path_to_string (const GtkWidgetPath *path)
{
    GString *string;
    guint i, j;

    g_return_val_if_fail (path != NULL, NULL);

    string = g_string_new ("");

    for (i = 0; i < path->elems->len; i++)
    {
        GtkPathElement *elem;

        elem = &g_array_index (path->elems, GtkPathElement, i);

        if (i > 0)
            g_string_append_c (string, ' ');

        g_string_append (string, g_type_name (elem->type));

        if (elem->name)
        {
            g_string_append_c (string, '(');
            g_string_append (string, g_quark_to_string (elem->name));
            g_string_append_c (string, ')');
        }


        if (elem->siblings)
            g_string_append_printf (string, "[%d/%d]",
                                    elem->sibling_index + 1,
                                    gtk_widget_path_length (elem->siblings));

        if (elem->classes)
        {
            for (j = 0; j < elem->classes->len; j++)
            {
                g_string_append_c (string, '.');
                g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
            }
        }

        if (elem->regions)
        {
            GHashTableIter iter;
            gpointer key, value;

            g_hash_table_iter_init (&iter, elem->regions);
            while (g_hash_table_iter_next (&iter, &key, &value))
            {
                GtkRegionFlags flags = GPOINTER_TO_UINT (value);
                static const char *flag_names[] = {
                    "even",
                    "odd",
                    "first",
                    "last",
                    "only",
                    "sorted"
                };

                g_string_append_c (string, ' ');
                g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
                for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
                {
                    if (flags & (1 << j))
                    {
                        g_string_append_c (string, ':');
                        g_string_append (string, flag_names[j]);
                    }
                }
            }
        }
    }

    return g_string_free (string, FALSE);
}