annotate lwlib/xlwgcs.c @ 5523:810b77562486

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