From: pprun@lookout.mnet.uswest.com
Subject: Re: More popup positioning troubles
Organization: US WEST Communications
Date: Thu, 27 Aug 1992 19:41:07 GMT

>> No matter if I set the resources [XtNx & XtNy] before the widget
>> creation call or just before the XtPopup call with an XtSetValues,
>> the shell goes where ever it please (and not always the same
>> place).  In my befuddled mind, this points to the window manager
>> playing the part of the bad guy.

>I'm a little surprised because I routinely use this method to position
>shells.  Make sure you are setting it on the Shell and not the child
>of the Shell.  Also, make sure you are using coordinates relative to
>the root window.  Can you post a _short_ code fragment/example?


Since I posted this (I'm the one who started this), I've gotten many
replies (thanks, everyone).  Most people suggested setting XtNx & XtNy.
Sorry people, as I mentioned I tried this, both as the widget is
created and with the XtPopup call.  A few people mentioned setting
XmNdefaultPosition to False.  I already knew about this.  One kind
soul, ironically who works in my building, mentioned setting the
position using the XtNgeometry resource.  BINGO!  Simply substituting
the XtNgeometry for the XtNx & XtNy, with no other changes, worked the
first time.  Now perhaps this is a bug with the X-Motif I am using
(ICS Motif 1.1 on Sun SparcStation 2), but I find it quite interesting
that XtNgeometry works in the same code where XtNx & XtNy don't work.
Keep in mind that I am trying to position popup shells of the 
topLevelShellWidgetClass variety, and I am not using them for popup
menus.  And to answer the questions posed above:

     - Yes, I was setting them on the shell, not any kids.  I am not
using dialogs, but my own shells created by XtCreatePopupShell.

     - My test coordinates were (1,1).  Besides, the placement changed
every time I ran the executable.

     - For the atheists among you, here is the desired code.  This is a
complete program.  In the displayed form, the shells will not be 
positioned properly.  Uncomment the two // lines and comment out the
setting of XtNx & XtNy lines to make it work correctly.

#include <stdarg.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/MwmUtil.h>
#include <Xm/BulletinB.h>
#include <Xm/Label.h>

void query_widget(Widget parent)
{
  Widget         widget_array[5];
  Arg            args[10];
  int            n;
  XmString       xms;

  n = 0;
//  XtSetArg(args[n], XtNgeometry, "+10+300"); n++;
  XtSetArg(args[n], XmNx, 10); n++;
  XtSetArg(args[n], XmNy, 300); n++;
  XtSetArg(args[n], XmNdefaultPosition, False); n++;
  widget_array[0] = XtCreatePopupShell
    ("query", topLevelShellWidgetClass, parent, args, n);

  n = 0;
  XtSetArg(args[n], XmNdefaultPosition, False); n++;
  XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  XtSetArg(args[n], XtNheight, 222); n++;
  XtSetArg(args[n], XtNwidth, 678); n++;
  widget_array[1] =
    XmCreateBulletinBoard(widget_array[0], "queryBB", args, n);

  n = 0;
  XtSetArg(args[n], XmNx, 19); n++;
  XtSetArg(args[n], XmNy, 71); n++;
  xms = XmStringCreateSimple("Customer:");
  XtSetArg(args[n], XmNlabelString, xms); n++;
  widget_array[2] =
    XmCreateLabel(widget_array[1], "customer", args, n);
  XmStringFree(xms);

  XtManageChild(widget_array[1]);
  XtManageChild(widget_array[2]);
  XtPopup(widget_array[0], XtGrabNone);
}

main (int argc, char **argv)
{
Widget         parent ;
XtAppContext   app ;
Arg            args[10];
int            n;

n = 0 ;
//XtSetArg(args[n], XtNgeometry, "+1+1"); n++;
XtSetArg(args[n], XmNx, 1); n++;
XtSetArg(args[n], XmNy, 1); n++;
XtSetArg(args[n], XtNheight, 250); n++;
XtSetArg(args[n], XtNwidth, 250); n++;
XtSetArg(args[n], XmNdefaultPosition, False); n++;
XtSetArg(args[n], XmNmappedWhenManaged, True); n++;
parent = XtAppInitialize(&app, "ssnq", NULL, 0,
             (Cardinal *) &argc, argv, NULL, args, n) ;

query_widget(parent);
XtRealizeWidget(parent);
XtAppMainLoop(app);
}


I don't know if it matters, but the compiler used is C++.

On a different note, the Motif code is originally generated from TeleUSE.
We are drawing the interface using TeleUSE vip and then converting the pcd
to C.  The C is encapsulated into a view (model-view-controller scheme).
There is a bit of massaging but a few thousand lines of Motif code can
be executed in about 30 minutes (from pcd file to standalone executable).
Enough babbling.


Pete
pprun@lookout.mnet.uswest.com


Newsgroups: comp.windows.x.intrinsics