clyne@redcloud.ucar.edu (John Clyne) (08/18/89)
Can someone please take the time to tell me why the following simple peace
of code won't work. I am trying to retrieve the font used by a text
widget in order to calculate the length of the string to be displayed
in said widget so that I may resize the text widget accordingly.
The problem is I can't seem to get the font using XtGetValues. The
documentation (ha ha) from MIT on athena widgets mentions something about
not being able to return the font resource with XtTextGetValue() but
nothing about XtGetValues(). If the font resource in fact cannot be
retrieved via XtGetValues ... then how do you do it?? Or is there
a more simple way to tell the athen text widget to resize itelf to the
width of the longest line?
thanks - jc
John Clyne (clyne@ncar.ucar.edu)
c/o
National Center for Atmospheric Research
P.O. Box 3000
Boulder, Colorado 80307
(303) 497-1236
%%% Its a small world. But I wouldn't want to paint it %%%
S. Wright
%%% %%%
/* $XConsortium: xtext.c,v 1.8 88/10/05 13:14:34 swick Exp $ */
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/AsciiText.h>
#include <stdio.h>
static char default_value[] =
"This is a\ntest. If this\nhad been an actual\nemergency...";
main(argc, argv)
unsigned int argc;
char **argv;
{
Arg args[5];
int len, width, height;
Widget toplevel;
Widget text;
XFontStruct font;
char *index();
toplevel = XtInitialize("textTest", "Demo", NULL, 0,
&argc, argv);
XtSetArg(args[0], XtNstring, default_value);
text = XtCreateManagedWidget( argv[0], asciiStringWidgetClass,
toplevel, args, 1);
/*
* get the font used by the text widget
*/
XtSetArg(args[0], XtNfont, &font);
XtSetArg(args[1], XtNwidth, &width);
XtSetArg(args[2], XtNheight, &height);
XtGetValues(text, args, 3);
/*
* calculate the length of our string in pixels
*/
len = XTextWidth(&font, default_value, strlen(default_value));
/*
* change width of text widget to width of string
*/
XtSetArg(args[0], XtNwidth, len);
XtSetValues(text, args, 1);
XtRealizeWidget(toplevel);
XtMainLoop();
}
kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/18/89)
> Can someone please take the time to tell me why the following simple peace > of code won't work. Because the text widget DOES NOT SUPPORT retrieving the font with XtGetValues. This is a bug, and I hope to fix it soon, but I am really busy. [ Don't bother sending code on this one, the "right" fix requires some functionality that is not defined in R3. ] > The documentation (ha ha) from MIT on athena widgets mentions something about > not being able to return the font resource with XtTextGetValue() but > nothing about XtGetValues(). XtTextGetValues is a typo it should read XtGetValues. This documentation bug is left over from X11 Beta. Chris D. Peterson MIT X Consortium Net: kit@expo.lcs.mit.edu Phone: (617) 253 - 9608 Address: MIT - Room NE43-213