annotate lwlib/xlwgcs.c @ 5316:9ac28212c75a

#'cl-safe-expr-p, forms that start with the symbol lambda are also safe. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (cl-safe-expr-p): Forms that start with the symbol lambda are also safe.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 29 Dec 2010 23:53:48 +0000
parents 5460287a3327
children 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
1 /* Tabs Widget for XEmacs.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
2 Copyright (C) 1999 Edward A. Falk
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
3
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
4 This file is part of XEmacs.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
5
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
9 later version.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
10
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
14 for more details.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
15
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
20
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
21 /* Synched up with: Gcs.c 1.7 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
22
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
23 /* #### This code is duplicated many times within lwlib and XEmacs. It
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
24 should be modularised. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
25
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
26 /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
27 * Gcs.c - Utility functions to allocate GCs.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
28 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
29 * Author: Edward A. Falk
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
30 * falk@falconer.vip.best.com
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
31 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
32 * Date: Sept 29, 1998
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
33 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
34
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
35 /* Functions:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
36 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
37 * GC AllocFgGC(w, fg, font)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
38 * Return a GC with foreground set as specified.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
39 * If font is None, then the returned GC is allocated with font specified
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
40 * as a "don't care" value.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
41 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
42 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
43 * AllocBackgroundGC(w, font)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
44 * Return a GC with the foreground set to the widget's background color.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
45 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
46 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
47 * AllocGreyGC(w, fg, font, contrast, be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
48 * Widget w ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
49 * Pixel fg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
50 * Font font ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
51 * int contrast ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
52 * int be_nice_to_cmap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
53 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
54 * Return a GC suitable for rendering a widget in its "inactive" color.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
55 * Normally returns a GC with a color somewhere between the widget's
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
56 * background color and the specified foreground. If font is None, then
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
57 * the returned GC is allocated with font specified as "don't care".
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
58 * If be_nice_to_cmap is True, the returned GC is created using a 50%
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
59 * dither instead of a new color.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
60 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
61 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
62 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
63 * AllocShadeGC(w, fg, bg, font, contrast, be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
64 * Widget w ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
65 * Pixel fg, bg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
66 * Font font ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
67 * int contrast ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
68 * int be_nice_to_cmap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
69 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
70 * Return a GC suitable for rendering in a shade somewhere between
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
71 * bg and fg, as determined by contrast (0 = bg, 100 = fg)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
72 * If font is None, then the returned GC is allocated with
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
73 * font specified as "don't care". If be_nice_to_cmap
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
74 * is True, the returned GC is created using a 50% dither
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
75 * instead of a new color.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
76 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
77 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
78 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
79 * AllocTopShadowGC(w, contrast, be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
80 * Return a GC suitable for rendering the "top shadow" decorations of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
81 * a widget. Returns a GC with foreground computed from widget's
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
82 * background color and contrast. If be_nice_to_cmap is True, the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
83 * returned GC will use a foreground color of white. If widget depth
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
84 * is 1, this function will use a foreground color of black.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
85 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
86 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
87 * AllocBotShadowGC(w, contrast, be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
88 * Return a GC suitable for rendering the "bottom shadow" decorations
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
89 * of a widget. Returns a GC with foreground computed from widget's
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
90 * background color and contrast. If be_nice_to_cmap is True, the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
91 * returned GC will use a foreground color of black.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
92 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
93 * GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
94 * AllocArmGC(w, contrast, be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
95 * Return a GC suitable for rendering the "armed" decorations of a
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
96 * widget. This GC would typically be used to fill in the widget's
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
97 * background. Returns a GC with foreground computed from widget's
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
98 * background color and contrast. If be_nice_to_cmap is True, the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
99 * returned GC will use a foreground color of black and a 50% dither.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
100 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
101 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
102 * void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
103 * Draw3dBox(w, x,y,wid,hgt,s, topgc, botgc)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
104 * Utility function. Draws a raised shadow box with outside dimensions
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
105 * as specified by x,y,wid,hgt and shadow width specified by s.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
106 * A lowered shadow box may be generated by swapping topgc and botgc.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
107 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
108 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
109
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
110 #include <config.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
111 #include <stdio.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
112
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
113 #include <X11/Xlib.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
114 #include <X11/IntrinsicP.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
115 #include <X11/StringDefs.h>
4769
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
116 #include <X11/Xmu/Drawing.h>
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
117 #include <X11/Xmu/Misc.h>
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
118 #include "xlwgcs.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
119
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
120 /* Color & GC allocation.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
121 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
122 * Frame widgets use the following graphics contexts:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
123 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
124 * Foreground tab label text drawn this way
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
125 * Insensitive Fg foreground color greyed out.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
126 * Background frame background color
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
127 * Top shadow upper-left highlight around widget
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
128 * Bottom shadow lower-right highlight around widget
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
129 * Arm shadow button pressed and ready to be released
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
130 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
131 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
132 * GC's are defined as follows, depending on attributes and
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
133 * window depth:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
134 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
135 * Monochrome:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
136 * Foreground = foreground color attribute or BlackPixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
137 * Grey = Foreground color + 50% dither
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
138 * Background = background color attribute or WhitePixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
139 * top shadow = foreground
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
140 * bottom shadow = foreground
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
141 * arm shadow = (what?)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
142 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
143 * Color, beNiceToColormap=true:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
144 * Foreground = foreground color attribute or BlackPixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
145 * Grey = Foreground color + 50% dither
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
146 * Background = background color attribute or WhitePixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
147 * top shadow = white
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
148 * bottom shadow = black
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
149 * arm shadow = (what?)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
150 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
151 * Color, beNiceToColormap=false:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
152 * Foreground = foreground color attribute or BlackPixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
153 * Grey = (foreground color + background color)/2
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
154 * Background = background color attribute or WhitePixel()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
155 * top shadow = background * 1.2
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
156 * bottom shadow = background * .6
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
157 * arm shadow = background * .8
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
158 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
159 * Special cases:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
160 * If background is white, ??
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
161 * if background is black, ??
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
162 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
163 *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
164 * If the widget's background is solid white or solid black,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
165 * this code just picks some numbers. (The choice is designed
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 398
diff changeset
166 * to be compatible with ThreeD interface.)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
167 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
168
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
169
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
170
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
171 #if NeedFunctionPrototypes
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
172 static Pixmap getDitherPixmap(Widget, int contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
173 #else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
174 static Pixmap getDitherPixmap() ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
175 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
176
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
177 /* return a GC with the specified foreground and optional font */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
178
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
179 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
180 AllocFgGC(Widget w, Pixel fg, Font font)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
181 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
182 XGCValues values ;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
183 unsigned long vmask, dcmask ;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
184
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
185 values.foreground = fg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
186 values.font = font ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
187
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
188 if( font != None ) {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
189 vmask = GCForeground|GCFont ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
190 dcmask = GCSubwindowMode|GCDashOffset|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
191 GCDashList|GCArcMode|GCBackground|GCGraphicsExposures ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
192 } else {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
193 vmask = GCForeground ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
194 dcmask = GCFont|GCSubwindowMode|GCDashOffset|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
195 GCDashList|GCArcMode|GCBackground|GCGraphicsExposures ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
196 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
197
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
198 return XtAllocateGC(w, w->core.depth, vmask, &values, 0L, dcmask) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
199 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
200
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
201
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
202 /* return gc with widget background color as the foreground */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
203
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
204 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
205 AllocBackgroundGC(Widget w, Font font)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
206 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
207 return AllocFgGC(w, w->core.background_pixel, font) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
208 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
209
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
210
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
211 /* Allocate an "inactive" GC. Color is grey (possibly via
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
212 * dither pattern).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
213 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
214
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
215 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
216 AllocGreyGC(Widget w, Pixel fg, Font font, int contrast, Bool be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
217 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
218 return AllocShadeGC(w, fg, w->core.background_pixel,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
219 font, contrast, be_nice_to_cmap) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
220 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
221
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
222
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
223 /* Allocate a GC somewhere between two colors. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
224
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
225 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
226 AllocShadeGC(Widget w, Pixel fg, Pixel bg, Font font,
4769
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
227 int contrast, Bool be_nice_to_cmap)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
228 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
229 XGCValues values ;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
230 unsigned long vmask, dcmask ;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
231
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
232 values.foreground = fg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
233 values.background = bg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
234 values.font = font ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
235
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
236 if( font != None ) {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
237 vmask = GCForeground|GCFont ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
238 dcmask = GCSubwindowMode|GCDashOffset|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
239 GCDashList|GCArcMode|GCGraphicsExposures ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
240 } else {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
241 vmask = GCForeground;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
242 dcmask = GCFont|GCSubwindowMode|GCDashOffset|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
243 GCDashList|GCArcMode|GCGraphicsExposures ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
244 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
245 if( be_nice_to_cmap || w->core.depth == 1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
246 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
247 if( contrast <= 5 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
248 values.foreground = bg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
249 else if( contrast >= 95 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
250 values.foreground = fg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
251 else {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
252 vmask |= GCBackground|GCStipple|GCFillStyle ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
253 values.fill_style = FillOpaqueStippled ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
254 values.stipple = getDitherPixmap(w, contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
255 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
256
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
257 return XtAllocateGC(w, w->core.depth, vmask, &values, 0L, dcmask) ;
4769
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
258 } else {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
259 dcmask |= GCBackground ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
260 values.foreground = AllocGreyPixel(w, fg, bg, contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
261 return XtAllocateGC(w, w->core.depth, vmask, &values, 0L, dcmask) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
262 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
263 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
264
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
265 /* return top-shadow gc. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
266
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
267 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
268 AllocTopShadowGC(Widget w, int contrast, Bool be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
269 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
270 Screen *scr = XtScreen (w);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
271 XGCValues values ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
272
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
273 if( w->core.depth == 1 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
274 values.foreground = BlackPixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
275 else if( be_nice_to_cmap )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
276 values.foreground = WhitePixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
277 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
278 values.foreground = AllocShadowPixel(w, 100+contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
279
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
280 return XtAllocateGC(w, w->core.depth,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
281 GCForeground, &values,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
282 0L,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
283 GCBackground|GCFont|GCSubwindowMode|GCGraphicsExposures|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
284 GCDashOffset|GCDashList|GCArcMode) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
285 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
286
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
287 /* return bottom-shadow gc. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
288
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
289 GC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
290 AllocBotShadowGC(Widget w, int contrast, Bool be_nice_to_cmap)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
291 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
292 Screen *scr = XtScreen (w);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
293 XGCValues values ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
294
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
295 if( w->core.depth == 1 || be_nice_to_cmap )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
296 values.foreground = BlackPixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
297 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
298 values.foreground = AllocShadowPixel(w, 100-contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
299
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
300 return XtAllocateGC(w, w->core.depth,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
301 GCForeground, &values,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
302 0L,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
303 GCBackground|GCFont|GCSubwindowMode|GCGraphicsExposures|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
304 GCDashOffset|GCDashList|GCArcMode) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
305 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
306
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
307 /* return arm-shadow gc. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
308
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
309 GC
4769
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
310 AllocArmGC(Widget w, int contrast, Bool be_nice_to_cmap)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
311 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
312 Screen *scr = XtScreen (w);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
313 XGCValues values ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
314
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
315 /* Not clear exactly what we should do here. Take a look at
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
316 * Xaw3d to see what they do.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
317 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
318 if( w->core.depth == 1 || be_nice_to_cmap )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
319 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
320 values.background = w->core.background_pixel ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
321 if( values.background == BlackPixelOfScreen(scr) )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
322 values.foreground = WhitePixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
323 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
324 values.foreground = BlackPixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
325 values.fill_style = FillStippled ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
326 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
327
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
328 return XtAllocateGC(w, w->core.depth,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
329 GCForeground|GCBackground|GCStipple|GCFillStyle,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
330 &values, 0L,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
331 GCFont|GCSubwindowMode|GCGraphicsExposures|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
332 GCDashOffset|GCDashList|GCArcMode) ;
4769
5460287a3327 Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents: 2286
diff changeset
333 } else {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
334 values.foreground = AllocShadowPixel(w, 100-contrast) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
335 return XtAllocateGC(w, w->core.depth,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
336 GCForeground, &values,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
337 0L,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
338 GCBackground|GCFont|GCSubwindowMode|GCGraphicsExposures|
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
339 GCDashOffset|GCDashList|GCArcMode) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
340 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
341 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
342
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
343
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
344 Pixel
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
345 AllocShadowPixel(Widget w, int scale)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
346 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
347 XColor get_c, set_c ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
348 Display *dpy = XtDisplay(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
349 Screen *scr = XtScreen(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
350 Colormap cmap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
351 Pixel maxColor ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
352
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
353 cmap = w->core.colormap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
354
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
355 get_c.pixel = w->core.background_pixel ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
356 if( get_c.pixel == WhitePixelOfScreen(scr) ||
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
357 get_c.pixel == BlackPixelOfScreen(scr) )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
358 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
359 /* what we *ought* to do is choose gray75 as the base color,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
360 * or perhaps gray83. Instead, we choose colors that are
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
361 * the same as ThreeD would choose.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
362 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
363 if( scale > 100 ) scale = 200 - scale ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
364 set_c.red = set_c.green = set_c.blue = 65535*scale/100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
365 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
366 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
367 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
368 XQueryColor(dpy, cmap, &get_c) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
369 /* adjust scale so that brightest component does not
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
370 * exceed 65535; otherwise hue would change.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
371 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
372 if( scale > 100 ) {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
373 maxColor = Max(get_c.red, Max(get_c.green, get_c.blue)) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
374 if( scale*maxColor > 65535*100 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
375 scale = 65535*100/maxColor ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
376 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
377 set_c.red = scale * get_c.red / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
378 set_c.green = scale * get_c.green / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
379 set_c.blue = scale * get_c.blue / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
380 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
381 set_c.flags = DoRed | DoGreen | DoBlue ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
382 if( XAllocColor(dpy, cmap, &set_c) )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
383 return set_c.pixel ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
384 else if( scale > 100 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
385 return WhitePixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
386 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
387 return BlackPixelOfScreen(scr) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
388 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
389
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
390
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
391 /* Allocate a pixel partway between foreground and background */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
392
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
393
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
394 Pixel
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
395 AllocGreyPixel(Widget w, Pixel fg, Pixel bg, int scale)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
396 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
397 XColor get_cf, get_cb ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
398 Display *dpy = XtDisplay(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
399 Colormap cmap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
400
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
401 cmap = w->core.colormap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
402
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
403 get_cf.pixel = fg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
404 get_cb.pixel = bg ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
405
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
406 XQueryColor(dpy, cmap, &get_cf) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
407 XQueryColor(dpy, cmap, &get_cb) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
408
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
409 return AllocGreyPixelC(w, &get_cf, &get_cb, scale) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
410 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
411
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
412
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
413
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
414 /* Allocate a pixel partway between foreground and background */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
415
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
416
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
417 Pixel
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
418 AllocGreyPixelC(Widget w, XColor *fg, XColor *bg, int scale)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
419 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
420 XColor set_c ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
421 Display *dpy = XtDisplay(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
422 int r,g,b ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
423 Colormap cmap = w->core.colormap ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
424
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
425 r = (fg->red * scale + bg->red * (100-scale)) / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
426 g = (fg->green * scale + bg->green * (100-scale)) / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
427 b = (fg->blue * scale + bg->blue * (100-scale)) / 100 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
428
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
429 if( scale > 100 || scale < 0 ) /* look out for overflow */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
430 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
431 int minc, maxc ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
432 maxc = Max(r, Max(g,b)) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
433 minc = Min(r, Min(g,b)) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
434 if( maxc > 65535 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
435 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
436 maxc /= 16 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
437 r = r*(65535/16) / maxc ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
438 g = g*(65535/16) / maxc ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
439 b = b*(65535/16) / maxc ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
440 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
441 if( minc < 0 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
442 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
443 r = Max(r,0) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
444 g = Max(g,0) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
445 b = Max(b,0) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
446 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
447 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
448
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
449 set_c.red = r ; set_c.green = g ; set_c.blue = b ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
450 set_c.flags = DoRed | DoGreen | DoBlue ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
451 (void)XAllocColor(dpy, cmap, &set_c) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
452 return set_c.pixel ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
453 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
454
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
455
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
456
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
457
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
458
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
459 /* draw a 3-d box */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
460
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
461 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
462 Draw3dBox(Widget w, int x, int y, int wid, int hgt, int s, GC topgc, GC botgc)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
463 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
464 Display *dpy = XtDisplay(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
465 Window win = XtWindow(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
466
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
467 if( s == 0 ) return ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
468
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
469 if( s == 1 ) {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
470 XDrawLine(dpy,win,botgc, x,y+hgt-1, x+wid-1,y+hgt-1) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
471 XDrawLine(dpy,win,botgc, x+wid-1,y, x+wid-1,y+hgt-1) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
472 XDrawLine(dpy,win,topgc, x,y, x,y+hgt-1) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
473 XDrawLine(dpy,win,topgc, x,y, x+wid-1,y) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
474 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
475 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
476 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
477 XPoint pts[6] ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
478
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
479 /* bottom-right shadow */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
480 pts[0].x = x ; pts[0].y = y + hgt ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
481 pts[1].x = s ; pts[1].y = -s ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
482 pts[2].x = wid-2*s ; pts[2].y = 0 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
483 pts[3].x = 0 ; pts[3].y = -(hgt-2*s) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
484 pts[4].x = s ; pts[4].y = -s ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
485 pts[5].x = 0 ; pts[5].y = hgt ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
486 XFillPolygon(dpy,win,botgc, pts,6, Nonconvex,CoordModePrevious) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
487
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
488 /* top-left shadow */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
489 pts[0].x = x ; pts[0].y = y ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
490 pts[1].x = wid ; pts[1].y = 0 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
491 pts[2].x = -s ; pts[2].y = s ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
492 pts[3].x = -wid+2*s ; pts[3].y = 0 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
493 pts[4].x = 0 ; pts[4].y = hgt-2*s ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
494 pts[5].x = -s ; pts[5].y = s ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
495 XFillPolygon(dpy,win,topgc, pts,6, Nonconvex,CoordModePrevious) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
496 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
497 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
498
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
499 static unsigned char screen0[2] = {0,0} ;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
500 static unsigned char screen25[2] = {0,0xaa} ;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
501 static unsigned char screen75[2] = {0xaa,0xff} ;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
502 static unsigned char screen100[2] = {0xff,0xff} ;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
503
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
504 static Pixmap
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
505 getDitherPixmap(Widget w, int contrast)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
506 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
507 Display *dpy = XtDisplay(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
508 Window win = XtWindow(w) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
509
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
510 if( contrast <= 5 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
511 return XCreateBitmapFromData(dpy,win, (char *)screen0, 2,2) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
512 else if( contrast <= 37 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
513 return XCreateBitmapFromData(dpy,win, (char *)screen25, 2,2) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
514 else if( contrast <= 62 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
515 return XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
516 else if( contrast <= 95 )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
517 return XCreateBitmapFromData(dpy,win, (char *)screen75, 2,2) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
518 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
519 return XCreateBitmapFromData(dpy,win, (char *)screen100, 2,2) ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
520 }