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