smithey@esosun.UUCP (Brian Smithey) (09/01/88)
Hi, I'm having trouble centering a popup shell widget within the borders of another widget (in my case, my application's toplevel widget). If anybody has any ideas on how to do this correctly I'd appreciate hearing them. Scenario: I create a toplevel widget and widget tree. Included in the tree are some command widgets, one of them a "quit" button to terminate the application. When the user hits "quit", I go to a callback to handle the command. I want to popup a "confirm/cancel" widget, centered in my toplevel widget window, containing a text string prompt (implemented as a label widget) and confirm/cancel buttons (command widgets). Problems: In order to do the centering, I need to know the position and size of toplevel, and the size of popup. I retrieve the XtNx, XtNy, XtNwidth, and XtNheight resources with XtGetValues(), and the values look fine. The problem arises when I try to retrieve XtNwidth and XtNheight and set XtNx and XtNy of the popup. If I try to retrieve the width and height before the widget has been realized, I get back width == 0 and height == 0. If I XtRealize() the popup before the call to XtGetValues(), the width and height are filled in correctly but my call to XtSetValues() to set the XtNx and XtNy resources seems to have no effect. This is not too surprising, since the Xaw manual says that "Some widgets may not allow certain resources to be modified after the widget instance has been created or realized." If there's a way to do what I'm trying to do, I haven't found it yet. Any ideas? Another problem I've run across is is getting my "quit" command widget to unhighlight. Unhighlighting is done on the <LeaveWindow> event; unfortunately, the XtPopup() causes an XtAddGrab() to take place, causing LeaveNotify events occuring outside the grabbing modal widget to be ignored. My "quit" command widget doesn't get unhighlighted until I popdown the popup and re-enter and leave the command button. Environment: X11R2, Sun 3/50, SunOS 3.3 Thanks for any help, Brian ---------------------------------------------------------------- SAMPLE CODE: /* * At this point, the popup has been created, a form widget * has been added as a child, and a label widget and two * command widgets have been added as children of the form. */ /* * Realize the popup, XtGetValues() gets correct width and * height, but XtSetValues() for x and y position won't * work (popup will appear at screen's (0, 0)). Don't realize * the popup and width and height both come back as 0, but * XtSetValues() for x and y will position the popup. */ /* XtRealizeWidget(popup_shell); */ arg_cnt = 0; args[arg_cnt].name = XtNwidth; args[arg_cnt++].value = (XtArgVal)&popup_width; args[arg_cnt].name = XtNheight; args[arg_cnt++].value = (XtArgVal)&popup_height; XtGetValues(popup_shell, args, arg_cnt); /* Set popup's XtNx and XtNy resources. */ popup_x = toplevel_x + (toplevel_width - popup_width) / 2; popup_y = toplevel_y + (toplevel_height - popup_height) / 2; arg_cnt = 0; args[arg_cnt].name = XtNx; args[arg_cnt++].value = (XtArgVal)popup_x; args[arg_cnt].name = XtNy; args[arg_cnt++].value = (XtArgVal)popup_y; XtSetValues(popup_shell, args, arg_cnt); -- Brian Smithey | Geophysics Division | {ucbvax!ucsd,uunet!seismo}!esosun!smithey Science Applications Int'l Corp. | esosun!smithey@seismo.css.gov San Diego, CA |
diamant@hpfclp.SDE.HP.COM (John Diamant) (09/03/88)
> If I try to retrieve the width and height before the widget has > been realized, I get back width == 0 and height == 0. If I > XtRealize() the popup before the call to XtGetValues(), the > width and height are filled in correctly but my call to XtSetValues() > to set the XtNx and XtNy resources seems to have no effect. The behavior before you realize is to be expected. It doesn't know how big it will be yet. The behavior of the XtSetValues is a bug in the R2 toolkit. You shouldn't do this, but it will work. If you call XtMoveWidget directly, it bypasses the code that is not working. However, this should be removed as soon as you get the R3 toolkit, because what this does is bypass the geometry negotiation that should be occurring. John Diamant Software Development Environments Hewlett-Packard Co. ARPA Internet: diamant@hpfclp.sde.hp.com Fort Collins, CO UUCP: {hplabs,hpfcla}!hpfclp!diamant
fred@hpcvlx.HP.COM (Fred Taft) (09/08/88)
You're on the right track. To center your popup shell, first realize it, then query its height and width. Calculate the x and y where you want the popup shell to appear, and then use XtMoveWidget() to move the shell widget. Our menuing system does this, and it works great!