2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /************************************<+>*************************************
24 ****************************************************************************
26 ** File: ColorPalette.c
30 ** Description: Controls the Dtstyle Color Palette data
33 ** (c) Copyright Hewlett-Packard Company, 1990.
37 ****************************************************************************
38 ************************************<+>*************************************/
39 /* $XConsortium: ColorPalette.c /main/6 1995/10/30 13:08:58 rswiston $ */
40 /*+++++++++++++++++++++++++++++++++++++++*/
42 /*+++++++++++++++++++++++++++++++++++++++*/
49 #include "ColorMain.h"
51 /*+++++++++++++++++++++++++++++++++++++++*/
52 /* include extern functions */
53 /*+++++++++++++++++++++++++++++++++++++++*/
54 #include "ColorPalette.h"
56 /*+++++++++++++++++++++++++++++++++++++++*/
57 /* Internal Variables */
58 /*+++++++++++++++++++++++++++++++++++++++*/
59 extern Pixmap BGPixmap;
61 /*************************************************************************
62 ** Allocate colors for the 8 color sets within a palette, if HIGH_COLOR.
63 ** Will have to do major checking for low color
64 ** moitors. Setting the allocated pixels to pCurrentPalette.
66 ** NOTE: for now I am allocating them all, In future we will want to
67 ** be more careful about our allocations.
68 **************************************************************************/
75 XmPixelSet pixels[XmCO_MAX_NUM_COLORS];
77 XColor colors[XmCO_MAX_NUM_COLORS * 5];
82 XmeGetPixelData (style.screenNum, &colorUse, pixels,
83 &(pCurrentPalette->active),
84 &(pCurrentPalette->inactive),
85 &(pCurrentPalette->primary),
86 &(pCurrentPalette->secondary));
88 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
90 pCurrentPalette->color[i].bg.pixel = pixels[i].bg;
91 pCurrentPalette->color[i].sc.pixel = pixels[i].sc;
92 pCurrentPalette->color[i].fg.pixel = pixels[i].fg;
93 pCurrentPalette->color[i].ts.pixel = pixels[i].ts;
94 pCurrentPalette->color[i].bs.pixel = pixels[i].bs;
96 if (style.dynamicColor)
98 pCurrentPalette->color[i].bg.flags = DoRed | DoGreen | DoBlue;
99 pCurrentPalette->color[i].fg.flags = DoRed | DoGreen | DoBlue;
100 pCurrentPalette->color[i].ts.flags = DoRed | DoGreen | DoBlue;
101 pCurrentPalette->color[i].bs.flags = DoRed | DoGreen | DoBlue;
102 pCurrentPalette->color[i].sc.flags = DoRed | DoGreen | DoBlue;
104 if(i < pCurrentPalette->num_of_colors)
106 colors[j++] = pCurrentPalette->color[i].bg;
107 colors[j++] = pCurrentPalette->color[i].sc;
109 if(FgColor == DYNAMIC)
110 colors[j++] = pCurrentPalette->color[i].fg;
114 colors[j++] = pCurrentPalette->color[i].ts;
115 colors[j++] = pCurrentPalette->color[i].bs;
118 } /* if(TypeOfMonitor != XmCO_BLACK_WHITE) */
121 if (style.dynamicColor)
122 XStoreColors(style.display, style.colormap, colors, j );
129 /*************************************************************************
130 ** ReColorPalette changes to RGB values of the already allocated pixels
131 ** for the 8 color buttons. Each color button uses 5 pixels (at least
134 ** The palette passed has the colors the pixels are going to change to.
136 **************************************************************************/
138 ReColorPalette( void )
144 XColor colors[XmCO_MAX_NUM_COLORS * 5];
146 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
148 pCurrentPalette->primary = pOldPalette->primary;
149 pCurrentPalette->secondary = pOldPalette->secondary;
150 pCurrentPalette->active = pOldPalette->active;
151 pCurrentPalette->inactive = pOldPalette->inactive;
153 pCurrentPalette->color[i].bg.pixel =
154 pOldPalette->color[i].bg.pixel;
155 if(TypeOfMonitor != XmCO_BLACK_WHITE)
157 pCurrentPalette->color[i].bg.flags = DoRed | DoGreen | DoBlue;
158 if(i < pCurrentPalette->num_of_colors)
159 colors[j++] = pCurrentPalette->color[i].bg;
162 pCurrentPalette->color[i].sc.pixel =
163 pOldPalette->color[i].sc.pixel;
164 if(TypeOfMonitor != XmCO_BLACK_WHITE)
166 pCurrentPalette->color[i].sc.flags = DoRed | DoGreen | DoBlue;
167 if(i < pCurrentPalette->num_of_colors)
168 colors[j++] = pCurrentPalette->color[i].sc;
171 pCurrentPalette->color[i].fg.pixel =
172 pOldPalette->color[i].fg.pixel;
173 if(TypeOfMonitor != XmCO_BLACK_WHITE)
175 if(FgColor == DYNAMIC)
177 pCurrentPalette->color[i].fg.flags = DoRed | DoGreen | DoBlue;
178 if(i < pCurrentPalette->num_of_colors)
179 colors[j++] = pCurrentPalette->color[i].fg;
183 pCurrentPalette->color[i].ts.pixel =
184 pOldPalette->color[i].ts.pixel;
185 if(TypeOfMonitor != XmCO_BLACK_WHITE)
187 if(UsePixmaps == FALSE)
189 pCurrentPalette->color[i].ts.flags = DoRed | DoGreen | DoBlue;
190 if(i < pCurrentPalette->num_of_colors)
191 colors[j++] = pCurrentPalette->color[i].ts;
195 pCurrentPalette->color[i].bs.pixel =
196 pOldPalette->color[i].bs.pixel;
197 if(TypeOfMonitor != XmCO_BLACK_WHITE)
199 if(UsePixmaps == FALSE)
201 pCurrentPalette->color[i].bs.flags = DoRed | DoGreen | DoBlue;
202 if(i < pCurrentPalette->num_of_colors)
203 colors[j++] = pCurrentPalette->color[i].bs;
208 if (TypeOfMonitor != XmCO_BLACK_WHITE)
209 XStoreColors(style.display, style.colormap, colors, j );
214 /*************************************************************************
215 ** CheckMonitor - querry color server for monitor type
216 **************************************************************************/
221 WaitSelection = TRUE;
223 XtGetSelectionValue(shell, XA_CUSTOMIZE, XA_TYPE_MONITOR, show_selection,
224 (XtPointer)GET_TYPE_MONITOR, CurrentTime);
226 XFlush(style.display);
229 XtAppProcessEvent (XtWidgetToApplicationContext(shell), XtIMAll);