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



The ConstraintClassPart Structure

The third part of the class record is the ConstraintClassPart structure. For example, following is theConstraintClassPart structure of the ExmGrid widget:

{                 /* constraint_class */
  /* resources */                  constraints,
  /* num_resources */              XtNumber(constraints),
  /* constraint_size */            sizeof(ExmGridConstraintRec),
  /* initialize */                 NULL,
  /* destroy */                    NULL,
  /* set_values */                 ConstraintSetValues,
  /* extension */                  NULL,
},

The following subsections detail each of these fields.

The resources (constraints) Field

The resources field holds the name of the constraints array. This array has the same syntax as a resources array. For example, following is the constraints array of the ExmGrid widget:

static XtResource constraints[] =
{
    {
        ExmNgridMarginWidthWithinCell,
        ExmCGridMarginWidthWithinCell,
        XmRHorizontalDimension,
        sizeof (Dimension),
        XtOffsetOf( ExmGridConstraintRec,
                   grid.grid_margin_width_within_cell),
        XmRImmediate,
        (XtPointer) 0
    },
    {
        ExmNgridMarginHeightWithinCell,
        ExmCGridMarginHeightWithinCell,
        XmRVerticalDimension,
        sizeof (Dimension),
        XtOffsetOf( ExmGridConstraintRec,
                   grid.grid_margin_height_within_cell),
        XmRImmediate,
        (XtPointer) 0
    },
};

Motif also supports synthetic constraints, which are explained later in this section.

The num_resources Field

The num_resources field holds the number of constraints defined by the array in the resources field of the ConstraintClassPart structure. If your widget does not provide a constraints array, then you should specify 0 for the num_resources field. If your widget does provide a constraints array, then your widget should use the XtNumber macro to count these resources. For example, the ExmSimple widget does provide a resources array, so its num_resources field looks as follows:

/* num_resources */               
XtNumber(constraints),

The constraint_size Field

The constraint_size field holds the size of the full constraint structure. For example, the full constraint structure of the ExmGrid demonstration widget is named ExmGridConstraintRec; therefore, the Core class part of ExmSimple defines the constraint_size field as follows:

/* constraint_size */               
sizeof(ExmGridConstraintRec);

The Constraint initialize Field (Chained)

To satisfy the Constraint initialize field, you can either specify the name of your widget's Constraint initialize method or you can specify NULL, to indicate the absence of a Constraint initialize method.

The Constraint initialize field is chained; therefore, the Intrinsics call the Constraint initialize method of XmManager before calling the Constraint initialize method in your own widget. The Constraint initialize method of XmManager examines each child of your widget as it is created. The response taken by this method depends on whether the created child is a widget or is a gadget.

If the created child is a gadget, the Constraint initialize method of XmManager examines the selected events of its gadgets. If the selected events are any of the following, the Constraint initialize method installs an event handler:

  1. Motion

  2. Enter

  3. Leave

    The event handler dispatches events to the appropriate gadget for analysis.

    If the created child is a widget, the Constraint initialize method installs accelerators stored in the accelerator widget.

  4. The Constraint destroy Field (Chained)

    The Constraint destroy field holds the name of a method that is invoked when a widget is destroyed. You must specify one of the following:

    1. The name of your widget's Constraint destroy method. Your widget should provide a Constraint destroy method if your widget's Constraint initialize method allocated any dynamic memory. The Constraint destroy method of your widget is responsible for deallocating this dynamic memory.

    2. NULL, to indicate the absence of a Constraint destroy method. Your widget should probably specify NULL if your widget's Constraint initialize method did not allocate any dynamic memory.

      The Constraint destroy method is chained in subclass-to-superclass order. Therefore, the Intrinsics will call the Constraint destroy method of XmManager after calling the Constraint destroy method in your own widget. The Constraint destroy method of XmManager conditionally removes the event handler that was put into place by the Constraint initialize method of XmManager. That is, the Constraint destroy method of XmManager determines whether the event handler is still needed. If it is not needed, Constraint destroy removes it. Otherwise, Constraint destroy keeps it.

    3. The Constraint set_values Field (Chained)

      To satisfy the Constraint set_values field, you must specify one of the following:

      1. The name of your widget's Constraint set_values method

      2. NULL, to indicate the absence of a Constraint set_values method

        The Constraint set_values field is chained; therefore, the Constraint set_values method of XmManager will be called before any Constraint set_values method in your own widget. The Constraint set_values method of XmManager determines whether any changes to gadget children (for instance, a change in the gadget's selected events) make it necessary to install or remove the event handler.

      3. The extension Field

        If you want your widget to support a ConstraintClassPart extension record, set the extension field to the name of that extension record. If you do not want this extension record, set the field to NULL.

        The one nontrivial field in the extension record is get_values_hook. Motif makes no recommendations on this field. (See the Intrinsics documentation for details.)


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