[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

2754.0. "Is there an example of a widget field access macro?" by AIAG::ARTEMIEFF () Mon May 14 1990 11:45

I need to define macros to access the fields of my user-defined widget, to 
ensure binary compatibility with the toolkit.  Does anyone have any examples?

Also, the DECwindows Guide to Application Programming, Appendix D, needs to be 
updated to reflect the requirements of upward-compatible user-defined widgets.
The fact that the manual does not document those requirements has cost me much
time and aggravation.

T.RTitleUserPersonal
Name
DateLines
2754.1Example I wrote a long time ago, but I think it's still validLEOVAX::TREGGIARIMon May 14 1990 13:15177
/*
 *  This is an example widget using the upward compatibility code of the
 *  DECtoolkit.  The widget is a simple "pushbutton".  It is a sub-class
 *  of the Label widget
 */

#include <decw$include/DECwDwtWidgetProg.h>

static void Notify(), Destroy(), ClassInitialize();

/*
 *  Index used by the DwtField macro
 */
#define DwtSimplePushIndex  (DwtLabelIndex + 1)

/*
 *  Class part record
 */
typedef struct _SimplePushClass {
    DwtOffsetPtr simplepushoffsets;
    int reserved;
} SimplePushClassPart;

/*
 *  Class record
 */
typedef struct _SimplePushClassRec {
    CoreClassPart	core_class;
    CompositeClassPart	composite_class;
    DwtCommonClassPart	dwtcommon_class;
    LabelClassPart	label_class;
    SimplePushClassPart	simplepush_class;
} SimplePushClassRec, *SimplePushWidgetClass;

/*
 *  Instance Part Record
 */
typedef struct {
    XtCallbackList	callback_list;
    int			anything;
} SimplePushPart;

/*
 *  Instance record
 */
typedef struct _SimplePushRec {
    CorePart		core;
    CompositePart	composite;
    DwtCommonPart	dwtcommon;
    LabelPart		label;
    SimplePushPart	simplepush;
} SimplePushRec, *SimplePushWidget;


/*
 *  Resources for the SimplePush widget.  NOTE the use of the
 *  DwtPartResources and DwtPartOffset macros
 */
static DwtPartResource resources[] = { 
    {"callback", XtCCallback, XtRCallback, sizeof(caddr_t),
	DwtPartOffset(SimplePush, callback_list), XtRCallback, (caddr_t) NULL},
    {"anything", "Int", XtRInt, sizeof(int),
	DwtPartOffset(SimplePush, anything), XtRInt, (caddr_t) NULL},
};  

/*
 *  Translation table for SimplePush;  activates on button 1 up
 */
static char defaultTranslations[] = "<Btn1Up>:	notify()";

/*
 *  Action table
 */
static XtActionsRec actionsList[] = { {"notify",	Notify} };

/*
 *  Initialization of Class Record
 *  NOTE that the size is set to the size of the SimplePush's part
 */
SimplePushClassRec simplepushClassRec = {
  {  /* Core Class Part */
    /* superclass	  */	(WidgetClass) &labelwidgetclassrec,
    /* class_name	  */	"SimplePush",
    /* widget_size	  */    sizeof(SimplePushPart),
    /* class_initialize   */    ClassInitialize,
    /* class_part_initialize*/	NULL,
    /* class_inited       */	FALSE,
    /* initialize	  */	NULL,
    /* initialize_hook    */	NULL,		
    /* realize		  */	XtInheritRealize,
    /* actions		  */    actionsList,
    /* num_actions	  */   	XtNumber(actionsList),
    /* resources	  */	(XtResource *) resources,
    /* num_resources	  */	XtNumber(resources),
    /* xrm_class	  */	NULLQUARK,
    /* compress_motion	  */	TRUE,
    /* compress_exposure  */	TRUE,
    /* compress_enterleave*/	TRUE,
    /* visible_interest	  */	FALSE,
    /* destroy		  */    Destroy,
    /* resize		  */    XtInheritResize,
    /* expose		  */	XtInheritExpose,
    /* set_values	  */	NULL,
    /* set_values_hook    */	NULL,			
    /* set_values_almost  */	XtInheritSetValuesAlmost,  
    /* get_values_hook    */	NULL,			
    /* accept_focus	  */	NULL,
    /* version		  */	XtVersionDontCheck,
    /* callback offsets   */    NULL,
    /* tm_table           */    defaultTranslations,
    /* query geometry     */    NULL,
    /* disp accelerators  */	NULL,
    /* extension          */    NULL,
    },
    {	/* composite class record */

    /* childrens geo mgr proc */XtInheritGeometryManager,
    /* set changed proc */      XtInheritChangeManaged,
    /* add a child */		XtInheritInsertChild,
    /* remove a child */        XtInheritDeleteChild,
    /* extension          */    NULL,
    },
    {   /* dwt common class record */

    /* reserved           */	_XtInherit,
    /* reserved           */	_XtInherit,
    /* reserved           */	_XtInherit,
    /* extension          */    NULL,
    },
    {   /* label class record */

    /* 		           */   NULL,
    },
    {   /* simplepush class record */

    /* 		           */   NULL,
    /* 		           */   NULL,
    }
};

WidgetClass simplepushWidgetClass = (WidgetClass) &simplepushClassRec;

/*
 *  Class Initialize Routine.  NOTE the call to DwtResolvePartOffsets
 */
static void ClassInitialize()
{
    DwtResolvePartOffsets(simplepushWidgetClass, 
		&simplepushClassRec.simplepush_class.simplepushoffsets);
}

/*
 *  Action routine for the widget
 */
static void Notify(w, event)
    SimplePushWidget w;
    XEvent *event;
{
    int  data;
    DwtOffsetPtr o;
    
/*
 *  Pass back the label
 */
    o = ((SimplePushWidgetClass)w->core.widget_class)->simplepush_class.simplepushoffsets;
    data = DwtField(w, o, Label, label, char *);
    XtCallCallbacks(w, XtNcallback, data);
}

/*
 *  Class Destroy Routine
 */
static void Destroy(w)
    Widget w;
{
    XtRemoveAllCallbacks(w, XtNcallback);
}
2754.2Thanks, one question regarding the example...AIAG::ARTEMIEFFTue May 22 1990 11:335
Let's say that in the routine Notify you wanted to set the variable data to the
value of the resource anything.  Would you do that as follows?

	data = DwtField(w, o,SimplePush, anything, int);
2754.3Looks right...LEOVAX::TREGGIARIWed May 23 1990 12:200