Change the "length of bstream" data type to be a gsize, since it represents
[pidgin-git.git] / finch / libgnt / gntmenuitem.c
blob306ef55d5247519f027138d68e0cfec8fecd0759
1 /**
2 * GNT - The GLib Ncurses Toolkit
4 * GNT is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "gntinternal.h"
24 #include "gntmenu.h"
25 #include "gntmenuitem.h"
27 enum
29 SIG_ACTIVATE,
30 SIGS
32 static guint signals[SIGS] = { 0 };
34 static GObjectClass *parent_class = NULL;
36 static void
37 gnt_menuitem_destroy(GObject *obj)
39 GntMenuItem *item = GNT_MENU_ITEM(obj);
40 g_free(item->text);
41 item->text = NULL;
42 if (item->submenu)
43 gnt_widget_destroy(GNT_WIDGET(item->submenu));
44 g_free(item->priv.id);
45 parent_class->dispose(obj);
48 static void
49 gnt_menuitem_class_init(GntMenuItemClass *klass)
51 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
52 parent_class = g_type_class_peek_parent(klass);
54 obj_class->dispose = gnt_menuitem_destroy;
56 signals[SIG_ACTIVATE] =
57 g_signal_new("activate",
58 G_TYPE_FROM_CLASS(klass),
59 G_SIGNAL_RUN_LAST,
60 0, NULL, NULL,
61 g_cclosure_marshal_VOID__VOID,
62 G_TYPE_NONE, 0);
65 static void
66 gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
70 /******************************************************************************
71 * GntMenuItem API
72 *****************************************************************************/
73 GType
74 gnt_menuitem_get_gtype(void)
76 static GType type = 0;
78 if(type == 0)
80 static const GTypeInfo info = {
81 sizeof(GntMenuItemClass),
82 NULL, /* base_init */
83 NULL, /* base_finalize */
84 (GClassInitFunc)gnt_menuitem_class_init,
85 NULL, /* class_finalize */
86 NULL, /* class_data */
87 sizeof(GntMenuItem),
88 0, /* n_preallocs */
89 gnt_menuitem_init, /* instance_init */
90 NULL /* value_table */
93 type = g_type_register_static(G_TYPE_OBJECT,
94 "GntMenuItem",
95 &info, 0);
98 return type;
101 GntMenuItem *gnt_menuitem_new(const char *text)
103 GObject *item = g_object_new(GNT_TYPE_MENU_ITEM, NULL);
104 GntMenuItem *menuitem = GNT_MENU_ITEM(item);
106 menuitem->text = g_strdup(text);
108 return menuitem;
111 void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data)
113 item->callback = callback;
114 item->callbackdata = data;
117 void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu)
119 if (item->submenu)
120 gnt_widget_destroy(GNT_WIDGET(item->submenu));
121 item->submenu = menu;
124 GntMenu *gnt_menuitem_get_submenu(GntMenuItem *item)
126 return item->submenu;
129 void gnt_menuitem_set_trigger(GntMenuItem *item, char trigger)
131 item->priv.trigger = trigger;
134 char gnt_menuitem_get_trigger(GntMenuItem *item)
136 return item->priv.trigger;
139 void gnt_menuitem_set_id(GntMenuItem *item, const char *id)
141 g_free(item->priv.id);
142 item->priv.id = g_strdup(id);
145 const char * gnt_menuitem_get_id(GntMenuItem *item)
147 return item->priv.id;
150 gboolean gnt_menuitem_activate(GntMenuItem *item)
152 g_signal_emit(item, signals[SIG_ACTIVATE], 0);
153 if (item->callback) {
154 item->callback(item, item->callbackdata);
155 return TRUE;
157 return FALSE;