Mercurial > pidgin.yaz
annotate src/gtkmenutray.c @ 11827:f588ced280bf
[gaim-migrate @ 14118]
Comment changes, plus I removed some of the win32 placeholder stuff. I figured I would've broken it by changing the comments, and we probably don't need it anyway. I'm sure someone familiar with wingaim will fix this if I'm wrong. ;)
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 26 Oct 2005 00:31:45 +0000 |
parents | c9188d3eb9d3 |
children | 7d2d926704aa |
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); |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
124 GtkSettings *settings; |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
125 gint height = -1; |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
126 |
11553 | 127 gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray), TRUE); |
128 | |
11558 | 129 if(!GTK_IS_WIDGET(menu_tray->tray)) |
130 menu_tray->tray = gtk_hbox_new(FALSE, 0); | |
11553 | 131 |
11787
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
132 #if GTK_CHECK_VERSION(2,2,0) |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
133 settings = |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
134 gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
135 #else |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
136 settings = gtk_settings_get_default(); |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
137 #endif |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
138 |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
139 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
|
140 NULL, &height)) |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
141 { |
c9188d3eb9d3
[gaim-migrate @ 14078]
Gary Kramlich <grim@reaperworld.com>
parents:
11599
diff
changeset
|
142 gtk_widget_set_size_request(widget, -1, height); |
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 |
11558 | 145 gtk_container_add(GTK_CONTAINER(menu_tray), menu_tray->tray); |
11553 | 146 |
11558 | 147 gtk_widget_show(menu_tray->tray); |
11553 | 148 } |
149 | |
150 /****************************************************************************** | |
151 * API | |
152 *****************************************************************************/ | |
153 GType | |
154 gaim_gtk_menu_tray_get_gtype(void) { | |
155 static GType type = 0; | |
156 | |
157 if(type == 0) { | |
158 static const GTypeInfo info = { | |
159 sizeof(GaimGtkMenuTrayClass), | |
160 NULL, | |
161 NULL, | |
162 (GClassInitFunc)gaim_gtk_menu_tray_class_init, | |
163 NULL, | |
164 NULL, | |
165 sizeof(GaimGtkMenuTray), | |
166 0, | |
167 (GInstanceInitFunc)gaim_gtk_menu_tray_init, | |
168 NULL | |
169 }; | |
170 | |
171 type = g_type_register_static(GTK_TYPE_MENU_ITEM, | |
172 "GaimGtkMenuTray", | |
173 &info, 0); | |
174 } | |
175 | |
176 return type; | |
177 } | |
178 | |
179 GtkWidget * | |
180 gaim_gtk_menu_tray_new() { | |
181 return g_object_new(GAIM_GTK_TYPE_MENU_TRAY, NULL); | |
182 } | |
183 | |
184 GtkWidget * | |
185 gaim_gtk_menu_tray_get_box(GaimGtkMenuTray *menu_tray) { | |
186 g_return_val_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray), NULL); | |
11558 | 187 return menu_tray->tray; |
11553 | 188 } |
189 | |
190 void | |
191 gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
192 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
193 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
194 | |
11558 | 195 gtk_box_pack_end(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0); |
11553 | 196 } |
197 | |
198 void | |
199 gaim_gtk_menu_tray_prepend(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
200 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
201 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
202 | |
11558 | 203 gtk_box_pack_start(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0); |
11553 | 204 } |