1 /*
2  * grNull.c -
3  *
4  *     *********************************************************************
5  *     * Copyright (C) 1985, 1990 Regents of the University of California. *
6  *     * Permission to use, copy, modify, and distribute this              *
7  *     * software and its documentation for any purpose and without        *
8  *     * fee is hereby granted, provided that the above copyright          *
9  *     * notice appear in all copies.  The University of California        *
10  *     * makes no representations about the suitability of this            *
11  *     * software for any purpose.  It is provided "as is" without         *
12  *     * express or implied warranty.  Export of this software outside     *
13  *     * of the United States of America may require an export license.    *
14  *     *********************************************************************
15  *
16  * This file contains dummy functions for use when there is no
17  * graphics display.
18  */
19 
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include "utils/magsgtty.h"
24 #include "utils/magic.h"
25 #include "utils/geometry.h"
26 #include "windows/windows.h"
27 #include "graphics/graphics.h"
28 #include "graphics/graphicsInt.h"
29 #include "textio/textio.h"
30 #include "textio/txcommands.h"
31 #include "utils/signals.h"
32 
33 
34 #ifndef lint
35 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/graphics/grNull.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
36 #endif  /* not lint */
37 
38 
39 /* Forward declarations */
40 extern bool nullReturnFalse();
41 extern void nullDoNothing();
42 extern int nullReturnZero();
43 
44 /*
45  *---------------------------------------------------------
46  *
47  * nullDoNothing --
48  *
49  * This procedure does nothing.
50  *
51  * Results:
52  *	None.
53  *
54  * Side Effects:
55  *	None.
56  *
57  *---------------------------------------------------------
58  */
59 
60 void
nullDoNothing()61 nullDoNothing()
62 {
63 }
64 
65 /*
66  *---------------------------------------------------------
67  *
68  * nullReturnFalse --
69  *
70  * This procedure does nothing, and returns FALSE.
71  *
72  * Results:
73  *	Returns FALSE always.
74  *
75  * Side Effects:
76  *	None.
77  *
78  *---------------------------------------------------------
79  */
80 
81 bool
nullReturnFalse()82 nullReturnFalse()
83 {
84     return (FALSE);
85 }
86 
87 /*
88  *---------------------------------------------------------
89  *
90  * nullReturnZero --
91  *
92  * This procedure does nothing, and returns 0.
93  *
94  * Results:
95  *	Returns 0 always.
96  *
97  * Side Effects:
98  *	None.
99  *
100  *---------------------------------------------------------
101  */
102 
103 int
nullReturnZero()104 nullReturnZero()
105 {
106     return (0);
107 }
108 
109 /*
110  *---------------------------------------------------------
111  *
112  * NullInit --
113  *
114  * NullInit doesn't do much of anything.
115  *
116  * Results:
117  *	TRUE always.
118  *
119  * Side Effects:
120  *	None.
121  *
122  *---------------------------------------------------------
123  */
124 
125 bool
NullInit()126 NullInit()
127 {
128     return TRUE;
129 }
130 
131 /*
132  * ----------------------------------------------------------------------------
133  *
134  * NullTextSize --
135  *
136  *	Determine the size of a text string.
137  *
138  * Results:
139  *	None.
140  *
141  * Side effects:
142  *	A rectangle is filled in that is the size of the text in pixels.
143  *	The origin (0, 0) of this rectangle is located on the baseline
144  *	at the far left side of the string.
145  *
146  * ----------------------------------------------------------------------------
147  */
148 
149 void
NullTextSize(text,size,r)150 NullTextSize(text, size, r)
151     char *text;
152     int size;
153     Rect *r;
154 {
155     ASSERT(r != NULL, "nullTextSize");
156     r->r_xbot = 0;
157     r->r_xtop = strlen(text);
158     r->r_ybot = 0;
159     r->r_ytop = 1;
160 }
161 
162 /*
163  * ----------------------------------------------------------------------------
164  *
165  * nullStdin --
166  *
167  *      Handle the stdin device for the NULL driver.
168  *
169  * Results:
170  *      None.
171  *
172  * Side Effects:
173  *      Adds events to the event queue.
174  *
175  * ----------------------------------------------------------------------------
176  */
177 
178 void
nullStdin(fd,cdata)179 nullStdin(fd, cdata)
180     int fd;
181     ClientData cdata;
182 {
183     int ch;
184     TxInputEvent *event;
185 
186     ch = getc(stdin);
187     event = TxNewEvent();
188     if (ch == EOF)
189 	event->txe_button = TX_EOF;
190     else
191 	event->txe_button = TX_NO_BUTTON;
192     event->txe_buttonAction = 0;
193     event->txe_ch = ch;
194     event->txe_wid = WIND_UNKNOWN_WINDOW;
195     event->txe_p.p_x = GR_CURSOR_X;
196     event->txe_p.p_y = GR_CURSOR_Y;
197     TxAddEvent(event);
198 }
199 
200 /*
201  * ----------------------------------------------------------------------------
202  *
203  * NullBitBlt --
204  *
205  *	A no-op BitBlt operation for devices that don't have one (such as
206  *	the NULL device).
207  *
208  * Results:
209  *	None.
210  *
211  * Side Effects:
212  *	None, for sure, for sure.
213  *
214  * ----------------------------------------------------------------------------
215  */
216 
217 void
NullBitBlt()218 NullBitBlt()
219 {
220 }
221 
222 
223 /*
224  *---------------------------------------------------------
225  *
226  * nullSetDisplay --
227  *
228  * This routine sets the appropriate parameters so that
229  * Magic will work with the particular display type.
230  *
231  * Results:
232  *	Returns TRUE.
233  *
234  * Side Effects:
235  *	Depends on the display type.
236  *
237  *---------------------------------------------------------
238  */
239 
240 bool
nullSetDisplay(dispType,outFileName,mouseFileName)241 nullSetDisplay(dispType, outFileName, mouseFileName)
242     char *dispType;
243     char *outFileName;
244     char *mouseFileName;
245 {
246     TxPrintf("Using NULL graphics device.\n");
247 
248     TxAdd1InputDevice(fileno(stdin), nullStdin, (ClientData) NULL);
249     if (TxStdinIsatty) SigWatchFile(fileno(stdin), "stdin");
250 
251     /* Set up the procedure values in the indirection table. */
252 
253     GrLockPtr = grSimpleLock;
254     GrUnlockPtr = grSimpleUnlock;
255     GrInitPtr = NullInit;
256     GrClosePtr = nullDoNothing;
257     GrSetCMapPtr = nullDoNothing;
258 
259     GrEnableTabletPtr = nullDoNothing;
260     GrDisableTabletPtr = nullDoNothing;
261     GrSetCursorPtr = nullDoNothing;
262     GrTextSizePtr = NullTextSize;
263     GrDrawGlyphPtr = nullDoNothing;
264     GrBitBltPtr = NullBitBlt;
265     GrReadPixelPtr = nullReturnZero;
266     GrFlushPtr = nullDoNothing;
267 
268     /* local indirections */
269     grSetSPatternPtr = nullDoNothing;
270     grPutTextPtr = nullDoNothing;
271     grFontTextPtr = nullDoNothing;
272     grDefineCursorPtr = nullDoNothing;
273     grDrawGridPtr = nullReturnFalse;
274     grDrawLinePtr = nullDoNothing;
275     grSetWMandCPtr = nullDoNothing;
276     grFillRectPtr = nullDoNothing;
277     grSetStipplePtr = nullDoNothing;
278     grSetLineStylePtr = nullDoNothing;
279     grSetCharSizePtr = nullDoNothing;
280 
281     GrScreenRect.r_xtop = 511;
282     GrScreenRect.r_ytop = 483;
283 
284     /* Set GrDisplayStatus to force graphics updates to be suspended */
285     GrDisplayStatus = DISPLAY_SUSPEND;
286 
287     return TRUE;
288 }
289