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