Appendix C. Naming Conventions

This appendix describes a suggested set of conventions for naming widgets, and elements within widget code.

This appendix proposes a set of conventions for naming certain elements of widget code.[111]If the naming conventions used in all widget sets are consistent, there will be several benefits:

These conventions are common between the OPEN LOOK and Motif widget sets with a few minor differences. However, the Athena widget set currently does not follow the conventions described.

It is important to note that these suggestions are in no way blessed (or damned) by the X Consortium--they are simply a guideline that we suggest you follow in the interests of promoting the benefits listed above. We will use Motif as an example.

A toolkit uses a special prefix with all its widgets. In the case of Motif, this prefix is m. Using that prefix and a hypothetical Label widget as an example, the conventions are as follows:

Toolkit library name 

libXm.a

Widget class name 

XmLabel

Include directives 

<Xm/Label.h>

class_name field in the core structure 

Label

Enumerated resource values 

XmCAPITALIZED_WORDS

Public function names 

XmLabelFunctionName()

Truncated include file names 

Strip the lowercase letters a word at a time until the basename is nine characters or fewer (but strip as few letters as possible from the initial word). Thus:

<Xm/VeryLongWidgetName.h>

becomes:

<Xm/VeryLWN.h>

but:

<Xm/Verylongwidgetname.h>

becomes:

<Xm/Verylongw.h>

(Note difference in VeryLong (two words) and Verylong (one word).)

Macro names for preprocessor in include files 

#ifndef XM_LABEL_H

This is to prevent header files from being included more than once.

If a widget has a corresponding gadget, then Gadget is appended to the widget name, so XmLabelGadget is the gadget class name.

Widget class pointer 

xmLabelWidgetClass

Gadget class pointer 

xmLabelGadgetClass

Create function for widgets or gadgets 

Widget XmCreateLabel (parent, name, arglist, argcount)

This is a shortcut to using XtCreateWidget(). However, in the case of top-level widgets (menus, dialogs, MainWindow), it also creates the shell widget and creates the requested widget within it.

The special Create functions can also be used as convenience routines for specialized widget instances. For example, XmCreateWorkingDialog() and XmCreateWarningDialog() actually create a MessageBox whose XmDialogType resources are respectively XmDIALOG_WARNING and XmDIALOG_WORKING.

OPEN LOOK uses conventions similar to Motif, but leaves the prefixes off the widget class name. We recommend that you supply a prefix for any widgets you write, especially if there is any chance that some other widget set may use the same class name. In other words, if we wrote a new Label widget, we might call it OraLabel, not just Label, so that we could still use the Athena Label widget in the same application.



[111] This appendix is based on a comp.windows.x network news posting by Gene Dykes of Cornell University.