SetWMCW.c revision 249c3046
1249c3046Smrg/*
2444c061aSmrg *
3444c061aSmrg * Author:  Chris D. Peterson, MIT X Consortium
4444c061aSmrg */
5444c061aSmrg
61477040fSmrg/************************************************************
71477040fSmrg
8249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
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
63444c061aSmrg/*	Function Name: XtSetWMColormapWindows
64444c061aSmrg *
65444c061aSmrg *	Description: Sets the value of the WM_COLORMAP_WINDOWS
66444c061aSmrg *                   property on a widget's window.
67444c061aSmrg *
68444c061aSmrg *	Arguments:  widget - specifies the widget on whose window the
69444c061aSmrg *   		           - WM_COLORMAP_WINDOWS property will be stored.
70444c061aSmrg *
71444c061aSmrg *                  list - Specifies a list of widgets whose windows are to be
72444c061aSmrg *		           listed in the WM_COLORMAP_WINDOWS property.
73444c061aSmrg *                  count - Specifies the number of widgets in list.
74444c061aSmrg *
75444c061aSmrg *	Returns: none.
76444c061aSmrg */
77444c061aSmrg
78444c061aSmrgvoid
79444c061aSmrgXtSetWMColormapWindows(
80444c061aSmrg    Widget widget,
81444c061aSmrg    Widget *list,
82444c061aSmrg    Cardinal count)
83444c061aSmrg{
84444c061aSmrg    Window *data;
85444c061aSmrg    Widget *checked, *top, *temp, hookobj;
86444c061aSmrg    Cardinal i, j, checked_count;
87444c061aSmrg    Boolean match;
88444c061aSmrg    Atom xa_wm_colormap_windows;
89444c061aSmrg    WIDGET_TO_APPCON(widget);
90444c061aSmrg
91444c061aSmrg    LOCK_APP(app);
92444c061aSmrg    if ( !XtIsRealized(widget) || (count == 0) ) {
93444c061aSmrg	UNLOCK_APP(app);
94444c061aSmrg	return;
95444c061aSmrg    }
96444c061aSmrg
97444c061aSmrg    top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count);
98444c061aSmrg
99444c061aSmrg
100444c061aSmrg/*
101444c061aSmrg * The specification calls for only adding the windows that have unique
102444c061aSmrg * colormaps to the property to this function, so we will make a pass through
103444c061aSmrg * the widget list removing all the widgets with non-unique colormaps.
104444c061aSmrg *
105444c061aSmrg * We will also remove any unrealized widgets from the list at this time.
106444c061aSmrg */
107444c061aSmrg
108444c061aSmrg    for (checked_count = 0, i = 0; i < count; i++) {
109444c061aSmrg	if (!XtIsRealized(list[i])) continue;
110444c061aSmrg
111444c061aSmrg	*checked = list[i];
112444c061aSmrg	match = FALSE;
113444c061aSmrg
114444c061aSmrg/*
115444c061aSmrg * Don't check first element for matching colormap since there is nothing
116444c061aSmrg * to check it against.
117444c061aSmrg */
118444c061aSmrg
119444c061aSmrg	if (checked != top)
120444c061aSmrg	    for (j = 0, temp = top; j < checked_count ; j++, temp++)
121444c061aSmrg		if ( (*temp)->core.colormap == (*checked)->core.colormap) {
122444c061aSmrg		    match = TRUE;
123444c061aSmrg		    break;
124444c061aSmrg		}
125444c061aSmrg
126444c061aSmrg/*
127444c061aSmrg * If no colormap was found to match then add this widget to the linked list.
128444c061aSmrg */
129444c061aSmrg
130444c061aSmrg	if (!match) {
131444c061aSmrg	    checked++;
132444c061aSmrg	    checked_count++;
133444c061aSmrg	}
134444c061aSmrg    }
135444c061aSmrg
136444c061aSmrg/*
137444c061aSmrg * Now that we have the list of widgets we need to convert it to a list of
138444c061aSmrg * windows and set the property.
139444c061aSmrg */
140444c061aSmrg
141444c061aSmrg    data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count);
142444c061aSmrg
143444c061aSmrg    for ( i = 0 ; i < checked_count ; i++)
144444c061aSmrg	data[i] = XtWindow(top[i]);
145444c061aSmrg
146444c061aSmrg    xa_wm_colormap_windows = XInternAtom(XtDisplay(widget),
147444c061aSmrg					 "WM_COLORMAP_WINDOWS", FALSE);
148444c061aSmrg
149444c061aSmrg    XChangeProperty(XtDisplay(widget), XtWindow(widget),
150444c061aSmrg		    xa_wm_colormap_windows, XA_WINDOW, 32,
151444c061aSmrg		    PropModeReplace, (unsigned char *) data, (int) i);
152444c061aSmrg
153444c061aSmrg    hookobj = XtHooksOfDisplay(XtDisplay(widget));
154444c061aSmrg    if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
155444c061aSmrg	XtChangeHookDataRec call_data;
156444c061aSmrg
157444c061aSmrg	call_data.type = XtHsetWMColormapWindows;
158444c061aSmrg	call_data.widget = widget;
159444c061aSmrg	call_data.event_data = (XtPointer) list;
160444c061aSmrg	call_data.num_event_data = count;
161444c061aSmrg	XtCallCallbackList(hookobj,
162444c061aSmrg		((HookObject)hookobj)->hooks.changehook_callbacks,
163444c061aSmrg		(XtPointer)&call_data);
164444c061aSmrg    }
165444c061aSmrg
166444c061aSmrg    XtFree( (char *) data);
167444c061aSmrg    XtFree( (char *) top);
168444c061aSmrg    UNLOCK_APP(app);
169444c061aSmrg}
170