home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / SetWMCW.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-08  |  3.8 KB  |  126 lines

  1. /* $XConsortium: SetWMCW.c,v 1.4 91/01/08 15:06:58 converse Exp $ */
  2. /*
  3.  * Copyright 1989 Massachusetts Institute of Technology
  4.  *
  5.  * Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of M.I.T. not be used in advertising or
  10.  * publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.  M.I.T. makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  17.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Chris D. Peterson, MIT X Consortium
  23.  */
  24.  
  25. #include "IntrinsicI.h"
  26. #include <X11/Xatom.h>
  27.  
  28. /*    Function Name: XtSetWMColormapWindows
  29.  *
  30.  *    Description: Sets the value of the WM_COLORMAP_WINDOWS
  31.  *                   property on a widget's window.
  32.  *
  33.  *    Arguments:  widget - specifies the widget on whose window the
  34.  *                      - WM_COLORMAP_WINDOWS property will be stored.
  35.  *
  36.  *                  list - Specifies a list of widgets whose windows are to be
  37.  *                   listed in the WM_COLORMAP_WINDOWS property.
  38.  *                  count - Specifies the number of widgets in list.
  39.  *
  40.  *    Returns: none.
  41.  */
  42.  
  43. void
  44. XtSetWMColormapWindows(widget, list, count)
  45. Widget widget, *list;
  46. Cardinal count;
  47. {
  48.     Window *data;
  49.     Widget *checked, *top, *temp;
  50.     register Cardinal i, j, checked_count;
  51.     register Boolean match;
  52.     Atom xa_wm_colormap_windows;
  53.  
  54.     if ( !XtIsRealized(widget) || (count == 0) ) return;
  55.  
  56.     top = checked = (Widget *) XtMalloc( (Cardinal) sizeof(Widget) * count);
  57.  
  58.  
  59. /*
  60.  * The specification calls for only adding the windows that have unique 
  61.  * colormaps to the property to this function, so we will make a pass through
  62.  * the widget list removing all the widgets with non-unique colormaps.
  63.  *
  64.  * We will also remove any unrealized widgets from the list at this time.
  65.  */
  66.  
  67.     for (checked_count = 0, i = 0; i < count; i++) {
  68.     if (!XtIsRealized(list[i])) continue;
  69.         
  70.     *checked = list[i];
  71.     match = FALSE;
  72.  
  73. /*
  74.  * Don't check first element for matching colormap since there is nothing
  75.  * to check it against.
  76.  */
  77.  
  78.     if (checked != top)    
  79.         for (j = 0, temp = top; j < checked_count ; j++, temp++)
  80.         if ( (*temp)->core.colormap == (*checked)->core.colormap) {
  81.             match = TRUE;
  82.             break;
  83.         }
  84.  
  85. /*
  86.  * If no colormap was found to match then add this widget to the linked list.
  87.  */
  88.  
  89.     if (!match) {
  90.         checked++;
  91.         checked_count++;
  92.     }
  93.     }
  94.  
  95. /*
  96.  * Now that we have the list of widgets we need to convert it to a list of
  97.  * windows and set the property.
  98.  */
  99.  
  100.     data = (Window *) XtMalloc( (Cardinal) sizeof(Window) * checked_count);
  101.  
  102.     for ( i = 0 ; i < checked_count ; i++)
  103.     data[i] = XtWindow(top[i]);
  104.  
  105. /*
  106.  * Relax, there's an atom cache in Xlib.
  107.  */
  108.  
  109.     xa_wm_colormap_windows = XInternAtom(XtDisplay(widget),
  110.                      "WM_COLORMAP_WINDOWS", FALSE);
  111.  
  112. /*
  113.  * No need to check return from XInternAtom() since the atom will be
  114.  * created if it doesn't exist.
  115.  */
  116.  
  117.     XChangeProperty(XtDisplay(widget), XtWindow(widget), 
  118.             xa_wm_colormap_windows, XA_WINDOW, 32,
  119.             PropModeReplace, (unsigned char *) data, (int) i);
  120.  
  121.     XtFree( (char *) data);
  122.     XtFree( (char *) top);
  123. }
  124.             
  125.     
  126.