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