Widget Absolute Coordinates

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
Widget Absolute Coordinates

 

Hi Everyone,

I have been having a hard time understanding how to obtain a Widget's absolute coordinates relative to the upper left hand of the screen.

For instance, if I have a Widget in the middle of the screen and my screen is maximized to cover the full area of my display, I would want the Widget coordinates relative to the screen.

I can obtain the 'relative' coordinates of the Widget relative to the parent Widget. However, I can't seem to get a Widget relative to the Screen.

I have read that I should use 'XtTranslateCoords' to get the screen coordinates of the Widget. However, it only ever seems to return the x,y cordinates relative to the parent Widget.

-----
Position x;
Position y;

Widget widgetMiddleScreen;

/*...*/

XtTranslateCoords(widgetMiddleScreen, (Position)0,(Position)0, &x, &y);

----

For instance, I have the root widget, then I have a frame widget, then I have a button widget within the frame widget that falls in the middle of the Frame. Now, I want to get the x,y coordinates of the button widget (which is in the middle of the display) relative to the Screen and not relative to it's parent (in this case the Frame widget).

Ideas?

Thanks!

Jason

 

 

Re: Widget Absolute Coordinates

 

Ok, I found the problem...

I am calling XtTranslateCoords during creation. Meaning, after I create the widget, I am calling XtTranslateCoords. Now if I call XtTranslateCoords upon the activation of some event, then I do actually get the absolute position of the widget relative to the Screen.

Why is this? I suppose it's because at this point in time the widow for that widget has not been created? After I create the root widget, the Frame, and then the button. At what point can I call XtTranslateCoords?

Thanks,

Jason

 

 

 

 

Re: Widget Absolute Coordinates

 

You must reaslize the top level shell that is an ancestor of the widget in question before you can get anything meaningful from XtTranslateCoordinates. Also, the widget in question and all of its ancestors up to the shell should all be managed.

Think about it. If the top shell has not yet been realized, it has no position. Also, a manager does not give a position to any unmanaged children.

--
Fred K.