SetWMCW.c revision 444c061a
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
7444c061aSmrg/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
8444c061aSmrg *
9444c061aSmrg * Permission is hereby granted, free of charge, to any person obtaining a
10444c061aSmrg * copy of this software and associated documentation files (the
11444c061aSmrg * "Software"), to deal in the Software without restriction, including
12444c061aSmrg * without limitation the rights to use, copy, modify, merge, publish,
13444c061aSmrg * distribute, and/or sell copies of the Software, and to permit persons
14444c061aSmrg * to whom the Software is furnished to do so, provided that the above
15444c061aSmrg * copyright notice(s) and this permission notice appear in all copies of
16444c061aSmrg * the Software and that both the above copyright notice(s) and this
17444c061aSmrg * permission notice appear in supporting documentation.
18444c061aSmrg *
19444c061aSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20444c061aSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21444c061aSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22444c061aSmrg * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23444c061aSmrg * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24444c061aSmrg * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25444c061aSmrg * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26444c061aSmrg * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27444c061aSmrg * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28444c061aSmrg *
29444c061aSmrg * Except as contained in this notice, the name of a copyright holder
30444c061aSmrg * shall not be used in advertising or otherwise to promote the sale, use
31444c061aSmrg * or other dealings in this Software without prior written authorization
32444c061aSmrg * of the copyright holder.
33444c061aSmrg */
34444c061aSmrg
35444c061aSmrg/*
36444c061aSmrg
37444c061aSmrgCopyright 1989, 1994, 1998  The Open Group
38444c061aSmrg
39444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
40444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
41444c061aSmrgthe above copyright notice appear in all copies and that both that
42444c061aSmrgcopyright notice and this permission notice appear in supporting
43444c061aSmrgdocumentation.
44444c061aSmrg
45444c061aSmrgThe above copyright notice and this permission notice shall be included in
46444c061aSmrgall copies or substantial portions of the Software.
47444c061aSmrg
48444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
51444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
52444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54444c061aSmrg
55444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
56444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
57444c061aSmrgin this Software without prior written authorization from The Open Group.
58444c061aSmrg
59444c061aSmrg*/
60444c061aSmrg
61444c061aSmrg#ifdef HAVE_CONFIG_H
62444c061aSmrg#include <config.h>
63444c061aSmrg#endif
64444c061aSmrg#include "IntrinsicI.h"
65444c061aSmrg#include <X11/Xatom.h>
66444c061aSmrg
67444c061aSmrg/*	Function Name: XtSetWMColormapWindows
68444c061aSmrg *
69444c061aSmrg *	Description: Sets the value of the WM_COLORMAP_WINDOWS
70444c061aSmrg *                   property on a widget's window.
71444c061aSmrg *
72444c061aSmrg *	Arguments:  widget - specifies the widget on whose window the
73444c061aSmrg *   		           - WM_COLORMAP_WINDOWS property will be stored.
74444c061aSmrg *
75444c061aSmrg *                  list - Specifies a list of widgets whose windows are to be
76444c061aSmrg *		           listed in the WM_COLORMAP_WINDOWS property.
77444c061aSmrg *                  count - Specifies the number of widgets in list.
78444c061aSmrg *
79444c061aSmrg *	Returns: none.
80444c061aSmrg */
81444c061aSmrg
82444c061aSmrgvoid
83444c061aSmrgXtSetWMColormapWindows(
84444c061aSmrg    Widget widget,
85444c061aSmrg    Widget *list,
86444c061aSmrg    Cardinal count)
87444c061aSmrg{
88444c061aSmrg    Window *data;
89444c061aSmrg    Widget *checked, *top, *temp, hookobj;
90444c061aSmrg    Cardinal i, j, checked_count;
91444c061aSmrg    Boolean match;
92444c061aSmrg    Atom xa_wm_colormap_windows;
93444c061aSmrg    WIDGET_TO_APPCON(widget);
94444c061aSmrg
95444c061aSmrg    LOCK_APP(app);
96444c061aSmrg    if ( !XtIsRealized(widget) || (count == 0) ) {
97444c061aSmrg	UNLOCK_APP(app);
98444c061aSmrg	return;
99444c061aSmrg    }
100444c061aSmrg
101444c061aSmrg    top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count);
102444c061aSmrg
103444c061aSmrg
104444c061aSmrg/*
105444c061aSmrg * The specification calls for only adding the windows that have unique
106444c061aSmrg * colormaps to the property to this function, so we will make a pass through
107444c061aSmrg * the widget list removing all the widgets with non-unique colormaps.
108444c061aSmrg *
109444c061aSmrg * We will also remove any unrealized widgets from the list at this time.
110444c061aSmrg */
111444c061aSmrg
112444c061aSmrg    for (checked_count = 0, i = 0; i < count; i++) {
113444c061aSmrg	if (!XtIsRealized(list[i])) continue;
114444c061aSmrg
115444c061aSmrg	*checked = list[i];
116444c061aSmrg	match = FALSE;
117444c061aSmrg
118444c061aSmrg/*
119444c061aSmrg * Don't check first element for matching colormap since there is nothing
120444c061aSmrg * to check it against.
121444c061aSmrg */
122444c061aSmrg
123444c061aSmrg	if (checked != top)
124444c061aSmrg	    for (j = 0, temp = top; j < checked_count ; j++, temp++)
125444c061aSmrg		if ( (*temp)->core.colormap == (*checked)->core.colormap) {
126444c061aSmrg		    match = TRUE;
127444c061aSmrg		    break;
128444c061aSmrg		}
129444c061aSmrg
130444c061aSmrg/*
131444c061aSmrg * If no colormap was found to match then add this widget to the linked list.
132444c061aSmrg */
133444c061aSmrg
134444c061aSmrg	if (!match) {
135444c061aSmrg	    checked++;
136444c061aSmrg	    checked_count++;
137444c061aSmrg	}
138444c061aSmrg    }
139444c061aSmrg
140444c061aSmrg/*
141444c061aSmrg * Now that we have the list of widgets we need to convert it to a list of
142444c061aSmrg * windows and set the property.
143444c061aSmrg */
144444c061aSmrg
145444c061aSmrg    data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count);
146444c061aSmrg
147444c061aSmrg    for ( i = 0 ; i < checked_count ; i++)
148444c061aSmrg	data[i] = XtWindow(top[i]);
149444c061aSmrg
150444c061aSmrg    xa_wm_colormap_windows = XInternAtom(XtDisplay(widget),
151444c061aSmrg					 "WM_COLORMAP_WINDOWS", FALSE);
152444c061aSmrg
153444c061aSmrg    XChangeProperty(XtDisplay(widget), XtWindow(widget),
154444c061aSmrg		    xa_wm_colormap_windows, XA_WINDOW, 32,
155444c061aSmrg		    PropModeReplace, (unsigned char *) data, (int) i);
156444c061aSmrg
157444c061aSmrg    hookobj = XtHooksOfDisplay(XtDisplay(widget));
158444c061aSmrg    if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
159444c061aSmrg	XtChangeHookDataRec call_data;
160444c061aSmrg
161444c061aSmrg	call_data.type = XtHsetWMColormapWindows;
162444c061aSmrg	call_data.widget = widget;
163444c061aSmrg	call_data.event_data = (XtPointer) list;
164444c061aSmrg	call_data.num_event_data = count;
165444c061aSmrg	XtCallCallbackList(hookobj,
166444c061aSmrg		((HookObject)hookobj)->hooks.changehook_callbacks,
167444c061aSmrg		(XtPointer)&call_data);
168444c061aSmrg    }
169444c061aSmrg
170444c061aSmrg    XtFree( (char *) data);
171444c061aSmrg    XtFree( (char *) top);
172444c061aSmrg    UNLOCK_APP(app);
173444c061aSmrg}
174