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