ColorPalette.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 libraries 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. #include <X11/Xlib.h>
  44. #include <Xm/Xm.h>
  45. #include "Main.h"
  46. #include "ColorMain.h"
  47. /*+++++++++++++++++++++++++++++++++++++++*/
  48. /* include extern functions */
  49. /*+++++++++++++++++++++++++++++++++++++++*/
  50. #include "ColorPalette.h"
  51. /*+++++++++++++++++++++++++++++++++++++++*/
  52. /* Internal Variables */
  53. /*+++++++++++++++++++++++++++++++++++++++*/
  54. extern Pixmap BGPixmap;
  55. /*************************************************************************
  56. ** Allocate colors for the 8 color sets within a palette, if HIGH_COLOR.
  57. ** Will have to do major checking for low color
  58. ** moitors. Setting the allocated pixels to pCurrentPalette.
  59. **
  60. ** NOTE: for now I am allocating them all, In future we will want to
  61. ** be more careful about our allocations.
  62. **************************************************************************/
  63. Bool
  64. AllocatePaletteCells(
  65. Widget shell )
  66. {
  67. int i;
  68. int colorUse;
  69. XmPixelSet pixels[XmCO_MAX_NUM_COLORS];
  70. int j=0;
  71. XColor colors[XmCO_MAX_NUM_COLORS * 5];
  72. if(style.count > 9)
  73. return 0;
  74. XmeGetPixelData (style.screenNum, &colorUse, pixels,
  75. &(pCurrentPalette->active),
  76. &(pCurrentPalette->inactive),
  77. &(pCurrentPalette->primary),
  78. &(pCurrentPalette->secondary));
  79. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  80. {
  81. pCurrentPalette->color[i].bg.pixel = pixels[i].bg;
  82. pCurrentPalette->color[i].sc.pixel = pixels[i].sc;
  83. pCurrentPalette->color[i].fg.pixel = pixels[i].fg;
  84. pCurrentPalette->color[i].ts.pixel = pixels[i].ts;
  85. pCurrentPalette->color[i].bs.pixel = pixels[i].bs;
  86. if (style.dynamicColor)
  87. {
  88. pCurrentPalette->color[i].bg.flags = DoRed | DoGreen | DoBlue;
  89. pCurrentPalette->color[i].fg.flags = DoRed | DoGreen | DoBlue;
  90. pCurrentPalette->color[i].ts.flags = DoRed | DoGreen | DoBlue;
  91. pCurrentPalette->color[i].bs.flags = DoRed | DoGreen | DoBlue;
  92. pCurrentPalette->color[i].sc.flags = DoRed | DoGreen | DoBlue;
  93. if(i < pCurrentPalette->num_of_colors)
  94. {
  95. colors[j++] = pCurrentPalette->color[i].bg;
  96. colors[j++] = pCurrentPalette->color[i].sc;
  97. if(FgColor == DYNAMIC)
  98. colors[j++] = pCurrentPalette->color[i].fg;
  99. if(!UsePixmaps)
  100. {
  101. colors[j++] = pCurrentPalette->color[i].ts;
  102. colors[j++] = pCurrentPalette->color[i].bs;
  103. }
  104. }
  105. } /* if(TypeOfMonitor != XmCO_BLACK_WHITE) */
  106. }
  107. if (style.dynamicColor)
  108. XStoreColors(style.display, style.colormap, colors, j );
  109. style.count++;
  110. return(True);
  111. }
  112. /*************************************************************************
  113. ** ReColorPalette changes to RGB values of the already allocated pixels
  114. ** for the 8 color buttons. Each color button uses 5 pixels (at least
  115. ** for now.)
  116. **
  117. ** The palette passed has the colors the pixels are going to change to.
  118. **
  119. **************************************************************************/
  120. int
  121. ReColorPalette( void )
  122. {
  123. int n;
  124. Arg args[MAX_ARGS];
  125. int i;
  126. int j=0;
  127. XColor colors[XmCO_MAX_NUM_COLORS * 5];
  128. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  129. {
  130. pCurrentPalette->primary = pOldPalette->primary;
  131. pCurrentPalette->secondary = pOldPalette->secondary;
  132. pCurrentPalette->active = pOldPalette->active;
  133. pCurrentPalette->inactive = pOldPalette->inactive;
  134. pCurrentPalette->color[i].bg.pixel =
  135. pOldPalette->color[i].bg.pixel;
  136. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  137. {
  138. pCurrentPalette->color[i].bg.flags = DoRed | DoGreen | DoBlue;
  139. if(i < pCurrentPalette->num_of_colors)
  140. colors[j++] = pCurrentPalette->color[i].bg;
  141. }
  142. pCurrentPalette->color[i].sc.pixel =
  143. pOldPalette->color[i].sc.pixel;
  144. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  145. {
  146. pCurrentPalette->color[i].sc.flags = DoRed | DoGreen | DoBlue;
  147. if(i < pCurrentPalette->num_of_colors)
  148. colors[j++] = pCurrentPalette->color[i].sc;
  149. }
  150. pCurrentPalette->color[i].fg.pixel =
  151. pOldPalette->color[i].fg.pixel;
  152. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  153. {
  154. if(FgColor == DYNAMIC)
  155. {
  156. pCurrentPalette->color[i].fg.flags = DoRed | DoGreen | DoBlue;
  157. if(i < pCurrentPalette->num_of_colors)
  158. colors[j++] = pCurrentPalette->color[i].fg;
  159. }
  160. }
  161. pCurrentPalette->color[i].ts.pixel =
  162. pOldPalette->color[i].ts.pixel;
  163. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  164. {
  165. if(UsePixmaps == FALSE)
  166. {
  167. pCurrentPalette->color[i].ts.flags = DoRed | DoGreen | DoBlue;
  168. if(i < pCurrentPalette->num_of_colors)
  169. colors[j++] = pCurrentPalette->color[i].ts;
  170. }
  171. }
  172. pCurrentPalette->color[i].bs.pixel =
  173. pOldPalette->color[i].bs.pixel;
  174. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  175. {
  176. if(UsePixmaps == FALSE)
  177. {
  178. pCurrentPalette->color[i].bs.flags = DoRed | DoGreen | DoBlue;
  179. if(i < pCurrentPalette->num_of_colors)
  180. colors[j++] = pCurrentPalette->color[i].bs;
  181. }
  182. }
  183. }
  184. if (TypeOfMonitor != XmCO_BLACK_WHITE)
  185. XStoreColors(style.display, style.colormap, colors, j );
  186. return(True);
  187. }
  188. /*************************************************************************
  189. ** CheckMonitor - querry color server for monitor type
  190. **************************************************************************/
  191. void
  192. CheckMonitor(
  193. Widget shell )
  194. {
  195. WaitSelection = TRUE;
  196. XtGetSelectionValue(shell, XA_CUSTOMIZE, XA_TYPE_MONITOR, show_selection,
  197. (XtPointer)GET_TYPE_MONITOR, CurrentTime);
  198. XFlush(style.display);
  199. while(WaitSelection)
  200. XtAppProcessEvent (XtWidgetToApplicationContext(shell), XtIMAll);
  201. }