summaryrefslogtreecommitdiff
path: root/src/Geometry.c
blob: e725be8ef3919f7c558ca7b6b9735bc61037213f (plain)
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/* $Xorg: Geometry.c,v 1.5 2001/02/09 02:03:54 xorgcvs Exp $ */

/***********************************************************
Copyright 1993 Sun Microsystems, Inc.  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.

*/
/* $XFree86: xc/lib/Xt/Geometry.c,v 1.12 2001/12/14 19:56:15 dawes Exp $ */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "IntrinsicI.h"
#include "ShellP.h"
#include "ShellI.h"

static void ClearRectObjAreas(
    RectObj r,
    XWindowChanges* old)
{
    Widget pw = _XtWindowedAncestor((Widget)r);
    int bw2;

    bw2 = old->border_width << 1;
    XClearArea( XtDisplay(pw), XtWindow(pw),
		old->x, old->y,
		old->width + bw2, old->height + bw2,
		TRUE );

    bw2 = r->rectangle.border_width << 1;
    XClearArea( XtDisplay(pw), XtWindow(pw),
		(int)r->rectangle.x, (int)r->rectangle.y,
		(unsigned int)(r->rectangle.width + bw2),
	        (unsigned int)(r->rectangle.height + bw2),
		TRUE );
}

/*
 * Internal function used by XtMakeGeometryRequest and XtSetValues.
 * Returns more data than the public interface.  Does not convert
 * XtGeometryDone to XtGeometryYes.
 *
 * clear_rect_obj - *** RETURNED ***
 *		    TRUE if the rect obj has been cleared, false otherwise.
 */

XtGeometryResult
_XtMakeGeometryRequest (
    Widget widget,
    XtWidgetGeometry *request,
    XtWidgetGeometry *reply,
    Boolean * clear_rect_obj)
{
    XtWidgetGeometry    junk;
    XtGeometryHandler manager = (XtGeometryHandler) NULL;
    XtGeometryResult returnCode;
    Widget parent = widget->core.parent;
    Boolean managed, parentRealized, rgm = False;
    XtConfigureHookDataRec req;
    Widget hookobj;

    *clear_rect_obj = FALSE;

    CALLGEOTAT(_XtGeoTrace(widget,
	"\"%s\" is making a %sgeometry request to its parent \"%s\".\n",
		   XtName(widget),
		   ((request->request_mode & XtCWQueryOnly))? "query only ":"",
		   (XtParent(widget))?XtName(XtParent(widget)):"Root"));
    CALLGEOTAT(_XtGeoTab(1));

    if (XtIsShell(widget)) {
	ShellClassExtension ext;
	LOCK_PROCESS;
	for (ext = (ShellClassExtension)((ShellWidgetClass)XtClass(widget))
		   ->shell_class.extension;
	     ext != NULL && ext->record_type != NULLQUARK;
	     ext = (ShellClassExtension)ext->next_extension);

	if (ext != NULL) {
	    if (  ext->version == XtShellExtensionVersion
		  && ext->record_size == sizeof(ShellClassExtensionRec)) {
		manager = ext->root_geometry_manager;
		rgm = True;
	    } else {
		String params[1];
		Cardinal num_params = 1;
		params[0] = XtClass(widget)->core_class.class_name;
		XtAppErrorMsg(XtWidgetToApplicationContext(widget),
		     "invalidExtension", "xtMakeGeometryRequest",
		     XtCXtToolkitError,
		     "widget class %s has invalid ShellClassExtension record",
		     params, &num_params);
	    }
	} else {
	    XtAppErrorMsg(XtWidgetToApplicationContext(widget),
			  "internalError", "xtMakeGeometryRequest",
			  XtCXtToolkitError,
			  "internal error; ShellClassExtension is NULL",
			  NULL, NULL);
	}
	managed = True;
	parentRealized = TRUE;
	UNLOCK_PROCESS;
    } else /* not shell */ {
	if (parent == NULL)
	    XtAppErrorMsg(XtWidgetToApplicationContext(widget),
			  "invalidParent","xtMakeGeometryRequest",
			  XtCXtToolkitError,
			  "non-shell has no parent in XtMakeGeometryRequest",
			  (String *)NULL, (Cardinal *)NULL);

	managed = XtIsManaged(widget);
	parentRealized = XtIsRealized(parent);
	if (XtIsComposite(parent))
	{
	    LOCK_PROCESS;
	    manager = ((CompositeWidgetClass) (parent->core.widget_class))
		      ->composite_class.geometry_manager;
	    UNLOCK_PROCESS;
	}
    }

#if 0
    /*
     * The Xt spec says that these conditions must generate
     * error messages (not warnings), but many Xt applications
     * and toolkits (including parts of Xaw, Motif and Netscape)
     * depend on the previous Xt behaviour.  Thus, these tests
     * should probably remain disabled.
     */
    if (parentRealized && managed) {
	if (parent && !XtIsComposite(parent))
	{
	    /*
	     * This shouldn't ever happen, we only test for this to pass
	     * VSW5.  Normally managing the widget will catch this, but VSW5
	     * does some really screwy stuff to get here.
	     */
	    XtAppErrorMsg(XtWidgetToApplicationContext(widget),
			  "invalidParent", "xtMakeGeometryRequest",
			  XtCXtToolkitError,
			  "XtMakeGeometryRequest - parent not composite",
			  (String *)NULL, (Cardinal *)NULL);
	}
	else if (manager == (XtGeometryHandler) NULL)
	{
	    XtAppErrorMsg(XtWidgetToApplicationContext(widget),
			  "invalidGeometryManager","xtMakeGeometryRequest",
			  XtCXtToolkitError,
			  "XtMakeGeometryRequest - parent has no geometry manager",
			  (String *)NULL, (Cardinal *)NULL);
	}
    }
#else
    if (!manager)
	managed = False;
#endif

    if (widget->core.being_destroyed) {
	CALLGEOTAT(_XtGeoTab(-1));
	CALLGEOTAT(_XtGeoTrace(widget,
		       "It is being destroyed, just return XtGeometryNo.\n"));
	return XtGeometryNo;
    }

    /* see if requesting anything to change */
    req.changeMask = 0;
    if (request->request_mode & CWStackMode
	&& request->stack_mode != XtSMDontChange) {
	    req.changeMask |= CWStackMode;
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "Asking for a change in StackMode!\n"));
	    if (request->request_mode & CWSibling) {
		XtCheckSubclass(request->sibling, rectObjClass,
				"XtMakeGeometryRequest");
		req.changeMask |= CWSibling;
	    }
    }
    if (request->request_mode & CWX
	&& widget->core.x != request->x) {
	CALLGEOTAT(_XtGeoTrace(widget,
			       "Asking for a change in x: from %d to %d.\n",
			       widget->core.x, request->x));
	req.changeMask |= CWX;
    }
    if (request->request_mode & CWY
	&& widget->core.y != request->y) {
	CALLGEOTAT(_XtGeoTrace(widget,
			       "Asking for a change in y: from %d to %d.\n",
			       widget->core.y, request->y));
	req.changeMask |= CWY;
    }
    if (request->request_mode & CWWidth
	&& widget->core.width != request->width) {
	CALLGEOTAT(_XtGeoTrace(widget,"Asking for a change in width: from %d to %d.\n",
		       widget->core.width, request->width));
	req.changeMask |= CWWidth;
    }
    if (request->request_mode & CWHeight
	&& widget->core.height != request->height) {
	CALLGEOTAT(_XtGeoTrace(widget,
			    "Asking for a change in height: from %d to %d.\n",
			       widget->core.height, request->height));
	req.changeMask |= CWHeight;
    }
    if (request->request_mode & CWBorderWidth
	&& widget->core.border_width != request->border_width){
	CALLGEOTAT(_XtGeoTrace(widget,
		       "Asking for a change in border_width: from %d to %d.\n",
		       widget->core.border_width, request->border_width));
	req.changeMask |= CWBorderWidth;
    }
    if (! req.changeMask) {
	CALLGEOTAT(_XtGeoTrace(widget,
		       "Asking for nothing new,\n"));
	CALLGEOTAT(_XtGeoTab(-1));
	CALLGEOTAT(_XtGeoTrace(widget,
		       "just return XtGeometryYes.\n"));
	return XtGeometryYes;
    }
    req.changeMask |= (request->request_mode & XtCWQueryOnly);

    if ( !(req.changeMask & XtCWQueryOnly) && XtIsRealized(widget) ) {
	/* keep record of the current geometry so we know what's changed */
	req.changes.x = widget->core.x ;
	req.changes.y = widget->core.y ;
	req.changes.width = widget->core.width ;
	req.changes.height = widget->core.height ;
	req.changes.border_width = widget->core.border_width ;
    }

    if (!managed || !parentRealized) {
	CALLGEOTAT(_XtGeoTrace(widget,
			       "Not Managed or Parent not realized.\n"));
	/* Don't get parent's manager involved--assume the answer is yes */
	if (req.changeMask & XtCWQueryOnly) {
	    /* He was just asking, don't change anything, just tell him yes */
	    CALLGEOTAT(_XtGeoTrace(widget,"QueryOnly request\n"));
	    CALLGEOTAT(_XtGeoTab(-1));
	    CALLGEOTAT(_XtGeoTrace(widget,"just return XtGeometryYes.\n"));
	    return XtGeometryYes;
	} else {
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "Copy values from request to widget.\n"));
	    /* copy values from request to widget */
	    if (request->request_mode & CWX)
		widget->core.x = request->x;
	    if (request->request_mode & CWY)
		widget->core.y = request->y;
	    if (request->request_mode & CWWidth)
		widget->core.width = request->width;
	    if (request->request_mode & CWHeight)
		widget->core.height = request->height;
	    if (request->request_mode & CWBorderWidth)
		widget->core.border_width = request->border_width;
	    if (!parentRealized) {
		CALLGEOTAT(_XtGeoTab(-1));
		CALLGEOTAT(_XtGeoTrace(widget,"and return XtGeometryYes.\n"));
		return XtGeometryYes;
	    }
	    else returnCode = XtGeometryYes;
	}
    } else {
	/* go ask the widget's geometry manager */
	CALLGEOTAT(_XtGeoTrace(widget,
			       "Go ask the parent geometry manager.\n"));
	if (reply == (XtWidgetGeometry *) NULL) {
	    returnCode = (*manager)(widget, request, &junk);
	} else {
	    returnCode = (*manager)(widget, request, reply);
	}
    }

    /*
     * If Unrealized, not a XtGeometryYes, or a query-only then we are done.
     */

    if ((returnCode != XtGeometryYes) ||
	(req.changeMask & XtCWQueryOnly) || !XtIsRealized(widget)) {

#ifdef XT_GEO_TATTLER
	switch(returnCode){
	case XtGeometryNo:
	    CALLGEOTAT(_XtGeoTab(-1));
	    CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" returns XtGeometryNo.\n",
			  (XtParent(widget))?XtName(XtParent(widget)):"Root"));
            /* check for no change */
            break ;
	case XtGeometryDone:
	    CALLGEOTAT(_XtGeoTab(-1));
	    CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" returns XtGeometryDone.\n",
		        (XtParent(widget))?XtName(XtParent(widget)):"Root"));
            /* check for no change in queryonly */
            break ;
	case XtGeometryAlmost:
	    CALLGEOTAT(_XtGeoTab(-1));
	    CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" returns XtGeometryAlmost.\n",
			 (XtParent(widget))?XtName(XtParent(widget)):"Root"));
	    CALLGEOTAT(_XtGeoTab(1));
	    CALLGEOTAT(_XtGeoTrace(widget,"Proposal: width %d height %d.\n",
			   (reply)?reply->width:junk.width,
			   (reply)?reply->height:junk.height));
	    CALLGEOTAT(_XtGeoTab(-1));

            /* check for no change */
            break ;
	case XtGeometryYes:
	    if (req.changeMask & XtCWQueryOnly) {
		CALLGEOTAT(_XtGeoTrace(widget,
				"QueryOnly specified, no configuration.\n"));
	    }
            if (!XtIsRealized(widget)) {
		CALLGEOTAT(_XtGeoTrace(widget,
				 "\"%s\" not realized, no configuration.\n",
				 XtName(widget)));
	    }
	    CALLGEOTAT(_XtGeoTab(-1));
            CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" returns XtGeometryYes.\n",
                         (XtParent(widget))?XtName(XtParent(widget)):"Root"));
	    break ;
	}
#endif
	return returnCode;
    }

    CALLGEOTAT(_XtGeoTab(-1));
    CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" returns XtGeometryYes.\n",
		   (XtParent(widget))?XtName(XtParent(widget)):"Root"));

    if (XtIsWidget(widget)) {	/* reconfigure the window (if needed) */

	if (rgm) return returnCode;

	if (req.changes.x != widget->core.x) {
 	    req.changeMask |= CWX;
 	    req.changes.x = widget->core.x;
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "x changing to %d\n",widget->core.x));
 	}
 	if (req.changes.y != widget->core.y) {
 	    req.changeMask |= CWY;
 	    req.changes.y = widget->core.y;
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "y changing to %d\n",widget->core.y));
 	}
 	if (req.changes.width != widget->core.width) {
 	    req.changeMask |= CWWidth;
 	    req.changes.width = widget->core.width;
	    CALLGEOTAT(_XtGeoTrace(widget,
				 "width changing to %d\n",widget->core.width));
 	}
 	if (req.changes.height != widget->core.height) {
 	    req.changeMask |= CWHeight;
 	    req.changes.height = widget->core.height;
	    CALLGEOTAT(_XtGeoTrace(widget,
                               "height changing to %d\n",widget->core.height));
 	}
 	if (req.changes.border_width != widget->core.border_width) {
 	    req.changeMask |= CWBorderWidth;
 	    req.changes.border_width = widget->core.border_width;
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "border_width changing to %d\n",
				   widget->core.border_width));
 	}
	if (req.changeMask & CWStackMode) {
	    req.changes.stack_mode = request->stack_mode;
	    CALLGEOTAT(_XtGeoTrace(widget,"stack_mode changing\n"));
	    if (req.changeMask & CWSibling) {
		if (XtIsWidget(request->sibling))
		    req.changes.sibling = XtWindow(request->sibling);
		else
		    req.changeMask &= ~(CWStackMode | CWSibling);
	    }
	}

#ifdef XT_GEO_TATTLER
        if (req.changeMask) {
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "XConfigure \"%s\"'s window.\n",
				   XtName(widget)));
	} else {
	    CALLGEOTAT(_XtGeoTrace(widget,
			     "No window configuration needed for \"%s\".\n",
			     XtName(widget)));
	}
#endif

	XConfigureWindow(XtDisplay(widget), XtWindow(widget),
			 req.changeMask, &req.changes);
    }
    else {			/* RectObj child of realized Widget */
	*clear_rect_obj = TRUE;
	CALLGEOTAT(_XtGeoTrace(widget,
			       "ClearRectObj on \"%s\".\n",XtName(widget)));

	ClearRectObjAreas((RectObj)widget, &req.changes);
    }
    hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget));;
    if (XtHasCallbacks(hookobj, XtNconfigureHook) == XtCallbackHasSome) {
	req.type = XtHconfigure;
	req.widget = widget;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.confighook_callbacks,
		(XtPointer)&req);
    }

    return returnCode;
} /* _XtMakeGeometryRequest */


/* Public routines */

XtGeometryResult XtMakeGeometryRequest (
    Widget         widget,
    XtWidgetGeometry *request,
    XtWidgetGeometry *reply)
{
    Boolean junk;
    XtGeometryResult r;
    XtGeometryHookDataRec call_data;
    Widget hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget));
    WIDGET_TO_APPCON(widget);

    LOCK_APP(app);
    if (XtHasCallbacks(hookobj, XtNgeometryHook) == XtCallbackHasSome) {
	call_data.type = XtHpreGeometry;
	call_data.widget = widget;
	call_data.request = request;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.geometryhook_callbacks,
		(XtPointer)&call_data);
	call_data.result = r =
	    _XtMakeGeometryRequest(widget, request, reply, &junk);
	call_data.type = XtHpostGeometry;
	call_data.reply = reply;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.geometryhook_callbacks,
		(XtPointer)&call_data);
    } else {
	r = _XtMakeGeometryRequest(widget, request, reply, &junk);
    }
    UNLOCK_APP(app);

    return ((r == XtGeometryDone) ? XtGeometryYes : r);
}

XtGeometryResult
XtMakeResizeRequest(
    Widget	widget,
    _XtDimension width,
    _XtDimension height,
    Dimension	*replyWidth,
    Dimension	*replyHeight)
{
    XtWidgetGeometry request, reply;
    XtGeometryResult r;
    XtGeometryHookDataRec call_data;
    Boolean junk;
    Widget hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget));
    WIDGET_TO_APPCON(widget);

    LOCK_APP(app);
    request.request_mode = CWWidth | CWHeight;
    request.width = width;
    request.height = height;

    if (XtHasCallbacks(hookobj, XtNgeometryHook) == XtCallbackHasSome) {
	call_data.type = XtHpreGeometry;
	call_data.widget = widget;
	call_data.request = &request;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.geometryhook_callbacks,
		(XtPointer)&call_data);
	call_data.result = r =
	    _XtMakeGeometryRequest(widget, &request, &reply, &junk);
	call_data.type = XtHpostGeometry;
	call_data.reply = &reply;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.geometryhook_callbacks,
		(XtPointer)&call_data);
    } else {
	r = _XtMakeGeometryRequest(widget, &request, &reply, &junk);
    }
    if (replyWidth != NULL) {
	if (r == XtGeometryAlmost && reply.request_mode & CWWidth)
	    *replyWidth = reply.width;
	else
	    *replyWidth = width;
    }
    if (replyHeight != NULL) {
	if (r == XtGeometryAlmost && reply.request_mode & CWHeight)
	    *replyHeight = reply.height;
	else
	    *replyHeight = height;
    }
    UNLOCK_APP(app);
    return ((r == XtGeometryDone) ? XtGeometryYes : r);
} /* XtMakeResizeRequest */

void XtResizeWindow(
    Widget w)
{
    XtConfigureHookDataRec req;
    Widget hookobj;
    WIDGET_TO_APPCON(w);

    LOCK_APP(app);
    if (XtIsRealized(w)) {
	req.changes.width = w->core.width;
	req.changes.height = w->core.height;
	req.changes.border_width = w->core.border_width;
	req.changeMask = CWWidth | CWHeight | CWBorderWidth;
	XConfigureWindow(XtDisplay(w), XtWindow(w),
	    (unsigned) req.changeMask, &req.changes);
	hookobj = XtHooksOfDisplay(XtDisplayOfObject(w));;
	if (XtHasCallbacks(hookobj, XtNconfigureHook) == XtCallbackHasSome) {
	    req.type = XtHconfigure;
	    req.widget = w;
	    XtCallCallbackList(hookobj,
			((HookObject)hookobj)->hooks.confighook_callbacks,
			(XtPointer)&req);
	}
    }
    UNLOCK_APP(app);
} /* XtResizeWindow */

void XtResizeWidget(
    Widget w,
    _XtDimension width,
    _XtDimension height,
    _XtDimension borderWidth)
{
    XtConfigureWidget(w, w->core.x, w->core.y, width, height, borderWidth);
} /* XtResizeWidget */

void XtConfigureWidget(
    Widget w,
    _XtPosition x,
    _XtPosition y,
    _XtDimension width,
    _XtDimension height,
    _XtDimension borderWidth)
{
    XtConfigureHookDataRec req;
    Widget hookobj;
    XWindowChanges old;
    WIDGET_TO_APPCON(w);

    CALLGEOTAT(_XtGeoTrace(w,
                   "\"%s\" is being configured by its parent \"%s\"\n",
		   XtName(w),
		   (XtParent(w))?XtName(XtParent(w)):"Root"));
    CALLGEOTAT(_XtGeoTab(1));

    LOCK_APP(app);
    req.changeMask = 0;
    if ((old.x = w->core.x) != x) {
	CALLGEOTAT(_XtGeoTrace(w,"x move from %d to %d\n",w->core.x, x));
	req.changes.x = w->core.x = x;
	req.changeMask |= CWX;
    }

    if ((old.y = w->core.y) != y) {
	CALLGEOTAT(_XtGeoTrace(w,"y move from %d to %d\n",w->core.y, y));
	req.changes.y = w->core.y = y;
	req.changeMask |= CWY;
    }

    if ((old.width = w->core.width) != width) {
	CALLGEOTAT(_XtGeoTrace(w,
			 "width move from %d to %d\n",w->core.width, width));
	req.changes.width = w->core.width = width;
	req.changeMask |= CWWidth;
    }

    if ((old.height = w->core.height) != height) {
	CALLGEOTAT(_XtGeoTrace(w,
		       "height move from %d to %d\n",w->core.height, height));
	req.changes.height = w->core.height = height;
	req.changeMask |= CWHeight;
    }

    if ((old.border_width = w->core.border_width) != borderWidth) {
	CALLGEOTAT(_XtGeoTrace(w,"border_width move from %d to %d\n",
		    w->core.border_width,borderWidth ));
	req.changes.border_width = w->core.border_width = borderWidth;
	req.changeMask |= CWBorderWidth;
    }

    if (req.changeMask != 0) {
	if (XtIsRealized(w)) {
	    if (XtIsWidget(w)) {
		CALLGEOTAT(_XtGeoTrace(w,
                                  "XConfigure \"%s\"'s window\n",XtName(w)));
		XConfigureWindow(XtDisplay(w), XtWindow(w),
				 req.changeMask, &req.changes);
	    } else {
		CALLGEOTAT(_XtGeoTrace(w,
			       "ClearRectObj called on \"%s\"\n",XtName(w)));
		ClearRectObjAreas((RectObj)w, &old);
	    }
	}
	hookobj = XtHooksOfDisplay(XtDisplayOfObject(w));;
	if (XtHasCallbacks(hookobj, XtNconfigureHook) == XtCallbackHasSome) {
	    req.type = XtHconfigure;
	    req.widget = w;
	    XtCallCallbackList(hookobj,
			((HookObject)hookobj)->hooks.confighook_callbacks,
			(XtPointer)&req);
	}
	{
	XtWidgetProc resize;

	LOCK_PROCESS;
	resize = XtClass(w)->core_class.resize;
	UNLOCK_PROCESS;
	if ((req.changeMask & (CWWidth | CWHeight)) &&
	    resize != (XtWidgetProc) NULL) {
	    CALLGEOTAT(_XtGeoTrace(w,"Resize proc is called.\n"));
	    (*resize)(w);
	 }
	}
    } else {
	CALLGEOTAT(_XtGeoTrace(w,"No change in configuration\n"));
    }

    CALLGEOTAT(_XtGeoTab(-1));
    UNLOCK_APP(app);
} /* XtConfigureWidget */

void XtMoveWidget(
    Widget w,
    _XtPosition x,
    _XtPosition y)
{
    XtConfigureWidget(w, x, y, w->core.width, w->core.height,
		      w->core.border_width);
} /* XtMoveWidget */

void XtTranslateCoords(
    register Widget w,
    _XtPosition x,
    _XtPosition y,
    register Position *rootx,	/* return */
    register Position *rooty)	/* return */
{
    Position garbagex, garbagey;
    XtAppContext app = XtWidgetToApplicationContext(w);

    LOCK_APP(app);
    if (rootx == NULL) rootx = &garbagex;
    if (rooty == NULL) rooty = &garbagey;

    *rootx = x;
    *rooty = y;

    for (; w != NULL && ! XtIsShell(w); w = w->core.parent) {
	*rootx += w->core.x + w->core.border_width;
	*rooty += w->core.y + w->core.border_width;
    }

    if (w == NULL)
        XtAppWarningMsg(app,
		"invalidShell","xtTranslateCoords",XtCXtToolkitError,
                "Widget has no shell ancestor",
		(String *)NULL, (Cardinal *)NULL);
    else {
	Position x, y;
	_XtShellGetCoordinates( w, &x, &y );
	*rootx += x + w->core.border_width;
	*rooty += y + w->core.border_width;
    }
    UNLOCK_APP(app);
}

XtGeometryResult XtQueryGeometry(
    Widget widget,
    register XtWidgetGeometry *intended, /* parent's changes; may be NULL */
    XtWidgetGeometry *reply)	/* child's preferred geometry; never NULL */
{
    XtWidgetGeometry null_intended;
    XtGeometryHandler query;
    XtGeometryResult result;
    WIDGET_TO_APPCON(widget);

    CALLGEOTAT(_XtGeoTrace(widget,
		     "\"%s\" is asking its preferred geometry to \"%s\".\n",
		     (XtParent(widget))?XtName(XtParent(widget)):"Root",
		     XtName(widget)));
    CALLGEOTAT(_XtGeoTab(1));

    LOCK_APP(app);
    LOCK_PROCESS;
    query = XtClass(widget)->core_class.query_geometry;
    UNLOCK_PROCESS;
    reply->request_mode = 0;
    if (query != NULL) {
	if (intended == NULL) {
	    null_intended.request_mode = 0;
	    intended = &null_intended;
#ifdef XT_GEO_TATTLER
	    CALLGEOTAT(_XtGeoTrace(widget,"without any constraint.\n"));
	} else {
	    CALLGEOTAT(_XtGeoTrace(widget,
				   "with the following constraints:\n"));

	    if (intended->request_mode & CWX) {
		CALLGEOTAT(_XtGeoTrace(widget," x = %d\n",intended->x));
	    }
	    if (intended->request_mode & CWY) {
		CALLGEOTAT(_XtGeoTrace(widget," y = %d\n",intended->y));
	    }
	    if (intended->request_mode & CWWidth) {
		CALLGEOTAT(_XtGeoTrace(widget,
				       " width = %d\n",intended->width));
	    }
	    if (intended->request_mode & CWHeight) {
		CALLGEOTAT(_XtGeoTrace(widget,
				       " height = %d\n",intended->height));
	    }
	    if (intended->request_mode & CWBorderWidth) {
		CALLGEOTAT(_XtGeoTrace(widget,
			       " border_width = %d\n",intended->border_width));
	    }
#endif
	}

	result = (*query) (widget, intended, reply);
    }
    else {
	CALLGEOTAT(_XtGeoTrace(widget,"\"%s\" has no QueryGeometry proc, return the current state\n",XtName(widget)));

	result = XtGeometryYes;
    }

#ifdef XT_GEO_TATTLER
#define FillIn(mask, field) \
	if (!(reply->request_mode & mask)) {\
	      reply->field = widget->core.field;\
	      _XtGeoTrace(widget," using core %s = %d.\n","field",\
			                               widget->core.field);\
	} else {\
	      _XtGeoTrace(widget," replied %s = %d\n","field",\
			                           reply->field);\
	}
#else
#define FillIn(mask, field) \
	if (!(reply->request_mode & mask)) reply->field = widget->core.field;
#endif

    FillIn(CWX, x);
    FillIn(CWY, y);
    FillIn(CWWidth, width);
    FillIn(CWHeight, height);
    FillIn(CWBorderWidth, border_width);

    CALLGEOTAT(_XtGeoTab(-1));
#undef FillIn

    if (!(reply->request_mode & CWStackMode))
	reply->stack_mode = XtSMDontChange;
    UNLOCK_APP(app);
    return result;
}