Mercurial > pidgin
comparison src/gtkmenutray.c @ 11553:5c8210f7cbe2
[gaim-migrate @ 13813]
Here is my menu tray widget. It needs a bit of work yet and is only capable of displaying status information at the moment. Integration coming in my next commit...
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sat, 17 Sep 2005 03:23:50 +0000 |
parents | |
children | 19941a47405c |
comparison
equal
deleted
inserted
replaced
11552:11d30825c1bb | 11553:5c8210f7cbe2 |
---|---|
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 | |
22 #define GAIM_GTK_MENU_TRAY_GET_PRIVATE(obj) \ | |
23 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GAIM_GTK_TYPE_MENU_TRAY, GaimGtkMenuTrayPriv)) | |
24 | |
25 /****************************************************************************** | |
26 * Structs | |
27 *****************************************************************************/ | |
28 typedef struct { | |
29 GtkWidget *tray; | |
30 } GaimGtkMenuTrayPriv; | |
31 | |
32 /****************************************************************************** | |
33 * Enums | |
34 *****************************************************************************/ | |
35 enum { | |
36 PROP_ZERO = 0, | |
37 PROP_BOX | |
38 }; | |
39 | |
40 /****************************************************************************** | |
41 * Globals | |
42 *****************************************************************************/ | |
43 static GObjectClass *parent_class = NULL; | |
44 | |
45 /****************************************************************************** | |
46 * Internal Stuff | |
47 *****************************************************************************/ | |
48 | |
49 /****************************************************************************** | |
50 * Item Stuff | |
51 *****************************************************************************/ | |
52 static void | |
53 gaim_gtk_menu_tray_select(GtkItem *item) { | |
54 /* this may look like nothing, but it's really overriding the | |
55 * GtkMenuItem's select function so that it doesn't get highlighted like | |
56 * a normal menu item would. | |
57 */ | |
58 } | |
59 | |
60 static void | |
61 gaim_gtk_menu_tray_deselect(GtkItem *item) { | |
62 /* Probably not necessary, but I'd rather be safe than sorry. We're | |
63 * overridding the select, so it makes sense to override deselect as well. | |
64 */ | |
65 } | |
66 | |
67 /****************************************************************************** | |
68 * Widget Stuff | |
69 *****************************************************************************/ | |
70 | |
71 /****************************************************************************** | |
72 * Object Stuff | |
73 *****************************************************************************/ | |
74 static void | |
75 gaim_gtk_menu_tray_get_property(GObject *obj, guint param_id, GValue *value, | |
76 GParamSpec *pspec) | |
77 { | |
78 GaimGtkMenuTray *menu_tray = GAIM_GTK_MENU_TRAY(obj); | |
79 | |
80 switch(param_id) { | |
81 case PROP_BOX: | |
82 g_value_set_object(value, gaim_gtk_menu_tray_get_box(menu_tray)); | |
83 break; | |
84 default: | |
85 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); | |
86 break; | |
87 } | |
88 } | |
89 | |
90 static void | |
91 gaim_gtk_menu_tray_finalize(GObject *obj) { | |
92 GaimGtkMenuTrayPriv *priv = GAIM_GTK_MENU_TRAY_GET_PRIVATE(obj); | |
93 | |
94 if(GTK_IS_WIDGET(priv->tray)) | |
95 gtk_widget_destroy(GTK_WIDGET(priv->tray)); | |
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 g_type_class_add_private(klass, sizeof(GaimGtkMenuTrayPriv)); | |
115 | |
116 pspec = g_param_spec_object("box", "The box", | |
117 "The box", | |
118 GTK_TYPE_BOX, | |
119 G_PARAM_READABLE); | |
120 g_object_class_install_property(object_class, PROP_BOX, pspec); | |
121 } | |
122 | |
123 static void | |
124 gaim_gtk_menu_tray_init(GaimGtkMenuTray *menu_tray) { | |
125 GaimGtkMenuTrayPriv *priv = GAIM_GTK_MENU_TRAY_GET_PRIVATE(menu_tray); | |
126 | |
127 gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray), TRUE); | |
128 | |
129 if(!GTK_IS_WIDGET(priv->tray)) | |
130 priv->tray = gtk_hbox_new(FALSE, 0); | |
131 | |
132 gtk_container_add(GTK_CONTAINER(menu_tray), priv->tray); | |
133 | |
134 gtk_widget_show(priv->tray); | |
135 } | |
136 | |
137 /****************************************************************************** | |
138 * API | |
139 *****************************************************************************/ | |
140 GType | |
141 gaim_gtk_menu_tray_get_gtype(void) { | |
142 static GType type = 0; | |
143 | |
144 if(type == 0) { | |
145 static const GTypeInfo info = { | |
146 sizeof(GaimGtkMenuTrayClass), | |
147 NULL, | |
148 NULL, | |
149 (GClassInitFunc)gaim_gtk_menu_tray_class_init, | |
150 NULL, | |
151 NULL, | |
152 sizeof(GaimGtkMenuTray), | |
153 0, | |
154 (GInstanceInitFunc)gaim_gtk_menu_tray_init, | |
155 NULL | |
156 }; | |
157 | |
158 type = g_type_register_static(GTK_TYPE_MENU_ITEM, | |
159 "GaimGtkMenuTray", | |
160 &info, 0); | |
161 } | |
162 | |
163 return type; | |
164 } | |
165 | |
166 GtkWidget * | |
167 gaim_gtk_menu_tray_new() { | |
168 return g_object_new(GAIM_GTK_TYPE_MENU_TRAY, NULL); | |
169 } | |
170 | |
171 GtkWidget * | |
172 gaim_gtk_menu_tray_get_box(GaimGtkMenuTray *menu_tray) { | |
173 GaimGtkMenuTrayPriv *priv; | |
174 | |
175 g_return_val_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray), NULL); | |
176 | |
177 priv = GAIM_GTK_MENU_TRAY_GET_PRIVATE(menu_tray); | |
178 | |
179 return priv->tray; | |
180 } | |
181 | |
182 void | |
183 gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
184 GaimGtkMenuTrayPriv *priv; | |
185 | |
186 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
187 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
188 | |
189 priv = GAIM_GTK_MENU_TRAY_GET_PRIVATE(menu_tray); | |
190 | |
191 gtk_box_pack_end(GTK_BOX(priv->tray), widget, FALSE, FALSE, 0); | |
192 } | |
193 | |
194 void | |
195 gaim_gtk_menu_tray_prepend(GaimGtkMenuTray *menu_tray, GtkWidget *widget) { | |
196 GaimGtkMenuTrayPriv *priv; | |
197 | |
198 g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray)); | |
199 g_return_if_fail(GTK_IS_WIDGET(widget)); | |
200 | |
201 priv = GAIM_GTK_MENU_TRAY_GET_PRIVATE(menu_tray); | |
202 | |
203 gtk_box_pack_start(GTK_BOX(priv->tray), widget, FALSE, FALSE, 0); | |
204 } |