3 * Copyright (C) 2003 Sun Microsystems, Inc.
4 * Copyright (C) 2005 Hans Breuer <hans@breuer.org>
5 * Copyright (C) 2005 Novell, Inc.
6 * Copyright (C) 2006 Imendio AB
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Mark McLoughlin <mark@skynet.ie>
25 * Hans Breuer <hans@breuer.org>
26 * Tor Lillqvist <tml@novell.com>
27 * Mikael Hallendal <micke@imendio.com>
33 #include "gtkstatusicon.h"
36 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
39 #include "gtktrayicon.h"
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
43 #include "gtktooltip.h"
45 #ifdef GDK_WINDOWING_X11
46 #include "gdk/x11/gdkx.h"
49 #ifdef GDK_WINDOWING_WIN32
50 #include "gtkicontheme.h"
53 #include "win32/gdkwin32.h"
54 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
57 #ifdef GDK_WINDOWING_QUARTZ
58 #include "gtkicontheme.h"
62 #include "gdkkeysyms.h"
66 #define BLINK_TIMEOUT 500
93 BUTTON_PRESS_EVENT_SIGNAL,
94 BUTTON_RELEASE_EVENT_SIGNAL,
100 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
102 #ifdef GDK_WINDOWING_QUARTZ
103 #include "gtkstatusicon-quartz.c"
106 struct _GtkStatusIconPrivate
108 #ifdef GDK_WINDOWING_X11
109 GtkWidget *tray_icon;
113 #ifdef GDK_WINDOWING_WIN32
114 GtkWidget *dummy_widget;
116 gint last_click_x, last_click_y;
117 GtkOrientation orientation;
121 #ifdef GDK_WINDOWING_QUARTZ
122 GtkWidget *dummy_widget;
123 GtkQuartzStatusIcon *status_item;
132 GtkImageType storage_type;
142 GdkPixbuf *blank_icon;
143 guint blinking_timeout;
150 static GObject* gtk_status_icon_constructor (GType type,
151 guint n_construct_properties,
152 GObjectConstructParam *construct_params);
153 static void gtk_status_icon_finalize (GObject *object);
154 static void gtk_status_icon_set_property (GObject *object,
158 static void gtk_status_icon_get_property (GObject *object,
163 #ifdef GDK_WINDOWING_X11
164 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
165 GtkAllocation *allocation);
166 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
167 GdkScreen *old_screen);
168 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
169 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
170 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
171 GdkEventScroll *event);
172 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
175 gboolean keyboard_tip,
176 GtkTooltip *tooltip);
178 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
180 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
182 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
183 GdkEventButton *event);
184 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
185 GdkEventButton *event);
186 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
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 ("blinking",
286 P_("Whether or not the status icon is blinking"),
288 GTK_PARAM_READWRITE));
290 g_object_class_install_property (gobject_class,
292 g_param_spec_boolean ("visible",
294 P_("Whether or not the status icon is visible"),
296 GTK_PARAM_READWRITE));
300 * GtkStatusIcon:embedded:
302 * %TRUE if the statusicon is embedded in a notification area.
306 g_object_class_install_property (gobject_class,
308 g_param_spec_boolean ("embedded",
310 P_("Whether or not the status icon is embedded"),
312 GTK_PARAM_READABLE));
315 * GtkStatusIcon:orientation:
317 * The orientation of the tray in which the statusicon
322 g_object_class_install_property (gobject_class,
324 g_param_spec_enum ("orientation",
326 P_("The orientation of the tray"),
327 GTK_TYPE_ORIENTATION,
328 GTK_ORIENTATION_HORIZONTAL,
329 GTK_PARAM_READABLE));
332 * GtkStatusIcon:has-tooltip:
334 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
335 * @status_icon. A value of %TRUE indicates that @status_icon can have a
336 * tooltip, in this case the status icon will be queried using
337 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
340 * Note that setting this property to %TRUE for the first time will change
341 * the event masks of the windows of this status icon to include leave-notify
342 * and motion-notify events. This will not be undone when the property is set
345 * Whether this property is respected is platform dependent.
346 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
350 g_object_class_install_property (gobject_class,
352 g_param_spec_boolean ("has-tooltip",
354 P_("Whether this tray icon has a tooltip"),
356 GTK_PARAM_READWRITE));
358 * GtkStatusIcon:tooltip-text:
360 * Sets the text of tooltip to be the given string.
362 * Also see gtk_tooltip_set_text().
364 * This is a convenience property which will take care of getting the
365 * tooltip shown if the given string is not %NULL.
366 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
367 * the default handler for the #GtkStatusIcon::query-tooltip signal
368 * will take care of displaying the tooltip.
372 g_object_class_install_property (gobject_class,
374 g_param_spec_string ("tooltip-text",
376 P_("The contents of the tooltip for this widget"),
378 GTK_PARAM_READWRITE));
380 * GtkStatusIcon:tooltip-markup:
382 * Sets the text of tooltip to be the given string, which is marked up
383 * with the <link linkend="PangoMarkupFormat">Pango text markup
384 * language</link>. Also see gtk_tooltip_set_markup().
386 * This is a convenience property which will take care of getting the
387 * tooltip shown if the given string is not %NULL.
388 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
389 * the default handler for the #GtkStatusIcon::query-tooltip signal
390 * will take care of displaying the tooltip.
392 * On some platforms, embedded markup will be ignored.
396 g_object_class_install_property (gobject_class,
398 g_param_spec_string ("tooltip-markup",
399 P_("Tooltip markup"),
400 P_("The contents of the tooltip for this tray icon"),
402 GTK_PARAM_READWRITE));
406 * GtkStatusIcon::activate:
407 * @status_icon: the object which received the signal
409 * Gets emitted when the user activates the status icon.
410 * If and how status icons can activated is platform-dependent.
412 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
413 * be used by applications and should be wrapped by language bindings.
417 status_icon_signals [ACTIVATE_SIGNAL] =
418 g_signal_new (I_("activate"),
419 G_TYPE_FROM_CLASS (gobject_class),
420 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
421 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
424 g_cclosure_marshal_VOID__VOID,
429 * GtkStatusIcon::popup-menu:
430 * @status_icon: the object which received the signal
431 * @button: the button that was pressed, or 0 if the
432 * signal is not emitted in response to a button press event
433 * @activate_time: the timestamp of the event that
434 * triggered the signal emission
436 * Gets emitted when the user brings up the context menu
437 * of the status icon. Whether status icons can have context
438 * menus and how these are activated is platform-dependent.
440 * The @button and @activate_time parameters should be
441 * passed as the last to arguments to gtk_menu_popup().
443 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
444 * be used by applications and should be wrapped by language bindings.
448 status_icon_signals [POPUP_MENU_SIGNAL] =
449 g_signal_new (I_("popup-menu"),
450 G_TYPE_FROM_CLASS (gobject_class),
451 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
452 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
455 _gtk_marshal_VOID__UINT_UINT,
462 * GtkStatusIcon::size-changed:
463 * @status_icon: the object which received the signal
464 * @size: the new size
466 * Gets emitted when the size available for the image
467 * changes, e.g. because the notification area got resized.
469 * Return value: %TRUE if the icon was updated for the new
470 * size. Otherwise, GTK+ will scale the icon as necessary.
474 status_icon_signals [SIZE_CHANGED_SIGNAL] =
475 g_signal_new (I_("size-changed"),
476 G_TYPE_FROM_CLASS (gobject_class),
478 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
479 g_signal_accumulator_true_handled,
481 _gtk_marshal_BOOLEAN__INT,
487 * GtkStatusIcon::button-press-event:
488 * @status_icon: the object which received the signal
489 * @event: the #GdkEventButton which triggered this signal
491 * The ::button-press-event signal will be emitted when a button
492 * (typically from a mouse) is pressed.
494 * Whether this event is emitted is platform-dependent. Use the ::activate
495 * and ::popup-menu signals in preference.
497 * Return value: %TRUE to stop other handlers from being invoked
498 * for the event. %FALSE to propagate the event further.
502 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
503 g_signal_new (I_("button_press_event"),
504 G_TYPE_FROM_CLASS (gobject_class),
506 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
507 g_signal_accumulator_true_handled, NULL,
508 _gtk_marshal_BOOLEAN__BOXED,
510 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
513 * GtkStatusIcon::button-release-event:
514 * @status_icon: the object which received the signal
515 * @event: the #GdkEventButton which triggered this signal
517 * The ::button-release-event signal will be emitted when a button
518 * (typically from a mouse) is released.
520 * Whether this event is emitted is platform-dependent. Use the ::activate
521 * and ::popup-menu signals in preference.
523 * Return value: %TRUE to stop other handlers from being invoked
524 * for the event. %FALSE to propagate the event further.
528 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
529 g_signal_new (I_("button_release_event"),
530 G_TYPE_FROM_CLASS (gobject_class),
532 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
533 g_signal_accumulator_true_handled, NULL,
534 _gtk_marshal_BOOLEAN__BOXED,
536 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
539 * GtkStatusIcon::scroll-event:
540 * @status_icon: the object which received the signal.
541 * @event: the #GdkEventScroll which triggered this signal
543 * The ::scroll-event signal is emitted when a button in the 4 to 7
544 * range is pressed. Wheel mice are usually configured to generate
545 * button press events for buttons 4 and 5 when the wheel is turned.
547 * Whether this event is emitted is platform-dependent.
549 * Returns: %TRUE to stop other handlers from being invoked for the event.
550 * %FALSE to propagate the event further.
552 status_icon_signals[SCROLL_EVENT_SIGNAL] =
553 g_signal_new (I_("scroll_event"),
554 G_TYPE_FROM_CLASS (gobject_class),
556 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
557 g_signal_accumulator_true_handled, NULL,
558 _gtk_marshal_BOOLEAN__BOXED,
560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
563 * GtkStatusIcon::query-tooltip:
564 * @status_icon: the object which received the signal
565 * @x: the x coordinate of the cursor position where the request has been
566 * emitted, relative to @status_icon
567 * @y: the y coordinate of the cursor position where the request has been
568 * emitted, relative to @status_icon
569 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
570 * @tooltip: a #GtkTooltip
572 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
573 * cursor hovering above @status_icon; or emitted when @status_icon got
574 * focus in keyboard mode.
576 * Using the given coordinates, the signal handler should determine
577 * whether a tooltip should be shown for @status_icon. If this is
578 * the case %TRUE should be returned, %FALSE otherwise. Note that if
579 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
580 * should not be used.
582 * The signal handler is free to manipulate @tooltip with the therefore
583 * destined function calls.
585 * Whether this signal is emitted is platform-dependent.
586 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
588 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
592 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
593 g_signal_new (I_("query_tooltip"),
594 G_TYPE_FROM_CLASS (gobject_class),
596 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
597 g_signal_accumulator_true_handled, NULL,
598 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
605 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
608 #ifdef GDK_WINDOWING_WIN32
611 build_button_event (GtkStatusIconPrivate *priv,
616 GdkRectangle monitor0;
618 /* We know that gdk/win32 puts the primary monitor at index 0 */
619 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
620 e->window = g_object_ref (gdk_get_default_root_window ());
621 e->send_event = TRUE;
622 e->time = GetTickCount ();
624 priv->last_click_x = e->x = pos.x + monitor0.x;
625 priv->last_click_y = e->y = pos.y + monitor0.y;
629 e->device = gdk_display_get_default ()->core_pointer;
636 GtkStatusIcon *status_icon;
637 GdkEventButton *event;
638 } ButtonCallbackData;
641 button_callback (gpointer data)
643 ButtonCallbackData *bc = (ButtonCallbackData *) data;
645 if (event->type == GDK_BUTTON_PRESS)
646 gtk_status_icon_button_press (bc->status_icon, bc->event);
648 gtk_status_icon_button_release (bc->status_icon, bc->event);
650 gdk_event_free ((GdkEvent *) bc->event);
656 static UINT taskbar_created_msg = 0;
657 static GSList *status_icons = NULL;
659 static LRESULT CALLBACK
665 if (message == taskbar_created_msg)
669 for (rover = status_icons; rover != NULL; rover = rover->next)
671 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
672 GtkStatusIconPrivate *priv = status_icon->priv;
674 priv->nid.hWnd = hwnd;
675 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
676 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
677 priv->nid.uFlags = NIF_MESSAGE;
679 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
681 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
682 priv->nid.hWnd = NULL;
686 gtk_status_icon_update_image (status_icon);
691 if (message == WM_GTK_TRAY_NOTIFICATION)
693 ButtonCallbackData *bc;
711 if (HIWORD (wparam) == XBUTTON1)
717 bc = g_new (ButtonCallbackData, 1);
718 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
719 bc->status_icon = GTK_STATUS_ICON (wparam);
720 build_button_event (bc->status_icon->priv, bc->event, button);
721 g_idle_add (button_callback, bc);
737 if (HIWORD (wparam) == XBUTTON1)
743 bc = g_new (ButtonCallbackData, 1);
744 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
745 bc->status_icon = GTK_STATUS_ICON (wparam);
746 build_button_event (bc->status_icon->priv, bc->event, button);
747 g_idle_add (button_callback, bc);
757 return DefWindowProc (hwnd, message, wparam, lparam);
762 create_tray_observer (void)
765 static HWND hwnd = NULL;
767 HINSTANCE hmodule = GetModuleHandle (NULL);
772 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
774 memset (&wclass, 0, sizeof(WNDCLASS));
775 wclass.lpszClassName = "gtkstatusicon-observer";
776 wclass.lpfnWndProc = wndproc;
777 wclass.hInstance = hmodule;
779 klass = RegisterClass (&wclass);
783 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
785 0, 0, 1, 1, NULL, NULL,
789 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
799 gtk_status_icon_init (GtkStatusIcon *status_icon)
801 GtkStatusIconPrivate *priv;
803 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
804 GtkStatusIconPrivate);
805 status_icon->priv = priv;
807 priv->storage_type = GTK_IMAGE_EMPTY;
808 priv->visible = TRUE;
810 #ifdef GDK_WINDOWING_X11
812 priv->image_width = 0;
813 priv->image_height = 0;
815 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
817 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
818 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
821 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
822 G_CALLBACK (gtk_status_icon_key_press), status_icon);
823 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
824 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
825 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
826 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
827 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
828 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
829 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
830 G_CALLBACK (gtk_status_icon_button_press), status_icon);
831 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
832 G_CALLBACK (gtk_status_icon_button_release), status_icon);
833 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
834 G_CALLBACK (gtk_status_icon_scroll), status_icon);
835 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
836 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
837 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
838 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
839 priv->image = gtk_image_new ();
840 GTK_WIDGET_SET_FLAGS (priv->image, GTK_CAN_FOCUS);
841 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
842 gtk_widget_show (priv->image);
844 g_signal_connect_swapped (priv->image, "size-allocate",
845 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
849 #ifdef GDK_WINDOWING_WIN32
851 /* Get position and orientation of Windows taskbar. */
855 abd.cbSize = sizeof (abd);
856 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
857 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
858 priv->orientation = GTK_ORIENTATION_VERTICAL;
860 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
863 priv->last_click_x = priv->last_click_y = 0;
865 /* Are the system tray icons always 16 pixels square? */
867 priv->image_width = 16;
868 priv->image_height = 16;
870 priv->dummy_widget = gtk_label_new ("");
872 memset (&priv->nid, 0, sizeof (priv->nid));
874 priv->nid.hWnd = create_tray_observer ();
875 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
876 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
877 priv->nid.uFlags = NIF_MESSAGE;
879 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
881 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
882 priv->nid.hWnd = NULL;
885 status_icons = g_slist_append (status_icons, status_icon);
889 #ifdef GDK_WINDOWING_QUARTZ
890 priv->dummy_widget = gtk_label_new ("");
894 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
896 priv->image_width = priv->image_height = [priv->status_item getHeight];
897 priv->size = priv->image_height;
905 gtk_status_icon_constructor (GType type,
906 guint n_construct_properties,
907 GObjectConstructParam *construct_params)
910 #ifdef GDK_WINDOWING_X11
911 GtkStatusIcon *status_icon;
912 GtkStatusIconPrivate *priv;
915 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
916 n_construct_properties,
919 #ifdef GDK_WINDOWING_X11
920 status_icon = GTK_STATUS_ICON (object);
921 priv = status_icon->priv;
924 gtk_widget_show (priv->tray_icon);
931 gtk_status_icon_finalize (GObject *object)
933 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
934 GtkStatusIconPrivate *priv = status_icon->priv;
936 gtk_status_icon_disable_blinking (status_icon);
938 gtk_status_icon_reset_image_data (status_icon);
940 if (priv->blank_icon)
941 g_object_unref (priv->blank_icon);
942 priv->blank_icon = NULL;
944 #ifdef GDK_WINDOWING_X11
945 gtk_widget_destroy (priv->tray_icon);
948 #ifdef GDK_WINDOWING_WIN32
949 if (priv->nid.hWnd != NULL && priv->visible)
950 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
952 DestroyIcon (priv->nid.hIcon);
953 g_free (priv->tooltip_text);
955 gtk_widget_destroy (priv->dummy_widget);
957 status_icons = g_slist_remove (status_icons, status_icon);
960 #ifdef GDK_WINDOWING_QUARTZ
962 [priv->status_item release];
964 g_free (priv->tooltip_text);
967 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
971 gtk_status_icon_set_property (GObject *object,
976 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
981 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
984 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
987 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
990 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
993 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
996 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
999 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
1002 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1004 case PROP_HAS_TOOLTIP:
1005 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1006 case PROP_TOOLTIP_TEXT:
1007 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1008 case PROP_TOOLTIP_MARKUP:
1009 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1011 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1017 gtk_status_icon_get_property (GObject *object,
1022 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1023 GtkStatusIconPrivate *priv = status_icon->priv;
1025 /* The "getter" functions whine if you try to get the wrong
1026 * storage type. This function is instead robust against that,
1027 * so that GUI builders don't have to jump through hoops
1028 * to avoid g_warning
1034 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1035 g_value_set_object (value, NULL);
1037 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1040 if (priv->storage_type != GTK_IMAGE_STOCK)
1041 g_value_set_string (value, NULL);
1043 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1045 case PROP_ICON_NAME:
1046 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1047 g_value_set_string (value, NULL);
1049 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1052 if (priv->storage_type != GTK_IMAGE_GICON)
1053 g_value_set_object (value, NULL);
1055 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1057 case PROP_STORAGE_TYPE:
1058 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1061 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1064 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1067 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
1070 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1073 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1075 case PROP_ORIENTATION:
1076 #ifdef GDK_WINDOWING_X11
1077 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1079 #ifdef GDK_WINDOWING_WIN32
1080 g_value_set_enum (value, status_icon->priv->orientation);
1083 case PROP_HAS_TOOLTIP:
1084 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1086 case PROP_TOOLTIP_TEXT:
1087 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1089 case PROP_TOOLTIP_MARKUP:
1090 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1093 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1099 * gtk_status_icon_new:
1101 * Creates an empty status icon object.
1103 * Return value: a new #GtkStatusIcon
1108 gtk_status_icon_new (void)
1110 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1114 * gtk_status_icon_new_from_pixbuf:
1115 * @pixbuf: a #GdkPixbuf
1117 * Creates a status icon displaying @pixbuf.
1119 * The image will be scaled down to fit in the available
1120 * space in the notification area, if necessary.
1122 * Return value: a new #GtkStatusIcon
1127 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1129 return g_object_new (GTK_TYPE_STATUS_ICON,
1135 * gtk_status_icon_new_from_file:
1136 * @filename: a filename
1138 * Creates a status icon displaying the file @filename.
1140 * The image will be scaled down to fit in the available
1141 * space in the notification area, if necessary.
1143 * Return value: a new #GtkStatusIcon
1148 gtk_status_icon_new_from_file (const gchar *filename)
1150 return g_object_new (GTK_TYPE_STATUS_ICON,
1156 * gtk_status_icon_new_from_stock:
1157 * @stock_id: a stock icon id
1159 * Creates a status icon displaying a stock icon. Sample stock icon
1160 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1161 * own stock icon names, see gtk_icon_factory_add_default() and
1162 * gtk_icon_factory_add().
1164 * Return value: a new #GtkStatusIcon
1169 gtk_status_icon_new_from_stock (const gchar *stock_id)
1171 return g_object_new (GTK_TYPE_STATUS_ICON,
1177 * gtk_status_icon_new_from_icon_name:
1178 * @icon_name: an icon name
1180 * Creates a status icon displaying an icon from the current icon theme.
1181 * If the current icon theme is changed, the icon will be updated
1184 * Return value: a new #GtkStatusIcon
1189 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1191 return g_object_new (GTK_TYPE_STATUS_ICON,
1192 "icon-name", icon_name,
1197 * gtk_status_icon_new_from_gicon:
1200 * Creates a status icon displaying a #GIcon. If the icon is a
1201 * themed icon, it will be updated when the theme changes.
1203 * Return value: a new #GtkStatusIcon
1208 gtk_status_icon_new_from_gicon (GIcon *icon)
1210 return g_object_new (GTK_TYPE_STATUS_ICON,
1216 emit_activate_signal (GtkStatusIcon *status_icon)
1218 g_signal_emit (status_icon,
1219 status_icon_signals [ACTIVATE_SIGNAL], 0);
1223 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1225 guint32 activate_time)
1227 g_signal_emit (status_icon,
1228 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1233 #ifdef GDK_WINDOWING_X11
1236 emit_size_changed_signal (GtkStatusIcon *status_icon,
1239 gboolean handled = FALSE;
1241 g_signal_emit (status_icon,
1242 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1252 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
1254 GtkStatusIconPrivate *priv = status_icon->priv;
1256 if (priv->blank_icon)
1260 width = gdk_pixbuf_get_width (priv->blank_icon);
1261 height = gdk_pixbuf_get_height (priv->blank_icon);
1264 if (width == priv->image_width && height == priv->image_height)
1265 return priv->blank_icon;
1268 g_object_unref (priv->blank_icon);
1269 priv->blank_icon = NULL;
1273 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
1275 priv->image_height);
1276 if (priv->blank_icon)
1277 gdk_pixbuf_fill (priv->blank_icon, 0);
1279 return priv->blank_icon;
1282 #ifdef GDK_WINDOWING_X11
1285 find_icon_size (GtkWidget *widget,
1289 GtkSettings *settings;
1290 GtkIconSize s, size;
1293 screen = gtk_widget_get_screen (widget);
1296 return GTK_ICON_SIZE_MENU;
1298 settings = gtk_settings_get_for_screen (screen);
1301 size = GTK_ICON_SIZE_MENU;
1303 for (s = GTK_ICON_SIZE_MENU; s < GTK_ICON_SIZE_DIALOG; s++)
1305 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1306 w <= pixel_size && h <= pixel_size)
1308 d = MAX (pixel_size - w, pixel_size - h);
1323 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1325 GtkStatusIconPrivate *priv = status_icon->priv;
1326 #ifdef GDK_WINDOWING_WIN32
1330 if (priv->blink_off)
1332 #ifdef GDK_WINDOWING_X11
1333 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
1334 gtk_status_icon_blank_icon (status_icon));
1336 #ifdef GDK_WINDOWING_WIN32
1337 prev_hicon = priv->nid.hIcon;
1338 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
1339 priv->nid.uFlags |= NIF_ICON;
1340 if (priv->nid.hWnd != NULL && priv->visible)
1341 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1342 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1344 DestroyIcon (prev_hicon);
1346 #ifdef GDK_WINDOWING_QUARTZ
1348 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
1349 QUARTZ_POOL_RELEASE;
1354 switch (priv->storage_type)
1356 case GTK_IMAGE_PIXBUF:
1360 pixbuf = priv->image_data.pixbuf;
1371 width = gdk_pixbuf_get_width (pixbuf);
1372 height = gdk_pixbuf_get_height (pixbuf);
1374 if (width > size || height > size)
1375 scaled = gdk_pixbuf_scale_simple (pixbuf,
1378 GDK_INTERP_BILINEAR);
1380 scaled = g_object_ref (pixbuf);
1382 #ifdef GDK_WINDOWING_X11
1383 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1385 #ifdef GDK_WINDOWING_WIN32
1386 prev_hicon = priv->nid.hIcon;
1387 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1388 priv->nid.uFlags |= NIF_ICON;
1389 if (priv->nid.hWnd != NULL && priv->visible)
1390 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1391 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1393 DestroyIcon (prev_hicon);
1395 #ifdef GDK_WINDOWING_QUARTZ
1397 [priv->status_item setImage:scaled];
1398 QUARTZ_POOL_RELEASE;
1401 g_object_unref (scaled);
1405 #ifdef GDK_WINDOWING_X11
1406 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1408 #ifdef GDK_WINDOWING_WIN32
1409 priv->nid.uFlags &= ~NIF_ICON;
1410 if (priv->nid.hWnd != NULL && priv->visible)
1411 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1412 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1414 #ifdef GDK_WINDOWING_QUARTZ
1415 [priv->status_item setImage:NULL];
1421 case GTK_IMAGE_STOCK:
1423 #ifdef GDK_WINDOWING_X11
1424 GtkIconSize size = find_icon_size (priv->image, priv->size);
1425 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1426 priv->image_data.stock_id,
1429 #ifdef GDK_WINDOWING_WIN32
1432 gtk_widget_render_icon (priv->dummy_widget,
1433 priv->image_data.stock_id,
1434 GTK_ICON_SIZE_SMALL_TOOLBAR,
1437 prev_hicon = priv->nid.hIcon;
1438 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1439 priv->nid.uFlags |= NIF_ICON;
1440 if (priv->nid.hWnd != NULL && priv->visible)
1441 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1442 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1444 DestroyIcon (prev_hicon);
1445 g_object_unref (pixbuf);
1448 #ifdef GDK_WINDOWING_QUARTZ
1452 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1453 priv->image_data.stock_id,
1454 GTK_ICON_SIZE_SMALL_TOOLBAR,
1457 [priv->status_item setImage:pixbuf];
1458 QUARTZ_POOL_RELEASE;
1459 g_object_unref (pixbuf);
1465 case GTK_IMAGE_ICON_NAME:
1467 #ifdef GDK_WINDOWING_X11
1468 GtkIconSize size = find_icon_size (priv->image, priv->size);
1469 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1470 priv->image_data.icon_name,
1473 #ifdef GDK_WINDOWING_WIN32
1476 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1477 priv->image_data.icon_name,
1481 prev_hicon = priv->nid.hIcon;
1482 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1483 priv->nid.uFlags |= NIF_ICON;
1484 if (priv->nid.hWnd != NULL && priv->visible)
1485 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1486 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1488 DestroyIcon (prev_hicon);
1489 g_object_unref (pixbuf);
1492 #ifdef GDK_WINDOWING_QUARTZ
1496 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1497 priv->image_data.icon_name,
1502 [priv->status_item setImage:pixbuf];
1503 QUARTZ_POOL_RELEASE;
1504 g_object_unref (pixbuf);
1511 case GTK_IMAGE_GICON:
1513 #ifdef GDK_WINDOWING_X11
1514 GtkIconSize size = find_icon_size (priv->image, priv->size);
1515 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1516 priv->image_data.gicon,
1519 #ifdef GDK_WINDOWING_WIN32
1522 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1523 priv->image_data.gicon,
1526 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1528 prev_hicon = priv->nid.hIcon;
1529 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1530 priv->nid.uFlags |= NIF_ICON;
1531 if (priv->nid.hWnd != NULL && priv->visible)
1532 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1533 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1535 DestroyIcon (prev_hicon);
1536 g_object_unref (pixbuf);
1539 #ifdef GDK_WINDOWING_QUARTZ
1542 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1543 priv->image_data.gicon,
1546 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1549 [priv->status_item setImage:pixbuf];
1550 QUARTZ_POOL_RELEASE;
1551 g_object_unref (pixbuf);
1558 case GTK_IMAGE_EMPTY:
1559 #ifdef GDK_WINDOWING_X11
1560 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1562 #ifdef GDK_WINDOWING_WIN32
1563 priv->nid.uFlags &= ~NIF_ICON;
1564 if (priv->nid.hWnd != NULL && priv->visible)
1565 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1566 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1568 #ifdef GDK_WINDOWING_QUARTZ
1571 [priv->status_item setImage:NULL];
1572 QUARTZ_POOL_RELEASE;
1577 g_assert_not_reached ();
1582 #ifdef GDK_WINDOWING_X11
1585 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1586 GtkAllocation *allocation)
1588 GtkStatusIconPrivate *priv = status_icon->priv;
1589 GtkOrientation orientation;
1592 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1594 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1595 size = allocation->height;
1597 size = allocation->width;
1599 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1600 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1602 if (priv->size != size)
1606 g_object_notify (G_OBJECT (status_icon), "size");
1608 if (!emit_size_changed_signal (status_icon, size))
1609 gtk_status_icon_update_image (status_icon);
1614 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1615 GdkScreen *old_screen)
1617 GtkStatusIconPrivate *priv = status_icon->priv;
1619 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1621 g_object_notify (G_OBJECT (status_icon), "screen");
1627 #ifdef GDK_WINDOWING_X11
1630 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1632 g_object_notify (G_OBJECT (status_icon), "embedded");
1636 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1638 g_object_notify (G_OBJECT (status_icon), "orientation");
1642 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1645 guint state, keyval;
1647 state = event->state & gtk_accelerator_get_default_mod_mask ();
1648 keyval = event->keyval;
1650 (keyval == GDK_Return ||
1651 keyval == GDK_KP_Enter ||
1652 keyval == GDK_ISO_Enter ||
1653 keyval == GDK_space ||
1654 keyval == GDK_KP_Space))
1656 emit_activate_signal (status_icon);
1664 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1666 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1672 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1673 GdkEventButton *event)
1675 gboolean handled = FALSE;
1677 g_signal_emit (status_icon,
1678 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1683 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1685 emit_activate_signal (status_icon);
1688 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1690 emit_popup_menu_signal (status_icon, event->button, event->time);
1698 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1699 GdkEventButton *event)
1701 gboolean handled = FALSE;
1702 g_signal_emit (status_icon,
1703 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1708 #ifdef GDK_WINDOWING_X11
1710 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1711 GdkEventScroll *event)
1713 gboolean handled = FALSE;
1714 g_signal_emit (status_icon,
1715 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1721 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1724 gboolean keyboard_tip,
1725 GtkTooltip *tooltip)
1727 gboolean handled = FALSE;
1728 g_signal_emit (status_icon,
1729 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1730 x, y, keyboard_tip, tooltip, &handled);
1733 #endif /* GDK_WINDOWING_X11 */
1736 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1738 GtkStatusIconPrivate *priv = status_icon->priv;
1740 switch (priv->storage_type)
1742 case GTK_IMAGE_PIXBUF:
1743 if (priv->image_data.pixbuf)
1744 g_object_unref (priv->image_data.pixbuf);
1745 priv->image_data.pixbuf = NULL;
1746 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1749 case GTK_IMAGE_STOCK:
1750 g_free (priv->image_data.stock_id);
1751 priv->image_data.stock_id = NULL;
1753 g_object_notify (G_OBJECT (status_icon), "stock");
1756 case GTK_IMAGE_ICON_NAME:
1757 g_free (priv->image_data.icon_name);
1758 priv->image_data.icon_name = NULL;
1760 g_object_notify (G_OBJECT (status_icon), "icon-name");
1763 case GTK_IMAGE_GICON:
1764 g_free (priv->image_data.gicon);
1765 priv->image_data.gicon = NULL;
1767 g_object_notify (G_OBJECT (status_icon), "gicon");
1770 case GTK_IMAGE_EMPTY:
1773 g_assert_not_reached ();
1777 priv->storage_type = GTK_IMAGE_EMPTY;
1778 g_object_notify (G_OBJECT (status_icon), "storage-type");
1782 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1783 GtkImageType storage_type,
1786 GtkStatusIconPrivate *priv = status_icon->priv;
1788 g_object_freeze_notify (G_OBJECT (status_icon));
1790 gtk_status_icon_reset_image_data (status_icon);
1792 priv->storage_type = storage_type;
1793 g_object_notify (G_OBJECT (status_icon), "storage-type");
1795 switch (storage_type)
1797 case GTK_IMAGE_PIXBUF:
1798 priv->image_data.pixbuf = (GdkPixbuf *)data;
1799 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1801 case GTK_IMAGE_STOCK:
1802 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1803 g_object_notify (G_OBJECT (status_icon), "stock");
1805 case GTK_IMAGE_ICON_NAME:
1806 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1807 g_object_notify (G_OBJECT (status_icon), "icon-name");
1809 case GTK_IMAGE_GICON:
1810 priv->image_data.gicon = (GIcon *)data;
1811 g_object_notify (G_OBJECT (status_icon), "gicon");
1814 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1817 g_object_thaw_notify (G_OBJECT (status_icon));
1819 gtk_status_icon_update_image (status_icon);
1823 * gtk_status_icon_set_from_pixbuf:
1824 * @status_icon: a #GtkStatusIcon
1825 * @pixbuf: a #GdkPixbuf or %NULL
1827 * Makes @status_icon display @pixbuf.
1828 * See gtk_status_icon_new_from_pixbuf() for details.
1833 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1836 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1837 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1840 g_object_ref (pixbuf);
1842 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1847 * gtk_status_icon_set_from_file:
1848 * @status_icon: a #GtkStatusIcon
1849 * @filename: a filename
1851 * Makes @status_icon display the file @filename.
1852 * See gtk_status_icon_new_from_file() for details.
1857 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1858 const gchar *filename)
1862 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1863 g_return_if_fail (filename != NULL);
1865 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1867 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1870 g_object_unref (pixbuf);
1874 * gtk_status_icon_set_from_stock:
1875 * @status_icon: a #GtkStatusIcon
1876 * @stock_id: a stock icon id
1878 * Makes @status_icon display the stock icon with the id @stock_id.
1879 * See gtk_status_icon_new_from_stock() for details.
1884 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1885 const gchar *stock_id)
1887 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1888 g_return_if_fail (stock_id != NULL);
1890 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1891 (gpointer) stock_id);
1895 * gtk_status_icon_set_from_icon_name:
1896 * @status_icon: a #GtkStatusIcon
1897 * @icon_name: an icon name
1899 * Makes @status_icon display the icon named @icon_name from the
1900 * current icon theme.
1901 * See gtk_status_icon_new_from_icon_name() for details.
1906 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1907 const gchar *icon_name)
1909 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1910 g_return_if_fail (icon_name != NULL);
1912 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1913 (gpointer) icon_name);
1917 * gtk_status_icon_set_from_gicon:
1918 * @status_icon: a #GtkStatusIcon
1921 * Makes @status_icon display the #GIcon.
1922 * See gtk_status_icon_new_from_gicon() for details.
1927 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1930 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1931 g_return_if_fail (icon != NULL);
1933 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1938 * gtk_status_icon_get_storage_type:
1939 * @status_icon: a #GtkStatusIcon
1941 * Gets the type of representation being used by the #GtkStatusIcon
1942 * to store image data. If the #GtkStatusIcon has no image data,
1943 * the return value will be %GTK_IMAGE_EMPTY.
1945 * Return value: the image representation being used
1950 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1952 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1954 return status_icon->priv->storage_type;
1957 * gtk_status_icon_get_pixbuf:
1958 * @status_icon: a #GtkStatusIcon
1960 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1961 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1962 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1963 * The caller of this function does not own a reference to the
1966 * Return value: the displayed pixbuf, or %NULL if the image is empty.
1971 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1973 GtkStatusIconPrivate *priv;
1975 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1977 priv = status_icon->priv;
1979 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
1980 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1982 if (priv->storage_type == GTK_IMAGE_EMPTY)
1983 priv->image_data.pixbuf = NULL;
1985 return priv->image_data.pixbuf;
1989 * gtk_status_icon_get_stock:
1990 * @status_icon: a #GtkStatusIcon
1992 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1993 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1994 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1995 * The returned string is owned by the #GtkStatusIcon and should not
1996 * be freed or modified.
1998 * Return value: stock id of the displayed stock icon,
1999 * or %NULL if the image is empty.
2003 G_CONST_RETURN gchar *
2004 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2006 GtkStatusIconPrivate *priv;
2008 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2010 priv = status_icon->priv;
2012 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2013 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2015 if (priv->storage_type == GTK_IMAGE_EMPTY)
2016 priv->image_data.stock_id = NULL;
2018 return priv->image_data.stock_id;
2022 * gtk_status_icon_get_icon_name:
2023 * @status_icon: a #GtkStatusIcon
2025 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2026 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2027 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2028 * The returned string is owned by the #GtkStatusIcon and should not
2029 * be freed or modified.
2031 * Return value: name of the displayed icon, or %NULL if the image is empty.
2035 G_CONST_RETURN gchar *
2036 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2038 GtkStatusIconPrivate *priv;
2040 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2042 priv = status_icon->priv;
2044 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2045 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2047 if (priv->storage_type == GTK_IMAGE_EMPTY)
2048 priv->image_data.icon_name = NULL;
2050 return priv->image_data.icon_name;
2054 * gtk_status_icon_get_gicon:
2055 * @status_icon: a #GtkStatusIcon
2057 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2058 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2059 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2060 * The caller of this function does not own a reference to the
2063 * If this function fails, @icon is left unchanged;
2065 * Returns: the displayed icon, or %NULL if the image is empty
2070 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2072 GtkStatusIconPrivate *priv;
2074 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2076 priv = status_icon->priv;
2078 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2079 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2081 if (priv->storage_type == GTK_IMAGE_EMPTY)
2082 priv->image_data.gicon = NULL;
2084 return priv->image_data.gicon;
2088 * gtk_status_icon_get_size:
2089 * @status_icon: a #GtkStatusIcon
2091 * Gets the size in pixels that is available for the image.
2092 * Stock icons and named icons adapt their size automatically
2093 * if the size of the notification area changes. For other
2094 * storage types, the size-changed signal can be used to
2095 * react to size changes.
2097 * Note that the returned size is only meaningful while the
2098 * status icon is embedded (see gtk_status_icon_is_embedded()).
2100 * Return value: the size that is available for the image
2105 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2107 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2109 return status_icon->priv->size;
2113 * gtk_status_icon_set_screen:
2114 * @status_icon: a #GtkStatusIcon
2115 * @screen: a #GdkScreen
2117 * Sets the #GdkScreen where @status_icon is displayed; if
2118 * the icon is already mapped, it will be unmapped, and
2119 * then remapped on the new screen.
2124 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2127 g_return_if_fail (GDK_IS_SCREEN (screen));
2129 #ifdef GDK_WINDOWING_X11
2130 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2135 * gtk_status_icon_get_screen:
2136 * @status_icon: a #GtkStatusIcon
2138 * Returns the #GdkScreen associated with @status_icon.
2140 * Return value: a #GdkScreen.
2145 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2147 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2149 #ifdef GDK_WINDOWING_X11
2150 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2152 return gdk_screen_get_default ();
2157 * gtk_status_icon_set_tooltip:
2158 * @status_icon: a #GtkStatusIcon
2159 * @tooltip_text: the tooltip text, or %NULL
2161 * Sets the tooltip of the status icon.
2165 * Deprecated: 2.16: Use gtk_status_icon_set_tooltip_text() instead.
2168 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
2169 const gchar *tooltip_text)
2171 gtk_status_icon_set_tooltip_text (status_icon, tooltip_text);
2175 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
2177 GtkStatusIconPrivate *priv = status_icon->priv;
2179 priv->blink_off = !priv->blink_off;
2181 gtk_status_icon_update_image (status_icon);
2187 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
2189 GtkStatusIconPrivate *priv = status_icon->priv;
2191 if (!priv->blinking_timeout)
2193 gtk_status_icon_blinker (status_icon);
2195 priv->blinking_timeout =
2196 gdk_threads_add_timeout (BLINK_TIMEOUT,
2197 (GSourceFunc) gtk_status_icon_blinker,
2203 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
2205 GtkStatusIconPrivate *priv = status_icon->priv;
2207 if (priv->blinking_timeout)
2209 g_source_remove (priv->blinking_timeout);
2210 priv->blinking_timeout = 0;
2211 priv->blink_off = FALSE;
2213 gtk_status_icon_update_image (status_icon);
2218 * gtk_status_icon_set_visible:
2219 * @status_icon: a #GtkStatusIcon
2220 * @visible: %TRUE to show the status icon, %FALSE to hide it
2222 * Shows or hides a status icon.
2227 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2230 GtkStatusIconPrivate *priv;
2232 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2234 priv = status_icon->priv;
2236 visible = visible != FALSE;
2238 if (priv->visible != visible)
2240 priv->visible = visible;
2242 #ifdef GDK_WINDOWING_X11
2244 gtk_widget_show (priv->tray_icon);
2245 else if (GTK_WIDGET_REALIZED (priv->tray_icon))
2247 gtk_widget_hide (priv->tray_icon);
2248 gtk_widget_unrealize (priv->tray_icon);
2251 #ifdef GDK_WINDOWING_WIN32
2252 if (priv->nid.hWnd != NULL)
2255 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2257 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2260 #ifdef GDK_WINDOWING_QUARTZ
2262 [priv->status_item setVisible:visible];
2263 QUARTZ_POOL_RELEASE;
2265 g_object_notify (G_OBJECT (status_icon), "visible");
2270 * gtk_status_icon_get_visible:
2271 * @status_icon: a #GtkStatusIcon
2273 * Returns whether the status icon is visible or not.
2274 * Note that being visible does not guarantee that
2275 * the user can actually see the icon, see also
2276 * gtk_status_icon_is_embedded().
2278 * Return value: %TRUE if the status icon is visible
2283 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2285 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2287 return status_icon->priv->visible;
2291 * gtk_status_icon_set_blinking:
2292 * @status_icon: a #GtkStatusIcon
2293 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
2295 * Makes the status icon start or stop blinking.
2296 * Note that blinking user interface elements may be problematic
2297 * for some users, and thus may be turned off, in which case
2298 * this setting has no effect.
2303 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
2306 GtkStatusIconPrivate *priv;
2308 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2310 priv = status_icon->priv;
2312 blinking = blinking != FALSE;
2314 if (priv->blinking != blinking)
2316 priv->blinking = blinking;
2319 gtk_status_icon_enable_blinking (status_icon);
2321 gtk_status_icon_disable_blinking (status_icon);
2323 g_object_notify (G_OBJECT (status_icon), "blinking");
2328 * gtk_status_icon_get_blinking:
2329 * @status_icon: a #GtkStatusIcon
2331 * Returns whether the icon is blinking, see
2332 * gtk_status_icon_set_blinking().
2334 * Return value: %TRUE if the icon is blinking
2339 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
2341 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2343 return status_icon->priv->blinking;
2347 * gtk_status_icon_is_embedded:
2348 * @status_icon: a #GtkStatusIcon
2350 * Returns whether the status icon is embedded in a notification
2353 * Return value: %TRUE if the status icon is embedded in
2354 * a notification area.
2359 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2361 #ifdef GDK_WINDOWING_X11
2365 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2367 #ifdef GDK_WINDOWING_X11
2368 plug = GTK_PLUG (status_icon->priv->tray_icon);
2370 if (plug->socket_window)
2375 #ifdef GDK_WINDOWING_WIN32
2378 #ifdef GDK_WINDOWING_QUARTZ
2384 * gtk_status_icon_position_menu:
2385 * @menu: the #GtkMenu
2386 * @x: return location for the x position
2387 * @y: return location for the y position
2388 * @push_in: whether the first menu item should be offset (pushed in) to be
2389 * aligned with the menu popup position (only useful for GtkOptionMenu).
2390 * @user_data: the status icon to position the menu on
2392 * Menu positioning function to use with gtk_menu_popup()
2393 * to position @menu aligned to the status icon @user_data.
2398 gtk_status_icon_position_menu (GtkMenu *menu,
2404 #ifdef GDK_WINDOWING_X11
2405 GtkStatusIcon *status_icon;
2406 GtkStatusIconPrivate *priv;
2407 GtkTrayIcon *tray_icon;
2410 GtkTextDirection direction;
2411 GtkRequisition menu_req;
2412 GdkRectangle monitor;
2413 gint monitor_num, height, width, xoffset, yoffset;
2415 g_return_if_fail (GTK_IS_MENU (menu));
2416 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2418 status_icon = GTK_STATUS_ICON (user_data);
2419 priv = status_icon->priv;
2420 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2421 widget = priv->tray_icon;
2423 direction = gtk_widget_get_direction (widget);
2425 screen = gtk_widget_get_screen (widget);
2426 gtk_menu_set_screen (menu, screen);
2428 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
2429 if (monitor_num < 0)
2431 gtk_menu_set_monitor (menu, monitor_num);
2433 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2435 gdk_window_get_origin (widget->window, x, y);
2437 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2439 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2442 height = widget->allocation.height;
2443 xoffset = widget->allocation.width;
2448 width = widget->allocation.width;
2451 yoffset = widget->allocation.height;
2454 if (direction == GTK_TEXT_DIR_RTL)
2456 if ((*x - (menu_req.width - width)) >= monitor.x)
2457 *x -= menu_req.width - width;
2458 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2460 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2461 *x -= menu_req.width - width;
2467 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2469 else if ((*x - (menu_req.width - width)) >= monitor.x)
2470 *x -= menu_req.width - width;
2471 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2474 *x -= menu_req.width - width;
2477 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2479 else if ((*y - (menu_req.height - height)) >= monitor.y)
2480 *y -= menu_req.height - height;
2481 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2484 *y -= menu_req.height - height;
2487 #endif /* GDK_WINDOWING_X11 */
2489 #ifdef GDK_WINDOWING_WIN32
2490 GtkStatusIcon *status_icon;
2491 GtkStatusIconPrivate *priv;
2493 g_return_if_fail (GTK_IS_MENU (menu));
2494 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2496 status_icon = GTK_STATUS_ICON (user_data);
2497 priv = status_icon->priv;
2499 *x = priv->last_click_x;
2500 *y = priv->last_click_y;
2506 * gtk_status_icon_get_geometry:
2507 * @status_icon: a #GtkStatusIcon
2508 * @screen: return location for the screen, or %NULL if the
2509 * information is not needed
2510 * @area: return location for the area occupied by the status
2512 * @orientation: return location for the orientation of the panel
2513 * in which the status icon is embedded, or %NULL. A panel
2514 * at the top or bottom of the screen is horizontal, a panel
2515 * at the left or right is vertical.
2517 * Obtains information about the location of the status icon
2518 * on screen. This information can be used to e.g. position
2519 * popups like notification bubbles.
2521 * See gtk_status_icon_position_menu() for a more convenient
2522 * alternative for positioning menus.
2524 * Note that some platforms do not allow GTK+ to provide
2525 * this information, and even on platforms that do allow it,
2526 * the information is not reliable unless the status icon
2527 * is embedded in a notification area, see
2528 * gtk_status_icon_is_embedded().
2530 * Return value: %TRUE if the location information has
2536 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2539 GtkOrientation *orientation)
2541 #ifdef GDK_WINDOWING_X11
2543 GtkStatusIconPrivate *priv;
2546 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2548 priv = status_icon->priv;
2549 widget = priv->tray_icon;
2552 *screen = gtk_widget_get_screen (widget);
2556 gdk_window_get_origin (widget->window, &x, &y);
2559 area->width = widget->allocation.width;
2560 area->height = widget->allocation.height;
2564 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2569 #endif /* GDK_WINDOWING_X11 */
2573 * gtk_status_icon_set_has_tooltip:
2574 * @status_icon: a #GtkStatusIcon
2575 * @has_tooltip: whether or not @status_icon has a tooltip
2577 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2578 * See #GtkStatusIcon:has-tooltip for more information.
2583 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2584 gboolean has_tooltip)
2586 GtkStatusIconPrivate *priv;
2588 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2590 priv = status_icon->priv;
2592 #ifdef GDK_WINDOWING_X11
2593 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2595 #ifdef GDK_WINDOWING_WIN32
2596 if (!has_tooltip && priv->tooltip_text)
2597 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2599 #ifdef GDK_WINDOWING_QUARTZ
2600 if (!has_tooltip && priv->tooltip_text)
2601 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2606 * gtk_status_icon_get_has_tooltip:
2607 * @status_icon: a #GtkStatusIcon
2609 * Returns the current value of the has-tooltip property.
2610 * See #GtkStatusIcon:has-tooltip for more information.
2612 * Return value: current value of has-tooltip on @status_icon.
2617 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2619 GtkStatusIconPrivate *priv;
2620 gboolean has_tooltip = FALSE;
2622 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2624 priv = status_icon->priv;
2626 #ifdef GDK_WINDOWING_X11
2627 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2629 #ifdef GDK_WINDOWING_WIN32
2630 has_tooltip = (priv->tooltip_text != NULL);
2632 #ifdef GDK_WINDOWING_QUARTZ
2633 has_tooltip = (priv->tooltip_text != NULL);
2640 * gtk_status_icon_set_tooltip_text:
2641 * @status_icon: a #GtkStatusIcon
2642 * @tooltip_text: the contents of the tooltip for @status_icon
2644 * Sets @tooltip_text as the contents of the tooltip.
2646 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2647 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2650 * See also the #GtkStatusIcon:tooltip-text property and
2651 * gtk_tooltip_set_text().
2656 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2657 const gchar *tooltip_text)
2659 GtkStatusIconPrivate *priv;
2661 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2663 priv = status_icon->priv;
2665 #ifdef GDK_WINDOWING_X11
2667 gtk_widget_set_tooltip_text (priv->tray_icon, tooltip_text);
2670 #ifdef GDK_WINDOWING_WIN32
2671 if (tooltip_text == NULL)
2672 priv->nid.uFlags &= ~NIF_TIP;
2675 WCHAR *wcs = g_utf8_to_utf16 (tooltip_text, -1, NULL, NULL, NULL);
2677 priv->nid.uFlags |= NIF_TIP;
2678 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2679 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2682 if (priv->nid.hWnd != NULL && priv->visible)
2683 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2684 g_warning ("%s:%d:Shell_NotifyIconW(NIM_MODIFY) failed", __FILE__, __LINE__-1);
2686 g_free (priv->tooltip_text);
2687 priv->tooltip_text = g_strdup (tooltip_text);
2689 #ifdef GDK_WINDOWING_QUARTZ
2691 [priv->status_item setToolTip:tooltip_text];
2692 QUARTZ_POOL_RELEASE;
2694 g_free (priv->tooltip_text);
2695 priv->tooltip_text = g_strdup (tooltip_text);
2700 * gtk_status_icon_get_tooltip_text:
2701 * @status_icon: a #GtkStatusIcon
2703 * Gets the contents of the tooltip for @status_icon.
2705 * Return value: the tooltip text, or %NULL. You should free the
2706 * returned string with g_free() when done.
2711 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2713 GtkStatusIconPrivate *priv;
2714 gchar *tooltip_text = NULL;
2716 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2718 priv = status_icon->priv;
2720 #ifdef GDK_WINDOWING_X11
2721 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2723 #ifdef GDK_WINDOWING_WIN32
2724 if (priv->tooltip_text)
2725 tooltip_text = g_strdup (priv->tooltip_text);
2727 #ifdef GDK_WINDOWING_QUARTZ
2728 if (priv->tooltip_text)
2729 tooltip_text = g_strdup (priv->tooltip_text);
2732 return tooltip_text;
2736 * gtk_status_icon_set_tooltip_markup:
2737 * @status_icon: a #GtkStatusIcon
2738 * @markup: the contents of the tooltip for @status_icon, or %NULL
2740 * Sets @markup as the contents of the tooltip, which is marked up with
2741 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2743 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2744 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2746 * See also the #GtkStatusIcon:tooltip-markup property and
2747 * gtk_tooltip_set_markup().
2752 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2753 const gchar *markup)
2755 GtkStatusIconPrivate *priv;
2756 #ifndef GDK_WINDOWING_X11
2760 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2762 priv = status_icon->priv;
2764 #ifdef GDK_WINDOWING_X11
2765 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2767 #ifdef GDK_WINDOWING_WIN32
2769 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2770 gtk_status_icon_set_tooltip_text (status_icon, text);
2773 #ifdef GDK_WINDOWING_QUARTZ
2775 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2776 gtk_status_icon_set_tooltip_text (status_icon, text);
2782 * gtk_status_icon_get_tooltip_markup:
2783 * @status_icon: a #GtkStatusIcon
2785 * Gets the contents of the tooltip for @status_icon.
2787 * Return value: the tooltip text, or %NULL. You should free the
2788 * returned string with g_free() when done.
2793 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2795 GtkStatusIconPrivate *priv;
2796 gchar *markup = NULL;
2798 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2800 priv = status_icon->priv;
2802 #ifdef GDK_WINDOWING_X11
2803 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2805 #ifdef GDK_WINDOWING_WIN32
2806 if (priv->tooltip_text)
2807 markup = g_markup_escape_text (priv->tooltip_text, -1);
2809 #ifdef GDK_WINDOWING_QUARTZ
2810 if (priv->tooltip_text)
2811 markup = g_markup_escape_text (priv->tooltip_text, -1);
2818 * gtk_status_icon_get_x11_window_id:
2819 * @status_icon: a #GtkStatusIcon
2821 * This function is only useful on the X11/freedesktop.org platform.
2822 * It returns a window ID for the widget in the underlying
2823 * status icon implementation. This is useful for the Galago
2824 * notification service, which can send a window ID in the protocol
2825 * in order for the server to position notification windows
2826 * pointing to a status icon reliably.
2828 * This function is not intended for other use cases which are
2829 * more likely to be met by one of the non-X11 specific methods, such
2830 * as gtk_status_icon_position_menu().
2832 * Return value: An 32 bit unsigned integer identifier for the
2833 * underlying X11 Window
2838 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2840 #ifdef GDK_WINDOWING_X11
2841 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2842 return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
2848 #define __GTK_STATUS_ICON_C__
2849 #include "gtkaliasdef.c"