Re: porting issues



On Wed, 17 Jul 2002, Jeffrey Goddard wrote:

i can relate to the frustration of trying to learn a new toolkit.
although i cannot help you with your problem, perhaps you can help
me with mine. i need to know how to provide a "hot key" access to
the top level menus in a gtk app, but can't seem to decipher the
docs. perhaps you have a code snippet that will show me the way?

OK, here goes:

static void set_up_my_menu (GtkItemFactoryEntry my_items[],
                            GtkWidget *parent_window)
{
    GtkItemFactory *ifac;
    GtkAccelGroup *accel;
    gint n_items;

    accel = gtk_accel_group_new ();

    ifac = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
                                 accel);

    n_items = sizeof my_items / sizeof my_items[0];

    gtk_item_factory_create_items (ifac, n_items, my_items,
                                   NULL);

    gtk_window_add_accel_group(GTK_WINDOW(parent_window),
                               accel);

    /* Example accelerator setting: F4 selects File/Exit */
    gtk_accel_map_add_entry ("<main>/File/Exit", GDK_F4, 0);
}

If you want to require a modifier key, look at the GdkModifierType
enumeration and substitute, e.g., GDK_SHIFT_MASK for the 0 as the last
argument to gtk_accel_map_add_entry().

Allin Cottrell.




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