Popup menu refuses appends :-(
- From: "Shantanu Kumar" <shantanu_k06 rediffmail com>
- To: gtk-app-devel-list gnome org
- Subject: Popup menu refuses appends :-(
- Date: 21 Nov 2002 13:26:04 -0000
Hi,
Is it possible to add menuitems to a menu at runtime? I mean, when
the menu is already displayed. And same, is it possible to
set/remove submenus to menuitems at runtime?
I am listing below a small program, which is a sample of what I
have been unsuccessfully trying to do. I wanted to either add
menuitems or set new submenus at runtime through callbacks, while
the menu is already displayed. But not only the runtime assertion
error shows up, also no effect is seen on the menu. Any
pointers/guidance will be of immense help.
***************
Code listing :-
***************
#include <gtk/gtk.h>
void callback(GtkButton *button, gpointer user_data) {
GtkMenu *submenu = (GtkMenu *) user_data;
g_print("Adding label item to submenu...");
gtk_menu_append(submenu,
gtk_menu_item_new_with_label("Test"));
g_print("...adding done\n");
}
void exitfunc(GtkWidget *widget, gpointer user_data) {
gtk_main_quit();
}
int main(int argc, char *argv[]) {
GtkMenu *menu, *submenu;
GtkWidget *item1, *item2;
// initialize
gtk_init(&argc, &argv);
menu = (GtkMenu *) gtk_menu_new();
submenu = (GtkMenu *) gtk_menu_new();
item1 = gtk_menu_item_new_with_label("Item 1");
item2 = gtk_menu_item_new_with_label("Item 2");
// set submenus and prepare widgets
gtk_menu_append(menu, item1);
gtk_menu_append(menu, item2);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item2),
GTK_WIDGET(submenu));
gtk_menu_append(submenu,
gtk_menu_item_new_with_label("First
subitem"));
callback(NULL, (gpointer) submenu);
// connect signals
gtk_signal_connect_object(GTK_OBJECT(item2), "activate",
GTK_SIGNAL_FUNC(callback), (gpointer) submenu);
gtk_signal_connect(GTK_OBJECT(menu), "selection-done",
GTK_SIGNAL_FUNC(exitfunc), NULL);
// display menu and activate the loop
gtk_widget_show_all(GTK_WIDGET(menu));
gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 0, 0);
gtk_main();
return 0;
}
********************************
Output from the above program :-
********************************
Adding label item to submenu......adding done
Adding label item to submenu...
Gtk-CRITICAL **: file gtkmenushell.c: line 308
(gtk_menu_shell_insert): assertion `GTK_IS_MENU_SHELL
(menu_shell)' failed.
...adding done
Thanks,
Shantanu
__________________________________________________________
Give your Company an email address like
ravi @ ravi-exports.com. Sign up for Rediffmail Pro today!
Know more. http://www.rediffmailpro.com/signup/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]