heap@bmc.uu.se (07/11/90)
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 <X11/StringDefs.h> #include <X11/Intrinsic.h> #include <X11/Shell.h> #include <Xm/Xm.h> #include <Xm/RowColumn.h> #include <Xm/ToggleB.h> 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 ----------------------------------------------------------------------
carl@quad1.quad.com (Carl Priddy) (07/12/90)
The form widget provides a couple of interesting ways of ensuring that everything is visible and in the geometry that you desire. Using the XmNxxxAttachment resource as Xm_ATTACH_FORM, you can specify attachments to the sides of the form itself. Using it as Xm_ATTACH_WIDGET, you can attach the "inside" widgets to each other. I used the XmATTACH_FORM for the attachments, and then used the XmNxxxOffset resource to specify the top and left offsets within the form. I did this because I have no a priori knowledge of how many children the Form will have, or what their sizes are. The form changes size to accomodate it's children. carl priddy
ben@HPCVXBEN.CV.HP.COM (Benjamin Ellsworth) (07/12/90)
> Why are the defaults for the initial size of the Form widget so bad ? The 1.0 Form does not calculate its initial size correctly in many cases (the most common being child attachments to the bottom or right edge of the Form). > ... I have tried to set the allowOverlap resource to False in order > to prevent overlapping, but it is ignored. The allowOverlap resource is an artifact of the class heirarchy of the Form--it comes from BulletinBoard--and is ignored. This is true in 1.1 also. There is some chance that this resource will be honored at some time in the future. > Is there any standard, simple way to get a good default size of the > window ? There is no simple answer. The "standard" answer is to set up a map callback and in that callback query all of the children for their size, do the necessary calculations and size the form accordingly. Good Luck! ----------------------------------------------------------------------- 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. -----------------------------------------------------------------------