1 /*
2  * duplicate xmcd's checkbox.
3  * OH, WOE IS ME, THE ORDER OF OPERATIONS MAKES A HUGE DIFFERENCE IN MOTIF
4  * BUT NOT IN LESSTIF.  Sigh -- we're more predictable??!?
5  */
6 #include <stdio.h>
7 #include <Xm/XmP.h>
8 #ifdef LESSTIF_REVISION
9 #include <XmI/XmI.h>
10 #endif
11 #include <Xm/Form.h>
12 #include <Xm/Frame.h>
13 #include <Xm/RowColumnP.h>
14 #include <Xm/ToggleB.h>
15 
16 #ifdef LESSTIF_REVISION
17 #define lt_dump_boxes(a,b,c) dump_boxes(a,b,c)
18 #else
19 #define lt_dump_boxes(a,b,c) NULL
20 #endif
21 void
dump_boxes(WidgetList wl,XmRCKidGeometry boxes,int cnt)22 dump_boxes(WidgetList wl, XmRCKidGeometry boxes, int cnt)
23 {
24     int i;
25 
26     for (i = 0; i < cnt; i++)
27     {
28         printf("Child: %-20s:%p ", XtName(wl[i]), wl[i]);
29 #if 0
30 	if (boxes)
31 	    printf(" box: %-20s:%p\n", XtName(boxes[i].kid), boxes[i].kid);
32 	else
33 	    putchar('\n');
34 #endif
35         printf("       x/y: %3d %3d  w/h: %3d %3d\n",
36                 XtX(wl[i]), XtY(wl[i]), XtWidth(wl[i]), XtHeight(wl[i]));
37 #if 0
38 	if (boxes)
39             printf("   box x/y: %3d %3d  w/h: %3d %3d mt/mb: %3d %3d\n",
40                     boxes[i].box.x, boxes[i].box.y,
41                     boxes[i].box.width, boxes[i].box.height,
42                     boxes[i].margin_top, boxes[i].margin_bottom);
43 	else
44 	    printf("   no box data\n");
45 #endif
46     }
47     putchar('\n');
48 }
49 
50 #define btnlbl_width 16
51 #define btnlbl_height 16
52 static unsigned char btnlbl_bits[] = {
53    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x04, 0x20, 0x84, 0x21,
54    0x44, 0x22, 0x44, 0x22, 0xc4, 0x23, 0x44, 0x22, 0x44, 0x22, 0x04, 0x20,
55    0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
56 };
57 
58 
59 #define lock_width 16
60 #define lock_height 16
61 static unsigned char lock_bits[] = {
62    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x20, 0x04, 0x20, 0x04,
63    0x20, 0x04, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f,
64    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
65 };
66 
67 
68 #define repeat_width 16
69 #define repeat_height 16
70 static unsigned char repeat_bits[] = {
71    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x13,
72    0x0c, 0x31, 0x04, 0x20, 0x04, 0x20, 0x8c, 0x30, 0xc8, 0x1f, 0x80, 0x00,
73    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
74 };
75 
76 
77 #define shuffle_width 16
78 #define shuffle_height 16
79 static unsigned char shuffle_bits[] = {
80    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xcc, 0x00,
81    0x84, 0x0c, 0xc0, 0x3c, 0x60, 0x3c, 0x30, 0x0c, 0x00, 0x00, 0x30, 0x00,
82    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
83 };
84 
85 String fallback[] = {
86 	"*.highlightThickness: 0",
87 	"*.labelType: PIXMAP",
88 	"*XmFrame*highlightThickness: 1",
89 	"*XmFrame*indicatorSize: 13",
90 	"*XmFrame*borderWidth: 1",
91 	"*mainForm.width: 360",
92 	"*mainForm.height: 135",
93 	"*mainForm*borderWidth: 0",
94 	NULL
95 };
96 
97 Pixmap
bm_to_px(Widget w,void * bits,int width,int height,int depth)98 bm_to_px(Widget w, void *bits, int width, int height, int depth)
99 {
100     Display *display = XtDisplay(w);
101     Window win = XtWindow(w);
102     int screen = DefaultScreen(display);
103     Pixmap ret;
104     Pixel fg, bg;
105 
106     XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL);
107 
108     ret = XCreatePixmapFromBitmapData(display, win, (char *)bits,
109 				      width, height, fg, bg, depth);
110 
111     if (ret == None)
112 	return XmUNSPECIFIED_PIXMAP;
113     return ret;
114 }
115 
116 #ifdef LESSTIF_REVISION
117 XmRCKidGeometry
_XmRCGetKidGeo(Widget w,Widget instig,XtWidgetGeometry * instig_request,int uniform_border,Dimension border,int uniform_width_margins,int uniform_height_margins,Widget help,Widget toc,int geoType)118 _XmRCGetKidGeo(Widget w, Widget instig,
119                XtWidgetGeometry *instig_request,
120                int uniform_border, Dimension border,
121                int uniform_width_margins, int uniform_height_margins,
122                Widget help, Widget toc, int geoType)
123 {
124     int i;
125     XmRCKidGeometry kid_geometry;
126     Dimension mmt = 0, mmb = 0;
127     XmRCKidGeometry boxes = NULL;
128 
129 printf("%s GET KID GEO: Type: %d %p %p ", XtName(w), geoType, instig, instig_request);
130 if (instig)
131 	printf("%s\n", XtName(instig));
132 else
133 	printf("\n");
134 
135     boxes = (XmRCKidGeometry)XtCalloc(MGR_NumChildren(w) + 1,
136                                       sizeof(XmRCKidGeometryRec));
137     for (i = 0; i < MGR_NumChildren(w); i++)
138     {
139         kid_geometry = &(boxes[i]);
140         kid_geometry->kid = MGR_Children(w)[i];
141 
142 
143         if (!XtIsManaged(kid_geometry->kid))
144         {
145             if (RCC_WasManaged(kid_geometry->kid))
146             {
147                 RCC_WasManaged(kid_geometry->kid) = False;
148             }
149             continue;
150         }
151 
152         _XmGeoLoadValues(kid_geometry->kid, geoType,
153                              instig, instig_request, &kid_geometry->box);
154 
155 
156         RCC_WasManaged(kid_geometry->kid) = True;
157 
158         kid_geometry->box.width += (2 * XtBorderWidth(kid_geometry->kid));
159         kid_geometry->box.height += (2 * XtBorderWidth(kid_geometry->kid));
160 
161         if (mmt < RCC_MarginTop(kid_geometry->kid))
162             mmt = RCC_MarginTop(kid_geometry->kid);
163         if (mmb < RCC_MarginBottom(kid_geometry->kid))
164             mmb = RCC_MarginBottom(kid_geometry->kid);
165     }
166 
167     for (i = 0; i < MGR_NumChildren(w); i++)
168     {
169         kid_geometry = &(boxes[i]);
170 
171         if (!XtIsManaged(kid_geometry->kid) || !RC_DoMarginAdjust(w))
172             continue;
173 
174         if (mmt > kid_geometry->margin_top)
175             kid_geometry->margin_top = mmt;
176         if (mmb > kid_geometry->margin_bottom)
177             kid_geometry->margin_bottom = mmb;
178     }
179 
180     return boxes;
181 }
182 #endif
183 void
_XmRCSetKidGeo(XmRCKidGeometry kg,Widget instigator)184 _XmRCSetKidGeo(XmRCKidGeometry kg, Widget instigator)
185 {
186     /* Now we actually lay out our children.  */
187     while (kg->kid != NULL)
188     {
189         if (kg->kid == instigator)
190         {
191             XtX(instigator) = kg->box.x;
192             XtY(instigator) = kg->box.y;
193             XtWidth(instigator) = kg->box.width;
194             XtHeight(instigator) = kg->box.height;
195             instigator->core.border_width = kg->box.border_width;
196         }
197         else if (kg->box.x != XtX(kg->kid) ||
198                  kg->box.y != XtY(kg->kid) ||
199                  kg->box.width != XtWidth(kg->kid) ||
200                  kg->box.height != XtHeight(kg->kid) ||
201                  kg->box.border_width != XtBorderWidth(kg->kid))
202             _XmConfigureObject(kg->kid,
203                                kg->box.x, kg->box.y,
204                                kg->box.width, kg->box.height,
205                                kg->box.border_width);
206         kg++;
207     }
208 }
209 
210 int
main(int argc,char ** argv)211 main(int argc, char **argv)
212 {
213 	XtAppContext app;
214 	Arg arg[10];
215 	Widget toplevel, form, frame, rc, t1, t2, t3, t4;
216 	int i;
217 	Pixmap px;
218 	Boolean rw, rh;
219 
220 	toplevel = XtVaAppInitialize(&app, "rc-test23", NULL, 0,
221 				     &argc, argv, fallback, NULL);
222 
223 	form = XmCreateForm(toplevel, "mainForm", NULL, 0);
224 
225 	frame = XmCreateFrame(form, "frame", NULL, 0);
226 
227 	i = 0;
228 	XtSetArg(arg[i], XmNrowColumnType, XmWORK_AREA); i++;
229 	XtSetArg(arg[i], XmNnumColumns, 1); i++;
230 	XtSetArg(arg[i], XmNspacing, 2); i++;
231 	XtSetArg(arg[i], XmNmarginHeight, 4); i++;
232 	XtSetArg(arg[i], XmNorientation, XmVERTICAL); i++;
233 	XtSetArg(arg[i], XmNisHomogeneous, True); i++;
234 	XtSetArg(arg[i], XmNentryClass, xmToggleButtonWidgetClass); i++;
235 	rc = XmCreateRowColumn(frame, "checkBox", arg, i);
236 
237 	t1 = XmCreateToggleButton(rc, "button_0", NULL, 0);
238 	t2 = XmCreateToggleButton(rc, "button_1", NULL, 0);
239 	t3 = XmCreateToggleButton(rc, "button_2", NULL, 0);
240 	t4 = XmCreateToggleButton(rc, "button_3", NULL, 0);
241 
242 	printf("Before managing...\n");
243 	lt_dump_boxes(MGR_Children(rc), RC_Boxes(rc), MGR_NumChildren(rc));
244 
245 	XtManageChild(form);
246 	XtManageChild(frame);
247 	XtManageChild(rc);
248 	XtManageChild(t1);
249 	XtManageChild(t2);
250 	XtManageChild(t3);
251 	XtManageChild(t4);
252 
253 	XtVaGetValues(rc, XmNresizeWidth, &rw, XmNresizeHeight, &rh, NULL);
254 	printf("RW: %d RH: %d\n", rw, rh);
255 
256 	printf("After managing...\n");
257 	lt_dump_boxes(MGR_Children(rc), RC_Boxes(rc), MGR_NumChildren(rc));
258 
259 	XtVaSetValues(frame,
260 			XmNleftAttachment, XmATTACH_POSITION,
261 			XmNleftPosition, 0,
262 			XmNrightAttachment, XmATTACH_POSITION,
263 			XmNrightPosition, 14,
264 			XmNtopAttachment, XmATTACH_POSITION,
265 			XmNtopPosition, 0,
266 			XmNbottomAttachment, XmATTACH_POSITION,
267 			XmNbottomPosition, 60,
268 			XmNshadowType, XmSHADOW_OUT,
269 			NULL);
270 
271 	XtVaSetValues(t1,
272 			XmNrecomputeSize, False,
273 			XmNheight, 16,
274 			NULL);
275 
276 	XtVaSetValues(t2,
277 			XmNrecomputeSize, False,
278 			XmNheight, 16,
279 			NULL);
280 	XtVaSetValues(t3,
281 			XmNrecomputeSize, False,
282 			XmNheight, 16,
283 			NULL);
284 	XtVaSetValues(t4,
285 			XmNrecomputeSize, False,
286 			XmNheight, 16,
287 			NULL);
288 
289 	XtVaGetValues(rc, XmNresizeWidth, &rw, XmNresizeHeight, &rh, NULL);
290 	printf("RW: %d RH: %d\n", rw, rh);
291 	printf("After setting height...\n");
292 	lt_dump_boxes(MGR_Children(rc), RC_Boxes(rc), MGR_NumChildren(rc));
293 
294 	XtRealizeWidget(toplevel);
295 
296 	printf("After realize...\n");
297 	lt_dump_boxes(MGR_Children(rc), RC_Boxes(rc), MGR_NumChildren(rc));
298 
299 	px = bm_to_px(rc, btnlbl_bits, btnlbl_width, btnlbl_height,
300 		      rc->core.depth);
301 	XtVaSetValues(t1, XmNlabelPixmap, px, NULL);
302 
303 	px = bm_to_px(rc, lock_bits, lock_width, lock_height,
304 		      rc->core.depth);
305 	XtVaSetValues(t2, XmNlabelPixmap, px, NULL);
306 
307 	px = bm_to_px(rc, repeat_bits, repeat_width, repeat_height,
308 		      rc->core.depth);
309 	XtVaSetValues(t3, XmNlabelPixmap, px, NULL);
310 
311 	px = bm_to_px(rc, shuffle_bits, shuffle_width, shuffle_height,
312 		      rc->core.depth);
313 	XtVaSetValues(t4, XmNlabelPixmap, px, NULL);
314 
315 	printf("After setting pixmaps...\n");
316 	lt_dump_boxes(MGR_Children(rc), RC_Boxes(rc), MGR_NumChildren(rc));
317 
318 /* Note: the following values are the result of
319  * querying the current geometry.
320  */
321 {
322 static XtWidgetGeometry Expected[] = {
323    CWWidth | CWHeight            ,    0,    0,  360,  135, 0,0,0, /* mainForm */
324    CWWidth | CWHeight | CWX | CWY,    0,    0,   50,   81, 0,0,0, /* frame */
325    CWWidth | CWHeight | CWX | CWY,    2,    2,   46,   77, 0,0,0, /* checkBox */
326    CWWidth | CWHeight | CWX | CWY,    3,    4,   40,   16, 0,0,0, /* button_0 */
327    CWWidth | CWHeight | CWX | CWY,    3,   22,   40,   16, 0,0,0, /* button_1 */
328    CWWidth | CWHeight | CWX | CWY,    3,   40,   40,   16, 0,0,0, /* button_2 */
329    CWWidth | CWHeight | CWX | CWY,    3,   58,   40,   16, 0,0,0, /* button_3 */
330 };
331 /* toplevel should be replaced with to correct applicationShell */
332 PrintDetails(toplevel, Expected);
333 }
334 LessTifTestMainLoop(toplevel);
335 
336 	exit(0);
337 }
338