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