3
我正在嘗試使用DrawingAreas,而且事情並不按我期望的方式工作。我應該如何使用X11,motif,DrawingArea和C++來設置DrawingArea(X,Y)座標(0,0)
#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);
}
}
當我進入窗口,與我的指針離開窗口,我得到的輸出:
(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)
爲什麼不XtVaSetValues設置BOX1到(X,Y)=(0,0) ?我怎樣才能在窗口內的(0,0)處放置一個繪圖區?
我想出答案,但沒有信譽爲它:
XtManageChild(box1);
XtUnmanageChild(box1);
XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtMapWidget(box1);
它看起來像調用XtManageChild()正在調用父級的change_managed過程: http://linux.die.net/man/3/xtmanagechild –
現在你應該有代表。提供答案。 – ypnos