SetWMCW.c revision 1477040f
1/* $Xorg: SetWMCW.c,v 1.4 2001/02/09 02:03:58 xorgcvs Exp $ */ 2/* $XdotOrg: $ 3 * 4 * Author: Chris D. Peterson, MIT X Consortium 5 */ 6 7/************************************************************ 8 9Copyright 1993 Sun Microsystems, Inc. All rights reserved. 10 11Permission is hereby granted, free of charge, to any person obtaining a 12copy of this software and associated documentation files (the "Software"), 13to deal in the Software without restriction, including without limitation 14the rights to use, copy, modify, merge, publish, distribute, sublicense, 15and/or sell copies of the Software, and to permit persons to whom the 16Software is furnished to do so, subject to the following conditions: 17 18The above copyright notice and this permission notice (including the next 19paragraph) shall be included in all copies or substantial portions of the 20Software. 21 22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28DEALINGS IN THE SOFTWARE. 29 30********************************************************/ 31 32/* 33 34Copyright 1989, 1994, 1998 The Open Group 35 36Permission to use, copy, modify, distribute, and sell this software and its 37documentation for any purpose is hereby granted without fee, provided that 38the above copyright notice appear in all copies and that both that 39copyright notice and this permission notice appear in supporting 40documentation. 41 42The above copyright notice and this permission notice shall be included in 43all copies or substantial portions of the Software. 44 45THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 49AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 50CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 51 52Except as contained in this notice, the name of The Open Group shall not be 53used in advertising or otherwise to promote the sale, use or other dealings 54in this Software without prior written authorization from The Open Group. 55 56*/ 57 58#ifdef HAVE_CONFIG_H 59#include <config.h> 60#endif 61#include "IntrinsicI.h" 62#include <X11/Xatom.h> 63 64/* Function Name: XtSetWMColormapWindows 65 * 66 * Description: Sets the value of the WM_COLORMAP_WINDOWS 67 * property on a widget's window. 68 * 69 * Arguments: widget - specifies the widget on whose window the 70 * - WM_COLORMAP_WINDOWS property will be stored. 71 * 72 * list - Specifies a list of widgets whose windows are to be 73 * listed in the WM_COLORMAP_WINDOWS property. 74 * count - Specifies the number of widgets in list. 75 * 76 * Returns: none. 77 */ 78 79void 80XtSetWMColormapWindows( 81 Widget widget, 82 Widget *list, 83 Cardinal count) 84{ 85 Window *data; 86 Widget *checked, *top, *temp, hookobj; 87 Cardinal i, j, checked_count; 88 Boolean match; 89 Atom xa_wm_colormap_windows; 90 WIDGET_TO_APPCON(widget); 91 92 LOCK_APP(app); 93 if ( !XtIsRealized(widget) || (count == 0) ) { 94 UNLOCK_APP(app); 95 return; 96 } 97 98 top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count); 99 100 101/* 102 * The specification calls for only adding the windows that have unique 103 * colormaps to the property to this function, so we will make a pass through 104 * the widget list removing all the widgets with non-unique colormaps. 105 * 106 * We will also remove any unrealized widgets from the list at this time. 107 */ 108 109 for (checked_count = 0, i = 0; i < count; i++) { 110 if (!XtIsRealized(list[i])) continue; 111 112 *checked = list[i]; 113 match = FALSE; 114 115/* 116 * Don't check first element for matching colormap since there is nothing 117 * to check it against. 118 */ 119 120 if (checked != top) 121 for (j = 0, temp = top; j < checked_count ; j++, temp++) 122 if ( (*temp)->core.colormap == (*checked)->core.colormap) { 123 match = TRUE; 124 break; 125 } 126 127/* 128 * If no colormap was found to match then add this widget to the linked list. 129 */ 130 131 if (!match) { 132 checked++; 133 checked_count++; 134 } 135 } 136 137/* 138 * Now that we have the list of widgets we need to convert it to a list of 139 * windows and set the property. 140 */ 141 142 data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count); 143 144 for ( i = 0 ; i < checked_count ; i++) 145 data[i] = XtWindow(top[i]); 146 147 xa_wm_colormap_windows = XInternAtom(XtDisplay(widget), 148 "WM_COLORMAP_WINDOWS", FALSE); 149 150 XChangeProperty(XtDisplay(widget), XtWindow(widget), 151 xa_wm_colormap_windows, XA_WINDOW, 32, 152 PropModeReplace, (unsigned char *) data, (int) i); 153 154 hookobj = XtHooksOfDisplay(XtDisplay(widget)); 155 if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) { 156 XtChangeHookDataRec call_data; 157 158 call_data.type = XtHsetWMColormapWindows; 159 call_data.widget = widget; 160 call_data.event_data = (XtPointer) list; 161 call_data.num_event_data = count; 162 XtCallCallbackList(hookobj, 163 ((HookObject)hookobj)->hooks.changehook_callbacks, 164 (XtPointer)&call_data); 165 } 166 167 XtFree( (char *) data); 168 XtFree( (char *) top); 169 UNLOCK_APP(app); 170} 171