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
24 #include "gntmenuitem.h"
31 static guint signals
[SIGS
] = { 0 };
33 static GObjectClass
*parent_class
= NULL
;
36 gnt_menuitem_destroy(GObject
*obj
)
38 GntMenuItem
*item
= GNT_MENU_ITEM(obj
);
42 gnt_widget_destroy(GNT_WIDGET(item
->submenu
));
43 g_free(item
->priv
.id
);
44 parent_class
->dispose(obj
);
48 gnt_menuitem_class_init(GntMenuItemClass
*klass
)
50 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
51 parent_class
= g_type_class_peek_parent(klass
);
53 obj_class
->dispose
= gnt_menuitem_destroy
;
55 signals
[SIG_ACTIVATE
] =
56 g_signal_new("activate",
57 G_TYPE_FROM_CLASS(klass
),
60 g_cclosure_marshal_VOID__VOID
,
65 gnt_menuitem_init(GTypeInstance
*instance
, gpointer klass
)
69 /******************************************************************************
71 *****************************************************************************/
73 gnt_menuitem_get_gtype(void)
75 static GType type
= 0;
79 static const GTypeInfo info
= {
80 sizeof(GntMenuItemClass
),
82 NULL
, /* base_finalize */
83 (GClassInitFunc
)gnt_menuitem_class_init
,
84 NULL
, /* class_finalize */
85 NULL
, /* class_data */
88 gnt_menuitem_init
, /* instance_init */
89 NULL
/* value_table */
92 type
= g_type_register_static(G_TYPE_OBJECT
,
100 GntMenuItem
*gnt_menuitem_new(const char *text
)
102 GObject
*item
= g_object_new(GNT_TYPE_MENU_ITEM
, NULL
);
103 GntMenuItem
*menuitem
= GNT_MENU_ITEM(item
);
105 menuitem
->text
= g_strdup(text
);
110 void gnt_menuitem_set_callback(GntMenuItem
*item
, GntMenuItemCallback callback
, gpointer data
)
112 item
->callback
= callback
;
113 item
->callbackdata
= data
;
116 void gnt_menuitem_set_submenu(GntMenuItem
*item
, GntMenu
*menu
)
119 gnt_widget_destroy(GNT_WIDGET(item
->submenu
));
120 item
->submenu
= menu
;
123 GntMenu
*gnt_menuitem_get_submenu(GntMenuItem
*item
)
125 return item
->submenu
;
128 void gnt_menuitem_set_trigger(GntMenuItem
*item
, char trigger
)
130 item
->priv
.trigger
= trigger
;
133 char gnt_menuitem_get_trigger(GntMenuItem
*item
)
135 return item
->priv
.trigger
;
138 void gnt_menuitem_set_id(GntMenuItem
*item
, const char *id
)
140 g_free(item
->priv
.id
);
141 item
->priv
.id
= g_strdup(id
);
144 const char * gnt_menuitem_get_id(GntMenuItem
*item
)
146 return item
->priv
.id
;
149 gboolean
gnt_menuitem_activate(GntMenuItem
*item
)
151 g_signal_emit(item
, signals
[SIG_ACTIVATE
], 0);
152 if (item
->callback
) {
153 item
->callback(item
, item
->callbackdata
);