Mercurial > pidgin.yaz
annotate src/gtkmenutray.c @ 11907:d2db6426c88a
[gaim-migrate @ 14198]
sf patch #1342817, from Evan Schoenberg
"As discussed in #gaim, this patch removes idle.c and replaces it
with gtkidle.c and gtkidle.h. The attached diff removes the idle
management from its various hiding places in connection.c, server.c,
and gaim.h. The plugins Changelog.API is appropriately updated.
The new gtkidle files are attached; idle.c should be removed from
CVS."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 30 Oct 2005 23:00:47 +0000 |
parents | 7d2d926704aa |
children | 34ea75bdd0c9 |
rev | line source |
---|---|
11553 | 1 /* |
2 * Gaim 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 | |
4 * source distribution. | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 #include "gtkmenutray.h" | |
21 | |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
22 #include <gtk/gtkiconfactory.h> |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
23 #include <gtk/gtkversion.h> |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
24 |
11553 | 25 /****************************************************************************** |
26 * Enums | |
27 *****************************************************************************/ | |
28 enum { | |
29 PROP_ZERO = 0, | |
30 PROP_BOX | |
31 }; | |
32 | |
33 /****************************************************************************** | |
34 * Globals | |
35 *****************************************************************************/ | |
36 static GObjectClass *parent_class = NULL; | |
37 | |
38 /****************************************************************************** | |
39 * Internal Stuff | |
40 *****************************************************************************/ | |
41 | |
42 /****************************************************************************** | |
43 * Item Stuff | |
44 *****************************************************************************/ | |
45 static void | |
46 gaim_gtk_menu_tray_select(GtkItem *item) { | |
47 /* this may look like nothing, but it's really overriding the | |
48 * GtkMenuItem's select function so that it doesn't get highlighted like | |
49 * a normal menu item would. | |
50 */ | |
51 } | |
52 | |
53 static void | |
54 gaim_gtk_menu_tray_deselect(GtkItem *item) { | |
55 /* Probably not necessary, but I'd rather be safe than sorry. We're | |
56 * overridding the select, so it makes sense to override deselect as well. | |
57 */ | |
58 } | |
59 | |
60 /****************************************************************************** | |
61 * Widget Stuff | |
62 *****************************************************************************/ | |
63 | |
64 /****************************************************************************** | |
65 * Object Stuff | |
66 *****************************************************************************/ | |
67 static void | |
68 gaim_gtk_menu_tray_get_property(GObject *obj, guint param_id, GValue *value, | |
69 GParamSpec *pspec) | |
70 { | |
71 GaimGtkMenuTray *menu_tray = GAIM_GTK_MENU_TRAY(obj); | |
72 | |
73 switch(param_id) { | |
74 case PROP_BOX: | |
75 g_value_set_object(value, gaim_gtk_menu_tray_get_box(menu_tray)); | |
76 break; | |
77 default: | |
78 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); | |
79 break; | |
80 } | |
81 } | |
82 | |
83 static void | |
84 gaim_gtk_menu_tray_finalize(GObject *obj) { | |
11599
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
85 #if 0 |
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
86 /* This _might_ be leaking, but I have a sneaking suspicion that the widget is |
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
87 * getting destroyed in GtkContainer's finalize function. But if were are |
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
88 * leaking here, be sure to figure out why this causes a crash. |
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
89 * -- Gary |
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
90 */ |
11558 | 91 GaimGtkMenuTray *tray = GAIM_GTK_MENU_TRAY(obj); |
11599
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
92 |
11558 | 93 if(GTK_IS_WIDGET(tray->tray)) |
94 gtk_widget_destroy(GTK_WIDGET(tray->tray)); | |
11599
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
95 #endif |
11553 | 96 |
97 G_OBJECT_CLASS(parent_class)->finalize(obj); | |
98 } | |
99 | |
100 static void | |
101 gaim_gtk_menu_tray_class_init(GaimGtkMenuTrayClass *klass) { | |
102 GObjectClass *object_class = G_OBJECT_CLASS(klass); | |
103 GtkItemClass *item_class = GTK_ITEM_CLASS(klass); | |
104 GParamSpec *pspec; | |
105 | |
106 parent_class = g_type_class_peek_parent(klass); | |
107 | |
108 object_class->finalize = gaim_gtk_menu_tray_finalize; | |
109 object_class->get_property = gaim_gtk_menu_tray_get_property; | |
110 | |
111 item_class->select = gaim_gtk_menu_tray_select; | |
112 item_class->deselect = gaim_gtk_menu_tray_deselect; | |
113 | |
114 pspec = g_param_spec_object("box", "The box", | |
115 "The box", | |
116 GTK_TYPE_BOX, | |
117 G_PARAM_READABLE); | |
118 g_object_class_install_property(object_class, PROP_BOX, pspec); | |
119 } | |
120 | |
121 static void | |
122 gaim_gtk_menu_tray_init(GaimGtkMenuTray *menu_tray) { | |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
123 GtkWidget *widget = GTK_WIDGET(menu_tray); |
11888 | 124 #if GTK_CHECK_VERSION(2,2,0) |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
125 GtkSettings *settings; |
11888 | 126 #endif |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
127 gint height = -1; |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
128 |
11553 | 129 gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray), TRUE); |
130 | |
11558 | 131 if(!GTK_IS_WIDGET(menu_tray->tray)) |
132 menu_tray->tray = gtk_hbox_new(FALSE, 0); | |
11553 | 133 |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
134 #if GTK_CHECK_VERSION(2,2,0) |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
135 settings = |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
136 gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
137 |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
138 if(gtk_icon_size_lookup_for_settings(settings, GTK_ICON_SIZE_MENU, |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
139 NULL, &height)) |
11888 | 140 #else |
141 if(gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, NULL, &height)) | |
142 #endif | |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
143 { |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
144 gtk_widget_set_size_request(widget, -1, height); |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
145 } |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
146 |
11558 | 147 gtk_container_add(GTK_CONTAINER(menu_tray), menu_tray->tray); |
11553 | 148 |
11558 | 149 gtk_widget_show(menu_tray->tray); |
11553 | 150 } |
151 | |
152 /****************************************************************************** | |
153 * API | |
154 *****************************************************************************/ | |
155 GType | |
156 gaim_gtk_menu_tray_get_gtype(void) { | |
157 static GType type = 0; | |
158 | |
159 if(type == 0) { | |
160 static const GTypeInfo info = { | |
161 sizeof(GaimGtkMenuTrayClass), | |
162 NULL, | |
163 NULL, | |
164 (GClassInitFunc)gaim_gtk_menu_tray_class_init, | |
165 NULL, | |
166 NULL, | |
167 sizeof(GaimGtkMenuTray), | |
168 0, | |
169 (GInstanceInitFunc)gaim_gtk_menu_tray_init, | |
170 NULL | |
171 }; | |
172 | |
173 type = g_type_register_static(GTK_TYPE_MENU_ITEM, | |
174 "GaimGtkMenuTray", | |
175 &info, 0); | |
176 } | |
177 | |
178 return type; | |
179 } | |
180 | |
181 GtkWidget * | |
182 gaim_gtk_menu_tray_new() { | |
183 return g_object_new(GAIM_GTK_TYPE_MENU_TRAY, NULL); | |
184 } | |
185 | |
186 GtkWidget * | |
187 gaim_gtk_menu_tray_get_box(GaimGtkMenuTray *menu_tray) { | |
188 g_return_val_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray), NULL); | |
11558 | 189 return menu_tray->tray; |
11553 | 190 } |
191 | |
192 void | |
193 gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
194 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
195 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
196 | |
11558 | 197 gtk_box_pack_end(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0); |
11553 | 198 } |
199 | |
200 void | |
201 gaim_gtk_menu_tray_prepend(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
202 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
203 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
204 | |
11558 | 205 gtk_box_pack_start(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0); |
11553 | 206 } |