[comp.windows.x] Resource Converter is not being called

pnp@cs.purdue.EDU (Panayiotis Papachiou) (04/11/89)

     I have written a Resource Converter from XtRString to XtRVector3d.
I add it to the toolkit in the class initialization routine.  The
Converter is called on the default resources of the widget specified in
the Graph3d.c file and on the resources specified in the XDEFAULTS file,
as it is expected.  However, it is not being called on the resources
specified in the ArgList passed to XtCreateWidget.

     Is there something more I have to do beyond declaring the Converter
to the Toolkit at class-initialization?  I have included source code
below.


Panayiotis Papachiou                 pnp@purdue.EDU	           ARPA
Dept. of Computer Science        pnp.purdue@csnet-relay            CSNET
Purdue University          {ucbvax,decvax,hplabs}!purdue!pnp 	   USENET 
W. Lafayette IN 47907		    317-494-7840		   PHONE      
#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	Graph3d.c
#	Graph3d.h
#	Graph3dP.h
#	Graph3dTest.c
#	Imakefile
# This archive created: Mon Apr 10 17:10:13 1989
echo shar: extracting Graph3d.c '(5338 characters)'
sed 's/^XX//' << \SHAR_EOF > Graph3d.c
XX#include <X11/copyright.h>
XX#include <X11/IntrinsicP.h>
XX#include <X11/StringDefs.h>
XX#include <math.h>
XX#include "Graph3dP.h"
XX
XX#define offset(field) XtOffset(Graph3dWidget, graph3d.field)
XX
XXstatic XtResource resources[] = {
XX    { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
XX	offset(foreground), XtRString, XtDefaultForeground },
XX    { XtNxWindowSize, XtCXWindowSize, XtRFloat, sizeof(float),
XX	offset(xWindowSize), XtRString, "1.0" },
XX    { XtNyWindowSize, XtCYWindowSize, XtRFloat, sizeof(float),
XX	offset(yWindowSize), XtRString, "1.0" },
XX    { XtNzFrontDistance,  XtCZFrontDistance, XtRFloat, sizeof(float),
XX	offset(zFrontDistance), XtRString, "0.1" },
XX    { XtNzBackDistance,  XtCZBackDistance, XtRFloat, sizeof(float),
XX	offset(zBackDistance), XtRString, "1000.0" },
XX    { XtNaim,  XtCAim, XtRVector3d, sizeof(Vector3d),
XX	offset(aim), XtRString, "0.0 0.0 0.0" },
XX    { XtNeye,  XtCEye, XtRVector3d, sizeof(Vector3d),
XX	offset(eye), XtRString, "0.0 0.0 1.0" },
XX    { XtNnVectors,  XtCNVectors, XtRInt, sizeof(int),
XX	offset(nVectors), XtRString, (caddr_t) "0" },
XX    { XtNvectors,  XtCVectors, XtRVector3dPtr, sizeof(Vector3dPtr),
XX	offset(vectors), XtRVector3dPtr, NULL },
XX};
XX
XX#undef offset
XX
XXstatic void ClassInitialize();
XXstatic void ClassPartInitialize();
XXstatic void Initialize();
XXstatic void Realize();
XXstatic void Resize();
XXstatic void Redisplay();
XXstatic Boolean SetValues();
XX
XXGraph3dClassRec graph3dClassRec = {
XX  { /* core fields */
XX#define superclass (&widgetClassRec)
XX    /* superclass		*/	(WidgetClass) superclass,
XX    /* class_name		*/	"Graph3d",
XX    /* widget_size		*/	sizeof(Graph3dRec),
XX    /* class_initialize		*/	ClassInitialize,
XX    /* class_part_initialize	*/	ClassPartInitialize,
XX    /* class_inited		*/	FALSE,
XX    /* initialize		*/	Initialize,
XX    /* initialize_hook		*/	NULL,
XX    /* realize			*/	XtInheritRealize,
XX    /* actions			*/	NULL,
XX    /* num_actions		*/	(Cardinal) 0,
XX    /* resources		*/	resources,
XX    /* num_resources		*/	XtNumber(resources),
XX    /* xrm_class		*/	NULLQUARK,
XX    /* compress_motion		*/	TRUE,
XX    /* compress_exposure	*/	TRUE,
XX    /* compress_enterleave	*/	TRUE,
XX    /* visible_interest		*/	FALSE,
XX    /* destroy			*/	NULL,
XX    /* resize			*/	NULL,
XX    /* expose			*/	NULL,
XX    /* set_values		*/	NULL,
XX    /* set_values_hook		*/	NULL,
XX    /* set_values_almost	*/	XtInheritSetValuesAlmost,
XX    /* get_values_hook		*/	NULL,
XX    /* accept_focus		*/	NULL,
XX    /* version			*/	XtVersion,
XX    /* callback_private		*/	NULL,
XX    /* tm_table			*/	NULL,
XX    /* query_geometry		*/	XtInheritQueryGeometry,
XX    /* display_accelerator	*/	XtInheritDisplayAccelerator,
XX    /* extension		*/	NULL
XX  },
XX  { /* Graph3d fields */
XX    /* pi			*/	0
XX  }
XX};
XX
XXWidgetClass graph3dWidgetClass = (WidgetClass) &graph3dClassRec;
XX
XX     /* implementation of Graph widget */
XX
XXtypedef struct {
XX  float x, y, z;
XX} point3d;
XX
XXtypedef struct {
XX  float p1[4];
XX  float p2[4];
XX} line3d;
XX
XXtypedef struct {
XX  int p1[2];
XX  int p2[2];
XX} linedev;
XX
XX/*ARGSUSED*/
XXstatic void CvtStringToFloat(args, num_args, fromVal, toVal)
XX    XrmValuePtr args;
XX    Cardinal    *num_args;
XX    XrmValuePtr fromVal;
XX    XrmValuePtr toVal;
XX{
XX    static float f;
XX
XX    if (*num_args != 0)
XX      XtWarningMsg("wrongParameters","cvtStringToFloat","XtToolkitError",
XX		   "String to Float conversion needs no extra arguments",
XX		   (String *) NULL, (Cardinal *)NULL);
XX    if (sscanf((char *)fromVal->addr, "%f", &f) == 1) {
XX      (*toVal).size = sizeof(float);
XX      (*toVal).addr = (caddr_t) &f;
XX    } else {
XX      XtStringConversionWarning((char *) fromVal->addr, "Float");
XX    }
XX}
XX
XXvoid CvtStringToVector3d(args, num_args, fromVal, toVal)
XX    XrmValuePtr args;
XX    Cardinal    *num_args;
XX    XrmValuePtr fromVal;
XX    XrmValuePtr toVal;
XX{
XX    static Vector3d v;
XX
XX    if (*num_args != 0)
XX      XtWarningMsg("wrongParameters","cvtStringToVector3d","XtToolkitError",
XX		   "String to Vector3d conversion needs no extra arguments",
XX		   (String *) NULL, (Cardinal *)NULL);
XX    if (sscanf((char *)fromVal->addr, "%f%f%f", 
XX	       &(v.x), &(v.y), &(v.z)) == 3) {
XX      (*toVal).size = sizeof(Vector3d);
XX      (*toVal).addr = (caddr_t) &v;
XX    } else {
XX      XtStringConversionWarning((char *) fromVal->addr, "Vector3d");
XX    }
XX}
XX
XXstatic void ClassInitialize()
XX{
XX  XtAddConverter(XtRString, XtRFloat, CvtStringToFloat, NULL,
XX		 (Cardinal) 0);
XX  XtAddConverter(XtRString, XtRVector3d, CvtStringToVector3d, NULL,
XX		 (Cardinal) 0);
XX}
XX
XXstatic void ClassPartInitialize(widgetClass)
XX     WidgetClass widgetClass;
XX{
XX  Graph3dWidgetClass wc = ( Graph3dWidgetClass) widgetClass;
XX
XX  wc->graph3d_class.pi = acos((double) -1.0);
XX}
XX
XXstatic void GetGC(gw)
XX     Graph3dWidget gw;
XX{
XX  XGCValues values;
XX
XX  values.foreground = gw->graph3d.foreground;
XX  values.background = gw->core.background_pixel;
XX
XX  gw->graph3d.normal_GC = XtGetGC(
XX				  (Widget) gw,
XX				  (unsigned) GCForeground | GCBackground,
XX				  &values);
XX}
XX
XXstatic void Initialize(request, new)
XX     Widget request, new;
XX{
XX  Graph3dWidget w = (Graph3dWidget) new;
XX
XX  if (w->graph3d.nVectors > 0)
XX    w->graph3d.vectors2d = (Line2d *) XtMalloc(sizeof(Line2d) *
XX						 w->graph3d.nVectors);
XX  
XX  GetGC(w);
XX}
XX
XXstatic void Realize(w, value_mask, attributes)
XX     register Widget w;
XX     XtValueMask *value_mask;
XX     XSetWindowAttributes *attributes;
XX{
XX  (*superclass->core_class.realize) (w, value_mask, attributes);
XX}
SHAR_EOF
if test 5338 -ne "`wc -c Graph3d.c`"
then
echo shar: error transmitting Graph3d.c '(should have been 5338 characters)'
fi
echo shar: extracting Graph3d.h '(2177 characters)'
sed 's/^XX//' << \SHAR_EOF > Graph3d.h
XX#include <X11/copyright.h>
XX
XX#ifndef _Graph3d_h
XX#define _Graph3d_h
XX
XX/****************************************************************
XX *
XX * Graph3d widget
XX *
XX ****************************************************************/
XX
XX/* Resources:
XX
XX Name		     Class		RepType		Default Value
XX ----		     -----		-------		-------------
XX xWindowSize         XWindowSize        Float           1.0
XX yWindowSize         YWindowSize        Float           1.0
XX zFrontDistance      ZFrontDistance     Float           0.1
XX zBackDistance       ZBackDistance      Float           100.0
XX aim                 Aim                Vector3d        0.0, 0.0, 0.0
XX eye                 Eye                Vector3d        0.0, 0.0, 1.0
XX nVectors            NVectors           Int             0
XX vectors             Vectors            *Vector3d       NULL
XX
XX*/
XX
XX/* define any special resource names here
XX   that are not in <X11/StringDefs.h> */
XX
XX#define XtNxWindowSize                  "xWindowSize"
XX#define XtCXWindowSize                  "XWindowSize"
XX#define XtNyWindowSize                  "yWindowSize"
XX#define XtCYWindowSize                  "YWindowSize"
XX#define XtNzFrontDistance               "zFrontDistance"
XX#define XtCZFrontDistance               "ZFrontDistance"
XX#define XtNzBackDistance                "zBackDistance"
XX#define XtCZBackDistance                "ZBackDistance"
XX#define XtNaim                          "aim"
XX#define XtCAim                          "Aim"
XX#define XtNeye                          "eye"
XX#define XtCEye                          "Eye"
XX#define XtNnVectors                     "nVectors"
XX#define XtCNVectors                     "NVectors"
XX#define XtNvectors                      "vectors"
XX#define XtCVectors                      "Vectors"
XX
XX#define XtRFloat                        "Float"
XX#define XtRVector3d                     "Vector3d"
XX#define XtRVector3dPtr                  "Vector3dPtr"
XX
XX/* declare specific Graph3dWidget class and instance datatypes */
XX
XXtypedef struct _Graph3dClassRec        *Graph3dWidgetClass;
XXtypedef struct _Graph3dRec             *Graph3dWidget;
XX
XX/* declare the class constant */
XX
XXextern WidgetClass graph3dWidgetClass;
XX
XX#endif  _Graph3d_h
XX
XX
XX
XX
SHAR_EOF
if test 2177 -ne "`wc -c Graph3d.h`"
then
echo shar: error transmitting Graph3d.h '(should have been 2177 characters)'
fi
echo shar: extracting Graph3dP.h '(1371 characters)'
sed 's/^XX//' << \SHAR_EOF > Graph3dP.h
XX#include <X11/copyright.h>
XX  
XX#ifndef _Graph3dP_h
XX#define _Graph3dP_h
XX
XX#include "Graph3d.h"
XX#include <X11/CoreP.h>
XX
XX /* No new fields need to be defined for the Graph3d widgets class record */
XX
XXtypedef struct {
XX  float pi;
XX} Graph3dClassPart;
XX
XX /* Full class record declaration for Graph3d class */
XX
XXtypedef struct _Graph3dClassRec {
XX  CoreClassPart	        core_class;
XX  Graph3dClassPart	graph3d_class;
XX} Graph3dClassRec;
XX
XXextern Graph3dClassRec graph3dClassRec;
XX
XX /* New types needed for instance record */
XX
XXtypedef struct {
XX  float x, y, z;
XX} Vector3d, *Vector3dPtr;
XX
XXtypedef struct {
XX  float p1[2];
XX  float p2[2];
XX} Line2d;
XX
XX /* New fields needed for instance record */
XX
XXtypedef struct {
XX /* public resources */
XX  Pixel      foreground;
XX  float	     xWindowSize;
XX  float	     yWindowSize;
XX  float	     zFrontDistance;
XX  float	     zBackDistance;
XX  Vector3d   aim;
XX  Vector3d   eye;
XX  int        nVectors;
XX  Vector3d   *vectors;
XX
XX /* private resources */
XX  Vector3d   fred;
XX  float	     alpha;
XX  float	     beta;
XX  float	     vt[4][4];
XX  int	     vcx, vcy;
XX  int	     vsx, vsy;
XX  float	     wxmin, wxmax, wymin, wymax;
XX  float	     xfactor, yfactor;
XX  float	     zb, zf;
XX  float	     focal;
XX  Line2d     *vectors2d;
XX  GC         normal_GC;
XX} Graph3dPart;
XX
XXtypedef struct _Graph3dRec {
XX  CorePart	   core;
XX  Graph3dPart	   graph3d;
XX} Graph3dRec;
XX
XX#endif  _Graph3dP_h
XX
XX
SHAR_EOF
if test 1371 -ne "`wc -c Graph3dP.h`"
then
echo shar: error transmitting Graph3dP.h '(should have been 1371 characters)'
fi
echo shar: extracting Graph3dTest.c '(925 characters)'
sed 's/^XX//' << \SHAR_EOF > Graph3dTest.c
XX#include <X11/StringDefs.h>
XX#include <X11/Intrinsic.h>
XX#include <X11/Shell.h>
XX#include "Graph3d.h"
XX
XXmain(argc, argv)
XX     int       argc;
XX     char    **argv;
XX{
XX  static Arg topArgs[] = {
XX    {XtNwidth, (XtArgVal) 100},
XX    {XtNheight, (XtArgVal) 100},
XX  };
XX  static Arg graphArgs[] = {
XX    {XtNaim, (XtArgVal) "3.2 -0.3e-3 1.0"},
XX    {XtNwidth, (XtArgVal) 100},
XX    {XtNheight, (XtArgVal) 100},
XX  };
XX  XtAppContext context;
XX  Widget toplevel;
XX  Widget gw;
XX  Display *dpy;
XX
XX  XtToolkitInitialize();
XX  context = XtCreateApplicationContext();
XX  dpy = XtOpenDisplay(context, NULL, argv[0], "GTe", NULL, 
XX		      (Cardinal) 0, &argc, argv);
XX
XX  toplevel = XtAppCreateShell(argv[0], "GTe",
XX			      topLevelShellWidgetClass, dpy, 
XX			      topArgs, XtNumber(topArgs));
XX
XX  gw = XtCreateWidget("graph3d", graph3dWidgetClass, toplevel,
XX			    graphArgs, XtNumber(graphArgs));
XX
XX  XtRealizeWidget(toplevel);
XX  XtAppMainLoop(context);
XX}
SHAR_EOF
if test 925 -ne "`wc -c Graph3dTest.c`"
then
echo shar: error transmitting Graph3dTest.c '(should have been 925 characters)'
fi
echo shar: extracting Imakefile '(354 characters)'
sed 's/^XX//' << \SHAR_EOF > Imakefile
XX    STD_DEFINES = LibraryDefines
XX    CDEBUGFLAGS = -g -traditional -fwritable-strings
XX       INCLUDES = -I$(TOP)
XX   INSTALLFLAGS = $(INSTINCFLAGS)
XX
XXSYSLAST_LIBRARIES = -lXt -lX11 -lm
XX
XXHEADERS = \
XX	Graph3dP.h\
XX	Grpah3d.h
XX
XXSRCS = \
XX	Graph3d.c\
XX	Graph3dTest.c
XX
XXOBJS = \
XX	Graph3d.o\
XX	Graph3dTest.o
XX
XXComplexProgramTarget(Graph3dTest)
XXDependTarget(Graph3dTest)SHAR_EOF
if test 354 -ne "`wc -c Imakefile`"
then
echo shar: error transmitting Imakefile '(should have been 354 characters)'
fi
#	End of shell archive
exit 0

ben@hpcvlx.HP.COM (Benjamin Ellsworth) (04/12/89)

>    Is there something more I have to do beyond declaring the Converter
> to the Toolkit at class-initialization?  I have included source code
> below.

There is no implicit converter call for arglist elements.  The 
intrinsics assume that the programmer has the wherewithal to provide 
the right type of data in an arglist.  You'll have to call a converter
routine on the data yourself before you load the arglist.

-----------------------------------------------------------------------
Benjamin Ellsworth      | ben@cv.hp.com                | INTERNET
Hewlett-Packard Company | {backbone}!hplabs!hp-pcd!ben | UUCP
1000 N.E. Circle        | (USA) (503) 750-4980         | FAX
Corvallis, OR 97330     | (USA) (503) 757-2000         | VOICE
-----------------------------------------------------------------------
                     All relevant disclaimers apply.
-----------------------------------------------------------------------