[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 User's Guide



Creating New Menus

To create a completely new menu, use the general menu syntax in Section 6.2 as a model and follow these steps:

  1. Fill in a menu name.

  2. Create the item names.

  3. Choose a mnemonic and accelerator (optional).

  4. Give each item a function to perform (see Table 6-1).

  5. Menu Items

    An item can be either a character string or a graphic representation (bitmap or pixmap).

    A character string for items must be compatible with the menu font that is used. Character strings must be typed precisely using one of the following styles:

    1. Any character string containing a space must be enclosed in "" (double quotes) (for example, "Menu name").

    2. Single-word strings do not have to be enclosed in double quotes, but it is probably a good idea for the sake of consistency (for example, "Menuname").

    3. An alternate method of dealing with multiple-word item names is to use an underbar in place of the space (for example, Menu_name).

      An item in either X bitmap (XBM) or X pixmap (XPM) file format can be created. Using the @ (at sign) in the menu syntax tells the window manager that what follows is the pathname for a bitmap or pixmap file:

      @
       
      bitmapfile function [
       
      argument]

      The following is an example of a newly created menu. The menu is named Graphics Projects. The menu items are all bitmaps symbolizing different graphics projects. The bitmaps are kept in the directory /users/pat/bits. When the user selects a symbol, the graphics program starts and opens the appropriate graphics file.

      Menu "Graphics Projects"



      {
      "Graphics Projects" f.title
      @/users/pat/bits/fusel.bits f.exec "cad /spacestar/fusel.e12"
      @/users/pat/bits/lwing.bits f.exec "cad /spacestar/lwing.s05"
      @/users/pat/bits/rwing.bits f.exec "cad /spacestar/rwing.s04"
      @/users/pat/bits/nose.bits f.exec "cad /spacestar/nose.e17"
      }

      Another method for specifying the pathname is to replace /users/pat/ with the ~/ (tilde and slash) characters. The ~/ specifies the user's home directory. Another method is to use the bitmapDirectory resource. If the bitmapDirectory resource is set to /users/pat/bits, then a menu item could be specified as follows:

      @fusel.bits

      f.exec "cad /spacestar/fusel.e12

    4. Mnemonics and Accelerators

      You can use mnemonics and keyboard accelerators in the menus that you create. Mnemonics are functional only when the menu is posted; accelerators are functional whether or not the menu is posted. A mnemonic specification has the following syntax:

      mnemonic = _
       
      character

      The _ (underbar) is placed under the first matching character in the label. If there is no matching character in the label, no mnemonic is registered with the window manager for that label. The accelerator specification is a key action with the same syntax as is used for binding keys to window manager functions:

      key context function [
       
      argument]

      When choosing accelerators, be careful not to use key actions that are already used in key bindings. (See Section 6.5 for information about keyboard bindings.)

      The following line from the default Window Menu illustrates mnemonic and accelerator syntax:

      Restore _R Alt<Key>F5 f.normalize

      Functions

      The predefined Motif Window Manager functions are listed in Table 6-1. Each mwm function operates in one or more of the following contexts:

      root
      Operates the function when the workspace or root window is selected.

      window
      Operates the function when a client window is selected. All subparts of a window are considered as windows for function contexts. Note that some functions operate only when the window is in its normalized or iconified state (f.maximize), or its maximized or iconified state (f.normalize).

      icon
      Operates the function when an icon is selected.

      Each function is activated by one or more of the following devices:

      1. Mouse button

      2. Keyboard key

      3. Menu item

        Any selection that uses an invalid context, an invalid function, or a function that does not apply to the current context is grayed out. For example, the Restore selection on a terminal window's Window Menu and the Minimize selection on an icon's menu are invalid. Also, menu items are grayed out if they are assigned the f.nop (no operation performed) function.

        If you want your new menu to appear whenever a certain mouse button or keyboard key is pressed, follow these steps:

        1. Choose the mouse button or keyboard key that you want to use.

        2. Choose the action on the button or key that causes the menu to appear.

        3. Choose the context in which the menu is to appear.

        4. Use the f.menu function with the new menu's name as an argument to bind the menu to the button or key.

          For example, you may want to create a root menu that gives some control over the entire screen area. The definition of a root menu might look as follows:

          Menu RootMenu


          {

          "Workspace Menu" f.title
          "New Window" f.exec "mterm"
          "Mail" f.exec "mail"
          "Editor" f.exec "editor"
          "Refresh" f.refresh
          no-label f.separator
          "Restart" f.restart
          }

          Once you have defined the menu, you need to bind the menu to a mouse button in your .mwmrc file:

          <Btn3Down>  root f.menu RootMenu

        5. [ Previous | Next | Contents | Glossary | Home | Search ]