[comp.windows.x] Why are my resources ignored

kern@goofy.inria.fr (Michel Kern) (08/29/90)

Hello X wizards, 

As a first try to X programming (with very little C programming experience),
I tried to modify Ed Kubaitis' Gnuplot X11 terminal.
It was mostly easy except for the following: the window into which all
curves are drawn is a Label widget. I would like to give it a default size
when it is first map, so that the user won't have to resize the window to
see the first plot. 
Using a app-default file for this slooks to me like overkill (though it
works), and I thought the code below would give the same effect. 
It doesn't :(

What happens is the following:
goofy[81]: simple
width = 640, height = 450
Label: width = 38 height = 17       <---  this is before XtrealizeWidget
Top  : width = 0 height = 0                 
Label: width = 38 height = 17       <---- this is after XtrealizeWidget
Top  : width = 38 height = 17

that is, the window is created with a size just large enough to display the
string "label". Yet, with command line arguments, 

goofy[83]: simple -geom 640x450
width = 640, height = 450
Label: width = 38 height = 17
Top  : width = 0 height = 0
Label: width = 640 height = 450
Top  : width = 640 height = 450

it gives me a reasonably sized window.

What I want is just to give an *initial* size, leaving the user the option
of giving any args [s]he wants, but not forcing him to give one.
Could some kind soul explain to me what is wrong with the sample code below?
(that it doesn't do anything is irelevant !)

All this is in R3, on a DN4500 Apollo, SR10.2.

-------------------------- sample code: simple.c -------------------------- 
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Cardinals.h>
#include <X11/Label.h>

typedef struct {
    Dimension       width, height;
}   AppData,  *AppDataPtr;
   
static XtResource resources[] = {
  { XtNwidth,  XtCWidth,  XtRDimension, sizeof(Dimension),
XtOffset(AppDataPtr, width),  
         XtRString, "640" },
  { XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
XtOffset(AppDataPtr, height), 
         XtRString, "450" }
};

Widget w_top, w_label;
AppData data; Arg args[5];

main(argc, argv) int argc; char *argv[]; {

   w_top = XtInitialize (argv[0], "Xgnuplot", NULL, ZERO, &argc, argv);

   w_label = XtCreateManagedWidget ("Label", labelWidgetClass, w_top,
NULL, ZERO);

   XtGetApplicationResources (w_top, &data, resources,
XtNumber(resources), NULL, ZERO);
   
   printf ("width = %d, height = %d\n", data.width, data.height);
   printf ("Label: width = %d, height = %d\n", GetWidth(w_label),
GetHeight(w_label));
   printf ("Top  : width = %d, height = %d\n", GetWidth(w_top),
GetHeight(w_top));

   XtRealizeWidget(w_top);
   printf ("Label: width = %d, height = %d\n", GetWidth(w_label),
GetHeight(w_label));
   printf ("Top  : width = %d, height = %d\n", GetWidth(w_top),
GetHeight(w_top));

   XtMainLoop();
   }

int GetWidth(w)
Widget w;
{
	Dimension width; Arg args[1];

	XtSetArg(args[0], XtNwidth, &width); XtGetValues( w, args, (Cardinal)1 );
	return (int)width;
}
int GetHeight(w)
Widget w;
{
	Dimension height;Arg args[1];

	XtSetArg(args[0], XtNheight, &height); XtGetValues( w, args, (Cardinal)1 );
	return (int)height;
}

------------------------------------------------------------------------- 

Thanks in advance for your help !


Michel KERN               |   Tel. (33) (1) 39 63 54 48 
INRIA Rocquencourt        |   E-mail: kern@goofy.inria.fr
78153 Le Chesnay Cedex    |           mcsun!goofy.inria.fr!kern@uunet.uu.net
FRANCE                    |