Ejemplo n.º 1
0
static void
serialize_icon_sources (gchar *icon_name, GList *sources, GString *string)
{
  GList *l;

  for (l = sources; l; l = g_list_next (l))
    {
      GtkIconSource *source = l->data;
      GdkPixbuf *pixbuf;
      gchar *str;

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      pixbuf = gtk_icon_source_get_pixbuf (source);
G_GNUC_END_IGNORE_DEPRECATIONS
      str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");

      g_string_append_printf (string, "%s[%s] ", icon_name, str);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_direction_wildcarded (source))
        {
          GtkTextDirection direction = gtk_icon_source_get_direction (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          str =
              glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION,
                                                  direction);
          g_string_append_printf (string, "dir-%s ", str);
          g_free (str);
        }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_size_wildcarded (source))
        {
          GtkIconSize size = gtk_icon_source_get_size (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
          g_string_append_printf (string, "size-%s ", str);
          g_free (str);
        }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_state_wildcarded (source))
        {
          GtkStateType state = gtk_icon_source_get_state (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
          g_string_append_printf (string, "state-%s ", str);
          g_free (str);
        }

      g_string_append_printf (string, "| ");
    }
}
Ejemplo n.º 2
0
Archivo: gtkrender.c Proyecto: Vort/gtk
/**
 * gtk_render_icon_pixbuf:
 * @context: a #GtkStyleContext
 * @source: the #GtkIconSource specifying the icon to render
 * @size: (type int): the size (#GtkIconSize) to render the icon at.
 *        A size of `(GtkIconSize) -1` means render at the size of the source
 *        and don’t scale.
 *
 * Renders the icon specified by @source at the given @size, returning the result
 * in a pixbuf.
 *
 * Returns: (transfer full): a newly-created #GdkPixbuf containing the rendered icon
 *
 * Since: 3.0
 *
 * Deprecated: 3.10: Use gtk_icon_theme_load_icon() instead.
 **/
GdkPixbuf *
gtk_render_icon_pixbuf (GtkStyleContext     *context,
                        const GtkIconSource *source,
                        GtkIconSize          size)
{
  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
  g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL);
  g_return_val_if_fail (source != NULL, NULL);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
  return gtk_render_icon_pixbuf_unpacked (gtk_icon_source_get_pixbuf (source),
                                          gtk_icon_source_get_size_wildcarded (source) ? size : -1,
                                          gtk_icon_source_get_state_wildcarded (source)
                                          ? _gtk_css_icon_effect_value_get (
                                             _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_EFFECT))
                                          : GTK_CSS_ICON_EFFECT_NONE);
G_GNUC_END_IGNORE_DEPRECATIONS;
}
Ejemplo n.º 3
0
static GdkPixbuf *
render_icon (GtkStyle               *style,
	     const GtkIconSource    *source,
	     GtkTextDirection        direction,
	     GtkStateType            state,
	     GtkIconSize             size,
	     GtkWidget              *widget,
	     const gchar            *detail)
{
	int width = 1;
	int height = 1;
	GdkPixbuf *scaled;
	GdkPixbuf *stated;
	GdkPixbuf *base_pixbuf;
	GdkScreen *screen;
	GtkSettings *settings;

	/* Oddly, style can be NULL in this function, because
	 * GtkIconSet can be used without a style and if so
	 * it uses this function.
	 */

	base_pixbuf = gtk_icon_source_get_pixbuf (source);

	g_return_val_if_fail (base_pixbuf != NULL, NULL);

	if (widget && gtk_widget_has_screen (widget))
	{
		screen = gtk_widget_get_screen (widget);
		settings = gtk_settings_get_for_screen (screen);
	}
	else if (style->colormap)
	{
		screen = gdk_colormap_get_screen (style->colormap);
		settings = gtk_settings_get_for_screen (screen);
	}
	else
	{
		settings = gtk_settings_get_default ();
		GTK_NOTE (MULTIHEAD,
			  g_warning ("Using the default screen for gtk_default_render_icon()"));
	}

	if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
	{
		g_warning (G_STRLOC ": invalid icon size '%d'", size);
		return NULL;
	}

	/* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
	 * leave it alone.
	 */
	if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
		scaled = scale_or_ref (base_pixbuf, width, height);
	else
		scaled = g_object_ref (base_pixbuf);

	/* If the state was wildcarded, then generate a state. */
	if (gtk_icon_source_get_state_wildcarded (source))
	{
		if (state == GTK_STATE_INSENSITIVE)
		{
			stated = set_transparency (scaled, 0.3);
			gdk_pixbuf_saturate_and_pixelate (stated, stated, 0.1, FALSE);

			g_object_unref (scaled);
		}
		else if (state == GTK_STATE_PRELIGHT)
		{
			stated = gdk_pixbuf_copy (scaled);

			gdk_pixbuf_saturate_and_pixelate (scaled, stated, 1.2, FALSE);

			g_object_unref (scaled);
		}
		else
		{
			stated = scaled;
		}
	}
	else
		stated = scaled;

	return stated;
}
Ejemplo n.º 4
0
static void
write_icon_sources (gchar *icon_name, GList *sources, SourceWriteTab *tab)
{
  GladeXmlNode *source_node;
  GtkIconSource *source;
  GList *l;
  gchar *string;

  GdkPixbuf *pixbuf;

  for (l = sources; l; l = l->next)
    {
      source = l->data;

      source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE);
      glade_xml_node_append_child (tab->node, source_node);

      glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID,
                                          icon_name);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_direction_wildcarded (source))
        {
          GtkTextDirection direction = gtk_icon_source_get_direction (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          string =
              glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION,
                                                  direction);
          glade_xml_node_set_property_string (source_node, GLADE_TAG_DIRECTION,
                                              string);
          g_free (string);
        }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_size_wildcarded (source))
        {
          GtkIconSize size = gtk_icon_source_get_size (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          string =
              glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
          glade_xml_node_set_property_string (source_node, GLADE_TAG_SIZE,
                                              string);
          g_free (string);
        }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      if (!gtk_icon_source_get_state_wildcarded (source))
        {
          GtkStateType state = gtk_icon_source_get_state (source);
G_GNUC_END_IGNORE_DEPRECATIONS
          string =
              glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
          glade_xml_node_set_property_string (source_node, GLADE_TAG_STATE,
                                              string);
          g_free (string);
        }

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      pixbuf = gtk_icon_source_get_pixbuf (source);
G_GNUC_END_IGNORE_DEPRECATIONS
      string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");

      glade_xml_node_set_property_string (source_node,
                                          GLADE_TAG_FILENAME, string);
    }
}
Ejemplo n.º 5
0
static void
populate_store_foreach (const gchar * icon_name,
                        GList * sources, GladeEPropIconSources * eprop_sources)
{
  GtkIconSource *source;
  GtkTreeIter parent_iter, iter;
  GList *l;

  /* Update the comboboxentry's store here... */
  gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT (eprop_sources->combo), -1, icon_name, icon_name);
  gtk_combo_box_set_active_id (GTK_COMBO_BOX (eprop_sources->combo), icon_name);

  /* Dont set COLUMN_ICON_NAME here */
  gtk_tree_store_append (eprop_sources->store, &parent_iter, NULL);
  gtk_tree_store_set (eprop_sources->store, &parent_iter,
                      COLUMN_TEXT, icon_name,
                      COLUMN_TEXT_EDITABLE, FALSE,
                      COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, -1);

  for (l = sources; l; l = l->next)
    {
      GdkPixbuf *pixbuf;
      gchar *str;

      source = l->data;
      pixbuf = gtk_icon_source_get_pixbuf (source);
      str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");

      gtk_tree_store_append (eprop_sources->store, &iter, &parent_iter);
      gtk_tree_store_set (eprop_sources->store, &iter,
                          COLUMN_ICON_NAME, icon_name,
                          COLUMN_LIST_INDEX, g_list_index (sources, source),
                          COLUMN_TEXT, str,
                          COLUMN_TEXT_EDITABLE, TRUE,
                          COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, -1);

      if (!gtk_icon_source_get_direction_wildcarded (source))
        {
          GtkTextDirection direction = gtk_icon_source_get_direction (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_TEXT_DIRECTION, direction);
          gtk_tree_store_set (eprop_sources->store, &iter,
                              COLUMN_DIRECTION_ACTIVE, TRUE, COLUMN_DIRECTION,
                              str, -1);
          g_free (str);
        }

      if (!gtk_icon_source_get_size_wildcarded (source))
        {
          GtkIconSize size = gtk_icon_source_get_size (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_ICON_SIZE, size);
          gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_SIZE_ACTIVE,
                              TRUE, COLUMN_SIZE, str, -1);
          g_free (str);
        }

      if (!gtk_icon_source_get_state_wildcarded (source))
        {
          GtkStateType state = gtk_icon_source_get_state (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_STATE_TYPE, state);
          gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_STATE_ACTIVE,
                              TRUE, COLUMN_STATE, str, -1);
          g_free (str);
        }

      if (!l->next)
        {
          GtkTreePath *path =
              gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store),
                                       &iter);
          gtk_tree_view_expand_to_path (GTK_TREE_VIEW (eprop_sources->view),
                                        path);
          gtk_tree_path_free (path);
        }
    }
}