2 * Pidgin is the legal property of its developers, whose names are too numerous
3 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * This program is free software; you can redistribute it and/or modify
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "gtkmenutray.h"
24 #include <gtk/gtkeventbox.h>
25 #include <gtk/gtkiconfactory.h>
26 #include <gtk/gtkversion.h>
28 /******************************************************************************
30 *****************************************************************************/
36 /******************************************************************************
38 *****************************************************************************/
39 static GObjectClass
*parent_class
= NULL
;
41 /******************************************************************************
43 *****************************************************************************/
45 /******************************************************************************
47 *****************************************************************************/
49 pidgin_menu_tray_select(GtkItem
*item
) {
50 /* this may look like nothing, but it's really overriding the
51 * GtkMenuItem's select function so that it doesn't get highlighted like
52 * a normal menu item would.
57 pidgin_menu_tray_deselect(GtkItem
*item
) {
58 /* Probably not necessary, but I'd rather be safe than sorry. We're
59 * overridding the select, so it makes sense to override deselect as well.
63 /******************************************************************************
65 *****************************************************************************/
67 /******************************************************************************
69 *****************************************************************************/
71 pidgin_menu_tray_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
74 PidginMenuTray
*menu_tray
= PIDGIN_MENU_TRAY(obj
);
78 g_value_set_object(value
, pidgin_menu_tray_get_box(menu_tray
));
81 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
87 pidgin_menu_tray_finalize(GObject
*obj
) {
89 /* This _might_ be leaking, but I have a sneaking suspicion that the widget is
90 * getting destroyed in GtkContainer's finalize function. But if were are
91 * leaking here, be sure to figure out why this causes a crash.
94 PidginMenuTray
*tray
= PIDGIN_MENU_TRAY(obj
);
96 if(GTK_IS_WIDGET(tray
->tray
))
97 gtk_widget_destroy(GTK_WIDGET(tray
->tray
));
100 G_OBJECT_CLASS(parent_class
)->finalize(obj
);
104 pidgin_menu_tray_class_init(PidginMenuTrayClass
*klass
) {
105 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
106 GtkItemClass
*item_class
= GTK_ITEM_CLASS(klass
);
109 parent_class
= g_type_class_peek_parent(klass
);
111 object_class
->finalize
= pidgin_menu_tray_finalize
;
112 object_class
->get_property
= pidgin_menu_tray_get_property
;
114 item_class
->select
= pidgin_menu_tray_select
;
115 item_class
->deselect
= pidgin_menu_tray_deselect
;
117 pspec
= g_param_spec_object("box", "The box",
121 g_object_class_install_property(object_class
, PROP_BOX
, pspec
);
125 pidgin_menu_tray_init(PidginMenuTray
*menu_tray
) {
126 GtkWidget
*widget
= GTK_WIDGET(menu_tray
);
127 #if GTK_CHECK_VERSION(2,2,0)
128 GtkSettings
*settings
;
132 gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray
), TRUE
);
134 if(!GTK_IS_WIDGET(menu_tray
->tray
))
135 menu_tray
->tray
= gtk_hbox_new(FALSE
, 0);
137 menu_tray
->tooltips
= gtk_tooltips_new();
139 #if GTK_CHECK_VERSION(2,2,0)
141 gtk_settings_get_for_screen(gtk_widget_get_screen(widget
));
143 if(gtk_icon_size_lookup_for_settings(settings
, GTK_ICON_SIZE_MENU
,
146 if(gtk_icon_size_lookup(GTK_ICON_SIZE_MENU
, NULL
, &height
))
149 gtk_widget_set_size_request(widget
, -1, height
);
152 gtk_container_add(GTK_CONTAINER(menu_tray
), menu_tray
->tray
);
154 gtk_widget_show(menu_tray
->tray
);
157 /******************************************************************************
159 *****************************************************************************/
161 pidgin_menu_tray_get_gtype(void) {
162 static GType type
= 0;
165 static const GTypeInfo info
= {
166 sizeof(PidginMenuTrayClass
),
169 (GClassInitFunc
)pidgin_menu_tray_class_init
,
172 sizeof(PidginMenuTray
),
174 (GInstanceInitFunc
)pidgin_menu_tray_init
,
178 type
= g_type_register_static(GTK_TYPE_MENU_ITEM
,
187 pidgin_menu_tray_new() {
188 return g_object_new(PIDGIN_TYPE_MENU_TRAY
, NULL
);
192 pidgin_menu_tray_get_box(PidginMenuTray
*menu_tray
) {
193 g_return_val_if_fail(PIDGIN_IS_MENU_TRAY(menu_tray
), NULL
);
194 return menu_tray
->tray
;
198 pidgin_menu_tray_add(PidginMenuTray
*menu_tray
, GtkWidget
*widget
,
199 const char *tooltip
, gboolean prepend
)
201 g_return_if_fail(PIDGIN_IS_MENU_TRAY(menu_tray
));
202 g_return_if_fail(GTK_IS_WIDGET(widget
));
204 if (GTK_WIDGET_NO_WINDOW(widget
))
208 event
= gtk_event_box_new();
209 gtk_container_add(GTK_CONTAINER(event
), widget
);
210 gtk_widget_show(event
);
214 pidgin_menu_tray_set_tooltip(menu_tray
, widget
, tooltip
);
217 gtk_box_pack_start(GTK_BOX(menu_tray
->tray
), widget
, FALSE
, FALSE
, 0);
219 gtk_box_pack_end(GTK_BOX(menu_tray
->tray
), widget
, FALSE
, FALSE
, 0);
223 pidgin_menu_tray_append(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
225 pidgin_menu_tray_add(menu_tray
, widget
, tooltip
, FALSE
);
229 pidgin_menu_tray_prepend(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
231 pidgin_menu_tray_add(menu_tray
, widget
, tooltip
, TRUE
);
235 pidgin_menu_tray_set_tooltip(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
237 if (!menu_tray
->tooltips
)
240 /* Should we check whether widget is a child of menu_tray? */
243 * If the widget does not have it's own window, then it
244 * must have automatically been added to an event box
245 * when it was added to the menu tray. If this is the
246 * case, we want to set the tooltip on the widget's parent,
247 * not on the widget itself.
249 if (GTK_WIDGET_NO_WINDOW(widget
))
250 widget
= widget
->parent
;
252 gtk_tooltips_set_tip(menu_tray
->tooltips
, widget
, tooltip
, NULL
);