comparison finch/libgnt/gntmenuitem.c @ 15818:0e3a8505ebbe

renamed gaim-text to finch
author Sean Egan <seanegan@gmail.com>
date Sun, 18 Mar 2007 19:38:15 +0000
parents
children f00f2e283ffb
comparison
equal deleted inserted replaced
15817:317e7613e581 15818:0e3a8505ebbe
1 #include "gntmenu.h"
2 #include "gntmenuitem.h"
3
4 static GObjectClass *parent_class = NULL;
5
6 static void
7 gnt_menuitem_destroy(GObject *obj)
8 {
9 GntMenuItem *item = GNT_MENUITEM(obj);
10 g_free(item->text);
11 item->text = NULL;
12 if (item->submenu)
13 gnt_widget_destroy(GNT_WIDGET(item->submenu));
14 parent_class->dispose(obj);
15 }
16
17 static void
18 gnt_menuitem_class_init(GntMenuItemClass *klass)
19 {
20 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
21 parent_class = g_type_class_peek_parent(klass);
22
23 obj_class->dispose = gnt_menuitem_destroy;
24 }
25
26 static void
27 gnt_menuitem_init(GTypeInstance *instance, gpointer class)
28 {
29 }
30
31 /******************************************************************************
32 * GntMenuItem API
33 *****************************************************************************/
34 GType
35 gnt_menuitem_get_gtype(void)
36 {
37 static GType type = 0;
38
39 if(type == 0)
40 {
41 static const GTypeInfo info = {
42 sizeof(GntMenuItemClass),
43 NULL, /* base_init */
44 NULL, /* base_finalize */
45 (GClassInitFunc)gnt_menuitem_class_init,
46 NULL, /* class_finalize */
47 NULL, /* class_data */
48 sizeof(GntMenuItem),
49 0, /* n_preallocs */
50 gnt_menuitem_init, /* instance_init */
51 NULL /* value_table */
52 };
53
54 type = g_type_register_static(G_TYPE_OBJECT,
55 "GntMenuItem",
56 &info, 0);
57 }
58
59 return type;
60 }
61
62 GntMenuItem *gnt_menuitem_new(const char *text)
63 {
64 GObject *item = g_object_new(GNT_TYPE_MENUITEM, NULL);
65 GntMenuItem *menuitem = GNT_MENUITEM(item);
66
67 menuitem->text = g_strdup(text);
68
69 return menuitem;
70 }
71
72 void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data)
73 {
74 item->callback = callback;
75 item->callbackdata = data;
76 }
77
78 void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu)
79 {
80 if (item->submenu)
81 gnt_widget_destroy(GNT_WIDGET(item->submenu));
82 item->submenu = menu;
83 }
84