question about menu item callback and window closing




I have a question regarding the callbacks for a menu which has been 
generated with the item factory.  An excerpt from the code is:

It is the window_close() part I'm struggling with.

static GtkItemFactoryEntry menu_items[] = {
  { "/_File",         NULL,          NULL, 0, "<Branch>" },
  { "/File/sep1",     NULL,          NULL, 0, "<Separator>" },
  { "/File/Close",    "<control>W",  window_close, 0, NULL },
  { "/File/Quit",     "<control>Q",  gtk_main_quit, 0, NULL },
  { "/_Help",                        NULL,        NULL, 0, "<LastBranch>"},
  { "/_Help/About",                  NULL, about_popup, 0, NULL },
  { "/_Help/Copyright",              NULL, copyright_popup, 0, NULL },
};


void get_main_menu( GtkWidget  *window,
                    GtkWidget **menubar,
                    gpointer  mydata )
{
  GtkItemFactory *item_factory;
  GtkAccelGroup *accel_group;
  gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
  accel_group = gtk_accel_group_new ();
  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", 
                                       accel_group);

  /* XXX - is this the right way to get 'mydata' passed to the menu
   * item callbacks??
   */
  gtk_item_factory_create_items (item_factory, nmenu_items, 
                                 menu_items, mydata);


  gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
  if (menubar)
    *menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}


so now my question is when I choose "file->close" exactly how does
window_close() get called?

Is the following the correct prototype at least for window_close()?

static void window_close(GtkWidget *widget,
                         GdkEventAny *event,
                         gpointer data)
{
        /* I want data to be a pointer to the window that contains the
         * menu so that if I have multiple windows open I can close only
         * the one that I selected file->close from.
         */
        gtk_widget_destroy(GTK_WIDGET(data));
}

I know this should be a simple question, but I've been unable to find the
answer in the tutorial or API guide.


Thanks
-Dan








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]