Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!rutgers!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!bmc.uu.se!heap From: heap@bmc.uu.se Newsgroups: comp.windows.x.motif Subject: bad size default for the XmForm widget Message-ID: <1990Jul11.165130.3364@bmc.uu.se> Date: 11 Jul 90 15:51:30 GMT Organization: Biomedical Center, University of Uppsala, Sweden Lines: 102 Why are the defaults for the initial size of the Form widget so bad ? I create a form with some togglebuttons in (see program below), and one could expect that the form (and the window) would be sized after the sum of the childrens preferred sizes. But no, the window that is created on the screen is very small (so the togglebuttons overlap eachother) and must immediately be resized to be useable. I have tried to set the allowOverlap resource to False in order to prevent overlapping, but it is ignored. The only two fixes I have found are: i) set the size of the form explicitly as a resource (bad solution since I do not know before run-time how many children the form will have, thus making it hard to guess a good size) and ii) find out the preferred size of the children with XtQueryGeometry and change the size of the form explicitly with XtMakeResizeRequest (a bit cludgy). Is there any standard,simple way to get a good default size of the window ? I have not found anything in the book by Young or in the on-line examples on my machine. I'm using a HP-300 running HP-UX 7.0, Motif 1.0 and X11 R3 Thank you in advance for any help on this. ---------------------------------------------------------------------- #include #include #include #include #include #include main(argc, argv) int argc; char *argv[]; { Arg args[5]; XtAppContext app; Display *dpy; XEvent event; Widget toplevel; Widget form,radiob[3]; XtToolkitInitialize(); app = XtCreateApplicationContext(); dpy = XtOpenDisplay(app,"",argv[0], "Test", NULL, 0, &argc, argv); toplevel = XtAppCreateShell(argv[0],"Test",applicationShellWidgetClass, dpy,NULL,0); form = XmCreateForm(toplevel,"form",NULL,0); XtManageChild(form); radiob[0] = XmCreateToggleButton(form,"radiob1",NULL,0); radiob[1] = XmCreateToggleButton(form,"radiob2",NULL,0); radiob[2] = XmCreateToggleButton(form,"radiob3",NULL,0); XtManageChildren(radiob,3); XtRealizeWidget(toplevel); while (TRUE) { XtAppNextEvent(app,&event); XtDispatchEvent(&event); } } ---------------------------------------------------------------------- Resource file: Test*form*resizable: TRUE Test*form*topAttachment: attach_position Test*form*bottomAttachment: attach_position Test*form*leftAttachment: attach_position Test*form*rightAttachment: attach_position Test*form*leftPosition: 1 Test*form*rightPosition: 99 Test*form*radiob1.topPosition: 1 Test*form*radiob1.bottomPosition: 33 Test*form*radiob2.topPosition: 34 Test*form*radiob2.bottomPosition: 66 Test*form*radiob3.topPosition: 67 Test*form*radiob3.bottomPosition: 99 ---------------------------------------------------------------------- Code for fix #2: .. #define MAX(a,b) ((a) > (b) ? (a) : (b)) .. XtWidgetGeometry preferred; XtGeometryResult result; Dimension reqheight,reqwidth,*retwidth,*retheight; .. /* Find out the size of a togglebutton and set size explicitly on the form */ XtQueryGeometry(radiob[0],NULL,&preferred); reqheight = 3*preferred.height + 6*preferred.border_width; reqwidth = preferred.width; retwidth = (Dimension *)XtMalloc(sizeof(Dimension)); retheight = (Dimension *)XtMalloc(sizeof(Dimension)); result = XtMakeResizeRequest(form,reqwidth,reqheight,retwidth,retheight); -- ---------------------------------------------------------------------- Per Bengtsson, Dept. of Scientific Computing, Univ. of Uppsala, Sweden Internet: heap@tdb.uu.se Sunet/Decnet: tdb::heap ----------------------------------------------------------------------