Fix some minor issues and re-enable building of DE, ES, FR, and IT locale data (help...
[oweals/cde.git] / cde / programs / dtstyle / ColorPalette.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /************************************<+>*************************************
24  ****************************************************************************
25  **
26  **   File:        ColorPalette.c
27  **
28  **   Project:     DT 3.0
29  **
30  **   Description: Controls the Dtstyle Color Palette data
31  **
32  **
33  **  (c) Copyright Hewlett-Packard Company, 1990.  
34  **
35  **
36  **
37  ****************************************************************************
38  ************************************<+>*************************************/
39 /* $XConsortium: ColorPalette.c /main/6 1995/10/30 13:08:58 rswiston $ */
40 /*+++++++++++++++++++++++++++++++++++++++*/
41 /* include files                         */
42 /*+++++++++++++++++++++++++++++++++++++++*/
43
44 #include <X11/Xlib.h>
45
46 #include <Xm/Xm.h>
47
48 #include "Main.h"
49 #include "ColorMain.h"
50
51 /*+++++++++++++++++++++++++++++++++++++++*/
52 /* include extern functions              */
53 /*+++++++++++++++++++++++++++++++++++++++*/
54 #include "ColorPalette.h"
55
56 /*+++++++++++++++++++++++++++++++++++++++*/
57 /* Internal Variables                    */
58 /*+++++++++++++++++++++++++++++++++++++++*/
59 extern Pixmap BGPixmap;
60
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.
65 **
66 **  NOTE: for now I am allocating them all, In future we will want to
67 **        be more careful about our allocations.
68 **************************************************************************/
69 Bool 
70 AllocatePaletteCells(
71         Widget shell )
72 {
73     int i;
74     int         colorUse;
75     XmPixelSet  pixels[XmCO_MAX_NUM_COLORS];
76     int         j=0;
77     XColor      colors[XmCO_MAX_NUM_COLORS * 5];
78
79     if(style.count > 9)
80        return;
81
82     XmeGetPixelData (style.screenNum, &colorUse, pixels,
83                                    &(pCurrentPalette->active),
84                                    &(pCurrentPalette->inactive),
85                                    &(pCurrentPalette->primary),
86                                    &(pCurrentPalette->secondary));
87           
88     for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
89     {
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;
95
96        if (style.dynamicColor)
97        {
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;
103
104           if(i < pCurrentPalette->num_of_colors)
105           {
106              colors[j++] =  pCurrentPalette->color[i].bg;
107              colors[j++] =  pCurrentPalette->color[i].sc;
108
109              if(FgColor == DYNAMIC)
110                 colors[j++] =  pCurrentPalette->color[i].fg;
111
112              if(!UsePixmaps)
113              {
114                 colors[j++] =  pCurrentPalette->color[i].ts;
115                 colors[j++] =  pCurrentPalette->color[i].bs;
116              }
117           }
118        } /* if(TypeOfMonitor != XmCO_BLACK_WHITE) */
119     }
120
121     if (style.dynamicColor)
122        XStoreColors(style.display, style.colormap, colors, j );
123
124     style.count++;
125     return(True);
126
127 }
128
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
132 **  for now.)
133 **
134 **  The palette passed has the colors the pixels are going to change to.
135 **
136 **************************************************************************/
137 int 
138 ReColorPalette( void )
139 {
140     register int     n;
141     Arg              args[MAX_ARGS];
142     int              i;
143     int              j=0;
144     XColor           colors[XmCO_MAX_NUM_COLORS * 5];
145
146     for(i = 0; i < XmCO_MAX_NUM_COLORS; i++) 
147     {
148        pCurrentPalette->primary = pOldPalette->primary;
149        pCurrentPalette->secondary = pOldPalette->secondary;
150        pCurrentPalette->active = pOldPalette->active;
151        pCurrentPalette->inactive = pOldPalette->inactive;
152
153        pCurrentPalette->color[i].bg.pixel = 
154                          pOldPalette->color[i].bg.pixel; 
155        if(TypeOfMonitor != XmCO_BLACK_WHITE)
156        {
157           pCurrentPalette->color[i].bg.flags = DoRed | DoGreen | DoBlue;
158           if(i < pCurrentPalette->num_of_colors)
159              colors[j++] =  pCurrentPalette->color[i].bg;
160        }
161
162        pCurrentPalette->color[i].sc.pixel =
163                          pOldPalette->color[i].sc.pixel; 
164        if(TypeOfMonitor != XmCO_BLACK_WHITE)
165        {
166           pCurrentPalette->color[i].sc.flags = DoRed | DoGreen | DoBlue;
167           if(i < pCurrentPalette->num_of_colors)
168              colors[j++] =  pCurrentPalette->color[i].sc;
169        }
170
171        pCurrentPalette->color[i].fg.pixel =
172                          pOldPalette->color[i].fg.pixel; 
173        if(TypeOfMonitor != XmCO_BLACK_WHITE)
174        {
175           if(FgColor == DYNAMIC)
176           {
177              pCurrentPalette->color[i].fg.flags = DoRed | DoGreen | DoBlue;
178              if(i < pCurrentPalette->num_of_colors)
179                 colors[j++] =  pCurrentPalette->color[i].fg;
180           }
181        }
182
183        pCurrentPalette->color[i].ts.pixel =
184                          pOldPalette->color[i].ts.pixel; 
185        if(TypeOfMonitor != XmCO_BLACK_WHITE)
186        {
187           if(UsePixmaps == FALSE)
188           {
189              pCurrentPalette->color[i].ts.flags = DoRed | DoGreen | DoBlue;
190              if(i < pCurrentPalette->num_of_colors)
191                 colors[j++] =  pCurrentPalette->color[i].ts;
192           }
193        }
194
195        pCurrentPalette->color[i].bs.pixel = 
196                          pOldPalette->color[i].bs.pixel; 
197        if(TypeOfMonitor != XmCO_BLACK_WHITE)
198        {
199           if(UsePixmaps == FALSE)
200           {
201              pCurrentPalette->color[i].bs.flags = DoRed | DoGreen | DoBlue;
202              if(i < pCurrentPalette->num_of_colors)
203                 colors[j++] =  pCurrentPalette->color[i].bs;
204           }
205        }
206     }
207
208     if (TypeOfMonitor != XmCO_BLACK_WHITE)
209         XStoreColors(style.display, style.colormap, colors, j );
210
211     return(True);
212 }
213
214 /*************************************************************************
215 **  CheckMonitor - querry color server for monitor type
216 **************************************************************************/
217 void 
218 CheckMonitor(
219         Widget shell )
220 {
221     WaitSelection = TRUE;
222
223     XtGetSelectionValue(shell, XA_CUSTOMIZE, XA_TYPE_MONITOR, show_selection,
224                                     (XtPointer)GET_TYPE_MONITOR, CurrentTime);
225
226     XFlush(style.display);
227
228     while(WaitSelection)
229           XtAppProcessEvent (XtWidgetToApplicationContext(shell), XtIMAll);
230
231 }