Composite.c revision 444c061a
1/* $Xorg: Composite.c,v 1.4 2001/02/09 02:03:54 xorgcvs Exp $ */
2
3/***********************************************************
4Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts
5Copyright 1993 by Sun Microsystems, Inc. Mountain View, CA.
6
7                        All Rights Reserved
8
9Permission to use, copy, modify, and distribute this software and its
10documentation for any purpose and without fee is hereby granted,
11provided that the above copyright notice appear in all copies and that
12both that copyright notice and this permission notice appear in
13supporting documentation, and that the names of Digital, or Sun not be
14used in advertising or publicity pertaining to distribution of the
15software without specific, written prior permission.
16
17DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
20ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23SOFTWARE.
24
25SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
26INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
27NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
28ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
29ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
30PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
31OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
32THE USE OR PERFORMANCE OF THIS SOFTWARE.
33
34******************************************************************/
35
36/*
37
38Copyright 1987, 1988, 1998  The Open Group
39
40Permission to use, copy, modify, distribute, and sell this software and its
41documentation for any purpose is hereby granted without fee, provided that
42the above copyright notice appear in all copies and that both that
43copyright notice and this permission notice appear in supporting
44documentation.
45
46The above copyright notice and this permission notice shall be included in
47all copies or substantial portions of the Software.
48
49THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
52OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
53AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
54CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55
56Except as contained in this notice, the name of The Open Group shall not be
57used in advertising or otherwise to promote the sale, use or other dealings
58in this Software without prior written authorization from The Open Group.
59
60*/
61/* $XFree86: xc/lib/Xt/Composite.c,v 1.5 2001/08/22 22:52:17 dawes Exp $ */
62
63#define XT_COMPOSITE
64#ifdef HAVE_CONFIG_H
65#include <config.h>
66#endif
67#include "IntrinsicI.h"
68#include "StringDefs.h"
69
70static XtResource resources[] = {
71    {XtNchildren, XtCReadOnly, XtRWidgetList, sizeof(WidgetList),
72     XtOffsetOf(CompositeRec, composite.children), XtRImmediate, NULL},
73    {XtNnumChildren, XtCReadOnly, XtRCardinal, sizeof(Cardinal),
74     XtOffsetOf(CompositeRec, composite.num_children), XtRImmediate, 0},
75    {XtNinsertPosition, XtCInsertPosition, XtRFunction, sizeof(XtOrderProc),
76     XtOffsetOf(CompositeRec, composite.insert_position), XtRImmediate, NULL},
77};
78
79static void CompositeClassPartInitialize(WidgetClass);
80static void CompositeInitialize(Widget, Widget, ArgList, Cardinal *);
81static void CompositeInsertChild(Widget);
82static void CompositeDeleteChild(Widget);
83static void CompositeDestroy(Widget);
84
85externaldef(compositeclassrec) CompositeClassRec compositeClassRec = {
86  { /******* CorePart *******/
87    /* superclass	    */	&widgetClassRec,
88    /* class_name	    */	"Composite",
89    /* widget_size	    */	sizeof(CompositeRec),
90    /* class_initialize     */  NULL,
91    /* class_part_initialize*/	CompositeClassPartInitialize,
92    /* class_inited	    */	FALSE,
93    /* initialize	    */	CompositeInitialize,
94    /* initialize_hook      */	NULL,
95    /* realize		    */	XtInheritRealize,
96    /* actions		    */	NULL,
97    /* num_actions	    */	0,
98    /* resources	    */	resources,
99    /* num_resources	    */	XtNumber(resources),
100    /* xrm_class	    */	NULLQUARK,
101    /* compress_motion      */	FALSE,
102    /* compress_exposure    */	TRUE,
103    /* compress_enterleave  */  FALSE,
104    /* visible_interest     */	FALSE,
105    /* destroy		    */	CompositeDestroy,
106    /* resize		    */	NULL,
107    /* expose		    */	NULL,
108    /* set_values	    */	NULL,
109    /* set_values_hook      */	NULL,
110    /* set_values_almost    */	XtInheritSetValuesAlmost,
111    /* get_values_hook      */	NULL,
112    /* accept_focus	    */	NULL,
113    /* version		    */	XtVersion,
114    /* callback_offsets     */  NULL,
115    /* tm_table		    */  NULL,
116    /* query_geometry	    */  NULL,
117    /* display_accelerator  */	NULL,
118    /* extension	    */  NULL
119  },
120  { /**** CompositePart *****/
121    /* geometry_handler     */  NULL,
122    /* change_managed       */  NULL,
123    /* insert_child	    */  CompositeInsertChild,
124    /* delete_child	    */  CompositeDeleteChild,
125    /* extension	    */  NULL
126    }
127};
128
129externaldef(compositewidgetclass) WidgetClass compositeWidgetClass = (WidgetClass) &compositeClassRec;
130
131static void InheritAllowsChangeManagedSet(
132    WidgetClass widget_class)
133{
134    CompositeWidgetClass cc = (CompositeWidgetClass) widget_class;
135    CompositeClassExtension ext, super_ext, new_ext;
136
137    ext = (CompositeClassExtension)
138	XtGetClassExtension(widget_class,
139		    XtOffsetOf(CompositeClassRec, composite_class.extension),
140			    NULLQUARK, 1L, 0);
141
142    if (ext && ext->version == XtCompositeExtensionVersion)
143	return;
144
145    super_ext = (CompositeClassExtension)
146	XtGetClassExtension(cc->core_class.superclass,
147		    XtOffsetOf(CompositeClassRec, composite_class.extension),
148			    NULLQUARK, 1L, 0);
149
150    LOCK_PROCESS;
151    if (super_ext && super_ext->version == XtCompositeExtensionVersion &&
152	super_ext->record_size == sizeof(CompositeClassExtensionRec) &&
153	super_ext->allows_change_managed_set) {
154
155	new_ext = (CompositeClassExtension)
156	    __XtCalloc(1, sizeof(CompositeClassExtensionRec));
157
158	/* Be careful to inherit only what is appropriate */
159	new_ext->next_extension = cc->composite_class.extension;
160	new_ext->record_type = NULLQUARK;
161	new_ext->version = XtCompositeExtensionVersion;
162	new_ext->record_size = sizeof(CompositeClassExtensionRec);
163	new_ext->accepts_objects = (ext ? ext->accepts_objects : False);
164	new_ext->allows_change_managed_set = True;
165	cc->composite_class.extension = (XtPointer) new_ext;
166    }
167    UNLOCK_PROCESS;
168}
169
170static void CompositeClassPartInitialize(
171	WidgetClass widgetClass)
172{
173    register CompositePartPtr wcPtr;
174    register CompositePartPtr superPtr = NULL;
175
176    wcPtr = (CompositePartPtr)
177	&(((CompositeWidgetClass)widgetClass)->composite_class);
178
179    if (widgetClass != compositeWidgetClass)
180	/* don't compute possible bogus pointer */
181	superPtr = (CompositePartPtr)&(((CompositeWidgetClass)widgetClass
182			->core_class.superclass)->composite_class);
183
184    /* We don't need to check for null super since we'll get to composite
185       eventually, and it had better define them!  */
186
187    LOCK_PROCESS;
188    if (wcPtr->geometry_manager == XtInheritGeometryManager) {
189	wcPtr->geometry_manager =
190		superPtr->geometry_manager;
191    }
192
193    if (wcPtr->change_managed == XtInheritChangeManaged) {
194	wcPtr->change_managed =
195		superPtr->change_managed;
196	InheritAllowsChangeManagedSet(widgetClass);
197    }
198
199    if (wcPtr->insert_child == XtInheritInsertChild) {
200	wcPtr->insert_child = superPtr->insert_child;
201    }
202
203    if (wcPtr->delete_child == XtInheritDeleteChild) {
204	wcPtr->delete_child = superPtr->delete_child;
205    }
206    UNLOCK_PROCESS;
207}
208
209static void CompositeDestroy(
210    Widget	w)
211{
212    register CompositeWidget cw = (CompositeWidget) w;
213
214    XtFree((char *) cw->composite.children);
215}
216
217static void CompositeInsertChild(
218    Widget	w)
219{
220    register Cardinal	     position;
221    register Cardinal        i;
222    register CompositeWidget cw;
223    register WidgetList      children;
224
225    cw = (CompositeWidget) w->core.parent;
226    children = cw->composite.children;
227
228    if (cw->composite.insert_position != NULL)
229	position = (*(cw->composite.insert_position))(w);
230    else
231	position = cw->composite.num_children;
232
233    if (cw->composite.num_children == cw->composite.num_slots) {
234	/* Allocate more space */
235	cw->composite.num_slots +=  (cw->composite.num_slots / 2) + 2;
236	cw->composite.children = children =
237	    (WidgetList) XtRealloc((XtPointer) children,
238	    (unsigned) (cw->composite.num_slots) * sizeof(Widget));
239    }
240    /* Ripple children up one space from "position" */
241    for (i = cw->composite.num_children; i > position; i--) {
242	children[i] = children[i-1];
243    }
244    children[position] = w;
245    cw->composite.num_children++;
246}
247
248static void CompositeDeleteChild(
249    Widget	w)
250{
251    register Cardinal	     position;
252    register Cardinal	     i;
253    register CompositeWidget cw;
254
255    cw = (CompositeWidget) w->core.parent;
256
257    for (position = 0; position < cw->composite.num_children; position++) {
258        if (cw->composite.children[position] == w) {
259	    break;
260	}
261    }
262    if (position == cw->composite.num_children) return;
263
264    /* Ripple children down one space from "position" */
265    cw->composite.num_children--;
266    for (i = position; i < cw->composite.num_children; i++) {
267        cw->composite.children[i] = cw->composite.children[i+1];
268    }
269}
270
271/* ARGSUSED */
272static void CompositeInitialize(
273    Widget   requested_widget,
274    Widget   new_widget,
275    ArgList args,
276    Cardinal *num_args)
277{
278    register CompositeWidget cw;
279
280    cw = (CompositeWidget) new_widget;
281    cw->composite.num_children = 0;
282    cw->composite.children = NULL;
283    cw->composite.num_slots = 0;
284}
285