Re: Not disabling menu item accelerator when hiding menu bar, ...
- From: David Nečas (Yeti) <yeti physics muni cz>
- To: gtk-app-devel-list gnome org
- Subject: Re: Not disabling menu item accelerator when hiding menu bar, ...
- Date: Wed, 28 Feb 2007 16:31:08 +0100
On Tue, Feb 27, 2007 at 03:13:48PM -0800, Daniel Yek wrote:
I'm looking for the most convenient way to keep menu item accelerator
functioning when the application has to hide the menu bar from view. Any
suggestion?
An example demonstrating the kluge I have been using is
enclosed.
Yeti
--
Whatever.
======================================================================
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
int
main(int argc, char *argv[])
{
static const struct { const gchar *label; guint key; GCallback callback; }
items[] = {
{ "_Show Menubar", GDK_S, G_CALLBACK(gtk_widget_show) },
{ "_Hide Menubar", GDK_H, G_CALLBACK(gtk_widget_hide) },
{ "_Quit", GDK_Q, G_CALLBACK(gtk_main_quit) },
};
GtkWidget *window, *vbox, *menubar, *menu, *item;
GtkAccelGroup *accel_group;
guint i;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
g_object_unref(accel_group);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
/* Menu bar */
menubar = gtk_menu_bar_new();
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
item = gtk_menu_item_new_with_mnemonic("_Foo");
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), item);
menu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
for (i = 0; i < G_N_ELEMENTS(items); i++) {
item = gtk_menu_item_new_with_mnemonic(items[i].label);
gtk_widget_add_accelerator(item, "activate", accel_group,
items[i].key, GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect_swapped(item, "activate", items[i].callback, menubar);
}
/* Dummy popup menu */
menu = gtk_menu_new();
gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
for (i = 0; i < G_N_ELEMENTS(items); i++) {
item = gtk_menu_item_new_with_mnemonic(items[i].label);
gtk_widget_add_accelerator(item, "activate", accel_group,
items[i].key, GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect_swapped(item, "activate", items[i].callback, menubar);
}
gtk_widget_show_all(menu);
/* The rest */
gtk_box_pack_start(GTK_BOX(vbox),
gtk_label_new("Place your bloody application here."),
TRUE, TRUE, 0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]