1249c3046Smrg/* 2444c061aSmrg * 3444c061aSmrg * Author: Chris D. Peterson, MIT X Consortium 4444c061aSmrg */ 5444c061aSmrg 61477040fSmrg/************************************************************ 71477040fSmrg 8fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates. 91477040fSmrg 101477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a 111477040fSmrgcopy of this software and associated documentation files (the "Software"), 121477040fSmrgto deal in the Software without restriction, including without limitation 131477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense, 141477040fSmrgand/or sell copies of the Software, and to permit persons to whom the 151477040fSmrgSoftware is furnished to do so, subject to the following conditions: 161477040fSmrg 171477040fSmrgThe above copyright notice and this permission notice (including the next 181477040fSmrgparagraph) shall be included in all copies or substantial portions of the 191477040fSmrgSoftware. 201477040fSmrg 211477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 221477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 231477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 241477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 251477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 261477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 271477040fSmrgDEALINGS IN THE SOFTWARE. 281477040fSmrg 291477040fSmrg********************************************************/ 30444c061aSmrg 31444c061aSmrg/* 32444c061aSmrg 33444c061aSmrgCopyright 1989, 1994, 1998 The Open Group 34444c061aSmrg 35444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 36444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 37444c061aSmrgthe above copyright notice appear in all copies and that both that 38444c061aSmrgcopyright notice and this permission notice appear in supporting 39444c061aSmrgdocumentation. 40444c061aSmrg 41444c061aSmrgThe above copyright notice and this permission notice shall be included in 42444c061aSmrgall copies or substantial portions of the Software. 43444c061aSmrg 44444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 48444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 49444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 50444c061aSmrg 51444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 52444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 53444c061aSmrgin this Software without prior written authorization from The Open Group. 54444c061aSmrg 55444c061aSmrg*/ 56444c061aSmrg 57444c061aSmrg#ifdef HAVE_CONFIG_H 58444c061aSmrg#include <config.h> 59444c061aSmrg#endif 60444c061aSmrg#include "IntrinsicI.h" 61444c061aSmrg#include <X11/Xatom.h> 62444c061aSmrg 63a3bd7f05Smrg/* Function Name: XtSetWMColormapWindows 64444c061aSmrg * 65a3bd7f05Smrg * Description: Sets the value of the WM_COLORMAP_WINDOWS 66444c061aSmrg * property on a widget's window. 67444c061aSmrg * 68a3bd7f05Smrg * Arguments: widget - specifies the widget on whose window the 69a3bd7f05Smrg * - WM_COLORMAP_WINDOWS property will be stored. 70444c061aSmrg * 71444c061aSmrg * list - Specifies a list of widgets whose windows are to be 72a3bd7f05Smrg * listed in the WM_COLORMAP_WINDOWS property. 73444c061aSmrg * count - Specifies the number of widgets in list. 74444c061aSmrg * 75a3bd7f05Smrg * Returns: none. 76444c061aSmrg */ 77444c061aSmrg 78444c061aSmrgvoid 79a3bd7f05SmrgXtSetWMColormapWindows(Widget widget, Widget *list, Cardinal count) 80444c061aSmrg{ 81444c061aSmrg Window *data; 82444c061aSmrg Widget *checked, *top, *temp, hookobj; 83444c061aSmrg Cardinal i, j, checked_count; 84444c061aSmrg Boolean match; 85444c061aSmrg Atom xa_wm_colormap_windows; 86a3bd7f05Smrg 87444c061aSmrg WIDGET_TO_APPCON(widget); 88444c061aSmrg 89444c061aSmrg LOCK_APP(app); 90a3bd7f05Smrg if (!XtIsRealized(widget) || (count == 0)) { 91a3bd7f05Smrg UNLOCK_APP(app); 92a3bd7f05Smrg return; 93444c061aSmrg } 94444c061aSmrg 95fdf6a26fSmrg top = checked = XtMallocArray(count, (Cardinal) sizeof(Widget)); 96444c061aSmrg 97444c061aSmrg/* 98444c061aSmrg * The specification calls for only adding the windows that have unique 99444c061aSmrg * colormaps to the property to this function, so we will make a pass through 100444c061aSmrg * the widget list removing all the widgets with non-unique colormaps. 101444c061aSmrg * 102444c061aSmrg * We will also remove any unrealized widgets from the list at this time. 103444c061aSmrg */ 104444c061aSmrg 105444c061aSmrg for (checked_count = 0, i = 0; i < count; i++) { 106a3bd7f05Smrg if (!XtIsRealized(list[i])) 107a3bd7f05Smrg continue; 108444c061aSmrg 109a3bd7f05Smrg *checked = list[i]; 110a3bd7f05Smrg match = FALSE; 111444c061aSmrg 112444c061aSmrg/* 113444c061aSmrg * Don't check first element for matching colormap since there is nothing 114444c061aSmrg * to check it against. 115444c061aSmrg */ 116444c061aSmrg 117a3bd7f05Smrg if (checked != top) 118a3bd7f05Smrg for (j = 0, temp = top; j < checked_count; j++, temp++) 119a3bd7f05Smrg if ((*temp)->core.colormap == (*checked)->core.colormap) { 120a3bd7f05Smrg match = TRUE; 121a3bd7f05Smrg break; 122a3bd7f05Smrg } 123444c061aSmrg 124444c061aSmrg/* 125444c061aSmrg * If no colormap was found to match then add this widget to the linked list. 126444c061aSmrg */ 127444c061aSmrg 128a3bd7f05Smrg if (!match) { 129a3bd7f05Smrg checked++; 130a3bd7f05Smrg checked_count++; 131a3bd7f05Smrg } 132444c061aSmrg } 133444c061aSmrg 134444c061aSmrg/* 135444c061aSmrg * Now that we have the list of widgets we need to convert it to a list of 136444c061aSmrg * windows and set the property. 137444c061aSmrg */ 138444c061aSmrg 139fdf6a26fSmrg data = XtMallocArray(checked_count, (Cardinal) sizeof(Window)); 140444c061aSmrg 141a3bd7f05Smrg for (i = 0; i < checked_count; i++) 142a3bd7f05Smrg data[i] = XtWindow(top[i]); 143444c061aSmrg 144444c061aSmrg xa_wm_colormap_windows = XInternAtom(XtDisplay(widget), 145a3bd7f05Smrg "WM_COLORMAP_WINDOWS", FALSE); 146444c061aSmrg 147444c061aSmrg XChangeProperty(XtDisplay(widget), XtWindow(widget), 148a3bd7f05Smrg xa_wm_colormap_windows, XA_WINDOW, 32, 149a3bd7f05Smrg PropModeReplace, (unsigned char *) data, (int) i); 150444c061aSmrg 151444c061aSmrg hookobj = XtHooksOfDisplay(XtDisplay(widget)); 152444c061aSmrg if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) { 153a3bd7f05Smrg XtChangeHookDataRec call_data; 154a3bd7f05Smrg 155a3bd7f05Smrg call_data.type = XtHsetWMColormapWindows; 156a3bd7f05Smrg call_data.widget = widget; 157a3bd7f05Smrg call_data.event_data = (XtPointer) list; 158a3bd7f05Smrg call_data.num_event_data = count; 159a3bd7f05Smrg XtCallCallbackList(hookobj, 160a3bd7f05Smrg ((HookObject) hookobj)->hooks.changehook_callbacks, 161a3bd7f05Smrg (XtPointer) &call_data); 162444c061aSmrg } 163444c061aSmrg 164a3bd7f05Smrg XtFree((char *) data); 165a3bd7f05Smrg XtFree((char *) top); 166444c061aSmrg UNLOCK_APP(app); 167444c061aSmrg} 168