139)+ How do I obtain the size of a unmanaged shell widget?

Answer: In the code below, use getsize() for widgets which have been managed,
and getsize2() for newly created shell widgets which have not yet been
managed.

getsize2() takes two widget parameters because popup dialogs etc.  _consist_
of two separate widgets - the parent shell and the child bulletin board, form,
whatever.  This important distinction (somewhat glossed over in the Motif
manuals) is the cause of a large number of queries in comp.windows.x.motif.
XmCreate...Dialog() functions return the (bulletin board, form, whatever)
_child_ of the pair, not the parent shell.

getsize2() takes the _shell_ widget as it's first parameter, and the shell's
_child_ (the bulletin board, form, whatever) as it's second.  Thus, if you are
using code like widget = XmCreate...Dialog() to create your popup dialogs, use
code like getsize2(XtParent(widget),widget,&width,&height) to get the width
and height. If you use e.g. XmCreateDialogShell() or XtCreatePopupShell(),
then you are creating the the shell widget and it's child explicitly, and can
just pass them into getsize2() with no problem.

Note: getsize2() calls getsize().

/* getsize(widget,width,height);
 * Widget widget;
 * int *width,*height;
 *
 * returns the width and height of a managed widget */




void getsize(l,w,h) Widget l; int *w,*h; { Dimension w_,h_,b_;

static Arg size_args[] =
  {
  { XmNwidth,0 },
  { XmNheight,0 },
  { XmNborderWidth,0 },
  };

size_args[0].value = (XtArgVal)&w_; size_args[1].value = (XtArgVal)&h_;
size_args[2].value = (XtArgVal)&b_;

XtGetValues(l,size_args,3);

if (w) *w = w_ + b_; if (h) *h = h_ + b_; } /*
getsize2(shell,child,width,height);
 * Widget shell,child;
 * int *width,*height;
 *
 * returns the width, height of an unmanaged shell widget */

void getsize2(p,c,w,h) Widget p,c; int *w,*h; { XtSetMappedWhenManaged(p,0);

XtManageChild(c);

getsize(p,w,h);

XtUnmanageChild(c);

XtSetMappedWhenManaged(p,-1); } submitted by: [ Huw Rogers  Communications
Software Engineer, NEC Corporation, Tokyo, Japan ] [ Email:
rogersh@ccs.mt.nec.co.jp  Fax: +81-3-5476-1005  Tel: +81-3-5476-1096 ]
Go Back Up

Go To Previous

Go To Next