📄 test15.c
字号:
Test3(Widget W){WidgetList kids;Cardinal numkids;XtWidgetGeometry Form;XtWidgetGeometry Kid1;XtWidgetGeometry Kid2; fprintf(stderr,"Test 3 starting...\n"); XtVaGetValues(W, XmNchildren, &kids, XmNnumChildren, &numkids, XmNx, &Form.x, XmNy, &Form.y, XmNwidth, &Form.width, XmNheight, &Form.height, NULL); XtVaGetValues(kids[TOPLABEL], XmNx, &Kid1.x, XmNy, &Kid1.y, XmNwidth, &Kid1.width, XmNheight, &Kid1.height, XmNborderWidth, &Kid1.border_width, NULL); XtVaGetValues(kids[BOTLABEL], XmNx, &Kid2.x, XmNy, &Kid2.y, XmNwidth, &Kid2.width, XmNheight, &Kid2.height, XmNborderWidth, &Kid2.border_width, NULL); XtVaSetValues(kids[TOPLABEL], XmNrightAttachment, XmATTACH_NONE, XmNwidth, Kid1.width * 4, NULL); ExpectedResults[0].request_mode = CWWidth | CWHeight; ExpectedResults[0].x = 0; ExpectedResults[0].y = 0; ExpectedResults[0].width = Kid1.width * 4 + 2 * Kid1.border_width; ExpectedResults[0].height = Form.height; ExpectedResults[1].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[1].x = 0; ExpectedResults[1].y = 0; ExpectedResults[1].width = Kid1.width * 4; ExpectedResults[1].height = Kid1.height; ExpectedResults[2].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[2].request_mode = 0; ExpectedResults[2].x = 0; ExpectedResults[2].y = 0; ExpectedResults[2].width = 0; ExpectedResults[2].height = 0; printf("Test 3\n"); FinishTest(W); return(True);}static BooleanTest2(Widget W){Dimension h,w;Dimension ch,cw,bw,mw;Position cx,cy;WidgetList kids;Cardinal numkids;int i;XmString string;XmFontList font_list; fprintf(stderr,"Test 2 starting...\n"); XtVaGetValues(W, XmNchildren, &kids, XmNnumChildren, &numkids, NULL); XtVaSetValues(kids[TOPLABEL], XmNbottomAttachment, XmATTACH_NONE, NULL); for (i = 1; i<numkids; i++) { XtUnmanageChild(kids[i]); } XtVaGetValues(kids[TOPLABEL], XmNlabelString, &string, XmNfontList, &font_list, XmNborderWidth, &bw, XmNmarginWidth, &mw, XmNwidth, &cw, NULL); ExpectedResults[1].width = XmStringWidth(font_list,string) + 2 * mw; XmStringFree(string); ExpectedResults[0].request_mode = CWWidth | CWHeight; ExpectedResults[0].x = 0; ExpectedResults[0].y = 0; ExpectedResults[0].width = ExpectedResults[1].width + 2 * bw; ExpectedResults[0].height = 19; ExpectedResults[1].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[1].x = 0; ExpectedResults[1].y = 0; ExpectedResults[1].height = 17; ExpectedResults[2].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[2].request_mode = 0; ExpectedResults[2].x = 0; ExpectedResults[2].y = 0; ExpectedResults[2].width = 0; ExpectedResults[2].height = 0; printf("Test 2 Unmanage all but the first child\n"); FinishTest(W); return(True);}static BooleanTest1(Widget W){Dimension h,w;Dimension ch,cw,bw;Position cx,cy;WidgetList kids;Cardinal numkids; XtVaGetValues(W, XmNchildren, &kids, XmNnumChildren, &numkids, XmNwidth, &w, XmNheight, &h, NULL); ExpectedResults[0].request_mode = CWWidth | CWHeight; ExpectedResults[0].x = 0; ExpectedResults[0].y = 0; ExpectedResults[0].width = w * 2; ExpectedResults[0].height = h * 2; XtVaGetValues(kids[TOPLABEL], XmNborderWidth, &bw, NULL); ExpectedResults[1].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[1].x = 0; ExpectedResults[1].y = 0; ExpectedResults[1].width = w * 2 - 2 * bw; ExpectedResults[1].height = h * 2 - 4 * bw - 17; ExpectedResults[2].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[2].x = 0; ExpectedResults[2].y = h * 2 - 2 * bw - 17; ExpectedResults[2].width = w * 2 - 2 * bw; ExpectedResults[2].height = 17; XtVaSetValues(W, XmNwidth, w * 2, XmNheight, h * 2, NULL); printf("Test 1 double form height and width\n"); FinishTest(W); return(True);}static Boolean (*TestList[])() = { Test1, Test2, Test3, Test4, Test5, /* Test6, */NULL};static voidPrintWidgetDetails(Widget W, int index){Position x,y;Dimension h,w;Boolean Result;XtGeometryMask mode; if (!XtIsManaged(W)) return; mode = ExpectedResults[index].request_mode; w = h = x = y = 0; XtVaGetValues(W, XmNwidth, &w, XmNheight, &h, XmNx, &x, XmNy, &y, NULL); Result = (mode & CWX ? ExpectedResults[index].x == x : True) && (mode & CWY ? ExpectedResults[index].y == y : True) && (mode & CWWidth ? ExpectedResults[index].width == w : True) && (mode & CWHeight ? ExpectedResults[index].height == h : True); GlobalResult1 = GlobalResult1 && Result; printf("%14s x %-4i(%4i) y %-4i(%4i) w %-4i(%4i) h %-4i(%4i) %s\n",XtName(W), x, (ExpectedResults[index].request_mode & CWX ? ExpectedResults[index].x : x), y, (ExpectedResults[index].request_mode & CWY ? ExpectedResults[index].y : y), w, (ExpectedResults[index].request_mode & CWWidth ? ExpectedResults[index].width : w), h, (ExpectedResults[index].request_mode & CWHeight ? ExpectedResults[index].height : h), Result ? "Good" : "Bad");}static Boolean_PrintDetails(Widget W){int i;WidgetList kids;Cardinal numkids; XmUpdateDisplay(W); PrintWidgetDetails(W, 0); if (XmIsForm(W)) { XtVaGetValues(W, XmNchildren, &kids, XmNnumChildren, &numkids, NULL); for (i=0; i<numkids; i++) { PrintWidgetDetails(kids[i], i+1); } printf("\n"); } return(True);}static voidPrintDetails(Widget W){ XtAppAddTimeOut(XtWidgetToApplicationContext(W), 0, (XtTimerCallbackProc)_PrintDetails, W);}static voidEvent(Widget W, Widget w){ printf("Event %s %s\n",XtName(W),XtName(w)); PrintDetails(w);}static BooleanDoAllTests(Widget W){static int TestNumber = 0; if (TestList[TestNumber] != NULL) { (*TestList[TestNumber])(W); TestNumber++; } else { printf("%s\n",GlobalResult1 ? "All tests passed" : "One or more tests failed"); if (AppResources.autoExit) exit(0); } return(True);}static voidFinishTest(Widget W){ PrintDetails(W); XtAppAddTimeOut(XtWidgetToApplicationContext(W), AppResources.time, (XtTimerCallbackProc)DoAllTests, W);}intmain(int argc, char **argv){ Widget toplevel, Form, BottomLabel, TopLabel; XtSetLanguageProc(NULL, NULL, NULL); toplevel = XtVaAppInitialize(&app, "Form1", opTable, XtNumber(opTable), &argc, argv, FallBack, NULL); XtGetApplicationResources(toplevel, &AppResources, resources, XtNumber(resources), NULL,0); XtVaSetValues(toplevel, XmNresizePolicy, XmRESIZE_ANY, XmNallowShellResize, True, NULL); Form = XmCreateForm(toplevel,"Form",NULL,0); XtVaSetValues(Form, XmNresizePolicy, XmRESIZE_ANY, XmNallowShellResize, True, NULL); TopLabel = XmCreateLabel(Form, "TopLabelTop", NULL, 0); BottomLabel = XmCreateLabel(Form, "BottomLabel", NULL, 0); ExpectedResults = (XtWidgetGeometry *)XtMalloc(3 * sizeof(XtWidgetGeometry)); ExpectedResults[0].request_mode = CWWidth | CWHeight; ExpectedResults[0].x = 72; ExpectedResults[0].y = 38; ExpectedResults[0].width = 72; ExpectedResults[0].height = 38; XtVaSetValues(TopLabel, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, BottomLabel, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); XtManageChild(TopLabel); ExpectedResults[1].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[1].x = 0; ExpectedResults[1].y = 0; ExpectedResults[1].width = 70; ExpectedResults[1].height = 17; XtVaSetValues(BottomLabel, XmNtopAttachment, XmATTACH_NONE, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); XtManageChild(BottomLabel); ExpectedResults[2].request_mode = CWX | CWY | CWWidth | CWHeight; ExpectedResults[2].x = 0; ExpectedResults[2].y = 19; ExpectedResults[2].width = 70; ExpectedResults[2].height = 17; XtManageChild(Form); XtAddEventHandler(TopLabel, ButtonPressMask, True, (XtEventHandler)Event, Form); XtAddEventHandler(BottomLabel, ButtonPressMask, True, (XtEventHandler)Event, Form); XtRealizeWidget(toplevel); printf("Initial\n"); XtVaSetValues(TopLabel, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, BottomLabel, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); XtVaSetValues(BottomLabel, XmNtopAttachment, XmATTACH_NONE, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); PrintDetails(Form); /* I would like to wait until the window manager has placed the thing */ XtAppAddTimeOut(app, AppResources.time, (XtTimerCallbackProc)DoAllTests, Form); XtAppMainLoop(app); /* LessTifTestMainLoop(toplevel); */ exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -