How should I use X11, motif, DrawingArea, and c++ to set the DrawingArea (X,Y) coordinate (0,0)
Question
I am trying to work with DrawingAreas and things aren't working the way I expected.
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
main(int argc, char *argv[])
{
Widget shell, workArea, box1;
XtAppContext app;
shell = XtVaAppInitialize(&app, "gp", NULL, 0, &argc, argv, NULL, XmNwidth, 500, XmNheight, 500, NULL);
XtRealizeWidget(shell);
workArea = XtCreateWidget("wa",xmDrawingAreaWidgetClass, shell, NULL, 0);
XtVaSetValues(workArea, XmNbackground, 30000, NULL);
box1 = XtCreateWidget("b1", xmDrawingAreaWidgetClass, workArea, NULL, 0);
XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtManageChild(workArea);
XtManageChild(box1);
//XtAppMainLoop(app);
XEvent event;
Dimension x,y,w,h;
while(1)
{
XtAppNextEvent(app, &event);
if (event.type == EnterNotify)
{
XtVaGetValues(box1, XmNx, &x, XmNy, &y, XmNwidth, &w, XmNheight, &h, NULL);
printf("(x,y,w,h) == (%d,%d,%d,%d)\n", x, y, w, h);
}
if (event.type == LeaveNotify)
{
XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
printf("tried to set (x,y,w,h) = (0,0,400,400)\n");
}
XtDispatchEvent(&event);
}
}
When I enter the window and leave the window with my pointer I get output:
(x,y,w,h) == (10,10,400,400)
(x,y,w,h) == (10,10,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
(x,y,w,h) == (10,10,400,400)
(x,y,w,h) == (10,10,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
Why doesn't the XtVaSetValues set box1 to (X,Y) = (0,0)? How can I accomplish placing a Drawing area at (0,0) within the window?
I figured out the answer but don't have the reputation to provide it:
XtManageChild(box1);
XtUnmanageChild(box1);
XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtMapWidget(box1);
Solution
It looks like the call to XtManageChild() is calling the parent's change_managed procedure:
xtmanpage
In order to set the (x,y) to (0,0), I must make sure that the widget is not managed:
XtManageChild(box1); // must be called once
XtUnmanageChild(box1); // unmanage to allow (0,0)
XtVaSetValues(box1, NmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtMapWidget(box1); // show the widget
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow