Fixed bug 1836, Description list item icon wrong.

2000-08-02  Gene Z. Ragan  <gzr@eazel.com>

	Fixed bug 1836, Description list item icon wrong.

	* mime-type-capplet/nautilus-mime-type-capplet.c:
	(populate_mime_list), (gdk_font_get_bold),
	Set up proper and scaled description column icon.

	(capplet_gdk_pixbuf_scale_to_fit):
	New function that scales an gdk-pixbuf to the requested
	width and height.  Copied from libnautilus.
This commit is contained in:
Gene Z. Ragan 2000-08-02 09:18:18 +00:00 committed by Gene Ragan
parent dd7acf74d1
commit 82353c4765

View file

@ -28,6 +28,7 @@
#include <config.h> #include <config.h>
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <math.h>
#include <regex.h> #include <regex.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -49,26 +50,30 @@
#define TOTAL_COLUMNS 4 #define TOTAL_COLUMNS 4
/* Local Prototypes */ /* Local Prototypes */
static void init_mime_capplet (void); static void init_mime_capplet (void);
static void populate_application_menu (GtkWidget *menu, static void populate_application_menu (GtkWidget *menu,
const char *mime_string); const char *mime_string);
static void populate_viewer_menu (GtkWidget *menu, static void populate_viewer_menu (GtkWidget *menu,
const char *mime_string); const char *mime_string);
static void delete_mime_clicked (GtkWidget *widget, static void delete_mime_clicked (GtkWidget *widget,
gpointer data); gpointer data);
static void add_mime_clicked (GtkWidget *widget, static void add_mime_clicked (GtkWidget *widget,
gpointer data); gpointer data);
static void edit_default_clicked (GtkWidget *widget, static void edit_default_clicked (GtkWidget *widget,
gpointer data); gpointer data);
static GtkWidget *create_mime_list_and_scroller (void); static GtkWidget *create_mime_list_and_scroller (void);
static char *pixmap_file (const char *partial_path); static char *pixmap_file (const char *partial_path);
static void ok_callback (void); static void ok_callback (void);
static void gtk_widget_make_bold (GtkWidget *widget); static void gtk_widget_make_bold (GtkWidget *widget);
static GdkFont *gdk_font_get_bold (const GdkFont *plain_font); static GdkFont *gdk_font_get_bold (const GdkFont *plain_font);
static void gtk_widget_set_font (GtkWidget *widget, static void gtk_widget_set_font (GtkWidget *widget,
GdkFont *font); GdkFont *font);
static void gtk_style_set_font (GtkStyle *style, static void gtk_style_set_font (GtkStyle *style,
GdkFont *font); GdkFont *font);
static GdkPixbuf *capplet_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf,
int max_width,
int max_height);
GtkWidget *capplet = NULL; GtkWidget *capplet = NULL;
GtkWidget *delete_button = NULL; GtkWidget *delete_button = NULL;
@ -959,8 +964,8 @@ static void
populate_mime_list (GList *type_list, GtkCList *clist) populate_mime_list (GList *type_list, GtkCList *clist)
{ {
static gchar *text[3]; static gchar *text[3];
const char *description, *action_icon_name; const char *description, *action_icon_name, *description_icon_name;
char *extensions, *mime_string, *action_icon_path; char *extensions, *mime_string, *action_icon_path, *description_icon_path;
gint row; gint row;
GList *element; GList *element;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
@ -969,6 +974,8 @@ populate_mime_list (GList *type_list, GtkCList *clist)
GnomeVFSMimeAction *action; GnomeVFSMimeAction *action;
GnomeVFSMimeApplication *default_app; GnomeVFSMimeApplication *default_app;
OAF_ServerInfo *default_component; OAF_ServerInfo *default_component;
//gtk_clist_set_row_height (clist, 20);
for (element = type_list; element != NULL; element= element->next) { for (element = type_list; element != NULL; element= element->next) {
mime_string = (char *)element->data; mime_string = (char *)element->data;
@ -1002,9 +1009,19 @@ populate_mime_list (GList *type_list, GtkCList *clist)
row = gtk_clist_insert (GTK_CLIST (clist), 1, text); row = gtk_clist_insert (GTK_CLIST (clist), 1, text);
gtk_clist_set_row_data (GTK_CLIST (clist), row, g_strdup(mime_string)); gtk_clist_set_row_data (GTK_CLIST (clist), row, g_strdup(mime_string));
/* Set column icons */ /* Set description column icon */
pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-regular-12.png"); description_icon_name = gnome_vfs_mime_get_icon (mime_string);
if (description_icon_name != NULL) {
/* Get custom icon */
description_icon_path = pixmap_file (description_icon_name);
pixbuf = gdk_pixbuf_new_from_file (description_icon_path);
} else {
/* Use default icon */
pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-regular-24.png");
}
if (pixbuf != NULL) { if (pixbuf != NULL) {
pixbuf = capplet_gdk_pixbuf_scale_to_fit (pixbuf, 18, 18);
gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100); gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100);
gtk_clist_set_pixtext (clist, row, 0, text[0], 5, pixmap, bitmap); gtk_clist_set_pixtext (clist, row, 0, text[0], 5, pixmap, bitmap);
gdk_pixbuf_unref (pixbuf); gdk_pixbuf_unref (pixbuf);
@ -1040,11 +1057,12 @@ populate_mime_list (GList *type_list, GtkCList *clist)
pixbuf = gdk_pixbuf_new_from_file (action_icon_path); pixbuf = gdk_pixbuf_new_from_file (action_icon_path);
} else { } else {
/* Use default icon */ /* Use default icon */
pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-regular-12.png"); pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-regular-24.png");
} }
/* Set column icon */ /* Set column icon */
if (pixbuf != NULL) { if (pixbuf != NULL) {
pixbuf = capplet_gdk_pixbuf_scale_to_fit (pixbuf, 18, 18);
gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100); gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 100);
gtk_clist_set_pixtext (clist, row, 3, text[3], 5, pixmap, bitmap); gtk_clist_set_pixtext (clist, row, 3, text[3], 5, pixmap, bitmap);
gdk_pixbuf_unref (pixbuf); gdk_pixbuf_unref (pixbuf);
@ -1322,3 +1340,38 @@ gdk_font_get_bold (const GdkFont *plain_font)
return result; return result;
} }
/* scale the passed in pixbuf to conform to the passed-in maximum width and height */
/* utility routine to scale the passed-in pixbuf to be smaller than the maximum allowed size, if necessary */
static GdkPixbuf *
capplet_gdk_pixbuf_scale_to_fit (GdkPixbuf *pixbuf, int max_width, int max_height)
{
double scale_factor;
double h_scale = 1.0;
double v_scale = 1.0;
int width = gdk_pixbuf_get_width(pixbuf);
int height = gdk_pixbuf_get_height(pixbuf);
if (width > max_width) {
h_scale = max_width / (double) width;
}
if (height > max_height) {
v_scale = max_height / (double) height;
}
scale_factor = MIN (h_scale, v_scale);
if (scale_factor < 1.0) {
GdkPixbuf *scaled_pixbuf;
/* the width and scale factor are always > 0, so it's OK to round by adding here */
int scaled_width = floor(width * scale_factor + .5);
int scaled_height = floor(height * scale_factor + .5);
scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scaled_width, scaled_height, GDK_INTERP_BILINEAR);
gdk_pixbuf_unref (pixbuf);
pixbuf = scaled_pixbuf;
}
return pixbuf;
}