gtkstatusicon.c 80 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 <string.h>

34 35
#include "gtkstatusicon.h"

36 37
#include "gtkintl.h"
#include "gtkiconfactory.h"
38
#include "gtkmain.h"
39
#include "gtkmarshalers.h"
40
#include "gtksizerequest.h"
41 42
#include "gtkprivate.h"
#include "gtkwidget.h"
43
#include "gtktooltip.h"
44 45 46
#include "gtkicontheme.h"
#include "gtklabel.h"
#include "gtktypebuiltins.h"
47

48 49
#ifdef GDK_WINDOWING_X11
#include "gdk/x11/gdkx.h"
50
#include "gtktrayicon.h"
51 52
#endif

53
#ifdef GDK_WINDOWING_WIN32
54
#include "gdk/win32/gdkwin32.h"
55 56 57
#define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
#endif

58 59 60 61 62 63 64 65 66
#define BLINK_TIMEOUT 500

enum
{
  PROP_0,
  PROP_PIXBUF,
  PROP_FILE,
  PROP_STOCK,
  PROP_ICON_NAME,
67
  PROP_GICON,
68 69
  PROP_STORAGE_TYPE,
  PROP_SIZE,
70
  PROP_SCREEN,
71
  PROP_VISIBLE,
72 73
  PROP_ORIENTATION,
  PROP_EMBEDDED,
74 75 76
  PROP_BLINKING,
  PROP_HAS_TOOLTIP,
  PROP_TOOLTIP_TEXT,
77 78
  PROP_TOOLTIP_MARKUP,
  PROP_TITLE
79 80 81 82 83 84 85
};

enum 
{
  ACTIVATE_SIGNAL,
  POPUP_MENU_SIGNAL,
  SIZE_CHANGED_SIGNAL,
86 87 88
  BUTTON_PRESS_EVENT_SIGNAL,
  BUTTON_RELEASE_EVENT_SIGNAL,
  SCROLL_EVENT_SIGNAL,
89
  QUERY_TOOLTIP_SIGNAL,
90 91 92
  LAST_SIGNAL
};

93 94 95 96 97 98
static guint status_icon_signals [LAST_SIGNAL] = { 0 };

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

99 100
struct _GtkStatusIconPrivate
{
101
#ifdef GDK_WINDOWING_X11
102 103
  GtkWidget    *tray_icon;
  GtkWidget    *image;
104 105 106 107 108
#endif

#ifdef GDK_WINDOWING_WIN32
  GtkWidget     *dummy_widget;
  NOTIFYICONDATAW nid;
109 110
  gint		last_click_x, last_click_y;
  GtkOrientation orientation;
111
  gchar         *tooltip_text;
112
  gchar         *title;
113
#endif
114 115 116 117
	
#ifdef GDK_WINDOWING_QUARTZ
  GtkWidget     *dummy_widget;
  GtkQuartzStatusIcon *status_item;
118
  gchar         *tooltip_text;
119
  gchar         *title;
120
#endif
121

122 123 124 125 126 127 128 129 130 131 132 133
  gint          size;

  gint          image_width;
  gint          image_height;

  GtkImageType  storage_type;

  union
    {
      GdkPixbuf *pixbuf;
      gchar     *stock_id;
      gchar     *icon_name;
134
      GIcon     *gicon;
135 136 137 138 139
    } image_data;

  guint         visible : 1;
};

140 141 142
static GObject* gtk_status_icon_constructor      (GType                  type,
                                                  guint                  n_construct_properties,
                                                  GObjectConstructParam *construct_params);
143 144 145 146 147 148 149 150 151 152
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);

153
#ifdef GDK_WINDOWING_X11
154 155
static void     gtk_status_icon_size_allocate    (GtkStatusIcon  *status_icon,
						  GtkAllocation  *allocation);
156 157
static void     gtk_status_icon_screen_changed   (GtkStatusIcon  *status_icon,
						  GdkScreen      *old_screen);
158 159
static void     gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
static void     gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
160
static void     gtk_status_icon_padding_changed  (GtkStatusIcon *status_icon);
161 162 163 164
static void     gtk_status_icon_fg_changed       (GtkStatusIcon *status_icon);
static void     gtk_status_icon_color_changed    (GtkTrayIcon   *tray,
                                                  GParamSpec    *pspec,
                                                  GtkStatusIcon *status_icon);
165 166
static gboolean gtk_status_icon_scroll           (GtkStatusIcon  *status_icon,
						  GdkEventScroll *event);
167 168 169 170 171
static gboolean gtk_status_icon_query_tooltip    (GtkStatusIcon *status_icon,
						  gint           x,
						  gint           y,
						  gboolean       keyboard_tip,
						  GtkTooltip    *tooltip);
172

173 174 175
static gboolean gtk_status_icon_key_press        (GtkStatusIcon  *status_icon,
						  GdkEventKey    *event);
static void     gtk_status_icon_popup_menu       (GtkStatusIcon  *status_icon);
176
#endif
177 178
static gboolean gtk_status_icon_button_press     (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
179 180
static gboolean gtk_status_icon_button_release   (GtkStatusIcon  *status_icon,
						  GdkEventButton *event);
181
static void     gtk_status_icon_reset_image_data (GtkStatusIcon  *status_icon);
Tor Lillqvist's avatar
Tor Lillqvist committed
182
static void     gtk_status_icon_update_image    (GtkStatusIcon *status_icon);
183

Matthias Clasen's avatar
Matthias Clasen committed
184
G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
185 186 187 188 189 190

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

191
  gobject_class->constructor  = gtk_status_icon_constructor;
192 193 194 195
  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;

196 197 198
  class->button_press_event   = NULL;
  class->button_release_event = NULL;
  class->scroll_event         = NULL;
199
  class->query_tooltip        = NULL;
200

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  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));
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

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

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
  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));

268 269 270 271 272 273 274 275
  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));

276 277 278 279
  g_object_class_install_property (gobject_class,
				   PROP_VISIBLE,
				   g_param_spec_boolean ("visible",
							 P_("Visible"),
280
							 P_("Whether the status icon is visible"),
281 282 283 284
							 TRUE,
							 GTK_PARAM_READWRITE));


285 286 287 288 289 290 291 292 293 294 295
  /**
   * 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"),
296
							 P_("Whether the status icon is embedded"),
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
							 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));

317 318 319 320 321 322 323 324 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
/**
 * 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.
   *
356 357 358 359
   * 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.
   *
360 361 362 363 364 365 366 367 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
   * 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));


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

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

571 572 573 574 575 576 577 578 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
  /**
   * 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);

614 615 616
  g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
}

617 618 619
#ifdef GDK_WINDOWING_WIN32

static void
620 621 622
build_button_event (GtkStatusIconPrivate *priv,
		    GdkEventButton       *e,
		    guint                 button)
623 624 625 626 627 628
{
  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);
629
  e->window = g_object_ref (gdk_get_default_root_window ());
630 631 632
  e->send_event = TRUE;
  e->time = GetTickCount ();
  GetCursorPos (&pos);
633 634
  priv->last_click_x = e->x = pos.x + monitor0.x;
  priv->last_click_y = e->y = pos.y + monitor0.y;
635 636 637
  e->axes = NULL;
  e->state = 0;
  e->button = button;
638
  //FIXME: e->device = gdk_display_get_default ()->core_pointer;
639 640 641 642
  e->x_root = e->x;
  e->y_root = e->y;
}

643 644 645 646 647 648 649 650 651 652 653
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
654
  if (bc->event->type == GDK_BUTTON_PRESS)
655 656 657
    gtk_status_icon_button_press (bc->status_icon, bc->event);
  else
    gtk_status_icon_button_release (bc->status_icon, bc->event);
658 659 660 661 662 663 664

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

  return FALSE;
}

665 666 667
static UINT taskbar_created_msg = 0;
static GSList *status_icons = NULL;

668 669 670 671 672 673
static LRESULT CALLBACK
wndproc (HWND   hwnd,
	 UINT   message,
	 WPARAM wparam,
	 LPARAM lparam)
{
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  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))
	    {
690
	      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
691 692 693 694 695 696 697 698 699
	      priv->nid.hWnd = NULL;
	      continue;
	    }

	  gtk_status_icon_update_image (status_icon);
	}
      return 0;
    }

700 701
  if (message == WM_GTK_TRAY_NOTIFICATION)
    {
702
      ButtonCallbackData *bc;
703
      guint button;
704 705 706 707
      
      switch (lparam)
	{
	case WM_LBUTTONDOWN:
708 709 710 711 712 713 714
	  button = 1;
	  goto buttondown0;

	case WM_MBUTTONDOWN:
	  button = 2;
	  goto buttondown0;

715
	case WM_RBUTTONDOWN:
716 717 718 719 720 721 722 723 724 725
	  button = 3;
	  goto buttondown0;

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

	buttondown0:
726 727 728
	  bc = g_new (ButtonCallbackData, 1);
	  bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
	  bc->status_icon = GTK_STATUS_ICON (wparam);
729
	  build_button_event (bc->status_icon->priv, bc->event, button);
730
	  g_idle_add (button_callback, bc);
731
	  break;
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758

	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;

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
	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;

781 782
  taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");

783 784 785 786 787 788 789 790 791
  memset (&wclass, 0, sizeof(WNDCLASS));
  wclass.lpszClassName = "gtkstatusicon-observer";
  wclass.lpfnWndProc   = wndproc;
  wclass.hInstance     = hmodule;

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

792
  hwnd = CreateWindow (MAKEINTRESOURCE (klass),
793 794 795 796 797 798 799 800 801 802 803 804 805 806
                       NULL, WS_POPUP,
                       0, 0, 1, 1, NULL, NULL,
                       hmodule, NULL);
  if (!hwnd)
    {
      UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
      return NULL;
    }

  return hwnd;
}

#endif

807 808 809
static void
gtk_status_icon_init (GtkStatusIcon *status_icon)
{
Matthias Clasen's avatar
Matthias Clasen committed
810 811 812 813 814
  GtkStatusIconPrivate *priv;

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

Matthias Clasen's avatar
Matthias Clasen committed
816 817
  priv->storage_type = GTK_IMAGE_EMPTY;
  priv->visible      = TRUE;
818 819

#ifdef GDK_WINDOWING_X11
Matthias Clasen's avatar
Matthias Clasen committed
820 821 822
  priv->size         = 0;
  priv->image_width  = 0;
  priv->image_height = 0;
823

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

Matthias Clasen's avatar
Matthias Clasen committed
826
  gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
827 828
			 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
			 GDK_SCROLL_MASK);
829

830 831 832 833
  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);
834 835 836 837
  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);
838 839
  g_signal_connect_swapped (priv->tray_icon, "notify::padding",
			    G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
840 841 842 843 844 845 846 847
  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
848
  g_signal_connect_swapped (priv->tray_icon, "button-press-event",
849
			    G_CALLBACK (gtk_status_icon_button_press), status_icon);
850 851 852 853
  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);
854 855
  g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
			    G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
856 857
  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
858
  priv->image = gtk_image_new ();
859
  gtk_widget_set_can_focus (priv->image, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
860
  gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
861
  gtk_widget_show (priv->image);
862

863 864 865 866 867 868
  /* Force-initialize the symbolic colors */
  g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
  g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
  g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
  g_object_notify (G_OBJECT (priv->tray_icon), "success-color");

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

872 873 874 875
#endif

#ifdef GDK_WINDOWING_WIN32

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

  priv->last_click_x = priv->last_click_y = 0;
889 890

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

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

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

Matthias Clasen's avatar
Matthias Clasen committed
899 900 901 902
  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;
903

904 905 906 907 908 909 910 911 912 913 914
  /* 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
915
  if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
916
    {
917
      g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
Matthias Clasen's avatar
Matthias Clasen committed
918
      priv->nid.hWnd = NULL;
919
    }
920 921 922

  status_icons = g_slist_append (status_icons, status_icon);

923
#endif
924 925 926 927 928 929 930 931
	
#ifdef GDK_WINDOWING_QUARTZ
  priv->dummy_widget = gtk_label_new ("");

  QUARTZ_POOL_ALLOC;

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

932 933
  priv->image_width = priv->image_height = [priv->status_item getHeight];
  priv->size = priv->image_height;
934 935 936 937

  QUARTZ_POOL_RELEASE;

#endif 
938 939
}

940 941 942 943 944 945
static GObject*
gtk_status_icon_constructor (GType                  type,
                             guint                  n_construct_properties,
                             GObjectConstructParam *construct_params)
{
  GObject *object;
946
#ifdef GDK_WINDOWING_X11
947 948
  GtkStatusIcon *status_icon;
  GtkStatusIconPrivate *priv;
949 950
#endif

951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
  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;
}

966 967 968 969
static void
gtk_status_icon_finalize (GObject *object)
{
  GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
Matthias Clasen's avatar
Matthias Clasen committed
970
  GtkStatusIconPrivate *priv = status_icon->priv;
971 972 973

  gtk_status_icon_reset_image_data (status_icon);

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

#ifdef GDK_WINDOWING_WIN32
Matthias Clasen's avatar
Matthias Clasen committed
1004 1005
  if (priv->nid.hWnd != NULL && priv->visible)
    Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1006 1007
  if (priv->nid.hIcon)
    DestroyIcon (priv->nid.hIcon);
1008
  g_free (priv->tooltip_text);
1009

Matthias Clasen's avatar
Matthias Clasen committed
1010
  gtk_widget_destroy (priv->dummy_widget);
1011 1012

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

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

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

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

Matthias Clasen's avatar
Matthias Clasen committed
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
/**
 * 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
 **/
1184 1185 1186 1187 1188 1189 1190 1191
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
1192 1193
/**
 * gtk_status_icon_new_from_file:
1194
 * @filename: (type filename): a filename
Matthias Clasen's avatar
Matthias Clasen committed
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
 * 
 * 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
 **/
1205 1206 1207 1208 1209 1210 1211