static GtkIconSource* make_icon_source (const gchar *icon, const gchar *base, const gchar *ext, GtkIconSize size) { GtkIconSource *source; gchar *filename; filename = g_strdup_printf ("%s/%s/%s.%s", PIXMAPSDIR, base, icon, ext); source = gtk_icon_source_new (); gtk_icon_source_set_filename (source, filename); gtk_icon_source_set_direction_wildcarded (source, TRUE); gtk_icon_source_set_state_wildcarded (source, TRUE); if (size == -1) { gtk_icon_source_set_size_wildcarded (source, TRUE); } else { gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_icon_source_set_size (source, size); } g_free(filename); return source; }
static void register_bidi_stock_icon (GtkIconFactory *factory, const gchar *stock_id, const gchar *icon_name_ltr, const gchar *icon_name_rtl) { GtkIconSet *set = gtk_icon_set_new (); GtkIconSource *source = gtk_icon_source_new (); gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR); gtk_icon_source_set_direction_wildcarded (source, FALSE); gtk_icon_source_set_size_wildcarded (source, TRUE); gtk_icon_source_set_state_wildcarded (source, TRUE); gtk_icon_source_set_icon_name (source, icon_name_ltr); gtk_icon_set_add_source (set, source); gtk_icon_source_free (source); source = gtk_icon_source_new (); gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL); gtk_icon_source_set_direction_wildcarded (source, FALSE); gtk_icon_source_set_size_wildcarded (source, TRUE); gtk_icon_source_set_state_wildcarded (source, TRUE); gtk_icon_source_set_icon_name (source, icon_name_rtl); gtk_icon_set_add_source (set, source); gtk_icon_source_free (source); gtk_icon_factory_add (factory, stock_id, set); gtk_icon_set_unref (set); }
static void add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme, const char *size, SizedStockIcon sized_icon, gboolean translucent) { char *filename; GtkIconSource *source; GdkPixbuf *pixbuf; filename = find_icon_file(theme, size, sized_icon, FALSE); g_return_if_fail(filename != NULL); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); if (translucent) do_alphashift(pixbuf, pixbuf); source = gtk_icon_source_new(); gtk_icon_source_set_pixbuf(source, pixbuf); gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR); gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl); gtk_icon_source_set_size(source, sizeid); gtk_icon_source_set_size_wildcarded(source, FALSE); gtk_icon_source_set_state_wildcarded(source, TRUE); gtk_icon_set_add_source(iconset, source); gtk_icon_source_free(source); if (sizeid == gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL)) { source = gtk_icon_source_new(); gtk_icon_source_set_pixbuf(source, pixbuf); gtk_icon_source_set_direction_wildcarded(source, TRUE); gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU); gtk_icon_source_set_size_wildcarded(source, FALSE); gtk_icon_source_set_state_wildcarded(source, TRUE); gtk_icon_set_add_source(iconset, source); gtk_icon_source_free(source); } g_free(filename); g_object_unref(pixbuf); if (sized_icon.rtl) { filename = find_icon_file(theme, size, sized_icon, TRUE); g_return_if_fail(filename != NULL); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); if (translucent) do_alphashift(pixbuf, pixbuf); source = gtk_icon_source_new(); gtk_icon_source_set_pixbuf(source, pixbuf); gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL); gtk_icon_source_set_size(source, sizeid); gtk_icon_source_set_size_wildcarded(source, FALSE); gtk_icon_source_set_state_wildcarded(source, TRUE); gtk_icon_set_add_source(iconset, source); g_free(filename); g_object_unref(pixbuf); gtk_icon_source_free(source); } }
void camorama_stock_init(void) { GtkIconFactory* factory = gtk_icon_factory_new(); GtkIconSet * set = gtk_icon_set_new (); GtkIconSource * source = gtk_icon_source_new(); gtk_stock_add_static(camorama_items, G_N_ELEMENTS(camorama_items)); gtk_icon_source_set_size_wildcarded(source, TRUE); gtk_icon_source_set_direction_wildcarded(source, TRUE); gtk_icon_source_set_state_wildcarded(source, TRUE); gtk_icon_source_set_icon_name(source, CAMORAMA_STOCK_WEBCAM); gtk_icon_set_add_source(set, source); gtk_icon_factory_add(factory, CAMORAMA_STOCK_WEBCAM, set); add_default_image(CAMORAMA_STOCK_WEBCAM, 16, camorama_webcam_16); add_default_image(CAMORAMA_STOCK_WEBCAM, 24, camorama_webcam_24); gtk_icon_factory_add_default(factory); gtk_icon_set_unref(set); gtk_icon_source_free(source); }
static GdkPixbuf * ensure_stated_pixbuf_from_pixbuf (GtkIconHelper *self, GtkStyleContext *context, GdkPixbuf *pixbuf) { GdkPixbuf *rendered; GtkIconSource *source; G_GNUC_BEGIN_IGNORE_DEPRECATIONS; /* FIXME: use gtk_icon_info_load_icon? */ source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, pixbuf); /* The size here is arbitrary; since size isn't * wildcarded in the source, it isn't supposed to be * scaled by the engine function */ gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1); gtk_icon_source_free (source); G_GNUC_END_IGNORE_DEPRECATIONS; return rendered; }
static void add_stock_icon (const gchar *stock_id, GtkIconSize size, const guint8 *inline_data) { GtkIconSource *source; GtkIconSet *set; GdkPixbuf *pixbuf; source = gtk_icon_source_new (); gtk_icon_source_set_size (source, size); gtk_icon_source_set_size_wildcarded (source, FALSE); pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL); gtk_icon_source_set_pixbuf (source, pixbuf); g_object_unref (pixbuf); set = gtk_icon_set_new (); gtk_icon_set_add_source (set, source); gtk_icon_source_free (source); gtk_icon_factory_add (mapobject_icon_factory, stock_id, set); gtk_icon_set_unref (set); }
static void value_attribute_toggled (GtkCellRendererToggle * cell_renderer, gchar * path, GladeEditorProperty * eprop) { GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); GladeProperty *property = glade_editor_property_get_property (eprop); GtkTreeIter iter; GladeIconSources *icon_sources = NULL; GtkIconSource *source; gchar *icon_name; gint index, edit_column; gboolean edit_column_active = FALSE; if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) return; edit_column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell_renderer), "attribute-column")); gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index, edit_column, &edit_column_active, -1); glade_property_get (property, &icon_sources); if (icon_sources) icon_sources = glade_icon_sources_copy (icon_sources); if (icon_sources && (source = get_icon_source (icon_sources, icon_name, index)) != NULL) { /* Note the reverse meaning of active toggles vs. wildcarded sources... */ switch (edit_column) { case COLUMN_DIRECTION_ACTIVE: gtk_icon_source_set_direction_wildcarded (source, edit_column_active); break; case COLUMN_SIZE_ACTIVE: gtk_icon_source_set_size_wildcarded (source, edit_column_active); break; case COLUMN_STATE_ACTIVE: gtk_icon_source_set_state_wildcarded (source, edit_column_active); break; default: break; } update_icon_sources (eprop, icon_sources); g_free (icon_name); return; } if (icon_sources) glade_icon_sources_free (icon_sources); g_free (icon_name); return; }
static void add_icon (GtkIconFactory *factory, const char *scalable_filename, const char *sized_filename, const char *stock_id) { GtkIconSet *set = gtk_icon_set_new (); GtkIconSource *src = gtk_icon_source_new (); if (scalable_filename) { char *res = g_strconcat ("res:gnm:pixmaps/", scalable_filename, NULL); GdkPixbuf *pix = go_gdk_pixbuf_load_from_file (res); if (pix) { gtk_icon_source_set_size_wildcarded (src, TRUE); gtk_icon_source_set_pixbuf (src, pix); gtk_icon_set_add_source (set, src); g_object_unref (pix); } else { g_warning ("Missing resource %s\n", res); } g_free (res); } /* * For now, don't register a fixed-sized icon as doing so without * catching style changes kills things like bug 302902. */ if (sized_filename && !scalable_filename) { char *res = g_strconcat ("res:gnm:pixmaps/", sized_filename, NULL); GdkPixbuf *pix = go_gdk_pixbuf_load_from_file (res); gtk_icon_source_set_size (src, GTK_ICON_SIZE_MENU); gtk_icon_source_set_size_wildcarded (src, FALSE); gtk_icon_source_set_pixbuf (src, pix); gtk_icon_set_add_source (set, src); g_object_unref (pix); g_free (res); } gtk_icon_factory_add (factory, stock_id, set); gtk_icon_set_unref (set); gtk_icon_source_free (src); }
static GtkIconSource* make_theme_source (const gchar *icon, GtkIconSize size) { GtkIconSource *source; source = gtk_icon_source_new (); gtk_icon_source_set_icon_name (source, icon); gtk_icon_source_set_direction_wildcarded (source, TRUE); gtk_icon_source_set_state_wildcarded (source, TRUE); if (size == -1) { gtk_icon_source_set_size_wildcarded (source, TRUE); } else { gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_icon_source_set_size (source, size); } return source; }
static void icon_set_from_inline (GtkIconSet *set, const guchar *inline_data, GtkIconSize size, GtkTextDirection direction, gboolean fallback) { GtkIconSource *source; GdkPixbuf *pixbuf; source = gtk_icon_source_new (); if (direction != GTK_TEXT_DIR_NONE) { gtk_icon_source_set_direction (source, direction); gtk_icon_source_set_direction_wildcarded (source, FALSE); } gtk_icon_source_set_size (source, size); gtk_icon_source_set_size_wildcarded (source, FALSE); pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL); g_assert (pixbuf); gtk_icon_source_set_pixbuf (source, pixbuf); g_object_unref (pixbuf); gtk_icon_set_add_source (set, source); if (fallback) { gtk_icon_source_set_size_wildcarded (source, TRUE); gtk_icon_set_add_source (set, source); } gtk_icon_source_free (source); }
static void icon_set_from_data (GtkIconSet *set, const guint8 *icon_data, const guint data_size, GtkIconSize size, gboolean fallback) { GtkIconSource *source; GdkPixbuf *pixbuf; GError *err = NULL; source = gtk_icon_source_new (); gtk_icon_source_set_size (source, size); gtk_icon_source_set_size_wildcarded (source, FALSE); pixbuf = gdk_pixbuf_new_from_inline (data_size, icon_data, FALSE, &err); if (err) { g_warning ("%s",err->message); g_error_free (err); err = NULL; g_object_unref (source); return; } gtk_icon_source_set_pixbuf (source, pixbuf); g_object_unref (pixbuf); gtk_icon_set_add_source (set, source); if (fallback) { gtk_icon_source_set_size_wildcarded (source, TRUE); gtk_icon_set_add_source (set, source); } gtk_icon_source_free (source); }
static void register_stock_icons (void) { GdkPixbuf *pixbuf; GtkIconFactory *icon_factory; GtkIconSet *icon_set; GtkIconSource *icon_source; gint i; icon_factory = gtk_icon_factory_new (); for (i = 0; xpms[i].name; i++) { icon_set = gtk_icon_set_new (); icon_source = gtk_icon_source_new (); pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) xpms[i].xpm); gtk_icon_source_set_pixbuf (icon_source, pixbuf); gtk_icon_source_set_direction_wildcarded (icon_source, TRUE); gtk_icon_source_set_state_wildcarded (icon_source, TRUE); if (! strcmp (xpms[i].name, GPA_STOCK_PUBLIC_KEY) || ! strcmp (xpms[i].name, GPA_STOCK_SECRET_KEY)) { /* FIXME: For the keylist icons, we disable scaling for now for best visual results. */ gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_LARGE_TOOLBAR); } gtk_icon_set_add_source (icon_set, icon_source); gtk_icon_source_free (icon_source); gtk_icon_factory_add (icon_factory, xpms[i].name, icon_set); gtk_icon_set_unref (icon_set); } /* Add a fake stock icon for the clipboard window. */ icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_PASTE); icon_set = gtk_icon_set_copy (icon_set); gtk_icon_factory_add (icon_factory, GPA_STOCK_CLIPBOARD, icon_set); /* Add a fake stock icon for the file manager window. */ icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_DIRECTORY); icon_set = gtk_icon_set_copy (icon_set); gtk_icon_factory_add (icon_factory, GPA_STOCK_FILEMAN, icon_set); gtk_icon_factory_add_default (icon_factory); g_object_unref (icon_factory); }
static GdkPixbuf * ensure_stated_icon_from_info (GtkIconHelper *self, GtkStyleContext *context, GtkIconInfo *info) { GdkPixbuf *destination = NULL; gboolean symbolic; symbolic = FALSE; if (info) destination = gtk_icon_info_load_symbolic_for_context (info, context, &symbolic, NULL); if (destination == NULL) { GtkIconSet *icon_set; icon_set = gtk_style_context_lookup_icon_set (context, GTK_STOCK_MISSING_IMAGE); destination = gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size); } else if (!symbolic) { GtkIconSource *source; GdkPixbuf *rendered; source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, destination); /* The size here is arbitrary; since size isn't * wildcarded in the source, it isn't supposed to be * scaled by the engine function */ gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1); gtk_icon_source_free (source); g_object_unref (destination); destination = rendered; } return destination; }
static void on_preview_expose_event (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data) { ScreenshotDialog *dialog = data; GdkPixbuf *pixbuf = NULL; gboolean free_pixbuf = FALSE; cairo_t *cr; /* Stolen from GtkImage. I really should just make the drawing area an * image some day */ if (gtk_widget_get_state (drawing_area) != GTK_STATE_NORMAL) { GtkIconSource *source; source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, dialog->preview_image); gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); pixbuf = gtk_style_render_icon (drawing_area->style, source, gtk_widget_get_direction (drawing_area), gtk_widget_get_state (drawing_area), (GtkIconSize) -1, drawing_area, "gtk-image"); free_pixbuf = TRUE; gtk_icon_source_free (source); } else { pixbuf = g_object_ref (dialog->preview_image); } cr = gdk_cairo_create (drawing_area->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); cairo_destroy (cr); g_object_unref (pixbuf); }
static void register_stock_icon (GtkIconFactory *factory, const gchar *stock_id, const gchar *icon_name) { GtkIconSet *set = gtk_icon_set_new (); GtkIconSource *source = gtk_icon_source_new (); gtk_icon_source_set_direction_wildcarded (source, TRUE); gtk_icon_source_set_size_wildcarded (source, TRUE); gtk_icon_source_set_state_wildcarded (source, TRUE); gtk_icon_source_set_icon_name (source, icon_name); gtk_icon_set_add_source (set, source); gtk_icon_source_free (source); gtk_icon_factory_add (factory, stock_id, set); gtk_icon_set_unref (set); }
static void add_stock_icon (const gchar *stock_id, GtkIconSize size, const guint8 *inline_data) { GtkIconSource *source; GtkIconSet *set; GdkPixbuf *pixbuf; source = gtk_icon_source_new (); gtk_icon_source_set_size (source, size); gtk_icon_source_set_size_wildcarded (source, FALSE); pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL); if(gap_debug) { printf("add_stock_icon stock_id:%s size:%d inline_data:%d pixbuf:%d\n" ,stock_id ,(int)size ,(int)inline_data ,(int)pixbuf ); } gtk_icon_source_set_pixbuf (source, pixbuf); g_object_unref (pixbuf); set = gtk_icon_set_new (); gtk_icon_set_add_source (set, source); gtk_icon_source_free (source); gtk_icon_factory_add (gap_icon_factory, stock_id, set); gtk_icon_set_unref (set); }
void pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme) { GtkIconFactory *icon_factory; gint i; GtkWidget *win; if (theme != NULL) { purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", purple_theme_get_name(PURPLE_THEME(theme))); purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", purple_theme_get_dir(PURPLE_THEME(theme))); } else { purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); } icon_factory = gtk_icon_factory_new(); gtk_icon_factory_add_default(icon_factory); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_realize(win); /* All non-sized icons */ for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { GtkIconSource *source; GtkIconSet *iconset; gchar *filename; if (stock_icons[i].dir == NULL) { /* GTK+ Stock icon */ iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), stock_icons[i].filename); } else { filename = find_file(stock_icons[i].dir, stock_icons[i].filename); if (filename == NULL) continue; source = gtk_icon_source_new(); gtk_icon_source_set_filename(source, filename); gtk_icon_source_set_direction_wildcarded(source, TRUE); gtk_icon_source_set_size_wildcarded(source, TRUE); gtk_icon_source_set_state_wildcarded(source, TRUE); iconset = gtk_icon_set_new(); gtk_icon_set_add_source(iconset, source); gtk_icon_source_free(source); g_free(filename); } gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); gtk_icon_set_unref(iconset); } /* All non-status sized icons */ for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) { GtkIconSet *iconset = gtk_icon_set_new(); #define ADD_SIZED_ICON(name, size) \ if (sized_stock_icons[i].name) \ add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE); ADD_SIZED_ICON(microscopic, "11"); ADD_SIZED_ICON(extra_small, "16"); ADD_SIZED_ICON(small, "22"); ADD_SIZED_ICON(medium, "32"); ADD_SIZED_ICON(large, "48"); ADD_SIZED_ICON(huge, "64"); #undef ADD_SIZED_ICON gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); gtk_icon_set_unref(iconset); } gtk_widget_destroy(win); g_object_unref(G_OBJECT(icon_factory)); reload_settings(); }
static void thunar_icon_renderer_render (GtkCellRenderer *renderer, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { ThunarClipboardManager *clipboard; ThunarFileIconState icon_state; ThunarIconRenderer *icon_renderer = THUNAR_ICON_RENDERER (renderer); ThunarIconFactory *icon_factory; GtkIconSource *icon_source; GtkIconTheme *icon_theme; GdkRectangle emblem_area; GdkRectangle icon_area; GdkRectangle draw_area; GtkStateType state; GdkPixbuf *emblem; GdkPixbuf *icon; GdkPixbuf *temp; GList *emblems; GList *lp; gint max_emblems; gint position; if (G_UNLIKELY (icon_renderer->file == NULL)) return; /* determine the icon state */ icon_state = (icon_renderer->drop_file != icon_renderer->file) ? renderer->is_expanded ? THUNAR_FILE_ICON_STATE_OPEN : THUNAR_FILE_ICON_STATE_DEFAULT : THUNAR_FILE_ICON_STATE_DROP; /* load the main icon */ icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); icon = thunar_icon_factory_load_file_icon (icon_factory, icon_renderer->file, icon_state, icon_renderer->size); if (G_UNLIKELY (icon == NULL)) { g_object_unref (G_OBJECT (icon_factory)); return; } /* pre-light the item if we're dragging about it */ if (G_UNLIKELY (icon_state == THUNAR_FILE_ICON_STATE_DROP)) flags |= GTK_CELL_RENDERER_PRELIT; /* determine the real icon size */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); /* scale down the icon on-demand */ if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height)) { /* scale down to fit */ temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height); g_object_unref (G_OBJECT (icon)); icon = temp; /* determine the icon dimensions again */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); } icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2; icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2; /* check whether the icon is affected by the expose event */ if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area)) { /* use a translucent icon to represent cutted and hidden files to the user */ clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (widget)); if (thunar_clipboard_manager_has_cutted_file (clipboard, icon_renderer->file)) { /* 50% translucent for cutted files */ temp = exo_gdk_pixbuf_lucent (icon, 50); g_object_unref (G_OBJECT (icon)); icon = temp; } else if (thunar_file_is_hidden (icon_renderer->file)) { /* 75% translucent for hidden files */ temp = exo_gdk_pixbuf_lucent (icon, 75); g_object_unref (G_OBJECT (icon)); icon = temp; } g_object_unref (G_OBJECT (clipboard)); /* colorize the icon if we should follow the selection state */ if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && icon_renderer->follow_state) { if ((flags & GTK_CELL_RENDERER_SELECTED) != 0) { state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]); g_object_unref (G_OBJECT (icon)); icon = temp; } if ((flags & GTK_CELL_RENDERER_PRELIT) != 0) { temp = exo_gdk_pixbuf_spotlight (icon); g_object_unref (G_OBJECT (icon)); icon = temp; } } /* check if we should render an insensitive icon */ if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive)) { /* allocate an icon source */ icon_source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (icon_source, icon); gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR); /* render the insensitive icon */ temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget), GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf"); g_object_unref (G_OBJECT (icon)); icon = temp; /* release the icon source */ gtk_icon_source_free (icon_source); } /* render the invalid parts of the icon */ gdk_draw_pixbuf (window, widget->style->black_gc, icon, draw_area.x - icon_area.x, draw_area.y - icon_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the file's icon */ g_object_unref (G_OBJECT (icon)); /* check if we should render emblems as well */ if (G_LIKELY (icon_renderer->emblems)) { /* display the primary emblem as well (if any) */ emblems = thunar_file_get_emblem_names (icon_renderer->file); if (G_UNLIKELY (emblems != NULL)) { /* render up to four emblems for sizes from 48 onwards, else up to 2 emblems */ max_emblems = (icon_renderer->size < 48) ? 2 : 4; /* render the emblems */ for (lp = emblems, position = 0; lp != NULL && position < max_emblems; lp = lp->next) { /* check if we have the emblem in the icon theme */ emblem = thunar_icon_factory_load_icon (icon_factory, lp->data, icon_renderer->size, NULL, FALSE); if (G_UNLIKELY (emblem == NULL)) continue; /* determine the dimensions of the emblem */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); /* shrink insane emblems */ if (G_UNLIKELY (MAX (emblem_area.width, emblem_area.height) > (gint) MIN ((2 * icon_renderer->size) / 3, 36))) { /* scale down the emblem */ temp = exo_gdk_pixbuf_scale_ratio (emblem, MIN ((2 * icon_renderer->size) / 3, 36)); g_object_unref (G_OBJECT (emblem)); emblem = temp; /* determine the size again */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); } /* determine a good position for the emblem, depending on the position index */ switch (position) { case 0: /* right/bottom */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 1: /* left/bottom */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 2: /* left/top */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; case 3: /* right/top */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; default: _thunar_assert_not_reached (); } /* render the emblem */ if (gdk_rectangle_intersect (expose_area, &emblem_area, &draw_area)) { gdk_draw_pixbuf (window, widget->style->black_gc, emblem, draw_area.x - emblem_area.x, draw_area.y - emblem_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the emblem */ g_object_unref (G_OBJECT (emblem)); /* advance the position index */ ++position; } /* release the emblem name list */ g_list_free (emblems); } } /* release our reference on the icon factory */ g_object_unref (G_OBJECT (icon_factory)); }
static void exo_cell_renderer_icon_render (GtkCellRenderer *renderer, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { const ExoCellRendererIconPrivate *priv = EXO_CELL_RENDERER_ICON_GET_PRIVATE (renderer); GtkIconSource *icon_source; GtkIconTheme *icon_theme; GdkRectangle icon_area; GdkRectangle draw_area; GtkStateType state; const gchar *filename; GtkIconInfo *icon_info = NULL; GdkPixbuf *icon = NULL; GdkPixbuf *temp; GError *err = NULL; gchar *display_name = NULL; gint *icon_sizes; gint icon_size; gint n; /* verify that we have an icon */ if (G_UNLIKELY (priv->icon == NULL && priv->gicon == NULL)) return; /* icon may be either an image file or a named icon */ if (priv->icon != NULL && g_path_is_absolute (priv->icon)) { /* load the icon via the thumbnail database */ icon = _exo_thumbnail_get_for_file (priv->icon, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err); } else if (priv->icon != NULL || priv->gicon != NULL) { /* determine the best icon size (GtkIconTheme is somewhat messy scaling up small icons) */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)); if (priv->icon != NULL) { icon_sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->icon); for (icon_size = -1, n = 0; icon_sizes[n] != 0; ++n) { /* we can use any size if scalable, because we load the file directly */ if (icon_sizes[n] == -1) icon_size = priv->size; else if (icon_sizes[n] > icon_size && icon_sizes[n] <= priv->size) icon_size = icon_sizes[n]; } g_free (icon_sizes); /* if we don't know any icon sizes at all, the icon is probably not present */ if (G_UNLIKELY (icon_size < 0)) icon_size = priv->size; /* lookup the icon in the icon theme */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, priv->icon, icon_size, 0); } else if (priv->gicon != NULL) { icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, priv->gicon, priv->size, GTK_ICON_LOOKUP_USE_BUILTIN); } if (G_UNLIKELY (icon_info == NULL)) return; /* check if we have an SVG icon here */ filename = gtk_icon_info_get_filename (icon_info); if (filename != NULL && g_str_has_suffix (filename, ".svg")) { /* loading SVG icons is terribly slow, so we try to use thumbnail instead, and we use the * real available cell area directly here, because loading thumbnails involves scaling anyway * and this way we need to the thumbnail pixbuf scale only once. */ icon = _exo_thumbnail_get_for_file (filename, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err); } else { /* regularly load the icon from the theme */ icon = gtk_icon_info_load_icon (icon_info, &err); } gtk_icon_info_free (icon_info); } /* check if we failed */ if (G_UNLIKELY (icon == NULL)) { /* better let the user know whats going on, might be surprising otherwise */ if (G_LIKELY (priv->icon != NULL)) { display_name = g_filename_display_name (priv->icon); } else if (G_UNLIKELY (priv->gicon != NULL && g_object_class_find_property (G_OBJECT_GET_CLASS (priv->gicon), "name"))) { g_object_get (priv->gicon, "name", &display_name, NULL); } if (display_name != NULL) { g_warning ("Failed to load \"%s\": %s", display_name, err->message); g_free (display_name); } g_error_free (err); return; } /* determine the real icon size */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); /* scale down the icon on-demand */ if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height)) { /* scale down to fit */ temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height); g_object_unref (G_OBJECT (icon)); icon = temp; /* determine the icon dimensions again */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); } icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2; icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2; /* check whether the icon is affected by the expose event */ if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area)) { /* colorize the icon if we should follow the selection state */ if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && priv->follow_state) { if ((flags & GTK_CELL_RENDERER_SELECTED) != 0) { state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]); g_object_unref (G_OBJECT (icon)); icon = temp; } if ((flags & GTK_CELL_RENDERER_PRELIT) != 0) { temp = exo_gdk_pixbuf_spotlight (icon); g_object_unref (G_OBJECT (icon)); icon = temp; } } /* check if we should render an insensitive icon */ if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive)) { /* allocate an icon source */ icon_source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (icon_source, icon); gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR); /* render the insensitive icon */ temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget), GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf"); g_object_unref (G_OBJECT (icon)); icon = temp; /* release the icon source */ gtk_icon_source_free (icon_source); } /* render the invalid parts of the icon */ gdk_draw_pixbuf (window, widget->style->black_gc, icon, draw_area.x - icon_area.x, draw_area.y - icon_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the file's icon */ g_object_unref (G_OBJECT (icon)); }
static void glade_gtk_icon_factory_read_sources (GladeWidget *widget, GladeXmlNode *node) { GladeIconSources *sources; GtkIconSource *source; GladeXmlNode *sources_node, *source_node; GValue *value; GList *list; gchar *current_icon_name = NULL; GdkPixbuf *pixbuf; if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL) return; sources = glade_icon_sources_new (); /* Here we expect all icon sets to remain together in the list. */ for (source_node = glade_xml_node_get_children (sources_node); source_node; source_node = glade_xml_node_next (source_node)) { gchar *icon_name; gchar *str; if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE)) continue; if (!(icon_name = glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL))) continue; if (! (str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL))) { g_free (icon_name); continue; } if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0) current_icon_name = (g_free (current_icon_name), g_strdup (icon_name)); G_GNUC_BEGIN_IGNORE_DEPRECATIONS source = gtk_icon_source_new (); G_GNUC_END_IGNORE_DEPRECATIONS /* Deal with the filename... */ value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, glade_widget_get_project (widget)); pixbuf = g_value_dup_object (value); g_value_unset (value); g_free (value); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_pixbuf (source, pixbuf); G_GNUC_END_IGNORE_DEPRECATIONS g_object_unref (G_OBJECT (pixbuf)); g_free (str); /* Now the attributes... */ if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_DIRECTION)) != NULL) { GtkTextDirection direction = glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_direction_wildcarded (source, FALSE); gtk_icon_source_set_direction (source, direction); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL) { GtkIconSize size = glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_icon_source_set_size (source, size); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL) { GtkStateType state = glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_state_wildcarded (source, FALSE); gtk_icon_source_set_state (source, state); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL) { GList *new_list = g_list_append (list, source); /* Warning: if we use g_list_prepend() the returned pointer will be different * so we would have to replace the list pointer in the hash table. * But before doing that we have to steal the old list pointer otherwise * we would have to make a copy then add the new icon to finally replace the hash table * value. * Anyways if we choose to prepend we would have to reverse the list outside this loop * so its better to append. */ if (new_list != list) { /* current g_list_append() returns the same pointer so this is not needed */ g_hash_table_steal (sources->sources, current_icon_name); g_hash_table_insert (sources->sources, g_strdup (current_icon_name), new_list); } } else { list = g_list_append (NULL, source); g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list); } } if (g_hash_table_size (sources->sources) > 0) glade_widget_property_set (widget, "sources", sources); glade_icon_sources_free (sources); }
static void gimp_cell_renderer_toggle_render (GtkCellRenderer *cell, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell); GdkRectangle toggle_rect; GdkRectangle draw_rect; GtkStyleContext *context = gtk_widget_get_style_context (widget); GdkRectangle clip_rect; GtkStateFlags state; gboolean active; gint xpad; gint ypad; if (! toggle->stock_id) { GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, cr, widget, background_area, cell_area, flags); return; } gtk_cell_renderer_get_size (cell, widget, cell_area, &toggle_rect.x, &toggle_rect.y, &toggle_rect.width, &toggle_rect.height); gtk_cell_renderer_get_padding (cell, &xpad, &ypad); toggle_rect.x += cell_area->x + xpad; toggle_rect.y += cell_area->y + ypad; toggle_rect.width -= xpad * 2; toggle_rect.height -= ypad * 2; if (toggle_rect.width <= 0 || toggle_rect.height <= 0) return; active = gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell)); if (!gtk_cell_renderer_get_sensitive (cell)) { state = GTK_STATE_FLAG_INSENSITIVE; } else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED) { if (gtk_widget_has_focus (widget)) state = GTK_STATE_FLAG_SELECTED; else state = GTK_STATE_FLAG_ACTIVE; } else { if (gtk_cell_renderer_toggle_get_activatable (GTK_CELL_RENDERER_TOGGLE (cell))) state = GTK_STATE_FLAG_NORMAL; else state = GTK_STATE_FLAG_INSENSITIVE; } if ((flags & GTK_CELL_RENDERER_PRELIT) && gdk_cairo_get_clip_rectangle(cr, &clip_rect) && gdk_rectangle_intersect (&clip_rect, cell_area, &draw_rect)) { cairo_save (cr); gdk_cairo_rectangle (cr, &draw_rect); cairo_clip (cr); gtk_render_frame (context, //gtk_widget_get_style_context (widget), cr, toggle_rect.x, toggle_rect.y, toggle_rect.width, toggle_rect.height); gtk_style_context_restore (context); cairo_restore (cr); } if (active) { GdkPixbuf *insensitive = NULL; GdkPixbuf *pixbuf = toggle->pixbuf; GtkBorder border = { 1, 1, 1, 1 }; #if 0 /* FIXME: for some reason calling gtk_style_context_get_border * makes the icon only visible on hover, so use border = 1 * for now as a workaround */ gtk_style_context_get_border (context, state, &border); #endif toggle_rect.x += border.left; toggle_rect.y += border.top; toggle_rect.width -= (border.left + border.right); toggle_rect.height -= (border.top + border.bottom); if (state & GTK_STATE_FLAG_INSENSITIVE) { GtkIconSource *source; source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, pixbuf); /* The size here is arbitrary; since size isn't * wildcarded in the source, it isn't supposed to be * scaled by the engine function */ gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_style_context_save (context); gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE); insensitive = gtk_render_icon_pixbuf (context, source, (GtkIconSize)-1); gtk_style_context_restore (context); gtk_icon_source_free (source); pixbuf = insensitive; } if (gdk_rectangle_intersect (&draw_rect, &toggle_rect, &draw_rect)) { gdk_cairo_set_source_pixbuf (cr, pixbuf, toggle_rect.x, toggle_rect.y); gdk_cairo_rectangle (cr, &draw_rect); cairo_fill (cr); } if (insensitive) g_object_unref (insensitive); } }