3. Using ItemFactory

Now that we've shown you the hard way, here's how you do it using the gtk_item_factory calls.

ItemFactory creates a menu out of an array of ItemFactory entries. This means you can define your menu in its simplest form and then create the menu/menubar widgets with a minimum of function calls.

3.1. ItemFactory entries

At the core of ItemFactory is the ItemFactoryEntry. This structure defines one menu item, and when an array of these entries is defined a whole menu is formed. The ItemFactory entry struct definition looks like this:

3.1.1. Callback Description

The callback for an ItemFactory entry can take two forms. If callback_action is zero, it is of the following form:

3.1.2. ItemFactory entry examples

Creating a simple menu item:

3.1.3. ItemFactoryEntry Arrays

An ItemFactoryEntry on it's own however isn't useful. An array of entries is what's required to define a menu. Below is an example of how you'd declare this array.

3.2. Creating an ItemFactory

An array of GtkItemFactoryEntry items defines a menu. Once this array is defined then the item factory can be created. The function that does this is:

3.3. Making use of the menu and its menu items

The last thing to do is make use of the menu. The following function extracts the relevant widgets from the ItemFactory:

Now you have a menubar or menu which can be manipulated in the same way as shown in the Manual Menu Creation section.