Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!unido!sapwdf!wohler From: wohler@sapwdf.UUCP (Bill Wohler) Newsgroups: comp.windows.x.motif Subject: Re: How do I center a widget inside an XmForm? Keywords: x motif form center widget Message-ID: <2860@sapwdf.UUCP> Date: 6 Jun 91 10:43:59 GMT References: <64526@bbn.BBN.COM> Reply-To: Bill Wohler Organization: SAP AG, Walldorf, Germany Lines: 54 [same question within a month. must be a FAQ...] news@bbn.com (News system owner ID) writes: > - attach the CENTER of the widget to the CENTER of the form, in > either the x or y dimensions (or both) ron, here is where a previous discussion has led. i have yet to implement it, but perhaps you can run with the ideas. let us know what you find. --bw Bill Wohler writes: > > that's a little better, but you still have to know the width of your > text in the button and the width of the parent. before your widget > is managed and realized, these values are a little hard to come by. > perhaps you know of some tricks of realizing a widget, getting some > values and then setting some values (in this case, the location of a > button) with a minimal light show (windows flashing on and off). Just because a widget is managed, it does not mean that it is mapped. See XmNmappedWhenManaged. You can realize and manage the widget, change values and then map it after you get it the way you want. The "getting" of values can be via XtGetValues in most cases. However, sometimes this is buggy in Motif, returning nonsensical values. There- fore I wrote macros that extract x, y, width and height from core be- cause they are always right. I then placed them in a getWidgetGeometry routine so I could do it the "right" way if the problem with garbage return values is ever universally fixed. As far as the size of the parent goes, this is a similar problem. However, I would think that the size of the parent is less dynamic. If that is not the case, and the size of the parent is varying, and you want to keep the child centered, but a constant size, do it on the fly as follows: Create and Manage parent. Create Managed child with mapped when managed False. Check out the width of the parent and the width of the resultant child. Do your centering calculation. Use XtSetValues to move the widget to the desired location or attachment offset. Map the widget. Larry Rogers larry@boris.webo.dg.com -- --bw ----- Bill Wohler Heidelberg Red Barons Ultimate Frisbee Team