[Xfce4-commits] <xfce4-panel:devel> * Some small fixed in the scaled-image code. * Use the scaled image in the launcher plugin.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:24:17 CEST 2009
Updating branch refs/heads/devel
to e369d8d73517b3fa1ecce176d7f9a5d9862c4dc8 (commit)
from b69f4a2f4e72e59dc0944aef958f0538c75ee95c (commit)
commit e369d8d73517b3fa1ecce176d7f9a5d9862c4dc8
Author: Nick Schermer <nick at xfce.org>
Date: Sat Oct 4 20:58:35 2008 +0200
* Some small fixed in the scaled-image code.
* Use the scaled image in the launcher plugin.
libxfce4panel/xfce-scaled-image.c | 116 ++++++++++++++++++-------------------
plugins/launcher/launcher.c | 36 +++---------
plugins/launcher/launcher.h | 2 -
3 files changed, 65 insertions(+), 89 deletions(-)
diff --git a/libxfce4panel/xfce-scaled-image.c b/libxfce4panel/xfce-scaled-image.c
index 43ea9fa..adea342 100644
--- a/libxfce4panel/xfce-scaled-image.c
+++ b/libxfce4panel/xfce-scaled-image.c
@@ -186,6 +186,7 @@ xfce_scaled_image_size_allocate (GtkWidget *widget,
image->width = allocation->width;
image->height = allocation->height;
+ /* clear the cache if there is one */
if (image->cache)
{
g_object_unref (G_OBJECT (image->cache));
@@ -206,7 +207,7 @@ xfce_scaled_image_update_cache (XfceScaledImage *image)
gint source_width, source_height;
gint dest_width, dest_height;
gdouble wratio, hratio;
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf = NULL;
GdkScreen *screen;
panel_return_if_fail (image->cache == NULL);
@@ -219,7 +220,7 @@ xfce_scaled_image_update_cache (XfceScaledImage *image)
if (image->pixbuf)
{
/* use the pixbuf set by the user */
- pixbuf = image->pixbuf;
+ pixbuf = g_object_ref (G_OBJECT (image->pixbuf));
}
else if (image->icon_name)
{
@@ -232,30 +233,36 @@ xfce_scaled_image_update_cache (XfceScaledImage *image)
MIN (dest_width, dest_height),
0, NULL);
}
-
- /* get the pixbuf size */
- source_width = gdk_pixbuf_get_width (pixbuf);
- source_height = gdk_pixbuf_get_height (pixbuf);
-
- if (dest_width >= source_width && dest_height >= source_height)
- {
- /* use the origional pixmap */
- image->cache = g_object_ref (G_OBJECT (pixbuf));
- }
- else
+
+ if (G_LIKELY (pixbuf))
{
- /* calculate the new dimensions */
- wratio = (gdouble) source_width / (gdouble) dest_width;
- hratio = (gdouble) source_height / (gdouble) dest_height;
+ /* get the pixbuf size */
+ source_width = gdk_pixbuf_get_width (pixbuf);
+ source_height = gdk_pixbuf_get_height (pixbuf);
- if (hratio > wratio)
- dest_width = rint (source_width / hratio);
+ if (dest_width >= source_width && dest_height >= source_height)
+ {
+ /* use the origional pixmap (we already increased the reference) */
+ image->cache = pixbuf;
+ }
else
- dest_height = rint (source_height / wratio);
-
- /* scale the pixbuf */
- if (dest_width > 1 && dest_height > 1)
- image->cache = gdk_pixbuf_scale_simple (pixbuf, dest_width, dest_height, GDK_INTERP_BILINEAR);
+ {
+ /* calculate the new dimensions */
+ wratio = (gdouble) source_width / (gdouble) dest_width;
+ hratio = (gdouble) source_height / (gdouble) dest_height;
+
+ if (hratio > wratio)
+ dest_width = rint (source_width / hratio);
+ else
+ dest_height = rint (source_height / wratio);
+
+ /* scale the pixbuf */
+ if (dest_width > 1 && dest_height > 1)
+ image->cache = gdk_pixbuf_scale_simple (pixbuf, dest_width, dest_height, GDK_INTERP_BILINEAR);
+
+ /* release the pixbuf */
+ g_object_unref (G_OBJECT (pixbuf));
+ }
}
}
@@ -266,23 +273,19 @@ xfce_scaled_image_cleanup (XfceScaledImage *image)
{
/* release the pixbuf reference */
if (G_LIKELY (image->pixbuf))
- {
- g_object_unref (G_OBJECT (image->pixbuf));
- image->pixbuf = NULL;
- }
-
+ g_object_unref (G_OBJECT (image->pixbuf));
+
/* release the cached pixbuf */
if (G_LIKELY (image->cache))
- {
- g_object_unref (G_OBJECT (image->cache));
- image->cache = NULL;
- }
+ g_object_unref (G_OBJECT (image->cache));
/* free the icon name */
g_free (image->icon_name);
+
+ /* reset varaibles */
+ image->pixbuf = NULL;
+ image->cache = NULL;
image->icon_name = NULL;
-
- /* reset the cached width and height */
image->width = -1;
image->height = -1;
}
@@ -357,14 +360,11 @@ xfce_scaled_image_set_from_pixbuf (XfceScaledImage *image,
/* cleanup */
xfce_scaled_image_cleanup (image);
- if (G_LIKELY (pixbuf))
- {
- /* set the new pixbuf */
- image->pixbuf = g_object_ref (G_OBJECT (pixbuf));
+ /* set the new pixbuf */
+ image->pixbuf = g_object_ref (G_OBJECT (pixbuf));
- /* queue a resize */
- gtk_widget_queue_resize (GTK_WIDGET (image));
- }
+ /* queue a resize */
+ gtk_widget_queue_resize (GTK_WIDGET (image));
}
@@ -374,18 +374,17 @@ xfce_scaled_image_set_from_icon_name (XfceScaledImage *image,
const gchar *icon_name)
{
g_return_if_fail (XFCE_IS_SCALED_IMAGE (image));
+ panel_return_if_fail (icon_name == NULL || !g_path_is_absolute (icon_name));
/* cleanup */
xfce_scaled_image_cleanup (image);
+ /* set the new icon name */
if (G_LIKELY (icon_name && *icon_name != '\0'))
- {
- /* set the new icon name */
- image->icon_name = g_strdup (icon_name);
+ image->icon_name = g_strdup (icon_name);
- /* queue a resize */
- gtk_widget_queue_resize (GTK_WIDGET (image));
- }
+ /* queue a resize */
+ gtk_widget_queue_resize (GTK_WIDGET (image));
}
@@ -394,30 +393,29 @@ PANEL_SYMBOL_EXPORT void
xfce_scaled_image_set_from_file (XfceScaledImage *image,
const gchar *filename)
{
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
+ GError *error = NULL;
g_return_if_fail (XFCE_IS_SCALED_IMAGE (image));
+ panel_return_if_fail (filename == NULL || g_path_is_absolute (filename));
+
+ /* cleanup */
+ xfce_scaled_image_cleanup (image);
if (G_LIKELY (filename && *filename != '\0'))
{
/* try to load the image from the file */
- pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+ image->pixbuf = gdk_pixbuf_new_from_file (filename, &error);
- if (G_UNLIKELY (error != NULL))
+ if (G_LIKELY (error != NULL))
{
/* print a warning what went wrong */
- g_critical ("Failed to loading image from filesname: %s", error->message);
+ g_critical ("Failed to loading image from filename: %s", error->message);
/* cleanup */
g_error_free (error);
}
}
-
- /* set the pixbuf */
- xfce_scaled_image_set_from_pixbuf (image, pixbuf);
-
- /* release the pixbuf */
- if (G_LIKELY (pixbuf))
- g_object_unref (G_OBJECT (pixbuf));
+
+ /* queue a resize */
+ gtk_widget_queue_resize (GTK_WIDGET (image));
}
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 815ac9e..8469716 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -319,30 +319,15 @@ launcher_icon_button_expose_event (GtkWidget *widget,
static void
launcher_icon_button_set_icon (LauncherPlugin *launcher)
{
- GdkPixbuf *pixbuf;
LauncherEntry *entry;
- GdkScreen *screen;
/* get the first entry in the list */
entry = g_list_first (launcher->entries)->data;
-
- /* get widget screen */
- screen = gtk_widget_get_screen (launcher->image);
-
- /* try to load the file */
- pixbuf = launcher_utility_load_pixbuf (screen, entry->icon, launcher->image_size);
-
- if (G_LIKELY (pixbuf))
- {
- /* set the image and release the pixbuf */
- gtk_image_set_from_pixbuf (GTK_IMAGE (launcher->image), pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
- }
+
+ if (g_path_is_absolute (entry->icon))
+ xfce_scaled_image_set_from_file (XFCE_SCALED_IMAGE (launcher->image), entry->icon);
else
- {
- /* clear the image */
- gtk_image_clear (GTK_IMAGE (launcher->image));
- }
+ xfce_scaled_image_set_from_icon_name (XFCE_SCALED_IMAGE (launcher->image), entry->icon);
}
@@ -821,7 +806,7 @@ launcher_plugin_new (XfcePanelPlugin *plugin)
gtk_box_pack_start (GTK_BOX (launcher->box), launcher->icon_button, TRUE, TRUE, 0);
gtk_widget_show (launcher->icon_button);
- launcher->image = gtk_image_new ();
+ launcher->image = xfce_scaled_image_new ();
gtk_container_add (GTK_CONTAINER (launcher->icon_button), launcher->image);
gtk_widget_show (launcher->image);
@@ -1199,7 +1184,6 @@ launcher_plugin_set_size (LauncherPlugin *launcher,
{
gint width = size, height = size;
GtkOrientation orientation;
- GtkWidget *widget = launcher->icon_button;
if (g_list_length (launcher->entries) > 1)
{
@@ -1240,16 +1224,9 @@ launcher_plugin_set_size (LauncherPlugin *launcher,
}
}
- /* calculate the image size inside the button */
- launcher->image_size = MIN (width, height);
- launcher->image_size -= 2 + 2 * MAX (widget->style->xthickness, widget->style->ythickness);
-
/* set the plugin size */
gtk_widget_set_size_request (GTK_WIDGET (launcher->panel_plugin), width, height);
- /* update the icon button */
- launcher_icon_button_set_icon (launcher);
-
/* we handled the size */
return TRUE;
}
@@ -1319,4 +1296,7 @@ launcher_plugin_construct (XfcePanelPlugin *plugin)
G_CALLBACK (launcher_plugin_free), launcher);
g_signal_connect_swapped (G_OBJECT (plugin), "configure-plugin",
G_CALLBACK (launcher_dialog_show), launcher);
+
+ /* init the icon */
+ launcher_icon_button_set_icon (launcher);
}
diff --git a/plugins/launcher/launcher.h b/plugins/launcher/launcher.h
index 378fc05..ce70d6c 100644
--- a/plugins/launcher/launcher.h
+++ b/plugins/launcher/launcher.h
@@ -35,7 +35,6 @@
#define LAUNCHER_TREE_ICON_SIZE (24)
#define LAUNCHER_CHOOSER_ICON_SIZE (48)
-
/* frequently used code */
#define launcher_free_filenames(list) G_STMT_START{ \
g_slist_foreach (list, (GFunc) g_free, NULL); \
@@ -67,7 +66,6 @@ struct _LauncherPlugin
/* whether saving is allowed */
guint plugin_can_save : 1;
- gint image_size;
/* list of launcher entries */
GList *entries;
More information about the Xfce4-commits
mailing list