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
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"
25 #include "gntmenuitem.h"
32 static guint signals
[SIGS
] = { 0 };
34 static GObjectClass
*parent_class
= NULL
;
37 gnt_menuitem_destroy(GObject
*obj
)
39 GntMenuItem
*item
= GNT_MENU_ITEM(obj
);
43 gnt_widget_destroy(GNT_WIDGET(item
->submenu
));
44 g_free(item
->priv
.id
);
45 parent_class
->dispose(obj
);
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
),
61 g_cclosure_marshal_VOID__VOID
,
66 gnt_menuitem_init(GTypeInstance
*instance
, gpointer klass
)
70 /******************************************************************************
72 *****************************************************************************/
74 gnt_menuitem_get_gtype(void)
76 static GType type
= 0;
80 static const GTypeInfo info
= {
81 sizeof(GntMenuItemClass
),
83 NULL
, /* base_finalize */
84 (GClassInitFunc
)gnt_menuitem_class_init
,
85 NULL
, /* class_finalize */
86 NULL
, /* class_data */
89 gnt_menuitem_init
, /* instance_init */
90 NULL
/* value_table */
93 type
= g_type_register_static(G_TYPE_OBJECT
,
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
);
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
)
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
);