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"
64 #define BLINK_TIMEOUT 500
92 BUTTON_PRESS_EVENT_SIGNAL,
93 BUTTON_RELEASE_EVENT_SIGNAL,
99 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
101 #ifdef GDK_WINDOWING_QUARTZ
102 #include "gtkstatusicon-quartz.c"
105 struct _GtkStatusIconPrivate
107 #ifdef GDK_WINDOWING_X11
108 GtkWidget *tray_icon;
112 #ifdef GDK_WINDOWING_WIN32
113 GtkWidget *dummy_widget;
115 gint last_click_x, last_click_y;
116 GtkOrientation orientation;
121 #ifdef GDK_WINDOWING_QUARTZ
122 GtkWidget *dummy_widget;
123 GtkQuartzStatusIcon *status_item;
133 GtkImageType storage_type;
146 static GObject* gtk_status_icon_constructor (GType type,
147 guint n_construct_properties,
148 GObjectConstructParam *construct_params);
149 static void gtk_status_icon_finalize (GObject *object);
150 static void gtk_status_icon_set_property (GObject *object,
154 static void gtk_status_icon_get_property (GObject *object,
159 #ifdef GDK_WINDOWING_X11
160 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
161 GtkAllocation *allocation);
162 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
163 GdkScreen *old_screen);
164 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
165 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
166 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
167 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
168 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
170 GtkStatusIcon *status_icon);
171 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
172 GdkEventScroll *event);
173 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
176 gboolean keyboard_tip,
177 GtkTooltip *tooltip);
179 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
181 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
183 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
184 GdkEventButton *event);
185 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
186 GdkEventButton *event);
187 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
188 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
190 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
193 gtk_status_icon_class_init (GtkStatusIconClass *class)
195 GObjectClass *gobject_class = (GObjectClass *) class;
197 gobject_class->constructor = gtk_status_icon_constructor;
198 gobject_class->finalize = gtk_status_icon_finalize;
199 gobject_class->set_property = gtk_status_icon_set_property;
200 gobject_class->get_property = gtk_status_icon_get_property;
202 class->button_press_event = NULL;
203 class->button_release_event = NULL;
204 class->scroll_event = NULL;
205 class->query_tooltip = NULL;
207 g_object_class_install_property (gobject_class,
209 g_param_spec_object ("pixbuf",
211 P_("A GdkPixbuf to display"),
213 GTK_PARAM_READWRITE));
215 g_object_class_install_property (gobject_class,
217 g_param_spec_string ("file",
219 P_("Filename to load and display"),
221 GTK_PARAM_WRITABLE));
223 g_object_class_install_property (gobject_class,
225 g_param_spec_string ("stock",
227 P_("Stock ID for a stock image to display"),
229 GTK_PARAM_READWRITE));
231 g_object_class_install_property (gobject_class,
233 g_param_spec_string ("icon-name",
235 P_("The name of the icon from the icon theme"),
237 GTK_PARAM_READWRITE));
240 * GtkStatusIcon:gicon:
242 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
243 * the image will be updated automatically if the theme changes.
247 g_object_class_install_property (gobject_class,
249 g_param_spec_object ("gicon",
251 P_("The GIcon being displayed"),
253 GTK_PARAM_READWRITE));
255 g_object_class_install_property (gobject_class,
257 g_param_spec_enum ("storage-type",
259 P_("The representation being used for image data"),
262 GTK_PARAM_READABLE));
264 g_object_class_install_property (gobject_class,
266 g_param_spec_int ("size",
268 P_("The size of the icon"),
272 GTK_PARAM_READABLE));
274 g_object_class_install_property (gobject_class,
276 g_param_spec_object ("screen",
278 P_("The screen where this status icon will be displayed"),
280 GTK_PARAM_READWRITE));
282 g_object_class_install_property (gobject_class,
284 g_param_spec_boolean ("visible",
286 P_("Whether the status icon is visible"),
288 GTK_PARAM_READWRITE));
292 * GtkStatusIcon:embedded:
294 * %TRUE if the statusicon is embedded in a notification area.
298 g_object_class_install_property (gobject_class,
300 g_param_spec_boolean ("embedded",
302 P_("Whether the status icon is embedded"),
304 GTK_PARAM_READABLE));
307 * GtkStatusIcon:orientation:
309 * The orientation of the tray in which the statusicon
314 g_object_class_install_property (gobject_class,
316 g_param_spec_enum ("orientation",
318 P_("The orientation of the tray"),
319 GTK_TYPE_ORIENTATION,
320 GTK_ORIENTATION_HORIZONTAL,
321 GTK_PARAM_READABLE));
324 * GtkStatusIcon:has-tooltip:
326 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
327 * @status_icon. A value of %TRUE indicates that @status_icon can have a
328 * tooltip, in this case the status icon will be queried using
329 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
332 * Note that setting this property to %TRUE for the first time will change
333 * the event masks of the windows of this status icon to include leave-notify
334 * and motion-notify events. This will not be undone when the property is set
337 * Whether this property is respected is platform dependent.
338 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
342 g_object_class_install_property (gobject_class,
344 g_param_spec_boolean ("has-tooltip",
346 P_("Whether this tray icon has a tooltip"),
348 GTK_PARAM_READWRITE));
350 * GtkStatusIcon:tooltip-text:
352 * Sets the text of tooltip to be the given string.
354 * Also see gtk_tooltip_set_text().
356 * This is a convenience property which will take care of getting the
357 * tooltip shown if the given string is not %NULL.
358 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
359 * the default handler for the #GtkStatusIcon::query-tooltip signal
360 * will take care of displaying the tooltip.
362 * Note that some platforms have limitations on the length of tooltips
363 * that they allow on status icons, e.g. Windows only shows the first
368 g_object_class_install_property (gobject_class,
370 g_param_spec_string ("tooltip-text",
372 P_("The contents of the tooltip for this widget"),
374 GTK_PARAM_READWRITE));
376 * GtkStatusIcon:tooltip-markup:
378 * Sets the text of tooltip to be the given string, which is marked up
379 * with the <link linkend="PangoMarkupFormat">Pango text markup
380 * language</link>. Also see gtk_tooltip_set_markup().
382 * This is a convenience property which will take care of getting the
383 * tooltip shown if the given string is not %NULL.
384 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
385 * the default handler for the #GtkStatusIcon::query-tooltip signal
386 * will take care of displaying the tooltip.
388 * On some platforms, embedded markup will be ignored.
392 g_object_class_install_property (gobject_class,
394 g_param_spec_string ("tooltip-markup",
395 P_("Tooltip markup"),
396 P_("The contents of the tooltip for this tray icon"),
398 GTK_PARAM_READWRITE));
402 * GtkStatusIcon:title:
404 * The title of this tray icon. This should be a short, human-readable,
405 * localized string describing the tray icon. It may be used by tools
406 * like screen readers to render the tray icon.
410 g_object_class_install_property (gobject_class,
412 g_param_spec_string ("title",
414 P_("The title of this tray icon"),
416 GTK_PARAM_READWRITE));
419 * GtkStatusIcon::activate:
420 * @status_icon: the object which received the signal
422 * Gets emitted when the user activates the status icon.
423 * If and how status icons can activated is platform-dependent.
425 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
426 * be used by applications and should be wrapped by language bindings.
430 status_icon_signals [ACTIVATE_SIGNAL] =
431 g_signal_new (I_("activate"),
432 G_TYPE_FROM_CLASS (gobject_class),
433 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
434 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
437 g_cclosure_marshal_VOID__VOID,
442 * GtkStatusIcon::popup-menu:
443 * @status_icon: the object which received the signal
444 * @button: the button that was pressed, or 0 if the
445 * signal is not emitted in response to a button press event
446 * @activate_time: the timestamp of the event that
447 * triggered the signal emission
449 * Gets emitted when the user brings up the context menu
450 * of the status icon. Whether status icons can have context
451 * menus and how these are activated is platform-dependent.
453 * The @button and @activate_time parameters should be
454 * passed as the last to arguments to gtk_menu_popup().
456 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
457 * be used by applications and should be wrapped by language bindings.
461 status_icon_signals [POPUP_MENU_SIGNAL] =
462 g_signal_new (I_("popup-menu"),
463 G_TYPE_FROM_CLASS (gobject_class),
464 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
465 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
468 _gtk_marshal_VOID__UINT_UINT,
475 * GtkStatusIcon::size-changed:
476 * @status_icon: the object which received the signal
477 * @size: the new size
479 * Gets emitted when the size available for the image
480 * changes, e.g. because the notification area got resized.
482 * Return value: %TRUE if the icon was updated for the new
483 * size. Otherwise, GTK+ will scale the icon as necessary.
487 status_icon_signals [SIZE_CHANGED_SIGNAL] =
488 g_signal_new (I_("size-changed"),
489 G_TYPE_FROM_CLASS (gobject_class),
491 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
492 g_signal_accumulator_true_handled,
494 _gtk_marshal_BOOLEAN__INT,
500 * GtkStatusIcon::button-press-event:
501 * @status_icon: the object which received the signal
502 * @event: the #GdkEventButton which triggered this signal
504 * The ::button-press-event signal will be emitted when a button
505 * (typically from a mouse) is pressed.
507 * Whether this event is emitted is platform-dependent. Use the ::activate
508 * and ::popup-menu signals in preference.
510 * Return value: %TRUE to stop other handlers from being invoked
511 * for the event. %FALSE to propagate the event further.
515 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
516 g_signal_new (I_("button_press_event"),
517 G_TYPE_FROM_CLASS (gobject_class),
519 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
520 g_signal_accumulator_true_handled, NULL,
521 _gtk_marshal_BOOLEAN__BOXED,
523 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
526 * GtkStatusIcon::button-release-event:
527 * @status_icon: the object which received the signal
528 * @event: the #GdkEventButton which triggered this signal
530 * The ::button-release-event signal will be emitted when a button
531 * (typically from a mouse) is released.
533 * Whether this event is emitted is platform-dependent. Use the ::activate
534 * and ::popup-menu signals in preference.
536 * Return value: %TRUE to stop other handlers from being invoked
537 * for the event. %FALSE to propagate the event further.
541 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
542 g_signal_new (I_("button_release_event"),
543 G_TYPE_FROM_CLASS (gobject_class),
545 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
546 g_signal_accumulator_true_handled, NULL,
547 _gtk_marshal_BOOLEAN__BOXED,
549 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
552 * GtkStatusIcon::scroll-event:
553 * @status_icon: the object which received the signal.
554 * @event: the #GdkEventScroll which triggered this signal
556 * The ::scroll-event signal is emitted when a button in the 4 to 7
557 * range is pressed. Wheel mice are usually configured to generate
558 * button press events for buttons 4 and 5 when the wheel is turned.
560 * Whether this event is emitted is platform-dependent.
562 * Returns: %TRUE to stop other handlers from being invoked for the event.
563 * %FALSE to propagate the event further.
567 status_icon_signals[SCROLL_EVENT_SIGNAL] =
568 g_signal_new (I_("scroll_event"),
569 G_TYPE_FROM_CLASS (gobject_class),
571 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
572 g_signal_accumulator_true_handled, NULL,
573 _gtk_marshal_BOOLEAN__BOXED,
575 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
578 * GtkStatusIcon::query-tooltip:
579 * @status_icon: the object which received the signal
580 * @x: the x coordinate of the cursor position where the request has been
581 * emitted, relative to @status_icon
582 * @y: the y coordinate of the cursor position where the request has been
583 * emitted, relative to @status_icon
584 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
585 * @tooltip: a #GtkTooltip
587 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
588 * cursor hovering above @status_icon; or emitted when @status_icon got
589 * focus in keyboard mode.
591 * Using the given coordinates, the signal handler should determine
592 * whether a tooltip should be shown for @status_icon. If this is
593 * the case %TRUE should be returned, %FALSE otherwise. Note that if
594 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
595 * should not be used.
597 * The signal handler is free to manipulate @tooltip with the therefore
598 * destined function calls.
600 * Whether this signal is emitted is platform-dependent.
601 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
603 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
607 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
608 g_signal_new (I_("query_tooltip"),
609 G_TYPE_FROM_CLASS (gobject_class),
611 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
612 g_signal_accumulator_true_handled, NULL,
613 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
620 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
623 #ifdef GDK_WINDOWING_WIN32
626 build_button_event (GtkStatusIconPrivate *priv,
631 GdkRectangle monitor0;
633 /* We know that gdk/win32 puts the primary monitor at index 0 */
634 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
635 e->window = g_object_ref (gdk_get_default_root_window ());
636 e->send_event = TRUE;
637 e->time = GetTickCount ();
639 priv->last_click_x = e->x = pos.x + monitor0.x;
640 priv->last_click_y = e->y = pos.y + monitor0.y;
644 e->device = gdk_display_get_default ()->core_pointer;
651 GtkStatusIcon *status_icon;
652 GdkEventButton *event;
653 } ButtonCallbackData;
656 button_callback (gpointer data)
658 ButtonCallbackData *bc = (ButtonCallbackData *) data;
660 if (bc->event->type == GDK_BUTTON_PRESS)
661 gtk_status_icon_button_press (bc->status_icon, bc->event);
663 gtk_status_icon_button_release (bc->status_icon, bc->event);
665 gdk_event_free ((GdkEvent *) bc->event);
671 static UINT taskbar_created_msg = 0;
672 static GSList *status_icons = NULL;
674 static LRESULT CALLBACK
680 if (message == taskbar_created_msg)
684 for (rover = status_icons; rover != NULL; rover = rover->next)
686 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
687 GtkStatusIconPrivate *priv = status_icon->priv;
689 priv->nid.hWnd = hwnd;
690 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
691 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
692 priv->nid.uFlags = NIF_MESSAGE;
694 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
696 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
697 priv->nid.hWnd = NULL;
701 gtk_status_icon_update_image (status_icon);
706 if (message == WM_GTK_TRAY_NOTIFICATION)
708 ButtonCallbackData *bc;
726 if (HIWORD (wparam) == XBUTTON1)
732 bc = g_new (ButtonCallbackData, 1);
733 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
734 bc->status_icon = GTK_STATUS_ICON (wparam);
735 build_button_event (bc->status_icon->priv, bc->event, button);
736 g_idle_add (button_callback, bc);
752 if (HIWORD (wparam) == XBUTTON1)
758 bc = g_new (ButtonCallbackData, 1);
759 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
760 bc->status_icon = GTK_STATUS_ICON (wparam);
761 build_button_event (bc->status_icon->priv, bc->event, button);
762 g_idle_add (button_callback, bc);
772 return DefWindowProc (hwnd, message, wparam, lparam);
777 create_tray_observer (void)
780 static HWND hwnd = NULL;
782 HINSTANCE hmodule = GetModuleHandle (NULL);
787 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
789 memset (&wclass, 0, sizeof(WNDCLASS));
790 wclass.lpszClassName = "gtkstatusicon-observer";
791 wclass.lpfnWndProc = wndproc;
792 wclass.hInstance = hmodule;
794 klass = RegisterClass (&wclass);
798 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
800 0, 0, 1, 1, NULL, NULL,
804 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
814 gtk_status_icon_init (GtkStatusIcon *status_icon)
816 GtkStatusIconPrivate *priv;
818 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
819 GtkStatusIconPrivate);
820 status_icon->priv = priv;
822 priv->storage_type = GTK_IMAGE_EMPTY;
823 priv->visible = TRUE;
825 #ifdef GDK_WINDOWING_X11
827 priv->image_width = 0;
828 priv->image_height = 0;
830 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
832 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
833 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
836 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
837 G_CALLBACK (gtk_status_icon_key_press), status_icon);
838 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
839 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
840 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
841 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
842 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
843 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
844 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
845 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
846 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
847 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
848 g_signal_connect (priv->tray_icon, "notify::error-color",
849 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
850 g_signal_connect (priv->tray_icon, "notify::warning-color",
851 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
852 g_signal_connect (priv->tray_icon, "notify::success-color",
853 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
854 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
855 G_CALLBACK (gtk_status_icon_button_press), status_icon);
856 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
857 G_CALLBACK (gtk_status_icon_button_release), status_icon);
858 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
859 G_CALLBACK (gtk_status_icon_scroll), status_icon);
860 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
861 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
862 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
863 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
864 priv->image = gtk_image_new ();
865 gtk_widget_set_can_focus (priv->image, TRUE);
866 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
867 gtk_widget_show (priv->image);
869 g_signal_connect_swapped (priv->image, "size-allocate",
870 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
874 #ifdef GDK_WINDOWING_WIN32
876 /* Get position and orientation of Windows taskbar. */
880 abd.cbSize = sizeof (abd);
881 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
882 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
883 priv->orientation = GTK_ORIENTATION_VERTICAL;
885 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
888 priv->last_click_x = priv->last_click_y = 0;
890 /* Are the system tray icons always 16 pixels square? */
892 priv->image_width = 16;
893 priv->image_height = 16;
895 priv->dummy_widget = gtk_label_new ("");
897 memset (&priv->nid, 0, sizeof (priv->nid));
899 priv->nid.hWnd = create_tray_observer ();
900 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
901 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
902 priv->nid.uFlags = NIF_MESSAGE;
904 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
906 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
907 priv->nid.hWnd = NULL;
910 status_icons = g_slist_append (status_icons, status_icon);
914 #ifdef GDK_WINDOWING_QUARTZ
915 priv->dummy_widget = gtk_label_new ("");
919 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
921 priv->image_width = priv->image_height = [priv->status_item getHeight];
922 priv->size = priv->image_height;
930 gtk_status_icon_constructor (GType type,
931 guint n_construct_properties,
932 GObjectConstructParam *construct_params)
935 #ifdef GDK_WINDOWING_X11
936 GtkStatusIcon *status_icon;
937 GtkStatusIconPrivate *priv;
940 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
941 n_construct_properties,
944 #ifdef GDK_WINDOWING_X11
945 status_icon = GTK_STATUS_ICON (object);
946 priv = status_icon->priv;
949 gtk_widget_show (priv->tray_icon);
956 gtk_status_icon_finalize (GObject *object)
958 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
959 GtkStatusIconPrivate *priv = status_icon->priv;
961 gtk_status_icon_reset_image_data (status_icon);
963 #ifdef GDK_WINDOWING_X11
964 g_signal_handlers_disconnect_by_func (priv->tray_icon,
965 gtk_status_icon_key_press, status_icon);
966 g_signal_handlers_disconnect_by_func (priv->tray_icon,
967 gtk_status_icon_popup_menu, status_icon);
968 g_signal_handlers_disconnect_by_func (priv->tray_icon,
969 gtk_status_icon_embedded_changed, status_icon);
970 g_signal_handlers_disconnect_by_func (priv->tray_icon,
971 gtk_status_icon_orientation_changed, status_icon);
972 g_signal_handlers_disconnect_by_func (priv->tray_icon,
973 gtk_status_icon_padding_changed, status_icon);
974 g_signal_handlers_disconnect_by_func (priv->tray_icon,
975 gtk_status_icon_fg_changed, status_icon);
976 g_signal_handlers_disconnect_by_func (priv->tray_icon,
977 gtk_status_icon_color_changed, status_icon);
978 g_signal_handlers_disconnect_by_func (priv->tray_icon,
979 gtk_status_icon_button_press, status_icon);
980 g_signal_handlers_disconnect_by_func (priv->tray_icon,
981 gtk_status_icon_button_release, status_icon);
982 g_signal_handlers_disconnect_by_func (priv->tray_icon,
983 gtk_status_icon_scroll, status_icon);
984 g_signal_handlers_disconnect_by_func (priv->tray_icon,
985 gtk_status_icon_query_tooltip, status_icon);
986 g_signal_handlers_disconnect_by_func (priv->tray_icon,
987 gtk_status_icon_screen_changed, status_icon);
988 gtk_widget_destroy (priv->image);
989 gtk_widget_destroy (priv->tray_icon);
992 #ifdef GDK_WINDOWING_WIN32
993 if (priv->nid.hWnd != NULL && priv->visible)
994 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
996 DestroyIcon (priv->nid.hIcon);
997 g_free (priv->tooltip_text);
999 gtk_widget_destroy (priv->dummy_widget);
1001 status_icons = g_slist_remove (status_icons, status_icon);
1004 #ifdef GDK_WINDOWING_QUARTZ
1006 [priv->status_item release];
1007 QUARTZ_POOL_RELEASE;
1008 g_free (priv->tooltip_text);
1011 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1015 gtk_status_icon_set_property (GObject *object,
1017 const GValue *value,
1020 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1025 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1028 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1031 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1033 case PROP_ICON_NAME:
1034 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1037 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1040 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1043 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1045 case PROP_HAS_TOOLTIP:
1046 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1048 case PROP_TOOLTIP_TEXT:
1049 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1051 case PROP_TOOLTIP_MARKUP:
1052 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1055 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1058 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1064 gtk_status_icon_get_property (GObject *object,
1069 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1070 GtkStatusIconPrivate *priv = status_icon->priv;
1072 /* The "getter" functions whine if you try to get the wrong
1073 * storage type. This function is instead robust against that,
1074 * so that GUI builders don't have to jump through hoops
1075 * to avoid g_warning
1081 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1082 g_value_set_object (value, NULL);
1084 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1087 if (priv->storage_type != GTK_IMAGE_STOCK)
1088 g_value_set_string (value, NULL);
1090 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1092 case PROP_ICON_NAME:
1093 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1094 g_value_set_string (value, NULL);
1096 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1099 if (priv->storage_type != GTK_IMAGE_GICON)
1100 g_value_set_object (value, NULL);
1102 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1104 case PROP_STORAGE_TYPE:
1105 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1108 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1111 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1114 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1117 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1119 case PROP_ORIENTATION:
1120 #ifdef GDK_WINDOWING_X11
1121 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1123 #ifdef GDK_WINDOWING_WIN32
1124 g_value_set_enum (value, status_icon->priv->orientation);
1127 case PROP_HAS_TOOLTIP:
1128 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1130 case PROP_TOOLTIP_TEXT:
1131 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1133 case PROP_TOOLTIP_MARKUP:
1134 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1137 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1146 * gtk_status_icon_new:
1148 * Creates an empty status icon object.
1150 * Return value: a new #GtkStatusIcon
1155 gtk_status_icon_new (void)
1157 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1161 * gtk_status_icon_new_from_pixbuf:
1162 * @pixbuf: a #GdkPixbuf
1164 * Creates a status icon displaying @pixbuf.
1166 * The image will be scaled down to fit in the available
1167 * space in the notification area, if necessary.
1169 * Return value: a new #GtkStatusIcon
1174 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1176 return g_object_new (GTK_TYPE_STATUS_ICON,
1182 * gtk_status_icon_new_from_file:
1183 * @filename: a filename
1185 * Creates a status icon displaying the file @filename.
1187 * The image will be scaled down to fit in the available
1188 * space in the notification area, if necessary.
1190 * Return value: a new #GtkStatusIcon
1195 gtk_status_icon_new_from_file (const gchar *filename)
1197 return g_object_new (GTK_TYPE_STATUS_ICON,
1203 * gtk_status_icon_new_from_stock:
1204 * @stock_id: a stock icon id
1206 * Creates a status icon displaying a stock icon. Sample stock icon
1207 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1208 * own stock icon names, see gtk_icon_factory_add_default() and
1209 * gtk_icon_factory_add().
1211 * Return value: a new #GtkStatusIcon
1216 gtk_status_icon_new_from_stock (const gchar *stock_id)
1218 return g_object_new (GTK_TYPE_STATUS_ICON,
1224 * gtk_status_icon_new_from_icon_name:
1225 * @icon_name: an icon name
1227 * Creates a status icon displaying an icon from the current icon theme.
1228 * If the current icon theme is changed, the icon will be updated
1231 * Return value: a new #GtkStatusIcon
1236 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1238 return g_object_new (GTK_TYPE_STATUS_ICON,
1239 "icon-name", icon_name,
1244 * gtk_status_icon_new_from_gicon:
1247 * Creates a status icon displaying a #GIcon. If the icon is a
1248 * themed icon, it will be updated when the theme changes.
1250 * Return value: a new #GtkStatusIcon
1255 gtk_status_icon_new_from_gicon (GIcon *icon)
1257 return g_object_new (GTK_TYPE_STATUS_ICON,
1263 emit_activate_signal (GtkStatusIcon *status_icon)
1265 g_signal_emit (status_icon,
1266 status_icon_signals [ACTIVATE_SIGNAL], 0);
1270 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1272 guint32 activate_time)
1274 g_signal_emit (status_icon,
1275 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1280 #ifdef GDK_WINDOWING_X11
1283 emit_size_changed_signal (GtkStatusIcon *status_icon,
1286 gboolean handled = FALSE;
1288 g_signal_emit (status_icon,
1289 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1298 #ifdef GDK_WINDOWING_X11
1301 find_icon_size (GtkWidget *widget,
1305 GtkSettings *settings;
1306 GtkIconSize s, size;
1309 screen = gtk_widget_get_screen (widget);
1312 return GTK_ICON_SIZE_MENU;
1314 settings = gtk_settings_get_for_screen (screen);
1317 size = GTK_ICON_SIZE_MENU;
1319 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1321 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1322 w <= pixel_size && h <= pixel_size)
1324 d = MAX (pixel_size - w, pixel_size - h);
1339 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1341 GtkStatusIconPrivate *priv = status_icon->priv;
1342 #ifdef GDK_WINDOWING_WIN32
1346 switch (priv->storage_type)
1348 case GTK_IMAGE_PIXBUF:
1352 pixbuf = priv->image_data.pixbuf;
1363 width = gdk_pixbuf_get_width (pixbuf);
1364 height = gdk_pixbuf_get_height (pixbuf);
1366 if (width > size || height > size)
1367 scaled = gdk_pixbuf_scale_simple (pixbuf,
1370 GDK_INTERP_BILINEAR);
1372 scaled = g_object_ref (pixbuf);
1374 #ifdef GDK_WINDOWING_X11
1375 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1377 #ifdef GDK_WINDOWING_WIN32
1378 prev_hicon = priv->nid.hIcon;
1379 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1380 priv->nid.uFlags |= NIF_ICON;
1381 if (priv->nid.hWnd != NULL && priv->visible)
1382 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1383 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1385 DestroyIcon (prev_hicon);
1387 #ifdef GDK_WINDOWING_QUARTZ
1389 [priv->status_item setImage:scaled];
1390 QUARTZ_POOL_RELEASE;
1393 g_object_unref (scaled);
1397 #ifdef GDK_WINDOWING_X11
1398 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1400 #ifdef GDK_WINDOWING_WIN32
1401 priv->nid.uFlags &= ~NIF_ICON;
1402 if (priv->nid.hWnd != NULL && priv->visible)
1403 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1404 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1406 #ifdef GDK_WINDOWING_QUARTZ
1407 [priv->status_item setImage:NULL];
1413 case GTK_IMAGE_STOCK:
1415 #ifdef GDK_WINDOWING_X11
1416 GtkIconSize size = find_icon_size (priv->image, priv->size);
1417 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1418 priv->image_data.stock_id,
1421 #ifdef GDK_WINDOWING_WIN32
1424 gtk_widget_render_icon (priv->dummy_widget,
1425 priv->image_data.stock_id,
1426 GTK_ICON_SIZE_SMALL_TOOLBAR,
1429 prev_hicon = priv->nid.hIcon;
1430 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1431 priv->nid.uFlags |= NIF_ICON;
1432 if (priv->nid.hWnd != NULL && priv->visible)
1433 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1434 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1436 DestroyIcon (prev_hicon);
1437 g_object_unref (pixbuf);
1440 #ifdef GDK_WINDOWING_QUARTZ
1444 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1445 priv->image_data.stock_id,
1446 GTK_ICON_SIZE_SMALL_TOOLBAR,
1449 [priv->status_item setImage:pixbuf];
1450 QUARTZ_POOL_RELEASE;
1451 g_object_unref (pixbuf);
1457 case GTK_IMAGE_ICON_NAME:
1459 #ifdef GDK_WINDOWING_X11
1460 GtkIconSize size = find_icon_size (priv->image, priv->size);
1461 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1462 priv->image_data.icon_name,
1465 #ifdef GDK_WINDOWING_WIN32
1468 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1469 priv->image_data.icon_name,
1473 prev_hicon = priv->nid.hIcon;
1474 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1475 priv->nid.uFlags |= NIF_ICON;
1476 if (priv->nid.hWnd != NULL && priv->visible)
1477 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1478 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1480 DestroyIcon (prev_hicon);
1481 g_object_unref (pixbuf);
1484 #ifdef GDK_WINDOWING_QUARTZ
1488 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1489 priv->image_data.icon_name,
1494 [priv->status_item setImage:pixbuf];
1495 QUARTZ_POOL_RELEASE;
1496 g_object_unref (pixbuf);
1503 case GTK_IMAGE_GICON:
1505 #ifdef GDK_WINDOWING_X11
1506 GtkIconSize size = find_icon_size (priv->image, priv->size);
1507 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1508 priv->image_data.gicon,
1511 #ifdef GDK_WINDOWING_WIN32
1514 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1515 priv->image_data.gicon,
1518 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1520 prev_hicon = priv->nid.hIcon;
1521 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1522 priv->nid.uFlags |= NIF_ICON;
1523 if (priv->nid.hWnd != NULL && priv->visible)
1524 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1525 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1527 DestroyIcon (prev_hicon);
1528 g_object_unref (pixbuf);
1531 #ifdef GDK_WINDOWING_QUARTZ
1534 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1535 priv->image_data.gicon,
1538 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1541 [priv->status_item setImage:pixbuf];
1542 QUARTZ_POOL_RELEASE;
1543 g_object_unref (pixbuf);
1550 case GTK_IMAGE_EMPTY:
1551 #ifdef GDK_WINDOWING_X11
1552 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1554 #ifdef GDK_WINDOWING_WIN32
1555 priv->nid.uFlags &= ~NIF_ICON;
1556 if (priv->nid.hWnd != NULL && priv->visible)
1557 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1558 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1560 #ifdef GDK_WINDOWING_QUARTZ
1563 [priv->status_item setImage:NULL];
1564 QUARTZ_POOL_RELEASE;
1569 g_assert_not_reached ();
1574 #ifdef GDK_WINDOWING_X11
1577 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1578 GtkAllocation *allocation)
1580 GtkStatusIconPrivate *priv = status_icon->priv;
1581 GtkOrientation orientation;
1585 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1587 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1588 size = allocation->height;
1590 size = allocation->width;
1592 gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);
1594 priv->image_width = allocation->width - xpad * 2;
1595 priv->image_height = allocation->height - ypad * 2;
1597 if (priv->size != size)
1601 g_object_notify (G_OBJECT (status_icon), "size");
1603 if (!emit_size_changed_signal (status_icon, size))
1604 gtk_status_icon_update_image (status_icon);
1609 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1610 GdkScreen *old_screen)
1612 GtkStatusIconPrivate *priv = status_icon->priv;
1614 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1616 g_object_notify (G_OBJECT (status_icon), "screen");
1622 #ifdef GDK_WINDOWING_X11
1625 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1627 GtkStatusIconPrivate *priv = status_icon->priv;
1628 GtkOrientation orientation;
1631 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1632 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1634 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1635 gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
1637 gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
1641 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1643 gtk_status_icon_padding_changed (status_icon);
1644 g_object_notify (G_OBJECT (status_icon), "embedded");
1648 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1650 gtk_status_icon_padding_changed (status_icon);
1651 g_object_notify (G_OBJECT (status_icon), "orientation");
1655 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1657 GtkStatusIconPrivate *priv = status_icon->priv;
1660 g_object_get (priv->tray_icon, "fg-color", &color, NULL);
1661 gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
1665 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1667 GtkStatusIcon *status_icon)
1669 GtkStatusIconPrivate *priv = status_icon->priv;
1673 switch (pspec->name[0])
1691 g_object_get (priv->tray_icon, pspec->name, &color, NULL);
1692 gtk_widget_modify_symbolic_color (priv->image, name, &color);
1697 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1700 guint state, keyval;
1702 state = event->state & gtk_accelerator_get_default_mod_mask ();
1703 keyval = event->keyval;
1705 (keyval == GDK_Return ||
1706 keyval == GDK_KP_Enter ||
1707 keyval == GDK_ISO_Enter ||
1708 keyval == GDK_space ||
1709 keyval == GDK_KP_Space))
1711 emit_activate_signal (status_icon);
1719 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1721 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1727 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1728 GdkEventButton *event)
1730 gboolean handled = FALSE;
1732 g_signal_emit (status_icon,
1733 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1738 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1740 emit_activate_signal (status_icon);
1743 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1745 emit_popup_menu_signal (status_icon, event->button, event->time);
1753 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1754 GdkEventButton *event)
1756 gboolean handled = FALSE;
1757 g_signal_emit (status_icon,
1758 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1763 #ifdef GDK_WINDOWING_X11
1765 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1766 GdkEventScroll *event)
1768 gboolean handled = FALSE;
1769 g_signal_emit (status_icon,
1770 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1776 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1779 gboolean keyboard_tip,
1780 GtkTooltip *tooltip)
1782 gboolean handled = FALSE;
1783 g_signal_emit (status_icon,
1784 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1785 x, y, keyboard_tip, tooltip, &handled);
1788 #endif /* GDK_WINDOWING_X11 */
1791 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1793 GtkStatusIconPrivate *priv = status_icon->priv;
1795 switch (priv->storage_type)
1797 case GTK_IMAGE_PIXBUF:
1798 if (priv->image_data.pixbuf)
1799 g_object_unref (priv->image_data.pixbuf);
1800 priv->image_data.pixbuf = NULL;
1801 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1804 case GTK_IMAGE_STOCK:
1805 g_free (priv->image_data.stock_id);
1806 priv->image_data.stock_id = NULL;
1808 g_object_notify (G_OBJECT (status_icon), "stock");
1811 case GTK_IMAGE_ICON_NAME:
1812 g_free (priv->image_data.icon_name);
1813 priv->image_data.icon_name = NULL;
1815 g_object_notify (G_OBJECT (status_icon), "icon-name");
1818 case GTK_IMAGE_GICON:
1819 if (priv->image_data.gicon)
1820 g_object_unref (priv->image_data.gicon);
1821 priv->image_data.gicon = NULL;
1823 g_object_notify (G_OBJECT (status_icon), "gicon");
1826 case GTK_IMAGE_EMPTY:
1829 g_assert_not_reached ();
1833 priv->storage_type = GTK_IMAGE_EMPTY;
1834 g_object_notify (G_OBJECT (status_icon), "storage-type");
1838 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1839 GtkImageType storage_type,
1842 GtkStatusIconPrivate *priv = status_icon->priv;
1844 g_object_freeze_notify (G_OBJECT (status_icon));
1846 gtk_status_icon_reset_image_data (status_icon);
1848 priv->storage_type = storage_type;
1849 g_object_notify (G_OBJECT (status_icon), "storage-type");
1851 switch (storage_type)
1853 case GTK_IMAGE_PIXBUF:
1854 priv->image_data.pixbuf = (GdkPixbuf *)data;
1855 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1857 case GTK_IMAGE_STOCK:
1858 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1859 g_object_notify (G_OBJECT (status_icon), "stock");
1861 case GTK_IMAGE_ICON_NAME:
1862 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1863 g_object_notify (G_OBJECT (status_icon), "icon-name");
1865 case GTK_IMAGE_GICON:
1866 priv->image_data.gicon = (GIcon *)data;
1867 g_object_notify (G_OBJECT (status_icon), "gicon");
1870 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1873 g_object_thaw_notify (G_OBJECT (status_icon));
1875 gtk_status_icon_update_image (status_icon);
1879 * gtk_status_icon_set_from_pixbuf:
1880 * @status_icon: a #GtkStatusIcon
1881 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1883 * Makes @status_icon display @pixbuf.
1884 * See gtk_status_icon_new_from_pixbuf() for details.
1889 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1892 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1893 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1896 g_object_ref (pixbuf);
1898 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1903 * gtk_status_icon_set_from_file:
1904 * @status_icon: a #GtkStatusIcon
1905 * @filename: a filename
1907 * Makes @status_icon display the file @filename.
1908 * See gtk_status_icon_new_from_file() for details.
1913 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1914 const gchar *filename)
1918 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1919 g_return_if_fail (filename != NULL);
1921 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1923 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1926 g_object_unref (pixbuf);
1930 * gtk_status_icon_set_from_stock:
1931 * @status_icon: a #GtkStatusIcon
1932 * @stock_id: a stock icon id
1934 * Makes @status_icon display the stock icon with the id @stock_id.
1935 * See gtk_status_icon_new_from_stock() for details.
1940 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1941 const gchar *stock_id)
1943 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1944 g_return_if_fail (stock_id != NULL);
1946 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1947 (gpointer) stock_id);
1951 * gtk_status_icon_set_from_icon_name:
1952 * @status_icon: a #GtkStatusIcon
1953 * @icon_name: an icon name
1955 * Makes @status_icon display the icon named @icon_name from the
1956 * current icon theme.
1957 * See gtk_status_icon_new_from_icon_name() for details.
1962 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1963 const gchar *icon_name)
1965 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1966 g_return_if_fail (icon_name != NULL);
1968 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1969 (gpointer) icon_name);
1973 * gtk_status_icon_set_from_gicon:
1974 * @status_icon: a #GtkStatusIcon
1977 * Makes @status_icon display the #GIcon.
1978 * See gtk_status_icon_new_from_gicon() for details.
1983 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1986 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1987 g_return_if_fail (icon != NULL);
1990 g_object_ref (icon);
1992 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1997 * gtk_status_icon_get_storage_type:
1998 * @status_icon: a #GtkStatusIcon
2000 * Gets the type of representation being used by the #GtkStatusIcon
2001 * to store image data. If the #GtkStatusIcon has no image data,
2002 * the return value will be %GTK_IMAGE_EMPTY.
2004 * Return value: the image representation being used
2009 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2011 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2013 return status_icon->priv->storage_type;
2016 * gtk_status_icon_get_pixbuf:
2017 * @status_icon: a #GtkStatusIcon
2019 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2020 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2021 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2022 * The caller of this function does not own a reference to the
2025 * Return value: the displayed pixbuf, or %NULL if the image is empty.
2030 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2032 GtkStatusIconPrivate *priv;
2034 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2036 priv = status_icon->priv;
2038 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2039 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2041 if (priv->storage_type == GTK_IMAGE_EMPTY)
2042 priv->image_data.pixbuf = NULL;
2044 return priv->image_data.pixbuf;
2048 * gtk_status_icon_get_stock:
2049 * @status_icon: a #GtkStatusIcon
2051 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2052 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2053 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2054 * The returned string is owned by the #GtkStatusIcon and should not
2055 * be freed or modified.
2057 * Return value: stock id of the displayed stock icon,
2058 * or %NULL if the image is empty.
2062 G_CONST_RETURN gchar *
2063 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2065 GtkStatusIconPrivate *priv;
2067 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2069 priv = status_icon->priv;
2071 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2072 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2074 if (priv->storage_type == GTK_IMAGE_EMPTY)
2075 priv->image_data.stock_id = NULL;
2077 return priv->image_data.stock_id;
2081 * gtk_status_icon_get_icon_name:
2082 * @status_icon: a #GtkStatusIcon
2084 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2085 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2086 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2087 * The returned string is owned by the #GtkStatusIcon and should not
2088 * be freed or modified.
2090 * Return value: name of the displayed icon, or %NULL if the image is empty.
2094 G_CONST_RETURN gchar *
2095 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2097 GtkStatusIconPrivate *priv;
2099 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2101 priv = status_icon->priv;
2103 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2104 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2106 if (priv->storage_type == GTK_IMAGE_EMPTY)
2107 priv->image_data.icon_name = NULL;
2109 return priv->image_data.icon_name;
2113 * gtk_status_icon_get_gicon:
2114 * @status_icon: a #GtkStatusIcon
2116 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2117 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2118 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2119 * The caller of this function does not own a reference to the
2122 * If this function fails, @icon is left unchanged;
2124 * Returns: the displayed icon, or %NULL if the image is empty
2129 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2131 GtkStatusIconPrivate *priv;
2133 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2135 priv = status_icon->priv;
2137 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2138 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2140 if (priv->storage_type == GTK_IMAGE_EMPTY)
2141 priv->image_data.gicon = NULL;
2143 return priv->image_data.gicon;
2147 * gtk_status_icon_get_size:
2148 * @status_icon: a #GtkStatusIcon
2150 * Gets the size in pixels that is available for the image.
2151 * Stock icons and named icons adapt their size automatically
2152 * if the size of the notification area changes. For other
2153 * storage types, the size-changed signal can be used to
2154 * react to size changes.
2156 * Note that the returned size is only meaningful while the
2157 * status icon is embedded (see gtk_status_icon_is_embedded()).
2159 * Return value: the size that is available for the image
2164 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2166 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2168 return status_icon->priv->size;
2172 * gtk_status_icon_set_screen:
2173 * @status_icon: a #GtkStatusIcon
2174 * @screen: a #GdkScreen
2176 * Sets the #GdkScreen where @status_icon is displayed; if
2177 * the icon is already mapped, it will be unmapped, and
2178 * then remapped on the new screen.
2183 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2186 g_return_if_fail (GDK_IS_SCREEN (screen));
2188 #ifdef GDK_WINDOWING_X11
2189 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2194 * gtk_status_icon_get_screen:
2195 * @status_icon: a #GtkStatusIcon
2197 * Returns the #GdkScreen associated with @status_icon.
2199 * Return value: a #GdkScreen.
2204 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2206 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2208 #ifdef GDK_WINDOWING_X11
2209 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2211 return gdk_screen_get_default ();
2216 * gtk_status_icon_set_visible:
2217 * @status_icon: a #GtkStatusIcon
2218 * @visible: %TRUE to show the status icon, %FALSE to hide it
2220 * Shows or hides a status icon.
2225 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2228 GtkStatusIconPrivate *priv;
2230 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2232 priv = status_icon->priv;
2234 visible = visible != FALSE;
2236 if (priv->visible != visible)
2238 priv->visible = visible;
2240 #ifdef GDK_WINDOWING_X11
2242 gtk_widget_show (priv->tray_icon);
2243 else if (gtk_widget_get_realized (priv->tray_icon))
2245 gtk_widget_hide (priv->tray_icon);
2246 gtk_widget_unrealize (priv->tray_icon);
2249 #ifdef GDK_WINDOWING_WIN32
2250 if (priv->nid.hWnd != NULL)
2253 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2255 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2258 #ifdef GDK_WINDOWING_QUARTZ
2260 [priv->status_item setVisible:visible];
2261 QUARTZ_POOL_RELEASE;
2263 g_object_notify (G_OBJECT (status_icon), "visible");
2268 * gtk_status_icon_get_visible:
2269 * @status_icon: a #GtkStatusIcon
2271 * Returns whether the status icon is visible or not.
2272 * Note that being visible does not guarantee that
2273 * the user can actually see the icon, see also
2274 * gtk_status_icon_is_embedded().
2276 * Return value: %TRUE if the status icon is visible
2281 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2283 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2285 return status_icon->priv->visible;
2289 * gtk_status_icon_is_embedded:
2290 * @status_icon: a #GtkStatusIcon
2292 * Returns whether the status icon is embedded in a notification
2295 * Return value: %TRUE if the status icon is embedded in
2296 * a notification area.
2301 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2303 #ifdef GDK_WINDOWING_X11
2307 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2309 #ifdef GDK_WINDOWING_X11
2310 plug = GTK_PLUG (status_icon->priv->tray_icon);
2312 if (gtk_plug_get_embedded (plug))
2317 #ifdef GDK_WINDOWING_WIN32
2320 #ifdef GDK_WINDOWING_QUARTZ
2326 * gtk_status_icon_position_menu:
2327 * @menu: the #GtkMenu
2328 * @x: return location for the x position
2329 * @y: return location for the y position
2330 * @push_in: whether the first menu item should be offset (pushed in) to be
2331 * aligned with the menu popup position (only useful for GtkOptionMenu).
2332 * @user_data: the status icon to position the menu on
2334 * Menu positioning function to use with gtk_menu_popup()
2335 * to position @menu aligned to the status icon @user_data.
2340 gtk_status_icon_position_menu (GtkMenu *menu,
2346 #ifdef GDK_WINDOWING_X11
2347 GtkAllocation allocation;
2348 GtkStatusIcon *status_icon;
2349 GtkStatusIconPrivate *priv;
2350 GtkTrayIcon *tray_icon;
2353 GtkTextDirection direction;
2354 GtkRequisition menu_req;
2355 GdkRectangle monitor;
2357 gint monitor_num, height, width, xoffset, yoffset;
2359 g_return_if_fail (GTK_IS_MENU (menu));
2360 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2362 status_icon = GTK_STATUS_ICON (user_data);
2363 priv = status_icon->priv;
2364 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2365 widget = priv->tray_icon;
2367 direction = gtk_widget_get_direction (widget);
2369 screen = gtk_widget_get_screen (widget);
2370 gtk_menu_set_screen (menu, screen);
2372 window = gtk_widget_get_window (widget);
2373 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2374 if (monitor_num < 0)
2376 gtk_menu_set_monitor (menu, monitor_num);
2378 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2380 gdk_window_get_origin (window, x, y);
2382 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2384 gtk_widget_get_allocation (widget, &allocation);
2385 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2388 height = allocation.height;
2389 xoffset = allocation.width;
2394 width = allocation.width;
2397 yoffset = allocation.height;
2400 if (direction == GTK_TEXT_DIR_RTL)
2402 if ((*x - (menu_req.width - width)) >= monitor.x)
2403 *x -= menu_req.width - width;
2404 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2406 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2407 *x -= menu_req.width - width;
2413 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2415 else if ((*x - (menu_req.width - width)) >= monitor.x)
2416 *x -= menu_req.width - width;
2417 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2420 *x -= menu_req.width - width;
2423 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2425 else if ((*y - (menu_req.height - height)) >= monitor.y)
2426 *y -= menu_req.height - height;
2427 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2430 *y -= menu_req.height - height;
2433 #endif /* GDK_WINDOWING_X11 */
2435 #ifdef GDK_WINDOWING_WIN32
2436 GtkStatusIcon *status_icon;
2437 GtkStatusIconPrivate *priv;
2439 g_return_if_fail (GTK_IS_MENU (menu));
2440 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2442 status_icon = GTK_STATUS_ICON (user_data);
2443 priv = status_icon->priv;
2445 *x = priv->last_click_x;
2446 *y = priv->last_click_y;
2452 * gtk_status_icon_get_geometry:
2453 * @status_icon: a #GtkStatusIcon
2454 * @screen: (out) (transfer none) (allow-none): return location for the screen, or %NULL if the
2455 * information is not needed
2456 * @area: (out) (allow-none): return location for the area occupied by the status
2458 * @orientation: (out) (allow-none): return location for the orientation of the panel
2459 * in which the status icon is embedded, or %NULL. A panel
2460 * at the top or bottom of the screen is horizontal, a panel
2461 * at the left or right is vertical.
2463 * Obtains information about the location of the status icon
2464 * on screen. This information can be used to e.g. position
2465 * popups like notification bubbles.
2467 * See gtk_status_icon_position_menu() for a more convenient
2468 * alternative for positioning menus.
2470 * Note that some platforms do not allow GTK+ to provide
2471 * this information, and even on platforms that do allow it,
2472 * the information is not reliable unless the status icon
2473 * is embedded in a notification area, see
2474 * gtk_status_icon_is_embedded().
2476 * Return value: %TRUE if the location information has
2482 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2485 GtkOrientation *orientation)
2487 #ifdef GDK_WINDOWING_X11
2488 GtkAllocation allocation;
2490 GtkStatusIconPrivate *priv;
2493 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2495 priv = status_icon->priv;
2496 widget = priv->tray_icon;
2499 *screen = gtk_widget_get_screen (widget);
2503 gdk_window_get_origin (gtk_widget_get_window (widget),
2506 gtk_widget_get_allocation (widget, &allocation);
2509 area->width = allocation.width;
2510 area->height = allocation.height;
2514 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2519 #endif /* GDK_WINDOWING_X11 */
2523 * gtk_status_icon_set_has_tooltip:
2524 * @status_icon: a #GtkStatusIcon
2525 * @has_tooltip: whether or not @status_icon has a tooltip
2527 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2528 * See #GtkStatusIcon:has-tooltip for more information.
2533 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2534 gboolean has_tooltip)
2536 GtkStatusIconPrivate *priv;
2538 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2540 priv = status_icon->priv;
2542 #ifdef GDK_WINDOWING_X11
2543 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2545 #ifdef GDK_WINDOWING_WIN32
2546 if (!has_tooltip && priv->tooltip_text)
2547 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2549 #ifdef GDK_WINDOWING_QUARTZ
2550 if (!has_tooltip && priv->tooltip_text)
2551 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2556 * gtk_status_icon_get_has_tooltip:
2557 * @status_icon: a #GtkStatusIcon
2559 * Returns the current value of the has-tooltip property.
2560 * See #GtkStatusIcon:has-tooltip for more information.
2562 * Return value: current value of has-tooltip on @status_icon.
2567 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2569 GtkStatusIconPrivate *priv;
2570 gboolean has_tooltip = FALSE;
2572 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2574 priv = status_icon->priv;
2576 #ifdef GDK_WINDOWING_X11
2577 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2579 #ifdef GDK_WINDOWING_WIN32
2580 has_tooltip = (priv->tooltip_text != NULL);
2582 #ifdef GDK_WINDOWING_QUARTZ
2583 has_tooltip = (priv->tooltip_text != NULL);
2590 * gtk_status_icon_set_tooltip_text:
2591 * @status_icon: a #GtkStatusIcon
2592 * @text: the contents of the tooltip for @status_icon
2594 * Sets @text as the contents of the tooltip.
2596 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2597 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2600 * See also the #GtkStatusIcon:tooltip-text property and
2601 * gtk_tooltip_set_text().
2606 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2609 GtkStatusIconPrivate *priv;
2611 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2613 priv = status_icon->priv;
2615 #ifdef GDK_WINDOWING_X11
2617 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2620 #ifdef GDK_WINDOWING_WIN32
2622 priv->nid.uFlags &= ~NIF_TIP;
2625 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2627 priv->nid.uFlags |= NIF_TIP;
2628 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2629 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2632 if (priv->nid.hWnd != NULL && priv->visible)
2633 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2634 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2636 g_free (priv->tooltip_text);
2637 priv->tooltip_text = g_strdup (text);
2639 #ifdef GDK_WINDOWING_QUARTZ
2641 [priv->status_item setToolTip:text];
2642 QUARTZ_POOL_RELEASE;
2644 g_free (priv->tooltip_text);
2645 priv->tooltip_text = g_strdup (text);
2650 * gtk_status_icon_get_tooltip_text:
2651 * @status_icon: a #GtkStatusIcon
2653 * Gets the contents of the tooltip for @status_icon.
2655 * Return value: the tooltip text, or %NULL. You should free the
2656 * returned string with g_free() when done.
2661 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2663 GtkStatusIconPrivate *priv;
2664 gchar *tooltip_text = NULL;
2666 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2668 priv = status_icon->priv;
2670 #ifdef GDK_WINDOWING_X11
2671 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2673 #ifdef GDK_WINDOWING_WIN32
2674 if (priv->tooltip_text)
2675 tooltip_text = g_strdup (priv->tooltip_text);
2677 #ifdef GDK_WINDOWING_QUARTZ
2678 if (priv->tooltip_text)
2679 tooltip_text = g_strdup (priv->tooltip_text);
2682 return tooltip_text;
2686 * gtk_status_icon_set_tooltip_markup:
2687 * @status_icon: a #GtkStatusIcon
2688 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2690 * Sets @markup as the contents of the tooltip, which is marked up with
2691 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2693 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2694 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2696 * See also the #GtkStatusIcon:tooltip-markup property and
2697 * gtk_tooltip_set_markup().
2702 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2703 const gchar *markup)
2705 GtkStatusIconPrivate *priv;
2706 #ifndef GDK_WINDOWING_X11
2710 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2712 priv = status_icon->priv;
2714 #ifdef GDK_WINDOWING_X11
2715 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2717 #ifdef GDK_WINDOWING_WIN32
2719 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2720 gtk_status_icon_set_tooltip_text (status_icon, text);
2723 #ifdef GDK_WINDOWING_QUARTZ
2725 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2726 gtk_status_icon_set_tooltip_text (status_icon, text);
2732 * gtk_status_icon_get_tooltip_markup:
2733 * @status_icon: a #GtkStatusIcon
2735 * Gets the contents of the tooltip for @status_icon.
2737 * Return value: the tooltip text, or %NULL. You should free the
2738 * returned string with g_free() when done.
2743 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2745 GtkStatusIconPrivate *priv;
2746 gchar *markup = NULL;
2748 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2750 priv = status_icon->priv;
2752 #ifdef GDK_WINDOWING_X11
2753 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2755 #ifdef GDK_WINDOWING_WIN32
2756 if (priv->tooltip_text)
2757 markup = g_markup_escape_text (priv->tooltip_text, -1);
2759 #ifdef GDK_WINDOWING_QUARTZ
2760 if (priv->tooltip_text)
2761 markup = g_markup_escape_text (priv->tooltip_text, -1);
2768 * gtk_status_icon_get_x11_window_id:
2769 * @status_icon: a #GtkStatusIcon
2771 * This function is only useful on the X11/freedesktop.org platform.
2772 * It returns a window ID for the widget in the underlying
2773 * status icon implementation. This is useful for the Galago
2774 * notification service, which can send a window ID in the protocol
2775 * in order for the server to position notification windows
2776 * pointing to a status icon reliably.
2778 * This function is not intended for other use cases which are
2779 * more likely to be met by one of the non-X11 specific methods, such
2780 * as gtk_status_icon_position_menu().
2782 * Return value: An 32 bit unsigned integer identifier for the
2783 * underlying X11 Window
2788 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2790 #ifdef GDK_WINDOWING_X11
2791 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2792 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2799 * gtk_status_icon_set_title:
2800 * @status_icon: a #GtkStatusIcon
2803 * Sets the title of this tray icon.
2804 * This should be a short, human-readable, localized string
2805 * describing the tray icon. It may be used by tools like screen
2806 * readers to render the tray icon.
2811 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2814 GtkStatusIconPrivate *priv;
2816 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2818 priv = status_icon->priv;
2820 #ifdef GDK_WINDOWING_X11
2821 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2823 #ifdef GDK_WINDOWING_QUARTZ
2824 g_free (priv->title);
2825 priv->title = g_strdup (title);
2827 #ifdef GDK_WINDOWING_WIN32
2828 g_free (priv->title);
2829 priv->title = g_strdup (title);
2832 g_object_notify (G_OBJECT (status_icon), "title");
2836 * gtk_status_icon_get_title:
2837 * @status_icon: a #GtkStatusIcon
2839 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2841 * Returns: the title of the status icon
2845 G_CONST_RETURN gchar *
2846 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2848 GtkStatusIconPrivate *priv;
2850 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2852 priv = status_icon->priv;
2854 #ifdef GDK_WINDOWING_X11
2855 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2857 #ifdef GDK_WINDOWING_QUARTZ
2860 #ifdef GDK_WINDOWING_WIN32
2867 * gtk_status_icon_set_name:
2868 * @status_icon: a #GtkStatusIcon
2871 * Sets the name of this tray icon.
2872 * This should be a string identifying this icon. It is may be
2873 * used for sorting the icons in the tray and will not be shown to
2879 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2882 GtkStatusIconPrivate *priv;
2884 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2886 priv = status_icon->priv;
2888 #ifdef GDK_WINDOWING_X11
2889 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
2892 g_object_notify (G_OBJECT (status_icon), "name");