gtkstatusicon.c 79.8 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
#ifdef GDK_WINDOWING_X11
#include "gdk/x11/gdkx.h"
#endif
50 51 52
#ifdef GDK_WINDOWING_WIN32
#include "gdk/win32/gdkwin32.h"
#endif
53

54 55 56 57 58 59 60 61
#ifdef GDK_WINDOWING_WIN32
#include "gtkicontheme.h"
#include "gtklabel.h"

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

62 63 64 65 66
#ifdef GDK_WINDOWING_QUARTZ
#include "gtkicontheme.h"
#include "gtklabel.h"
#endif	

Matthias Clasen's avatar
Matthias Clasen committed
67 68
#include "gdkkeysyms.h"

69 70 71 72 73 74 75 76 77
#define BLINK_TIMEOUT 500

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

enum 
{
  ACTIVATE_SIGNAL,
  POPUP_MENU_SIGNAL,
  SIZE_CHANGED_SIGNAL,
97 98 99
  BUTTON_PRESS_EVENT_SIGNAL,
  BUTTON_RELEASE_EVENT_SIGNAL,
  SCROLL_EVENT_SIGNAL,
100
  QUERY_TOOLTIP_SIGNAL,
101 102 103
  LAST_SIGNAL
};

104 105 106 107 108 109
static guint status_icon_signals [LAST_SIGNAL] = { 0 };

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

110 111
struct _GtkStatusIconPrivate
{
112
#ifdef GDK_WINDOWING_X11
113 114
  GtkWidget    *tray_icon;
  GtkWidget    *image;
115 116 117 118 119
#endif

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

133 134 135 136 137 138 139 140 141 142 143 144
  gint          size;

  gint          image_width;
  gint          image_height;

  GtkImageType  storage_type;

  union
    {
      GdkPixbuf *pixbuf;
      gchar     *stock_id;
      gchar     *icon_name;
145
      GIcon     *gicon;
146 147 148 149 150
    } image_data;

  guint         visible : 1;
};

151 152 153
static GObject* gtk_status_icon_constructor      (GType                  type,
                                                  guint                  n_construct_properties,
                                                  GObjectConstructParam *construct_params);
154 155 156 157 158 159 160 161 162 163
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);

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

184 185 186
static gboolean gtk_status_icon_key_press        (GtkStatusIcon  *status_icon,
						  GdkEventKey    *event);
static void     gtk_status_icon_popup_menu       (GtkStatusIcon  *status_icon);
187
#endif
188 189
static gboolean gtk_status_icon_button_press     (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
190 191
static gboolean gtk_status_icon_button_release   (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
192
static void     gtk_status_icon_reset_image_data (GtkStatusIcon  *status_icon);
Tor Lillqvist's avatar
Tor Lillqvist committed
193
static void     gtk_status_icon_update_image    (GtkStatusIcon *status_icon);
194

Matthias Clasen's avatar
Matthias Clasen committed
195
G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
196 197 198 199 200 201

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

202
  gobject_class->constructor  = gtk_status_icon_constructor;
203 204 205 206
  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;

207 208 209
  class->button_press_event   = NULL;
  class->button_release_event = NULL;
  class->scroll_event         = NULL;
210
  class->query_tooltip        = NULL;
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 240 241 242
  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));
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259

  /**
   * 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));

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
  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));

279 280 281 282 283 284 285 286
  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));

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


296 297 298 299 300 301 302 303 304 305 306
  /**
   * 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"),
307
							 P_("Whether the status icon is embedded"),
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
							 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));

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 364 365 366
/**
 * 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.
   *
367 368 369 370
   * 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.
   *
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 403 404 405
   * 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));


406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
  /**
   * 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
423 424 425 426 427 428 429
  /**
   * 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.
   *
430 431 432
   * 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
433 434
   * Since: 2.10
   */
435
  status_icon_signals [ACTIVATE_SIGNAL] =
Matthias Clasen's avatar
Matthias Clasen committed
436
    g_signal_new (I_("activate"),
437 438 439 440 441 442 443 444 445
		  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
446 447 448 449 450 451 452 453 454 455 456 457
  /**
   * 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
458
   * The @button and @activate_time parameters should be 
Matthias Clasen's avatar
Matthias Clasen committed
459 460
   * passed as the last to arguments to gtk_menu_popup().
   *
461 462 463
   * 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
464 465
   * Since: 2.10
   */
466
  status_icon_signals [POPUP_MENU_SIGNAL] =
467
    g_signal_new (I_("popup-menu"),
468 469 470 471 472 473 474 475 476 477 478
		  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
479 480 481 482 483 484 485 486
  /**
   * 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.
   *
487 488 489
   * 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
490 491
   * Since: 2.10
   */
492
  status_icon_signals [SIZE_CHANGED_SIGNAL] =
493
    g_signal_new (I_("size-changed"),
Matthias Clasen's avatar
Matthias Clasen committed
494
		  G_TYPE_FROM_CLASS (gobject_class),
495
		  G_SIGNAL_RUN_LAST,
496
		  G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
497
		  g_signal_accumulator_true_handled,
498
		  NULL,
Matthias Clasen's avatar
Matthias Clasen committed
499
		  _gtk_marshal_BOOLEAN__INT,
500
		  G_TYPE_BOOLEAN,
501 502 503
		  1,
		  G_TYPE_INT);

504 505 506 507 508 509 510 511
  /**
   * 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.
   *
512 513
   * Whether this event is emitted is platform-dependent.  Use the ::activate
   * and ::popup-menu signals in preference.
514 515 516 517
   *
   * Return value: %TRUE to stop other handlers from being invoked
   * for the event. %FALSE to propagate the event further.
   *
518
   * Since: 2.14
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
   */
  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.
   *
538 539
   * Whether this event is emitted is platform-dependent.  Use the ::activate
   * and ::popup-menu signals in preference.
540 541 542 543
   *
   * Return value: %TRUE to stop other handlers from being invoked
   * for the event. %FALSE to propagate the event further.
   *
544
   * Since: 2.14
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
   */
  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
Matthias Clasen's avatar
Matthias Clasen committed
562
   * range is pressed. Wheel mice are usually configured to generate
563 564 565 566
   * button press events for buttons 4 and 5 when the wheel is turned.
   *
   * Whether this event is emitted is platform-dependent.
   *
Matthias Clasen's avatar
Matthias Clasen committed
567
   * Returns: %TRUE to stop other handlers from being invoked for the event.
568
   *   %FALSE to propagate the event further.
Matthias Clasen's avatar
Matthias Clasen committed
569 570
   *
   * Since: 2.16
571 572 573 574 575 576 577 578 579 580 581
   */
  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);

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 622 623 624
  /**
   * 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);

625 626 627
  g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
}

628 629 630
#ifdef GDK_WINDOWING_WIN32

static void
631 632 633
build_button_event (GtkStatusIconPrivate *priv,
		    GdkEventButton       *e,
		    guint                 button)
634 635 636 637 638 639
{
  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);
640
  e->window = g_object_ref (gdk_get_default_root_window ());
641 642 643
  e->send_event = TRUE;
  e->time = GetTickCount ();
  GetCursorPos (&pos);
644 645
  priv->last_click_x = e->x = pos.x + monitor0.x;
  priv->last_click_y = e->y = pos.y + monitor0.y;
646 647 648
  e->axes = NULL;
  e->state = 0;
  e->button = button;
649
  //FIXME: e->device = gdk_display_get_default ()->core_pointer;
650 651 652 653
  e->x_root = e->x;
  e->y_root = e->y;
}

654 655 656 657 658 659 660 661 662 663 664
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
665
  if (bc->event->type == GDK_BUTTON_PRESS)
666 667 668
    gtk_status_icon_button_press (bc->status_icon, bc->event);
  else
    gtk_status_icon_button_release (bc->status_icon, bc->event);
669 670 671 672 673 674 675

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

  return FALSE;
}

676 677 678
static UINT taskbar_created_msg = 0;
static GSList *status_icons = NULL;

679 680 681 682 683 684
static LRESULT CALLBACK
wndproc (HWND   hwnd,
	 UINT   message,
	 WPARAM wparam,
	 LPARAM lparam)
{
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
  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))
	    {
701
	      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
702 703 704 705 706 707 708 709 710
	      priv->nid.hWnd = NULL;
	      continue;
	    }

	  gtk_status_icon_update_image (status_icon);
	}
      return 0;
    }

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

	case WM_MBUTTONDOWN:
	  button = 2;
	  goto buttondown0;

726
	case WM_RBUTTONDOWN:
727 728 729 730 731 732 733 734 735 736
	  button = 3;
	  goto buttondown0;

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

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

	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;

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
	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;

792 793
  taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");

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

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

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

  return hwnd;
}

#endif

818 819 820
static void
gtk_status_icon_init (GtkStatusIcon *status_icon)
{
Matthias Clasen's avatar
Matthias Clasen committed
821 822 823 824 825
  GtkStatusIconPrivate *priv;

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

Matthias Clasen's avatar
Matthias Clasen committed
827 828
  priv->storage_type = GTK_IMAGE_EMPTY;
  priv->visible      = TRUE;
829 830

#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
831 832 833
  priv->size         = 0;
  priv->image_width  = 0;
  priv->image_height = 0;
834

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

Matthias Clasen's avatar
Matthias Clasen committed
837
  gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
838 839
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
			 GDK_SCROLL_MASK);
840

841 842 843 844
  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);
845 846 847 848
  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);
849 850
  g_signal_connect_swapped (priv->tray_icon, "notify::padding",
			    G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
851 852 853 854 855 856 857 858
  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
859
  g_signal_connect_swapped (priv->tray_icon, "button-press-event",
860
			    G_CALLBACK (gtk_status_icon_button_press), status_icon);
861 862 863 864
  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);
865 866
  g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
			    G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
867 868
  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
869
  priv->image = gtk_image_new ();
870
  gtk_widget_set_can_focus (priv->image, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
871
  gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
872
  gtk_widget_show (priv->image);
873

Matthias Clasen's avatar
Matthias Clasen committed
874
  g_signal_connect_swapped (priv->image, "size-allocate",
875 876
			    G_CALLBACK (gtk_status_icon_size_allocate), status_icon);

877 878 879 880
#endif

#ifdef GDK_WINDOWING_WIN32

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

  priv->last_click_x = priv->last_click_y = 0;
894 895

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

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

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

Matthias Clasen's avatar
Matthias Clasen committed
904 905 906 907
  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;
908

909 910 911 912 913 914 915 916 917 918 919
  /* To help win7 identify the icon create it with an application "unique" tip */
  if (g_get_prgname ())
  {
    WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);

    priv->nid.uFlags |= NIF_TIP;
    wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
    priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
    g_free (wcs);
  }

Matthias Clasen's avatar
Matthias Clasen committed
920
  if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
921
    {
922
      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
Matthias Clasen's avatar
Matthias Clasen committed
923
      priv->nid.hWnd = NULL;
924
    }
925 926 927

  status_icons = g_slist_append (status_icons, status_icon);

928
#endif
929 930 931 932 933 934 935 936
	
#ifdef GDK_WINDOWING_QUARTZ
  priv->dummy_widget = gtk_label_new ("");

  QUARTZ_POOL_ALLOC;

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

937 938
  priv->image_width = priv->image_height = [priv->status_item getHeight];
  priv->size = priv->image_height;
939 940 941 942

  QUARTZ_POOL_RELEASE;

#endif 
943 944
}

945 946 947 948 949 950
static GObject*
gtk_status_icon_constructor (GType                  type,
                             guint                  n_construct_properties,
                             GObjectConstructParam *construct_params)
{
  GObject *object;
951
#ifdef GDK_WINDOWING_X11
952 953
  GtkStatusIcon *status_icon;
  GtkStatusIconPrivate *priv;
954 955
#endif

956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
  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;
}

971 972 973 974
static void
gtk_status_icon_finalize (GObject *object)
{
  GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
Matthias Clasen's avatar
Matthias Clasen committed
975
  GtkStatusIconPrivate *priv = status_icon->priv;
976 977 978

  gtk_status_icon_reset_image_data (status_icon);

979
#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
980 981 982 983 984 985 986 987
  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);
988 989
  g_signal_handlers_disconnect_by_func (priv->tray_icon,
			                gtk_status_icon_padding_changed, status_icon);
990 991 992 993
  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
994 995 996 997 998 999 1000 1001 1002 1003
  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);
1004
  gtk_widget_destroy (priv->image);
Matthias Clasen's avatar
Matthias Clasen committed
1005
  gtk_widget_destroy (priv->tray_icon);
1006 1007 1008
#endif

#ifdef GDK_WINDOWING_WIN32
Matthias Clasen's avatar
Matthias Clasen committed
1009 1010
  if (priv->nid.hWnd != NULL && priv->visible)
    Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1011 1012
  if (priv->nid.hIcon)
    DestroyIcon (priv->nid.hIcon);
1013
  g_free (priv->tooltip_text);
1014

Matthias Clasen's avatar
Matthias Clasen committed
1015
  gtk_widget_destroy (priv->dummy_widget);
1016 1017

  status_icons = g_slist_remove (status_icons, status_icon);
1018
#endif
1019 1020 1021 1022 1023
	
#ifdef GDK_WINDOWING_QUARTZ
  QUARTZ_POOL_ALLOC;
  [priv->status_item release];
  QUARTZ_POOL_RELEASE;
1024
  g_free (priv->tooltip_text);
1025
#endif
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

  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;
1052 1053 1054
    case PROP_GICON:
      gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
      break;
1055 1056 1057
    case PROP_SCREEN:
      gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
      break;
1058 1059 1060
    case PROP_VISIBLE:
      gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
      break;
1061 1062
    case PROP_HAS_TOOLTIP:
      gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1063
      break;
1064 1065
    case PROP_TOOLTIP_TEXT:
      gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1066
      break;
1067 1068
    case PROP_TOOLTIP_MARKUP:
      gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1069
      break;
1070 1071 1072
    case PROP_TITLE:
      gtk_status_icon_set_title (status_icon, g_value_get_string (value));
      break;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
    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
1086 1087 1088 1089 1090 1091 1092
  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
   */
1093 1094 1095 1096

  switch (prop_id)
    {
    case PROP_PIXBUF:
Matthias Clasen's avatar
Matthias Clasen committed
1097 1098 1099 1100
      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));
1101 1102
      break;
    case PROP_STOCK:
Matthias Clasen's avatar
Matthias Clasen committed
1103 1104 1105 1106
      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));
1107 1108
      break;
    case PROP_ICON_NAME:
Matthias Clasen's avatar
Matthias Clasen committed
1109 1110 1111 1112
      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));
1113
      break;
1114 1115 1116 1117
    case PROP_GICON:
      if (priv->storage_type != GTK_IMAGE_GICON)
        g_value_set_object (value, NULL);
      else
Matthias Clasen's avatar
Matthias Clasen committed
1118
        g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1119
      break;
1120 1121 1122 1123 1124 1125
    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;
1126 1127 1128
    case PROP_SCREEN:
      g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
      break;
1129 1130 1131
    case PROP_VISIBLE:
      g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
      break;
1132 1133 1134 1135
    case PROP_EMBEDDED:
      g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
      break;
    case PROP_ORIENTATION:
1136
#ifdef GDK_WINDOWING_X11
1137
      g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1138 1139 1140 1141
#endif
#ifdef GDK_WINDOWING_WIN32
      g_value_set_enum (value, status_icon->priv->orientation);
#endif
1142
      break;
1143 1144 1145 1146 1147 1148 1149 1150 1151
    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;
1152 1153 1154
    case PROP_TITLE:
      g_value_set_string (value, gtk_status_icon_get_title (status_icon));
      break;
1155 1156 1157 1158 1159 1160
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
1161 1162 1163 1164 1165 1166 1167 1168 1169
/**
 * gtk_status_icon_new:
 * 
 * Creates an empty status icon object.
 * 
 * Return value: a new #GtkStatusIcon
 *
 * Since: 2.10
 **/
1170 1171 1172 1173 1174 1175
GtkStatusIcon *
gtk_status_icon_new (void)
{
  return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
/**
 * 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
 **/
1189 1190 1191 1192 1193 1194 1195 1196
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
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
/**
 * 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
 **/
1210 1211 1212 1213 1214 1215 1216 1217
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
1218 1219 1220 1221 1222
/**
 * gtk_status_icon_new_from_stock:
 * @stock_id: a stock icon id
 * 
 * Creates a status icon displaying a stock icon. Sample stock icon
1223
 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your