#include <stdio.h>
#include <Foundation/NSAutoreleasePool.h>

%%/* This class has been declared deprecated!!, use @GTKItemFactory instead. */

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_GET_OBJECT(widget)];
    [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);
}

#define gtk	((GtkMenuFactory *) gtk)
- (GTKAccelGroup *) accelGroup
{
    return Gtk_to_Object(gtk->accel_group, "GTKAccelGroup");
}
- (GTKWidget *) widget
{
    return GTK_GET_OBJECT(gtk->widget);
}
#undef gtk
