gc.c revision 645f5050
1/*****************************************************************************/
2/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
3/**                          Salt Lake City, Utah                           **/
4/**  Portions Copyright 1989 by the Massachusetts Institute of Technology   **/
5/**                        Cambridge, Massachusetts                         **/
6/**                                                                         **/
7/**                           All Rights Reserved                           **/
8/**                                                                         **/
9/**    Permission to use, copy, modify, and distribute this software and    **/
10/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
11/**    granted, provided that the above copyright notice appear  in  all    **/
12/**    copies and that both  that  copyright  notice  and  this  permis-    **/
13/**    sion  notice appear in supporting  documentation,  and  that  the    **/
14/**    names of Evans & Sutherland and M.I.T. not be used in advertising    **/
15/**    in publicity pertaining to distribution of the  software  without    **/
16/**    specific, written prior permission.                                  **/
17/**                                                                         **/
18/**    EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD    **/
19/**    TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES  OF  MERCHANT-    **/
20/**    ABILITY  AND  FITNESS,  IN  NO  EVENT SHALL EVANS & SUTHERLAND OR    **/
21/**    M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL  DAM-    **/
22/**    AGES OR  ANY DAMAGES WHATSOEVER  RESULTING FROM LOSS OF USE, DATA    **/
23/**    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER    **/
24/**    TORTIOUS ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE    **/
25/**    OR PERFORMANCE OF THIS SOFTWARE.                                     **/
26/*****************************************************************************/
27/*
28 *  [ ctwm ]
29 *
30 *  Copyright 1992 Claude Lecommandeur.
31 *
32 * Permission to use, copy, modify  and distribute this software  [ctwm] and
33 * its documentation for any purpose is hereby granted without fee, provided
34 * that the above  copyright notice appear  in all copies and that both that
35 * copyright notice and this permission notice appear in supporting documen-
36 * tation, and that the name of  Claude Lecommandeur not be used in adverti-
37 * sing or  publicity  pertaining to  distribution of  the software  without
38 * specific, written prior permission. Claude Lecommandeur make no represen-
39 * tations  about the suitability  of this software  for any purpose.  It is
40 * provided "as is" without express or implied warranty.
41 *
42 * Claude Lecommandeur DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
43 * INCLUDING ALL  IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS.  IN NO
44 * EVENT SHALL  Claude Lecommandeur  BE LIABLE FOR ANY SPECIAL,  INDIRECT OR
45 * CONSEQUENTIAL  DAMAGES OR ANY  DAMAGES WHATSOEVER  RESULTING FROM LOSS OF
46 * USE, DATA  OR PROFITS,  WHETHER IN AN ACTION  OF CONTRACT,  NEGLIGENCE OR
47 * OTHER  TORTIOUS ACTION,  ARISING OUT OF OR IN  CONNECTION WITH THE USE OR
48 * PERFORMANCE OF THIS SOFTWARE.
49 *
50 * Author:  Claude Lecommandeur [ lecom@sic.epfl.ch ][ April 1992 ]
51 */
52
53
54/**********************************************************************
55 *
56 * $XConsortium: gc.c,v 1.22 91/01/09 17:13:12 rws Exp $
57 *
58 * Open the fonts and create the GCs
59 *
60 * 31-Mar-88 Tom LaStrange        Initial Version.
61 *
62 * Do the necessary modification to be integrated in ctwm.
63 * Can no longer be used for the standard twm.
64 *
65 * 22-April-92 Claude Lecommandeur.
66 *
67 *
68 **********************************************************************/
69
70#include <stdio.h>
71#include "twm.h"
72#include "util.h"
73#include "gram.tab.h"
74#include "screen.h"
75#include "gc.h"
76
77extern void twmrc_error_prefix(void);
78
79/***********************************************************************
80 *
81 *  Procedure:
82 *	CreateGCs - open fonts and create all the needed GC's.  I only
83 *		    want to do this once, hence the first_time flag.
84 *
85 ***********************************************************************
86 */
87
88void CreateGCs(void)
89{
90    static ScreenInfo *prevScr = NULL;
91    XGCValues	    gcv;
92    unsigned long   gcm;
93    static unsigned char greypattern [] = {0x0f, 0x05, 0x0f, 0x0a};
94    Pixmap        greypixmap;
95    static char	dashlist [2] = {1, 1};
96
97    if (!Scr->FirstTime || prevScr == Scr)
98	return;
99
100    prevScr = Scr;
101
102    /* create GC's */
103
104    gcm = 0;
105    gcm |= GCFunction;	    gcv.function = GXxor;
106    gcm |= GCLineWidth;	    gcv.line_width = 0;
107    gcm |= GCForeground;    gcv.foreground = Scr->XORvalue;
108    gcm |= GCSubwindowMode; gcv.subwindow_mode = IncludeInferiors;
109
110    Scr->DrawGC = XCreateGC(dpy, Scr->Root, gcm, &gcv);
111
112    gcm = 0;
113    gcm |= GCForeground;    gcv.foreground = Scr->MenuC.fore;
114    gcm |= GCBackground;    gcv.background = Scr->MenuC.back;
115
116    Scr->MenuGC = XCreateGC(dpy, Scr->Root, gcm, &gcv);
117
118    gcm = 0;
119    gcm |= GCPlaneMask;	    gcv.plane_mask = AllPlanes;
120    /*
121     * Prevent GraphicsExpose and NoExpose events.  We'd only get NoExpose
122     * events anyway;  they cause BadWindow errors from XGetWindowAttributes
123     * call in FindScreenInfo (events.c) (since drawable is a pixmap).
124     */
125    gcm |= GCGraphicsExposures;  gcv.graphics_exposures = False;
126    gcm |= GCLineWidth;	    gcv.line_width = 0;
127
128    Scr->NormalGC = XCreateGC(dpy, Scr->Root, gcm, &gcv);
129
130    greypixmap = XCreatePixmapFromBitmapData(dpy, Scr->Root,
131				(char *) greypattern, 4, 4, 1, 0, 1);
132
133    if (Scr->Monochrome != COLOR) {
134	gcm  = 0;
135	gcm |= GCStipple;	gcv.stipple    = greypixmap;
136	gcm |= GCFillStyle;	gcv.fill_style = FillOpaqueStippled;
137	gcm |= GCForeground;	gcv.foreground = Scr->Black;
138	gcm |= GCBackground;	gcv.background = Scr->White;
139	Scr->BorderGC = XCreateGC (dpy, Scr->Root, gcm, &gcv);
140	XSetDashes (dpy, Scr->BorderGC, 1, dashlist, 2);
141    }
142    else
143    if (Scr->BeNiceToColormap) {
144	gcm  = 0;
145	gcm |= GCLineStyle;
146	gcv.line_style = LineDoubleDash;
147	Scr->BorderGC = XCreateGC (dpy, Scr->Root, gcm, &gcv);
148	XSetDashes (dpy, Scr->BorderGC, 0, dashlist, 2);
149    }
150    else {
151	Scr->BorderGC = XCreateGC (dpy, Scr->Root, 0, (XGCValues*) 0);
152    }
153}
154