gtkstatusicon.c 79.1 KB
Newer Older
1
/* gtkstatusicon.c:
2 3
 *
 * Copyright (C) 2003 Sun Microsystems, Inc.
4 5
 * Copyright (C) 2005 Hans Breuer <hans@breuer.org>
 * Copyright (C) 2005 Novell, Inc.
6
 * Copyright (C) 2006 Imendio AB
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors:
 *	Mark McLoughlin <mark@skynet.ie>
25 26
 *	Hans Breuer <hans@breuer.org>
 *	Tor Lillqvist <tml@novell.com>
27
 *	Mikael Hallendal <micke@imendio.com>
28 29
 */

30
#include "config.h"
31 32 33

#include "gtkstatusicon.h"

34 35
#include <string.h>

36 37
#include "gtkintl.h"
#include "gtkiconfactory.h"
38
#include "gtkmain.h"
39
#include "gtkmarshalers.h"
40
#include "gtksizerequest.h"
41 42 43 44
#include "gtktrayicon.h"

#include "gtkprivate.h"
#include "gtkwidget.h"
45
#include "gtktooltip.h"
46

47 48 49 50
#ifdef GDK_WINDOWING_X11
#include "gdk/x11/gdkx.h"
#endif

51 52 53 54 55 56 57 58
#ifdef GDK_WINDOWING_WIN32
#include "gtkicontheme.h"
#include "gtklabel.h"

#include "win32/gdkwin32.h"
#define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
#endif

59 60 61 62 63
#ifdef GDK_WINDOWING_QUARTZ
#include "gtkicontheme.h"
#include "gtklabel.h"
#endif	

Matthias Clasen's avatar
Matthias Clasen committed
64 65
#include "gdkkeysyms.h"

66 67 68 69 70 71 72 73 74
#define BLINK_TIMEOUT 500

enum
{
  PROP_0,
  PROP_PIXBUF,
  PROP_FILE,
  PROP_STOCK,
  PROP_ICON_NAME,
75
  PROP_GICON,
76 77
  PROP_STORAGE_TYPE,
  PROP_SIZE,
78
  PROP_SCREEN,
79
  PROP_VISIBLE,
80 81
  PROP_ORIENTATION,
  PROP_EMBEDDED,
82 83 84
  PROP_BLINKING,
  PROP_HAS_TOOLTIP,
  PROP_TOOLTIP_TEXT,
85 86
  PROP_TOOLTIP_MARKUP,
  PROP_TITLE
87 88 89 90 91 92 93
};

enum 
{
  ACTIVATE_SIGNAL,
  POPUP_MENU_SIGNAL,
  SIZE_CHANGED_SIGNAL,
94 95 96
  BUTTON_PRESS_EVENT_SIGNAL,
  BUTTON_RELEASE_EVENT_SIGNAL,
  SCROLL_EVENT_SIGNAL,
97
  QUERY_TOOLTIP_SIGNAL,
98 99 100
  LAST_SIGNAL
};

101 102 103 104 105 106
static guint status_icon_signals [LAST_SIGNAL] = { 0 };

#ifdef GDK_WINDOWING_QUARTZ
#include "gtkstatusicon-quartz.c"
#endif

107 108
struct _GtkStatusIconPrivate
{
109
#ifdef GDK_WINDOWING_X11
110 111
  GtkWidget    *tray_icon;
  GtkWidget    *image;
112 113 114 115 116
#endif

#ifdef GDK_WINDOWING_WIN32
  GtkWidget     *dummy_widget;
  NOTIFYICONDATAW nid;
117 118
  gint		last_click_x, last_click_y;
  GtkOrientation orientation;
119
  gchar         *tooltip_text;
120
  gchar         *title;
121
#endif
122 123 124 125
	
#ifdef GDK_WINDOWING_QUARTZ
  GtkWidget     *dummy_widget;
  GtkQuartzStatusIcon *status_item;
126
  gchar         *tooltip_text;
127
  gchar         *title;
128
#endif
129

130 131 132 133 134 135 136 137 138 139 140 141
  gint          size;

  gint          image_width;
  gint          image_height;

  GtkImageType  storage_type;

  union
    {
      GdkPixbuf *pixbuf;
      gchar     *stock_id;
      gchar     *icon_name;
142
      GIcon     *gicon;
143 144 145 146 147
    } image_data;

  guint         visible : 1;
};

148 149 150
static GObject* gtk_status_icon_constructor      (GType                  type,
                                                  guint                  n_construct_properties,
                                                  GObjectConstructParam *construct_params);
151 152 153 154 155 156 157 158 159 160
static void     gtk_status_icon_finalize         (GObject        *object);
static void     gtk_status_icon_set_property     (GObject        *object,
						  guint           prop_id,
						  const GValue   *value,
						  GParamSpec     *pspec);
static void     gtk_status_icon_get_property     (GObject        *object,
						  guint           prop_id,
						  GValue         *value,
					          GParamSpec     *pspec);

161
#ifdef GDK_WINDOWING_X11
162 163
static void     gtk_status_icon_size_allocate    (GtkStatusIcon  *status_icon,
						  GtkAllocation  *allocation);
164 165
static void     gtk_status_icon_screen_changed   (GtkStatusIcon  *status_icon,
						  GdkScreen      *old_screen);
166 167
static void     gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
static void     gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
168
static void     gtk_status_icon_padding_changed  (GtkStatusIcon *status_icon);
169 170 171 172
static void     gtk_status_icon_fg_changed       (GtkStatusIcon *status_icon);
static void     gtk_status_icon_color_changed    (GtkTrayIcon   *tray,
                                                  GParamSpec    *pspec,
                                                  GtkStatusIcon *status_icon);
173 174
static gboolean gtk_status_icon_scroll           (GtkStatusIcon  *status_icon,
						  GdkEventScroll *event);
175 176 177 178 179
static gboolean gtk_status_icon_query_tooltip    (GtkStatusIcon *status_icon,
						  gint           x,
						  gint           y,
						  gboolean       keyboard_tip,
						  GtkTooltip    *tooltip);
180

181 182 183
static gboolean gtk_status_icon_key_press        (GtkStatusIcon  *status_icon,
						  GdkEventKey    *event);
static void     gtk_status_icon_popup_menu       (GtkStatusIcon  *status_icon);
184
#endif
185 186
static gboolean gtk_status_icon_button_press     (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
187 188
static gboolean gtk_status_icon_button_release   (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
189
static void     gtk_status_icon_reset_image_data (GtkStatusIcon  *status_icon);
190
static void     gtk_status_icon_update_image    (GtkStatusIcon *status_icon);
191

Matthias Clasen's avatar
Matthias Clasen committed
192
G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
193 194 195 196 197 198

static void
gtk_status_icon_class_init (GtkStatusIconClass *class)
{
  GObjectClass *gobject_class = (GObjectClass *) class;

199
  gobject_class->constructor  = gtk_status_icon_constructor;
200 201 202 203
  gobject_class->finalize     = gtk_status_icon_finalize;
  gobject_class->set_property = gtk_status_icon_set_property;
  gobject_class->get_property = gtk_status_icon_get_property;

204 205 206
  class->button_press_event   = NULL;
  class->button_release_event = NULL;
  class->scroll_event         = NULL;
207
  class->query_tooltip        = NULL;
208

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
  g_object_class_install_property (gobject_class,
				   PROP_PIXBUF,
				   g_param_spec_object ("pixbuf",
							P_("Pixbuf"),
							P_("A GdkPixbuf to display"),
							GDK_TYPE_PIXBUF,
							GTK_PARAM_READWRITE));

  g_object_class_install_property (gobject_class,
				   PROP_FILE,
				   g_param_spec_string ("file",
							P_("Filename"),
							P_("Filename to load and display"),
							NULL,
							GTK_PARAM_WRITABLE));

  g_object_class_install_property (gobject_class,
				   PROP_STOCK,
				   g_param_spec_string ("stock",
							P_("Stock ID"),
							P_("Stock ID for a stock image to display"),
							NULL,
							GTK_PARAM_READWRITE));
  
  g_object_class_install_property (gobject_class,
                                   PROP_ICON_NAME,
                                   g_param_spec_string ("icon-name",
                                                        P_("Icon Name"),
                                                        P_("The name of the icon from the icon theme"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

  /**
   * GtkStatusIcon:gicon:
   *
   * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
   * the image will be updated automatically if the theme changes.
   *
   * Since: 2.14
   */
  g_object_class_install_property (gobject_class,
                                   PROP_GICON,
                                   g_param_spec_object ("gicon",
                                                        P_("GIcon"),
                                                        P_("The GIcon being displayed"),
                                                        G_TYPE_ICON,
                                                        GTK_PARAM_READWRITE));

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  g_object_class_install_property (gobject_class,
				   PROP_STORAGE_TYPE,
				   g_param_spec_enum ("storage-type",
						      P_("Storage type"),
						      P_("The representation being used for image data"),
						      GTK_TYPE_IMAGE_TYPE,
						      GTK_IMAGE_EMPTY,
						      GTK_PARAM_READABLE));

  g_object_class_install_property (gobject_class,
				   PROP_SIZE,
				   g_param_spec_int ("size",
						     P_("Size"),
						     P_("The size of the icon"),
						     0,
						     G_MAXINT,
						     0,
						     GTK_PARAM_READABLE));

276 277 278 279 280 281 282 283
  g_object_class_install_property (gobject_class,
				   PROP_SCREEN,
				   g_param_spec_object ("screen",
 							P_("Screen"),
 							P_("The screen where this status icon will be displayed"),
							GDK_TYPE_SCREEN,
 							GTK_PARAM_READWRITE));

284 285 286 287
  g_object_class_install_property (gobject_class,
				   PROP_VISIBLE,
				   g_param_spec_boolean ("visible",
							 P_("Visible"),
288
							 P_("Whether the status icon is visible"),
289 290 291 292
							 TRUE,
							 GTK_PARAM_READWRITE));


293 294 295 296 297 298 299 300 301 302 303
  /**
   * GtkStatusIcon:embedded: 
   *
   * %TRUE if the statusicon is embedded in a notification area.
   *
   * Since: 2.12
   */
  g_object_class_install_property (gobject_class,
				   PROP_EMBEDDED,
				   g_param_spec_boolean ("embedded",
							 P_("Embedded"),
304
							 P_("Whether the status icon is embedded"),
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
							 FALSE,
							 GTK_PARAM_READABLE));

  /**
   * GtkStatusIcon:orientation:
   *
   * The orientation of the tray in which the statusicon 
   * is embedded. 
   *
   * Since: 2.12
   */
  g_object_class_install_property (gobject_class,
				   PROP_ORIENTATION,
				   g_param_spec_enum ("orientation",
						      P_("Orientation"),
						      P_("The orientation of the tray"),
						      GTK_TYPE_ORIENTATION,
						      GTK_ORIENTATION_HORIZONTAL,
						      GTK_PARAM_READABLE));

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
/**
 * GtkStatusIcon:has-tooltip:
 *
 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
 * @status_icon.  A value of %TRUE indicates that @status_icon can have a
 * tooltip, in this case the status icon will be queried using
 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
 * tooltip or not.
 *
 * Note that setting this property to %TRUE for the first time will change
 * the event masks of the windows of this status icon to include leave-notify
 * and motion-notify events. This will not be undone when the property is set
 * to %FALSE again.
 *
 * Whether this property is respected is platform dependent.
 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
 *
 * Since: 2.16
 */
  g_object_class_install_property (gobject_class,
				   PROP_HAS_TOOLTIP,
				   g_param_spec_boolean ("has-tooltip",
 							 P_("Has tooltip"),
 							 P_("Whether this tray icon has a tooltip"),
 							 FALSE,
 							 GTK_PARAM_READWRITE));
  /**
   * GtkStatusIcon:tooltip-text:
   *
   * Sets the text of tooltip to be the given string.
   *
   * Also see gtk_tooltip_set_text().
   *
   * This is a convenience property which will take care of getting the
   * tooltip shown if the given string is not %NULL.
   * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
   * the default handler for the #GtkStatusIcon::query-tooltip signal
   * will take care of displaying the tooltip.
   *
364 365 366 367
   * Note that some platforms have limitations on the length of tooltips
   * that they allow on status icons, e.g. Windows only shows the first
   * 64 characters.
   *
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TOOLTIP_TEXT,
                                   g_param_spec_string ("tooltip-text",
                                                        P_("Tooltip Text"),
                                                        P_("The contents of the tooltip for this widget"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));
  /**
   * GtkStatusIcon:tooltip-markup:
   *
   * Sets the text of tooltip to be the given string, which is marked up
   * with the <link linkend="PangoMarkupFormat">Pango text markup 
   * language</link>. Also see gtk_tooltip_set_markup().
   *
   * This is a convenience property which will take care of getting the
   * tooltip shown if the given string is not %NULL.
   * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
   * the default handler for the #GtkStatusIcon::query-tooltip signal
   * will take care of displaying the tooltip.
   *
   * On some platforms, embedded markup will be ignored.
   *
   * Since: 2.16
   */
  g_object_class_install_property (gobject_class,
				   PROP_TOOLTIP_MARKUP,
				   g_param_spec_string ("tooltip-markup",
 							P_("Tooltip markup"),
							P_("The contents of the tooltip for this tray icon"),
							NULL,
							GTK_PARAM_READWRITE));


403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
  /**
   * GtkStatusIcon:title:
   *
   * The title of this tray icon. This should be a short, human-readable,
   * localized string describing the tray icon. It may be used by tools
   * like screen readers to render the tray icon.
   *
   * Since: 2.18
   */
  g_object_class_install_property (gobject_class,
                                   PROP_TITLE,
                                   g_param_spec_string ("title",
                                                        P_("Title"),
                                                        P_("The title of this tray icon"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
420 421 422 423 424 425 426
  /**
   * GtkStatusIcon::activate:
   * @status_icon: the object which received the signal
   *
   * Gets emitted when the user activates the status icon. 
   * If and how status icons can activated is platform-dependent.
   *
427 428 429
   * Unlike most G_SIGNAL_ACTION signals, this signal is meant to 
   * be used by applications and should be wrapped by language bindings.
   *
Matthias Clasen's avatar
Matthias Clasen committed
430 431
   * Since: 2.10
   */
432
  status_icon_signals [ACTIVATE_SIGNAL] =
433
    g_signal_new (I_("activate"),
434 435 436 437 438 439 440 441 442
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkStatusIconClass, activate),
		  NULL,
		  NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE,
		  0);

Matthias Clasen's avatar
Matthias Clasen committed
443 444 445 446 447 448 449 450 451 452 453 454
  /**
   * GtkStatusIcon::popup-menu:
   * @status_icon: the object which received the signal
   * @button: the button that was pressed, or 0 if the 
   *   signal is not emitted in response to a button press event
   * @activate_time: the timestamp of the event that
   *   triggered the signal emission
   *
   * Gets emitted when the user brings up the context menu
   * of the status icon. Whether status icons can have context 
   * menus and how these are activated is platform-dependent.
   *
Matthias Clasen's avatar
Matthias Clasen committed
455
   * The @button and @activate_time parameters should be 
Matthias Clasen's avatar
Matthias Clasen committed
456 457
   * passed as the last to arguments to gtk_menu_popup().
   *
458 459 460
   * Unlike most G_SIGNAL_ACTION signals, this signal is meant to 
   * be used by applications and should be wrapped by language bindings.
   *
Matthias Clasen's avatar
Matthias Clasen committed
461 462
   * Since: 2.10
   */
463
  status_icon_signals [POPUP_MENU_SIGNAL] =
464
    g_signal_new (I_("popup-menu"),
465 466 467 468 469 470 471 472 473 474 475
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
		  G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
		  NULL,
		  NULL,
		  _gtk_marshal_VOID__UINT_UINT,
		  G_TYPE_NONE,
		  2,
		  G_TYPE_UINT,
		  G_TYPE_UINT);

Matthias Clasen's avatar
Matthias Clasen committed
476 477 478 479 480 481 482 483
  /**
   * GtkStatusIcon::size-changed:
   * @status_icon: the object which received the signal
   * @size: the new size
   *
   * Gets emitted when the size available for the image
   * changes, e.g. because the notification area got resized.
   *
484 485 486
   * Return value: %TRUE if the icon was updated for the new
   * size. Otherwise, GTK+ will scale the icon as necessary.
   *
Matthias Clasen's avatar
Matthias Clasen committed
487 488
   * Since: 2.10
   */
489
  status_icon_signals [SIZE_CHANGED_SIGNAL] =
490
    g_signal_new (I_("size-changed"),
Matthias Clasen's avatar
Matthias Clasen committed
491
		  G_TYPE_FROM_CLASS (gobject_class),
492
		  G_SIGNAL_RUN_LAST,
493
		  G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
494
		  g_signal_accumulator_true_handled,
495
		  NULL,
Matthias Clasen's avatar
Matthias Clasen committed
496
		  _gtk_marshal_BOOLEAN__INT,
497
		  G_TYPE_BOOLEAN,
498 499 500
		  1,
		  G_TYPE_INT);

501 502 503 504 505 506 507 508
  /**
   * GtkStatusIcon::button-press-event:
   * @status_icon: the object which received the signal
   * @event: the #GdkEventButton which triggered this signal
   *
   * The ::button-press-event signal will be emitted when a button
   * (typically from a mouse) is pressed.
   *
509 510
   * Whether this event is emitted is platform-dependent.  Use the ::activate
   * and ::popup-menu signals in preference.
511 512 513 514
   *
   * Return value: %TRUE to stop other handlers from being invoked
   * for the event. %FALSE to propagate the event further.
   *
515
   * Since: 2.14
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
   */
  status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
    g_signal_new (I_("button_press_event"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
		  g_signal_accumulator_true_handled, NULL,
		  _gtk_marshal_BOOLEAN__BOXED,
		  G_TYPE_BOOLEAN, 1,
		  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);

  /**
   * GtkStatusIcon::button-release-event:
   * @status_icon: the object which received the signal
   * @event: the #GdkEventButton which triggered this signal
   *
   * The ::button-release-event signal will be emitted when a button
   * (typically from a mouse) is released.
   *
535 536
   * Whether this event is emitted is platform-dependent.  Use the ::activate
   * and ::popup-menu signals in preference.
537 538 539 540
   *
   * Return value: %TRUE to stop other handlers from being invoked
   * for the event. %FALSE to propagate the event further.
   *
541
   * Since: 2.14
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
   */
  status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
    g_signal_new (I_("button_release_event"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
		  g_signal_accumulator_true_handled, NULL,
		  _gtk_marshal_BOOLEAN__BOXED,
		  G_TYPE_BOOLEAN, 1,
		  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);

  /**
   * GtkStatusIcon::scroll-event:
   * @status_icon: the object which received the signal.
   * @event: the #GdkEventScroll which triggered this signal
   *
   * The ::scroll-event signal is emitted when a button in the 4 to 7
559
   * range is pressed. Wheel mice are usually configured to generate
560 561 562 563
   * button press events for buttons 4 and 5 when the wheel is turned.
   *
   * Whether this event is emitted is platform-dependent.
   *
564
   * Returns: %TRUE to stop other handlers from being invoked for the event.
565
   *   %FALSE to propagate the event further.
566 567
   *
   * Since: 2.16
568 569 570 571 572 573 574 575 576 577 578
   */
  status_icon_signals[SCROLL_EVENT_SIGNAL] =
    g_signal_new (I_("scroll_event"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
		  g_signal_accumulator_true_handled, NULL,
		  _gtk_marshal_BOOLEAN__BOXED,
		  G_TYPE_BOOLEAN, 1,
		  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
  /**
   * GtkStatusIcon::query-tooltip:
   * @status_icon: the object which received the signal
   * @x: the x coordinate of the cursor position where the request has been
   *     emitted, relative to @status_icon
   * @y: the y coordinate of the cursor position where the request has been
   *     emitted, relative to @status_icon
   * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
   * @tooltip: a #GtkTooltip
   *
   * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
   * cursor hovering above @status_icon; or emitted when @status_icon got
   * focus in keyboard mode.
   *
   * Using the given coordinates, the signal handler should determine
   * whether a tooltip should be shown for @status_icon. If this is
   * the case %TRUE should be returned, %FALSE otherwise. Note that if
   * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
   * should not be used.
   *
   * The signal handler is free to manipulate @tooltip with the therefore
   * destined function calls.
   *
   * Whether this signal is emitted is platform-dependent.
   * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
   *
   * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
   *
   * Since: 2.16
   */
  status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
    g_signal_new (I_("query_tooltip"),
		  G_TYPE_FROM_CLASS (gobject_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
		  g_signal_accumulator_true_handled, NULL,
		  _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
		  G_TYPE_BOOLEAN, 4,
		  G_TYPE_INT,
		  G_TYPE_INT,
		  G_TYPE_BOOLEAN,
		  GTK_TYPE_TOOLTIP);

622 623 624
  g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
}

625 626 627
#ifdef GDK_WINDOWING_WIN32

static void
628 629 630
build_button_event (GtkStatusIconPrivate *priv,
		    GdkEventButton       *e,
		    guint                 button)
631 632 633 634 635 636
{
  POINT pos;
  GdkRectangle monitor0;

  /* We know that gdk/win32 puts the primary monitor at index 0 */
  gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
637
  e->window = g_object_ref (gdk_get_default_root_window ());
638 639 640
  e->send_event = TRUE;
  e->time = GetTickCount ();
  GetCursorPos (&pos);
641 642
  priv->last_click_x = e->x = pos.x + monitor0.x;
  priv->last_click_y = e->y = pos.y + monitor0.y;
643 644 645 646 647 648 649 650
  e->axes = NULL;
  e->state = 0;
  e->button = button;
  e->device = gdk_display_get_default ()->core_pointer;
  e->x_root = e->x;
  e->y_root = e->y;
}

651 652 653 654 655 656 657 658 659 660 661
typedef struct
{
  GtkStatusIcon *status_icon;
  GdkEventButton *event;
} ButtonCallbackData;

static gboolean
button_callback (gpointer data)
{
  ButtonCallbackData *bc = (ButtonCallbackData *) data;

Matthias Clasen's avatar
Matthias Clasen committed
662
  if (bc->event->type == GDK_BUTTON_PRESS)
663 664 665
    gtk_status_icon_button_press (bc->status_icon, bc->event);
  else
    gtk_status_icon_button_release (bc->status_icon, bc->event);
666 667 668 669 670 671 672

  gdk_event_free ((GdkEvent *) bc->event);
  g_free (data);

  return FALSE;
}

673 674 675
static UINT taskbar_created_msg = 0;
static GSList *status_icons = NULL;

676 677 678 679 680 681
static LRESULT CALLBACK
wndproc (HWND   hwnd,
	 UINT   message,
	 WPARAM wparam,
	 LPARAM lparam)
{
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
  if (message == taskbar_created_msg)
    {
      GSList *rover;

      for (rover = status_icons; rover != NULL; rover = rover->next)
	{
	  GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
	  GtkStatusIconPrivate *priv = status_icon->priv;

	  priv->nid.hWnd = hwnd;
	  priv->nid.uID = GPOINTER_TO_UINT (status_icon);
	  priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
	  priv->nid.uFlags = NIF_MESSAGE;

	  if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
	    {
698
	      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
699 700 701 702 703 704 705 706 707
	      priv->nid.hWnd = NULL;
	      continue;
	    }

	  gtk_status_icon_update_image (status_icon);
	}
      return 0;
    }

708 709
  if (message == WM_GTK_TRAY_NOTIFICATION)
    {
710
      ButtonCallbackData *bc;
711
      guint button;
712 713 714 715
      
      switch (lparam)
	{
	case WM_LBUTTONDOWN:
716 717 718 719 720 721 722
	  button = 1;
	  goto buttondown0;

	case WM_MBUTTONDOWN:
	  button = 2;
	  goto buttondown0;

723
	case WM_RBUTTONDOWN:
724 725 726 727 728 729 730 731 732 733
	  button = 3;
	  goto buttondown0;

	case WM_XBUTTONDOWN:
	  if (HIWORD (wparam) == XBUTTON1)
	    button = 4;
	  else
	    button = 5;

	buttondown0:
734 735 736
	  bc = g_new (ButtonCallbackData, 1);
	  bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
	  bc->status_icon = GTK_STATUS_ICON (wparam);
737
	  build_button_event (bc->status_icon->priv, bc->event, button);
738
	  g_idle_add (button_callback, bc);
739
	  break;
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766

	case WM_LBUTTONUP:
	  button = 1;
	  goto buttonup0;

	case WM_MBUTTONUP:
	  button = 2;
	  goto buttonup0;

	case WM_RBUTTONUP:
	  button = 3;
	  goto buttonup0;

	case WM_XBUTTONUP:
	  if (HIWORD (wparam) == XBUTTON1)
	    button = 4;
	  else
	    button = 5;

	buttonup0:
	  bc = g_new (ButtonCallbackData, 1);
	  bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
	  bc->status_icon = GTK_STATUS_ICON (wparam);
	  build_button_event (bc->status_icon->priv, bc->event, button);
	  g_idle_add (button_callback, bc);
	  break;

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
	default :
	  break;
	}
	return 0;
    }
  else
    {
      return DefWindowProc (hwnd, message, wparam, lparam);
    }
}

static HWND
create_tray_observer (void)
{
  WNDCLASS    wclass;
  static HWND hwnd = NULL;
  ATOM        klass;
  HINSTANCE   hmodule = GetModuleHandle (NULL);

  if (hwnd)
    return hwnd;

789 790
  taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");

791 792 793 794 795 796 797 798 799
  memset (&wclass, 0, sizeof(WNDCLASS));
  wclass.lpszClassName = "gtkstatusicon-observer";
  wclass.lpfnWndProc   = wndproc;
  wclass.hInstance     = hmodule;

  klass = RegisterClass (&wclass);
  if (!klass)
    return NULL;

800
  hwnd = CreateWindow (MAKEINTRESOURCE (klass),
801 802 803 804 805 806 807 808 809 810 811 812 813 814
                       NULL, WS_POPUP,
                       0, 0, 1, 1, NULL, NULL,
                       hmodule, NULL);
  if (!hwnd)
    {
      UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
      return NULL;
    }

  return hwnd;
}

#endif

815 816 817
static void
gtk_status_icon_init (GtkStatusIcon *status_icon)
{
Matthias Clasen's avatar
Matthias Clasen committed
818 819 820 821 822
  GtkStatusIconPrivate *priv;

  priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
				      GtkStatusIconPrivate);
  status_icon->priv = priv;
823

Matthias Clasen's avatar
Matthias Clasen committed
824 825
  priv->storage_type = GTK_IMAGE_EMPTY;
  priv->visible      = TRUE;
826 827

#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
828 829 830
  priv->size         = 0;
  priv->image_width  = 0;
  priv->image_height = 0;
831

Matthias Clasen's avatar
Matthias Clasen committed
832
  priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
833

Matthias Clasen's avatar
Matthias Clasen committed
834
  gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
835 836
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
			 GDK_SCROLL_MASK);
837

838 839 840 841
  g_signal_connect_swapped (priv->tray_icon, "key-press-event",
			    G_CALLBACK (gtk_status_icon_key_press), status_icon);
  g_signal_connect_swapped (priv->tray_icon, "popup-menu",
			    G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
842 843 844 845
  g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
			    G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
  g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
			    G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
846 847
  g_signal_connect_swapped (priv->tray_icon, "notify::padding",
			    G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
848 849 850 851 852 853 854 855
  g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
                            G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
  g_signal_connect (priv->tray_icon, "notify::error-color",
                    G_CALLBACK (gtk_status_icon_color_changed), status_icon);
  g_signal_connect (priv->tray_icon, "notify::warning-color",
                    G_CALLBACK (gtk_status_icon_color_changed), status_icon);
  g_signal_connect (priv->tray_icon, "notify::success-color",
                    G_CALLBACK (gtk_status_icon_color_changed), status_icon);
Matthias Clasen's avatar
Matthias Clasen committed
856
  g_signal_connect_swapped (priv->tray_icon, "button-press-event",
857
			    G_CALLBACK (gtk_status_icon_button_press), status_icon);
858 859 860 861
  g_signal_connect_swapped (priv->tray_icon, "button-release-event",
			    G_CALLBACK (gtk_status_icon_button_release), status_icon);
  g_signal_connect_swapped (priv->tray_icon, "scroll-event",
			    G_CALLBACK (gtk_status_icon_scroll), status_icon);
862 863
  g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
			    G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
864 865
  g_signal_connect_swapped (priv->tray_icon, "screen-changed",
		    	    G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
Matthias Clasen's avatar
Matthias Clasen committed
866
  priv->image = gtk_image_new ();
867
  gtk_widget_set_can_focus (priv->image, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
868
  gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
869
  gtk_widget_show (priv->image);
870

Matthias Clasen's avatar
Matthias Clasen committed
871
  g_signal_connect_swapped (priv->image, "size-allocate",
872 873
			    G_CALLBACK (gtk_status_icon_size_allocate), status_icon);

874 875 876 877
#endif

#ifdef GDK_WINDOWING_WIN32

878
  /* Get position and orientation of Windows taskbar. */
879 880 881 882 883 884
  {
    APPBARDATA abd;
    
    abd.cbSize = sizeof (abd);
    SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
    if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
885
      priv->orientation = GTK_ORIENTATION_VERTICAL;
886
    else
887
      priv->orientation = GTK_ORIENTATION_HORIZONTAL;
888
  }
889 890

  priv->last_click_x = priv->last_click_y = 0;
891 892

  /* Are the system tray icons always 16 pixels square? */
Matthias Clasen's avatar
Matthias Clasen committed
893 894 895
  priv->size         = 16;
  priv->image_width  = 16;
  priv->image_height = 16;
896

Matthias Clasen's avatar
Matthias Clasen committed
897
  priv->dummy_widget = gtk_label_new ("");
898

Matthias Clasen's avatar
Matthias Clasen committed
899
  memset (&priv->nid, 0, sizeof (priv->nid));
900

Matthias Clasen's avatar
Matthias Clasen committed
901 902 903 904
  priv->nid.hWnd = create_tray_observer ();
  priv->nid.uID = GPOINTER_TO_UINT (status_icon);
  priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
  priv->nid.uFlags = NIF_MESSAGE;
905

Matthias Clasen's avatar
Matthias Clasen committed
906
  if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
907
    {
908
      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
Matthias Clasen's avatar
Matthias Clasen committed
909
      priv->nid.hWnd = NULL;
910
    }
911 912 913

  status_icons = g_slist_append (status_icons, status_icon);

914
#endif
915 916 917 918 919 920 921 922
	
#ifdef GDK_WINDOWING_QUARTZ
  priv->dummy_widget = gtk_label_new ("");

  QUARTZ_POOL_ALLOC;

  priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];

923 924
  priv->image_width = priv->image_height = [priv->status_item getHeight];
  priv->size = priv->image_height;
925 926 927 928

  QUARTZ_POOL_RELEASE;

#endif 
929 930
}

931 932 933 934 935 936
static GObject*
gtk_status_icon_constructor (GType                  type,
                             guint                  n_construct_properties,
                             GObjectConstructParam *construct_params)
{
  GObject *object;
937
#ifdef GDK_WINDOWING_X11
938 939
  GtkStatusIcon *status_icon;
  GtkStatusIconPrivate *priv;
940 941
#endif

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
  object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
                                                                       n_construct_properties,
                                                                       construct_params);

#ifdef GDK_WINDOWING_X11
  status_icon = GTK_STATUS_ICON (object);
  priv = status_icon->priv;
  
  if (priv->visible)
    gtk_widget_show (priv->tray_icon);
#endif

  return object;
}

957 958 959 960
static void
gtk_status_icon_finalize (GObject *object)
{
  GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
Matthias Clasen's avatar
Matthias Clasen committed
961
  GtkStatusIconPrivate *priv = status_icon->priv;
962 963 964

  gtk_status_icon_reset_image_data (status_icon);

965
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
966 967 968 969 970 971 972 973
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_key_press, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_popup_menu, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_embedded_changed, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_orientation_changed, status_icon);
974 975
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_padding_changed, status_icon);
976 977 978 979
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
                                        gtk_status_icon_fg_changed, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
                                        gtk_status_icon_color_changed, status_icon);
Matthias Clasen's avatar
Matthias Clasen committed
980 981 982 983 984 985 986 987 988 989
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_button_press, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_button_release, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_scroll, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_query_tooltip, status_icon);
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
		    	                gtk_status_icon_screen_changed, status_icon);
990
  gtk_widget_destroy (priv->image);
Matthias Clasen's avatar
Matthias Clasen committed
991
  gtk_widget_destroy (priv->tray_icon);
992 993 994
#endif

#ifdef GDK_WINDOWING_WIN32
Matthias Clasen's avatar
Matthias Clasen committed
995 996
  if (priv->nid.hWnd != NULL && priv->visible)
    Shell_NotifyIconW (NIM_DELETE, &priv->nid);
997 998
  if (priv->nid.hIcon)
    DestroyIcon (priv->nid.hIcon);
999
  g_free (priv->tooltip_text);
1000

Matthias Clasen's avatar
Matthias Clasen committed
1001
  gtk_widget_destroy (priv->dummy_widget);
1002 1003

  status_icons = g_slist_remove (status_icons, status_icon);
1004
#endif
1005 1006 1007 1008 1009
	
#ifdef GDK_WINDOWING_QUARTZ
  QUARTZ_POOL_ALLOC;
  [priv->status_item release];
  QUARTZ_POOL_RELEASE;
1010
  g_free (priv->tooltip_text);
1011
#endif
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

  G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
}

static void
gtk_status_icon_set_property (GObject      *object,
			      guint         prop_id,
			      const GValue *value,
			      GParamSpec   *pspec)
{
  GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);

  switch (prop_id)
    {
    case PROP_PIXBUF:
      gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
      break;
    case PROP_FILE:
      gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
      break;
    case PROP_STOCK:
      gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
      break;
    case PROP_ICON_NAME:
      gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
      break;
1038 1039 1040
    case PROP_GICON:
      gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
      break;
1041 1042 1043
    case PROP_SCREEN:
      gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
      break;
1044 1045 1046
    case PROP_VISIBLE:
      gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
      break;
1047 1048
    case PROP_HAS_TOOLTIP:
      gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1049
      break;
1050 1051
    case PROP_TOOLTIP_TEXT:
      gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1052
      break;
1053 1054
    case PROP_TOOLTIP_MARKUP:
      gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1055
      break;
1056 1057 1058
    case PROP_TITLE:
      gtk_status_icon_set_title (status_icon, g_value_get_string (value));
      break;
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_status_icon_get_property (GObject    *object,
			      guint       prop_id,
			      GValue     *value,
			      GParamSpec *pspec)
{
  GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
Matthias Clasen's avatar
Matthias Clasen committed
1072 1073 1074 1075 1076 1077 1078
  GtkStatusIconPrivate *priv = status_icon->priv;

  /* The "getter" functions whine if you try to get the wrong
   * storage type. This function is instead robust against that,
   * so that GUI builders don't have to jump through hoops
   * to avoid g_warning
   */
1079 1080 1081 1082

  switch (prop_id)
    {
    case PROP_PIXBUF:
Matthias Clasen's avatar
Matthias Clasen committed
1083 1084 1085 1086
      if (priv->storage_type != GTK_IMAGE_PIXBUF)
	g_value_set_object (value, NULL);
      else
	g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1087 1088
      break;
    case PROP_STOCK:
Matthias Clasen's avatar
Matthias Clasen committed
1089 1090 1091 1092
      if (priv->storage_type != GTK_IMAGE_STOCK)
	g_value_set_string (value, NULL);
      else
	g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1093 1094
      break;
    case PROP_ICON_NAME:
Matthias Clasen's avatar
Matthias Clasen committed
1095 1096 1097 1098
      if (priv->storage_type != GTK_IMAGE_ICON_NAME)
	g_value_set_string (value, NULL);
      else
	g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1099
      break;
1100 1101 1102 1103
    case PROP_GICON:
      if (priv->storage_type != GTK_IMAGE_GICON)
        g_value_set_object (value, NULL);
      else
Matthias Clasen's avatar
Matthias Clasen committed
1104
        g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1105
      break;
1106 1107 1108 1109 1110 1111
    case PROP_STORAGE_TYPE:
      g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
      break;
    case PROP_SIZE:
      g_value_set_int (value, gtk_status_icon_get_size (status_icon));
      break;
1112 1113 1114
    case PROP_SCREEN:
      g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
      break;
1115 1116 1117
    case PROP_VISIBLE:
      g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
      break;
1118 1119 1120 1121
    case PROP_EMBEDDED:
      g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
      break;
    case PROP_ORIENTATION:
1122
#ifdef GDK_WINDOWING_X11
1123
      g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1124 1125 1126 1127
#endif
#ifdef GDK_WINDOWING_WIN32
      g_value_set_enum (value, status_icon->priv->orientation);
#endif
1128
      break;
1129 1130 1131 1132 1133 1134 1135 1136 1137
    case PROP_HAS_TOOLTIP:
      g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
      break;
    case PROP_TOOLTIP_TEXT:
      g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
      break;
    case PROP_TOOLTIP_MARKUP:
      g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
      break;
1138 1139 1140
    case PROP_TITLE:
      g_value_set_string (value, gtk_status_icon_get_title (status_icon));
      break;
1141 1142 1143 1144 1145 1146
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
1147 1148 1149 1150 1151 1152 1153 1154 1155
/**
 * gtk_status_icon_new:
 * 
 * Creates an empty status icon object.
 * 
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1156 1157 1158 1159 1160 1161
GtkStatusIcon *
gtk_status_icon_new (void)
{
  return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
/**
 * gtk_status_icon_new_from_pixbuf:
 * @pixbuf: a #GdkPixbuf
 * 
 * Creates a status icon displaying @pixbuf. 
 *
 * The image will be scaled down to fit in the available 
 * space in the notification area, if necessary.
 * 
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1175 1176 1177 1178 1179 1180 1181 1182
GtkStatusIcon *
gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
{
  return g_object_new (GTK_TYPE_STATUS_ICON,
		       "pixbuf", pixbuf,
		       NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
/**
 * gtk_status_icon_new_from_file:
 * @filename: a filename
 * 
 * Creates a status icon displaying the file @filename. 
 *
 * The image will be scaled down to fit in the available 
 * space in the notification area, if necessary.
 * 
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1196 1197 1198 1199 1200 1201 1202 1203
GtkStatusIcon *
gtk_status_icon_new_from_file (const gchar *filename)
{
  return g_object_new (GTK_TYPE_STATUS_ICON,
		       "file", filename,
		       NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
1204 1205 1206 1207 1208
/**
 * gtk_status_icon_new_from_stock:
 * @stock_id: a stock icon id
 * 
 * Creates a status icon displaying a stock icon. Sample stock icon
1209
 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your 
Matthias Clasen's avatar
Matthias Clasen committed
1210 1211 1212 1213 1214 1215 1216
 * own stock icon names, see gtk_icon_factory_add_default() and 
 * gtk_icon_factory_add(). 
 *
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1217 1218 1219 1220 1221 1222 1223 1224
GtkStatusIcon *
gtk_status_icon_new_from_stock (const gchar *stock_id)
{
  return g_object_new (GTK_TYPE_STATUS_ICON,
		       "stock", stock_id,
		       NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
/**
 * gtk_status_icon_new_from_icon_name:
 * @icon_name: an icon name
 * 
 * Creates a status icon displaying an icon from the current icon theme.
 * If the current icon theme is changed, the icon will be updated 
 * appropriately.
 * 
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1237 1238 1239 1240 1241 1242 1243 1244
GtkStatusIcon *
gtk_status_icon_new_from_icon_name (const gchar *icon_name)
{
  return g_object_new (GTK_TYPE_STATUS_ICON,
		       "icon-name", icon_name,
		       NULL);
}

1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
/**
 * gtk_status_icon_new_from_gicon:
 * @icon: a #GIcon
 *
 * Creates a status icon displaying a #GIcon. If the icon is a
 * themed icon, it will be updated when the theme changes.
 *
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.14
 **/
GtkStatusIcon *
gtk_status_icon_new_from_gicon (GIcon *icon)
{
  return g_object_new (GTK_TYPE_STATUS_ICON,
		       "gicon", icon,
		       NULL);
}

1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
static void
emit_activate_signal (GtkStatusIcon *status_icon)
{
  g_signal_emit (status_icon,
		 status_icon_signals [ACTIVATE_SIGNAL], 0);
}

static void
emit_popup_menu_signal (GtkStatusIcon *status_icon,
			guint          button,
			guint32        activate_time)
{
  g_signal_emit (status_icon,
		 status_icon_signals [POPUP_MENU_SIGNAL], 0,
		 button,
		 activate_time);
}

1282 1283
#ifdef GDK_WINDOWING_X11

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
static gboolean
emit_size_changed_signal (GtkStatusIcon *status_icon,
			  gint           size)
{
  gboolean handled = FALSE;
  
  g_signal_emit (status_icon,
		 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
		 size,
		 &handled);

  return handled;
}

1298 1299 1300 1301
#endif

#ifdef GDK_WINDOWING_X11

1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
static GtkIconSize
find_icon_size (GtkWidget *widget, 
		gint       pixel_size)
{
  GdkScreen *screen;
  GtkSettings *settings;
  GtkIconSize s, size;
  gint w, h, d, dist;

  screen = gtk_widget_get_screen (widget);

  if (!screen)
    return GTK_ICON_SIZE_MENU;

  settings = gtk_settings_get_for_screen (screen);
  
  dist = G_MAXINT;
  size = GTK_ICON_SIZE_MENU;

1321
  for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
    {
      if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
	  w <= pixel_size && h <= pixel_size)
	{
	  d = MAX (pixel_size - w, pixel_size - h);
	  if (d < dist)
	    {
	      dist = d;
	      size = s;
	    }
	}
    }
  
  return size;
}

1338 1339
#endif

1340 1341 1342
static void
gtk_status_icon_update_image (GtkStatusIcon *status_icon)
{
Matthias Clasen's avatar
Matthias Clasen committed
1343
  GtkStatusIconPrivate *priv = status_icon->priv;
1344 1345 1346
#ifdef GDK_WINDOWING_WIN32
  HICON prev_hicon;
#endif
Matthias Clasen's avatar
Matthias Clasen committed
1347 1348

  switch (priv->storage_type)
1349 1350 1351 1352 1353
    {
    case GTK_IMAGE_PIXBUF:
      {
	GdkPixbuf *pixbuf;

Matthias Clasen's avatar
Matthias Clasen committed
1354
	pixbuf = priv->image_data.pixbuf;
1355 1356 1357 1358 1359 1360 1361 1362

	if (pixbuf)
	  {
	    GdkPixbuf *scaled;
	    gint size;
	    gint width;
	    gint height;

Matthias Clasen's avatar
Matthias Clasen committed
1363
	    size = priv->size;
1364 1365 1366 1367 1368

	    width  = gdk_pixbuf_get_width  (pixbuf);
	    height = gdk_pixbuf_get_height (pixbuf);

	    if (width > size || height > size)
Matthias Clasen's avatar
Matthias Clasen committed
1369 1370 1371 1372
	      scaled = gdk_pixbuf_scale_simple (pixbuf,
						MIN (size, width),
						MIN (size, height),
						GDK_INTERP_BILINEAR);
1373
	    else
Matthias Clasen's avatar
Matthias Clasen committed
1374
	      scaled = g_object_ref (pixbuf);
1375

1376
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
1377
	    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1378 1379
#endif
#ifdef GDK_WINDOWING_WIN32
1380
	    prev_hicon = priv->nid.hIcon;
Matthias Clasen's avatar
Matthias Clasen committed
1381 1382 1383 1384
	    priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
	    priv->nid.uFlags |= NIF_ICON;
	    if (priv->nid.hWnd != NULL && priv->visible)
	      if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1385
		  g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1386 1387
	    if (prev_hicon)
	      DestroyIcon (prev_hicon);
1388
#endif
1389 1390 1391 1392 1393 1394
#ifdef GDK_WINDOWING_QUARTZ
      QUARTZ_POOL_ALLOC;
      [priv->status_item setImage:scaled];
      QUARTZ_POOL_RELEASE;
#endif
			
1395 1396 1397 1398
	    g_object_unref (scaled);
	  }
	else
	  {
1399
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
1400
	    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1401 1402
#endif
#ifdef GDK_WINDOWING_WIN32
Matthias Clasen's avatar
Matthias Clasen committed
1403 1404 1405
	    priv->nid.uFlags &= ~NIF_ICON;
	    if (priv->nid.hWnd != NULL && priv->visible)
	      if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1406
		g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1407 1408 1409
#endif
#ifdef GDK_WINDOWING_QUARTZ
      [priv->status_item setImage:NULL];
1410
#endif
1411 1412 1413 1414 1415 1416
	  }
      }
      break;

    case GTK_IMAGE_STOCK:
      {
1417
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
1418 1419 1420
	GtkIconSize size = find_icon_size (priv->image, priv->size);
	gtk_image_set_from_stock (GTK_IMAGE (priv->image),
				  priv->image_data.stock_id,
1421
				  size);
1422 1423 1424 1425
#endif
#ifdef GDK_WINDOWING_WIN32
	{
	  GdkPixbuf *pixbuf =
Matthias Clasen's avatar
Matthias Clasen committed
1426 1427
	    gtk_widget_render_icon (priv->dummy_widget,
				    priv->image_data.stock_id,
1428 1429
				    GTK_ICON_SIZE_SMALL_TOOLBAR,
				    NULL);
1430 1431

	  prev_hicon = priv->nid.hIcon;
Matthias Clasen's avatar
Matthias Clasen committed
1432 1433 1434 1435
	  priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
	  priv->nid.uFlags |= NIF_ICON;
	  if (priv->nid.hWnd != NULL && priv->visible)
	    if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1436
	      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1437 1438
	  if (prev_hicon)
	    DestroyIcon (prev_hicon);
1439 1440
	  g_object_unref (pixbuf);
	}
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
#endif
#ifdef GDK_WINDOWING_QUARTZ
	{
	  GdkPixbuf *pixbuf;

	  pixbuf = gtk_widget_render_icon (priv->dummy_widget,
					   priv->image_data.stock_id,
					   GTK_ICON_SIZE_SMALL_TOOLBAR,
					   NULL);
	  QUARTZ_POOL_ALLOC;
	  [priv->status_item setImage:pixbuf];
	  QUARTZ_POOL_RELEASE;
	  g_object_unref (pixbuf);
	}	
1455
#endif
1456 1457 1458 1459 1460
      }
      break;
      
    case GTK_IMAGE_ICON_NAME:
      {
1461
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
1462 1463 1464
	GtkIconSize size = find_icon_size (priv->image, priv->size);
	gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
				      priv->image_data.icon_name,
1465
				      size);
1466 1467 1468 1469 1470
#endif
#ifdef GDK_WINDOWING_WIN32
	{
	  GdkPixbuf *pixbuf =
	    gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
Matthias Clasen's avatar
Matthias Clasen committed
1471 1472
				      priv->image_data.icon_name,
				      priv->size,
1473 1474
				      0, NULL);
	  
1475
	  prev_hicon = priv->nid.hIcon;
Matthias Clasen's avatar
Matthias Clasen committed
1476 1477 1478 1479
	  priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
	  priv->nid.uFlags |= NIF_ICON;
	  if (priv->nid.hWnd != NULL && priv->visible)
	    if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1480
	      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1481 1482
	  if (prev_hicon)
	    DestroyIcon (prev_hicon);
1483 1484 1485
	  g_object_unref (pixbuf);
	}
#endif
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
#ifdef GDK_WINDOWING_QUARTZ
	{
	  GdkPixbuf *pixbuf;

	  pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
					     priv->image_data.icon_name,
					     priv->size,
					     0, NULL);

	  QUARTZ_POOL_ALLOC;
	  [priv->status_item setImage:pixbuf];
	  QUARTZ_POOL_RELEASE;
	  g_object_unref (pixbuf);
	}
#endif
	
1502 1503
      }
      break;
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519

    case GTK_IMAGE_GICON:
      {
#ifdef GDK_WINDOWING_X11
        GtkIconSize size = find_icon_size (priv->image, priv->size);
        gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
                                  priv->image_data.gicon,
                                  size);
#endif
#ifdef GDK_WINDOWING_WIN32
      {
        GtkIconInfo *info =
        gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                        priv->image_data.gicon,
                                        priv->size,
                                        0);
1520
        GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1521 1522 1523 1524 1525 1526

        prev_hicon = priv->nid.hIcon;
        priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
        priv->nid.uFlags |= NIF_ICON;
        if (priv->nid.hWnd != NULL && priv->visible)
          if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1527
            g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
          if (prev_hicon)
            DestroyIcon (prev_hicon);
          g_object_unref (pixbuf);
      }
#endif
#ifdef GDK_WINDOWING_QUARTZ
      {
        GtkIconInfo *info =
        gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                        priv->image_data.gicon,
                                        priv->size,
                                        0);
1540
        GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551

        QUARTZ_POOL_ALLOC;
        [priv->status_item setImage:pixbuf];
        QUARTZ_POOL_RELEASE;
        g_object_unref (pixbuf);
      }
#endif

      }
      break;

1552
    case GTK_IMAGE_EMPTY:
1553
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
1554
      gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1555 1556
#endif
#ifdef GDK_WINDOWING_WIN32
Matthias Clasen's avatar
Matthias Clasen committed
1557 1558 1559
      priv->nid.uFlags &= ~NIF_ICON;
      if (priv->nid.hWnd != NULL && priv->visible)
	if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1560
	  g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1561 1562 1563 1564 1565 1566 1567
#endif
#ifdef GDK_WINDOWING_QUARTZ
        {
          QUARTZ_POOL_ALLOC;
          [priv->status_item setImage:NULL];
          QUARTZ_POOL_RELEASE;
        }
1568
#endif
1569 1570 1571 1572 1573 1574 1575
      break;
    default:
      g_assert_not_reached ();
      break;
    }
}

1576 1577
#ifdef GDK_WINDOWING_X11

1578 1579 1580 1581
static void
gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
			       GtkAllocation *allocation)
{
Matthias Clasen's avatar
Matthias Clasen committed
1582
  GtkStatusIconPrivate *priv = status_icon->priv;
1583 1584
  GtkOrientation orientation;
  gint size;
1585
  gint xpad, ypad;
1586

Matthias Clasen's avatar
Matthias Clasen committed
1587
  orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1588 1589 1590 1591 1592 1593

  if (orientation == GTK_ORIENTATION_HORIZONTAL)
    size = allocation->height;
  else
    size = allocation->width;

1594 1595 1596 1597
  gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);

  priv->image_width = allocation->width - xpad * 2;
  priv->image_height = allocation->height - ypad * 2;
1598

Matthias Clasen's avatar
Matthias Clasen committed
1599
  if (priv->size != size)
1600
    {
Matthias Clasen's avatar
Matthias Clasen committed
1601
      priv->size = size;
1602 1603 1604 1605

      g_object_notify (G_OBJECT (status_icon), "size");

      if (!emit_size_changed_signal (status_icon, size))
Matthias Clasen's avatar
Matthias Clasen committed
1606
	gtk_status_icon_update_image (status_icon);
1607 1608 1609
    }
}

1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
static void
gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
				GdkScreen *old_screen)
{
  GtkStatusIconPrivate *priv = status_icon->priv;

  if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
    {
      g_object_notify (G_OBJECT (status_icon), "screen");
    }
}

1622 1623
#endif

1624 1625
#ifdef GDK_WINDOWING_X11

1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
static void
gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
{
  GtkStatusIconPrivate *priv = status_icon->priv;
  GtkOrientation orientation;
  gint padding;

  orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
  padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));

  if (orientation == GTK_ORIENTATION_HORIZONTAL)
    gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
  else
    gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
}

1642 1643 1644
static void
gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
{
1645
  gtk_status_icon_padding_changed (status_icon);
1646 1647 1648 1649 1650 1651
  g_object_notify (G_OBJECT (status_icon), "embedded");
}

static void
gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
{
1652
  gtk_status_icon_padding_changed (status_icon);
1653 1654 1655
  g_object_notify (G_OBJECT (status_icon), "orientation");
}

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
static void
gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
{
  GtkStatusIconPrivate *priv = status_icon->priv;
  GdkColor color;

  g_object_get (priv->tray_icon, "fg-color", &color, NULL);
  gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
}

static void
gtk_status_icon_color_changed (GtkTrayIcon   *tray,
                               GParamSpec    *pspec,
                               GtkStatusIcon *status_icon)
{
  GtkStatusIconPrivate *priv = status_icon->priv;
  const gchar *name;
  GdkColor color;

  switch (pspec->name[0])
    {
    case 'e':
      name = "error";
      break;
    case 'w':
      name = "warning";
      break;
    case 's':
      name = "success";
      break;
    default:
      name = NULL;
      break;
    }

  if (name)
    {
      g_object_get (priv->tray_icon, pspec->name, &color, NULL);
      gtk_widget_modify_symbolic_color (priv->image, name, &color);
    }
}

1698 1699 1700 1701 1702 1703 1704 1705 1706
static gboolean
gtk_status_icon_key_press (GtkStatusIcon  *status_icon,
			   GdkEventKey    *event)
{
  guint state, keyval;

  state = event->state & gtk_accelerator_get_default_mod_mask ();
  keyval = event->keyval;
  if (state == 0 &&
1707 1708 1709 1710 1711
      (keyval == GDK_KEY_Return ||
       keyval == GDK_KEY_KP_Enter ||
       keyval == GDK_KEY_ISO_Enter ||
       keyval == GDK_KEY_space ||
       keyval == GDK_KEY_KP_Space))
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
    {
      emit_activate_signal (status_icon);
      return TRUE;
    }

  return FALSE;
}

static void
gtk_status_icon_popup_menu (GtkStatusIcon  *status_icon)
{
  emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
}

1726 1727
#endif

1728 1729 1730 1731
static gboolean
gtk_status_icon_button_press (GtkStatusIcon  *status_icon,
			      GdkEventButton *event)
{
1732 1733 1734 1735 1736 1737 1738 1739
  gboolean handled = FALSE;

  g_signal_emit (status_icon,
		 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
		 event, &handled);
  if (handled)
    return TRUE;

1740
  if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
    {
      emit_activate_signal (status_icon);
      return TRUE;
    }
  else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
    {
      emit_popup_menu_signal (status_icon, event->button, event->time);
      return TRUE;
    }

  return FALSE;
}

1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
static gboolean
gtk_status_icon_button_release (GtkStatusIcon  *status_icon,
				GdkEventButton *event)
{
  gboolean handled = FALSE;
  g_signal_emit (status_icon,
		 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
		 event, &handled);
  return handled;
}

#ifdef GDK_WINDOWING_X11
static gboolean
gtk_status_icon_scroll (GtkStatusIcon  *status_icon,
			GdkEventScroll *event)
{
  gboolean handled = FALSE;
  g_signal_emit (status_icon,
		 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
		 event, &handled);
  return handled;
}
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789

static gboolean
gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
			       gint           x,
			       gint           y,
			       gboolean       keyboard_tip,
			       GtkTooltip    *tooltip)
{
  gboolean handled = FALSE;
  g_signal_emit (status_icon,
		 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
		 x, y, keyboard_tip, tooltip, &handled);
  return handled;
}
1790 1791
#endif /* GDK_WINDOWING_X11 */

1792 1793 1794
static void
gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
{
Matthias Clasen's avatar
Matthias Clasen committed
1795 1796 1797
  GtkStatusIconPrivate *priv = status_icon->priv;

  switch (priv->storage_type)
1798 1799
  {
    case GTK_IMAGE_PIXBUF:
Matthias Clasen's avatar
Matthias Clasen committed
1800 1801 1802
      if (priv->image_data.pixbuf)
	g_object_unref (priv->image_data.pixbuf);
      priv->image_data.pixbuf = NULL;
1803 1804 1805 1806
      g_object_notify (G_OBJECT (status_icon), "pixbuf");
      break;

    case GTK_IMAGE_STOCK:
Matthias Clasen's avatar
Matthias Clasen committed
1807 1808
      g_free (priv->image_data.stock_id);
      priv->image_data.stock_id = NULL;
1809 1810 1811 1812 1813

      g_object_notify (G_OBJECT (status_icon), "stock");
      break;
      
    case GTK_IMAGE_ICON_NAME:
Matthias Clasen's avatar
Matthias Clasen committed
1814 1815
      g_free (priv->image_data.icon_name);
      priv->image_data.icon_name = NULL;
1816 1817