Composite.c revision 2265a131
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#ifdef HAVE_CONFIG_H 64#include <config.h> 65#endif 66#include "IntrinsicI.h" 67#include "StringDefs.h" 68 69static XtResource resources[] = { 70 {XtNchildren, XtCReadOnly, XtRWidgetList, sizeof(WidgetList), 71 XtOffsetOf(CompositeRec, composite.children), XtRImmediate, NULL}, 72 {XtNnumChildren, XtCReadOnly, XtRCardinal, sizeof(Cardinal), 73 XtOffsetOf(CompositeRec, composite.num_children), XtRImmediate, NULL}, 74 {XtNinsertPosition, XtCInsertPosition, XtRFunction, sizeof(XtOrderProc), 75 XtOffsetOf(CompositeRec, composite.insert_position), XtRImmediate, NULL}, 76}; 77 78static void CompositeClassPartInitialize(WidgetClass); 79static void CompositeInitialize(Widget, Widget, ArgList, Cardinal *); 80static void CompositeInsertChild(Widget); 81static void CompositeDeleteChild(Widget); 82static void CompositeDestroy(Widget); 83 84externaldef(compositeclassrec) CompositeClassRec compositeClassRec = { 85 { /******* CorePart *******/ 86 /* superclass */ &widgetClassRec, 87 /* class_name */ "Composite", 88 /* widget_size */ sizeof(CompositeRec), 89 /* class_initialize */ NULL, 90 /* class_part_initialize*/ CompositeClassPartInitialize, 91 /* class_inited */ FALSE, 92 /* initialize */ CompositeInitialize, 93 /* initialize_hook */ NULL, 94 /* realize */ XtInheritRealize, 95 /* actions */ NULL, 96 /* num_actions */ 0, 97 /* resources */ resources, 98 /* num_resources */ XtNumber(resources), 99 /* xrm_class */ NULLQUARK, 100 /* compress_motion */ FALSE, 101 /* compress_exposure */ TRUE, 102 /* compress_enterleave */ FALSE, 103 /* visible_interest */ FALSE, 104 /* destroy */ CompositeDestroy, 105 /* resize */ NULL, 106 /* expose */ NULL, 107 /* set_values */ NULL, 108 /* set_values_hook */ NULL, 109 /* set_values_almost */ XtInheritSetValuesAlmost, 110 /* get_values_hook */ NULL, 111 /* accept_focus */ NULL, 112 /* version */ XtVersion, 113 /* callback_offsets */ NULL, 114 /* tm_table */ NULL, 115 /* query_geometry */ NULL, 116 /* display_accelerator */ NULL, 117 /* extension */ NULL 118 }, 119 { /**** CompositePart *****/ 120 /* geometry_handler */ NULL, 121 /* change_managed */ NULL, 122 /* insert_child */ CompositeInsertChild, 123 /* delete_child */ CompositeDeleteChild, 124 /* extension */ NULL 125 } 126}; 127 128externaldef(compositewidgetclass) WidgetClass compositeWidgetClass = (WidgetClass) &compositeClassRec; 129 130static void InheritAllowsChangeManagedSet( 131 WidgetClass widget_class) 132{ 133 CompositeWidgetClass cc = (CompositeWidgetClass) widget_class; 134 CompositeClassExtension ext, super_ext, new_ext; 135 136 ext = (CompositeClassExtension) 137 XtGetClassExtension(widget_class, 138 XtOffsetOf(CompositeClassRec, composite_class.extension), 139 NULLQUARK, 1L, 0); 140 141 if (ext && ext->version == XtCompositeExtensionVersion) 142 return; 143 144 super_ext = (CompositeClassExtension) 145 XtGetClassExtension(cc->core_class.superclass, 146 XtOffsetOf(CompositeClassRec, composite_class.extension), 147 NULLQUARK, 1L, 0); 148 149 LOCK_PROCESS; 150 if (super_ext && super_ext->version == XtCompositeExtensionVersion && 151 super_ext->record_size == sizeof(CompositeClassExtensionRec) && 152 super_ext->allows_change_managed_set) { 153 154 new_ext = (CompositeClassExtension) 155 __XtCalloc(1, sizeof(CompositeClassExtensionRec)); 156 157 /* Be careful to inherit only what is appropriate */ 158 new_ext->next_extension = cc->composite_class.extension; 159 new_ext->record_type = NULLQUARK; 160 new_ext->version = XtCompositeExtensionVersion; 161 new_ext->record_size = sizeof(CompositeClassExtensionRec); 162 new_ext->accepts_objects = (ext ? ext->accepts_objects : False); 163 new_ext->allows_change_managed_set = True; 164 cc->composite_class.extension = (XtPointer) new_ext; 165 } 166 UNLOCK_PROCESS; 167} 168 169static void CompositeClassPartInitialize( 170 WidgetClass widgetClass) 171{ 172 register CompositePartPtr wcPtr; 173 register CompositePartPtr superPtr = NULL; 174 175 wcPtr = (CompositePartPtr) 176 &(((CompositeWidgetClass)widgetClass)->composite_class); 177 178 if (widgetClass != compositeWidgetClass) 179 /* don't compute possible bogus pointer */ 180 superPtr = (CompositePartPtr)&(((CompositeWidgetClass)widgetClass 181 ->core_class.superclass)->composite_class); 182 183 /* We don't need to check for null super since we'll get to composite 184 eventually, and it had better define them! */ 185 186 LOCK_PROCESS; 187 if (wcPtr->geometry_manager == XtInheritGeometryManager) { 188 wcPtr->geometry_manager = 189 superPtr->geometry_manager; 190 } 191 192 if (wcPtr->change_managed == XtInheritChangeManaged) { 193 wcPtr->change_managed = 194 superPtr->change_managed; 195 InheritAllowsChangeManagedSet(widgetClass); 196 } 197 198 if (wcPtr->insert_child == XtInheritInsertChild) { 199 wcPtr->insert_child = superPtr->insert_child; 200 } 201 202 if (wcPtr->delete_child == XtInheritDeleteChild) { 203 wcPtr->delete_child = superPtr->delete_child; 204 } 205 UNLOCK_PROCESS; 206} 207 208static void CompositeDestroy( 209 Widget w) 210{ 211 register CompositeWidget cw = (CompositeWidget) w; 212 213 XtFree((char *) cw->composite.children); 214} 215 216static void CompositeInsertChild( 217 Widget w) 218{ 219 register Cardinal position; 220 register Cardinal i; 221 register CompositeWidget cw; 222 register WidgetList children; 223 224 cw = (CompositeWidget) w->core.parent; 225 children = cw->composite.children; 226 227 if (cw->composite.insert_position != NULL) 228 position = (*(cw->composite.insert_position))(w); 229 else 230 position = cw->composite.num_children; 231 232 if (cw->composite.num_children == cw->composite.num_slots) { 233 /* Allocate more space */ 234 cw->composite.num_slots += (cw->composite.num_slots / 2) + 2; 235 cw->composite.children = children = 236 (WidgetList) XtRealloc((XtPointer) children, 237 (unsigned) (cw->composite.num_slots) * sizeof(Widget)); 238 } 239 /* Ripple children up one space from "position" */ 240 for (i = cw->composite.num_children; i > position; i--) { 241 children[i] = children[i-1]; 242 } 243 children[position] = w; 244 cw->composite.num_children++; 245} 246 247static void CompositeDeleteChild( 248 Widget w) 249{ 250 register Cardinal position; 251 register Cardinal i; 252 register CompositeWidget cw; 253 254 cw = (CompositeWidget) w->core.parent; 255 256 for (position = 0; position < cw->composite.num_children; position++) { 257 if (cw->composite.children[position] == w) { 258 break; 259 } 260 } 261 if (position == cw->composite.num_children) return; 262 263 /* Ripple children down one space from "position" */ 264 cw->composite.num_children--; 265 for (i = position; i < cw->composite.num_children; i++) { 266 cw->composite.children[i] = cw->composite.children[i+1]; 267 } 268} 269 270/* ARGSUSED */ 271static void CompositeInitialize( 272 Widget requested_widget, 273 Widget new_widget, 274 ArgList args, 275 Cardinal *num_args) 276{ 277 register CompositeWidget cw; 278 279 cw = (CompositeWidget) new_widget; 280 cw->composite.num_children = 0; 281 cw->composite.children = NULL; 282 cw->composite.num_slots = 0; 283} 284