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
24 #include "gtkmenutray.h"
26 #include "glibcompat.h"
27 #include "gtk3compat.h"
29 /******************************************************************************
31 *****************************************************************************/
37 /******************************************************************************
39 *****************************************************************************/
40 static GObjectClass
*parent_class
= NULL
;
41 /******************************************************************************
43 *****************************************************************************/
45 /******************************************************************************
47 *****************************************************************************/
49 pidgin_menu_tray_select(GtkMenuItem
*widget
) {
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(GtkMenuItem
*widget
) {
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 pidgin_menu_tray_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
70 PidginMenuTray
*menu_tray
= PIDGIN_MENU_TRAY(obj
);
74 g_value_set_object(value
, pidgin_menu_tray_get_box(menu_tray
));
77 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
83 pidgin_menu_tray_map(GtkWidget
*widget
)
85 GTK_WIDGET_CLASS(parent_class
)->map(widget
);
86 gtk_container_add(GTK_CONTAINER(widget
),
87 PIDGIN_MENU_TRAY(widget
)->tray
);
91 pidgin_menu_tray_finalize(GObject
*obj
)
94 PidginMenuTray
*tray
= PIDGIN_MENU_TRAY(obj
);
96 /* This _might_ be leaking, but I have a sneaking suspicion that the widget is
97 * getting destroyed in GtkContainer's finalize function. But if were are
98 * leaking here, be sure to figure out why this causes a crash.
102 if(GTK_IS_WIDGET(tray
->tray
))
103 gtk_widget_destroy(GTK_WIDGET(tray
->tray
));
106 G_OBJECT_CLASS(parent_class
)->finalize(obj
);
110 pidgin_menu_tray_class_init(PidginMenuTrayClass
*klass
) {
111 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
112 GtkMenuItemClass
*menu_item_class
= GTK_MENU_ITEM_CLASS(klass
);
113 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
116 parent_class
= g_type_class_peek_parent(klass
);
118 object_class
->finalize
= pidgin_menu_tray_finalize
;
119 object_class
->get_property
= pidgin_menu_tray_get_property
;
121 menu_item_class
->select
= pidgin_menu_tray_select
;
122 menu_item_class
->deselect
= pidgin_menu_tray_deselect
;
124 widget_class
->map
= pidgin_menu_tray_map
;
126 pspec
= g_param_spec_object("box", "The box",
129 G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
);
130 g_object_class_install_property(object_class
, PROP_BOX
, pspec
);
134 pidgin_menu_tray_init(PidginMenuTray
*menu_tray
) {
135 GtkWidget
*widget
= GTK_WIDGET(menu_tray
);
136 GtkSettings
*settings
;
139 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
140 /* Gtk3 docs says, it should be replaced with gtk_widget_set_hexpand and
141 * gtk_widget_set_halign. But it doesn't seems to work. */
142 gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray
), TRUE
);
143 G_GNUC_END_IGNORE_DEPRECATIONS
145 if(!GTK_IS_WIDGET(menu_tray
->tray
))
146 menu_tray
->tray
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
149 gtk_settings_get_for_screen(gtk_widget_get_screen(widget
));
151 if(gtk_icon_size_lookup_for_settings(settings
, GTK_ICON_SIZE_MENU
,
154 gtk_widget_set_size_request(widget
, -1, height
);
157 gtk_widget_show(menu_tray
->tray
);
160 /******************************************************************************
162 *****************************************************************************/
164 pidgin_menu_tray_get_type(void) {
165 static GType type
= 0;
168 static const GTypeInfo info
= {
169 sizeof(PidginMenuTrayClass
),
172 (GClassInitFunc
)pidgin_menu_tray_class_init
,
175 sizeof(PidginMenuTray
),
177 (GInstanceInitFunc
)pidgin_menu_tray_init
,
181 type
= g_type_register_static(GTK_TYPE_MENU_ITEM
,
190 pidgin_menu_tray_new() {
191 return g_object_new(PIDGIN_TYPE_MENU_TRAY
, NULL
);
195 pidgin_menu_tray_get_box(PidginMenuTray
*menu_tray
) {
196 g_return_val_if_fail(PIDGIN_IS_MENU_TRAY(menu_tray
), NULL
);
197 return menu_tray
->tray
;
201 pidgin_menu_tray_add(PidginMenuTray
*menu_tray
, GtkWidget
*widget
,
202 const char *tooltip
, gboolean prepend
)
204 g_return_if_fail(PIDGIN_IS_MENU_TRAY(menu_tray
));
205 g_return_if_fail(GTK_IS_WIDGET(widget
));
207 if (!gtk_widget_get_has_window(widget
))
211 event
= gtk_event_box_new();
212 gtk_container_add(GTK_CONTAINER(event
), widget
);
213 gtk_widget_show(event
);
217 pidgin_menu_tray_set_tooltip(menu_tray
, widget
, tooltip
);
220 gtk_box_pack_start(GTK_BOX(menu_tray
->tray
), widget
, FALSE
, FALSE
, 0);
222 gtk_box_pack_end(GTK_BOX(menu_tray
->tray
), widget
, FALSE
, FALSE
, 0);
226 pidgin_menu_tray_append(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
228 pidgin_menu_tray_add(menu_tray
, widget
, tooltip
, FALSE
);
232 pidgin_menu_tray_prepend(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
234 pidgin_menu_tray_add(menu_tray
, widget
, tooltip
, TRUE
);
238 pidgin_menu_tray_set_tooltip(PidginMenuTray
*menu_tray
, GtkWidget
*widget
, const char *tooltip
)
240 /* Should we check whether widget is a child of menu_tray? */
243 * If the widget does not have its 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_get_has_window(widget
))
250 widget
= gtk_widget_get_parent(widget
);
252 gtk_widget_set_tooltip_text(widget
, tooltip
);