Path: utzoo!utgpu!watmath!iuvax!mailrus!ncar!redcloud!clyne From: clyne@redcloud.ucar.edu (John Clyne) Newsgroups: comp.windows.x Subject: help with athena text widget Message-ID: <4015@ncar.ucar.edu> Date: 17 Aug 89 20:39:04 GMT Reply-To: clyne@ncar.ucar.edu (John Clyne) Organization: Scientific Computing Division/NCAR, Boulder CO Lines: 80 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#include #include #include 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(); }