next up previous contents index
Next: 1. Extra Prototypes Up: 5. How to Build Previous: 1. The Header Files   Contents   Index

2. The Implementation

In this section I'll describe the various sections in Trivial.c that are important to the subclass. The new sections are printed in a bold typewriter font. Important parts of the new sections are typeset in an italic bold typewriter font.


#include <LTconfig.h>
#include <Xm/XmP.h>
#include <Xm/XmI.h>
#include <Xm/BulletinBP.h>
#include <Xm/PushBP.h>
#include <Xm/PushBGP.h>
#include <Xm/DebugUtil.h>
#include "TrivialP.h"

/*
 * Forward Declarations
 */
static void class_initialize();
static void class_part_initialize(WidgetClass class);
static void initialize(Widget request, Widget new,
                       ArgList args, Cardinal *num_args);
static void destroy(Widget w);
static Boolean set_values(Widget current, Widget request, Widget new,
                          ArgList args, Cardinal *num_args);

!XmGeoMatrix trivial_matrix_create(Widget _w, Widget _from,
                                  XtWidgetGeometry *_pref);
Boolean trivial_NoGeoRequest(XmGeoMatrix _geoSpec);!

static XmBaseClassExtRec _XmTrivialCoreClassExtRec = {
    /* next_extension               */ NULL,
    /* record_type                  */ NULLQUARK,                             
    /* version                      */ XmBaseClassExtVersion,
    /* size                         */ sizeof(XmBaseClassExtRec),
    /* initialize_prehook           */ NULL,
    /* set_values_prehook           */ NULL,
    /* initialize_posthook          */ NULL,
    /* set_values_posthook          */ NULL,
    /* secondary_object_class       */ NULL,
    /* secondary_object_create      */ NULL,
    /* get_secondary_resources      */ NULL,
    /* fast_subclass                */ { 0 },
    /* get_values_prehook           */ NULL,
    /* get_values_posthook          */ NULL,
    /* class_part_init_prehook      */ NULL,
    /* class_part_init_posthook     */ NULL,
    /* ext_resources                */ NULL,
    /* compiled_ext_resources       */ NULL,
    /* num_ext_resources            */ 0,
    /* use_sub_resources            */ FALSE,
    /* widget_navigable             */ NULL,
    /* focus_change                 */ NULL,
    /* wrapper_data                 */ NULL
};

static XmManagerClassExtRec _XmTrivialMClassExtRec = {
    /* next_extension               */ NULL,
    /* record_type                  */ NULLQUARK,
    /* version                      */ XmManagerClassExtVersion,
    /* record_size                  */ sizeof(XmManagerClassExtRec),
    /* traversal_children           */ NULL /* FIXME */
};

XmTrivialClassRec xmTrivialClassRec = {
    /* Core class part */
    {
    /* superclass                   */ (WidgetClass)
                                         &xmBulletinBoardClassRec,
    /* class_name                   */ "XmTrivial",
    /* widget_size                  */ sizeof(XmBulletinBoardRec),
    /* class_initialize             */ class_initialize,
    /* class_part_initialize        */ class_part_initialize,
    /* class_inited                 */ FALSE,
    /* initialize                   */ initialize,
    /* initialize_hook              */ NULL,
!    /* realize                      */ XtInheritRealize,!
    /* actions                      */ NULL,
    /* num_actions                  */ 0,
    /* resources                    */ NULL,
    /* num_resources                */ 0,
    /* xrm_class                    */ NULLQUARK,
    /* compress_motion              */ TRUE,
    /* compress_exposure            */ XtExposeCompressMaximal,
    /* compress_enterleave          */ TRUE,
    /* visible_interest             */ FALSE,
    /* destroy                      */ destroy,
!    /* resize                       */ XtInheritResize,!
    /* expose                       */ XtInheritExpose,
    /* set_values                   */ set_values,
    /* set_values_hook              */ NULL,
    /* set_values_almost            */ XtInheritSetValuesAlmost,
    /* get_values_hook              */ NULL,
    /* accept_focus                 */ NULL,
    /* version                      */ XtVersion,
    /* callback offsets             */ NULL,
    /* tm_table                     */ NULL,
!    /* query_geometry               */ XtInheritQueryGeometry,!
    /* display_accelerator          */ NULL,
    /* extension                    */ (XtPointer)
                                         &_XmTrivialCoreClassExtRec
    },
    /* Composite class part */
    {
!    /* geometry_manager             */ XtInheritGeometryManager, 
    /* change_managed               */ XtInheritChangeManaged,!
    /* insert_child                 */ XtInheritInsertChild,
    /* delete_child                 */ XtInheritDeleteChild,
    /* extension                    */ NULL
    },
    /* Constraint class part */
    {
    /* subresources                 */ NULL,
    /* subresource_count            */ 0,
    /* constraint_size              */ 0,
    /* initialize                   */ NULL,
    /* destroy                      */ NULL,
    /* set_values                   */ NULL,
    /* extension                    */ NULL
    },
    /* XmManager class part */
    {
    /* translations                 */ XtInheritTranslations,
    /* syn_resources                */ NULL,
    /* num_syn_resources            */ 0,
    /* syn_constraint_resources     */ NULL,
    /* num_syn_constraint_resources */ 0,
    /* parent_process               */ XmInheritParentProcess,
    /* extension                    */ (XtPointer)
                                         &_XmTrivialMClassExtRec
    },
    /* XmBulletinBoard Area part */
    {
    /* always_install_accelerators  */ False,
!    /* geo_matrix_create            */ trivial_matrix_create,!
    /* focus_moved_proc             */ XmInheritFocusMovedProc,
    /* extension                    */ NULL

    },
    /* XmTrivial Class Part */
    {
    /* extension                    */ 0
    }
};

WidgetClass xmTrivialWidgetClass = (WidgetClass)&xmTrivialClassRec;

static void 
class_initialize()
{
    _XmTrivialCoreClassExtRec.record_type = XmQmotif;
}

static void
class_part_initialize(WidgetClass widget_class)
{
}

static void
initialize(Widget request,
           Widget new,
           ArgList args,
           Cardinal *num_args)
{
}

static void
destroy(Widget w)
{
}

static Boolean
set_values(Widget old,
           Widget request,
           Widget new,
           ArgList args,
           Cardinal *num_args)
{
    Boolean refresh_needed = False;

!    BB_InSetValues(new) = True;

    /* do any class specific stuff */

    BB_InSetValues(new) = False;!

!    if (refresh_needed && (XtClass(new) == xmTrivialWidgetClass))
    {
        _XmBulletinBoardSizeUpdate(new);
        return False;
    }!
    return refresh_needed;
}

!XmGeoMatrix
trivial_matrix_create(Widget _w, Widget _from, XtWidgetGeometry *_pref)
{
    XmGeoMatrix geoSpec;
    register XmGeoRowLayout layoutPtr;
    register XmKidGeometry boxPtr;
    Cardinal numKids;
    int i, nrows;
    Widget child;

    numKids = MGR_NumChildren(_w);

    °/* compute the number of rows you want here. */
    nrows = 1; /* Trivial only has one */°

    °geoSpec = _XmGeoMatrixAlloc(nrows, numKids, 0);
    geoSpec->composite = (Widget)_w;
    geoSpec->instigator = (Widget)_from;
    if (_pref)
        geoSpec->instig_request = *_pref;
    geoSpec->margin_w = BB_MarginWidth(_w) + MGR_ShadowThickness(_w);
    geoSpec->margin_h = BB_MarginHeight(_w) + MGR_ShadowThickness(_w);
    geoSpec->no_geo_request = trivial_NoGeoRequest;°

    layoutPtr = &(geoSpec->layouts->row);
    boxPtr = geoSpec->boxes;

    °/* row 1 */
    layoutPtr->fill_mode = XmGEO_CENTER;
    layoutPtr->fit_mode = XmGEO_WRAP;
    layoutPtr->even_width = 1;
    layoutPtr->even_height = 1;
    layoutPtr->space_above = BB_MarginHeight(_w);
    for (i = 0; i < numKids; i++) {
        child = MGR_Children(_w)[i];
        if ((XmIsPushButton(child) || XmIsPushButtonGadget(child)) &&
            XtIsManaged(child) && _XmGeoSetupKid(boxPtr, child))
        {
            boxPtr++;
        }
    }
    layoutPtr++;
    /* end marker */
    layoutPtr->space_above = 0;
    layoutPtr->end = TRUE;°

    return(geoSpec);
}

Boolean
trivial_NoGeoRequest(XmGeoMatrix geo)
{
    if (BB_InSetValues(geo->composite) &&
        XtClass(geo->composite) == xmTrivialWidgetClass)
        return TRUE;

    return FALSE;
}!

Not bad, only around 350 lines of code. This is about the mininum you can get away with if you write a manager widget anyway. But now let us go straight into the details.



Subsections

Danny Backx
2000-12-13