]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusicon.c
146b8f09c956d60415e69777e0e90c7f80479ada
[~andy/gtk] / gtk / gtkstatusicon.c
1 /* gtkstatusicon.c:
2  *
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
7  *
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.
12  *
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.
17  *
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.
22  *
23  * Authors:
24  *      Mark McLoughlin <mark@skynet.ie>
25  *      Hans Breuer <hans@breuer.org>
26  *      Tor Lillqvist <tml@novell.com>
27  *      Mikael Hallendal <micke@imendio.com>
28  */
29
30 #include "config.h"
31 #include <string.h>
32
33 #include "gtkstatusicon.h"
34
35 #include "gtkintl.h"
36 #include "gtkiconfactory.h"
37 #include "gtkmain.h"
38 #include "gtkmarshalers.h"
39 #include "gtktrayicon.h"
40
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
43 #include "gtktooltip.h"
44
45 #ifdef GDK_WINDOWING_X11
46 #include "gdk/x11/gdkx.h"
47 #endif
48
49 #ifdef GDK_WINDOWING_WIN32
50 #include "gtkicontheme.h"
51 #include "gtklabel.h"
52
53 #include "win32/gdkwin32.h"
54 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
55 #endif
56
57 #ifdef GDK_WINDOWING_QUARTZ
58 #include "gtkicontheme.h"
59 #include "gtklabel.h"
60 #endif  
61
62 #include "gdkkeysyms.h"
63
64 #include "gtkalias.h"
65
66 #define BLINK_TIMEOUT 500
67
68 enum
69 {
70   PROP_0,
71   PROP_PIXBUF,
72   PROP_FILE,
73   PROP_STOCK,
74   PROP_ICON_NAME,
75   PROP_GICON,
76   PROP_STORAGE_TYPE,
77   PROP_SIZE,
78   PROP_SCREEN,
79   PROP_VISIBLE,
80   PROP_ORIENTATION,
81   PROP_EMBEDDED,
82   PROP_BLINKING,
83   PROP_HAS_TOOLTIP,
84   PROP_TOOLTIP_TEXT,
85   PROP_TOOLTIP_MARKUP,
86   PROP_TITLE
87 };
88
89 enum 
90 {
91   ACTIVATE_SIGNAL,
92   POPUP_MENU_SIGNAL,
93   SIZE_CHANGED_SIGNAL,
94   BUTTON_PRESS_EVENT_SIGNAL,
95   BUTTON_RELEASE_EVENT_SIGNAL,
96   SCROLL_EVENT_SIGNAL,
97   QUERY_TOOLTIP_SIGNAL,
98   LAST_SIGNAL
99 };
100
101 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
102
103 #ifdef GDK_WINDOWING_QUARTZ
104 #include "gtkstatusicon-quartz.c"
105 #endif
106
107 struct _GtkStatusIconPrivate
108 {
109 #ifdef GDK_WINDOWING_X11
110   GtkWidget    *tray_icon;
111   GtkWidget    *image;
112 #endif
113
114 #ifdef GDK_WINDOWING_WIN32
115   GtkWidget     *dummy_widget;
116   NOTIFYICONDATAW nid;
117   gint          last_click_x, last_click_y;
118   GtkOrientation orientation;
119   gchar         *tooltip_text;
120   gchar         *title;
121 #endif
122         
123 #ifdef GDK_WINDOWING_QUARTZ
124   GtkWidget     *dummy_widget;
125   GtkQuartzStatusIcon *status_item;
126   gchar         *tooltip_text;
127   gchar         *title;
128 #endif
129
130   gint          size;
131
132   gint          image_width;
133   gint          image_height;
134
135   GtkImageType  storage_type;
136
137   union
138     {
139       GdkPixbuf *pixbuf;
140       gchar     *stock_id;
141       gchar     *icon_name;
142       GIcon     *gicon;
143     } image_data;
144
145   GdkPixbuf    *blank_icon;
146   guint         blinking_timeout;
147
148   guint         blinking : 1;
149   guint         blink_off : 1;
150   guint         visible : 1;
151 };
152
153 static GObject* gtk_status_icon_constructor      (GType                  type,
154                                                   guint                  n_construct_properties,
155                                                   GObjectConstructParam *construct_params);
156 static void     gtk_status_icon_finalize         (GObject        *object);
157 static void     gtk_status_icon_set_property     (GObject        *object,
158                                                   guint           prop_id,
159                                                   const GValue   *value,
160                                                   GParamSpec     *pspec);
161 static void     gtk_status_icon_get_property     (GObject        *object,
162                                                   guint           prop_id,
163                                                   GValue         *value,
164                                                   GParamSpec     *pspec);
165
166 #ifdef GDK_WINDOWING_X11
167 static void     gtk_status_icon_size_allocate    (GtkStatusIcon  *status_icon,
168                                                   GtkAllocation  *allocation);
169 static void     gtk_status_icon_screen_changed   (GtkStatusIcon  *status_icon,
170                                                   GdkScreen      *old_screen);
171 static void     gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
172 static void     gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
173 static void     gtk_status_icon_fg_changed       (GtkStatusIcon *status_icon);
174 static void     gtk_status_icon_color_changed    (GtkTrayIcon   *tray,
175                                                   GParamSpec    *pspec,
176                                                   GtkStatusIcon *status_icon);
177 static gboolean gtk_status_icon_scroll           (GtkStatusIcon  *status_icon,
178                                                   GdkEventScroll *event);
179 static gboolean gtk_status_icon_query_tooltip    (GtkStatusIcon *status_icon,
180                                                   gint           x,
181                                                   gint           y,
182                                                   gboolean       keyboard_tip,
183                                                   GtkTooltip    *tooltip);
184
185 static gboolean gtk_status_icon_key_press        (GtkStatusIcon  *status_icon,
186                                                   GdkEventKey    *event);
187 static void     gtk_status_icon_popup_menu       (GtkStatusIcon  *status_icon);
188 #endif
189 static gboolean gtk_status_icon_button_press     (GtkStatusIcon  *status_icon,
190                                                   GdkEventButton *event);
191 static gboolean gtk_status_icon_button_release   (GtkStatusIcon  *status_icon,
192                                                   GdkEventButton *event);
193 static void     gtk_status_icon_disable_blinking (GtkStatusIcon  *status_icon);
194 static void     gtk_status_icon_reset_image_data (GtkStatusIcon  *status_icon);
195 static void     gtk_status_icon_update_image    (GtkStatusIcon *status_icon);
196
197 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
198
199 static void
200 gtk_status_icon_class_init (GtkStatusIconClass *class)
201 {
202   GObjectClass *gobject_class = (GObjectClass *) class;
203
204   gobject_class->constructor  = gtk_status_icon_constructor;
205   gobject_class->finalize     = gtk_status_icon_finalize;
206   gobject_class->set_property = gtk_status_icon_set_property;
207   gobject_class->get_property = gtk_status_icon_get_property;
208
209   class->button_press_event   = NULL;
210   class->button_release_event = NULL;
211   class->scroll_event         = NULL;
212   class->query_tooltip        = NULL;
213
214   g_object_class_install_property (gobject_class,
215                                    PROP_PIXBUF,
216                                    g_param_spec_object ("pixbuf",
217                                                         P_("Pixbuf"),
218                                                         P_("A GdkPixbuf to display"),
219                                                         GDK_TYPE_PIXBUF,
220                                                         GTK_PARAM_READWRITE));
221
222   g_object_class_install_property (gobject_class,
223                                    PROP_FILE,
224                                    g_param_spec_string ("file",
225                                                         P_("Filename"),
226                                                         P_("Filename to load and display"),
227                                                         NULL,
228                                                         GTK_PARAM_WRITABLE));
229
230   g_object_class_install_property (gobject_class,
231                                    PROP_STOCK,
232                                    g_param_spec_string ("stock",
233                                                         P_("Stock ID"),
234                                                         P_("Stock ID for a stock image to display"),
235                                                         NULL,
236                                                         GTK_PARAM_READWRITE));
237   
238   g_object_class_install_property (gobject_class,
239                                    PROP_ICON_NAME,
240                                    g_param_spec_string ("icon-name",
241                                                         P_("Icon Name"),
242                                                         P_("The name of the icon from the icon theme"),
243                                                         NULL,
244                                                         GTK_PARAM_READWRITE));
245
246   /**
247    * GtkStatusIcon:gicon:
248    *
249    * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
250    * the image will be updated automatically if the theme changes.
251    *
252    * Since: 2.14
253    */
254   g_object_class_install_property (gobject_class,
255                                    PROP_GICON,
256                                    g_param_spec_object ("gicon",
257                                                         P_("GIcon"),
258                                                         P_("The GIcon being displayed"),
259                                                         G_TYPE_ICON,
260                                                         GTK_PARAM_READWRITE));
261
262   g_object_class_install_property (gobject_class,
263                                    PROP_STORAGE_TYPE,
264                                    g_param_spec_enum ("storage-type",
265                                                       P_("Storage type"),
266                                                       P_("The representation being used for image data"),
267                                                       GTK_TYPE_IMAGE_TYPE,
268                                                       GTK_IMAGE_EMPTY,
269                                                       GTK_PARAM_READABLE));
270
271   g_object_class_install_property (gobject_class,
272                                    PROP_SIZE,
273                                    g_param_spec_int ("size",
274                                                      P_("Size"),
275                                                      P_("The size of the icon"),
276                                                      0,
277                                                      G_MAXINT,
278                                                      0,
279                                                      GTK_PARAM_READABLE));
280
281   g_object_class_install_property (gobject_class,
282                                    PROP_SCREEN,
283                                    g_param_spec_object ("screen",
284                                                         P_("Screen"),
285                                                         P_("The screen where this status icon will be displayed"),
286                                                         GDK_TYPE_SCREEN,
287                                                         GTK_PARAM_READWRITE));
288
289   g_object_class_install_property (gobject_class,
290                                    PROP_BLINKING,
291                                    g_param_spec_boolean ("blinking",
292                                                          P_("Blinking"),
293                                                          P_("Whether or not the status icon is blinking"),
294                                                          FALSE,
295                                                          GTK_PARAM_READWRITE));
296
297   g_object_class_install_property (gobject_class,
298                                    PROP_VISIBLE,
299                                    g_param_spec_boolean ("visible",
300                                                          P_("Visible"),
301                                                          P_("Whether or not the status icon is visible"),
302                                                          TRUE,
303                                                          GTK_PARAM_READWRITE));
304
305
306   /**
307    * GtkStatusIcon:embedded: 
308    *
309    * %TRUE if the statusicon is embedded in a notification area.
310    *
311    * Since: 2.12
312    */
313   g_object_class_install_property (gobject_class,
314                                    PROP_EMBEDDED,
315                                    g_param_spec_boolean ("embedded",
316                                                          P_("Embedded"),
317                                                          P_("Whether or not the status icon is embedded"),
318                                                          FALSE,
319                                                          GTK_PARAM_READABLE));
320
321   /**
322    * GtkStatusIcon:orientation:
323    *
324    * The orientation of the tray in which the statusicon 
325    * is embedded. 
326    *
327    * Since: 2.12
328    */
329   g_object_class_install_property (gobject_class,
330                                    PROP_ORIENTATION,
331                                    g_param_spec_enum ("orientation",
332                                                       P_("Orientation"),
333                                                       P_("The orientation of the tray"),
334                                                       GTK_TYPE_ORIENTATION,
335                                                       GTK_ORIENTATION_HORIZONTAL,
336                                                       GTK_PARAM_READABLE));
337
338 /**
339  * GtkStatusIcon:has-tooltip:
340  *
341  * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
342  * @status_icon.  A value of %TRUE indicates that @status_icon can have a
343  * tooltip, in this case the status icon will be queried using
344  * #GtkStatusIcon::query-tooltip to determine whether it will provide a
345  * tooltip or not.
346  *
347  * Note that setting this property to %TRUE for the first time will change
348  * the event masks of the windows of this status icon to include leave-notify
349  * and motion-notify events. This will not be undone when the property is set
350  * to %FALSE again.
351  *
352  * Whether this property is respected is platform dependent.
353  * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
354  *
355  * Since: 2.16
356  */
357   g_object_class_install_property (gobject_class,
358                                    PROP_HAS_TOOLTIP,
359                                    g_param_spec_boolean ("has-tooltip",
360                                                          P_("Has tooltip"),
361                                                          P_("Whether this tray icon has a tooltip"),
362                                                          FALSE,
363                                                          GTK_PARAM_READWRITE));
364   /**
365    * GtkStatusIcon:tooltip-text:
366    *
367    * Sets the text of tooltip to be the given string.
368    *
369    * Also see gtk_tooltip_set_text().
370    *
371    * This is a convenience property which will take care of getting the
372    * tooltip shown if the given string is not %NULL.
373    * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
374    * the default handler for the #GtkStatusIcon::query-tooltip signal
375    * will take care of displaying the tooltip.
376    *
377    * Note that some platforms have limitations on the length of tooltips
378    * that they allow on status icons, e.g. Windows only shows the first
379    * 64 characters.
380    *
381    * Since: 2.16
382    */
383   g_object_class_install_property (gobject_class,
384                                    PROP_TOOLTIP_TEXT,
385                                    g_param_spec_string ("tooltip-text",
386                                                         P_("Tooltip Text"),
387                                                         P_("The contents of the tooltip for this widget"),
388                                                         NULL,
389                                                         GTK_PARAM_READWRITE));
390   /**
391    * GtkStatusIcon:tooltip-markup:
392    *
393    * Sets the text of tooltip to be the given string, which is marked up
394    * with the <link linkend="PangoMarkupFormat">Pango text markup 
395    * language</link>. Also see gtk_tooltip_set_markup().
396    *
397    * This is a convenience property which will take care of getting the
398    * tooltip shown if the given string is not %NULL.
399    * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
400    * the default handler for the #GtkStatusIcon::query-tooltip signal
401    * will take care of displaying the tooltip.
402    *
403    * On some platforms, embedded markup will be ignored.
404    *
405    * Since: 2.16
406    */
407   g_object_class_install_property (gobject_class,
408                                    PROP_TOOLTIP_MARKUP,
409                                    g_param_spec_string ("tooltip-markup",
410                                                         P_("Tooltip markup"),
411                                                         P_("The contents of the tooltip for this tray icon"),
412                                                         NULL,
413                                                         GTK_PARAM_READWRITE));
414
415
416   /**
417    * GtkStatusIcon:title:
418    *
419    * The title of this tray icon. This should be a short, human-readable,
420    * localized string describing the tray icon. It may be used by tools
421    * like screen readers to render the tray icon.
422    *
423    * Since: 2.18
424    */
425   g_object_class_install_property (gobject_class,
426                                    PROP_TITLE,
427                                    g_param_spec_string ("title",
428                                                         P_("Title"),
429                                                         P_("The title of this tray icon"),
430                                                         NULL,
431                                                         GTK_PARAM_READWRITE));
432
433   /**
434    * GtkStatusIcon::activate:
435    * @status_icon: the object which received the signal
436    *
437    * Gets emitted when the user activates the status icon. 
438    * If and how status icons can activated is platform-dependent.
439    *
440    * Unlike most G_SIGNAL_ACTION signals, this signal is meant to 
441    * be used by applications and should be wrapped by language bindings.
442    *
443    * Since: 2.10
444    */
445   status_icon_signals [ACTIVATE_SIGNAL] =
446     g_signal_new (I_("activate"),
447                   G_TYPE_FROM_CLASS (gobject_class),
448                   G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
449                   G_STRUCT_OFFSET (GtkStatusIconClass, activate),
450                   NULL,
451                   NULL,
452                   g_cclosure_marshal_VOID__VOID,
453                   G_TYPE_NONE,
454                   0);
455
456   /**
457    * GtkStatusIcon::popup-menu:
458    * @status_icon: the object which received the signal
459    * @button: the button that was pressed, or 0 if the 
460    *   signal is not emitted in response to a button press event
461    * @activate_time: the timestamp of the event that
462    *   triggered the signal emission
463    *
464    * Gets emitted when the user brings up the context menu
465    * of the status icon. Whether status icons can have context 
466    * menus and how these are activated is platform-dependent.
467    *
468    * The @button and @activate_time parameters should be 
469    * passed as the last to arguments to gtk_menu_popup().
470    *
471    * Unlike most G_SIGNAL_ACTION signals, this signal is meant to 
472    * be used by applications and should be wrapped by language bindings.
473    *
474    * Since: 2.10
475    */
476   status_icon_signals [POPUP_MENU_SIGNAL] =
477     g_signal_new (I_("popup-menu"),
478                   G_TYPE_FROM_CLASS (gobject_class),
479                   G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
480                   G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
481                   NULL,
482                   NULL,
483                   _gtk_marshal_VOID__UINT_UINT,
484                   G_TYPE_NONE,
485                   2,
486                   G_TYPE_UINT,
487                   G_TYPE_UINT);
488
489   /**
490    * GtkStatusIcon::size-changed:
491    * @status_icon: the object which received the signal
492    * @size: the new size
493    *
494    * Gets emitted when the size available for the image
495    * changes, e.g. because the notification area got resized.
496    *
497    * Return value: %TRUE if the icon was updated for the new
498    * size. Otherwise, GTK+ will scale the icon as necessary.
499    *
500    * Since: 2.10
501    */
502   status_icon_signals [SIZE_CHANGED_SIGNAL] =
503     g_signal_new (I_("size-changed"),
504                   G_TYPE_FROM_CLASS (gobject_class),
505                   G_SIGNAL_RUN_LAST,
506                   G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
507                   g_signal_accumulator_true_handled,
508                   NULL,
509                   _gtk_marshal_BOOLEAN__INT,
510                   G_TYPE_BOOLEAN,
511                   1,
512                   G_TYPE_INT);
513
514   /**
515    * GtkStatusIcon::button-press-event:
516    * @status_icon: the object which received the signal
517    * @event: the #GdkEventButton which triggered this signal
518    *
519    * The ::button-press-event signal will be emitted when a button
520    * (typically from a mouse) is pressed.
521    *
522    * Whether this event is emitted is platform-dependent.  Use the ::activate
523    * and ::popup-menu signals in preference.
524    *
525    * Return value: %TRUE to stop other handlers from being invoked
526    * for the event. %FALSE to propagate the event further.
527    *
528    * Since: 2.14
529    */
530   status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
531     g_signal_new (I_("button_press_event"),
532                   G_TYPE_FROM_CLASS (gobject_class),
533                   G_SIGNAL_RUN_LAST,
534                   G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
535                   g_signal_accumulator_true_handled, NULL,
536                   _gtk_marshal_BOOLEAN__BOXED,
537                   G_TYPE_BOOLEAN, 1,
538                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
539
540   /**
541    * GtkStatusIcon::button-release-event:
542    * @status_icon: the object which received the signal
543    * @event: the #GdkEventButton which triggered this signal
544    *
545    * The ::button-release-event signal will be emitted when a button
546    * (typically from a mouse) is released.
547    *
548    * Whether this event is emitted is platform-dependent.  Use the ::activate
549    * and ::popup-menu signals in preference.
550    *
551    * Return value: %TRUE to stop other handlers from being invoked
552    * for the event. %FALSE to propagate the event further.
553    *
554    * Since: 2.14
555    */
556   status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
557     g_signal_new (I_("button_release_event"),
558                   G_TYPE_FROM_CLASS (gobject_class),
559                   G_SIGNAL_RUN_LAST,
560                   G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
561                   g_signal_accumulator_true_handled, NULL,
562                   _gtk_marshal_BOOLEAN__BOXED,
563                   G_TYPE_BOOLEAN, 1,
564                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
565
566   /**
567    * GtkStatusIcon::scroll-event:
568    * @status_icon: the object which received the signal.
569    * @event: the #GdkEventScroll which triggered this signal
570    *
571    * The ::scroll-event signal is emitted when a button in the 4 to 7
572    * range is pressed. Wheel mice are usually configured to generate 
573    * button press events for buttons 4 and 5 when the wheel is turned.
574    *
575    * Whether this event is emitted is platform-dependent.
576    *
577    * Returns: %TRUE to stop other handlers from being invoked for the event. 
578    *   %FALSE to propagate the event further.
579    */
580   status_icon_signals[SCROLL_EVENT_SIGNAL] =
581     g_signal_new (I_("scroll_event"),
582                   G_TYPE_FROM_CLASS (gobject_class),
583                   G_SIGNAL_RUN_LAST,
584                   G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
585                   g_signal_accumulator_true_handled, NULL,
586                   _gtk_marshal_BOOLEAN__BOXED,
587                   G_TYPE_BOOLEAN, 1,
588                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
589
590   /**
591    * GtkStatusIcon::query-tooltip:
592    * @status_icon: the object which received the signal
593    * @x: the x coordinate of the cursor position where the request has been
594    *     emitted, relative to @status_icon
595    * @y: the y coordinate of the cursor position where the request has been
596    *     emitted, relative to @status_icon
597    * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
598    * @tooltip: a #GtkTooltip
599    *
600    * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
601    * cursor hovering above @status_icon; or emitted when @status_icon got
602    * focus in keyboard mode.
603    *
604    * Using the given coordinates, the signal handler should determine
605    * whether a tooltip should be shown for @status_icon. If this is
606    * the case %TRUE should be returned, %FALSE otherwise. Note that if
607    * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
608    * should not be used.
609    *
610    * The signal handler is free to manipulate @tooltip with the therefore
611    * destined function calls.
612    *
613    * Whether this signal is emitted is platform-dependent.
614    * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
615    *
616    * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
617    *
618    * Since: 2.16
619    */
620   status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
621     g_signal_new (I_("query_tooltip"),
622                   G_TYPE_FROM_CLASS (gobject_class),
623                   G_SIGNAL_RUN_LAST,
624                   G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
625                   g_signal_accumulator_true_handled, NULL,
626                   _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
627                   G_TYPE_BOOLEAN, 4,
628                   G_TYPE_INT,
629                   G_TYPE_INT,
630                   G_TYPE_BOOLEAN,
631                   GTK_TYPE_TOOLTIP);
632
633   g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
634 }
635
636 #ifdef GDK_WINDOWING_WIN32
637
638 static void
639 build_button_event (GtkStatusIconPrivate *priv,
640                     GdkEventButton       *e,
641                     guint                 button)
642 {
643   POINT pos;
644   GdkRectangle monitor0;
645
646   /* We know that gdk/win32 puts the primary monitor at index 0 */
647   gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
648   e->window = g_object_ref (gdk_get_default_root_window ());
649   e->send_event = TRUE;
650   e->time = GetTickCount ();
651   GetCursorPos (&pos);
652   priv->last_click_x = e->x = pos.x + monitor0.x;
653   priv->last_click_y = e->y = pos.y + monitor0.y;
654   e->axes = NULL;
655   e->state = 0;
656   e->button = button;
657   e->device = gdk_display_get_default ()->core_pointer;
658   e->x_root = e->x;
659   e->y_root = e->y;
660 }
661
662 typedef struct
663 {
664   GtkStatusIcon *status_icon;
665   GdkEventButton *event;
666 } ButtonCallbackData;
667
668 static gboolean
669 button_callback (gpointer data)
670 {
671   ButtonCallbackData *bc = (ButtonCallbackData *) data;
672
673   if (bc->event->type == GDK_BUTTON_PRESS)
674     gtk_status_icon_button_press (bc->status_icon, bc->event);
675   else
676     gtk_status_icon_button_release (bc->status_icon, bc->event);
677
678   gdk_event_free ((GdkEvent *) bc->event);
679   g_free (data);
680
681   return FALSE;
682 }
683
684 static UINT taskbar_created_msg = 0;
685 static GSList *status_icons = NULL;
686
687 static LRESULT CALLBACK
688 wndproc (HWND   hwnd,
689          UINT   message,
690          WPARAM wparam,
691          LPARAM lparam)
692 {
693   if (message == taskbar_created_msg)
694     {
695       GSList *rover;
696
697       for (rover = status_icons; rover != NULL; rover = rover->next)
698         {
699           GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
700           GtkStatusIconPrivate *priv = status_icon->priv;
701
702           priv->nid.hWnd = hwnd;
703           priv->nid.uID = GPOINTER_TO_UINT (status_icon);
704           priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
705           priv->nid.uFlags = NIF_MESSAGE;
706
707           if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
708             {
709               g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
710               priv->nid.hWnd = NULL;
711               continue;
712             }
713
714           gtk_status_icon_update_image (status_icon);
715         }
716       return 0;
717     }
718
719   if (message == WM_GTK_TRAY_NOTIFICATION)
720     {
721       ButtonCallbackData *bc;
722       guint button;
723       
724       switch (lparam)
725         {
726         case WM_LBUTTONDOWN:
727           button = 1;
728           goto buttondown0;
729
730         case WM_MBUTTONDOWN:
731           button = 2;
732           goto buttondown0;
733
734         case WM_RBUTTONDOWN:
735           button = 3;
736           goto buttondown0;
737
738         case WM_XBUTTONDOWN:
739           if (HIWORD (wparam) == XBUTTON1)
740             button = 4;
741           else
742             button = 5;
743
744         buttondown0:
745           bc = g_new (ButtonCallbackData, 1);
746           bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
747           bc->status_icon = GTK_STATUS_ICON (wparam);
748           build_button_event (bc->status_icon->priv, bc->event, button);
749           g_idle_add (button_callback, bc);
750           break;
751
752         case WM_LBUTTONUP:
753           button = 1;
754           goto buttonup0;
755
756         case WM_MBUTTONUP:
757           button = 2;
758           goto buttonup0;
759
760         case WM_RBUTTONUP:
761           button = 3;
762           goto buttonup0;
763
764         case WM_XBUTTONUP:
765           if (HIWORD (wparam) == XBUTTON1)
766             button = 4;
767           else
768             button = 5;
769
770         buttonup0:
771           bc = g_new (ButtonCallbackData, 1);
772           bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
773           bc->status_icon = GTK_STATUS_ICON (wparam);
774           build_button_event (bc->status_icon->priv, bc->event, button);
775           g_idle_add (button_callback, bc);
776           break;
777
778         default :
779           break;
780         }
781         return 0;
782     }
783   else
784     {
785       return DefWindowProc (hwnd, message, wparam, lparam);
786     }
787 }
788
789 static HWND
790 create_tray_observer (void)
791 {
792   WNDCLASS    wclass;
793   static HWND hwnd = NULL;
794   ATOM        klass;
795   HINSTANCE   hmodule = GetModuleHandle (NULL);
796
797   if (hwnd)
798     return hwnd;
799
800   taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
801
802   memset (&wclass, 0, sizeof(WNDCLASS));
803   wclass.lpszClassName = "gtkstatusicon-observer";
804   wclass.lpfnWndProc   = wndproc;
805   wclass.hInstance     = hmodule;
806
807   klass = RegisterClass (&wclass);
808   if (!klass)
809     return NULL;
810
811   hwnd = CreateWindow (MAKEINTRESOURCE (klass),
812                        NULL, WS_POPUP,
813                        0, 0, 1, 1, NULL, NULL,
814                        hmodule, NULL);
815   if (!hwnd)
816     {
817       UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
818       return NULL;
819     }
820
821   return hwnd;
822 }
823
824 #endif
825
826 static void
827 gtk_status_icon_init (GtkStatusIcon *status_icon)
828 {
829   GtkStatusIconPrivate *priv;
830
831   priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
832                                       GtkStatusIconPrivate);
833   status_icon->priv = priv;
834
835   priv->storage_type = GTK_IMAGE_EMPTY;
836   priv->visible      = TRUE;
837
838 #ifdef GDK_WINDOWING_X11
839   priv->size         = 0;
840   priv->image_width  = 0;
841   priv->image_height = 0;
842
843   priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
844
845   gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
846                          GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
847                          GDK_SCROLL_MASK);
848
849   g_signal_connect_swapped (priv->tray_icon, "key-press-event",
850                             G_CALLBACK (gtk_status_icon_key_press), status_icon);
851   g_signal_connect_swapped (priv->tray_icon, "popup-menu",
852                             G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
853   g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
854                             G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
855   g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
856                             G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
857   g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
858                             G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
859   g_signal_connect (priv->tray_icon, "notify::error-color",
860                     G_CALLBACK (gtk_status_icon_color_changed), status_icon);
861   g_signal_connect (priv->tray_icon, "notify::warning-color",
862                     G_CALLBACK (gtk_status_icon_color_changed), status_icon);
863   g_signal_connect (priv->tray_icon, "notify::success-color",
864                     G_CALLBACK (gtk_status_icon_color_changed), status_icon);
865   g_signal_connect_swapped (priv->tray_icon, "button-press-event",
866                             G_CALLBACK (gtk_status_icon_button_press), status_icon);
867   g_signal_connect_swapped (priv->tray_icon, "button-release-event",
868                             G_CALLBACK (gtk_status_icon_button_release), status_icon);
869   g_signal_connect_swapped (priv->tray_icon, "scroll-event",
870                             G_CALLBACK (gtk_status_icon_scroll), status_icon);
871   g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
872                             G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
873   g_signal_connect_swapped (priv->tray_icon, "screen-changed",
874                             G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
875   priv->image = gtk_image_new ();
876   gtk_widget_set_can_focus (priv->image, TRUE);
877   gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
878   gtk_widget_show (priv->image);
879
880   g_signal_connect_swapped (priv->image, "size-allocate",
881                             G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
882
883 #endif
884
885 #ifdef GDK_WINDOWING_WIN32
886
887   /* Get position and orientation of Windows taskbar. */
888   {
889     APPBARDATA abd;
890     
891     abd.cbSize = sizeof (abd);
892     SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
893     if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
894       priv->orientation = GTK_ORIENTATION_VERTICAL;
895     else
896       priv->orientation = GTK_ORIENTATION_HORIZONTAL;
897   }
898
899   priv->last_click_x = priv->last_click_y = 0;
900
901   /* Are the system tray icons always 16 pixels square? */
902   priv->size         = 16;
903   priv->image_width  = 16;
904   priv->image_height = 16;
905
906   priv->dummy_widget = gtk_label_new ("");
907
908   memset (&priv->nid, 0, sizeof (priv->nid));
909
910   priv->nid.hWnd = create_tray_observer ();
911   priv->nid.uID = GPOINTER_TO_UINT (status_icon);
912   priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
913   priv->nid.uFlags = NIF_MESSAGE;
914
915   if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
916     {
917       g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
918       priv->nid.hWnd = NULL;
919     }
920
921   status_icons = g_slist_append (status_icons, status_icon);
922
923 #endif
924         
925 #ifdef GDK_WINDOWING_QUARTZ
926   priv->dummy_widget = gtk_label_new ("");
927
928   QUARTZ_POOL_ALLOC;
929
930   priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
931
932   priv->image_width = priv->image_height = [priv->status_item getHeight];
933   priv->size = priv->image_height;
934
935   QUARTZ_POOL_RELEASE;
936
937 #endif 
938 }
939
940 static GObject*
941 gtk_status_icon_constructor (GType                  type,
942                              guint                  n_construct_properties,
943                              GObjectConstructParam *construct_params)
944 {
945   GObject *object;
946 #ifdef GDK_WINDOWING_X11
947   GtkStatusIcon *status_icon;
948   GtkStatusIconPrivate *priv;
949 #endif
950
951   object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
952                                                                        n_construct_properties,
953                                                                        construct_params);
954
955 #ifdef GDK_WINDOWING_X11
956   status_icon = GTK_STATUS_ICON (object);
957   priv = status_icon->priv;
958   
959   if (priv->visible)
960     gtk_widget_show (priv->tray_icon);
961 #endif
962
963   return object;
964 }
965
966 static void
967 gtk_status_icon_finalize (GObject *object)
968 {
969   GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
970   GtkStatusIconPrivate *priv = status_icon->priv;
971
972   gtk_status_icon_disable_blinking (status_icon);
973   
974   gtk_status_icon_reset_image_data (status_icon);
975
976   if (priv->blank_icon)
977     g_object_unref (priv->blank_icon);
978   priv->blank_icon = NULL;
979
980 #ifdef GDK_WINDOWING_X11
981   g_signal_handlers_disconnect_by_func (priv->tray_icon,
982                                         gtk_status_icon_key_press, status_icon);
983   g_signal_handlers_disconnect_by_func (priv->tray_icon,
984                                         gtk_status_icon_popup_menu, status_icon);
985   g_signal_handlers_disconnect_by_func (priv->tray_icon,
986                                         gtk_status_icon_embedded_changed, status_icon);
987   g_signal_handlers_disconnect_by_func (priv->tray_icon,
988                                         gtk_status_icon_orientation_changed, status_icon);
989   g_signal_handlers_disconnect_by_func (priv->tray_icon,
990                                         gtk_status_icon_fg_changed, status_icon);
991   g_signal_handlers_disconnect_by_func (priv->tray_icon,
992                                         gtk_status_icon_color_changed, status_icon);
993   g_signal_handlers_disconnect_by_func (priv->tray_icon,
994                                         gtk_status_icon_button_press, status_icon);
995   g_signal_handlers_disconnect_by_func (priv->tray_icon,
996                                         gtk_status_icon_button_release, status_icon);
997   g_signal_handlers_disconnect_by_func (priv->tray_icon,
998                                         gtk_status_icon_scroll, status_icon);
999   g_signal_handlers_disconnect_by_func (priv->tray_icon,
1000                                         gtk_status_icon_query_tooltip, status_icon);
1001   g_signal_handlers_disconnect_by_func (priv->tray_icon,
1002                                         gtk_status_icon_screen_changed, status_icon);
1003   gtk_widget_destroy (priv->image);
1004   gtk_widget_destroy (priv->tray_icon);
1005 #endif
1006
1007 #ifdef GDK_WINDOWING_WIN32
1008   if (priv->nid.hWnd != NULL && priv->visible)
1009     Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1010   if (priv->nid.hIcon)
1011     DestroyIcon (priv->nid.hIcon);
1012   g_free (priv->tooltip_text);
1013
1014   gtk_widget_destroy (priv->dummy_widget);
1015
1016   status_icons = g_slist_remove (status_icons, status_icon);
1017 #endif
1018         
1019 #ifdef GDK_WINDOWING_QUARTZ
1020   QUARTZ_POOL_ALLOC;
1021   [priv->status_item release];
1022   QUARTZ_POOL_RELEASE;
1023   g_free (priv->tooltip_text);
1024 #endif
1025
1026   G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1027 }
1028
1029 static void
1030 gtk_status_icon_set_property (GObject      *object,
1031                               guint         prop_id,
1032                               const GValue *value,
1033                               GParamSpec   *pspec)
1034 {
1035   GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1036
1037   switch (prop_id)
1038     {
1039     case PROP_PIXBUF:
1040       gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1041       break;
1042     case PROP_FILE:
1043       gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1044       break;
1045     case PROP_STOCK:
1046       gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1047       break;
1048     case PROP_ICON_NAME:
1049       gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1050       break;
1051     case PROP_GICON:
1052       gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1053       break;
1054     case PROP_SCREEN:
1055       gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1056       break;
1057     case PROP_BLINKING:
1058       gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
1059       break;
1060     case PROP_VISIBLE:
1061       gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1062       break;
1063     case PROP_HAS_TOOLTIP:
1064       gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1065       break;
1066     case PROP_TOOLTIP_TEXT:
1067       gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1068       break;
1069     case PROP_TOOLTIP_MARKUP:
1070       gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1071       break;
1072     case PROP_TITLE:
1073       gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1074       break;
1075     default:
1076       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1077       break;
1078     }
1079 }
1080
1081 static void
1082 gtk_status_icon_get_property (GObject    *object,
1083                               guint       prop_id,
1084                               GValue     *value,
1085                               GParamSpec *pspec)
1086 {
1087   GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1088   GtkStatusIconPrivate *priv = status_icon->priv;
1089
1090   /* The "getter" functions whine if you try to get the wrong
1091    * storage type. This function is instead robust against that,
1092    * so that GUI builders don't have to jump through hoops
1093    * to avoid g_warning
1094    */
1095
1096   switch (prop_id)
1097     {
1098     case PROP_PIXBUF:
1099       if (priv->storage_type != GTK_IMAGE_PIXBUF)
1100         g_value_set_object (value, NULL);
1101       else
1102         g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1103       break;
1104     case PROP_STOCK:
1105       if (priv->storage_type != GTK_IMAGE_STOCK)
1106         g_value_set_string (value, NULL);
1107       else
1108         g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1109       break;
1110     case PROP_ICON_NAME:
1111       if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1112         g_value_set_string (value, NULL);
1113       else
1114         g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1115       break;
1116     case PROP_GICON:
1117       if (priv->storage_type != GTK_IMAGE_GICON)
1118         g_value_set_object (value, NULL);
1119       else
1120         g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1121       break;
1122     case PROP_STORAGE_TYPE:
1123       g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1124       break;
1125     case PROP_SIZE:
1126       g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1127       break;
1128     case PROP_SCREEN:
1129       g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1130       break;
1131     case PROP_BLINKING:
1132       g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
1133       break;
1134     case PROP_VISIBLE:
1135       g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1136       break;
1137     case PROP_EMBEDDED:
1138       g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1139       break;
1140     case PROP_ORIENTATION:
1141 #ifdef GDK_WINDOWING_X11
1142       g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1143 #endif
1144 #ifdef GDK_WINDOWING_WIN32
1145       g_value_set_enum (value, status_icon->priv->orientation);
1146 #endif
1147       break;
1148     case PROP_HAS_TOOLTIP:
1149       g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1150       break;
1151     case PROP_TOOLTIP_TEXT:
1152       g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1153       break;
1154     case PROP_TOOLTIP_MARKUP:
1155       g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1156       break;
1157     case PROP_TITLE:
1158       g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1159       break;
1160     default:
1161       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1162       break;
1163     }
1164 }
1165
1166 /**
1167  * gtk_status_icon_new:
1168  * 
1169  * Creates an empty status icon object.
1170  * 
1171  * Return value: a new #GtkStatusIcon
1172  *
1173  * Since: 2.10
1174  **/
1175 GtkStatusIcon *
1176 gtk_status_icon_new (void)
1177 {
1178   return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1179 }
1180
1181 /**
1182  * gtk_status_icon_new_from_pixbuf:
1183  * @pixbuf: a #GdkPixbuf
1184  * 
1185  * Creates a status icon displaying @pixbuf. 
1186  *
1187  * The image will be scaled down to fit in the available 
1188  * space in the notification area, if necessary.
1189  * 
1190  * Return value: a new #GtkStatusIcon
1191  *
1192  * Since: 2.10
1193  **/
1194 GtkStatusIcon *
1195 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1196 {
1197   return g_object_new (GTK_TYPE_STATUS_ICON,
1198                        "pixbuf", pixbuf,
1199                        NULL);
1200 }
1201
1202 /**
1203  * gtk_status_icon_new_from_file:
1204  * @filename: a filename
1205  * 
1206  * Creates a status icon displaying the file @filename. 
1207  *
1208  * The image will be scaled down to fit in the available 
1209  * space in the notification area, if necessary.
1210  * 
1211  * Return value: a new #GtkStatusIcon
1212  *
1213  * Since: 2.10
1214  **/
1215 GtkStatusIcon *
1216 gtk_status_icon_new_from_file (const gchar *filename)
1217 {
1218   return g_object_new (GTK_TYPE_STATUS_ICON,
1219                        "file", filename,
1220                        NULL);
1221 }
1222
1223 /**
1224  * gtk_status_icon_new_from_stock:
1225  * @stock_id: a stock icon id
1226  * 
1227  * Creates a status icon displaying a stock icon. Sample stock icon
1228  * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your 
1229  * own stock icon names, see gtk_icon_factory_add_default() and 
1230  * gtk_icon_factory_add(). 
1231  *
1232  * Return value: a new #GtkStatusIcon
1233  *
1234  * Since: 2.10
1235  **/
1236 GtkStatusIcon *
1237 gtk_status_icon_new_from_stock (const gchar *stock_id)
1238 {
1239   return g_object_new (GTK_TYPE_STATUS_ICON,
1240                        "stock", stock_id,
1241                        NULL);
1242 }
1243
1244 /**
1245  * gtk_status_icon_new_from_icon_name:
1246  * @icon_name: an icon name
1247  * 
1248  * Creates a status icon displaying an icon from the current icon theme.
1249  * If the current icon theme is changed, the icon will be updated 
1250  * appropriately.
1251  * 
1252  * Return value: a new #GtkStatusIcon
1253  *
1254  * Since: 2.10
1255  **/
1256 GtkStatusIcon *
1257 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1258 {
1259   return g_object_new (GTK_TYPE_STATUS_ICON,
1260                        "icon-name", icon_name,
1261                        NULL);
1262 }
1263
1264 /**
1265  * gtk_status_icon_new_from_gicon:
1266  * @icon: a #GIcon
1267  *
1268  * Creates a status icon displaying a #GIcon. If the icon is a
1269  * themed icon, it will be updated when the theme changes.
1270  *
1271  * Return value: a new #GtkStatusIcon
1272  *
1273  * Since: 2.14
1274  **/
1275 GtkStatusIcon *
1276 gtk_status_icon_new_from_gicon (GIcon *icon)
1277 {
1278   return g_object_new (GTK_TYPE_STATUS_ICON,
1279                        "gicon", icon,
1280                        NULL);
1281 }
1282
1283 static void
1284 emit_activate_signal (GtkStatusIcon *status_icon)
1285 {
1286   g_signal_emit (status_icon,
1287                  status_icon_signals [ACTIVATE_SIGNAL], 0);
1288 }
1289
1290 static void
1291 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1292                         guint          button,
1293                         guint32        activate_time)
1294 {
1295   g_signal_emit (status_icon,
1296                  status_icon_signals [POPUP_MENU_SIGNAL], 0,
1297                  button,
1298                  activate_time);
1299 }
1300
1301 #ifdef GDK_WINDOWING_X11
1302
1303 static gboolean
1304 emit_size_changed_signal (GtkStatusIcon *status_icon,
1305                           gint           size)
1306 {
1307   gboolean handled = FALSE;
1308   
1309   g_signal_emit (status_icon,
1310                  status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1311                  size,
1312                  &handled);
1313
1314   return handled;
1315 }
1316
1317 #endif
1318
1319 static GdkPixbuf *
1320 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
1321 {
1322   GtkStatusIconPrivate *priv = status_icon->priv;
1323
1324   if (priv->blank_icon)
1325     {
1326       gint width, height;
1327
1328       width  = gdk_pixbuf_get_width (priv->blank_icon);
1329       height = gdk_pixbuf_get_height (priv->blank_icon);
1330
1331
1332       if (width == priv->image_width && height == priv->image_height)
1333         return priv->blank_icon;
1334       else
1335         {
1336           g_object_unref (priv->blank_icon);
1337           priv->blank_icon = NULL;
1338         }
1339     }
1340
1341   priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
1342                                      priv->image_width, 
1343                                      priv->image_height);
1344   if (priv->blank_icon)
1345     gdk_pixbuf_fill (priv->blank_icon, 0);
1346
1347   return priv->blank_icon;
1348 }
1349
1350 #ifdef GDK_WINDOWING_X11
1351
1352 static GtkIconSize
1353 find_icon_size (GtkWidget *widget, 
1354                 gint       pixel_size)
1355 {
1356   GdkScreen *screen;
1357   GtkSettings *settings;
1358   GtkIconSize s, size;
1359   gint w, h, d, dist;
1360
1361   screen = gtk_widget_get_screen (widget);
1362
1363   if (!screen)
1364     return GTK_ICON_SIZE_MENU;
1365
1366   settings = gtk_settings_get_for_screen (screen);
1367   
1368   dist = G_MAXINT;
1369   size = GTK_ICON_SIZE_MENU;
1370
1371   for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1372     {
1373       if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1374           w <= pixel_size && h <= pixel_size)
1375         {
1376           d = MAX (pixel_size - w, pixel_size - h);
1377           if (d < dist)
1378             {
1379               dist = d;
1380               size = s;
1381             }
1382         }
1383     }
1384   
1385   return size;
1386 }
1387
1388 #endif
1389
1390 static void
1391 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1392 {
1393   GtkStatusIconPrivate *priv = status_icon->priv;
1394 #ifdef GDK_WINDOWING_WIN32
1395   HICON prev_hicon;
1396 #endif
1397
1398   if (priv->blink_off)
1399     {
1400 #ifdef GDK_WINDOWING_X11
1401       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
1402                                  gtk_status_icon_blank_icon (status_icon));
1403 #endif
1404 #ifdef GDK_WINDOWING_WIN32
1405       prev_hicon = priv->nid.hIcon;
1406       priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
1407       priv->nid.uFlags |= NIF_ICON;
1408       if (priv->nid.hWnd != NULL && priv->visible)
1409         if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1410           g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1411       if (prev_hicon)
1412         DestroyIcon (prev_hicon);
1413 #endif
1414 #ifdef GDK_WINDOWING_QUARTZ
1415       QUARTZ_POOL_ALLOC;
1416       [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
1417       QUARTZ_POOL_RELEASE;
1418 #endif
1419       return;
1420     }
1421
1422   switch (priv->storage_type)
1423     {
1424     case GTK_IMAGE_PIXBUF:
1425       {
1426         GdkPixbuf *pixbuf;
1427
1428         pixbuf = priv->image_data.pixbuf;
1429
1430         if (pixbuf)
1431           {
1432             GdkPixbuf *scaled;
1433             gint size;
1434             gint width;
1435             gint height;
1436
1437             size = priv->size;
1438
1439             width  = gdk_pixbuf_get_width  (pixbuf);
1440             height = gdk_pixbuf_get_height (pixbuf);
1441
1442             if (width > size || height > size)
1443               scaled = gdk_pixbuf_scale_simple (pixbuf,
1444                                                 MIN (size, width),
1445                                                 MIN (size, height),
1446                                                 GDK_INTERP_BILINEAR);
1447             else
1448               scaled = g_object_ref (pixbuf);
1449
1450 #ifdef GDK_WINDOWING_X11
1451             gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1452 #endif
1453 #ifdef GDK_WINDOWING_WIN32
1454             prev_hicon = priv->nid.hIcon;
1455             priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1456             priv->nid.uFlags |= NIF_ICON;
1457             if (priv->nid.hWnd != NULL && priv->visible)
1458               if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1459                   g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1460             if (prev_hicon)
1461               DestroyIcon (prev_hicon);
1462 #endif
1463 #ifdef GDK_WINDOWING_QUARTZ
1464       QUARTZ_POOL_ALLOC;
1465       [priv->status_item setImage:scaled];
1466       QUARTZ_POOL_RELEASE;
1467 #endif
1468                         
1469             g_object_unref (scaled);
1470           }
1471         else
1472           {
1473 #ifdef GDK_WINDOWING_X11
1474             gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1475 #endif
1476 #ifdef GDK_WINDOWING_WIN32
1477             priv->nid.uFlags &= ~NIF_ICON;
1478             if (priv->nid.hWnd != NULL && priv->visible)
1479               if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1480                 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1481 #endif
1482 #ifdef GDK_WINDOWING_QUARTZ
1483       [priv->status_item setImage:NULL];
1484 #endif
1485           }
1486       }
1487       break;
1488
1489     case GTK_IMAGE_STOCK:
1490       {
1491 #ifdef GDK_WINDOWING_X11
1492         GtkIconSize size = find_icon_size (priv->image, priv->size);
1493         gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1494                                   priv->image_data.stock_id,
1495                                   size);
1496 #endif
1497 #ifdef GDK_WINDOWING_WIN32
1498         {
1499           GdkPixbuf *pixbuf =
1500             gtk_widget_render_icon (priv->dummy_widget,
1501                                     priv->image_data.stock_id,
1502                                     GTK_ICON_SIZE_SMALL_TOOLBAR,
1503                                     NULL);
1504
1505           prev_hicon = priv->nid.hIcon;
1506           priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1507           priv->nid.uFlags |= NIF_ICON;
1508           if (priv->nid.hWnd != NULL && priv->visible)
1509             if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1510               g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1511           if (prev_hicon)
1512             DestroyIcon (prev_hicon);
1513           g_object_unref (pixbuf);
1514         }
1515 #endif
1516 #ifdef GDK_WINDOWING_QUARTZ
1517         {
1518           GdkPixbuf *pixbuf;
1519
1520           pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1521                                            priv->image_data.stock_id,
1522                                            GTK_ICON_SIZE_SMALL_TOOLBAR,
1523                                            NULL);
1524           QUARTZ_POOL_ALLOC;
1525           [priv->status_item setImage:pixbuf];
1526           QUARTZ_POOL_RELEASE;
1527           g_object_unref (pixbuf);
1528         }       
1529 #endif
1530       }
1531       break;
1532       
1533     case GTK_IMAGE_ICON_NAME:
1534       {
1535 #ifdef GDK_WINDOWING_X11
1536         GtkIconSize size = find_icon_size (priv->image, priv->size);
1537         gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1538                                       priv->image_data.icon_name,
1539                                       size);
1540 #endif
1541 #ifdef GDK_WINDOWING_WIN32
1542         {
1543           GdkPixbuf *pixbuf =
1544             gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1545                                       priv->image_data.icon_name,
1546                                       priv->size,
1547                                       0, NULL);
1548           
1549           prev_hicon = priv->nid.hIcon;
1550           priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1551           priv->nid.uFlags |= NIF_ICON;
1552           if (priv->nid.hWnd != NULL && priv->visible)
1553             if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1554               g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1555           if (prev_hicon)
1556             DestroyIcon (prev_hicon);
1557           g_object_unref (pixbuf);
1558         }
1559 #endif
1560 #ifdef GDK_WINDOWING_QUARTZ
1561         {
1562           GdkPixbuf *pixbuf;
1563
1564           pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1565                                              priv->image_data.icon_name,
1566                                              priv->size,
1567                                              0, NULL);
1568
1569           QUARTZ_POOL_ALLOC;
1570           [priv->status_item setImage:pixbuf];
1571           QUARTZ_POOL_RELEASE;
1572           g_object_unref (pixbuf);
1573         }
1574 #endif
1575         
1576       }
1577       break;
1578
1579     case GTK_IMAGE_GICON:
1580       {
1581 #ifdef GDK_WINDOWING_X11
1582         GtkIconSize size = find_icon_size (priv->image, priv->size);
1583         gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1584                                   priv->image_data.gicon,
1585                                   size);
1586 #endif
1587 #ifdef GDK_WINDOWING_WIN32
1588       {
1589         GtkIconInfo *info =
1590         gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1591                                         priv->image_data.gicon,
1592                                         priv->size,
1593                                         0);
1594         GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1595
1596         prev_hicon = priv->nid.hIcon;
1597         priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1598         priv->nid.uFlags |= NIF_ICON;
1599         if (priv->nid.hWnd != NULL && priv->visible)
1600           if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1601             g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1602           if (prev_hicon)
1603             DestroyIcon (prev_hicon);
1604           g_object_unref (pixbuf);
1605       }
1606 #endif
1607 #ifdef GDK_WINDOWING_QUARTZ
1608       {
1609         GtkIconInfo *info =
1610         gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1611                                         priv->image_data.gicon,
1612                                         priv->size,
1613                                         0);
1614         GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1615
1616         QUARTZ_POOL_ALLOC;
1617         [priv->status_item setImage:pixbuf];
1618         QUARTZ_POOL_RELEASE;
1619         g_object_unref (pixbuf);
1620       }
1621 #endif
1622
1623       }
1624       break;
1625
1626     case GTK_IMAGE_EMPTY:
1627 #ifdef GDK_WINDOWING_X11
1628       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1629 #endif
1630 #ifdef GDK_WINDOWING_WIN32
1631       priv->nid.uFlags &= ~NIF_ICON;
1632       if (priv->nid.hWnd != NULL && priv->visible)
1633         if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1634           g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1635 #endif
1636 #ifdef GDK_WINDOWING_QUARTZ
1637         {
1638           QUARTZ_POOL_ALLOC;
1639           [priv->status_item setImage:NULL];
1640           QUARTZ_POOL_RELEASE;
1641         }
1642 #endif
1643       break;
1644     default:
1645       g_assert_not_reached ();
1646       break;
1647     }
1648 }
1649
1650 #ifdef GDK_WINDOWING_X11
1651
1652 static void
1653 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1654                                GtkAllocation *allocation)
1655 {
1656   GtkStatusIconPrivate *priv = status_icon->priv;
1657   GtkOrientation orientation;
1658   gint size;
1659
1660   orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1661
1662   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1663     size = allocation->height;
1664   else
1665     size = allocation->width;
1666
1667   priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1668   priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1669
1670   if (priv->size != size)
1671     {
1672       priv->size = size;
1673
1674       g_object_notify (G_OBJECT (status_icon), "size");
1675
1676       if (!emit_size_changed_signal (status_icon, size))
1677         gtk_status_icon_update_image (status_icon);
1678     }
1679 }
1680
1681 static void
1682 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1683                                 GdkScreen *old_screen)
1684 {
1685   GtkStatusIconPrivate *priv = status_icon->priv;
1686
1687   if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1688     {
1689       g_object_notify (G_OBJECT (status_icon), "screen");
1690     }
1691 }
1692
1693 #endif
1694
1695 #ifdef GDK_WINDOWING_X11
1696
1697 static void
1698 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1699 {
1700   g_object_notify (G_OBJECT (status_icon), "embedded");
1701 }
1702
1703 static void
1704 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1705 {
1706   g_object_notify (G_OBJECT (status_icon), "orientation");
1707 }
1708
1709 static void
1710 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1711 {
1712   GtkStatusIconPrivate *priv = status_icon->priv;
1713   GdkColor color;
1714
1715   g_object_get (priv->tray_icon, "fg-color", &color, NULL);
1716   gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
1717 }
1718
1719 static void
1720 gtk_status_icon_color_changed (GtkTrayIcon   *tray,
1721                                GParamSpec    *pspec,
1722                                GtkStatusIcon *status_icon)
1723 {
1724   GtkStatusIconPrivate *priv = status_icon->priv;
1725   const gchar *name;
1726   GdkColor color;
1727
1728   switch (pspec->name[0])
1729     {
1730     case 'e':
1731       name = "error";
1732       break;
1733     case 'w':
1734       name = "warning";
1735       break;
1736     case 's':
1737       name = "success";
1738       break;
1739     default:
1740       name = NULL;
1741       break;
1742     }
1743
1744   if (name)
1745     {
1746       g_object_get (priv->tray_icon, pspec->name, &color, NULL);
1747       gtk_widget_modify_symbolic_color (priv->image, name, &color);
1748     }
1749 }
1750
1751 static gboolean
1752 gtk_status_icon_key_press (GtkStatusIcon  *status_icon,
1753                            GdkEventKey    *event)
1754 {
1755   guint state, keyval;
1756
1757   state = event->state & gtk_accelerator_get_default_mod_mask ();
1758   keyval = event->keyval;
1759   if (state == 0 &&
1760       (keyval == GDK_Return ||
1761        keyval == GDK_KP_Enter ||
1762        keyval == GDK_ISO_Enter ||
1763        keyval == GDK_space ||
1764        keyval == GDK_KP_Space))
1765     {
1766       emit_activate_signal (status_icon);
1767       return TRUE;
1768     }
1769
1770   return FALSE;
1771 }
1772
1773 static void
1774 gtk_status_icon_popup_menu (GtkStatusIcon  *status_icon)
1775 {
1776   emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1777 }
1778
1779 #endif
1780
1781 static gboolean
1782 gtk_status_icon_button_press (GtkStatusIcon  *status_icon,
1783                               GdkEventButton *event)
1784 {
1785   gboolean handled = FALSE;
1786
1787   g_signal_emit (status_icon,
1788                  status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1789                  event, &handled);
1790   if (handled)
1791     return TRUE;
1792
1793   if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1794     {
1795       emit_activate_signal (status_icon);
1796       return TRUE;
1797     }
1798   else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1799     {
1800       emit_popup_menu_signal (status_icon, event->button, event->time);
1801       return TRUE;
1802     }
1803
1804   return FALSE;
1805 }
1806
1807 static gboolean
1808 gtk_status_icon_button_release (GtkStatusIcon  *status_icon,
1809                                 GdkEventButton *event)
1810 {
1811   gboolean handled = FALSE;
1812   g_signal_emit (status_icon,
1813                  status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1814                  event, &handled);
1815   return handled;
1816 }
1817
1818 #ifdef GDK_WINDOWING_X11
1819 static gboolean
1820 gtk_status_icon_scroll (GtkStatusIcon  *status_icon,
1821                         GdkEventScroll *event)
1822 {
1823   gboolean handled = FALSE;
1824   g_signal_emit (status_icon,
1825                  status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1826                  event, &handled);
1827   return handled;
1828 }
1829
1830 static gboolean
1831 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1832                                gint           x,
1833                                gint           y,
1834                                gboolean       keyboard_tip,
1835                                GtkTooltip    *tooltip)
1836 {
1837   gboolean handled = FALSE;
1838   g_signal_emit (status_icon,
1839                  status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1840                  x, y, keyboard_tip, tooltip, &handled);
1841   return handled;
1842 }
1843 #endif /* GDK_WINDOWING_X11 */
1844
1845 static void
1846 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1847 {
1848   GtkStatusIconPrivate *priv = status_icon->priv;
1849
1850   switch (priv->storage_type)
1851   {
1852     case GTK_IMAGE_PIXBUF:
1853       if (priv->image_data.pixbuf)
1854         g_object_unref (priv->image_data.pixbuf);
1855       priv->image_data.pixbuf = NULL;
1856       g_object_notify (G_OBJECT (status_icon), "pixbuf");
1857       break;
1858
1859     case GTK_IMAGE_STOCK:
1860       g_free (priv->image_data.stock_id);
1861       priv->image_data.stock_id = NULL;
1862
1863       g_object_notify (G_OBJECT (status_icon), "stock");
1864       break;
1865       
1866     case GTK_IMAGE_ICON_NAME:
1867       g_free (priv->image_data.icon_name);
1868       priv->image_data.icon_name = NULL;
1869
1870       g_object_notify (G_OBJECT (status_icon), "icon-name");
1871       break;
1872
1873     case GTK_IMAGE_GICON:
1874       if (priv->image_data.gicon)
1875         g_object_unref (priv->image_data.gicon);
1876       priv->image_data.gicon = NULL;
1877
1878       g_object_notify (G_OBJECT (status_icon), "gicon");
1879       break;
1880
1881     case GTK_IMAGE_EMPTY:
1882       break;
1883     default:
1884       g_assert_not_reached ();
1885       break;
1886   }
1887
1888   priv->storage_type = GTK_IMAGE_EMPTY;
1889   g_object_notify (G_OBJECT (status_icon), "storage-type");
1890 }
1891
1892 static void
1893 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1894                            GtkImageType   storage_type,
1895                            gpointer       data)
1896 {
1897   GtkStatusIconPrivate *priv = status_icon->priv;
1898
1899   g_object_freeze_notify (G_OBJECT (status_icon));
1900
1901   gtk_status_icon_reset_image_data (status_icon);
1902
1903   priv->storage_type = storage_type;
1904   g_object_notify (G_OBJECT (status_icon), "storage-type");
1905
1906   switch (storage_type) 
1907     {
1908     case GTK_IMAGE_PIXBUF:
1909       priv->image_data.pixbuf = (GdkPixbuf *)data;
1910       g_object_notify (G_OBJECT (status_icon), "pixbuf");
1911       break;
1912     case GTK_IMAGE_STOCK:
1913       priv->image_data.stock_id = g_strdup ((const gchar *)data);
1914       g_object_notify (G_OBJECT (status_icon), "stock");
1915       break;
1916     case GTK_IMAGE_ICON_NAME:
1917       priv->image_data.icon_name = g_strdup ((const gchar *)data);
1918       g_object_notify (G_OBJECT (status_icon), "icon-name");
1919       break;
1920     case GTK_IMAGE_GICON:
1921       priv->image_data.gicon = (GIcon *)data;
1922       g_object_notify (G_OBJECT (status_icon), "gicon");
1923       break;
1924     default:
1925       g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1926     }
1927
1928   g_object_thaw_notify (G_OBJECT (status_icon));
1929
1930   gtk_status_icon_update_image (status_icon);
1931 }
1932
1933 /**
1934  * gtk_status_icon_set_from_pixbuf:
1935  * @status_icon: a #GtkStatusIcon
1936  * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1937  *
1938  * Makes @status_icon display @pixbuf.
1939  * See gtk_status_icon_new_from_pixbuf() for details.
1940  *
1941  * Since: 2.10
1942  **/
1943 void
1944 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1945                                  GdkPixbuf     *pixbuf)
1946 {
1947   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1948   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1949
1950   if (pixbuf)
1951     g_object_ref (pixbuf);
1952
1953   gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1954                              (gpointer) pixbuf);
1955 }
1956
1957 /**
1958  * gtk_status_icon_set_from_file:
1959  * @status_icon: a #GtkStatusIcon
1960  * @filename: a filename
1961  * 
1962  * Makes @status_icon display the file @filename.
1963  * See gtk_status_icon_new_from_file() for details.
1964  *
1965  * Since: 2.10 
1966  **/
1967 void
1968 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1969                                const gchar   *filename)
1970 {
1971   GdkPixbuf *pixbuf;
1972   
1973   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1974   g_return_if_fail (filename != NULL);
1975   
1976   pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1977   
1978   gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1979   
1980   if (pixbuf)
1981     g_object_unref (pixbuf);
1982 }
1983
1984 /**
1985  * gtk_status_icon_set_from_stock:
1986  * @status_icon: a #GtkStatusIcon
1987  * @stock_id: a stock icon id
1988  * 
1989  * Makes @status_icon display the stock icon with the id @stock_id.
1990  * See gtk_status_icon_new_from_stock() for details.
1991  *
1992  * Since: 2.10 
1993  **/
1994 void
1995 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1996                                 const gchar   *stock_id)
1997 {
1998   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1999   g_return_if_fail (stock_id != NULL);
2000
2001   gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
2002                              (gpointer) stock_id);
2003 }
2004
2005 /**
2006  * gtk_status_icon_set_from_icon_name:
2007  * @status_icon: a #GtkStatusIcon
2008  * @icon_name: an icon name
2009  * 
2010  * Makes @status_icon display the icon named @icon_name from the 
2011  * current icon theme.
2012  * See gtk_status_icon_new_from_icon_name() for details.
2013  *
2014  * Since: 2.10 
2015  **/
2016 void
2017 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
2018                                     const gchar   *icon_name)
2019 {
2020   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2021   g_return_if_fail (icon_name != NULL);
2022
2023   gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
2024                              (gpointer) icon_name);
2025 }
2026
2027 /**
2028  * gtk_status_icon_set_from_gicon:
2029  * @status_icon: a #GtkStatusIcon
2030  * @icon: a GIcon
2031  *
2032  * Makes @status_icon display the #GIcon.
2033  * See gtk_status_icon_new_from_gicon() for details.
2034  *
2035  * Since: 2.14
2036  **/
2037 void
2038 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
2039                                 GIcon         *icon)
2040 {
2041   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2042   g_return_if_fail (icon != NULL);
2043
2044   if (icon)
2045     g_object_ref (icon);
2046
2047   gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
2048                              (gpointer) icon);
2049 }
2050
2051 /**
2052  * gtk_status_icon_get_storage_type:
2053  * @status_icon: a #GtkStatusIcon
2054  * 
2055  * Gets the type of representation being used by the #GtkStatusIcon
2056  * to store image data. If the #GtkStatusIcon has no image data,
2057  * the return value will be %GTK_IMAGE_EMPTY. 
2058  * 
2059  * Return value: the image representation being used
2060  *
2061  * Since: 2.10
2062  **/
2063 GtkImageType
2064 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2065 {
2066   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2067
2068   return status_icon->priv->storage_type;
2069 }
2070 /**
2071  * gtk_status_icon_get_pixbuf:
2072  * @status_icon: a #GtkStatusIcon
2073  * 
2074  * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2075  * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2076  * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2077  * The caller of this function does not own a reference to the
2078  * returned pixbuf.
2079  * 
2080  * Return value: the displayed pixbuf, or %NULL if the image is empty.
2081  *
2082  * Since: 2.10
2083  **/
2084 GdkPixbuf *
2085 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2086 {
2087   GtkStatusIconPrivate *priv;
2088
2089   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2090
2091   priv = status_icon->priv;
2092
2093   g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2094                         priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2095
2096   if (priv->storage_type == GTK_IMAGE_EMPTY)
2097     priv->image_data.pixbuf = NULL;
2098
2099   return priv->image_data.pixbuf;
2100 }
2101
2102 /**
2103  * gtk_status_icon_get_stock:
2104  * @status_icon: a #GtkStatusIcon
2105  * 
2106  * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2107  * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2108  * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2109  * The returned string is owned by the #GtkStatusIcon and should not
2110  * be freed or modified.
2111  * 
2112  * Return value: stock id of the displayed stock icon,
2113  *   or %NULL if the image is empty.
2114  *
2115  * Since: 2.10
2116  **/
2117 G_CONST_RETURN gchar *
2118 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2119 {
2120   GtkStatusIconPrivate *priv;
2121
2122   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2123
2124   priv = status_icon->priv;
2125
2126   g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2127                         priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2128   
2129   if (priv->storage_type == GTK_IMAGE_EMPTY)
2130     priv->image_data.stock_id = NULL;
2131
2132   return priv->image_data.stock_id;
2133 }
2134
2135 /**
2136  * gtk_status_icon_get_icon_name:
2137  * @status_icon: a #GtkStatusIcon
2138  * 
2139  * Gets the name of the icon being displayed by the #GtkStatusIcon.
2140  * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2141  * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2142  * The returned string is owned by the #GtkStatusIcon and should not
2143  * be freed or modified.
2144  * 
2145  * Return value: name of the displayed icon, or %NULL if the image is empty.
2146  *
2147  * Since: 2.10
2148  **/
2149 G_CONST_RETURN gchar *
2150 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2151 {
2152   GtkStatusIconPrivate *priv;
2153   
2154   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2155
2156   priv = status_icon->priv;
2157
2158   g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2159                         priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2160
2161   if (priv->storage_type == GTK_IMAGE_EMPTY)
2162     priv->image_data.icon_name = NULL;
2163
2164   return priv->image_data.icon_name;
2165 }
2166
2167 /**
2168  * gtk_status_icon_get_gicon:
2169  * @status_icon: a #GtkStatusIcon
2170  *
2171  * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2172  * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2173  * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2174  * The caller of this function does not own a reference to the
2175  * returned #GIcon.
2176  *
2177  * If this function fails, @icon is left unchanged;
2178  *
2179  * Returns: the displayed icon, or %NULL if the image is empty
2180  *
2181  * Since: 2.14
2182  **/
2183 GIcon *
2184 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2185 {
2186   GtkStatusIconPrivate *priv;
2187
2188   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2189
2190   priv = status_icon->priv;
2191
2192   g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2193                         priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2194
2195   if (priv->storage_type == GTK_IMAGE_EMPTY)
2196     priv->image_data.gicon = NULL;
2197
2198   return priv->image_data.gicon;
2199 }
2200
2201 /**
2202  * gtk_status_icon_get_size:
2203  * @status_icon: a #GtkStatusIcon
2204  * 
2205  * Gets the size in pixels that is available for the image. 
2206  * Stock icons and named icons adapt their size automatically
2207  * if the size of the notification area changes. For other
2208  * storage types, the size-changed signal can be used to
2209  * react to size changes.
2210  *
2211  * Note that the returned size is only meaningful while the 
2212  * status icon is embedded (see gtk_status_icon_is_embedded()).
2213  * 
2214  * Return value: the size that is available for the image
2215  *
2216  * Since: 2.10
2217  **/
2218 gint
2219 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2220 {
2221   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2222
2223   return status_icon->priv->size;
2224 }
2225
2226 /**
2227  * gtk_status_icon_set_screen:
2228  * @status_icon: a #GtkStatusIcon
2229  * @screen: a #GdkScreen
2230  *
2231  * Sets the #GdkScreen where @status_icon is displayed; if
2232  * the icon is already mapped, it will be unmapped, and
2233  * then remapped on the new screen.
2234  *
2235  * Since: 2.12
2236  */
2237 void
2238 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2239                             GdkScreen     *screen)
2240 {
2241   g_return_if_fail (GDK_IS_SCREEN (screen));
2242
2243 #ifdef GDK_WINDOWING_X11
2244   gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2245 #endif
2246 }
2247
2248 /** 
2249  * gtk_status_icon_get_screen:
2250  * @status_icon: a #GtkStatusIcon
2251  *
2252  * Returns the #GdkScreen associated with @status_icon.
2253  *
2254  * Return value: a #GdkScreen.
2255  *
2256  * Since: 2.12
2257  */
2258 GdkScreen *
2259 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2260 {
2261   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2262
2263 #ifdef GDK_WINDOWING_X11   
2264   return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2265 #else
2266   return gdk_screen_get_default ();
2267 #endif
2268 }
2269
2270 /**
2271  * gtk_status_icon_set_tooltip:
2272  * @status_icon: a #GtkStatusIcon
2273  * @tooltip_text: (allow-none): the tooltip text, or %NULL
2274  *
2275  * Sets the tooltip of the status icon.
2276  *
2277  * Since: 2.10
2278  *
2279  * Deprecated: 2.16: Use gtk_status_icon_set_tooltip_text() instead.
2280  */
2281 void
2282 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
2283                              const gchar   *tooltip_text)
2284 {
2285   gtk_status_icon_set_tooltip_text (status_icon, tooltip_text);
2286 }
2287
2288 static gboolean
2289 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
2290 {
2291   GtkStatusIconPrivate *priv = status_icon->priv;
2292   
2293   priv->blink_off = !priv->blink_off;
2294
2295   gtk_status_icon_update_image (status_icon);
2296
2297   return TRUE;
2298 }
2299
2300 static void
2301 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
2302 {
2303   GtkStatusIconPrivate *priv = status_icon->priv;
2304   
2305   if (!priv->blinking_timeout)
2306     {
2307       gtk_status_icon_blinker (status_icon);
2308
2309       priv->blinking_timeout =
2310         gdk_threads_add_timeout (BLINK_TIMEOUT, 
2311                        (GSourceFunc) gtk_status_icon_blinker, 
2312                        status_icon);
2313     }
2314 }
2315
2316 static void
2317 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
2318 {
2319   GtkStatusIconPrivate *priv = status_icon->priv;
2320   
2321   if (priv->blinking_timeout)
2322     {
2323       g_source_remove (priv->blinking_timeout);
2324       priv->blinking_timeout = 0;
2325       priv->blink_off = FALSE;
2326
2327       gtk_status_icon_update_image (status_icon);
2328     }
2329 }
2330
2331 /**
2332  * gtk_status_icon_set_visible:
2333  * @status_icon: a #GtkStatusIcon
2334  * @visible: %TRUE to show the status icon, %FALSE to hide it
2335  * 
2336  * Shows or hides a status icon.
2337  *
2338  * Since: 2.10
2339  **/
2340 void
2341 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2342                              gboolean       visible)
2343 {
2344   GtkStatusIconPrivate *priv;
2345
2346   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2347
2348   priv = status_icon->priv;
2349
2350   visible = visible != FALSE;
2351
2352   if (priv->visible != visible)
2353     {
2354       priv->visible = visible;
2355
2356 #ifdef GDK_WINDOWING_X11
2357       if (visible)
2358         gtk_widget_show (priv->tray_icon);
2359       else if (gtk_widget_get_realized (priv->tray_icon))
2360         {
2361           gtk_widget_hide (priv->tray_icon);
2362           gtk_widget_unrealize (priv->tray_icon);
2363         }
2364 #endif
2365 #ifdef GDK_WINDOWING_WIN32
2366       if (priv->nid.hWnd != NULL)
2367         {
2368           if (visible)
2369             Shell_NotifyIconW (NIM_ADD, &priv->nid);
2370           else
2371             Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2372         }
2373 #endif
2374 #ifdef GDK_WINDOWING_QUARTZ
2375       QUARTZ_POOL_ALLOC;
2376       [priv->status_item setVisible:visible];
2377       QUARTZ_POOL_RELEASE;
2378 #endif
2379       g_object_notify (G_OBJECT (status_icon), "visible");
2380     }
2381 }
2382
2383 /**
2384  * gtk_status_icon_get_visible:
2385  * @status_icon: a #GtkStatusIcon
2386  * 
2387  * Returns whether the status icon is visible or not. 
2388  * Note that being visible does not guarantee that 
2389  * the user can actually see the icon, see also 
2390  * gtk_status_icon_is_embedded().
2391  * 
2392  * Return value: %TRUE if the status icon is visible
2393  *
2394  * Since: 2.10
2395  **/
2396 gboolean
2397 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2398 {
2399   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2400
2401   return status_icon->priv->visible;
2402 }
2403
2404 /**
2405  * gtk_status_icon_set_blinking:
2406  * @status_icon: a #GtkStatusIcon
2407  * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
2408  * 
2409  * Makes the status icon start or stop blinking. 
2410  * Note that blinking user interface elements may be problematic
2411  * for some users, and thus may be turned off, in which case
2412  * this setting has no effect.
2413  *
2414  * Since: 2.10
2415  **/
2416 void
2417 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
2418                               gboolean       blinking)
2419 {
2420   GtkStatusIconPrivate *priv;
2421
2422   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2423
2424   priv = status_icon->priv;
2425
2426   blinking = blinking != FALSE;
2427
2428   if (priv->blinking != blinking)
2429     {
2430       priv->blinking = blinking;
2431
2432       if (blinking)
2433         gtk_status_icon_enable_blinking (status_icon);
2434       else
2435         gtk_status_icon_disable_blinking (status_icon);
2436
2437       g_object_notify (G_OBJECT (status_icon), "blinking");
2438     }
2439 }
2440
2441 /**
2442  * gtk_status_icon_get_blinking:
2443  * @status_icon: a #GtkStatusIcon
2444  * 
2445  * Returns whether the icon is blinking, see 
2446  * gtk_status_icon_set_blinking().
2447  * 
2448  * Return value: %TRUE if the icon is blinking
2449  *
2450  * Since: 2.10
2451  **/
2452 gboolean
2453 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
2454 {
2455   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2456
2457   return status_icon->priv->blinking;
2458 }
2459
2460 /**
2461  * gtk_status_icon_is_embedded:
2462  * @status_icon: a #GtkStatusIcon
2463  * 
2464  * Returns whether the status icon is embedded in a notification
2465  * area. 
2466  * 
2467  * Return value: %TRUE if the status icon is embedded in
2468  *   a notification area.
2469  *
2470  * Since: 2.10
2471  **/
2472 gboolean
2473 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2474 {
2475 #ifdef GDK_WINDOWING_X11
2476   GtkPlug *plug;
2477 #endif
2478
2479   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2480
2481 #ifdef GDK_WINDOWING_X11
2482   plug = GTK_PLUG (status_icon->priv->tray_icon);
2483
2484   if (plug->socket_window)
2485     return TRUE;
2486   else
2487     return FALSE;
2488 #endif
2489 #ifdef GDK_WINDOWING_WIN32
2490   return TRUE;
2491 #endif
2492 #ifdef GDK_WINDOWING_QUARTZ
2493   return TRUE;
2494 #endif
2495 }
2496
2497 /**
2498  * gtk_status_icon_position_menu:
2499  * @menu: the #GtkMenu
2500  * @x: return location for the x position
2501  * @y: return location for the y position
2502  * @push_in: whether the first menu item should be offset (pushed in) to be
2503  *           aligned with the menu popup position (only useful for GtkOptionMenu).
2504  * @user_data: the status icon to position the menu on
2505  *
2506  * Menu positioning function to use with gtk_menu_popup()
2507  * to position @menu aligned to the status icon @user_data.
2508  * 
2509  * Since: 2.10
2510  **/
2511 void
2512 gtk_status_icon_position_menu (GtkMenu  *menu,
2513                                gint     *x,
2514                                gint     *y,
2515                                gboolean *push_in,
2516                                gpointer  user_data)
2517 {
2518 #ifdef GDK_WINDOWING_X11
2519   GtkStatusIcon *status_icon;
2520   GtkStatusIconPrivate *priv;
2521   GtkTrayIcon *tray_icon;
2522   GtkWidget *widget;
2523   GdkScreen *screen;
2524   GtkTextDirection direction;
2525   GtkRequisition menu_req;
2526   GdkRectangle monitor;
2527   gint monitor_num, height, width, xoffset, yoffset;
2528   
2529   g_return_if_fail (GTK_IS_MENU (menu));
2530   g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2531
2532   status_icon = GTK_STATUS_ICON (user_data);
2533   priv = status_icon->priv;
2534   tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2535   widget = priv->tray_icon;
2536
2537   direction = gtk_widget_get_direction (widget);
2538
2539   screen = gtk_widget_get_screen (widget);
2540   gtk_menu_set_screen (menu, screen);
2541
2542   monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
2543   if (monitor_num < 0)
2544     monitor_num = 0;
2545   gtk_menu_set_monitor (menu, monitor_num);
2546
2547   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2548
2549   gdk_window_get_origin (widget->window, x, y);
2550   
2551   gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2552
2553   if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2554     {
2555       width = 0;
2556       height = widget->allocation.height;
2557       xoffset = widget->allocation.width;
2558       yoffset = 0;
2559     }
2560   else
2561     {
2562       width = widget->allocation.width;
2563       height = 0;
2564       xoffset = 0;
2565       yoffset = widget->allocation.height;
2566     }
2567
2568   if (direction == GTK_TEXT_DIR_RTL)
2569     {
2570       if ((*x - (menu_req.width - width)) >= monitor.x)
2571         *x -= menu_req.width - width;
2572       else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2573         *x += xoffset;
2574       else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2575         *x -= menu_req.width - width;
2576       else
2577         *x += xoffset;
2578     }
2579   else
2580     {
2581       if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2582         *x += xoffset;
2583       else if ((*x - (menu_req.width - width)) >= monitor.x)
2584         *x -= menu_req.width - width;
2585       else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2586         *x += xoffset;
2587       else 
2588         *x -= menu_req.width - width;
2589     }
2590
2591   if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2592     *y += yoffset;
2593   else if ((*y - (menu_req.height - height)) >= monitor.y)
2594     *y -= menu_req.height - height;
2595   else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2596     *y += yoffset;
2597   else 
2598     *y -= menu_req.height - height;
2599
2600   *push_in = FALSE;
2601 #endif /* GDK_WINDOWING_X11 */
2602
2603 #ifdef GDK_WINDOWING_WIN32
2604   GtkStatusIcon *status_icon;
2605   GtkStatusIconPrivate *priv;
2606   
2607   g_return_if_fail (GTK_IS_MENU (menu));
2608   g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2609
2610   status_icon = GTK_STATUS_ICON (user_data);
2611   priv = status_icon->priv;
2612
2613   *x = priv->last_click_x;
2614   *y = priv->last_click_y;
2615   *push_in = TRUE;
2616 #endif
2617 }
2618
2619 /**
2620  * gtk_status_icon_get_geometry:
2621  * @status_icon: a #GtkStatusIcon
2622  * @screen: (out) (transfer none) (allow-none): return location for the screen, or %NULL if the
2623  *          information is not needed
2624  * @area: (out) (allow-none): return location for the area occupied by the status
2625  *        icon, or %NULL
2626  * @orientation: (out) (allow-none): return location for the orientation of the panel
2627  *    in which the status icon is embedded, or %NULL. A panel
2628  *    at the top or bottom of the screen is horizontal, a panel
2629  *    at the left or right is vertical.
2630  *
2631  * Obtains information about the location of the status icon
2632  * on screen. This information can be used to e.g. position 
2633  * popups like notification bubbles. 
2634  *
2635  * See gtk_status_icon_position_menu() for a more convenient 
2636  * alternative for positioning menus.
2637  *
2638  * Note that some platforms do not allow GTK+ to provide 
2639  * this information, and even on platforms that do allow it,
2640  * the information is not reliable unless the status icon
2641  * is embedded in a notification area, see
2642  * gtk_status_icon_is_embedded().
2643  *
2644  * Return value: %TRUE if the location information has 
2645  *               been filled in
2646  *
2647  * Since: 2.10
2648  */
2649 gboolean  
2650 gtk_status_icon_get_geometry (GtkStatusIcon    *status_icon,
2651                               GdkScreen       **screen,
2652                               GdkRectangle     *area,
2653                               GtkOrientation   *orientation)
2654 {
2655 #ifdef GDK_WINDOWING_X11   
2656   GtkWidget *widget;
2657   GtkStatusIconPrivate *priv;
2658   gint x, y;
2659
2660   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2661
2662   priv = status_icon->priv;
2663   widget = priv->tray_icon;
2664
2665   if (screen)
2666     *screen = gtk_widget_get_screen (widget);
2667
2668   if (area)
2669     {
2670       gdk_window_get_origin (widget->window, &x, &y);
2671       area->x = x;
2672       area->y = y;
2673       area->width = widget->allocation.width;
2674       area->height = widget->allocation.height;
2675     }
2676
2677   if (orientation)
2678     *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2679
2680   return TRUE;
2681 #else
2682   return FALSE;
2683 #endif /* GDK_WINDOWING_X11 */
2684 }
2685
2686 /**
2687  * gtk_status_icon_set_has_tooltip:
2688  * @status_icon: a #GtkStatusIcon
2689  * @has_tooltip: whether or not @status_icon has a tooltip
2690  *
2691  * Sets the has-tooltip property on @status_icon to @has_tooltip.
2692  * See #GtkStatusIcon:has-tooltip for more information.
2693  *
2694  * Since: 2.16
2695  */
2696 void
2697 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2698                                  gboolean       has_tooltip)
2699 {
2700   GtkStatusIconPrivate *priv;
2701
2702   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2703
2704   priv = status_icon->priv;
2705
2706 #ifdef GDK_WINDOWING_X11
2707   gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2708 #endif
2709 #ifdef GDK_WINDOWING_WIN32
2710   if (!has_tooltip && priv->tooltip_text)
2711     gtk_status_icon_set_tooltip_text (status_icon, NULL);
2712 #endif
2713 #ifdef GDK_WINDOWING_QUARTZ
2714   if (!has_tooltip && priv->tooltip_text)
2715     gtk_status_icon_set_tooltip_text (status_icon, NULL);
2716 #endif
2717 }
2718
2719 /**
2720  * gtk_status_icon_get_has_tooltip:
2721  * @status_icon: a #GtkStatusIcon
2722  *
2723  * Returns the current value of the has-tooltip property.
2724  * See #GtkStatusIcon:has-tooltip for more information.
2725  *
2726  * Return value: current value of has-tooltip on @status_icon.
2727  *
2728  * Since: 2.16
2729  */
2730 gboolean
2731 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2732 {
2733   GtkStatusIconPrivate *priv;
2734   gboolean has_tooltip = FALSE;
2735
2736   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2737
2738   priv = status_icon->priv;
2739
2740 #ifdef GDK_WINDOWING_X11
2741   has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2742 #endif
2743 #ifdef GDK_WINDOWING_WIN32
2744   has_tooltip = (priv->tooltip_text != NULL);
2745 #endif
2746 #ifdef GDK_WINDOWING_QUARTZ
2747   has_tooltip = (priv->tooltip_text != NULL);
2748 #endif
2749
2750   return has_tooltip;
2751 }
2752
2753 /**
2754  * gtk_status_icon_set_tooltip_text:
2755  * @status_icon: a #GtkStatusIcon
2756  * @text: the contents of the tooltip for @status_icon
2757  *
2758  * Sets @text as the contents of the tooltip.
2759  *
2760  * This function will take care of setting #GtkStatusIcon:has-tooltip to
2761  * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2762  * signal.
2763  *
2764  * See also the #GtkStatusIcon:tooltip-text property and
2765  * gtk_tooltip_set_text().
2766  *
2767  * Since: 2.16
2768  */
2769 void
2770 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2771                                   const gchar   *text)
2772 {
2773   GtkStatusIconPrivate *priv;
2774
2775   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2776
2777   priv = status_icon->priv;
2778
2779 #ifdef GDK_WINDOWING_X11
2780
2781   gtk_widget_set_tooltip_text (priv->tray_icon, text);
2782
2783 #endif
2784 #ifdef GDK_WINDOWING_WIN32
2785   if (text == NULL)
2786     priv->nid.uFlags &= ~NIF_TIP;
2787   else
2788     {
2789       WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2790
2791       priv->nid.uFlags |= NIF_TIP;
2792       wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2793       priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2794       g_free (wcs);
2795     }
2796   if (priv->nid.hWnd != NULL && priv->visible)
2797     if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2798       g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2799
2800   g_free (priv->tooltip_text);
2801   priv->tooltip_text = g_strdup (text);
2802 #endif
2803 #ifdef GDK_WINDOWING_QUARTZ
2804   QUARTZ_POOL_ALLOC;
2805   [priv->status_item setToolTip:text];
2806   QUARTZ_POOL_RELEASE;
2807
2808   g_free (priv->tooltip_text);
2809   priv->tooltip_text = g_strdup (text);
2810 #endif
2811 }
2812
2813 /**
2814  * gtk_status_icon_get_tooltip_text:
2815  * @status_icon: a #GtkStatusIcon
2816  *
2817  * Gets the contents of the tooltip for @status_icon.
2818  *
2819  * Return value: the tooltip text, or %NULL. You should free the
2820  *   returned string with g_free() when done.
2821  *
2822  * Since: 2.16
2823  */
2824 gchar *
2825 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2826 {
2827   GtkStatusIconPrivate *priv;
2828   gchar *tooltip_text = NULL;
2829
2830   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2831
2832   priv = status_icon->priv;
2833
2834 #ifdef GDK_WINDOWING_X11
2835   tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2836 #endif
2837 #ifdef GDK_WINDOWING_WIN32
2838   if (priv->tooltip_text)
2839     tooltip_text = g_strdup (priv->tooltip_text);
2840 #endif
2841 #ifdef GDK_WINDOWING_QUARTZ
2842   if (priv->tooltip_text)
2843     tooltip_text = g_strdup (priv->tooltip_text);
2844 #endif
2845
2846   return tooltip_text;
2847 }
2848
2849 /**
2850  * gtk_status_icon_set_tooltip_markup:
2851  * @status_icon: a #GtkStatusIcon
2852  * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2853  *
2854  * Sets @markup as the contents of the tooltip, which is marked up with
2855  *  the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2856  *
2857  * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2858  * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2859  *
2860  * See also the #GtkStatusIcon:tooltip-markup property and
2861  * gtk_tooltip_set_markup().
2862  *
2863  * Since: 2.16
2864  */
2865 void
2866 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2867                                     const gchar   *markup)
2868 {
2869   GtkStatusIconPrivate *priv;
2870 #ifndef GDK_WINDOWING_X11
2871   gchar *text = NULL;
2872 #endif
2873
2874   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2875
2876   priv = status_icon->priv;
2877
2878 #ifdef GDK_WINDOWING_X11
2879   gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2880 #endif
2881 #ifdef GDK_WINDOWING_WIN32
2882   if (markup)
2883     pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2884   gtk_status_icon_set_tooltip_text (status_icon, text);
2885   g_free (text);
2886 #endif
2887 #ifdef GDK_WINDOWING_QUARTZ
2888   if (markup)
2889     pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2890   gtk_status_icon_set_tooltip_text (status_icon, text);
2891   g_free (text);
2892 #endif
2893 }
2894
2895 /**
2896  * gtk_status_icon_get_tooltip_markup:
2897  * @status_icon: a #GtkStatusIcon
2898  *
2899  * Gets the contents of the tooltip for @status_icon.
2900  *
2901  * Return value: the tooltip text, or %NULL. You should free the
2902  *   returned string with g_free() when done.
2903  *
2904  * Since: 2.16
2905  */
2906 gchar *
2907 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2908 {
2909   GtkStatusIconPrivate *priv;
2910   gchar *markup = NULL;
2911
2912   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2913
2914   priv = status_icon->priv;
2915
2916 #ifdef GDK_WINDOWING_X11
2917   markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2918 #endif
2919 #ifdef GDK_WINDOWING_WIN32
2920   if (priv->tooltip_text)
2921     markup = g_markup_escape_text (priv->tooltip_text, -1);
2922 #endif
2923 #ifdef GDK_WINDOWING_QUARTZ
2924   if (priv->tooltip_text)
2925     markup = g_markup_escape_text (priv->tooltip_text, -1);
2926 #endif
2927
2928   return markup;
2929 }
2930
2931 /**
2932  * gtk_status_icon_get_x11_window_id:
2933  * @status_icon: a #GtkStatusIcon
2934  *
2935  * This function is only useful on the X11/freedesktop.org platform.
2936  * It returns a window ID for the widget in the underlying
2937  * status icon implementation.  This is useful for the Galago 
2938  * notification service, which can send a window ID in the protocol 
2939  * in order for the server to position notification windows 
2940  * pointing to a status icon reliably.
2941  *
2942  * This function is not intended for other use cases which are
2943  * more likely to be met by one of the non-X11 specific methods, such
2944  * as gtk_status_icon_position_menu().
2945  *
2946  * Return value: An 32 bit unsigned integer identifier for the 
2947  * underlying X11 Window
2948  *
2949  * Since: 2.14
2950  */
2951 guint32
2952 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2953 {
2954 #ifdef GDK_WINDOWING_X11
2955   gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2956   return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
2957 #else
2958   return 0;
2959 #endif
2960 }
2961
2962 /**
2963  * gtk_status_icon_set_title:
2964  * @status_icon: a #GtkStatusIcon
2965  * @title: the title 
2966  *
2967  * Sets the title of this tray icon.
2968  * This should be a short, human-readable, localized string 
2969  * describing the tray icon. It may be used by tools like screen
2970  * readers to render the tray icon.
2971  *
2972  * Since: 2.18
2973  */
2974 void
2975 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2976                            const gchar   *title)
2977 {
2978   GtkStatusIconPrivate *priv;
2979
2980   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2981
2982   priv = status_icon->priv;
2983
2984 #ifdef GDK_WINDOWING_X11
2985   gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2986 #endif
2987 #ifdef GDK_WINDOWING_QUARTZ
2988   g_free (priv->title);
2989   priv->title = g_strdup (title);
2990 #endif
2991 #ifdef GDK_WINDOWING_WIN32
2992   g_free (priv->title);
2993   priv->title = g_strdup (title);
2994 #endif
2995
2996   g_object_notify (G_OBJECT (status_icon), "title");
2997 }
2998
2999 /**
3000  * gtk_status_icon_get_title:
3001  * @status_icon: a #GtkStatusIcon
3002  *
3003  * Gets the title of this tray icon. See gtk_status_icon_set_title().
3004  *
3005  * Returns: the title of the status icon
3006  *
3007  * Since: 2.18
3008  */
3009 G_CONST_RETURN gchar *
3010 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
3011 {
3012   GtkStatusIconPrivate *priv;
3013
3014   g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
3015
3016   priv = status_icon->priv;
3017
3018 #ifdef GDK_WINDOWING_X11
3019   return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
3020 #endif
3021 #ifdef GDK_WINDOWING_QUARTZ
3022   return priv->title;
3023 #endif
3024 #ifdef GDK_WINDOWING_WIN32
3025   return priv->title;
3026 #endif
3027 }
3028
3029
3030 /**
3031  * gtk_status_icon_set_name:
3032  * @status_icon: a #GtkStatusIcon
3033  * @name: the name
3034  *
3035  * Sets the name of this tray icon.
3036  * This should be a string identifying this icon. It is may be
3037  * used for sorting the icons in the tray and will not be shown to
3038  * the user.
3039  *
3040  * Since: 2.20
3041  */
3042 void
3043 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
3044                           const gchar   *name)
3045 {
3046   GtkStatusIconPrivate *priv;
3047
3048   g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
3049
3050   priv = status_icon->priv;
3051
3052 #ifdef GDK_WINDOWING_X11
3053   gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
3054 #endif
3055
3056   g_object_notify (G_OBJECT (status_icon), "name");
3057 }
3058
3059
3060 #define __GTK_STATUS_ICON_C__
3061 #include "gtkaliasdef.c"