#include <stdio.h>
#include <Foundation/NSAutoreleasePool.h>
#define gtk	((GtkMenuFactory *) gtk)
 
static void menu_forward_signal (GtkWidget *widget, gpointer user_data)
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    id target = gtk_object_get_data((GtkObject *) widget, "_menu_target");
 
#ifdef DEBUG
    fprintf(stderr, "(menu_forward_signal init) gtk = %p, action [%p %s]\n",
	    widget, target, [NSStringFromSelector(user_data) cString]);
#endif
    [target performSelector:user_data withObject:Gtk_to_Object(widget, NULL)];
    [pool release];
#ifdef DEBUG
    fprintf(stderr, "(menu_forward_signal exit) gtk = %p\n", widget);
#endif
}
- (void) addEntries:(GtkMenuEntry *) entries forTarget:target
{
    GtkMenuEntry *base = entries;
    int index, count = 0;
 
    while (entries->path) ++entries, ++count;
    for (index = 0; index != count; ++index)
	base[index].callback = menu_forward_signal;
 
    gtk_menu_factory_add_entries(gtk, base, count);
 
    for (index = 0; index != count; ++index)
	if (base[index].widget)
	    gtk_object_set_data((GtkObject *) base[index].widget,
				"_menu_target", target);
}
- (GTKAcceleratorTable *) acceleratorTable
{
    return Gtk_to_Object(gtk->table, "GTKAcceleratorTable");
}
- (GTKWidget *) widget
{
    return Gtk_to_Object(gtk->widget, 0);
}
#undef gtk
