static gint get_icon_margin (void) { gint toolbar_size, menu_size; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &menu_size, NULL); gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &toolbar_size, NULL); return (gint) floor ((toolbar_size - menu_size) / 2.0); }
static GdkPixbuf * get_image_pixbuf (GtkImage *image) { const gchar *icon_name; GtkIconSize size; GtkIconTheme *icon_theme; int width; switch (gtk_image_get_storage_type (image)) { case GTK_IMAGE_PIXBUF: return g_object_ref (gtk_image_get_pixbuf (image)); case GTK_IMAGE_ICON_NAME: gtk_image_get_icon_name (image, &icon_name, &size); icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (image))); gtk_icon_size_lookup (size, &width, NULL); return gtk_icon_theme_load_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); default: g_warning ("Image storage type %d not handled", gtk_image_get_storage_type (image)); return NULL; } }
/** Load/construct the images */ static void load_pixmaps(QuoteView * qv) { static gboolean init = FALSE; int width, height; GdkPixmap *pixmap; GdkGC *gc; if (init) return; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); pixmap = gdk_pixmap_new(qv->quotes->window, width, height, gtk_widget_get_visual(qv->quotes)->depth); gc = gdk_gc_new(pixmap); gdk_gc_set_fill(gc, GDK_TILED); gdk_gc_set_tile(gc, theme_get_terrain_pixmap(SEA_TERRAIN)); gdk_gc_set_foreground(gc, &black); gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, width, height); maritime_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, -1, -1); g_object_unref(pixmap); g_object_unref(gc); cross_pixbuf = gtk_widget_render_icon(qv->quotes, GTK_STOCK_CANCEL, GTK_ICON_SIZE_MENU, NULL); init = TRUE; }
static void gd_tagged_entry_tag_ensure_close_surface (GdTaggedEntryTag *tag, GtkStyleContext *context) { GtkIconInfo *info; GdkPixbuf *pixbuf; gint icon_size; gint scale_factor; if (tag->close_surface != NULL) return; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, NULL); scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (tag->entry)); info = gtk_icon_theme_lookup_icon_for_scale (gtk_icon_theme_get_default (), "window-close-symbolic", icon_size, scale_factor, GTK_ICON_LOOKUP_GENERIC_FALLBACK); /* FIXME: we need a fallback icon in case the icon is not found */ pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL); tag->close_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, tag->window); g_object_unref (info); g_object_unref (pixbuf); }
static void _on_add_filename(gchar const * pathname, gpointer data) { const char scheme[] = "file://"; Favorites * favorites = data; GtkTreeIter iter; struct stat st; gchar * filename; String * path; gint size = 24; GdkPixbuf * pixbuf; /* XXX ignore non-directories */ if(browser_vfs_stat(pathname, &st) != 0 || !S_ISDIR(st.st_mode)) return; if((filename = g_path_get_basename(pathname)) == NULL) return; if((path = string_new_append(scheme, pathname, NULL)) == NULL) return; gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &size, &size); if((pixbuf = browser_vfs_mime_icon(favorites->mime, pathname, NULL, NULL, &st, size)) == NULL) pixbuf = favorites->folder; #if GTK_CHECK_VERSION(2, 6, 0) gtk_list_store_insert_with_values(favorites->store, &iter, -1, #else gtk_list_store_append(favorites->store, &iter); gtk_list_store_set(favorites->store, &iter, #endif FC_ICON, pixbuf, FC_NAME, filename, FC_PATH, path, -1); string_delete(path); g_free(filename); _favorites_save(favorites); }
/* Finds the largest size at which the given image stock id is * available. This would not be useful for a normal application */ static GtkIconSize get_largest_size (const char *id) { GtkIconSet *set = gtk_icon_factory_lookup_default (id); GtkIconSize *sizes; gint n_sizes, i; GtkIconSize best_size = GTK_ICON_SIZE_INVALID; gint best_pixels = 0; gtk_icon_set_get_sizes (set, &sizes, &n_sizes); for (i = 0; i < n_sizes; i++) { gint width, height; gtk_icon_size_lookup (sizes[i], &width, &height); if (width * height > best_pixels) { best_size = sizes[i]; best_pixels = width * height; } } g_free (sizes); return best_size; }
static NAIOption * get_mode_from_struct( const NAImportModeStr *str ) { NAImportMode *mode; gint width, height; gchar *fname; GdkPixbuf *pixbuf; if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){ width = height = 48; } mode = na_import_mode_new( str->id ); pixbuf = NULL; if( str->image && g_utf8_strlen( str->image, -1 )){ fname = g_strdup_printf( "%s/%s", PKGIMPORTMODEDIR, str->image ); pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL ); g_free( fname ); } g_object_set( G_OBJECT( mode ), NA_IMPORT_PROP_MODE, str->mode, NA_IMPORT_PROP_LABEL, gettext( str->label ), NA_IMPORT_PROP_DESCRIPTION, gettext( str->description ), NA_IMPORT_PROP_IMAGE, pixbuf, NULL ); return( NA_IOPTION( mode )); }
/** * rb_scale_pixbuf_to_size: * @pixbuf: the #GdkPixbuf containing the original image * @size: a stock icon size * * Creates a new #GdkPixbuf from the original one, for a target of * size, respecting the aspect ratio of the image. */ GdkPixbuf * rb_scale_pixbuf_to_size (GdkPixbuf *pixbuf, GtkIconSize size) { int icon_size; int width, height; int d_width, d_height; g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); if (gtk_icon_size_lookup (size, &icon_size, NULL) == FALSE) return NULL; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); if (width > height) { d_width = icon_size; d_height = d_width * height / width; } else { d_height = icon_size; d_width = d_height * width / height; } return gdk_pixbuf_scale_simple (pixbuf, d_width, d_height, GDK_INTERP_BILINEAR); }
static void image_menuitem_set_size_request (GtkWidget *menuitem, GtkIconSize icon_size) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding, border; int border_width; int icon_height; int req_height; if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height)) return; /* If we don't have a pixmap for this menuitem * at least make sure its the same height as * the rest. * This is a bit ugly, since we should keep this in sync with what's in * gtk_menu_item_size_request() */ context = gtk_widget_get_style_context (menuitem); state = gtk_widget_get_state_flags (menuitem); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get_border (context, state, &border); border_width = gtk_container_get_border_width (GTK_CONTAINER (menuitem)); req_height = icon_height; req_height += (border_width * 2) + padding.top + padding.bottom + border.top + border.bottom; gtk_widget_set_size_request (menuitem, -1, req_height); }
void NotebookNoteAddin::initialize_tool_button() { gint icon_size = 16; gtk_icon_size_lookup(GTK_ICON_SIZE_SMALL_TOOLBAR, &icon_size, NULL); Gtk::Grid *grid = manage(new Gtk::Grid); grid->attach(*manage(new Gtk::Image( IconManager::obj().get_icon(IconManager::NOTEBOOK, icon_size))), 0, 0, 1, 1); m_label_widget = manage(new Gtk::Label); m_label_widget->set_vexpand(true); m_label_widget->set_valign(Gtk::ALIGN_CENTER); grid->attach(*m_label_widget, 1, 0, 1, 1); m_toolButton = Gtk::manage(new gnote::utils::ToolMenuButton(*grid, m_menu)); m_toolButton->set_tooltip_text(_("Place this note into a notebook")); m_show_menu_cid = m_menu->signal_show() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_menu_shown)); m_toolButton->show_all(); add_tool_item(m_toolButton, -1); update_notebook_button_label(); m_note_added_cid = NotebookManager::obj().signal_note_added_to_notebook() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_added_to_notebook)); m_note_removed_cid = NotebookManager::obj().signal_note_removed_from_notebook() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_removed_from_notebook)); get_note()->signal_tag_added() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_tag_added)); // TODO: Make sure this is handled in NotebookNoteAddin, too get_note()->signal_tag_removed() .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_note_tag_removed)); }
static CanvasItem* canvas_item_new (GtkWidget *widget, GtkToolButton *button, gdouble x, gdouble y) { CanvasItem *item = NULL; const gchar *icon_name; GdkPixbuf *pixbuf; GtkIconTheme *icon_theme; int width; icon_name = gtk_tool_button_get_icon_name (button); icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)); gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &width, NULL); pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); if (pixbuf) { item = g_slice_new0 (CanvasItem); item->pixbuf = pixbuf; item->x = x; item->y = y; } return item; }
static void panel_menu_bar_update_visibility (GSettings* settings, gchar* key, PanelMenuBar* menubar) { GtkWidget* image; gchar *str; GtkIconSize icon_size; gint icon_height; if (!GTK_IS_WIDGET (menubar)) return; gtk_widget_set_visible (GTK_WIDGET (menubar->priv->applications_item), g_settings_get_boolean (settings, PANEL_MENU_BAR_SHOW_APPLICATIONS_KEY)); gtk_widget_set_visible (GTK_WIDGET (menubar->priv->places_item), g_settings_get_boolean (settings, PANEL_MENU_BAR_SHOW_PLACES_KEY)); gtk_widget_set_visible (GTK_WIDGET (menubar->priv->desktop_item), g_settings_get_boolean (settings, PANEL_MENU_BAR_SHOW_DESKTOP_KEY)); if (g_settings_get_boolean (settings, PANEL_MENU_BAR_SHOW_ICON_KEY)) { str = g_settings_get_string (settings, PANEL_MENU_BAR_ICON_NAME_KEY); icon_size = panel_menu_bar_icon_get_size (); gtk_icon_size_lookup (icon_size, NULL, &icon_height); if (str != NULL && str[0] != 0) image = gtk_image_new_from_icon_name(str, icon_size); else image = gtk_image_new_from_icon_name(PANEL_ICON_MAIN_MENU, icon_size); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menubar->priv->applications_item), image); gtk_image_set_pixel_size (GTK_IMAGE (image), icon_height); g_free (str); } else gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menubar->priv->applications_item), NULL); }
image_menuitem_size_request (GtkWidget *menuitem, GtkRequisition *requisition, gpointer data) #endif { #if !GTK_CHECK_VERSION (3, 0, 0) GtkIconSize icon_size = (GtkIconSize) GPOINTER_TO_INT (data); #endif int icon_height; int req_height; if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height)) return; /* If we don't have a pixmap for this menuitem * at least make sure its the same height as * the rest. * This is a bit ugly, since we should keep this in sync with what's in * gtk_menu_item_size_request() */ req_height = icon_height; req_height += (gtk_container_get_border_width (GTK_CONTAINER (menuitem)) + (gtk_widget_get_style (menuitem))->ythickness) * 2; gtk_widget_set_size_request (menuitem, -1, req_height); }
/** * @param icon_size image size id * @return image size height * * Return the height of a specific image size. */ guint gxk_size_height (GtkIconSize icon_size) { gint height = 10; gtk_icon_size_lookup (icon_size, NULL, &height); return height; }
/** * rb_stock_icons_init: * * Initializes the stock icons, adding the necessary filesystem * locations to the GTK icon search path. Must be called on startup. */ void rb_stock_icons_init (void) { GtkIconTheme *theme = gtk_icon_theme_get_default (); int i; int icon_size; char *dot_icon_dir; /* add our icon search paths */ dot_icon_dir = g_build_filename (rb_user_data_dir (), "icons", NULL); gtk_icon_theme_append_search_path (theme, dot_icon_dir); g_free (dot_icon_dir); gtk_icon_theme_append_search_path (theme, SHARE_DIR G_DIR_SEPARATOR_S "icons"); #ifdef USE_UNINSTALLED_DIRS gtk_icon_theme_append_search_path (theme, SHARE_UNINSTALLED_DIR G_DIR_SEPARATOR_S "icons"); #endif /* add inline icons */ gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_size, NULL); for (i = 0; i < (int) G_N_ELEMENTS (inline_icons); i++) { GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_inline (-1, inline_icons[i].data, FALSE, NULL); g_assert (pixbuf); gtk_icon_theme_add_builtin_icon (inline_icons[i].name, icon_size, pixbuf); } }
RBVisualizerPage * rb_visualizer_page_new (GObject *plugin, RBShell *shell, GtkToggleAction *fullscreen, GtkWidget *popup) { GObject *page; GdkPixbuf *pixbuf; gint size; gtk_icon_size_lookup (RB_SOURCE_ICON_SIZE, &size, NULL); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "visualization", size, 0, NULL); page = g_object_new (RB_TYPE_VISUALIZER_PAGE, "plugin", plugin, "shell", shell, "name", _("Visual Effects"), "pixbuf", pixbuf, "fullscreen-action", fullscreen, "popup", popup, NULL); if (pixbuf != NULL) { g_object_unref (pixbuf); } return RB_VISUALIZER_PAGE (page); }
/** * @param icon_size image size id * @return image size width * * Return the width of a specific image size. */ guint gxk_size_width (GtkIconSize icon_size) { gint width = 10; gtk_icon_size_lookup (icon_size, &width, NULL); return width; }
static gboolean wp_button_press_cb (GtkWidget *widget, GdkEventButton *event, AppearanceData *data) { GtkCellRenderer *cell; GdkEventButton *button_event = (GdkEventButton *) event; if (event->type != GDK_BUTTON_PRESS) return FALSE; if (gtk_icon_view_get_item_at_pos (GTK_ICON_VIEW (widget), button_event->x, button_event->y, NULL, &cell)) { if (g_object_get_data (G_OBJECT (cell), "buttons")) { gint w, h; GtkCellRenderer *cell2 = NULL; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); if (gtk_icon_view_get_item_at_pos (GTK_ICON_VIEW (widget), button_event->x + w, button_event->y, NULL, &cell2) && cell == cell2) next_frame (data, cell, -1); else next_frame (data, cell, 1); return TRUE; } } return FALSE; }
void eek_preview_set_size_mappings( guint count, GtkIconSize const* sizes ) { gint width = 0; gint height = 0; gint smallest = 512; gint largest = 0; guint i = 0; guint delta = 0; for ( i = 0; i < count; ++i ) { gboolean worked = gtk_icon_size_lookup( sizes[i], &width, &height ); if ( worked ) { if ( width < smallest ) { smallest = width; } if ( width > largest ) { largest = width; } } } smallest = (smallest * 3) / 4; delta = largest - smallest; for ( i = 0; i < G_N_ELEMENTS(sizeThings); ++i ) { guint val = smallest + ( (i * delta) / (G_N_ELEMENTS(sizeThings) - 1) ); sizeThings[i].width = val; sizeThings[i].height = val; } setupDone = TRUE; }
static void ensure_icon_size (GtkIconHelper *self, GtkStyleContext *context, gint *width_out, gint *height_out) { gint width, height; if (self->priv->pixel_size != -1) { width = height = self->priv->pixel_size; } else if (!gtk_icon_size_lookup (self->priv->icon_size, &width, &height)) { if (self->priv->icon_size == GTK_ICON_SIZE_INVALID) { width = height = 0; } else { g_warning ("Invalid icon size %d\n", self->priv->icon_size); width = height = 24; } } *width_out = width; *height_out = height; }
static void on_notebook_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data) { GdkPixbuf *pixbuf; guint page_num; page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget)); if (page_num > 2) { GtkIconTheme *icon_theme; int width; icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)); gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &width, NULL); pixbuf = gtk_icon_theme_load_icon (icon_theme, (page_num % 2) ? "help-browser" : "process-stop", width, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0); g_object_unref (pixbuf); } }
void icons_load_throbber(GdkPixbuf *pbs[]) { const guint8 *data; int i; GdkPixbuf *pb; gint w, h; gtk_icon_size_lookup(GTK_ICON_SIZE_DIALOG, &w, &h); for (i = 0; i < THROBBER_COUNT; i++) { switch (i) { case 0: data = logjam_throbber_1; break; case 1: data = logjam_throbber_2; break; case 2: data = logjam_throbber_3; break; case 3: data = logjam_throbber_4; break; case 4: data = logjam_throbber_5; break; case 5: data = logjam_throbber_6; break; case 6: data = logjam_throbber_7; break; case 7: data = logjam_throbber_8; break; default: g_warning("tried to load unknown throbber %d.", i); return; } pb = gdk_pixbuf_new_from_inline(-1, data, FALSE, NULL); pbs[i] = gdk_pixbuf_scale_simple(pb, w, h, GDK_INTERP_BILINEAR); g_object_unref(G_OBJECT(pb)); } }
static void ido_source_menu_item_constructed (GObject *object) { IdoSourceMenuItem *item = IDO_SOURCE_MENU_ITEM (object); GtkWidget *grid; gint icon_width; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL); item->icon = g_object_ref (gtk_image_new ()); gtk_widget_set_margin_left (item->icon, icon_width); gtk_widget_set_margin_right (item->icon, 6); item->label = g_object_ref (gtk_label_new ("")); gtk_label_set_max_width_chars (GTK_LABEL (item->label), 40); gtk_label_set_ellipsize (GTK_LABEL (item->label), PANGO_ELLIPSIZE_END); gtk_misc_set_alignment (GTK_MISC (item->label), 0.0, 0.5); item->detail = g_object_ref (ido_detail_label_new ("")); gtk_widget_set_halign (item->detail, GTK_ALIGN_END); gtk_widget_set_hexpand (item->detail, TRUE); gtk_style_context_add_class (gtk_widget_get_style_context (item->detail), "accelerator"); grid = gtk_grid_new (); gtk_grid_attach (GTK_GRID (grid), item->icon, 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), item->label, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), item->detail, 2, 0, 1, 1); gtk_container_add (GTK_CONTAINER (object), grid); gtk_widget_show_all (grid); G_OBJECT_CLASS (ido_source_menu_item_parent_class)->constructed (object); }
/** * e_icon_factory_get_icon_filename: * @icon_name: name of the icon * @icon_size: size of the icon * * Returns the filename of the requested icon in the default icon theme. * * Returns: the filename of the requested icon **/ gchar * e_icon_factory_get_icon_filename (const gchar *icon_name, GtkIconSize icon_size) { GtkIconTheme *icon_theme; GtkIconInfo *icon_info; gchar *filename = NULL; gint width, height; g_return_val_if_fail (icon_name != NULL, NULL); icon_theme = gtk_icon_theme_get_default (); if (!gtk_icon_size_lookup (icon_size, &width, &height)) return NULL; icon_info = gtk_icon_theme_lookup_icon ( icon_theme, icon_name, height, 0); if (icon_info != NULL) { filename = g_strdup ( gtk_icon_info_get_filename (icon_info)); gtk_icon_info_free (icon_info); } return filename; }
static void menu_item_style_set (GtkImage *image, gpointer data) { GtkWidget *widget; GdkPixbuf *pixbuf; GtkIconSize icon_size = (GtkIconSize) GPOINTER_TO_INT (data); int icon_height; gboolean is_mapped; if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height)) return; pixbuf = gtk_image_get_pixbuf (image); if (!pixbuf) return; if (gdk_pixbuf_get_height (pixbuf) == icon_height) return; widget = GTK_WIDGET (image); is_mapped = gtk_widget_get_mapped (widget); if (is_mapped) gtk_widget_unmap (widget); gtk_image_set_from_pixbuf (image, NULL); if (is_mapped) gtk_widget_map (widget); }
GdkPixbuf * gedit_file_browser_utils_pixbuf_from_icon (GIcon *icon, GtkIconSize size) { GdkPixbuf *ret = NULL; GtkIconTheme *theme; GtkIconInfo *info; gint width; if (!icon) return NULL; theme = gtk_icon_theme_get_default (); gtk_icon_size_lookup (size, &width, NULL); info = gtk_icon_theme_lookup_by_gicon (theme, icon, width, GTK_ICON_LOOKUP_USE_BUILTIN); if (!info) return NULL; ret = gtk_icon_info_load_icon (info, NULL); g_object_unref (info); return ret; }
static void _new_contents_package(Helper * helper, char const * contentsdir, GtkTreeStore * store, char const * package) { const char ext[] = ".html"; gchar * p; DIR * dir; struct dirent * de; size_t len; GtkTreeIter parent; GtkTreeIter iter; gint size = 16; GdkPixbuf * pixbuf; if((p = g_strdup_printf("%s/%s", contentsdir, package)) == NULL) return; dir = opendir(p); g_free(p); if(dir == NULL) return; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &size, &size); pixbuf = gtk_icon_theme_load_icon(helper->icontheme, "folder", size, 0, NULL); #if GTK_CHECK_VERSION(2, 10, 0) gtk_tree_store_insert_with_values(store, &parent, NULL, -1, #else gtk_tree_store_insert(store, &parent, NULL, -1); gtk_tree_store_set(store, &parent, #endif HSC_TYPE, HST_CONTENTS, HSC_ICON, pixbuf, HSC_CONTENTS_PACKAGE, package, -1); if(pixbuf != NULL) { g_object_unref(pixbuf); pixbuf = NULL; } while((de = readdir(dir)) != NULL) { if(de->d_name[0] == '.' || (len = strlen(de->d_name)) < sizeof(ext) || strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0) continue; de->d_name[len - sizeof(ext) + 1] = '\0'; if(pixbuf == NULL) pixbuf = gtk_icon_theme_load_icon(helper->icontheme, "help-contents", size, 0, NULL); #if GTK_CHECK_VERSION(2, 10, 0) gtk_tree_store_insert_with_values(store, &iter, &parent, -1, #else gtk_tree_store_insert(store, &iter, &parent, -1); gtk_tree_store_set(store, &iter, #endif HSC_TYPE, HST_CONTENTS, HSC_ICON, pixbuf, HSC_CONTENTS_PACKAGE, de->d_name, -1); } closedir(dir); if(pixbuf != NULL) g_object_unref(pixbuf); }
static GtkWidget * clone_image_menu_size (GtkImage *image) { GtkImageType storage_type = gtk_image_get_storage_type (image); if (storage_type == GTK_IMAGE_STOCK) { gchar *stock_id; GtkWidget *widget; G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gtk_image_get_stock (image, &stock_id, NULL); widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); G_GNUC_END_IGNORE_DEPRECATIONS; return widget; } else if (storage_type == GTK_IMAGE_ICON_NAME) { const gchar *icon_name; gtk_image_get_icon_name (image, &icon_name, NULL); return gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); } else if (storage_type == GTK_IMAGE_ICON_SET) { GtkWidget *widget; GtkIconSet *icon_set; G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gtk_image_get_icon_set (image, &icon_set, NULL); widget = gtk_image_new_from_icon_set (icon_set, GTK_ICON_SIZE_MENU); G_GNUC_END_IGNORE_DEPRECATIONS; return widget; } else if (storage_type == GTK_IMAGE_GICON) { GIcon *icon; gtk_image_get_gicon (image, &icon, NULL); return gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU); } else if (storage_type == GTK_IMAGE_PIXBUF) { gint width, height; if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height)) { GdkPixbuf *src_pixbuf, *dest_pixbuf; GtkWidget *cloned_image; src_pixbuf = gtk_image_get_pixbuf (image); dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height, GDK_INTERP_BILINEAR); cloned_image = gtk_image_new_from_pixbuf (dest_pixbuf); g_object_unref (dest_pixbuf); return cloned_image; } } return NULL; }
static PidginStatusIconTheme * create_icon_theme(GtkWidget *window) { int s, i, j; const char *dirname = g_get_tmp_dir(); PidginStatusIconTheme *theme; const char *author; #ifndef _WIN32 author = getlogin(); #else author = "user"; #endif theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME, "type", "status-icon", "author", author, "directory", dirname, NULL); for (s = 0; sections[s].heading; s++) { GtkWidget *vbox = g_object_get_data(G_OBJECT(window), sections[s].heading); for (i = 0; sections[s].options[i].stockid; i++) { GtkWidget *image = g_object_get_data(G_OBJECT(vbox), sections[s].options[i].stockid); GdkPixbuf *pixbuf = g_object_get_data(G_OBJECT(image), "pixbuf"); if (!pixbuf) continue; pidgin_icon_theme_set_icon(PIDGIN_ICON_THEME(theme), sections[s].options[i].stockid, sections[s].options[i].stockid); for (j = 0; stocksizes[j]; j++) { int width, height; GtkIconSize iconsize; char size[8]; char *name; GdkPixbuf *scale; GError *error = NULL; if (!(sections[s].flags & (1 << j))) continue; iconsize = gtk_icon_size_from_name(stocksizes[j]); gtk_icon_size_lookup(iconsize, &width, &height); g_snprintf(size, sizeof(size), "%d", width); if (i == 0) { name = g_build_filename(dirname, size, NULL); purple_build_dir(name, S_IRUSR | S_IWUSR | S_IXUSR); g_free(name); } name = g_build_filename(dirname, size, sections[s].options[i].stockid, NULL); scale = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR); gdk_pixbuf_save(scale, name, "png", &error, "compression", "9", NULL); g_free(name); g_object_unref(G_OBJECT(scale)); if (error) g_error_free(error); } } } return theme; }
static void thunar_chooser_button_file_changed (ThunarChooserButton *chooser_button, ThunarFile *file) { ThunarVfsMimeApplication *application; ThunarVfsMimeInfo *info; ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; const gchar *icon_name; GdkPixbuf *icon = NULL; gint icon_size; _thunar_return_if_fail (THUNAR_IS_CHOOSER_BUTTON (chooser_button)); _thunar_return_if_fail (chooser_button->file == file); _thunar_return_if_fail (THUNAR_IS_FILE (file)); /* determine the mime info for the file */ info = thunar_file_get_mime_info (file); /* determine the default application for that mime info */ application = thunar_vfs_mime_database_get_default_application (chooser_button->database, info); if (G_LIKELY (application != NULL)) { /* determine the icon size for menus */ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size); /* setup the image for the application */ icon_factory = thunar_icon_factory_get_default (); icon_theme = thunar_icon_factory_get_icon_theme (icon_factory); icon_name = thunar_vfs_mime_handler_lookup_icon_name (THUNAR_VFS_MIME_HANDLER (application), icon_theme); if (G_LIKELY (icon_name != NULL)) icon = thunar_icon_factory_load_icon (icon_factory, icon_name, icon_size, NULL, FALSE); gtk_image_set_from_pixbuf (GTK_IMAGE (chooser_button->image), icon); g_object_unref (G_OBJECT (icon_factory)); if (G_LIKELY (icon != NULL)) g_object_unref (G_OBJECT (icon)); /* setup the label for the application */ gtk_label_set_attributes (GTK_LABEL (chooser_button->label), NULL); gtk_label_set_text (GTK_LABEL (chooser_button->label), thunar_vfs_mime_handler_get_name (THUNAR_VFS_MIME_HANDLER (application))); /* cleanup */ g_object_unref (G_OBJECT (application)); } else { /* no default application specified */ gtk_label_set_attributes (GTK_LABEL (chooser_button->label), thunar_pango_attr_list_italic ()); gtk_label_set_text (GTK_LABEL (chooser_button->label), _("No application selected")); gtk_image_set_from_pixbuf (GTK_IMAGE (chooser_button->image), NULL); } /* setup a useful tooltip for the button */ thunar_gtk_widget_set_tooltip (chooser_button->button, _("The selected application is used to open " "this and other files of type \"%s\"."), thunar_vfs_mime_info_get_comment (info)); }