GtkMenu "map" callback



Hi,

I'm trying to implement a function that needs to be called "before"
the menu attached to the menu bar is "mapped".  I tried doing this by
connecting to the "activate" signal for the menu item which is the
parent of this menu, but what's happening is that the "map" callback
is getting called BEFORE the "activate" callback for the menu item.

Is there a way for me to achieve this?  I need the callback "just
before" the mapping takes place.

The source file that I'm working with is below.

Thanks,
Gaurav

----------------------------
#include <gtk/gtk.h>
#include <glib.h>

/*-- This function allows the program to exit properly when the window
is closed --*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
  g_print ("Quitting...\n");
  gtk_main_quit();
  return (FALSE);
}

/*-- This function allows the program to exit properly when the window
is closed --*/
gint ClosingAppWindow (GtkWidget *widget, gpointer gdata)
{
  g_print ("Quitting...\n");
  gtk_main_quit();
  return (FALSE);
}

void menuItemActivate(GtkWidget *widget, gpointer clientData)
{
  g_print ("Menu Item Activated...\n");
}

void menuMapped(GtkWidget *widget, gpointer clientData)
{
  g_print ("Menu Mapped...\n");
}

int main (int argc, char *argv[])
{
  /*-- Declare the GTK Widgets used in the program --*/
  GtkWidget *window;
  GtkWidget *menuFile;
  GtkWidget *menubar;
  GtkWidget *menu;
  GtkWidget *menuitem;
  GtkWidget *vbox;

  gchar *buffer = "Go to the file menu and select Exit to close the
application.";

  /*--  Initialize GTK --*/
  gtk_init (&argc, &argv);

  /*-- Create the new window --*/
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  /*-- Create the vbox --*/
  vbox = gtk_vbox_new(FALSE, 0);

  /*-- Connect the window to the destroyapp function  --*/
  gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(destroyapp), NULL);

  /*-- Create the menu bar --*/
  menubar = gtk_menu_bar_new();

  /*-- Add the menubar to the vbox --*/
  gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
  gtk_widget_show(menubar);

  /*-- Add the vbox to the main window --*/
  gtk_container_add(GTK_CONTAINER(window), vbox);

  /*---------------- Create File menu items ------------------*/
  menuFile = gtk_menu_item_new_with_label ("File");
  gtk_menu_bar_append (GTK_MENU_BAR(menubar), menuFile);
  gtk_widget_show(menuFile);
  g_signal_connect(G_OBJECT(menuFile), "activate",
G_CALLBACK(menuItemActivate), (gpointer)NULL);
  
  /*-- Create File submenu  --*/
  menu = gtk_menu_new();
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuFile), menu);
  g_signal_connect (G_OBJECT (menu), "map", G_CALLBACK (menuMapped),
(gpointer) menu);


  /*-- Create New menu item under File submenu --*/
  menuitem = gtk_menu_item_new_with_label ("New");
  gtk_menu_append(GTK_MENU(menu), menuitem);
  gtk_widget_show (menuitem);

  /*-- Create Open menu item under File submenu --*/
  menuitem = gtk_menu_item_new_with_label ("Open");
  gtk_menu_append(GTK_MENU(menu), menuitem);
  gtk_widget_show (menuitem);

  /*-- Create Exit menu item under File submenu --*/
  menuitem = gtk_menu_item_new_with_label ("Exit");
  gtk_menu_append(GTK_MENU(menu), menuitem);
  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (ClosingAppWindow), NULL);
  gtk_widget_show (menuitem);
  /*---------------- End File menu declarations ----------------*/

  /*-- Set window border to zero so that text area takes up the whole
window --*/
  gtk_container_border_width (GTK_CONTAINER (window), 0);

  /*-- Set the window to be 640 x 480 pixels --*/
  gtk_window_set_default_size (GTK_WINDOW(window), 640, 200);

  /*-- Set the window title --*/
  gtk_window_set_title(GTK_WINDOW (window), "Text Area");

  /*-- Display the widgets --*/
  gtk_widget_show(menuitem);
  gtk_widget_show(menuFile);
  gtk_widget_show(vbox);
  gtk_widget_show(window);

  /*-- Start the GTK event loop --*/
  gtk_main();

  /*-- Return 0 if exit is successful --*/
  return 0;
}



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