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>
32 #include "gtkstatusicon.h"
37 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
40 #include "gtksizerequest.h"
41 #include "gtktrayicon.h"
43 #include "gtkprivate.h"
44 #include "gtkwidget.h"
45 #include "gtktooltip.h"
47 #ifdef GDK_WINDOWING_X11
48 #include "gdk/x11/gdkx.h"
51 #ifdef GDK_WINDOWING_WIN32
52 #include "gtkicontheme.h"
55 #include "win32/gdkwin32.h"
56 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
59 #ifdef GDK_WINDOWING_QUARTZ
60 #include "gtkicontheme.h"
64 #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;
148 static GObject* gtk_status_icon_constructor (GType type,
149 guint n_construct_properties,
150 GObjectConstructParam *construct_params);
151 static void gtk_status_icon_finalize (GObject *object);
152 static void gtk_status_icon_set_property (GObject *object,
156 static void gtk_status_icon_get_property (GObject *object,
161 #ifdef GDK_WINDOWING_X11
162 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
163 GtkAllocation *allocation);
164 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
165 GdkScreen *old_screen);
166 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
167 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
168 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
169 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
170 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
172 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_reset_image_data (GtkStatusIcon *status_icon);
190 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
192 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
195 gtk_status_icon_class_init (GtkStatusIconClass *class)
197 GObjectClass *gobject_class = (GObjectClass *) class;
199 gobject_class->constructor = gtk_status_icon_constructor;
200 gobject_class->finalize = gtk_status_icon_finalize;
201 gobject_class->set_property = gtk_status_icon_set_property;
202 gobject_class->get_property = gtk_status_icon_get_property;
204 class->button_press_event = NULL;
205 class->button_release_event = NULL;
206 class->scroll_event = NULL;
207 class->query_tooltip = NULL;
209 g_object_class_install_property (gobject_class,
211 g_param_spec_object ("pixbuf",
213 P_("A GdkPixbuf to display"),
215 GTK_PARAM_READWRITE));
217 g_object_class_install_property (gobject_class,
219 g_param_spec_string ("file",
221 P_("Filename to load and display"),
223 GTK_PARAM_WRITABLE));
225 g_object_class_install_property (gobject_class,
227 g_param_spec_string ("stock",
229 P_("Stock ID for a stock image to display"),
231 GTK_PARAM_READWRITE));
233 g_object_class_install_property (gobject_class,
235 g_param_spec_string ("icon-name",
237 P_("The name of the icon from the icon theme"),
239 GTK_PARAM_READWRITE));
242 * GtkStatusIcon:gicon:
244 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
245 * the image will be updated automatically if the theme changes.
249 g_object_class_install_property (gobject_class,
251 g_param_spec_object ("gicon",
253 P_("The GIcon being displayed"),
255 GTK_PARAM_READWRITE));
257 g_object_class_install_property (gobject_class,
259 g_param_spec_enum ("storage-type",
261 P_("The representation being used for image data"),
264 GTK_PARAM_READABLE));
266 g_object_class_install_property (gobject_class,
268 g_param_spec_int ("size",
270 P_("The size of the icon"),
274 GTK_PARAM_READABLE));
276 g_object_class_install_property (gobject_class,
278 g_param_spec_object ("screen",
280 P_("The screen where this status icon will be displayed"),
282 GTK_PARAM_READWRITE));
284 g_object_class_install_property (gobject_class,
286 g_param_spec_boolean ("visible",
288 P_("Whether the status icon is visible"),
290 GTK_PARAM_READWRITE));
294 * GtkStatusIcon:embedded:
296 * %TRUE if the statusicon is embedded in a notification area.
300 g_object_class_install_property (gobject_class,
302 g_param_spec_boolean ("embedded",
304 P_("Whether the status icon is embedded"),
306 GTK_PARAM_READABLE));
309 * GtkStatusIcon:orientation:
311 * The orientation of the tray in which the statusicon
316 g_object_class_install_property (gobject_class,
318 g_param_spec_enum ("orientation",
320 P_("The orientation of the tray"),
321 GTK_TYPE_ORIENTATION,
322 GTK_ORIENTATION_HORIZONTAL,
323 GTK_PARAM_READABLE));
326 * GtkStatusIcon:has-tooltip:
328 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
329 * @status_icon. A value of %TRUE indicates that @status_icon can have a
330 * tooltip, in this case the status icon will be queried using
331 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
334 * Note that setting this property to %TRUE for the first time will change
335 * the event masks of the windows of this status icon to include leave-notify
336 * and motion-notify events. This will not be undone when the property is set
339 * Whether this property is respected is platform dependent.
340 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
344 g_object_class_install_property (gobject_class,
346 g_param_spec_boolean ("has-tooltip",
348 P_("Whether this tray icon has a tooltip"),
350 GTK_PARAM_READWRITE));
352 * GtkStatusIcon:tooltip-text:
354 * Sets the text of tooltip to be the given string.
356 * Also see gtk_tooltip_set_text().
358 * This is a convenience property which will take care of getting the
359 * tooltip shown if the given string is not %NULL.
360 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
361 * the default handler for the #GtkStatusIcon::query-tooltip signal
362 * will take care of displaying the tooltip.
364 * Note that some platforms have limitations on the length of tooltips
365 * that they allow on status icons, e.g. Windows only shows the first
370 g_object_class_install_property (gobject_class,
372 g_param_spec_string ("tooltip-text",
374 P_("The contents of the tooltip for this widget"),
376 GTK_PARAM_READWRITE));
378 * GtkStatusIcon:tooltip-markup:
380 * Sets the text of tooltip to be the given string, which is marked up
381 * with the <link linkend="PangoMarkupFormat">Pango text markup
382 * language</link>. Also see gtk_tooltip_set_markup().
384 * This is a convenience property which will take care of getting the
385 * tooltip shown if the given string is not %NULL.
386 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
387 * the default handler for the #GtkStatusIcon::query-tooltip signal
388 * will take care of displaying the tooltip.
390 * On some platforms, embedded markup will be ignored.
394 g_object_class_install_property (gobject_class,
396 g_param_spec_string ("tooltip-markup",
397 P_("Tooltip markup"),
398 P_("The contents of the tooltip for this tray icon"),
400 GTK_PARAM_READWRITE));
404 * GtkStatusIcon:title:
406 * The title of this tray icon. This should be a short, human-readable,
407 * localized string describing the tray icon. It may be used by tools
408 * like screen readers to render the tray icon.
412 g_object_class_install_property (gobject_class,
414 g_param_spec_string ("title",
416 P_("The title of this tray icon"),
418 GTK_PARAM_READWRITE));
421 * GtkStatusIcon::activate:
422 * @status_icon: the object which received the signal
424 * Gets emitted when the user activates the status icon.
425 * If and how status icons can activated is platform-dependent.
427 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
428 * be used by applications and should be wrapped by language bindings.
432 status_icon_signals [ACTIVATE_SIGNAL] =
433 g_signal_new (I_("activate"),
434 G_TYPE_FROM_CLASS (gobject_class),
435 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
436 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
439 g_cclosure_marshal_VOID__VOID,
444 * GtkStatusIcon::popup-menu:
445 * @status_icon: the object which received the signal
446 * @button: the button that was pressed, or 0 if the
447 * signal is not emitted in response to a button press event
448 * @activate_time: the timestamp of the event that
449 * triggered the signal emission
451 * Gets emitted when the user brings up the context menu
452 * of the status icon. Whether status icons can have context
453 * menus and how these are activated is platform-dependent.
455 * The @button and @activate_time parameters should be
456 * passed as the last to arguments to gtk_menu_popup().
458 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
459 * be used by applications and should be wrapped by language bindings.
463 status_icon_signals [POPUP_MENU_SIGNAL] =
464 g_signal_new (I_("popup-menu"),
465 G_TYPE_FROM_CLASS (gobject_class),
466 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
467 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
470 _gtk_marshal_VOID__UINT_UINT,
477 * GtkStatusIcon::size-changed:
478 * @status_icon: the object which received the signal
479 * @size: the new size
481 * Gets emitted when the size available for the image
482 * changes, e.g. because the notification area got resized.
484 * Return value: %TRUE if the icon was updated for the new
485 * size. Otherwise, GTK+ will scale the icon as necessary.
489 status_icon_signals [SIZE_CHANGED_SIGNAL] =
490 g_signal_new (I_("size-changed"),
491 G_TYPE_FROM_CLASS (gobject_class),
493 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
494 g_signal_accumulator_true_handled,
496 _gtk_marshal_BOOLEAN__INT,
502 * GtkStatusIcon::button-press-event:
503 * @status_icon: the object which received the signal
504 * @event: the #GdkEventButton which triggered this signal
506 * The ::button-press-event signal will be emitted when a button
507 * (typically from a mouse) is pressed.
509 * Whether this event is emitted is platform-dependent. Use the ::activate
510 * and ::popup-menu signals in preference.
512 * Return value: %TRUE to stop other handlers from being invoked
513 * for the event. %FALSE to propagate the event further.
517 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
518 g_signal_new (I_("button_press_event"),
519 G_TYPE_FROM_CLASS (gobject_class),
521 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
522 g_signal_accumulator_true_handled, NULL,
523 _gtk_marshal_BOOLEAN__BOXED,
525 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
528 * GtkStatusIcon::button-release-event:
529 * @status_icon: the object which received the signal
530 * @event: the #GdkEventButton which triggered this signal
532 * The ::button-release-event signal will be emitted when a button
533 * (typically from a mouse) is released.
535 * Whether this event is emitted is platform-dependent. Use the ::activate
536 * and ::popup-menu signals in preference.
538 * Return value: %TRUE to stop other handlers from being invoked
539 * for the event. %FALSE to propagate the event further.
543 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
544 g_signal_new (I_("button_release_event"),
545 G_TYPE_FROM_CLASS (gobject_class),
547 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
548 g_signal_accumulator_true_handled, NULL,
549 _gtk_marshal_BOOLEAN__BOXED,
551 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
554 * GtkStatusIcon::scroll-event:
555 * @status_icon: the object which received the signal.
556 * @event: the #GdkEventScroll which triggered this signal
558 * The ::scroll-event signal is emitted when a button in the 4 to 7
559 * range is pressed. Wheel mice are usually configured to generate
560 * button press events for buttons 4 and 5 when the wheel is turned.
562 * Whether this event is emitted is platform-dependent.
564 * Returns: %TRUE to stop other handlers from being invoked for the event.
565 * %FALSE to propagate the event further.
569 status_icon_signals[SCROLL_EVENT_SIGNAL] =
570 g_signal_new (I_("scroll_event"),
571 G_TYPE_FROM_CLASS (gobject_class),
573 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
574 g_signal_accumulator_true_handled, NULL,
575 _gtk_marshal_BOOLEAN__BOXED,
577 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
580 * GtkStatusIcon::query-tooltip:
581 * @status_icon: the object which received the signal
582 * @x: the x coordinate of the cursor position where the request has been
583 * emitted, relative to @status_icon
584 * @y: the y coordinate of the cursor position where the request has been
585 * emitted, relative to @status_icon
586 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
587 * @tooltip: a #GtkTooltip
589 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
590 * cursor hovering above @status_icon; or emitted when @status_icon got
591 * focus in keyboard mode.
593 * Using the given coordinates, the signal handler should determine
594 * whether a tooltip should be shown for @status_icon. If this is
595 * the case %TRUE should be returned, %FALSE otherwise. Note that if
596 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
597 * should not be used.
599 * The signal handler is free to manipulate @tooltip with the therefore
600 * destined function calls.
602 * Whether this signal is emitted is platform-dependent.
603 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
605 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
609 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
610 g_signal_new (I_("query_tooltip"),
611 G_TYPE_FROM_CLASS (gobject_class),
613 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
614 g_signal_accumulator_true_handled, NULL,
615 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
622 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
625 #ifdef GDK_WINDOWING_WIN32
628 build_button_event (GtkStatusIconPrivate *priv,
633 GdkRectangle monitor0;
635 /* We know that gdk/win32 puts the primary monitor at index 0 */
636 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
637 e->window = g_object_ref (gdk_get_default_root_window ());
638 e->send_event = TRUE;
639 e->time = GetTickCount ();
641 priv->last_click_x = e->x = pos.x + monitor0.x;
642 priv->last_click_y = e->y = pos.y + monitor0.y;
646 e->device = gdk_display_get_default ()->core_pointer;
653 GtkStatusIcon *status_icon;
654 GdkEventButton *event;
655 } ButtonCallbackData;
658 button_callback (gpointer data)
660 ButtonCallbackData *bc = (ButtonCallbackData *) data;
662 if (bc->event->type == GDK_BUTTON_PRESS)
663 gtk_status_icon_button_press (bc->status_icon, bc->event);
665 gtk_status_icon_button_release (bc->status_icon, bc->event);
667 gdk_event_free ((GdkEvent *) bc->event);
673 static UINT taskbar_created_msg = 0;
674 static GSList *status_icons = NULL;
676 static LRESULT CALLBACK
682 if (message == taskbar_created_msg)
686 for (rover = status_icons; rover != NULL; rover = rover->next)
688 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
689 GtkStatusIconPrivate *priv = status_icon->priv;
691 priv->nid.hWnd = hwnd;
692 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
693 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
694 priv->nid.uFlags = NIF_MESSAGE;
696 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
698 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
699 priv->nid.hWnd = NULL;
703 gtk_status_icon_update_image (status_icon);
708 if (message == WM_GTK_TRAY_NOTIFICATION)
710 ButtonCallbackData *bc;
728 if (HIWORD (wparam) == XBUTTON1)
734 bc = g_new (ButtonCallbackData, 1);
735 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
736 bc->status_icon = GTK_STATUS_ICON (wparam);
737 build_button_event (bc->status_icon->priv, bc->event, button);
738 g_idle_add (button_callback, bc);
754 if (HIWORD (wparam) == XBUTTON1)
760 bc = g_new (ButtonCallbackData, 1);
761 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
762 bc->status_icon = GTK_STATUS_ICON (wparam);
763 build_button_event (bc->status_icon->priv, bc->event, button);
764 g_idle_add (button_callback, bc);
774 return DefWindowProc (hwnd, message, wparam, lparam);
779 create_tray_observer (void)
782 static HWND hwnd = NULL;
784 HINSTANCE hmodule = GetModuleHandle (NULL);
789 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
791 memset (&wclass, 0, sizeof(WNDCLASS));
792 wclass.lpszClassName = "gtkstatusicon-observer";
793 wclass.lpfnWndProc = wndproc;
794 wclass.hInstance = hmodule;
796 klass = RegisterClass (&wclass);
800 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
802 0, 0, 1, 1, NULL, NULL,
806 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
816 gtk_status_icon_init (GtkStatusIcon *status_icon)
818 GtkStatusIconPrivate *priv;
820 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
821 GtkStatusIconPrivate);
822 status_icon->priv = priv;
824 priv->storage_type = GTK_IMAGE_EMPTY;
825 priv->visible = TRUE;
827 #ifdef GDK_WINDOWING_X11
829 priv->image_width = 0;
830 priv->image_height = 0;
832 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
834 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
835 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
838 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
839 G_CALLBACK (gtk_status_icon_key_press), status_icon);
840 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
841 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
842 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
843 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
844 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
845 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
846 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
847 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
848 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
849 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
850 g_signal_connect (priv->tray_icon, "notify::error-color",
851 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
852 g_signal_connect (priv->tray_icon, "notify::warning-color",
853 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
854 g_signal_connect (priv->tray_icon, "notify::success-color",
855 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
856 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
857 G_CALLBACK (gtk_status_icon_button_press), status_icon);
858 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
859 G_CALLBACK (gtk_status_icon_button_release), status_icon);
860 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
861 G_CALLBACK (gtk_status_icon_scroll), status_icon);
862 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
863 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
864 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
865 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
866 priv->image = gtk_image_new ();
867 gtk_widget_set_can_focus (priv->image, TRUE);
868 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
869 gtk_widget_show (priv->image);
871 g_signal_connect_swapped (priv->image, "size-allocate",
872 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
876 #ifdef GDK_WINDOWING_WIN32
878 /* Get position and orientation of Windows taskbar. */
882 abd.cbSize = sizeof (abd);
883 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
884 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
885 priv->orientation = GTK_ORIENTATION_VERTICAL;
887 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
890 priv->last_click_x = priv->last_click_y = 0;
892 /* Are the system tray icons always 16 pixels square? */
894 priv->image_width = 16;
895 priv->image_height = 16;
897 priv->dummy_widget = gtk_label_new ("");
899 memset (&priv->nid, 0, sizeof (priv->nid));
901 priv->nid.hWnd = create_tray_observer ();
902 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
903 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
904 priv->nid.uFlags = NIF_MESSAGE;
906 /* To help win7 identify the icon create it with an application "unique" tip */
907 if (g_get_prgname ())
909 WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
911 priv->nid.uFlags |= NIF_TIP;
912 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
913 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
917 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
919 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
920 priv->nid.hWnd = NULL;
923 status_icons = g_slist_append (status_icons, status_icon);
927 #ifdef GDK_WINDOWING_QUARTZ
928 priv->dummy_widget = gtk_label_new ("");
932 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
934 priv->image_width = priv->image_height = [priv->status_item getHeight];
935 priv->size = priv->image_height;
943 gtk_status_icon_constructor (GType type,
944 guint n_construct_properties,
945 GObjectConstructParam *construct_params)
948 #ifdef GDK_WINDOWING_X11
949 GtkStatusIcon *status_icon;
950 GtkStatusIconPrivate *priv;
953 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
954 n_construct_properties,
957 #ifdef GDK_WINDOWING_X11
958 status_icon = GTK_STATUS_ICON (object);
959 priv = status_icon->priv;
962 gtk_widget_show (priv->tray_icon);
969 gtk_status_icon_finalize (GObject *object)
971 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
972 GtkStatusIconPrivate *priv = status_icon->priv;
974 gtk_status_icon_reset_image_data (status_icon);
976 #ifdef GDK_WINDOWING_X11
977 g_signal_handlers_disconnect_by_func (priv->tray_icon,
978 gtk_status_icon_key_press, status_icon);
979 g_signal_handlers_disconnect_by_func (priv->tray_icon,
980 gtk_status_icon_popup_menu, status_icon);
981 g_signal_handlers_disconnect_by_func (priv->tray_icon,
982 gtk_status_icon_embedded_changed, status_icon);
983 g_signal_handlers_disconnect_by_func (priv->tray_icon,
984 gtk_status_icon_orientation_changed, status_icon);
985 g_signal_handlers_disconnect_by_func (priv->tray_icon,
986 gtk_status_icon_padding_changed, status_icon);
987 g_signal_handlers_disconnect_by_func (priv->tray_icon,
988 gtk_status_icon_fg_changed, status_icon);
989 g_signal_handlers_disconnect_by_func (priv->tray_icon,
990 gtk_status_icon_color_changed, status_icon);
991 g_signal_handlers_disconnect_by_func (priv->tray_icon,
992 gtk_status_icon_button_press, status_icon);
993 g_signal_handlers_disconnect_by_func (priv->tray_icon,
994 gtk_status_icon_button_release, status_icon);
995 g_signal_handlers_disconnect_by_func (priv->tray_icon,
996 gtk_status_icon_scroll, status_icon);
997 g_signal_handlers_disconnect_by_func (priv->tray_icon,
998 gtk_status_icon_query_tooltip, status_icon);
999 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1000 gtk_status_icon_screen_changed, status_icon);
1001 gtk_widget_destroy (priv->image);
1002 gtk_widget_destroy (priv->tray_icon);
1005 #ifdef GDK_WINDOWING_WIN32
1006 if (priv->nid.hWnd != NULL && priv->visible)
1007 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1008 if (priv->nid.hIcon)
1009 DestroyIcon (priv->nid.hIcon);
1010 g_free (priv->tooltip_text);
1012 gtk_widget_destroy (priv->dummy_widget);
1014 status_icons = g_slist_remove (status_icons, status_icon);
1017 #ifdef GDK_WINDOWING_QUARTZ
1019 [priv->status_item release];
1020 QUARTZ_POOL_RELEASE;
1021 g_free (priv->tooltip_text);
1024 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1028 gtk_status_icon_set_property (GObject *object,
1030 const GValue *value,
1033 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1038 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1041 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1044 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1046 case PROP_ICON_NAME:
1047 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1050 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1053 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1056 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1058 case PROP_HAS_TOOLTIP:
1059 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1061 case PROP_TOOLTIP_TEXT:
1062 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1064 case PROP_TOOLTIP_MARKUP:
1065 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1068 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1071 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1077 gtk_status_icon_get_property (GObject *object,
1082 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1083 GtkStatusIconPrivate *priv = status_icon->priv;
1085 /* The "getter" functions whine if you try to get the wrong
1086 * storage type. This function is instead robust against that,
1087 * so that GUI builders don't have to jump through hoops
1088 * to avoid g_warning
1094 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1095 g_value_set_object (value, NULL);
1097 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1100 if (priv->storage_type != GTK_IMAGE_STOCK)
1101 g_value_set_string (value, NULL);
1103 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1105 case PROP_ICON_NAME:
1106 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1107 g_value_set_string (value, NULL);
1109 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1112 if (priv->storage_type != GTK_IMAGE_GICON)
1113 g_value_set_object (value, NULL);
1115 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1117 case PROP_STORAGE_TYPE:
1118 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1121 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1124 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1127 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1130 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1132 case PROP_ORIENTATION:
1133 #ifdef GDK_WINDOWING_X11
1134 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1136 #ifdef GDK_WINDOWING_WIN32
1137 g_value_set_enum (value, status_icon->priv->orientation);
1140 case PROP_HAS_TOOLTIP:
1141 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1143 case PROP_TOOLTIP_TEXT:
1144 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1146 case PROP_TOOLTIP_MARKUP:
1147 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1150 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1159 * gtk_status_icon_new:
1161 * Creates an empty status icon object.
1163 * Return value: a new #GtkStatusIcon
1168 gtk_status_icon_new (void)
1170 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1174 * gtk_status_icon_new_from_pixbuf:
1175 * @pixbuf: a #GdkPixbuf
1177 * Creates a status icon displaying @pixbuf.
1179 * The image will be scaled down to fit in the available
1180 * space in the notification area, if necessary.
1182 * Return value: a new #GtkStatusIcon
1187 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1189 return g_object_new (GTK_TYPE_STATUS_ICON,
1195 * gtk_status_icon_new_from_file:
1196 * @filename: a filename
1198 * Creates a status icon displaying the file @filename.
1200 * The image will be scaled down to fit in the available
1201 * space in the notification area, if necessary.
1203 * Return value: a new #GtkStatusIcon
1208 gtk_status_icon_new_from_file (const gchar *filename)
1210 return g_object_new (GTK_TYPE_STATUS_ICON,
1216 * gtk_status_icon_new_from_stock:
1217 * @stock_id: a stock icon id
1219 * Creates a status icon displaying a stock icon. Sample stock icon
1220 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1221 * own stock icon names, see gtk_icon_factory_add_default() and
1222 * gtk_icon_factory_add().
1224 * Return value: a new #GtkStatusIcon
1229 gtk_status_icon_new_from_stock (const gchar *stock_id)
1231 return g_object_new (GTK_TYPE_STATUS_ICON,
1237 * gtk_status_icon_new_from_icon_name:
1238 * @icon_name: an icon name
1240 * Creates a status icon displaying an icon from the current icon theme.
1241 * If the current icon theme is changed, the icon will be updated
1244 * Return value: a new #GtkStatusIcon
1249 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1251 return g_object_new (GTK_TYPE_STATUS_ICON,
1252 "icon-name", icon_name,
1257 * gtk_status_icon_new_from_gicon:
1260 * Creates a status icon displaying a #GIcon. If the icon is a
1261 * themed icon, it will be updated when the theme changes.
1263 * Return value: a new #GtkStatusIcon
1268 gtk_status_icon_new_from_gicon (GIcon *icon)
1270 return g_object_new (GTK_TYPE_STATUS_ICON,
1276 emit_activate_signal (GtkStatusIcon *status_icon)
1278 g_signal_emit (status_icon,
1279 status_icon_signals [ACTIVATE_SIGNAL], 0);
1283 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1285 guint32 activate_time)
1287 g_signal_emit (status_icon,
1288 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1293 #ifdef GDK_WINDOWING_X11
1296 emit_size_changed_signal (GtkStatusIcon *status_icon,
1299 gboolean handled = FALSE;
1301 g_signal_emit (status_icon,
1302 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1311 #ifdef GDK_WINDOWING_X11
1314 find_icon_size (GtkWidget *widget,
1318 GtkSettings *settings;
1319 GtkIconSize s, size;
1322 screen = gtk_widget_get_screen (widget);
1325 return GTK_ICON_SIZE_MENU;
1327 settings = gtk_settings_get_for_screen (screen);
1330 size = GTK_ICON_SIZE_MENU;
1332 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1334 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1335 w <= pixel_size && h <= pixel_size)
1337 d = MAX (pixel_size - w, pixel_size - h);
1352 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1354 GtkStatusIconPrivate *priv = status_icon->priv;
1355 #ifdef GDK_WINDOWING_WIN32
1359 switch (priv->storage_type)
1361 case GTK_IMAGE_PIXBUF:
1365 pixbuf = priv->image_data.pixbuf;
1376 width = gdk_pixbuf_get_width (pixbuf);
1377 height = gdk_pixbuf_get_height (pixbuf);
1379 if (width > size || height > size)
1380 scaled = gdk_pixbuf_scale_simple (pixbuf,
1383 GDK_INTERP_BILINEAR);
1385 scaled = g_object_ref (pixbuf);
1387 #ifdef GDK_WINDOWING_X11
1388 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1390 #ifdef GDK_WINDOWING_WIN32
1391 prev_hicon = priv->nid.hIcon;
1392 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1393 priv->nid.uFlags |= NIF_ICON;
1394 if (priv->nid.hWnd != NULL && priv->visible)
1395 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1396 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1398 DestroyIcon (prev_hicon);
1400 #ifdef GDK_WINDOWING_QUARTZ
1402 [priv->status_item setImage:scaled];
1403 QUARTZ_POOL_RELEASE;
1406 g_object_unref (scaled);
1410 #ifdef GDK_WINDOWING_X11
1411 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1413 #ifdef GDK_WINDOWING_WIN32
1414 priv->nid.uFlags &= ~NIF_ICON;
1415 if (priv->nid.hWnd != NULL && priv->visible)
1416 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1417 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1419 #ifdef GDK_WINDOWING_QUARTZ
1420 [priv->status_item setImage:NULL];
1426 case GTK_IMAGE_STOCK:
1428 #ifdef GDK_WINDOWING_X11
1429 GtkIconSize size = find_icon_size (priv->image, priv->size);
1430 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1431 priv->image_data.stock_id,
1434 #ifdef GDK_WINDOWING_WIN32
1437 gtk_widget_render_icon (priv->dummy_widget,
1438 priv->image_data.stock_id,
1439 GTK_ICON_SIZE_SMALL_TOOLBAR,
1442 prev_hicon = priv->nid.hIcon;
1443 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1444 priv->nid.uFlags |= NIF_ICON;
1445 if (priv->nid.hWnd != NULL && priv->visible)
1446 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1447 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1449 DestroyIcon (prev_hicon);
1450 g_object_unref (pixbuf);
1453 #ifdef GDK_WINDOWING_QUARTZ
1457 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1458 priv->image_data.stock_id,
1459 GTK_ICON_SIZE_SMALL_TOOLBAR,
1462 [priv->status_item setImage:pixbuf];
1463 QUARTZ_POOL_RELEASE;
1464 g_object_unref (pixbuf);
1470 case GTK_IMAGE_ICON_NAME:
1472 #ifdef GDK_WINDOWING_X11
1473 GtkIconSize size = find_icon_size (priv->image, priv->size);
1474 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1475 priv->image_data.icon_name,
1478 #ifdef GDK_WINDOWING_WIN32
1481 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1482 priv->image_data.icon_name,
1486 prev_hicon = priv->nid.hIcon;
1487 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1488 priv->nid.uFlags |= NIF_ICON;
1489 if (priv->nid.hWnd != NULL && priv->visible)
1490 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1491 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1493 DestroyIcon (prev_hicon);
1494 g_object_unref (pixbuf);
1497 #ifdef GDK_WINDOWING_QUARTZ
1501 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1502 priv->image_data.icon_name,
1507 [priv->status_item setImage:pixbuf];
1508 QUARTZ_POOL_RELEASE;
1509 g_object_unref (pixbuf);
1516 case GTK_IMAGE_GICON:
1518 #ifdef GDK_WINDOWING_X11
1519 GtkIconSize size = find_icon_size (priv->image, priv->size);
1520 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1521 priv->image_data.gicon,
1524 #ifdef GDK_WINDOWING_WIN32
1527 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1528 priv->image_data.gicon,
1531 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
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 (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1540 DestroyIcon (prev_hicon);
1541 g_object_unref (pixbuf);
1544 #ifdef GDK_WINDOWING_QUARTZ
1547 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1548 priv->image_data.gicon,
1551 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1554 [priv->status_item setImage:pixbuf];
1555 QUARTZ_POOL_RELEASE;
1556 g_object_unref (pixbuf);
1563 case GTK_IMAGE_EMPTY:
1564 #ifdef GDK_WINDOWING_X11
1565 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1567 #ifdef GDK_WINDOWING_WIN32
1568 priv->nid.uFlags &= ~NIF_ICON;
1569 if (priv->nid.hWnd != NULL && priv->visible)
1570 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1571 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1573 #ifdef GDK_WINDOWING_QUARTZ
1576 [priv->status_item setImage:NULL];
1577 QUARTZ_POOL_RELEASE;
1582 g_assert_not_reached ();
1587 #ifdef GDK_WINDOWING_X11
1590 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1591 GtkAllocation *allocation)
1593 GtkStatusIconPrivate *priv = status_icon->priv;
1594 GtkOrientation orientation;
1598 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1600 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1601 size = allocation->height;
1603 size = allocation->width;
1605 gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);
1607 priv->image_width = allocation->width - xpad * 2;
1608 priv->image_height = allocation->height - ypad * 2;
1610 if (priv->size != size)
1614 g_object_notify (G_OBJECT (status_icon), "size");
1616 if (!emit_size_changed_signal (status_icon, size))
1617 gtk_status_icon_update_image (status_icon);
1622 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1623 GdkScreen *old_screen)
1625 GtkStatusIconPrivate *priv = status_icon->priv;
1627 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1629 g_object_notify (G_OBJECT (status_icon), "screen");
1635 #ifdef GDK_WINDOWING_X11
1638 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1640 GtkStatusIconPrivate *priv = status_icon->priv;
1641 GtkOrientation orientation;
1644 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1645 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1647 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1648 gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
1650 gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
1654 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1656 gtk_status_icon_padding_changed (status_icon);
1657 g_object_notify (G_OBJECT (status_icon), "embedded");
1661 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1663 gtk_status_icon_padding_changed (status_icon);
1664 g_object_notify (G_OBJECT (status_icon), "orientation");
1668 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1670 GtkStatusIconPrivate *priv = status_icon->priv;
1673 g_object_get (priv->tray_icon, "fg-color", &color, NULL);
1674 gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
1678 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1680 GtkStatusIcon *status_icon)
1682 GtkStatusIconPrivate *priv = status_icon->priv;
1686 switch (pspec->name[0])
1704 g_object_get (priv->tray_icon, pspec->name, &color, NULL);
1705 gtk_widget_modify_symbolic_color (priv->image, name, &color);
1710 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1713 guint state, keyval;
1715 state = event->state & gtk_accelerator_get_default_mod_mask ();
1716 keyval = event->keyval;
1718 (keyval == GDK_KEY_Return ||
1719 keyval == GDK_KEY_KP_Enter ||
1720 keyval == GDK_KEY_ISO_Enter ||
1721 keyval == GDK_KEY_space ||
1722 keyval == GDK_KEY_KP_Space))
1724 emit_activate_signal (status_icon);
1732 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1734 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1740 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1741 GdkEventButton *event)
1743 gboolean handled = FALSE;
1745 g_signal_emit (status_icon,
1746 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1751 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1753 emit_activate_signal (status_icon);
1756 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1758 emit_popup_menu_signal (status_icon, event->button, event->time);
1766 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1767 GdkEventButton *event)
1769 gboolean handled = FALSE;
1770 g_signal_emit (status_icon,
1771 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1776 #ifdef GDK_WINDOWING_X11
1778 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1779 GdkEventScroll *event)
1781 gboolean handled = FALSE;
1782 g_signal_emit (status_icon,
1783 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1789 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1792 gboolean keyboard_tip,
1793 GtkTooltip *tooltip)
1795 gboolean handled = FALSE;
1796 g_signal_emit (status_icon,
1797 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1798 x, y, keyboard_tip, tooltip, &handled);
1801 #endif /* GDK_WINDOWING_X11 */
1804 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1806 GtkStatusIconPrivate *priv = status_icon->priv;
1808 switch (priv->storage_type)
1810 case GTK_IMAGE_PIXBUF:
1811 if (priv->image_data.pixbuf)
1812 g_object_unref (priv->image_data.pixbuf);
1813 priv->image_data.pixbuf = NULL;
1814 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1817 case GTK_IMAGE_STOCK:
1818 g_free (priv->image_data.stock_id);
1819 priv->image_data.stock_id = NULL;
1821 g_object_notify (G_OBJECT (status_icon), "stock");
1824 case GTK_IMAGE_ICON_NAME:
1825 g_free (priv->image_data.icon_name);
1826 priv->image_data.icon_name = NULL;
1828 g_object_notify (G_OBJECT (status_icon), "icon-name");
1831 case GTK_IMAGE_GICON:
1832 if (priv->image_data.gicon)
1833 g_object_unref (priv->image_data.gicon);
1834 priv->image_data.gicon = NULL;
1836 g_object_notify (G_OBJECT (status_icon), "gicon");
1839 case GTK_IMAGE_EMPTY:
1842 g_assert_not_reached ();
1846 priv->storage_type = GTK_IMAGE_EMPTY;
1847 g_object_notify (G_OBJECT (status_icon), "storage-type");
1851 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1852 GtkImageType storage_type,
1855 GtkStatusIconPrivate *priv = status_icon->priv;
1857 g_object_freeze_notify (G_OBJECT (status_icon));
1859 gtk_status_icon_reset_image_data (status_icon);
1861 priv->storage_type = storage_type;
1862 g_object_notify (G_OBJECT (status_icon), "storage-type");
1864 switch (storage_type)
1866 case GTK_IMAGE_PIXBUF:
1867 priv->image_data.pixbuf = (GdkPixbuf *)data;
1868 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1870 case GTK_IMAGE_STOCK:
1871 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1872 g_object_notify (G_OBJECT (status_icon), "stock");
1874 case GTK_IMAGE_ICON_NAME:
1875 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1876 g_object_notify (G_OBJECT (status_icon), "icon-name");
1878 case GTK_IMAGE_GICON:
1879 priv->image_data.gicon = (GIcon *)data;
1880 g_object_notify (G_OBJECT (status_icon), "gicon");
1883 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1886 g_object_thaw_notify (G_OBJECT (status_icon));
1888 gtk_status_icon_update_image (status_icon);
1892 * gtk_status_icon_set_from_pixbuf:
1893 * @status_icon: a #GtkStatusIcon
1894 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1896 * Makes @status_icon display @pixbuf.
1897 * See gtk_status_icon_new_from_pixbuf() for details.
1902 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1905 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1906 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1909 g_object_ref (pixbuf);
1911 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1916 * gtk_status_icon_set_from_file:
1917 * @status_icon: a #GtkStatusIcon
1918 * @filename: a filename
1920 * Makes @status_icon display the file @filename.
1921 * See gtk_status_icon_new_from_file() for details.
1926 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1927 const gchar *filename)
1931 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1932 g_return_if_fail (filename != NULL);
1934 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1936 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1939 g_object_unref (pixbuf);
1943 * gtk_status_icon_set_from_stock:
1944 * @status_icon: a #GtkStatusIcon
1945 * @stock_id: a stock icon id
1947 * Makes @status_icon display the stock icon with the id @stock_id.
1948 * See gtk_status_icon_new_from_stock() for details.
1953 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1954 const gchar *stock_id)
1956 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1957 g_return_if_fail (stock_id != NULL);
1959 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1960 (gpointer) stock_id);
1964 * gtk_status_icon_set_from_icon_name:
1965 * @status_icon: a #GtkStatusIcon
1966 * @icon_name: an icon name
1968 * Makes @status_icon display the icon named @icon_name from the
1969 * current icon theme.
1970 * See gtk_status_icon_new_from_icon_name() for details.
1975 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1976 const gchar *icon_name)
1978 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1979 g_return_if_fail (icon_name != NULL);
1981 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1982 (gpointer) icon_name);
1986 * gtk_status_icon_set_from_gicon:
1987 * @status_icon: a #GtkStatusIcon
1990 * Makes @status_icon display the #GIcon.
1991 * See gtk_status_icon_new_from_gicon() for details.
1996 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1999 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2000 g_return_if_fail (icon != NULL);
2003 g_object_ref (icon);
2005 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
2010 * gtk_status_icon_get_storage_type:
2011 * @status_icon: a #GtkStatusIcon
2013 * Gets the type of representation being used by the #GtkStatusIcon
2014 * to store image data. If the #GtkStatusIcon has no image data,
2015 * the return value will be %GTK_IMAGE_EMPTY.
2017 * Return value: the image representation being used
2022 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2024 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2026 return status_icon->priv->storage_type;
2029 * gtk_status_icon_get_pixbuf:
2030 * @status_icon: a #GtkStatusIcon
2032 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2033 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2034 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2035 * The caller of this function does not own a reference to the
2038 * Return value: (transfer none): the displayed pixbuf,
2039 * or %NULL if the image is empty.
2044 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2046 GtkStatusIconPrivate *priv;
2048 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2050 priv = status_icon->priv;
2052 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2053 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2055 if (priv->storage_type == GTK_IMAGE_EMPTY)
2056 priv->image_data.pixbuf = NULL;
2058 return priv->image_data.pixbuf;
2062 * gtk_status_icon_get_stock:
2063 * @status_icon: a #GtkStatusIcon
2065 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2066 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2067 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2068 * The returned string is owned by the #GtkStatusIcon and should not
2069 * be freed or modified.
2071 * Return value: stock id of the displayed stock icon,
2072 * or %NULL if the image is empty.
2076 G_CONST_RETURN gchar *
2077 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2079 GtkStatusIconPrivate *priv;
2081 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2083 priv = status_icon->priv;
2085 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2086 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2088 if (priv->storage_type == GTK_IMAGE_EMPTY)
2089 priv->image_data.stock_id = NULL;
2091 return priv->image_data.stock_id;
2095 * gtk_status_icon_get_icon_name:
2096 * @status_icon: a #GtkStatusIcon
2098 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2099 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2100 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2101 * The returned string is owned by the #GtkStatusIcon and should not
2102 * be freed or modified.
2104 * Return value: name of the displayed icon, or %NULL if the image is empty.
2108 G_CONST_RETURN gchar *
2109 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2111 GtkStatusIconPrivate *priv;
2113 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2115 priv = status_icon->priv;
2117 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2118 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2120 if (priv->storage_type == GTK_IMAGE_EMPTY)
2121 priv->image_data.icon_name = NULL;
2123 return priv->image_data.icon_name;
2127 * gtk_status_icon_get_gicon:
2128 * @status_icon: a #GtkStatusIcon
2130 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2131 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2132 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2133 * The caller of this function does not own a reference to the
2136 * If this function fails, @icon is left unchanged;
2138 * Returns: (transfer none): the displayed icon, or %NULL if the image is empty
2143 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2145 GtkStatusIconPrivate *priv;
2147 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2149 priv = status_icon->priv;
2151 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2152 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2154 if (priv->storage_type == GTK_IMAGE_EMPTY)
2155 priv->image_data.gicon = NULL;
2157 return priv->image_data.gicon;
2161 * gtk_status_icon_get_size:
2162 * @status_icon: a #GtkStatusIcon
2164 * Gets the size in pixels that is available for the image.
2165 * Stock icons and named icons adapt their size automatically
2166 * if the size of the notification area changes. For other
2167 * storage types, the size-changed signal can be used to
2168 * react to size changes.
2170 * Note that the returned size is only meaningful while the
2171 * status icon is embedded (see gtk_status_icon_is_embedded()).
2173 * Return value: the size that is available for the image
2178 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2180 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2182 return status_icon->priv->size;
2186 * gtk_status_icon_set_screen:
2187 * @status_icon: a #GtkStatusIcon
2188 * @screen: a #GdkScreen
2190 * Sets the #GdkScreen where @status_icon is displayed; if
2191 * the icon is already mapped, it will be unmapped, and
2192 * then remapped on the new screen.
2197 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2200 g_return_if_fail (GDK_IS_SCREEN (screen));
2202 #ifdef GDK_WINDOWING_X11
2203 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2208 * gtk_status_icon_get_screen:
2209 * @status_icon: a #GtkStatusIcon
2211 * Returns the #GdkScreen associated with @status_icon.
2213 * Return value: (transfer none): a #GdkScreen.
2218 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2220 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2222 #ifdef GDK_WINDOWING_X11
2223 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2225 return gdk_screen_get_default ();
2230 * gtk_status_icon_set_visible:
2231 * @status_icon: a #GtkStatusIcon
2232 * @visible: %TRUE to show the status icon, %FALSE to hide it
2234 * Shows or hides a status icon.
2239 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2242 GtkStatusIconPrivate *priv;
2244 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2246 priv = status_icon->priv;
2248 visible = visible != FALSE;
2250 if (priv->visible != visible)
2252 priv->visible = visible;
2254 #ifdef GDK_WINDOWING_X11
2256 gtk_widget_show (priv->tray_icon);
2257 else if (gtk_widget_get_realized (priv->tray_icon))
2259 gtk_widget_hide (priv->tray_icon);
2260 gtk_widget_unrealize (priv->tray_icon);
2263 #ifdef GDK_WINDOWING_WIN32
2264 if (priv->nid.hWnd != NULL)
2267 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2269 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2272 #ifdef GDK_WINDOWING_QUARTZ
2274 [priv->status_item setVisible:visible];
2275 QUARTZ_POOL_RELEASE;
2277 g_object_notify (G_OBJECT (status_icon), "visible");
2282 * gtk_status_icon_get_visible:
2283 * @status_icon: a #GtkStatusIcon
2285 * Returns whether the status icon is visible or not.
2286 * Note that being visible does not guarantee that
2287 * the user can actually see the icon, see also
2288 * gtk_status_icon_is_embedded().
2290 * Return value: %TRUE if the status icon is visible
2295 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2297 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2299 return status_icon->priv->visible;
2303 * gtk_status_icon_is_embedded:
2304 * @status_icon: a #GtkStatusIcon
2306 * Returns whether the status icon is embedded in a notification
2309 * Return value: %TRUE if the status icon is embedded in
2310 * a notification area.
2315 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2317 #ifdef GDK_WINDOWING_X11
2321 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2323 #ifdef GDK_WINDOWING_X11
2324 plug = GTK_PLUG (status_icon->priv->tray_icon);
2326 if (gtk_plug_get_embedded (plug))
2331 #ifdef GDK_WINDOWING_WIN32
2334 #ifdef GDK_WINDOWING_QUARTZ
2340 * gtk_status_icon_position_menu:
2341 * @menu: the #GtkMenu
2342 * @x: return location for the x position
2343 * @y: return location for the y position
2344 * @push_in: whether the first menu item should be offset (pushed in) to be
2345 * aligned with the menu popup position (only useful for GtkOptionMenu).
2346 * @user_data: the status icon to position the menu on
2348 * Menu positioning function to use with gtk_menu_popup()
2349 * to position @menu aligned to the status icon @user_data.
2354 gtk_status_icon_position_menu (GtkMenu *menu,
2360 #ifdef GDK_WINDOWING_X11
2361 GtkAllocation allocation;
2362 GtkStatusIcon *status_icon;
2363 GtkStatusIconPrivate *priv;
2364 GtkTrayIcon *tray_icon;
2367 GtkTextDirection direction;
2368 GtkRequisition menu_req;
2369 GdkRectangle monitor;
2371 gint monitor_num, height, width, xoffset, yoffset;
2373 g_return_if_fail (GTK_IS_MENU (menu));
2374 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2376 status_icon = GTK_STATUS_ICON (user_data);
2377 priv = status_icon->priv;
2378 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2379 widget = priv->tray_icon;
2381 direction = gtk_widget_get_direction (widget);
2383 screen = gtk_widget_get_screen (widget);
2384 gtk_menu_set_screen (menu, screen);
2386 window = gtk_widget_get_window (widget);
2387 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2388 if (monitor_num < 0)
2390 gtk_menu_set_monitor (menu, monitor_num);
2392 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2394 gdk_window_get_origin (window, x, y);
2396 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2399 gtk_widget_get_allocation (widget, &allocation);
2400 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2403 height = allocation.height;
2404 xoffset = allocation.width;
2409 width = allocation.width;
2412 yoffset = allocation.height;
2415 if (direction == GTK_TEXT_DIR_RTL)
2417 if ((*x - (menu_req.width - width)) >= monitor.x)
2418 *x -= menu_req.width - width;
2419 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2421 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2422 *x -= menu_req.width - width;
2428 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2430 else if ((*x - (menu_req.width - width)) >= monitor.x)
2431 *x -= menu_req.width - width;
2432 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2435 *x -= menu_req.width - width;
2438 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2440 else if ((*y - (menu_req.height - height)) >= monitor.y)
2441 *y -= menu_req.height - height;
2442 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2445 *y -= menu_req.height - height;
2448 #endif /* GDK_WINDOWING_X11 */
2450 #ifdef GDK_WINDOWING_WIN32
2451 GtkStatusIcon *status_icon;
2452 GtkStatusIconPrivate *priv;
2454 g_return_if_fail (GTK_IS_MENU (menu));
2455 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2457 status_icon = GTK_STATUS_ICON (user_data);
2458 priv = status_icon->priv;
2460 *x = priv->last_click_x;
2461 *y = priv->last_click_y;
2467 * gtk_status_icon_get_geometry:
2468 * @status_icon: a #GtkStatusIcon
2469 * @screen: (out) (transfer none) (allow-none): return location for the screen, or %NULL if the
2470 * information is not needed
2471 * @area: (out) (allow-none): return location for the area occupied by the status
2473 * @orientation: (out) (allow-none): return location for the orientation of the panel
2474 * in which the status icon is embedded, or %NULL. A panel
2475 * at the top or bottom of the screen is horizontal, a panel
2476 * at the left or right is vertical.
2478 * Obtains information about the location of the status icon
2479 * on screen. This information can be used to e.g. position
2480 * popups like notification bubbles.
2482 * See gtk_status_icon_position_menu() for a more convenient
2483 * alternative for positioning menus.
2485 * Note that some platforms do not allow GTK+ to provide
2486 * this information, and even on platforms that do allow it,
2487 * the information is not reliable unless the status icon
2488 * is embedded in a notification area, see
2489 * gtk_status_icon_is_embedded().
2491 * Return value: %TRUE if the location information has
2497 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2500 GtkOrientation *orientation)
2502 #ifdef GDK_WINDOWING_X11
2503 GtkAllocation allocation;
2505 GtkStatusIconPrivate *priv;
2508 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2510 priv = status_icon->priv;
2511 widget = priv->tray_icon;
2514 *screen = gtk_widget_get_screen (widget);
2518 gdk_window_get_origin (gtk_widget_get_window (widget),
2521 gtk_widget_get_allocation (widget, &allocation);
2524 area->width = allocation.width;
2525 area->height = allocation.height;
2529 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2534 #endif /* GDK_WINDOWING_X11 */
2538 * gtk_status_icon_set_has_tooltip:
2539 * @status_icon: a #GtkStatusIcon
2540 * @has_tooltip: whether or not @status_icon has a tooltip
2542 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2543 * See #GtkStatusIcon:has-tooltip for more information.
2548 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2549 gboolean has_tooltip)
2551 GtkStatusIconPrivate *priv;
2553 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2555 priv = status_icon->priv;
2557 #ifdef GDK_WINDOWING_X11
2558 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2560 #ifdef GDK_WINDOWING_WIN32
2561 if (!has_tooltip && priv->tooltip_text)
2562 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2564 #ifdef GDK_WINDOWING_QUARTZ
2565 if (!has_tooltip && priv->tooltip_text)
2566 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2571 * gtk_status_icon_get_has_tooltip:
2572 * @status_icon: a #GtkStatusIcon
2574 * Returns the current value of the has-tooltip property.
2575 * See #GtkStatusIcon:has-tooltip for more information.
2577 * Return value: current value of has-tooltip on @status_icon.
2582 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2584 GtkStatusIconPrivate *priv;
2585 gboolean has_tooltip = FALSE;
2587 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2589 priv = status_icon->priv;
2591 #ifdef GDK_WINDOWING_X11
2592 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2594 #ifdef GDK_WINDOWING_WIN32
2595 has_tooltip = (priv->tooltip_text != NULL);
2597 #ifdef GDK_WINDOWING_QUARTZ
2598 has_tooltip = (priv->tooltip_text != NULL);
2605 * gtk_status_icon_set_tooltip_text:
2606 * @status_icon: a #GtkStatusIcon
2607 * @text: the contents of the tooltip for @status_icon
2609 * Sets @text as the contents of the tooltip.
2611 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2612 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2615 * See also the #GtkStatusIcon:tooltip-text property and
2616 * gtk_tooltip_set_text().
2621 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2624 GtkStatusIconPrivate *priv;
2626 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2628 priv = status_icon->priv;
2630 #ifdef GDK_WINDOWING_X11
2632 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2635 #ifdef GDK_WINDOWING_WIN32
2637 priv->nid.uFlags &= ~NIF_TIP;
2640 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2642 priv->nid.uFlags |= NIF_TIP;
2643 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2644 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2647 if (priv->nid.hWnd != NULL && priv->visible)
2648 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2649 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2651 g_free (priv->tooltip_text);
2652 priv->tooltip_text = g_strdup (text);
2654 #ifdef GDK_WINDOWING_QUARTZ
2656 [priv->status_item setToolTip:text];
2657 QUARTZ_POOL_RELEASE;
2659 g_free (priv->tooltip_text);
2660 priv->tooltip_text = g_strdup (text);
2665 * gtk_status_icon_get_tooltip_text:
2666 * @status_icon: a #GtkStatusIcon
2668 * Gets the contents of the tooltip for @status_icon.
2670 * Return value: the tooltip text, or %NULL. You should free the
2671 * returned string with g_free() when done.
2676 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2678 GtkStatusIconPrivate *priv;
2679 gchar *tooltip_text = NULL;
2681 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2683 priv = status_icon->priv;
2685 #ifdef GDK_WINDOWING_X11
2686 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2688 #ifdef GDK_WINDOWING_WIN32
2689 if (priv->tooltip_text)
2690 tooltip_text = g_strdup (priv->tooltip_text);
2692 #ifdef GDK_WINDOWING_QUARTZ
2693 if (priv->tooltip_text)
2694 tooltip_text = g_strdup (priv->tooltip_text);
2697 return tooltip_text;
2701 * gtk_status_icon_set_tooltip_markup:
2702 * @status_icon: a #GtkStatusIcon
2703 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2705 * Sets @markup as the contents of the tooltip, which is marked up with
2706 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2708 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2709 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2711 * See also the #GtkStatusIcon:tooltip-markup property and
2712 * gtk_tooltip_set_markup().
2717 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2718 const gchar *markup)
2720 GtkStatusIconPrivate *priv;
2721 #ifndef GDK_WINDOWING_X11
2725 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2727 priv = status_icon->priv;
2729 #ifdef GDK_WINDOWING_X11
2730 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2732 #ifdef GDK_WINDOWING_WIN32
2734 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2735 gtk_status_icon_set_tooltip_text (status_icon, text);
2738 #ifdef GDK_WINDOWING_QUARTZ
2740 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2741 gtk_status_icon_set_tooltip_text (status_icon, text);
2747 * gtk_status_icon_get_tooltip_markup:
2748 * @status_icon: a #GtkStatusIcon
2750 * Gets the contents of the tooltip for @status_icon.
2752 * Return value: the tooltip text, or %NULL. You should free the
2753 * returned string with g_free() when done.
2758 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2760 GtkStatusIconPrivate *priv;
2761 gchar *markup = NULL;
2763 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2765 priv = status_icon->priv;
2767 #ifdef GDK_WINDOWING_X11
2768 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2770 #ifdef GDK_WINDOWING_WIN32
2771 if (priv->tooltip_text)
2772 markup = g_markup_escape_text (priv->tooltip_text, -1);
2774 #ifdef GDK_WINDOWING_QUARTZ
2775 if (priv->tooltip_text)
2776 markup = g_markup_escape_text (priv->tooltip_text, -1);
2783 * gtk_status_icon_get_x11_window_id:
2784 * @status_icon: a #GtkStatusIcon
2786 * This function is only useful on the X11/freedesktop.org platform.
2787 * It returns a window ID for the widget in the underlying
2788 * status icon implementation. This is useful for the Galago
2789 * notification service, which can send a window ID in the protocol
2790 * in order for the server to position notification windows
2791 * pointing to a status icon reliably.
2793 * This function is not intended for other use cases which are
2794 * more likely to be met by one of the non-X11 specific methods, such
2795 * as gtk_status_icon_position_menu().
2797 * Return value: An 32 bit unsigned integer identifier for the
2798 * underlying X11 Window
2803 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2805 #ifdef GDK_WINDOWING_X11
2806 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2807 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2814 * gtk_status_icon_set_title:
2815 * @status_icon: a #GtkStatusIcon
2818 * Sets the title of this tray icon.
2819 * This should be a short, human-readable, localized string
2820 * describing the tray icon. It may be used by tools like screen
2821 * readers to render the tray icon.
2826 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2829 GtkStatusIconPrivate *priv;
2831 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2833 priv = status_icon->priv;
2835 #ifdef GDK_WINDOWING_X11
2836 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2838 #ifdef GDK_WINDOWING_QUARTZ
2839 g_free (priv->title);
2840 priv->title = g_strdup (title);
2842 #ifdef GDK_WINDOWING_WIN32
2843 g_free (priv->title);
2844 priv->title = g_strdup (title);
2847 g_object_notify (G_OBJECT (status_icon), "title");
2851 * gtk_status_icon_get_title:
2852 * @status_icon: a #GtkStatusIcon
2854 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2856 * Returns: the title of the status icon
2860 G_CONST_RETURN gchar *
2861 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2863 GtkStatusIconPrivate *priv;
2865 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2867 priv = status_icon->priv;
2869 #ifdef GDK_WINDOWING_X11
2870 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2872 #ifdef GDK_WINDOWING_QUARTZ
2875 #ifdef GDK_WINDOWING_WIN32
2882 * gtk_status_icon_set_name:
2883 * @status_icon: a #GtkStatusIcon
2886 * Sets the name of this tray icon.
2887 * This should be a string identifying this icon. It is may be
2888 * used for sorting the icons in the tray and will not be shown to
2894 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2897 GtkStatusIconPrivate *priv;
2899 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2901 priv = status_icon->priv;
2903 #ifdef GDK_WINDOWING_X11
2904 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
2907 g_object_notify (G_OBJECT (status_icon), "name");