1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
/***********************************************************
Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
/*
Copyright 1987, 1988, 1994, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "IntrinsicI.h"
static _Xconst _XtString XtNinvalidChild = "invalidChild";
static _Xconst _XtString XtNxtUnmanageChildren = "xtUnmanageChildren";
static _Xconst _XtString XtNxtManageChildren = "xtManageChildren";
static _Xconst _XtString XtNxtChangeManagedSet = "xtChangeManagedSet";
static void
UnmanageChildren(WidgetList children,
Cardinal num_children,
Widget parent,
Cardinal *num_unique_children,
Boolean call_change_managed,
_Xconst _XtString caller_func)
{
Widget child;
Cardinal i;
XtWidgetProc change_managed = NULL;
Bool parent_realized = False;
*num_unique_children = 0;
if (XtIsComposite((Widget) parent)) {
LOCK_PROCESS;
change_managed = ((CompositeWidgetClass) parent->core.widget_class)
->composite_class.change_managed;
UNLOCK_PROCESS;
parent_realized = XtIsRealized((Widget) parent);
}
else {
XtAppErrorMsg(XtWidgetToApplicationContext((Widget) parent),
"invalidParent", caller_func, XtCXtToolkitError,
"Attempt to unmanage a child when parent is not Composite",
NULL, NULL);
}
for (i = 0; i < num_children; i++) {
child = children[i];
if (child == NULL) {
XtAppWarningMsg(XtWidgetToApplicationContext(parent),
XtNinvalidChild, caller_func, XtCXtToolkitError,
"Null child passed to XtUnmanageChildren",
NULL, NULL);
return;
}
if (child->core.parent != parent) {
XtAppWarningMsg(XtWidgetToApplicationContext(parent),
"ambiguousParent", caller_func, XtCXtToolkitError,
"Not all children have same parent in UnmanageChildren",
NULL, NULL);
}
else if (child->core.managed) {
(*num_unique_children)++;
CALLGEOTAT(_XtGeoTrace(child, "Child \"%s\" is marked unmanaged\n",
XtName(child)));
child->core.managed = FALSE;
if (XtIsWidget(child)
&& XtIsRealized(child)
&& child->core.mapped_when_managed)
XtUnmapWidget(child);
else { /* RectObj child */
Widget pw = child->core.parent;
RectObj r = (RectObj) child;
while ((pw != NULL) && (!XtIsWidget(pw)))
pw = pw->core.parent;
if ((pw != NULL) && XtIsRealized(pw))
XClearArea(XtDisplay(pw), XtWindow(pw),
r->rectangle.x, r->rectangle.y,
(unsigned) (r->rectangle.width +
(r->rectangle.border_width << 1)),
(unsigned) (r->rectangle.height +
(r->rectangle.border_width << 1)),
TRUE);
}
}
}
if (call_change_managed && *num_unique_children != 0 &&
change_managed != NULL && parent_realized) {
CALLGEOTAT(_XtGeoTrace((Widget) parent,
"Call parent: \"%s\"[%d,%d]'s changemanaged proc\n",
XtName((Widget) parent),
parent->core.width, parent->core.height));
(*change_managed) (parent);
}
} /* UnmanageChildren */
void
XtUnmanageChildren(WidgetList children, Cardinal num_children)
{
Widget parent, hookobj;
Cardinal ii;
#ifdef XTHREADS
XtAppContext app;
#endif
if (num_children == 0)
return;
if (children[0] == NULL) {
XtWarningMsg(XtNinvalidChild, XtNxtUnmanageChildren, XtCXtToolkitError,
"Null child found in argument list to unmanage",
NULL, NULL);
return;
}
#ifdef XTHREADS
app = XtWidgetToApplicationContext(children[0]);
#endif
LOCK_APP(app);
parent = children[0]->core.parent;
if (parent->core.being_destroyed) {
UNLOCK_APP(app);
return;
}
UnmanageChildren(children, num_children, parent, &ii,
(Boolean) True, XtNxtUnmanageChildren);
hookobj = XtHooksOfDisplay(XtDisplayOfObject(children[0]));
if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
XtChangeHookDataRec call_data;
call_data.type = XtHunmanageChildren;
call_data.widget = parent;
call_data.event_data = (XtPointer) children;
call_data.num_event_data = num_children;
XtCallCallbackList(hookobj,
((HookObject) hookobj)->hooks.changehook_callbacks,
(XtPointer) &call_data);
}
UNLOCK_APP(app);
} /* XtUnmanageChildren */
void
XtUnmanageChild(Widget child)
{
XtUnmanageChildren(&child, (Cardinal) 1);
} /* XtUnmanageChild */
static void
ManageChildren(WidgetList children,
Cardinal num_children,
Widget parent,
Boolean call_change_managed,
_Xconst _XtString caller_func)
{
#define MAXCHILDREN 100
Widget child;
Cardinal num_unique_children, i;
XtWidgetProc change_managed = NULL;
WidgetList unique_children;
Widget cache[MAXCHILDREN];
Bool parent_realized = False;
if (XtIsComposite((Widget) parent)) {
LOCK_PROCESS;
change_managed = ((CompositeWidgetClass) parent->core.widget_class)
->composite_class.change_managed;
UNLOCK_PROCESS;
parent_realized = XtIsRealized((Widget) parent);
}
else {
XtAppErrorMsg(XtWidgetToApplicationContext((Widget) parent),
"invalidParent", caller_func, XtCXtToolkitError,
"Attempt to manage a child when parent is not Composite",
NULL, NULL);
}
/* Construct new list of children that really need to be operated upon. */
if (num_children <= MAXCHILDREN) {
unique_children = cache;
}
else {
unique_children = (WidgetList)
__XtMalloc((Cardinal) ((size_t) num_children * sizeof(Widget)));
}
num_unique_children = 0;
for (i = 0; i < num_children; i++) {
child = children[i];
if (child == NULL) {
XtAppWarningMsg(XtWidgetToApplicationContext((Widget) parent),
XtNinvalidChild, caller_func, XtCXtToolkitError,
"null child passed to ManageChildren", NULL, NULL);
if (unique_children != cache)
XtFree((char *) unique_children);
return;
}
#ifdef DEBUG
if (!XtIsRectObj(child)) {
String params[2];
Cardinal num_params = 2;
params[0] = XtName(child);
params[1] = child->core.widget_class->core_class.class_name;
XtAppWarningMsg(XtWidgetToApplicationContext((Widget) parent),
"notRectObj", caller_func, XtCXtToolkitError,
"child \"%s\", class %s is not a RectObj",
params, &num_params);
continue;
}
#endif /*DEBUG*/
if (child->core.parent != parent) {
XtAppWarningMsg(XtWidgetToApplicationContext((Widget) parent),
"ambiguousParent", caller_func, XtCXtToolkitError,
"Not all children have same parent in XtManageChildren",
NULL, NULL);
}
else if (!child->core.managed && !child->core.being_destroyed) {
unique_children[num_unique_children++] = child;
CALLGEOTAT(_XtGeoTrace(child,
"Child \"%s\"[%d,%d] is marked managed\n",
XtName(child),
child->core.width, child->core.height));
child->core.managed = TRUE;
}
}
if ((call_change_managed || num_unique_children != 0) && parent_realized) {
/* Compute geometry of new managed set of children. */
if (change_managed != NULL) {
CALLGEOTAT(_XtGeoTrace((Widget) parent,
"Call parent: \"%s\"[%d,%d]'s changemanaged\n",
XtName((Widget) parent),
parent->core.width, parent->core.height));
(*change_managed) ((Widget) parent);
}
/* Realize each child if necessary, then map if necessary */
for (i = 0; i < num_unique_children; i++) {
child = unique_children[i];
if (XtIsWidget(child)) {
if (!XtIsRealized(child))
XtRealizeWidget(child);
if (child->core.mapped_when_managed)
XtMapWidget(child);
}
else { /* RectObj child */
Widget pw = child->core.parent;
RectObj r = (RectObj) child;
while ((pw != NULL) && (!XtIsWidget(pw)))
pw = pw->core.parent;
if (pw != NULL)
XClearArea(XtDisplay(pw), XtWindow(pw),
r->rectangle.x, r->rectangle.y,
(unsigned) (r->rectangle.width +
(r->rectangle.border_width << 1)),
(unsigned) (r->rectangle.height +
(r->rectangle.border_width << 1)),
TRUE);
}
}
}
if (unique_children != cache)
XtFree((char *) unique_children);
} /* ManageChildren */
void
XtManageChildren(WidgetList children, Cardinal num_children)
{
Widget parent, hookobj;
#ifdef XTHREADS
XtAppContext app;
#endif
if (num_children == 0)
return;
if (children[0] == NULL) {
XtWarningMsg(XtNinvalidChild, XtNxtManageChildren, XtCXtToolkitError,
"null child passed to XtManageChildren", NULL, NULL);
return;
}
#ifdef XTHREADS
app = XtWidgetToApplicationContext(children[0]);
#endif
LOCK_APP(app);
parent = children[0]->core.parent;
if (parent->core.being_destroyed) {
UNLOCK_APP(app);
return;
}
ManageChildren(children, num_children, parent, (Boolean) False,
XtNxtManageChildren);
hookobj = XtHooksOfDisplay(XtDisplayOfObject(children[0]));
if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
XtChangeHookDataRec call_data;
call_data.type = XtHmanageChildren;
call_data.widget = parent;
call_data.event_data = (XtPointer) children;
call_data.num_event_data = num_children;
XtCallCallbackList(hookobj,
((HookObject) hookobj)->hooks.changehook_callbacks,
(XtPointer) &call_data);
}
UNLOCK_APP(app);
} /* XtManageChildren */
void
XtManageChild(Widget child)
{
XtManageChildren(&child, (Cardinal) 1);
} /* XtManageChild */
void
XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed)
{
Widget hookobj;
WIDGET_TO_APPCON(widget);
LOCK_APP(app);
if (widget->core.mapped_when_managed == mapped_when_managed) {
UNLOCK_APP(app);
return;
}
widget->core.mapped_when_managed = (Boolean) mapped_when_managed;
hookobj = XtHooksOfDisplay(XtDisplay(widget));
if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
XtChangeHookDataRec call_data;
call_data.type = XtHsetMappedWhenManaged;
call_data.widget = widget;
call_data.event_data = (XtPointer) (unsigned long) mapped_when_managed;
XtCallCallbackList(hookobj,
((HookObject) hookobj)->hooks.changehook_callbacks,
(XtPointer) &call_data);
}
if (!XtIsManaged(widget)) {
UNLOCK_APP(app);
return;
}
if (mapped_when_managed) {
/* Didn't used to be mapped when managed. */
if (XtIsRealized(widget))
XtMapWidget(widget);
}
else {
/* Used to be mapped when managed. */
if (XtIsRealized(widget))
XtUnmapWidget(widget);
}
UNLOCK_APP(app);
} /* XtSetMappedWhenManaged */
void
XtChangeManagedSet(WidgetList unmanage_children,
Cardinal num_unmanage,
XtDoChangeProc do_change_proc,
XtPointer client_data,
WidgetList manage_children,
Cardinal num_manage)
{
WidgetList childp;
Widget parent;
int i;
Cardinal some_unmanaged;
Boolean call_out;
XtAppContext app;
Widget hookobj;
XtChangeHookDataRec call_data;
if (num_unmanage == 0 && num_manage == 0)
return;
/* specification doesn't state that library will check for NULL in list */
childp = num_unmanage ? unmanage_children : manage_children;
app = XtWidgetToApplicationContext(*childp);
LOCK_APP(app);
parent = XtParent(*childp);
childp = unmanage_children;
for (i = (int) num_unmanage; --i >= 0 && XtParent(*childp) == parent;
childp++);
call_out = (i >= 0);
childp = manage_children;
for (i = (int) num_manage; --i >= 0 && XtParent(*childp) == parent;
childp++);
if (call_out || i >= 0) {
XtAppWarningMsg(app, "ambiguousParent", XtNxtChangeManagedSet,
XtCXtToolkitError, "Not all children have same parent",
NULL, NULL);
}
if (!XtIsComposite(parent)) {
UNLOCK_APP(app);
XtAppErrorMsg(app, "invalidParent", XtNxtChangeManagedSet,
XtCXtToolkitError,
"Attempt to manage a child when parent is not Composite",
NULL, NULL);
}
if (parent->core.being_destroyed) {
UNLOCK_APP(app);
return;
}
call_out = False;
if (do_change_proc) {
CompositeClassExtension ext = (CompositeClassExtension)
XtGetClassExtension(parent->core.widget_class,
XtOffsetOf(CompositeClassRec,
composite_class.extension),
NULLQUARK, XtCompositeExtensionVersion,
sizeof(CompositeClassExtensionRec));
if (!ext || !ext->allows_change_managed_set)
call_out = True;
}
UnmanageChildren(unmanage_children, num_unmanage, parent,
&some_unmanaged, call_out, XtNxtChangeManagedSet);
hookobj = XtHooksOfDisplay(XtDisplay(parent));
if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
call_data.type = XtHunmanageSet;
call_data.widget = parent;
call_data.event_data = (XtPointer) unmanage_children;
call_data.num_event_data = num_unmanage;
XtCallCallbackList(hookobj,
((HookObject) hookobj)->hooks.changehook_callbacks,
(XtPointer) &call_data);
}
if (do_change_proc)
(*do_change_proc) (parent, unmanage_children, &num_unmanage,
manage_children, &num_manage, client_data);
call_out = (some_unmanaged && !call_out);
ManageChildren(manage_children, num_manage, parent, call_out,
XtNxtChangeManagedSet);
if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
call_data.type = XtHmanageSet;
call_data.event_data = (XtPointer) manage_children;
call_data.num_event_data = num_manage;
XtCallCallbackList(hookobj,
((HookObject) hookobj)->hooks.changehook_callbacks,
(XtPointer) &call_data);
}
UNLOCK_APP(app);
} /* XtChangeManagedSet */
|