3 * Copyright (C) 2003 Sun Microsystems, Inc.
4 * Copyright (C) 2005 Hans Breuer <hans@breuer.org>
5 * Copyright (C) 2005 Novell, Inc.
6 * Copyright (C) 2006 Imendio AB
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Mark McLoughlin <mark@skynet.ie>
25 * Hans Breuer <hans@breuer.org>
26 * Tor Lillqvist <tml@novell.com>
27 * Mikael Hallendal <micke@imendio.com>
33 #include "gtkstatusicon.h"
36 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
39 #include "gtktrayicon.h"
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
43 #include "gtktooltip.h"
45 #ifdef GDK_WINDOWING_X11
46 #include "gdk/x11/gdkx.h"
49 #ifdef GDK_WINDOWING_WIN32
50 #include "gtkicontheme.h"
53 #include "win32/gdkwin32.h"
54 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
57 #ifdef GDK_WINDOWING_QUARTZ
58 #include "gtkicontheme.h"
62 #include "gdkkeysyms.h"
66 #define BLINK_TIMEOUT 500
94 BUTTON_PRESS_EVENT_SIGNAL,
95 BUTTON_RELEASE_EVENT_SIGNAL,
101 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
103 #ifdef GDK_WINDOWING_QUARTZ
104 #include "gtkstatusicon-quartz.c"
107 struct _GtkStatusIconPrivate
109 #ifdef GDK_WINDOWING_X11
110 GtkWidget *tray_icon;
114 #ifdef GDK_WINDOWING_WIN32
115 GtkWidget *dummy_widget;
117 gint last_click_x, last_click_y;
118 GtkOrientation orientation;
123 #ifdef GDK_WINDOWING_QUARTZ
124 GtkWidget *dummy_widget;
125 GtkQuartzStatusIcon *status_item;
135 GtkImageType storage_type;
145 GdkPixbuf *blank_icon;
146 guint blinking_timeout;
153 static GObject* gtk_status_icon_constructor (GType type,
154 guint n_construct_properties,
155 GObjectConstructParam *construct_params);
156 static void gtk_status_icon_finalize (GObject *object);
157 static void gtk_status_icon_set_property (GObject *object,
161 static void gtk_status_icon_get_property (GObject *object,
166 #ifdef GDK_WINDOWING_X11
167 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
168 GtkAllocation *allocation);
169 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
170 GdkScreen *old_screen);
171 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
172 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
173 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
174 GdkEventScroll *event);
175 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
178 gboolean keyboard_tip,
179 GtkTooltip *tooltip);
181 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
183 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
185 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
186 GdkEventButton *event);
187 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
188 GdkEventButton *event);
189 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
190 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
191 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
193 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
196 gtk_status_icon_class_init (GtkStatusIconClass *class)
198 GObjectClass *gobject_class = (GObjectClass *) class;
200 gobject_class->constructor = gtk_status_icon_constructor;
201 gobject_class->finalize = gtk_status_icon_finalize;
202 gobject_class->set_property = gtk_status_icon_set_property;
203 gobject_class->get_property = gtk_status_icon_get_property;
205 class->button_press_event = NULL;
206 class->button_release_event = NULL;
207 class->scroll_event = NULL;
208 class->query_tooltip = NULL;
210 g_object_class_install_property (gobject_class,
212 g_param_spec_object ("pixbuf",
214 P_("A GdkPixbuf to display"),
216 GTK_PARAM_READWRITE));
218 g_object_class_install_property (gobject_class,
220 g_param_spec_string ("file",
222 P_("Filename to load and display"),
224 GTK_PARAM_WRITABLE));
226 g_object_class_install_property (gobject_class,
228 g_param_spec_string ("stock",
230 P_("Stock ID for a stock image to display"),
232 GTK_PARAM_READWRITE));
234 g_object_class_install_property (gobject_class,
236 g_param_spec_string ("icon-name",
238 P_("The name of the icon from the icon theme"),
240 GTK_PARAM_READWRITE));
243 * GtkStatusIcon:gicon:
245 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
246 * the image will be updated automatically if the theme changes.
250 g_object_class_install_property (gobject_class,
252 g_param_spec_object ("gicon",
254 P_("The GIcon being displayed"),
256 GTK_PARAM_READWRITE));
258 g_object_class_install_property (gobject_class,
260 g_param_spec_enum ("storage-type",
262 P_("The representation being used for image data"),
265 GTK_PARAM_READABLE));
267 g_object_class_install_property (gobject_class,
269 g_param_spec_int ("size",
271 P_("The size of the icon"),
275 GTK_PARAM_READABLE));
277 g_object_class_install_property (gobject_class,
279 g_param_spec_object ("screen",
281 P_("The screen where this status icon will be displayed"),
283 GTK_PARAM_READWRITE));
285 g_object_class_install_property (gobject_class,
287 g_param_spec_boolean ("blinking",
289 P_("Whether or not the status icon is blinking"),
291 GTK_PARAM_READWRITE));
293 g_object_class_install_property (gobject_class,
295 g_param_spec_boolean ("visible",
297 P_("Whether or not the status icon is visible"),
299 GTK_PARAM_READWRITE));
303 * GtkStatusIcon:embedded:
305 * %TRUE if the statusicon is embedded in a notification area.
309 g_object_class_install_property (gobject_class,
311 g_param_spec_boolean ("embedded",
313 P_("Whether or not the status icon is embedded"),
315 GTK_PARAM_READABLE));
318 * GtkStatusIcon:orientation:
320 * The orientation of the tray in which the statusicon
325 g_object_class_install_property (gobject_class,
327 g_param_spec_enum ("orientation",
329 P_("The orientation of the tray"),
330 GTK_TYPE_ORIENTATION,
331 GTK_ORIENTATION_HORIZONTAL,
332 GTK_PARAM_READABLE));
335 * GtkStatusIcon:has-tooltip:
337 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
338 * @status_icon. A value of %TRUE indicates that @status_icon can have a
339 * tooltip, in this case the status icon will be queried using
340 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
343 * Note that setting this property to %TRUE for the first time will change
344 * the event masks of the windows of this status icon to include leave-notify
345 * and motion-notify events. This will not be undone when the property is set
348 * Whether this property is respected is platform dependent.
349 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
353 g_object_class_install_property (gobject_class,
355 g_param_spec_boolean ("has-tooltip",
357 P_("Whether this tray icon has a tooltip"),
359 GTK_PARAM_READWRITE));
361 * GtkStatusIcon:tooltip-text:
363 * Sets the text of tooltip to be the given string.
365 * Also see gtk_tooltip_set_text().
367 * This is a convenience property which will take care of getting the
368 * tooltip shown if the given string is not %NULL.
369 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
370 * the default handler for the #GtkStatusIcon::query-tooltip signal
371 * will take care of displaying the tooltip.
373 * Note that some platforms have limitations on the length of tooltips
374 * that they allow on status icons, e.g. Windows only shows the first
379 g_object_class_install_property (gobject_class,
381 g_param_spec_string ("tooltip-text",
383 P_("The contents of the tooltip for this widget"),
385 GTK_PARAM_READWRITE));
387 * GtkStatusIcon:tooltip-markup:
389 * Sets the text of tooltip to be the given string, which is marked up
390 * with the <link linkend="PangoMarkupFormat">Pango text markup
391 * language</link>. Also see gtk_tooltip_set_markup().
393 * This is a convenience property which will take care of getting the
394 * tooltip shown if the given string is not %NULL.
395 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
396 * the default handler for the #GtkStatusIcon::query-tooltip signal
397 * will take care of displaying the tooltip.
399 * On some platforms, embedded markup will be ignored.
403 g_object_class_install_property (gobject_class,
405 g_param_spec_string ("tooltip-markup",
406 P_("Tooltip markup"),
407 P_("The contents of the tooltip for this tray icon"),
409 GTK_PARAM_READWRITE));
413 * GtkStatusIcon:title:
415 * The title of this tray icon. This should be a short, human-readable,
416 * localized string describing the tray icon. It may be used by tools
417 * like screen readers to render the tray icon.
421 g_object_class_install_property (gobject_class,
423 g_param_spec_string ("title",
425 P_("The title of this tray icon"),
427 GTK_PARAM_READWRITE));
430 * GtkStatusIcon::activate:
431 * @status_icon: the object which received the signal
433 * Gets emitted when the user activates the status icon.
434 * If and how status icons can activated is platform-dependent.
436 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
437 * be used by applications and should be wrapped by language bindings.
441 status_icon_signals [ACTIVATE_SIGNAL] =
442 g_signal_new (I_("activate"),
443 G_TYPE_FROM_CLASS (gobject_class),
444 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
445 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
448 g_cclosure_marshal_VOID__VOID,
453 * GtkStatusIcon::popup-menu:
454 * @status_icon: the object which received the signal
455 * @button: the button that was pressed, or 0 if the
456 * signal is not emitted in response to a button press event
457 * @activate_time: the timestamp of the event that
458 * triggered the signal emission
460 * Gets emitted when the user brings up the context menu
461 * of the status icon. Whether status icons can have context
462 * menus and how these are activated is platform-dependent.
464 * The @button and @activate_time parameters should be
465 * passed as the last to arguments to gtk_menu_popup().
467 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
468 * be used by applications and should be wrapped by language bindings.
472 status_icon_signals [POPUP_MENU_SIGNAL] =
473 g_signal_new (I_("popup-menu"),
474 G_TYPE_FROM_CLASS (gobject_class),
475 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
476 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
479 _gtk_marshal_VOID__UINT_UINT,
486 * GtkStatusIcon::size-changed:
487 * @status_icon: the object which received the signal
488 * @size: the new size
490 * Gets emitted when the size available for the image
491 * changes, e.g. because the notification area got resized.
493 * Return value: %TRUE if the icon was updated for the new
494 * size. Otherwise, GTK+ will scale the icon as necessary.
498 status_icon_signals [SIZE_CHANGED_SIGNAL] =
499 g_signal_new (I_("size-changed"),
500 G_TYPE_FROM_CLASS (gobject_class),
502 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
503 g_signal_accumulator_true_handled,
505 _gtk_marshal_BOOLEAN__INT,
511 * GtkStatusIcon::button-press-event:
512 * @status_icon: the object which received the signal
513 * @event: the #GdkEventButton which triggered this signal
515 * The ::button-press-event signal will be emitted when a button
516 * (typically from a mouse) is pressed.
518 * Whether this event is emitted is platform-dependent. Use the ::activate
519 * and ::popup-menu signals in preference.
521 * Return value: %TRUE to stop other handlers from being invoked
522 * for the event. %FALSE to propagate the event further.
526 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
527 g_signal_new (I_("button_press_event"),
528 G_TYPE_FROM_CLASS (gobject_class),
530 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
531 g_signal_accumulator_true_handled, NULL,
532 _gtk_marshal_BOOLEAN__BOXED,
534 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
537 * GtkStatusIcon::button-release-event:
538 * @status_icon: the object which received the signal
539 * @event: the #GdkEventButton which triggered this signal
541 * The ::button-release-event signal will be emitted when a button
542 * (typically from a mouse) is released.
544 * Whether this event is emitted is platform-dependent. Use the ::activate
545 * and ::popup-menu signals in preference.
547 * Return value: %TRUE to stop other handlers from being invoked
548 * for the event. %FALSE to propagate the event further.
552 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
553 g_signal_new (I_("button_release_event"),
554 G_TYPE_FROM_CLASS (gobject_class),
556 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
557 g_signal_accumulator_true_handled, NULL,
558 _gtk_marshal_BOOLEAN__BOXED,
560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
563 * GtkStatusIcon::scroll-event:
564 * @status_icon: the object which received the signal.
565 * @event: the #GdkEventScroll which triggered this signal
567 * The ::scroll-event signal is emitted when a button in the 4 to 7
568 * range is pressed. Wheel mice are usually configured to generate
569 * button press events for buttons 4 and 5 when the wheel is turned.
571 * Whether this event is emitted is platform-dependent.
573 * Returns: %TRUE to stop other handlers from being invoked for the event.
574 * %FALSE to propagate the event further.
576 status_icon_signals[SCROLL_EVENT_SIGNAL] =
577 g_signal_new (I_("scroll_event"),
578 G_TYPE_FROM_CLASS (gobject_class),
580 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
581 g_signal_accumulator_true_handled, NULL,
582 _gtk_marshal_BOOLEAN__BOXED,
584 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
587 * GtkStatusIcon::query-tooltip:
588 * @status_icon: the object which received the signal
589 * @x: the x coordinate of the cursor position where the request has been
590 * emitted, relative to @status_icon
591 * @y: the y coordinate of the cursor position where the request has been
592 * emitted, relative to @status_icon
593 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
594 * @tooltip: a #GtkTooltip
596 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
597 * cursor hovering above @status_icon; or emitted when @status_icon got
598 * focus in keyboard mode.
600 * Using the given coordinates, the signal handler should determine
601 * whether a tooltip should be shown for @status_icon. If this is
602 * the case %TRUE should be returned, %FALSE otherwise. Note that if
603 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
604 * should not be used.
606 * The signal handler is free to manipulate @tooltip with the therefore
607 * destined function calls.
609 * Whether this signal is emitted is platform-dependent.
610 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
612 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
616 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
617 g_signal_new (I_("query_tooltip"),
618 G_TYPE_FROM_CLASS (gobject_class),
620 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
621 g_signal_accumulator_true_handled, NULL,
622 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
629 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
632 #ifdef GDK_WINDOWING_WIN32
635 build_button_event (GtkStatusIconPrivate *priv,
640 GdkRectangle monitor0;
642 /* We know that gdk/win32 puts the primary monitor at index 0 */
643 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
644 e->window = g_object_ref (gdk_get_default_root_window ());
645 e->send_event = TRUE;
646 e->time = GetTickCount ();
648 priv->last_click_x = e->x = pos.x + monitor0.x;
649 priv->last_click_y = e->y = pos.y + monitor0.y;
653 e->device = gdk_display_get_default ()->core_pointer;
660 GtkStatusIcon *status_icon;
661 GdkEventButton *event;
662 } ButtonCallbackData;
665 button_callback (gpointer data)
667 ButtonCallbackData *bc = (ButtonCallbackData *) data;
669 if (bc->event->type == GDK_BUTTON_PRESS)
670 gtk_status_icon_button_press (bc->status_icon, bc->event);
672 gtk_status_icon_button_release (bc->status_icon, bc->event);
674 gdk_event_free ((GdkEvent *) bc->event);
680 static UINT taskbar_created_msg = 0;
681 static GSList *status_icons = NULL;
683 static LRESULT CALLBACK
689 if (message == taskbar_created_msg)
693 for (rover = status_icons; rover != NULL; rover = rover->next)
695 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
696 GtkStatusIconPrivate *priv = status_icon->priv;
698 priv->nid.hWnd = hwnd;
699 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
700 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
701 priv->nid.uFlags = NIF_MESSAGE;
703 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
705 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
706 priv->nid.hWnd = NULL;
710 gtk_status_icon_update_image (status_icon);
715 if (message == WM_GTK_TRAY_NOTIFICATION)
717 ButtonCallbackData *bc;
735 if (HIWORD (wparam) == XBUTTON1)
741 bc = g_new (ButtonCallbackData, 1);
742 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
743 bc->status_icon = GTK_STATUS_ICON (wparam);
744 build_button_event (bc->status_icon->priv, bc->event, button);
745 g_idle_add (button_callback, bc);
761 if (HIWORD (wparam) == XBUTTON1)
767 bc = g_new (ButtonCallbackData, 1);
768 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
769 bc->status_icon = GTK_STATUS_ICON (wparam);
770 build_button_event (bc->status_icon->priv, bc->event, button);
771 g_idle_add (button_callback, bc);
781 return DefWindowProc (hwnd, message, wparam, lparam);
786 create_tray_observer (void)
789 static HWND hwnd = NULL;
791 HINSTANCE hmodule = GetModuleHandle (NULL);
796 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
798 memset (&wclass, 0, sizeof(WNDCLASS));
799 wclass.lpszClassName = "gtkstatusicon-observer";
800 wclass.lpfnWndProc = wndproc;
801 wclass.hInstance = hmodule;
803 klass = RegisterClass (&wclass);
807 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
809 0, 0, 1, 1, NULL, NULL,
813 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
823 gtk_status_icon_init (GtkStatusIcon *status_icon)
825 GtkStatusIconPrivate *priv;
827 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
828 GtkStatusIconPrivate);
829 status_icon->priv = priv;
831 priv->storage_type = GTK_IMAGE_EMPTY;
832 priv->visible = TRUE;
834 #ifdef GDK_WINDOWING_X11
836 priv->image_width = 0;
837 priv->image_height = 0;
839 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
841 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
842 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
845 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
846 G_CALLBACK (gtk_status_icon_key_press), status_icon);
847 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
848 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
849 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
850 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
851 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
852 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
853 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
854 G_CALLBACK (gtk_status_icon_button_press), status_icon);
855 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
856 G_CALLBACK (gtk_status_icon_button_release), status_icon);
857 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
858 G_CALLBACK (gtk_status_icon_scroll), status_icon);
859 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
860 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
861 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
862 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
863 priv->image = gtk_image_new ();
864 GTK_WIDGET_SET_FLAGS (priv->image, GTK_CAN_FOCUS);
865 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
866 gtk_widget_show (priv->image);
868 g_signal_connect_swapped (priv->image, "size-allocate",
869 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
873 #ifdef GDK_WINDOWING_WIN32
875 /* Get position and orientation of Windows taskbar. */
879 abd.cbSize = sizeof (abd);
880 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
881 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
882 priv->orientation = GTK_ORIENTATION_VERTICAL;
884 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
887 priv->last_click_x = priv->last_click_y = 0;
889 /* Are the system tray icons always 16 pixels square? */
891 priv->image_width = 16;
892 priv->image_height = 16;
894 priv->dummy_widget = gtk_label_new ("");
896 memset (&priv->nid, 0, sizeof (priv->nid));
898 priv->nid.hWnd = create_tray_observer ();
899 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
900 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
901 priv->nid.uFlags = NIF_MESSAGE;
903 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
905 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
906 priv->nid.hWnd = NULL;
909 status_icons = g_slist_append (status_icons, status_icon);
913 #ifdef GDK_WINDOWING_QUARTZ
914 priv->dummy_widget = gtk_label_new ("");
918 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
920 priv->image_width = priv->image_height = [priv->status_item getHeight];
921 priv->size = priv->image_height;
929 gtk_status_icon_constructor (GType type,
930 guint n_construct_properties,
931 GObjectConstructParam *construct_params)
934 #ifdef GDK_WINDOWING_X11
935 GtkStatusIcon *status_icon;
936 GtkStatusIconPrivate *priv;
939 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
940 n_construct_properties,
943 #ifdef GDK_WINDOWING_X11
944 status_icon = GTK_STATUS_ICON (object);
945 priv = status_icon->priv;
948 gtk_widget_show (priv->tray_icon);
955 gtk_status_icon_finalize (GObject *object)
957 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
958 GtkStatusIconPrivate *priv = status_icon->priv;
960 gtk_status_icon_disable_blinking (status_icon);
962 gtk_status_icon_reset_image_data (status_icon);
964 if (priv->blank_icon)
965 g_object_unref (priv->blank_icon);
966 priv->blank_icon = NULL;
968 #ifdef GDK_WINDOWING_X11
969 g_signal_handlers_disconnect_by_func (priv->tray_icon,
970 gtk_status_icon_key_press, status_icon);
971 g_signal_handlers_disconnect_by_func (priv->tray_icon,
972 gtk_status_icon_popup_menu, status_icon);
973 g_signal_handlers_disconnect_by_func (priv->tray_icon,
974 gtk_status_icon_embedded_changed, status_icon);
975 g_signal_handlers_disconnect_by_func (priv->tray_icon,
976 gtk_status_icon_orientation_changed, status_icon);
977 g_signal_handlers_disconnect_by_func (priv->tray_icon,
978 gtk_status_icon_button_press, status_icon);
979 g_signal_handlers_disconnect_by_func (priv->tray_icon,
980 gtk_status_icon_button_release, status_icon);
981 g_signal_handlers_disconnect_by_func (priv->tray_icon,
982 gtk_status_icon_scroll, status_icon);
983 g_signal_handlers_disconnect_by_func (priv->tray_icon,
984 gtk_status_icon_query_tooltip, status_icon);
985 g_signal_handlers_disconnect_by_func (priv->tray_icon,
986 gtk_status_icon_screen_changed, status_icon);
987 gtk_widget_destroy (priv->image);
988 gtk_widget_destroy (priv->tray_icon);
991 #ifdef GDK_WINDOWING_WIN32
992 if (priv->nid.hWnd != NULL && priv->visible)
993 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
995 DestroyIcon (priv->nid.hIcon);
996 g_free (priv->tooltip_text);
998 gtk_widget_destroy (priv->dummy_widget);
1000 status_icons = g_slist_remove (status_icons, status_icon);
1003 #ifdef GDK_WINDOWING_QUARTZ
1005 [priv->status_item release];
1006 QUARTZ_POOL_RELEASE;
1007 g_free (priv->tooltip_text);
1010 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1014 gtk_status_icon_set_property (GObject *object,
1016 const GValue *value,
1019 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1024 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1027 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1030 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1032 case PROP_ICON_NAME:
1033 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1036 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1039 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1042 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
1045 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1047 case PROP_HAS_TOOLTIP:
1048 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1050 case PROP_TOOLTIP_TEXT:
1051 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1053 case PROP_TOOLTIP_MARKUP:
1054 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1057 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1060 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1066 gtk_status_icon_get_property (GObject *object,
1071 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1072 GtkStatusIconPrivate *priv = status_icon->priv;
1074 /* The "getter" functions whine if you try to get the wrong
1075 * storage type. This function is instead robust against that,
1076 * so that GUI builders don't have to jump through hoops
1077 * to avoid g_warning
1083 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1084 g_value_set_object (value, NULL);
1086 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1089 if (priv->storage_type != GTK_IMAGE_STOCK)
1090 g_value_set_string (value, NULL);
1092 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1094 case PROP_ICON_NAME:
1095 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1096 g_value_set_string (value, NULL);
1098 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1101 if (priv->storage_type != GTK_IMAGE_GICON)
1102 g_value_set_object (value, NULL);
1104 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1106 case PROP_STORAGE_TYPE:
1107 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1110 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1113 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1116 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
1119 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1122 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1124 case PROP_ORIENTATION:
1125 #ifdef GDK_WINDOWING_X11
1126 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1128 #ifdef GDK_WINDOWING_WIN32
1129 g_value_set_enum (value, status_icon->priv->orientation);
1132 case PROP_HAS_TOOLTIP:
1133 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1135 case PROP_TOOLTIP_TEXT:
1136 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1138 case PROP_TOOLTIP_MARKUP:
1139 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1142 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1151 * gtk_status_icon_new:
1153 * Creates an empty status icon object.
1155 * Return value: a new #GtkStatusIcon
1160 gtk_status_icon_new (void)
1162 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1166 * gtk_status_icon_new_from_pixbuf:
1167 * @pixbuf: a #GdkPixbuf
1169 * Creates a status icon displaying @pixbuf.
1171 * The image will be scaled down to fit in the available
1172 * space in the notification area, if necessary.
1174 * Return value: a new #GtkStatusIcon
1179 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1181 return g_object_new (GTK_TYPE_STATUS_ICON,
1187 * gtk_status_icon_new_from_file:
1188 * @filename: a filename
1190 * Creates a status icon displaying the file @filename.
1192 * The image will be scaled down to fit in the available
1193 * space in the notification area, if necessary.
1195 * Return value: a new #GtkStatusIcon
1200 gtk_status_icon_new_from_file (const gchar *filename)
1202 return g_object_new (GTK_TYPE_STATUS_ICON,
1208 * gtk_status_icon_new_from_stock:
1209 * @stock_id: a stock icon id
1211 * Creates a status icon displaying a stock icon. Sample stock icon
1212 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1213 * own stock icon names, see gtk_icon_factory_add_default() and
1214 * gtk_icon_factory_add().
1216 * Return value: a new #GtkStatusIcon
1221 gtk_status_icon_new_from_stock (const gchar *stock_id)
1223 return g_object_new (GTK_TYPE_STATUS_ICON,
1229 * gtk_status_icon_new_from_icon_name:
1230 * @icon_name: an icon name
1232 * Creates a status icon displaying an icon from the current icon theme.
1233 * If the current icon theme is changed, the icon will be updated
1236 * Return value: a new #GtkStatusIcon
1241 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1243 return g_object_new (GTK_TYPE_STATUS_ICON,
1244 "icon-name", icon_name,
1249 * gtk_status_icon_new_from_gicon:
1252 * Creates a status icon displaying a #GIcon. If the icon is a
1253 * themed icon, it will be updated when the theme changes.
1255 * Return value: a new #GtkStatusIcon
1260 gtk_status_icon_new_from_gicon (GIcon *icon)
1262 return g_object_new (GTK_TYPE_STATUS_ICON,
1268 emit_activate_signal (GtkStatusIcon *status_icon)
1270 g_signal_emit (status_icon,
1271 status_icon_signals [ACTIVATE_SIGNAL], 0);
1275 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1277 guint32 activate_time)
1279 g_signal_emit (status_icon,
1280 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1285 #ifdef GDK_WINDOWING_X11
1288 emit_size_changed_signal (GtkStatusIcon *status_icon,
1291 gboolean handled = FALSE;
1293 g_signal_emit (status_icon,
1294 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1304 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
1306 GtkStatusIconPrivate *priv = status_icon->priv;
1308 if (priv->blank_icon)
1312 width = gdk_pixbuf_get_width (priv->blank_icon);
1313 height = gdk_pixbuf_get_height (priv->blank_icon);
1316 if (width == priv->image_width && height == priv->image_height)
1317 return priv->blank_icon;
1320 g_object_unref (priv->blank_icon);
1321 priv->blank_icon = NULL;
1325 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
1327 priv->image_height);
1328 if (priv->blank_icon)
1329 gdk_pixbuf_fill (priv->blank_icon, 0);
1331 return priv->blank_icon;
1334 #ifdef GDK_WINDOWING_X11
1337 find_icon_size (GtkWidget *widget,
1341 GtkSettings *settings;
1342 GtkIconSize s, size;
1345 screen = gtk_widget_get_screen (widget);
1348 return GTK_ICON_SIZE_MENU;
1350 settings = gtk_settings_get_for_screen (screen);
1353 size = GTK_ICON_SIZE_MENU;
1355 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1357 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1358 w <= pixel_size && h <= pixel_size)
1360 d = MAX (pixel_size - w, pixel_size - h);
1375 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1377 GtkStatusIconPrivate *priv = status_icon->priv;
1378 #ifdef GDK_WINDOWING_WIN32
1382 if (priv->blink_off)
1384 #ifdef GDK_WINDOWING_X11
1385 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
1386 gtk_status_icon_blank_icon (status_icon));
1388 #ifdef GDK_WINDOWING_WIN32
1389 prev_hicon = priv->nid.hIcon;
1390 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
1391 priv->nid.uFlags |= NIF_ICON;
1392 if (priv->nid.hWnd != NULL && priv->visible)
1393 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1394 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1396 DestroyIcon (prev_hicon);
1398 #ifdef GDK_WINDOWING_QUARTZ
1400 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
1401 QUARTZ_POOL_RELEASE;
1406 switch (priv->storage_type)
1408 case GTK_IMAGE_PIXBUF:
1412 pixbuf = priv->image_data.pixbuf;
1423 width = gdk_pixbuf_get_width (pixbuf);
1424 height = gdk_pixbuf_get_height (pixbuf);
1426 if (width > size || height > size)
1427 scaled = gdk_pixbuf_scale_simple (pixbuf,
1430 GDK_INTERP_BILINEAR);
1432 scaled = g_object_ref (pixbuf);
1434 #ifdef GDK_WINDOWING_X11
1435 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1437 #ifdef GDK_WINDOWING_WIN32
1438 prev_hicon = priv->nid.hIcon;
1439 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1440 priv->nid.uFlags |= NIF_ICON;
1441 if (priv->nid.hWnd != NULL && priv->visible)
1442 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1443 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1445 DestroyIcon (prev_hicon);
1447 #ifdef GDK_WINDOWING_QUARTZ
1449 [priv->status_item setImage:scaled];
1450 QUARTZ_POOL_RELEASE;
1453 g_object_unref (scaled);
1457 #ifdef GDK_WINDOWING_X11
1458 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1460 #ifdef GDK_WINDOWING_WIN32
1461 priv->nid.uFlags &= ~NIF_ICON;
1462 if (priv->nid.hWnd != NULL && priv->visible)
1463 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1464 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1466 #ifdef GDK_WINDOWING_QUARTZ
1467 [priv->status_item setImage:NULL];
1473 case GTK_IMAGE_STOCK:
1475 #ifdef GDK_WINDOWING_X11
1476 GtkIconSize size = find_icon_size (priv->image, priv->size);
1477 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1478 priv->image_data.stock_id,
1481 #ifdef GDK_WINDOWING_WIN32
1484 gtk_widget_render_icon (priv->dummy_widget,
1485 priv->image_data.stock_id,
1486 GTK_ICON_SIZE_SMALL_TOOLBAR,
1489 prev_hicon = priv->nid.hIcon;
1490 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1491 priv->nid.uFlags |= NIF_ICON;
1492 if (priv->nid.hWnd != NULL && priv->visible)
1493 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1494 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1496 DestroyIcon (prev_hicon);
1497 g_object_unref (pixbuf);
1500 #ifdef GDK_WINDOWING_QUARTZ
1504 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1505 priv->image_data.stock_id,
1506 GTK_ICON_SIZE_SMALL_TOOLBAR,
1509 [priv->status_item setImage:pixbuf];
1510 QUARTZ_POOL_RELEASE;
1511 g_object_unref (pixbuf);
1517 case GTK_IMAGE_ICON_NAME:
1519 #ifdef GDK_WINDOWING_X11
1520 GtkIconSize size = find_icon_size (priv->image, priv->size);
1521 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1522 priv->image_data.icon_name,
1525 #ifdef GDK_WINDOWING_WIN32
1528 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1529 priv->image_data.icon_name,
1533 prev_hicon = priv->nid.hIcon;
1534 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1535 priv->nid.uFlags |= NIF_ICON;
1536 if (priv->nid.hWnd != NULL && priv->visible)
1537 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1538 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1540 DestroyIcon (prev_hicon);
1541 g_object_unref (pixbuf);
1544 #ifdef GDK_WINDOWING_QUARTZ
1548 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1549 priv->image_data.icon_name,
1554 [priv->status_item setImage:pixbuf];
1555 QUARTZ_POOL_RELEASE;
1556 g_object_unref (pixbuf);
1563 case GTK_IMAGE_GICON:
1565 #ifdef GDK_WINDOWING_X11
1566 GtkIconSize size = find_icon_size (priv->image, priv->size);
1567 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1568 priv->image_data.gicon,
1571 #ifdef GDK_WINDOWING_WIN32
1574 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1575 priv->image_data.gicon,
1578 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1580 prev_hicon = priv->nid.hIcon;
1581 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1582 priv->nid.uFlags |= NIF_ICON;
1583 if (priv->nid.hWnd != NULL && priv->visible)
1584 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1585 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1587 DestroyIcon (prev_hicon);
1588 g_object_unref (pixbuf);
1591 #ifdef GDK_WINDOWING_QUARTZ
1594 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1595 priv->image_data.gicon,
1598 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1601 [priv->status_item setImage:pixbuf];
1602 QUARTZ_POOL_RELEASE;
1603 g_object_unref (pixbuf);
1610 case GTK_IMAGE_EMPTY:
1611 #ifdef GDK_WINDOWING_X11
1612 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1614 #ifdef GDK_WINDOWING_WIN32
1615 priv->nid.uFlags &= ~NIF_ICON;
1616 if (priv->nid.hWnd != NULL && priv->visible)
1617 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1618 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1620 #ifdef GDK_WINDOWING_QUARTZ
1623 [priv->status_item setImage:NULL];
1624 QUARTZ_POOL_RELEASE;
1629 g_assert_not_reached ();
1634 #ifdef GDK_WINDOWING_X11
1637 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1638 GtkAllocation *allocation)
1640 GtkStatusIconPrivate *priv = status_icon->priv;
1641 GtkOrientation orientation;
1644 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1646 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1647 size = allocation->height;
1649 size = allocation->width;
1651 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1652 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1654 if (priv->size != size)
1658 g_object_notify (G_OBJECT (status_icon), "size");
1660 if (!emit_size_changed_signal (status_icon, size))
1661 gtk_status_icon_update_image (status_icon);
1666 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1667 GdkScreen *old_screen)
1669 GtkStatusIconPrivate *priv = status_icon->priv;
1671 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1673 g_object_notify (G_OBJECT (status_icon), "screen");
1679 #ifdef GDK_WINDOWING_X11
1682 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1684 g_object_notify (G_OBJECT (status_icon), "embedded");
1688 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1690 g_object_notify (G_OBJECT (status_icon), "orientation");
1694 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1697 guint state, keyval;
1699 state = event->state & gtk_accelerator_get_default_mod_mask ();
1700 keyval = event->keyval;
1702 (keyval == GDK_Return ||
1703 keyval == GDK_KP_Enter ||
1704 keyval == GDK_ISO_Enter ||
1705 keyval == GDK_space ||
1706 keyval == GDK_KP_Space))
1708 emit_activate_signal (status_icon);
1716 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1718 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1724 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1725 GdkEventButton *event)
1727 gboolean handled = FALSE;
1729 g_signal_emit (status_icon,
1730 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1735 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1737 emit_activate_signal (status_icon);
1740 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1742 emit_popup_menu_signal (status_icon, event->button, event->time);
1750 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1751 GdkEventButton *event)
1753 gboolean handled = FALSE;
1754 g_signal_emit (status_icon,
1755 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1760 #ifdef GDK_WINDOWING_X11
1762 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1763 GdkEventScroll *event)
1765 gboolean handled = FALSE;
1766 g_signal_emit (status_icon,
1767 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1773 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1776 gboolean keyboard_tip,
1777 GtkTooltip *tooltip)
1779 gboolean handled = FALSE;
1780 g_signal_emit (status_icon,
1781 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1782 x, y, keyboard_tip, tooltip, &handled);
1785 #endif /* GDK_WINDOWING_X11 */
1788 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1790 GtkStatusIconPrivate *priv = status_icon->priv;
1792 switch (priv->storage_type)
1794 case GTK_IMAGE_PIXBUF:
1795 if (priv->image_data.pixbuf)
1796 g_object_unref (priv->image_data.pixbuf);
1797 priv->image_data.pixbuf = NULL;
1798 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1801 case GTK_IMAGE_STOCK:
1802 g_free (priv->image_data.stock_id);
1803 priv->image_data.stock_id = NULL;
1805 g_object_notify (G_OBJECT (status_icon), "stock");
1808 case GTK_IMAGE_ICON_NAME:
1809 g_free (priv->image_data.icon_name);
1810 priv->image_data.icon_name = NULL;
1812 g_object_notify (G_OBJECT (status_icon), "icon-name");
1815 case GTK_IMAGE_GICON:
1816 if (priv->image_data.gicon)
1817 g_object_unref (priv->image_data.gicon);
1818 priv->image_data.gicon = NULL;
1820 g_object_notify (G_OBJECT (status_icon), "gicon");
1823 case GTK_IMAGE_EMPTY:
1826 g_assert_not_reached ();
1830 priv->storage_type = GTK_IMAGE_EMPTY;
1831 g_object_notify (G_OBJECT (status_icon), "storage-type");
1835 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1836 GtkImageType storage_type,
1839 GtkStatusIconPrivate *priv = status_icon->priv;
1841 g_object_freeze_notify (G_OBJECT (status_icon));
1843 gtk_status_icon_reset_image_data (status_icon);
1845 priv->storage_type = storage_type;
1846 g_object_notify (G_OBJECT (status_icon), "storage-type");
1848 switch (storage_type)
1850 case GTK_IMAGE_PIXBUF:
1851 priv->image_data.pixbuf = (GdkPixbuf *)data;
1852 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1854 case GTK_IMAGE_STOCK:
1855 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1856 g_object_notify (G_OBJECT (status_icon), "stock");
1858 case GTK_IMAGE_ICON_NAME:
1859 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1860 g_object_notify (G_OBJECT (status_icon), "icon-name");
1862 case GTK_IMAGE_GICON:
1863 priv->image_data.gicon = (GIcon *)data;
1864 g_object_notify (G_OBJECT (status_icon), "gicon");
1867 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1870 g_object_thaw_notify (G_OBJECT (status_icon));
1872 gtk_status_icon_update_image (status_icon);
1876 * gtk_status_icon_set_from_pixbuf:
1877 * @status_icon: a #GtkStatusIcon
1878 * @pixbuf: a #GdkPixbuf or %NULL
1880 * Makes @status_icon display @pixbuf.
1881 * See gtk_status_icon_new_from_pixbuf() for details.
1886 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1889 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1890 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1893 g_object_ref (pixbuf);
1895 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1900 * gtk_status_icon_set_from_file:
1901 * @status_icon: a #GtkStatusIcon
1902 * @filename: a filename
1904 * Makes @status_icon display the file @filename.
1905 * See gtk_status_icon_new_from_file() for details.
1910 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1911 const gchar *filename)
1915 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1916 g_return_if_fail (filename != NULL);
1918 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1920 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1923 g_object_unref (pixbuf);
1927 * gtk_status_icon_set_from_stock:
1928 * @status_icon: a #GtkStatusIcon
1929 * @stock_id: a stock icon id
1931 * Makes @status_icon display the stock icon with the id @stock_id.
1932 * See gtk_status_icon_new_from_stock() for details.
1937 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1938 const gchar *stock_id)
1940 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1941 g_return_if_fail (stock_id != NULL);
1943 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1944 (gpointer) stock_id);
1948 * gtk_status_icon_set_from_icon_name:
1949 * @status_icon: a #GtkStatusIcon
1950 * @icon_name: an icon name
1952 * Makes @status_icon display the icon named @icon_name from the
1953 * current icon theme.
1954 * See gtk_status_icon_new_from_icon_name() for details.
1959 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1960 const gchar *icon_name)
1962 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1963 g_return_if_fail (icon_name != NULL);
1965 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1966 (gpointer) icon_name);
1970 * gtk_status_icon_set_from_gicon:
1971 * @status_icon: a #GtkStatusIcon
1974 * Makes @status_icon display the #GIcon.
1975 * See gtk_status_icon_new_from_gicon() for details.
1980 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1983 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1984 g_return_if_fail (icon != NULL);
1987 g_object_ref (icon);
1989 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1994 * gtk_status_icon_get_storage_type:
1995 * @status_icon: a #GtkStatusIcon
1997 * Gets the type of representation being used by the #GtkStatusIcon
1998 * to store image data. If the #GtkStatusIcon has no image data,
1999 * the return value will be %GTK_IMAGE_EMPTY.
2001 * Return value: the image representation being used
2006 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2008 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2010 return status_icon->priv->storage_type;
2013 * gtk_status_icon_get_pixbuf:
2014 * @status_icon: a #GtkStatusIcon
2016 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2017 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2018 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2019 * The caller of this function does not own a reference to the
2022 * Return value: the displayed pixbuf, or %NULL if the image is empty.
2027 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2029 GtkStatusIconPrivate *priv;
2031 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2033 priv = status_icon->priv;
2035 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2036 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2038 if (priv->storage_type == GTK_IMAGE_EMPTY)
2039 priv->image_data.pixbuf = NULL;
2041 return priv->image_data.pixbuf;
2045 * gtk_status_icon_get_stock:
2046 * @status_icon: a #GtkStatusIcon
2048 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2049 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2050 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2051 * The returned string is owned by the #GtkStatusIcon and should not
2052 * be freed or modified.
2054 * Return value: stock id of the displayed stock icon,
2055 * or %NULL if the image is empty.
2059 G_CONST_RETURN gchar *
2060 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2062 GtkStatusIconPrivate *priv;
2064 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2066 priv = status_icon->priv;
2068 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2069 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2071 if (priv->storage_type == GTK_IMAGE_EMPTY)
2072 priv->image_data.stock_id = NULL;
2074 return priv->image_data.stock_id;
2078 * gtk_status_icon_get_icon_name:
2079 * @status_icon: a #GtkStatusIcon
2081 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2082 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2083 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2084 * The returned string is owned by the #GtkStatusIcon and should not
2085 * be freed or modified.
2087 * Return value: name of the displayed icon, or %NULL if the image is empty.
2091 G_CONST_RETURN gchar *
2092 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2094 GtkStatusIconPrivate *priv;
2096 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2098 priv = status_icon->priv;
2100 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2101 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2103 if (priv->storage_type == GTK_IMAGE_EMPTY)
2104 priv->image_data.icon_name = NULL;
2106 return priv->image_data.icon_name;
2110 * gtk_status_icon_get_gicon:
2111 * @status_icon: a #GtkStatusIcon
2113 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2114 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2115 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2116 * The caller of this function does not own a reference to the
2119 * If this function fails, @icon is left unchanged;
2121 * Returns: the displayed icon, or %NULL if the image is empty
2126 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2128 GtkStatusIconPrivate *priv;
2130 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2132 priv = status_icon->priv;
2134 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2135 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2137 if (priv->storage_type == GTK_IMAGE_EMPTY)
2138 priv->image_data.gicon = NULL;
2140 return priv->image_data.gicon;
2144 * gtk_status_icon_get_size:
2145 * @status_icon: a #GtkStatusIcon
2147 * Gets the size in pixels that is available for the image.
2148 * Stock icons and named icons adapt their size automatically
2149 * if the size of the notification area changes. For other
2150 * storage types, the size-changed signal can be used to
2151 * react to size changes.
2153 * Note that the returned size is only meaningful while the
2154 * status icon is embedded (see gtk_status_icon_is_embedded()).
2156 * Return value: the size that is available for the image
2161 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2163 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2165 return status_icon->priv->size;
2169 * gtk_status_icon_set_screen:
2170 * @status_icon: a #GtkStatusIcon
2171 * @screen: a #GdkScreen
2173 * Sets the #GdkScreen where @status_icon is displayed; if
2174 * the icon is already mapped, it will be unmapped, and
2175 * then remapped on the new screen.
2180 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2183 g_return_if_fail (GDK_IS_SCREEN (screen));
2185 #ifdef GDK_WINDOWING_X11
2186 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2191 * gtk_status_icon_get_screen:
2192 * @status_icon: a #GtkStatusIcon
2194 * Returns the #GdkScreen associated with @status_icon.
2196 * Return value: a #GdkScreen.
2201 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2203 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2205 #ifdef GDK_WINDOWING_X11
2206 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2208 return gdk_screen_get_default ();
2213 * gtk_status_icon_set_tooltip:
2214 * @status_icon: a #GtkStatusIcon
2215 * @tooltip_text: the tooltip text, or %NULL
2217 * Sets the tooltip of the status icon.
2221 * Deprecated: 2.16: Use gtk_status_icon_set_tooltip_text() instead.
2224 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
2225 const gchar *tooltip_text)
2227 gtk_status_icon_set_tooltip_text (status_icon, tooltip_text);
2231 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
2233 GtkStatusIconPrivate *priv = status_icon->priv;
2235 priv->blink_off = !priv->blink_off;
2237 gtk_status_icon_update_image (status_icon);
2243 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
2245 GtkStatusIconPrivate *priv = status_icon->priv;
2247 if (!priv->blinking_timeout)
2249 gtk_status_icon_blinker (status_icon);
2251 priv->blinking_timeout =
2252 gdk_threads_add_timeout (BLINK_TIMEOUT,
2253 (GSourceFunc) gtk_status_icon_blinker,
2259 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
2261 GtkStatusIconPrivate *priv = status_icon->priv;
2263 if (priv->blinking_timeout)
2265 g_source_remove (priv->blinking_timeout);
2266 priv->blinking_timeout = 0;
2267 priv->blink_off = FALSE;
2269 gtk_status_icon_update_image (status_icon);
2274 * gtk_status_icon_set_visible:
2275 * @status_icon: a #GtkStatusIcon
2276 * @visible: %TRUE to show the status icon, %FALSE to hide it
2278 * Shows or hides a status icon.
2283 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2286 GtkStatusIconPrivate *priv;
2288 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2290 priv = status_icon->priv;
2292 visible = visible != FALSE;
2294 if (priv->visible != visible)
2296 priv->visible = visible;
2298 #ifdef GDK_WINDOWING_X11
2300 gtk_widget_show (priv->tray_icon);
2301 else if (GTK_WIDGET_REALIZED (priv->tray_icon))
2303 gtk_widget_hide (priv->tray_icon);
2304 gtk_widget_unrealize (priv->tray_icon);
2307 #ifdef GDK_WINDOWING_WIN32
2308 if (priv->nid.hWnd != NULL)
2311 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2313 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2316 #ifdef GDK_WINDOWING_QUARTZ
2318 [priv->status_item setVisible:visible];
2319 QUARTZ_POOL_RELEASE;
2321 g_object_notify (G_OBJECT (status_icon), "visible");
2326 * gtk_status_icon_get_visible:
2327 * @status_icon: a #GtkStatusIcon
2329 * Returns whether the status icon is visible or not.
2330 * Note that being visible does not guarantee that
2331 * the user can actually see the icon, see also
2332 * gtk_status_icon_is_embedded().
2334 * Return value: %TRUE if the status icon is visible
2339 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2341 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2343 return status_icon->priv->visible;
2347 * gtk_status_icon_set_blinking:
2348 * @status_icon: a #GtkStatusIcon
2349 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
2351 * Makes the status icon start or stop blinking.
2352 * Note that blinking user interface elements may be problematic
2353 * for some users, and thus may be turned off, in which case
2354 * this setting has no effect.
2359 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
2362 GtkStatusIconPrivate *priv;
2364 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2366 priv = status_icon->priv;
2368 blinking = blinking != FALSE;
2370 if (priv->blinking != blinking)
2372 priv->blinking = blinking;
2375 gtk_status_icon_enable_blinking (status_icon);
2377 gtk_status_icon_disable_blinking (status_icon);
2379 g_object_notify (G_OBJECT (status_icon), "blinking");
2384 * gtk_status_icon_get_blinking:
2385 * @status_icon: a #GtkStatusIcon
2387 * Returns whether the icon is blinking, see
2388 * gtk_status_icon_set_blinking().
2390 * Return value: %TRUE if the icon is blinking
2395 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
2397 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2399 return status_icon->priv->blinking;
2403 * gtk_status_icon_is_embedded:
2404 * @status_icon: a #GtkStatusIcon
2406 * Returns whether the status icon is embedded in a notification
2409 * Return value: %TRUE if the status icon is embedded in
2410 * a notification area.
2415 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2417 #ifdef GDK_WINDOWING_X11
2421 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2423 #ifdef GDK_WINDOWING_X11
2424 plug = GTK_PLUG (status_icon->priv->tray_icon);
2426 if (plug->socket_window)
2431 #ifdef GDK_WINDOWING_WIN32
2434 #ifdef GDK_WINDOWING_QUARTZ
2440 * gtk_status_icon_position_menu:
2441 * @menu: the #GtkMenu
2442 * @x: return location for the x position
2443 * @y: return location for the y position
2444 * @push_in: whether the first menu item should be offset (pushed in) to be
2445 * aligned with the menu popup position (only useful for GtkOptionMenu).
2446 * @user_data: the status icon to position the menu on
2448 * Menu positioning function to use with gtk_menu_popup()
2449 * to position @menu aligned to the status icon @user_data.
2454 gtk_status_icon_position_menu (GtkMenu *menu,
2460 #ifdef GDK_WINDOWING_X11
2461 GtkStatusIcon *status_icon;
2462 GtkStatusIconPrivate *priv;
2463 GtkTrayIcon *tray_icon;
2466 GtkTextDirection direction;
2467 GtkRequisition menu_req;
2468 GdkRectangle monitor;
2469 gint monitor_num, height, width, xoffset, yoffset;
2471 g_return_if_fail (GTK_IS_MENU (menu));
2472 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2474 status_icon = GTK_STATUS_ICON (user_data);
2475 priv = status_icon->priv;
2476 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2477 widget = priv->tray_icon;
2479 direction = gtk_widget_get_direction (widget);
2481 screen = gtk_widget_get_screen (widget);
2482 gtk_menu_set_screen (menu, screen);
2484 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
2485 if (monitor_num < 0)
2487 gtk_menu_set_monitor (menu, monitor_num);
2489 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2491 gdk_window_get_origin (widget->window, x, y);
2493 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2495 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2498 height = widget->allocation.height;
2499 xoffset = widget->allocation.width;
2504 width = widget->allocation.width;
2507 yoffset = widget->allocation.height;
2510 if (direction == GTK_TEXT_DIR_RTL)
2512 if ((*x - (menu_req.width - width)) >= monitor.x)
2513 *x -= menu_req.width - width;
2514 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2516 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2517 *x -= menu_req.width - width;
2523 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2525 else if ((*x - (menu_req.width - width)) >= monitor.x)
2526 *x -= menu_req.width - width;
2527 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2530 *x -= menu_req.width - width;
2533 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2535 else if ((*y - (menu_req.height - height)) >= monitor.y)
2536 *y -= menu_req.height - height;
2537 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2540 *y -= menu_req.height - height;
2543 #endif /* GDK_WINDOWING_X11 */
2545 #ifdef GDK_WINDOWING_WIN32
2546 GtkStatusIcon *status_icon;
2547 GtkStatusIconPrivate *priv;
2549 g_return_if_fail (GTK_IS_MENU (menu));
2550 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2552 status_icon = GTK_STATUS_ICON (user_data);
2553 priv = status_icon->priv;
2555 *x = priv->last_click_x;
2556 *y = priv->last_click_y;
2562 * gtk_status_icon_get_geometry:
2563 * @status_icon: a #GtkStatusIcon
2564 * @screen: return location for the screen, or %NULL if the
2565 * information is not needed
2566 * @area: return location for the area occupied by the status
2568 * @orientation: return location for the orientation of the panel
2569 * in which the status icon is embedded, or %NULL. A panel
2570 * at the top or bottom of the screen is horizontal, a panel
2571 * at the left or right is vertical.
2573 * Obtains information about the location of the status icon
2574 * on screen. This information can be used to e.g. position
2575 * popups like notification bubbles.
2577 * See gtk_status_icon_position_menu() for a more convenient
2578 * alternative for positioning menus.
2580 * Note that some platforms do not allow GTK+ to provide
2581 * this information, and even on platforms that do allow it,
2582 * the information is not reliable unless the status icon
2583 * is embedded in a notification area, see
2584 * gtk_status_icon_is_embedded().
2586 * Return value: %TRUE if the location information has
2592 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2595 GtkOrientation *orientation)
2597 #ifdef GDK_WINDOWING_X11
2599 GtkStatusIconPrivate *priv;
2602 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2604 priv = status_icon->priv;
2605 widget = priv->tray_icon;
2608 *screen = gtk_widget_get_screen (widget);
2612 gdk_window_get_origin (widget->window, &x, &y);
2615 area->width = widget->allocation.width;
2616 area->height = widget->allocation.height;
2620 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2625 #endif /* GDK_WINDOWING_X11 */
2629 * gtk_status_icon_set_has_tooltip:
2630 * @status_icon: a #GtkStatusIcon
2631 * @has_tooltip: whether or not @status_icon has a tooltip
2633 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2634 * See #GtkStatusIcon:has-tooltip for more information.
2639 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2640 gboolean has_tooltip)
2642 GtkStatusIconPrivate *priv;
2644 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2646 priv = status_icon->priv;
2648 #ifdef GDK_WINDOWING_X11
2649 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2651 #ifdef GDK_WINDOWING_WIN32
2652 if (!has_tooltip && priv->tooltip_text)
2653 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2655 #ifdef GDK_WINDOWING_QUARTZ
2656 if (!has_tooltip && priv->tooltip_text)
2657 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2662 * gtk_status_icon_get_has_tooltip:
2663 * @status_icon: a #GtkStatusIcon
2665 * Returns the current value of the has-tooltip property.
2666 * See #GtkStatusIcon:has-tooltip for more information.
2668 * Return value: current value of has-tooltip on @status_icon.
2673 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2675 GtkStatusIconPrivate *priv;
2676 gboolean has_tooltip = FALSE;
2678 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2680 priv = status_icon->priv;
2682 #ifdef GDK_WINDOWING_X11
2683 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2685 #ifdef GDK_WINDOWING_WIN32
2686 has_tooltip = (priv->tooltip_text != NULL);
2688 #ifdef GDK_WINDOWING_QUARTZ
2689 has_tooltip = (priv->tooltip_text != NULL);
2696 * gtk_status_icon_set_tooltip_text:
2697 * @status_icon: a #GtkStatusIcon
2698 * @text: the contents of the tooltip for @status_icon
2700 * Sets @text as the contents of the tooltip.
2702 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2703 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2706 * See also the #GtkStatusIcon:tooltip-text property and
2707 * gtk_tooltip_set_text().
2712 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2715 GtkStatusIconPrivate *priv;
2717 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2719 priv = status_icon->priv;
2721 #ifdef GDK_WINDOWING_X11
2723 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2726 #ifdef GDK_WINDOWING_WIN32
2728 priv->nid.uFlags &= ~NIF_TIP;
2731 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2733 priv->nid.uFlags |= NIF_TIP;
2734 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2735 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2738 if (priv->nid.hWnd != NULL && priv->visible)
2739 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2740 g_warning ("%s:%d:Shell_NotifyIconW(NIM_MODIFY) failed", __FILE__, __LINE__-1);
2742 g_free (priv->tooltip_text);
2743 priv->tooltip_text = g_strdup (text);
2745 #ifdef GDK_WINDOWING_QUARTZ
2747 [priv->status_item setToolTip:text];
2748 QUARTZ_POOL_RELEASE;
2750 g_free (priv->tooltip_text);
2751 priv->tooltip_text = g_strdup (text);
2756 * gtk_status_icon_get_tooltip_text:
2757 * @status_icon: a #GtkStatusIcon
2759 * Gets the contents of the tooltip for @status_icon.
2761 * Return value: the tooltip text, or %NULL. You should free the
2762 * returned string with g_free() when done.
2767 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2769 GtkStatusIconPrivate *priv;
2770 gchar *tooltip_text = NULL;
2772 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2774 priv = status_icon->priv;
2776 #ifdef GDK_WINDOWING_X11
2777 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2779 #ifdef GDK_WINDOWING_WIN32
2780 if (priv->tooltip_text)
2781 tooltip_text = g_strdup (priv->tooltip_text);
2783 #ifdef GDK_WINDOWING_QUARTZ
2784 if (priv->tooltip_text)
2785 tooltip_text = g_strdup (priv->tooltip_text);
2788 return tooltip_text;
2792 * gtk_status_icon_set_tooltip_markup:
2793 * @status_icon: a #GtkStatusIcon
2794 * @markup: the contents of the tooltip for @status_icon, or %NULL
2796 * Sets @markup as the contents of the tooltip, which is marked up with
2797 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2799 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2800 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2802 * See also the #GtkStatusIcon:tooltip-markup property and
2803 * gtk_tooltip_set_markup().
2808 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2809 const gchar *markup)
2811 GtkStatusIconPrivate *priv;
2812 #ifndef GDK_WINDOWING_X11
2816 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2818 priv = status_icon->priv;
2820 #ifdef GDK_WINDOWING_X11
2821 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2823 #ifdef GDK_WINDOWING_WIN32
2825 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2826 gtk_status_icon_set_tooltip_text (status_icon, text);
2829 #ifdef GDK_WINDOWING_QUARTZ
2831 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2832 gtk_status_icon_set_tooltip_text (status_icon, text);
2838 * gtk_status_icon_get_tooltip_markup:
2839 * @status_icon: a #GtkStatusIcon
2841 * Gets the contents of the tooltip for @status_icon.
2843 * Return value: the tooltip text, or %NULL. You should free the
2844 * returned string with g_free() when done.
2849 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2851 GtkStatusIconPrivate *priv;
2852 gchar *markup = NULL;
2854 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2856 priv = status_icon->priv;
2858 #ifdef GDK_WINDOWING_X11
2859 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2861 #ifdef GDK_WINDOWING_WIN32
2862 if (priv->tooltip_text)
2863 markup = g_markup_escape_text (priv->tooltip_text, -1);
2865 #ifdef GDK_WINDOWING_QUARTZ
2866 if (priv->tooltip_text)
2867 markup = g_markup_escape_text (priv->tooltip_text, -1);
2874 * gtk_status_icon_get_x11_window_id:
2875 * @status_icon: a #GtkStatusIcon
2877 * This function is only useful on the X11/freedesktop.org platform.
2878 * It returns a window ID for the widget in the underlying
2879 * status icon implementation. This is useful for the Galago
2880 * notification service, which can send a window ID in the protocol
2881 * in order for the server to position notification windows
2882 * pointing to a status icon reliably.
2884 * This function is not intended for other use cases which are
2885 * more likely to be met by one of the non-X11 specific methods, such
2886 * as gtk_status_icon_position_menu().
2888 * Return value: An 32 bit unsigned integer identifier for the
2889 * underlying X11 Window
2894 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2896 #ifdef GDK_WINDOWING_X11
2897 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2898 return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
2905 * gtk_status_icon_set_title:
2906 * @status_icon: a #GtkStatusIcon
2909 * Sets the title of this tray icon.
2910 * This should be a short, human-readable, localized string
2911 * describing the tray icon. It may be used by tools like screen
2912 * readers to render the tray icon.
2917 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2920 GtkStatusIconPrivate *priv;
2922 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2924 priv = status_icon->priv;
2926 #ifdef GDK_WINDOWING_X11
2927 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2929 #ifdef GDK_WINDOWING_QUARTZ
2930 g_free (priv->title);
2931 priv->title = g_strdup (title);
2933 #ifdef GDK_WINDOWING_WIN32
2934 g_free (priv->title);
2935 priv->title = g_strdup (title);
2938 g_object_notify (G_OBJECT (status_icon), "title");
2942 * gtk_status_icon_get_title:
2943 * @status_icon: a #GtkStatusIcon
2945 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2947 * Returns: the title of the status icon
2951 G_CONST_RETURN gchar *
2952 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2954 GtkStatusIconPrivate *priv;
2956 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2958 priv = status_icon->priv;
2960 #ifdef GDK_WINDOWING_X11
2961 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2963 #ifdef GDK_WINDOWING_QUARTZ
2966 #ifdef GDK_WINDOWING_WIN32
2972 #define __GTK_STATUS_ICON_C__
2973 #include "gtkaliasdef.c"