1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <Xm/BulletinB.h>
5 #include <Xm/GrabShell.h>
6 #include <Xm/PushB.h>
7 #include <Xm/Label.h>
8
9 #include "../../common/Test.h"
10
11 /*
12 This tests synchronous grabs and owner events.
13 */
14
15 Widget grabshell;
16
17 void
check_geometry()18 check_geometry()
19 {
20 static int result_index = 0;
21
22 static XtWidgetGeometry Expected[] =
23 {
24 /* result test 0 */
25 CWWidth | CWHeight , 0, 0, 70, 17, 0,0,0, /* Hello World */
26 CWWidth | CWHeight | CWX | CWY, 0, 100, 42, 25, 0,0,0, /* hello */
27 /* result test 1 */
28 CWWidth | CWHeight , 2, 2, 70, 17, 0,0,0, /* Hello World */
29 CWWidth | CWHeight | CWX | CWY, 0, 100, 42, 25, 0,0,0, /* hello */
30 };
31
32 if (result_index <= 1)
33 {
34 /* Only have results for two test. Must record more results before
35 doing any further testing otherwise you start looking at bogus
36 memory locations.
37 */
38 #if 0
39 PrintDetails(grabshell, NULL);
40 #endif
41 PrintDetails(grabshell, Expected);
42 result_index ++;
43 }
44 }
45
46 void
onPopup(Widget w,XtPointer mydata,XtPointer cbs)47 onPopup(Widget w, XtPointer mydata, XtPointer cbs)
48 {
49 check_geometry();
50 }
51
onActivate(Widget w,XtPointer mydata,XtPointer cbs)52 void onActivate(Widget w, XtPointer mydata, XtPointer cbs)
53 {
54 Widget grabshell = (Widget) mydata;
55
56 XtPopupSpringLoaded(grabshell);
57
58 #if 0
59 XdbPrintCompleteTree(grabshell);
60 #endif
61 }
62
GrabShellResources(Widget w)63 void GrabShellResources(Widget w)
64 {
65 int grabStyle = -1;
66 Boolean ownerEvents, saveUnder, overrideRedirect;
67 Dimension shadowThickness;
68
69 XtVaGetValues(w,
70 XmNgrabStyle, &grabStyle,
71 XtNoverrideRedirect, &overrideRedirect,
72 XmNownerEvents, &ownerEvents,
73 XtNsaveUnder, &saveUnder,
74 XmNshadowThickness, &shadowThickness,
75 NULL);
76
77
78 fprintf(stderr,"BEGIN_RESOURCE_DUMP\n");
79 fprintf(stderr,"GrabStyle (%d)\n",grabStyle);
80 fprintf(stderr,"OverrideRedirect (%d)\n",(int) overrideRedirect);
81 fprintf(stderr,"OwnerEvents (%d)\n",(int) ownerEvents);
82 fprintf(stderr,"SaveUnder (%d)\n",(int) saveUnder);
83 fprintf(stderr,"ShadowThickness (%d)\n",(int) shadowThickness);
84 fprintf(stderr,"END_RESOURCE_DUMP\n");
85 }
86
87 int
main(int argc,char ** argv)88 main(int argc, char **argv)
89 {
90 int i;
91 Widget toplevel, bb, label, pressme, pb;
92 XtAppContext app;
93 XmString item;
94 Arg args[5];
95
96 XtSetLanguageProc(NULL, NULL, NULL);
97
98 toplevel = XtVaAppInitialize(&app, "GrabShell", NULL, 0, &argc, argv, NULL, NULL);
99
100 bb = XmCreateBulletinBoard(toplevel, "bb", NULL, 0);
101
102 pressme = XmCreatePushButton(bb,"Press me and let's see what the grab shell does.",NULL,0);
103
104 XtManageChild(pressme);
105
106 XtManageChild(bb);
107
108 i = 0;
109 XtSetArg(args[i], XmNownerEvents, True); i++;
110 XtSetArg(args[i], XmNgrabStyle, GrabModeSync); i++;
111 grabshell = XmCreateGrabShell(bb, "grab", args, i);
112 label = XmCreateLabel(grabshell, "Hello World", NULL, 0);
113
114 XtManageChild(label);
115
116 i = 0;
117 XtSetArg(args[i], XmNy, 100); i++;
118 XtSetArg(args[i], XmNx, 0); i++;
119 pb = XmCreatePushButton(grabshell,"hello", args, i);
120 XtManageChild(pb);
121
122 /* setup callback for an activate action */
123 XtAddCallback(pressme,
124 XmNactivateCallback,
125 (XtCallbackProc) onActivate,
126 (XtPointer) grabshell);
127
128 XtAddCallback(grabshell,
129 XmNpopupCallback,
130 (XtCallbackProc) onPopup,
131 (XtPointer) grabshell);
132
133 XtRealizeWidget(toplevel);
134
135 #if 1
136 GrabShellResources(grabshell);
137 #endif
138
139 check_geometry();
140
141 LessTifTestMainLoop(toplevel);
142
143 exit(0);
144 }
145
146