~ubuntu-branches/debian/experimental/xfce4-panel/experimental

« back to all changes in this revision

Viewing changes to libxfce4panel/xfce-panel-image.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Lionel Le Folgoc, Yves-Alexis Perez
  • Date: 2011-02-06 18:10:07 UTC
  • mfrom: (1.3.13 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110206181007-vpw5z3xnm3hdvybx
Tags: 4.8.1-1
[ Lionel Le Folgoc ]
* New upstream bugfix release.
* debian/control:
  - refreshed (b-)deps for this new major release
  - add myself to Uploaders
  - bump Standards-Version to 3.9.1.
* debian/NEWS: dropped, unneeded.
* debian/xfce4-panel.shlibs: refreshed, bump to (>= 4.7.2).
* debian/xfce4-panel.lintian-overrides: refreshed, new lib name.
* debian/xfce4-panel.preinst: added, handles removal of old conffiles.
* debian/xfce4-panel.postinst: explicitly set -e.
* debian/*.install: refreshed.
* debian/rules:
  - call dpkg-buildflags
  - dropped rc files mangling as they don't exist anymore
  - updated removal of *.{l,}a files.
  - drop overrides for dh_auto_{configure,clean}, obsolete.
* debian/xfce4-panel.{preinst,postinst,prerm}: use dpkg-maintscript-helper
  to remove pre-xfconf config files.
* Bugs fixed by 4.7.x/4.8.x series:
  - rgba support                                                  lp: #586012
  - disappearing menus                                             lp: #53897
  - xrandr support                               lp: #176174, Closes: #432914
  - Fails to reap children, creating zombies                      lp: #420187
  - DND of desktop-files on the panel to create new launchers Closes: #480380
* Bumped shlibs to >= 4.7.7, abi break for external plugins.

[ Yves-Alexis Perez ]
* New upstream development release
* debian/xfce4-panel.install:
  - install wrapper and migrate tools in xfce4-panel package
  - update plugins paths
* debian/rules:
  - update path when removing .a/.la files for plugins.
  - add hardening flags to {C,LD}FLAGS
* debian/control:
  - add build-dep on hardening-includes
  - update build-dep on garcon to 0.1.4.
* debian/copyright updated for new release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008-2010 Nick Schermer <nick@xfce.org>
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the Free
 
6
 * Software Foundation; either version 2 of the License, or (at your option)
 
7
 * any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
12
 * more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public License
 
15
 * along with this library; if not, write to the Free Software Foundation,
 
16
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include <config.h>
 
21
#endif
 
22
 
 
23
#ifdef HAVE_MATH_H
 
24
#include <math.h>
 
25
#endif
 
26
#ifdef HAVE_STRING_H
 
27
#include <string.h>
 
28
#endif
 
29
 
 
30
#include <gtk/gtk.h>
 
31
#include <libxfce4util/libxfce4util.h>
 
32
 
 
33
#include <common/panel-private.h>
 
34
#include <libxfce4panel/xfce-panel-macros.h>
 
35
#include <libxfce4panel/xfce-panel-image.h>
 
36
#include <libxfce4panel/xfce-panel-convenience.h>
 
37
#include <libxfce4panel/libxfce4panel-alias.h>
 
38
 
 
39
 
 
40
 
 
41
/**
 
42
 * SECTION: xfce-panel-image
 
43
 * @title: XfcePanelImage
 
44
 * @short_description: Scalable image suitable for panel plugins
 
45
 * @include: libxfce4panel/libxfce4panel.h
 
46
 *
 
47
 * The #XfcePanelImage is a widgets suitable for for example panel
 
48
 * buttons where the developer does not exacly know the size of the
 
49
 * image (due to theming and user setting).
 
50
 *
 
51
 * The #XfcePanelImage widget automatically scales to the allocated
 
52
 * size of the widget. Because of that nature it never requests a size,
 
53
 * so this will only work if you pack the image in another widget
 
54
 * that will expand it.
 
55
 * If you want to force an image size you can use xfce_panel_image_set_size()
 
56
 * to set a pixel size, in that case the widget will request an fixed size
 
57
 * which makes it usefull for usage in dialogs.
 
58
 **/
 
59
 
 
60
 
 
61
 
 
62
/* design limit for the panel, to reduce the uncached pixbuf size */
 
63
#define MAX_PIXBUF_SIZE (128)
 
64
 
 
65
#define xfce_panel_image_unref_null(obj)   G_STMT_START { if ((obj) != NULL) \
 
66
                                             { \
 
67
                                               g_object_unref (G_OBJECT (obj)); \
 
68
                                               (obj) = NULL; \
 
69
                                             } } G_STMT_END
 
70
 
 
71
 
 
72
 
 
73
struct _XfcePanelImagePrivate
 
74
{
 
75
  /* pixbuf set by the user */
 
76
  GdkPixbuf *pixbuf;
 
77
 
 
78
  /* internal cached pixbuf (resized) */
 
79
  GdkPixbuf *cache;
 
80
 
 
81
  /* source name */
 
82
  gchar     *source;
 
83
 
 
84
  /* fixed size */
 
85
  gint       size;
 
86
 
 
87
  /* whether we round to fixed icon sizes */
 
88
  guint      force_icon_sizes : 1;
 
89
 
 
90
  /* cached width and height */
 
91
  gint       width;
 
92
  gint       height;
 
93
};
 
94
 
 
95
enum
 
96
{
 
97
  PROP_0,
 
98
  PROP_SOURCE,
 
99
  PROP_PIXBUF,
 
100
  PROP_SIZE
 
101
};
 
102
 
 
103
 
 
104
 
 
105
static void       xfce_panel_image_get_property  (GObject         *object,
 
106
                                                  guint            prop_id,
 
107
                                                  GValue          *value,
 
108
                                                  GParamSpec      *pspec);
 
109
static void       xfce_panel_image_set_property  (GObject         *object,
 
110
                                                  guint            prop_id,
 
111
                                                  const GValue    *value,
 
112
                                                  GParamSpec      *pspec);
 
113
static void       xfce_panel_image_finalize      (GObject         *object);
 
114
static void       xfce_panel_image_size_request  (GtkWidget       *widget,
 
115
                                                  GtkRequisition  *requisition);
 
116
static void       xfce_panel_image_size_allocate (GtkWidget       *widget,
 
117
                                                  GtkAllocation   *allocation);
 
118
static gboolean   xfce_panel_image_expose_event  (GtkWidget       *widget,
 
119
                                                  GdkEventExpose  *event);
 
120
static void       xfce_panel_image_style_set     (GtkWidget       *widget,
 
121
                                                  GtkStyle        *previous_style);
 
122
static GdkPixbuf *xfce_panel_image_scale_pixbuf  (GdkPixbuf       *source,
 
123
                                                  gint             dest_width,
 
124
                                                  gint             dest_height);
 
125
 
 
126
 
 
127
 
 
128
G_DEFINE_TYPE (XfcePanelImage, xfce_panel_image, GTK_TYPE_WIDGET)
 
129
 
 
130
 
 
131
 
 
132
static void
 
133
xfce_panel_image_class_init (XfcePanelImageClass *klass)
 
134
{
 
135
  GObjectClass   *gobject_class;
 
136
  GtkWidgetClass *gtkwidget_class;
 
137
 
 
138
  g_type_class_add_private (klass, sizeof (XfcePanelImagePrivate));
 
139
 
 
140
  gobject_class = G_OBJECT_CLASS (klass);
 
141
  gobject_class->get_property = xfce_panel_image_get_property;
 
142
  gobject_class->set_property = xfce_panel_image_set_property;
 
143
  gobject_class->finalize = xfce_panel_image_finalize;
 
144
 
 
145
  gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
146
  gtkwidget_class->size_request = xfce_panel_image_size_request;
 
147
  gtkwidget_class->size_allocate = xfce_panel_image_size_allocate;
 
148
  gtkwidget_class->expose_event = xfce_panel_image_expose_event;
 
149
  gtkwidget_class->style_set = xfce_panel_image_style_set;
 
150
 
 
151
  g_object_class_install_property (gobject_class,
 
152
                                   PROP_SOURCE,
 
153
                                   g_param_spec_string ("source",
 
154
                                                        "Source",
 
155
                                                        "Icon or filename",
 
156
                                                        NULL,
 
157
                                                        G_PARAM_READWRITE
 
158
                                                        | G_PARAM_STATIC_STRINGS));
 
159
 
 
160
  g_object_class_install_property (gobject_class,
 
161
                                   PROP_PIXBUF,
 
162
                                   g_param_spec_object ("pixbuf",
 
163
                                                        "Pixbuf",
 
164
                                                        "Pixbuf image",
 
165
                                                        GDK_TYPE_PIXBUF,
 
166
                                                        G_PARAM_READWRITE
 
167
                                                        | G_PARAM_STATIC_STRINGS));
 
168
 
 
169
  g_object_class_install_property (gobject_class,
 
170
                                   PROP_SIZE,
 
171
                                   g_param_spec_int ("size",
 
172
                                                     "Size",
 
173
                                                     "Pixel size of the image",
 
174
                                                     -1, MAX_PIXBUF_SIZE, -1,
 
175
                                                     G_PARAM_READWRITE
 
176
                                                     | G_PARAM_STATIC_STRINGS));
 
177
 
 
178
  gtk_widget_class_install_style_property (gtkwidget_class,
 
179
                                           g_param_spec_boolean ("force-gtk-icon-sizes",
 
180
                                                                 NULL,
 
181
                                                                 "Force the image to fix to GtkIconSizes",
 
182
                                                                 FALSE,
 
183
                                                                 G_PARAM_READWRITE
 
184
                                                                 | G_PARAM_STATIC_STRINGS));
 
185
}
 
186
 
 
187
 
 
188
 
 
189
static void
 
190
xfce_panel_image_init (XfcePanelImage *image)
 
191
{
 
192
  GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
 
193
 
 
194
  image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image, XFCE_TYPE_PANEL_IMAGE, XfcePanelImagePrivate);
 
195
 
 
196
  image->priv->pixbuf = NULL;
 
197
  image->priv->cache = NULL;
 
198
  image->priv->source = NULL;
 
199
  image->priv->size = -1;
 
200
  image->priv->width = -1;
 
201
  image->priv->height = -1;
 
202
  image->priv->force_icon_sizes = FALSE;
 
203
}
 
204
 
 
205
 
 
206
 
 
207
static void
 
208
xfce_panel_image_get_property (GObject    *object,
 
209
                               guint       prop_id,
 
210
                               GValue     *value,
 
211
                               GParamSpec *pspec)
 
212
{
 
213
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (object)->priv;
 
214
 
 
215
  switch (prop_id)
 
216
    {
 
217
    case PROP_SOURCE:
 
218
      g_value_set_string (value, priv->source);
 
219
      break;
 
220
 
 
221
    case PROP_PIXBUF:
 
222
      g_value_set_object (value, priv->pixbuf);
 
223
      break;
 
224
 
 
225
    case PROP_SIZE:
 
226
      g_value_set_int (value, priv->size);
 
227
      break;
 
228
 
 
229
    default:
 
230
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
231
      break;
 
232
    }
 
233
}
 
234
 
 
235
 
 
236
 
 
237
static void
 
238
xfce_panel_image_set_property (GObject      *object,
 
239
                               guint         prop_id,
 
240
                               const GValue *value,
 
241
                               GParamSpec   *pspec)
 
242
{
 
243
  switch (prop_id)
 
244
    {
 
245
    case PROP_SOURCE:
 
246
      xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (object),
 
247
                                        g_value_get_string (value));
 
248
      break;
 
249
 
 
250
    case PROP_PIXBUF:
 
251
      xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (object),
 
252
                                        g_value_get_object (value));
 
253
      break;
 
254
 
 
255
    case PROP_SIZE:
 
256
      xfce_panel_image_set_size (XFCE_PANEL_IMAGE (object),
 
257
                                 g_value_get_int (value));
 
258
      break;
 
259
 
 
260
    default:
 
261
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
262
      break;
 
263
    }
 
264
}
 
265
 
 
266
 
 
267
 
 
268
static void
 
269
xfce_panel_image_finalize (GObject *object)
 
270
{
 
271
  xfce_panel_image_clear (XFCE_PANEL_IMAGE (object));
 
272
 
 
273
  (*G_OBJECT_CLASS (xfce_panel_image_parent_class)->finalize) (object);
 
274
}
 
275
 
 
276
 
 
277
 
 
278
static void
 
279
xfce_panel_image_size_request (GtkWidget      *widget,
 
280
                               GtkRequisition *requisition)
 
281
{
 
282
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
 
283
 
 
284
  if (priv->size > 0)
 
285
    {
 
286
      requisition->width = priv->size;
 
287
      requisition->height = priv->size;
 
288
    }
 
289
  else if (priv->pixbuf != NULL)
 
290
    {
 
291
      requisition->width = gdk_pixbuf_get_width (priv->pixbuf);
 
292
      requisition->height = gdk_pixbuf_get_height (priv->pixbuf);
 
293
    }
 
294
  else
 
295
    {
 
296
      requisition->width = widget->allocation.width;
 
297
      requisition->height = widget->allocation.height;
 
298
    }
 
299
}
 
300
 
 
301
 
 
302
 
 
303
static void
 
304
xfce_panel_image_size_allocate (GtkWidget     *widget,
 
305
                                GtkAllocation *allocation)
 
306
{
 
307
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
 
308
  GdkPixbuf             *pixbuf;
 
309
  GdkScreen             *screen;
 
310
  GtkIconTheme          *icon_theme = NULL;
 
311
  gint                   size;
 
312
 
 
313
  widget->allocation = *allocation;
 
314
 
 
315
  /* check if the available size changed */
 
316
  if ((priv->pixbuf != NULL || priv->source != NULL)
 
317
      && allocation->width > 0
 
318
      && allocation->height > 0
 
319
      && (allocation->width != priv->width
 
320
      || allocation->height != priv->height))
 
321
    {
 
322
      /* store the new size */
 
323
      priv->width = allocation->width;
 
324
      priv->height = allocation->height;
 
325
 
 
326
      /* free cache */
 
327
      xfce_panel_image_unref_null (priv->cache);
 
328
 
 
329
      size = MIN (priv->width, priv->height);
 
330
      if (G_UNLIKELY (priv->force_icon_sizes && size < 32))
 
331
        {
 
332
          /* we use some hardcoded values here for convienence,
 
333
           * above 32 pixels svg icons will kick in */
 
334
          if (size > 16 && size < 22)
 
335
            size = 16;
 
336
          else if (size > 22 && size < 24)
 
337
            size = 22;
 
338
          else if (size > 24 && size < 32)
 
339
            size = 24;
 
340
        }
 
341
 
 
342
      if (priv->pixbuf != NULL)
 
343
        {
 
344
          /* use the pixbuf set by the user */
 
345
          pixbuf = g_object_ref (G_OBJECT (priv->pixbuf));
 
346
 
 
347
          if (G_LIKELY (pixbuf != NULL))
 
348
            {
 
349
              /* scale the icon to the correct size */
 
350
              priv->cache = xfce_panel_image_scale_pixbuf (pixbuf, size, size);
 
351
              g_object_unref (G_OBJECT (pixbuf));
 
352
            }
 
353
        }
 
354
      else
 
355
        {
 
356
          screen = gtk_widget_get_screen (widget);
 
357
          if (G_LIKELY (screen != NULL))
 
358
            icon_theme = gtk_icon_theme_get_for_screen (screen);
 
359
 
 
360
          priv->cache = xfce_panel_pixbuf_from_source (priv->source, icon_theme, size);
 
361
        }
 
362
    }
 
363
}
 
364
 
 
365
 
 
366
 
 
367
static gboolean
 
368
xfce_panel_image_expose_event (GtkWidget      *widget,
 
369
                               GdkEventExpose *event)
 
370
{
 
371
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
 
372
  gint                   source_width, source_height;
 
373
  gint                   dest_x, dest_y;
 
374
  GtkIconSource         *source;
 
375
  GdkPixbuf             *rendered = NULL;
 
376
  GdkPixbuf             *pixbuf = priv->cache;
 
377
 
 
378
  if (G_LIKELY (pixbuf != NULL))
 
379
    {
 
380
      /* get the size of the cache pixbuf */
 
381
      source_width = gdk_pixbuf_get_width (priv->cache);
 
382
      source_height = gdk_pixbuf_get_height (priv->cache);
 
383
 
 
384
      /* position */
 
385
      dest_x = widget->allocation.x + (priv->width - source_width) / 2;
 
386
      dest_y = widget->allocation.y + (priv->height - source_height) / 2;
 
387
 
 
388
      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
 
389
        {
 
390
          source = gtk_icon_source_new ();
 
391
          gtk_icon_source_set_pixbuf (source, pixbuf);
 
392
 
 
393
          rendered = gtk_style_render_icon (widget->style,
 
394
                                            source,
 
395
                                            gtk_widget_get_direction (widget),
 
396
                                            GTK_WIDGET_STATE (widget),
 
397
                                            -1, widget, "xfce-panel-image");
 
398
          gtk_icon_source_free (source);
 
399
 
 
400
          if (G_LIKELY (rendered != NULL))
 
401
            pixbuf = rendered;
 
402
        }
 
403
 
 
404
      /* draw the pixbuf */
 
405
      gdk_draw_pixbuf (widget->window,
 
406
                       widget->style->black_gc,
 
407
                       pixbuf, 0, 0,
 
408
                       dest_x, dest_y,
 
409
                       source_width, source_height,
 
410
                       GDK_RGB_DITHER_NORMAL, 0, 0);
 
411
 
 
412
      if (rendered != NULL)
 
413
        g_object_unref (G_OBJECT (rendered));
 
414
    }
 
415
 
 
416
  return FALSE;
 
417
}
 
418
 
 
419
 
 
420
 
 
421
static void
 
422
xfce_panel_image_style_set (GtkWidget *widget,
 
423
                            GtkStyle  *previous_style)
 
424
{
 
425
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
 
426
  gboolean               force;
 
427
 
 
428
  /* let gtk update the widget style */
 
429
  (*GTK_WIDGET_CLASS (xfce_panel_image_parent_class)->style_set) (widget, previous_style);
 
430
 
 
431
  /* get style property */
 
432
  gtk_widget_style_get (widget, "force-gtk-icon-sizes", &force, NULL);
 
433
 
 
434
  /* update if needed */
 
435
  if (priv->force_icon_sizes != force)
 
436
    {
 
437
      priv->force_icon_sizes = force;
 
438
      if (priv->size > 0)
 
439
        gtk_widget_queue_resize (widget);
 
440
    }
 
441
 
 
442
  /* update the icon if we have an icon-name source */
 
443
  if (previous_style != NULL && priv->source != NULL
 
444
      && !g_path_is_absolute (priv->source))
 
445
    {
 
446
      /* unset the size to force an update */
 
447
      priv->width = priv->height = -1;
 
448
      gtk_widget_queue_resize (widget);
 
449
    }
 
450
}
 
451
 
 
452
 
 
453
 
 
454
static GdkPixbuf *
 
455
xfce_panel_image_scale_pixbuf (GdkPixbuf *source,
 
456
                               gint       dest_width,
 
457
                               gint       dest_height)
 
458
{
 
459
  gdouble wratio;
 
460
  gdouble hratio;
 
461
  gint    source_width;
 
462
  gint    source_height;
 
463
 
 
464
  panel_return_val_if_fail (GDK_IS_PIXBUF (source), NULL);
 
465
 
 
466
  /* we fail on invalid sizes */
 
467
  if (G_UNLIKELY (dest_width <= 0 || dest_height <= 0))
 
468
    return NULL;
 
469
 
 
470
  source_width = gdk_pixbuf_get_width (source);
 
471
  source_height = gdk_pixbuf_get_height (source);
 
472
 
 
473
  /* check if we need to scale */
 
474
  if (source_width <= dest_width && source_height <= dest_height)
 
475
    return g_object_ref (G_OBJECT (source));
 
476
 
 
477
  /* calculate the new dimensions */
 
478
  wratio = (gdouble) source_width  / (gdouble) dest_width;
 
479
  hratio = (gdouble) source_height / (gdouble) dest_height;
 
480
 
 
481
  if (hratio > wratio)
 
482
    dest_width  = rint (source_width / hratio);
 
483
  else
 
484
    dest_height = rint (source_height / wratio);
 
485
 
 
486
  return gdk_pixbuf_scale_simple (source, MAX (dest_width, 1),
 
487
                                  MAX (dest_height, 1),
 
488
                                  GDK_INTERP_BILINEAR);
 
489
}
 
490
 
 
491
 
 
492
 
 
493
/**
 
494
 * xfce_panel_image_new:
 
495
 *
 
496
 * Creates a new empty #XfcePanelImage widget.
 
497
 *
 
498
 * returns: a newly created XfcePanelImage widget.
 
499
 *
 
500
 * Since: 4.8
 
501
 **/
 
502
GtkWidget *
 
503
xfce_panel_image_new (void)
 
504
{
 
505
  return g_object_new (XFCE_TYPE_PANEL_IMAGE, NULL);
 
506
}
 
507
 
 
508
 
 
509
 
 
510
/**
 
511
 * xfce_panel_image_new_from_pixbuf:
 
512
 * @pixbuf : a #GdkPixbuf, or %NULL.
 
513
 *
 
514
 * Creates a new #XfcePanelImage displaying @pixbuf. #XfcePanelImage
 
515
 * will add its own reference rather than adopting yours. You don't
 
516
 * need to scale the pixbuf to the correct size, the #XfcePanelImage
 
517
 * will take care of that based on the allocation of the widget or
 
518
 * the size set with xfce_panel_image_set_size().
 
519
 *
 
520
 * returns: a newly created XfcePanelImage widget.
 
521
 *
 
522
 * Since: 4.8
 
523
 **/
 
524
GtkWidget *
 
525
xfce_panel_image_new_from_pixbuf (GdkPixbuf *pixbuf)
 
526
{
 
527
  g_return_val_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf), NULL);
 
528
 
 
529
  return g_object_new (XFCE_TYPE_PANEL_IMAGE,
 
530
                       "pixbuf", pixbuf, NULL);
 
531
}
 
532
 
 
533
 
 
534
 
 
535
/**
 
536
 * xfce_panel_image_new_from_source:
 
537
 * @source : source of the image. This can be an absolute path or
 
538
 *           an icon-name or %NULL.
 
539
 *
 
540
 * Creates a new #XfcePanelImage displaying @source. #XfcePanelImage
 
541
 * will detect if @source points to an absolute file or it and icon-name.
 
542
 * For icon-names it will also look for files in the pixbuf folder or
 
543
 * strip the extensions, which makes it suitable for usage with icon
 
544
 * keys in .desktop files.
 
545
 *
 
546
 * returns: a newly created XfcePanelImage widget.
 
547
 *
 
548
 * Since: 4.8
 
549
 **/
 
550
GtkWidget *
 
551
xfce_panel_image_new_from_source (const gchar *source)
 
552
{
 
553
  g_return_val_if_fail (source == NULL || *source != '\0', NULL);
 
554
 
 
555
  return g_object_new (XFCE_TYPE_PANEL_IMAGE,
 
556
                       "source", source, NULL);
 
557
}
 
558
 
 
559
 
 
560
 
 
561
/**
 
562
 * xfce_panel_image_set_from_pixbuf:
 
563
 * @image  : an #XfcePanelImage.
 
564
 * @pixbuf : a #GdkPixbuf, or %NULL.
 
565
 *
 
566
 * See xfce_panel_image_new_from_pixbuf() for details.
 
567
 *
 
568
 * Since: 4.8
 
569
 **/
 
570
void
 
571
xfce_panel_image_set_from_pixbuf (XfcePanelImage *image,
 
572
                                  GdkPixbuf      *pixbuf)
 
573
{
 
574
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
 
575
  g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
 
576
 
 
577
  xfce_panel_image_clear (image);
 
578
 
 
579
  /* set the new pixbuf, scale it to the maximum size if needed */
 
580
  image->priv->pixbuf = xfce_panel_image_scale_pixbuf (pixbuf,
 
581
      MAX_PIXBUF_SIZE, MAX_PIXBUF_SIZE);
 
582
 
 
583
  gtk_widget_queue_resize (GTK_WIDGET (image));
 
584
}
 
585
 
 
586
 
 
587
 
 
588
/**
 
589
 * xfce_panel_image_set_from_source:
 
590
 * @image  : an #XfcePanelImage.
 
591
 * @source : source of the image. This can be an absolute path or
 
592
 *           an icon-name or %NULL.
 
593
 *
 
594
 * See xfce_panel_image_new_from_source() for details.
 
595
 *
 
596
 * Since: 4.8
 
597
 **/
 
598
void
 
599
xfce_panel_image_set_from_source (XfcePanelImage *image,
 
600
                                  const gchar    *source)
 
601
{
 
602
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
 
603
  g_return_if_fail (source == NULL || *source != '\0');
 
604
 
 
605
  xfce_panel_image_clear (image);
 
606
 
 
607
  image->priv->source = g_strdup (source);
 
608
 
 
609
  gtk_widget_queue_resize (GTK_WIDGET (image));
 
610
}
 
611
 
 
612
 
 
613
 
 
614
/**
 
615
 * xfce_panel_image_set_size:
 
616
 * @image : an #XfcePanelImage.
 
617
 * @size  : a new size in pixels.
 
618
 *
 
619
 * This will force an image size, instead of looking at the allocation
 
620
 * size, see introduction for more details. You can set a @size of
 
621
 * -1 to turn this off.
 
622
 *
 
623
 * Since: 4.8
 
624
 **/
 
625
void
 
626
xfce_panel_image_set_size (XfcePanelImage *image,
 
627
                           gint            size)
 
628
{
 
629
 
 
630
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
 
631
 
 
632
  if (G_LIKELY (image->priv->size != size))
 
633
    {
 
634
      image->priv->size = size;
 
635
      gtk_widget_queue_resize (GTK_WIDGET (image));
 
636
    }
 
637
}
 
638
 
 
639
 
 
640
 
 
641
/**
 
642
 * xfce_panel_image_get_size:
 
643
 * @image : an #XfcePanelImage.
 
644
 *
 
645
 * The size of the image, set by xfce_panel_image_set_size() or -1
 
646
 * if no size is forced and the image is scaled to the allocation size.
 
647
 *
 
648
 * Returns: icon size in pixels of the image or -1.
 
649
 *
 
650
 * Since: 4.8
 
651
 **/
 
652
gint
 
653
xfce_panel_image_get_size (XfcePanelImage *image)
 
654
{
 
655
  g_return_val_if_fail (XFCE_IS_PANEL_IMAGE (image), -1);
 
656
  return image->priv->size;
 
657
}
 
658
 
 
659
 
 
660
 
 
661
/**
 
662
 * xfce_panel_image_clear:
 
663
 * @image : an #XfcePanelImage.
 
664
 *
 
665
 * Resets the image to be empty.
 
666
 *
 
667
 * Since: 4.8
 
668
 **/
 
669
void
 
670
xfce_panel_image_clear (XfcePanelImage *image)
 
671
{
 
672
  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (image)->priv;
 
673
 
 
674
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
 
675
 
 
676
  if (priv->source != NULL)
 
677
    {
 
678
     g_free (priv->source);
 
679
     priv->source = NULL;
 
680
    }
 
681
 
 
682
  xfce_panel_image_unref_null (priv->pixbuf);
 
683
  xfce_panel_image_unref_null (priv->cache);
 
684
 
 
685
  /* reset values */
 
686
  priv->width = -1;
 
687
  priv->height = -1;
 
688
}
 
689
 
 
690
 
 
691
 
 
692
#define __XFCE_PANEL_IMAGE_C__
 
693
#include <libxfce4panel/libxfce4panel-aliasdef.c>