comparison console/libgnt/gntmenuitem.c @ 14613:62bb53609a36

[gaim-migrate @ 17341] Menus and windows. I have added a test-app test/menu.c to show how to use it. Pressing Ctrl+o brings up the menu for the window (if it has one). It should now be possible to add menus for account-actions and all that stuff. Patches are very welcome. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 24 Sep 2006 07:14:26 +0000
parents
children f1f1dcb26d89
comparison
equal deleted inserted replaced
14612:1f46715c08d9 14613:62bb53609a36
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 }
15
16 static void
17 gnt_menuitem_class_init(GntMenuItemClass *klass)
18 {
19 parent_class = G_OBJECT_CLASS(klass);
20
21 parent_class->dispose = gnt_menuitem_destroy;
22 }
23
24 static void
25 gnt_menuitem_init(GTypeInstance *instance, gpointer class)
26 {
27 }
28
29 /******************************************************************************
30 * GntMenuItem API
31 *****************************************************************************/
32 GType
33 gnt_menuitem_get_gtype(void)
34 {
35 static GType type = 0;
36
37 if(type == 0)
38 {
39 static const GTypeInfo info = {
40 sizeof(GntMenuItemClass),
41 NULL, /* base_init */
42 NULL, /* base_finalize */
43 (GClassInitFunc)gnt_menuitem_class_init,
44 NULL, /* class_finalize */
45 NULL, /* class_data */
46 sizeof(GntMenuItem),
47 0, /* n_preallocs */
48 gnt_menuitem_init, /* instance_init */
49 };
50
51 type = g_type_register_static(G_TYPE_OBJECT,
52 "GntMenuItem",
53 &info, 0);
54 }
55
56 return type;
57 }
58
59 GObject *gnt_menuitem_new(const char *text)
60 {
61 GObject *item = g_object_new(GNT_TYPE_MENUITEM, NULL);
62 GntMenuItem *menuitem = GNT_MENUITEM(item);
63
64 menuitem->text = g_strdup(text);
65
66 return item;
67 }
68
69 void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data)
70 {
71 item->callback = callback;
72 item->callbackdata = data;
73 }
74
75 void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu)
76 {
77 item->submenu = menu;
78 }
79