The GNOME App Helper module contains macros, functions and data
structures used to simplify the creation of menus and toolbars
for GNOME applications.
Menus and toolbars created with GnomeApp helper ensure
a consistent user interface.
The basic building block is an array of
GnomeUIInfoType structures. You can use a
number of macros to fill in each one of these structure entries, or
you can fill each parameter manually if you wish to do so (although,
it is not recommended, as it is an error-prone task).
GNOME user interface recomendations for
applications
The following is a list of suggestions to improve the
consistency of your application with the rest of the GNOME
tools
The order of the toplevel menus should be:
File, < any MDI child menus >, Edit, View, Game, CUSTOM MENUS,
Settings, Windows and Help
The Help menu should not be right-justified.
CUSTOM MENUS is where you should put your
application-specific top-level menus, such as Gnumeric's
"Insert" menu. These are all optional except Help.
The prescribed order of standard menu items in
the "File" menu is the following:
New Window, SEPARATOR, New, Open, Save, Save As, Revert,
SEPARATOR, Print, Print Setup, SEPARATOR, Close, and Exit
The first menu must always be the "File" menu (unless
there are no files in your application, for example, in a
game you can call this "Game"), and it must always be called
"_File".
The main reason for this is that it is important for
the menu accelerators to be consistent. Your application is
required to have at the very least a "File" menu containing
at the very least "Exit".
The New Window menu item should be a subtree if there
are different types of new windows which can be spawned.
All of these are optional, except Exit.
The prescribed order of standard menu items in the "Edit"
menu is the following:
Undo, Redo, SEPARATOR, Cut, Copy, Paste, Clear, Select
All, SEPARATOR, Add, SEPARATOR, Find, Find Again, and Replace
The "Add" item should be used to insert new editable
items, e.g. a new card in a rolodex app. If there is more
than one type of insertable editable item, "Add" should be a
menu subtree.
The 'Windows' menu should be used by MDI
applications to contain a list of the document windows. It
should be structured like this:
MDI window list
For standard menu items (Save, Save As, Close,
Quit, etc), use the macros defined in gnome-app-helper.h,
e.g.
GNOMEUIINFO_MENU_EXIT_ITEM(CB, DATA)
except for New where the define is:
GNOMEUIINFO_MENU_NEW_ITEM(LABEL,TIP,CB,DATA)
Where LABEL is the the text which appears in the menu
for this menu item. You should put LABEL in the form of
N_("_New Document"), or whatever is appropriate for your
application. TIP should be the description of this menu
item's function, e.g. N_("Create a new document"). This
ensures that your application menus can be translated to the
language of the user.
The standard print menu item should immediately print
the document without popping up a dialog. If the user wants
a dialog, he will use the print_setup menu item.
For some standard toplevel menus (File, Edit, Help,
etc), you should use the macros GNOMEUIINFO_*_MENU(tree).
For the help menu, you should have this:
GNOMEUIINFO_HELP(app_name), GNOMEUIINFO_MENU_ABOUT_ITEM(cb,
data), GNOMEUIINFO_END
Ellipsis ("...") should be used on menu items that
require the application to prompt the user for extra information
before the command can execute. "Save as..." is one of these
because the application needs to ask the user for the filename.
"About" is not because the command *is* to pop up an about box,
and it does not need to prompt for information before doing that.
Your menu hints should not have a trailing period.
They should be phrased like commands, e.g. "Open a new file". Do
not phrase them like a description, e.g. "Opens a new file".
All menu text should be internationalized. Use
the N_() macro, e.g. N_("Open new mailbox")
You may notice that most of these guidelines seem
geared towards "productivity" applications (editors,
spreadsheets, ...). If you're writing a game, most of your menu
items won't be appropriate in these menus. The solution is to
create a "Game" menu which contains the game-related menu items.
The contents of the Game menu are as follows:
New Game, Pause Game, Restart Game, SEPARATOR, Undo Move,
Redo Move, Hint, SEPARATOR, Scores, and End game
End game should just end the current game -- it shouldn't
close the application. That's the job of File/Exit.
Defining menus and toolbars.
All of the macros prefixed with GNOMEUIINFO_MENU_ can be
used to simplify the task of making your application consistent
with the GNOME user interface recomendations. The macros include
the default texts to show, images (in case they have one), pop-up
tooltips and in some cases default key-bindings.
A toplevel menu (like the one used by the GnomeApp widget)
is just an array of structures of type
GnomeUIInfoType. Each record of type
GnomeUIInfoType in this array can
represent a menu item that the user can select, a radio-button, a
check-box, a division line, or a submenu.
There are a number of macros that will help you fill in this
structure to make your application conform to the GNOME user
interface guidelines.
The following macros can be used to create consistent
toplevel menus and they provide the standard naming for your
toplevel menus as well as translated texts for the various
languages supported by the GNOME libraries:
GNOMEUIINFO_MENU_FILE_TREE: Used for the
program "File" menu.
GNOMEUIINFO_MENU_EDIT_TREE: Used for the
program "Edit" menu.
GNOMEUIINFO_MENU_VIEW_TREE: Used for the
program "View" menu.
GNOMEUIINFO_MENU_SETTINGS_TREE: Used for the
program "Settings" menu.
GNOMEUIINFO_MENU_FILES_TREE: Used for the
program "Files" menu.
GNOMEUIINFO_MENU_WINDOWS_TREE: Used for the
program "Windows" menu.
GNOMEUIINFO_MENU_HELP_TREE: Used for the
program "Help" menu.
GNOMEUIINFO_MENU_GAME_TREE: Used for the
program "Game" menu. Games should use the "Game" menu is used
instead of the "File" menu as the main menu entry in the GNOME
user interface guidelines
Details
enum GnomeUIInfoType
typedef enum {
GNOME_APP_UI_ENDOFINFO, /* No more items, use it at the end of
an array */
GNOME_APP_UI_ITEM, /* Normal item, or radio item if it is
inside a radioitems group */
GNOME_APP_UI_TOGGLEITEM, /* Toggle (check box) item */
GNOME_APP_UI_RADIOITEMS, /* Radio item group */
GNOME_APP_UI_SUBTREE, /* Item that defines a
subtree/submenu */
GNOME_APP_UI_SEPARATOR, /* Separator line (menus) or blank
space (toolbars) */
GNOME_APP_UI_HELP, /* Create a list of help topics,
used in the Help menu */
GNOME_APP_UI_BUILDER_DATA, /* Specifies the builder data for the
following entries, see code for
further info */
GNOME_APP_UI_ITEM_CONFIGURABLE, /* A configurable menu item. */
/* one should be careful when using
* gnome_app_create_*_[custom|interp|with_data]() functions with
* GnomeUIInfo arrays containing GNOME_APP_UI_BUILDER_DATA items since
* their GnomeUIBuilderData structures completely override the ones
* generated or supplied by the above functions. */
GNOME_APP_UI_SUBTREE_STOCK /* Item that defines a
subtree/submenu, same as GNOME_APP_UI_SUBTREE,
but the texts should be looked up in the
gnome-libs catalog
*/
} GnomeUIInfoType;
This enumeration is used to set the value in a
GnomeUIInfo record to specify the type of the
record. There are macros that can do all the work for you. Use
those instead of these macros. It is defined as follows:
GNOME_APP_UI_ENDOFINFO: Use this to denote
the end of the records in a GnomeUIInfo array.
GNOME_APP_UI_ITEM: Use this for a normal
item, or radio item if it is inside a radioitems group.
GNOME_APP_UI_TOGGLEITEM: Use this for a
toggle (check box) item.
GNOME_APP_UI_RADIOITEMS: Use this for a radio
item group.
GNOME_APP_UI_SUBTREE: Use this to define a
subtree or a submenu. Set the
moreinfo field in the
structure to point to another array of GnomeUIInfo
structures.
GNOME_APP_UI_SEPARATOR: Use this to introduce
a separator line (for menus) or a blank (for toolbars).
GNOME_APP_UI_HELP: Use this to create a list
of help topics. This is usually employed on the Help
menu.
GNOME_APP_UI_BUILDER_DATA: Specifies the
builder data for the following entries, see code for
further info.
GNOME_APP_UI_ITEM_CONFIGURABLE: A
configurable menu item. You should be careful when using
gnome_app_create_*_[custom|interp|with_data]() functions
with GnomeUIInfo arrays containing
GNOME_APP_UI_BUILDER_DATA items since their
GnomeUIBuilderData structures completely override the
ones generated or supplied by the above
functions.
GNOME_APP_UI_SUBTREE_STOCK: Use this to
specifiy a subtree/submenu. Same as
GNOME_APP_UI_SUBTREE, but the texts should be looked up
in the gnome-libs catalog.
typedef enum {
GNOME_APP_PIXMAP_NONE, /* No pixmap specified */
GNOME_APP_PIXMAP_STOCK, /* Use a stock pixmap (GnomeStock) */
GNOME_APP_PIXMAP_DATA, /* Use a pixmap from inline xpm data */
GNOME_APP_PIXMAP_FILENAME /* Use a pixmap from the specified
filename */
} GnomeUIPixmapType;
struct GnomeUIInfo
typedef struct {
GnomeUIInfoType type; /* Type of item */
gchar *label; /* String to use in the label */
gchar *hint; /* For toolbar items, the tooltip. For
menu items, the status bar message */
gpointer moreinfo; /* For an item, toggleitem, or
radioitem, this is a pointer to the
function to call when the item is
activated. For a subtree, a pointer
to another array of GnomeUIInfo
structures. For a radioitem lead
entry, a pointer to an array of
GnomeUIInfo structures for the radio
item group. For a help item,
specifies the help node to load
(i.e. the application's identifier)
or NULL for the main program's name.
For builder data, points to the
GnomeUIBuilderData structure for
the following items */
gpointer user_data; /* Data pointer to pass to callbacks */
gpointer unused_data; /* Reserved for future expansion,
should be NULL */
GnomeUIPixmapType pixmap_type; /* Type of pixmap for the item */
gpointer pixmap_info; /* Pointer to the pixmap information:
*
* For GNOME_APP_PIXMAP_STOCK, a
* pointer to the stock icon name.
*
* For GNOME_APP_PIXMAP_DATA, a
* pointer to the inline xpm data.
*
* For GNOME_APP_PIXMAP_FILENAME, a
* pointer to the filename string.
*/
guint accelerator_key; /* Accelerator key, or 0 for none */
GdkModifierType ac_mods; /* Mask of modifier keys for the
accelerator */
GtkWidget *widget; /* Filled in by gnome_app_create*, you
can use this to tweak the widgets
once they have been created */
} GnomeUIInfo;
GNOMEUIINFO_KEY_UIDATA
#define GNOMEUIINFO_KEY_UIDATA "uidata"
GNOMEUIINFO_KEY_UIBDATA
#define GNOMEUIINFO_KEY_UIBDATA "uibdata"
GNOMEUIINFO_END
#define GNOMEUIINFO_END
Use this macro to tag the end of a menu or toolbar definition.
GNOMEUIINFO_SEPARATOR
#define GNOMEUIINFO_SEPARATOR
Use this macro to include a separator in your menu.
Creates a toggle-item (a checkbox) in a menu, this includes an xpm
graphic. Allows you to specify the data to be passed around to your
callback routine.
label :
The text that will be displayed
tooltip :
The tooltip that will popup.
callback :
Callback routine to invoke.
user_data :
Data to pass to callback routine.
xpm_data :
Pointer to a pixmap to display (in C-xpm format).
GNOMEUIINFO_HELP()
#define GNOMEUIINFO_HELP(app_name)
This special item inserts all of the topics defined by the application
in the topic.dat file. The menu is constructed
from the information stored in the file associated with the app_name
you provide. The information is usually taken from
$(datadir)/help/app_name/$LANG/topic.dat. Where
$LANG is the language chosen when running the application.
app_name :
The application name. Used to locate the correct topic.dat file.
GNOMEUIINFO_SUBTREE()
#define GNOMEUIINFO_SUBTREE(label, tree)
Creates a submenu or a sub-tree in the menu structure. The argument
passed is an array of GnomeUIInfo.
Use this macro inside a GnomeUIInfo structure to include an "About"
menu entry.
cb :
Specifies the routine to be invoked when the menu is selected
data :
The data passed to your routine.
GNOMEUIINFO_MENU_CLEAR_ITEM()
#define GNOMEUIINFO_MENU_CLEAR_ITEM(cb, data)
Use this macro inside a GnomeUIInfo structure to include a "Clear"
option. This is used typically in the Edit menu.
cb :
Specifies the routine to be invoked when the menu is selected
data :
The data passed to your routine.
GNOMEUIINFO_MENU_CLOSE_ITEM()
#define GNOMEUIINFO_MENU_CLOSE_ITEM(cb, data)
Use this macro inside a GnomeUIInfo structure to include a "Close"
menu entry. This is used typically in the File menu or the Game menu
to close the toplevel window.
cb :
Specifies the routine to be invoked when the menu is selected
struct GnomeUIBuilderData {
GnomeUISignalConnectFunc connect_func; /* Function that connects to the item's signals */
gpointer data; /* User data pointer */
gboolean is_interp; /* Should use gtk_signal_connect_interp or normal gtk_signal_connect? */
GtkCallbackMarshal relay_func; /* Marshaller function for language bindings */
GtkDestroyNotify destroy_func; /* Destroy notification function for language bindings */
};
Fills the specified menu shell with items created from the specified
info, inserting them from the item no. pos on.
The accel group will be used as the accel group for all newly created
sub menus and serves as the global accel group for all menu item
hotkeys. If it is passed as NULL, global hotkeys will be disabled.
The uline_accels argument determines whether underline accelerators
will be featured from the menu item labels.
Fills the specified menu shell with items created from the specified
info, inserting them from item no. pos on and using the specified
builder data -- this is intended for language bindings.
The accel group will be used as the accel group for all newly created
sub menus and serves as the global accel group for all menu item
hotkeys. If it is passed as NULL, global hotkeys will be disabled.
The uline_accels argument determines whether underline accelerators
will be featured from the menu item labels.
Configure all user-configurable elements in the given UI info
structure. This includes loading and setting previously-set options from
GNOME config files.
finds menu item described by path starting
in the GtkMenuShell top and returns its parent GtkMenuShell and the
position after this item in pos: gtk_menu_shell_insert(p, w, pos)
would then insert widget w in GtkMenuShell p right after the menu item
described by path.
parent :
Root menu shell widget containing menu items to be searched
Same as the gnome_app_remove_menus, except it removes the specified number
of items from the existing app's menu structure begining with item described
by path, plus the number specified by start - very useful for adding and
removing Recent document items in the File menu.