SetWMCW.c revision 1477040f
1444c061aSmrg/* $Xorg: SetWMCW.c,v 1.4 2001/02/09 02:03:58 xorgcvs Exp $ */
2444c061aSmrg/* $XdotOrg: $
3444c061aSmrg *
4444c061aSmrg * Author:  Chris D. Peterson, MIT X Consortium
5444c061aSmrg */
6444c061aSmrg
71477040fSmrg/************************************************************
81477040fSmrg
91477040fSmrgCopyright 1993 Sun Microsystems, Inc.  All rights reserved.
101477040fSmrg
111477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
121477040fSmrgcopy of this software and associated documentation files (the "Software"),
131477040fSmrgto deal in the Software without restriction, including without limitation
141477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
151477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
161477040fSmrgSoftware is furnished to do so, subject to the following conditions:
171477040fSmrg
181477040fSmrgThe above copyright notice and this permission notice (including the next
191477040fSmrgparagraph) shall be included in all copies or substantial portions of the
201477040fSmrgSoftware.
211477040fSmrg
221477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
231477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
251477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
261477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
271477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
281477040fSmrgDEALINGS IN THE SOFTWARE.
291477040fSmrg
301477040fSmrg********************************************************/
31444c061aSmrg
32444c061aSmrg/*
33444c061aSmrg
34444c061aSmrgCopyright 1989, 1994, 1998  The Open Group
35444c061aSmrg
36444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
37444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
38444c061aSmrgthe above copyright notice appear in all copies and that both that
39444c061aSmrgcopyright notice and this permission notice appear in supporting
40444c061aSmrgdocumentation.
41444c061aSmrg
42444c061aSmrgThe above copyright notice and this permission notice shall be included in
43444c061aSmrgall copies or substantial portions of the Software.
44444c061aSmrg
45444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
48444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
49444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
50444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51444c061aSmrg
52444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
53444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
54444c061aSmrgin this Software without prior written authorization from The Open Group.
55444c061aSmrg
56444c061aSmrg*/
57444c061aSmrg
58444c061aSmrg#ifdef HAVE_CONFIG_H
59444c061aSmrg#include <config.h>
60444c061aSmrg#endif
61444c061aSmrg#include "IntrinsicI.h"
62444c061aSmrg#include <X11/Xatom.h>
63444c061aSmrg
64444c061aSmrg/*	Function Name: XtSetWMColormapWindows
65444c061aSmrg *
66444c061aSmrg *	Description: Sets the value of the WM_COLORMAP_WINDOWS
67444c061aSmrg *                   property on a widget's window.
68444c061aSmrg *
69444c061aSmrg *	Arguments:  widget - specifies the widget on whose window the
70444c061aSmrg *   		           - WM_COLORMAP_WINDOWS property will be stored.
71444c061aSmrg *
72444c061aSmrg *                  list - Specifies a list of widgets whose windows are to be
73444c061aSmrg *		           listed in the WM_COLORMAP_WINDOWS property.
74444c061aSmrg *                  count - Specifies the number of widgets in list.
75444c061aSmrg *
76444c061aSmrg *	Returns: none.
77444c061aSmrg */
78444c061aSmrg
79444c061aSmrgvoid
80444c061aSmrgXtSetWMColormapWindows(
81444c061aSmrg    Widget widget,
82444c061aSmrg    Widget *list,
83444c061aSmrg    Cardinal count)
84444c061aSmrg{
85444c061aSmrg    Window *data;
86444c061aSmrg    Widget *checked, *top, *temp, hookobj;
87444c061aSmrg    Cardinal i, j, checked_count;
88444c061aSmrg    Boolean match;
89444c061aSmrg    Atom xa_wm_colormap_windows;
90444c061aSmrg    WIDGET_TO_APPCON(widget);
91444c061aSmrg
92444c061aSmrg    LOCK_APP(app);
93444c061aSmrg    if ( !XtIsRealized(widget) || (count == 0) ) {
94444c061aSmrg	UNLOCK_APP(app);
95444c061aSmrg	return;
96444c061aSmrg    }
97444c061aSmrg
98444c061aSmrg    top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count);
99444c061aSmrg
100444c061aSmrg
101444c061aSmrg/*
102444c061aSmrg * The specification calls for only adding the windows that have unique
103444c061aSmrg * colormaps to the property to this function, so we will make a pass through
104444c061aSmrg * the widget list removing all the widgets with non-unique colormaps.
105444c061aSmrg *
106444c061aSmrg * We will also remove any unrealized widgets from the list at this time.
107444c061aSmrg */
108444c061aSmrg
109444c061aSmrg    for (checked_count = 0, i = 0; i < count; i++) {
110444c061aSmrg	if (!XtIsRealized(list[i])) continue;
111444c061aSmrg
112444c061aSmrg	*checked = list[i];
113444c061aSmrg	match = FALSE;
114444c061aSmrg
115444c061aSmrg/*
116444c061aSmrg * Don't check first element for matching colormap since there is nothing
117444c061aSmrg * to check it against.
118444c061aSmrg */
119444c061aSmrg
120444c061aSmrg	if (checked != top)
121444c061aSmrg	    for (j = 0, temp = top; j < checked_count ; j++, temp++)
122444c061aSmrg		if ( (*temp)->core.colormap == (*checked)->core.colormap) {
123444c061aSmrg		    match = TRUE;
124444c061aSmrg		    break;
125444c061aSmrg		}
126444c061aSmrg
127444c061aSmrg/*
128444c061aSmrg * If no colormap was found to match then add this widget to the linked list.
129444c061aSmrg */
130444c061aSmrg
131444c061aSmrg	if (!match) {
132444c061aSmrg	    checked++;
133444c061aSmrg	    checked_count++;
134444c061aSmrg	}
135444c061aSmrg    }
136444c061aSmrg
137444c061aSmrg/*
138444c061aSmrg * Now that we have the list of widgets we need to convert it to a list of
139444c061aSmrg * windows and set the property.
140444c061aSmrg */
141444c061aSmrg
142444c061aSmrg    data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count);
143444c061aSmrg
144444c061aSmrg    for ( i = 0 ; i < checked_count ; i++)
145444c061aSmrg	data[i] = XtWindow(top[i]);
146444c061aSmrg
147444c061aSmrg    xa_wm_colormap_windows = XInternAtom(XtDisplay(widget),
148444c061aSmrg					 "WM_COLORMAP_WINDOWS", FALSE);
149444c061aSmrg
150444c061aSmrg    XChangeProperty(XtDisplay(widget), XtWindow(widget),
151444c061aSmrg		    xa_wm_colormap_windows, XA_WINDOW, 32,
152444c061aSmrg		    PropModeReplace, (unsigned char *) data, (int) i);
153444c061aSmrg
154444c061aSmrg    hookobj = XtHooksOfDisplay(XtDisplay(widget));
155444c061aSmrg    if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
156444c061aSmrg	XtChangeHookDataRec call_data;
157444c061aSmrg
158444c061aSmrg	call_data.type = XtHsetWMColormapWindows;
159444c061aSmrg	call_data.widget = widget;
160444c061aSmrg	call_data.event_data = (XtPointer) list;
161444c061aSmrg	call_data.num_event_data = count;
162444c061aSmrg	XtCallCallbackList(hookobj,
163444c061aSmrg		((HookObject)hookobj)->hooks.changehook_callbacks,
164444c061aSmrg		(XtPointer)&call_data);
165444c061aSmrg    }
166444c061aSmrg
167444c061aSmrg    XtFree( (char *) data);
168444c061aSmrg    XtFree( (char *) top);
169444c061aSmrg    UNLOCK_APP(app);
170444c061aSmrg}
171