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



Defining Translations in the Class Record

All Motif widgets descend from Core. Therefore, all Motif widgets define keyboard translations through the following two fields of the Core class record:

  1. The tm_table field, which holds the name of a string. This string contains information that maps event to action routine names.

  2. The actions field, which holds the name of an array that maps the action routine names in the translation string to the action methods defined by your widget.

    For example, the ExmMenuButton widget provides the following string for its tm_table field:

    static char defaultTranslations[] =
    "<EnterWindow>:                 MenuButtonEnter()\n\
    <LeaveWindow>:                     MenuButtonLeave()\n\
    <BtnDown>:                    BtnDown()\n\
    <BtnUp>:                         BtnUp()\n\
    :<Key>osfActivate:      ArmAndActivate()\n\
    :<Key>osfCancel:           MenuEscape()\n\
    :<Key>osfHelp:                     MenuButtonHelp()\n\
    ~s ~m ~a <Key>Return:        ArmAndActivate()\n\
    ~s ~m ~a <Key>space:    ArmAndActivate()";

    and the following array for the actions field:

    static XtActionsRec Actions[] = {
               {"ArmAndActivate",   ArmAndActivate},
               {"BtnDown",                BtnDown},
               {"BtnUp",                  BtnUp},
               {"MenuButtonEnter",  MenuButtonEnter},
               {"MenuButtonLeave",  MenuButtonLeave},
               {"MenuButtonHelp",   MenuButtonHelp}
    };

    In addition to the two fields of CoreClassPart, both PrimitiveClassPart and ManagerClassPart provide an additional field named translations. You can set the translations field to one of the following:

    1. NULL, meaning that the translations described by the tm_table string of the CoreClassPart are the only translations defined in the class record.

    2. XtInheritTranslations, meaning that you are inheriting the translations field of your superclass.

    3. A translations string of your own devising. If your widget does do this, the Intrinsics will place the additional translations at the top of the translations table. Therefore, the additional translations take precedence over the translations defined in CoreClassPart. (See the ExmMenuButton demonstration widget for an example of an additional translations string.)

      Most standard Motif widgets set the additional translation field either to NULL or to XtInheritTranslations. If you are subclassing the XmPrimitive widget and specify XtInheritTranslations, you will inherit the following actions:

      <Unmap>:                         PrimitiveUnmap()\n\
      <FocusIn>:                    PrimitiveFocusIn()\n\
      <FocusOut>:                   PrimitiveFocusOut()\n\
      :<Key>osfActivate:      PrimitiveParentActivate()\n\
      :<Key>osfCancel:           PrimitiveParentCancel()\n\
      :<Key>osfBeginLine:     PrimitiveTraverseHome()\n\
      :<Key>osfUp:               PrimitiveTraverseUp()\n\
      :<Key>osfDown:                     PrimitiveTraverseDown()\n\
      :<Key>osfLeft:                     PrimitiveTraverseLeft()\n\
      :<Key>osfRight:                 PrimitiveTraverseRight()\n\
      ~s ~m ~a <Key>Return:        PrimitiveParentActivate()\n\
      s ~m ~a <Key>Tab:            PrimitivePrevTabGroup()\n\
      ~m ~a <Key>Tab:                 PrimitiveNextTabGroup()";

      (All these actions are documented in the reference page for XmPrimitive; see the Motif Programmer's Reference for details.) By specifying XtInheritTranslations in a subclass of XmPrimitive, your widget will automatically inherit the standard keyboard traversal translations for primitive widgets.

      If you are subclassing the XmManager widget and specify XtInheritTranslations, your subclass will inherit the following actions:

      <EnterWindow>:                  ManagerEnter()\n\
      <LeaveWindow>:                  ManagerLeave()\n\
      <FocusOut>:                ManagerFocusOut()\n\
      <FocusIn>:                 ManagerFocusIn()\n\
      :<Key>osfBeginLine:  ManagerGadgetTraverseHome()\n\
      :<Key>osfUp:            ManagerGadgetTraverseUp()\n\
      :<Key>osfDown:                  ManagerGadgetTraverseDown()\n\
      :<Key>osfLeft:                  ManagerGadgetTraverseLeft()\n\
      :<Key>osfRight:              ManagerGadgetTraverseRight()\n\
      s ~m ~a <Key>Tab:       ManagerGadgetPrevTabGroup()\n\
      ~m ~a <Key>Tab:              ManagerGadgetNextTabGroup()";

      (All these actions are documented in the reference page for XmManager; see the Motif Programmer's Reference for details.)


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