1    | /*	SCCS Id: @(#)Window.c	3.3	93/02/02	*/
2    | /* Copyright (c) Dean Luick, 1992				  */
3    | /* NetHack may be freely redistributed.  See license for details. */
4    | 
5    | /*
6    |  * Data structures and support routines for the Window widget.  This is a
7    |  * drawing canvas with 16 colors and one font.
8    |  */
9    | 
10   | #ifndef SYSV
11   | #define PRESERVE_NO_SYSV	/* X11 include files may define SYSV */
12   | #endif
13   | 
14   | #ifdef MSDOS			/* from compiler */
15   | #define SHORT_FILENAMES
16   | #endif
17   | 
18   | #ifdef SHORT_FILENAMES
19   | #include <X11/IntrinsP.h>
20   | #else
21   | #include <X11/IntrinsicP.h>
22   | #endif
23   | #include <X11/StringDefs.h>
24   | 
25   | #ifdef PRESERVE_NO_SYSV
26   | # ifdef SYSV
27   | #  undef SYSV
28   | # endif
29   | # undef PRESERVE_NO_SYSV
30   | #endif
31   | 
32   | #include "xwindowp.h"
33   | 
34   | #include "config.h"
35   | 
36   | static XtResource resources[] = {
37   | #define offset(field) XtOffset(WindowWidget, window.field)
38   |     /* {name, class, type, size, offset, default_type, default_addr}, */
39   |     { XtNrows, XtCRows, XtRDimension, sizeof(Dimension),
40   | 	  offset(rows), XtRImmediate, (XtPointer) 21},
41   |     { XtNcolumns, XtCColumns, XtRDimension, sizeof(Dimension),
42   | 	  offset(columns), XtRImmediate, (XtPointer) 80},
43   |     { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
44   | 	  offset(foreground), XtRString, XtDefaultForeground },
45   | 
46   |     { XtNblack, XtCColor, XtRPixel, sizeof(Pixel),
47   | 	  offset(black), XtRString, "black"},
48   |     { XtNred, XtCColor, XtRPixel, sizeof(Pixel),
49   | 	  offset(red), XtRString, "red" },
50   |     { XtNgreen, XtCColor, XtRPixel, sizeof(Pixel),
51   | 	  offset(green), XtRString, "pale green" },
52   |     { XtNbrown, XtCColor, XtRPixel, sizeof(Pixel),
53   | 	  offset(brown), XtRString, "brown" },
54   |     { XtNblue, XtCColor, XtRPixel, sizeof(Pixel),
55   | 	  offset(blue), XtRString, "blue" },
56   |     { XtNmagenta, XtCColor, XtRPixel, sizeof(Pixel),
57   | 	  offset(magenta), XtRString, "magenta" },
58   |     { XtNcyan, XtCColor, XtRPixel, sizeof(Pixel),
59   | 	  offset(cyan), XtRString, "light cyan" },
60   |     { XtNgray, XtCColor, XtRPixel, sizeof(Pixel),
61   | 	  offset(gray), XtRString, "gray" },
62   |     { XtNorange, XtCColor, XtRPixel, sizeof(Pixel),
63   | 	  offset(orange), XtRString, "orange" },
64   |     { XtNbright_green, XtCColor, XtRPixel, sizeof(Pixel),
65   | 	  offset(bright_green), XtRString, "green" },
66   |     { XtNyellow, XtCColor, XtRPixel, sizeof(Pixel),
67   | 	  offset(yellow), XtRString, "yellow" },
68   |     { XtNbright_blue, XtCColor, XtRPixel, sizeof(Pixel),
69   | 	  offset(bright_blue), XtRString, "royal blue" },
70   |     { XtNbright_magenta, XtCColor, XtRPixel, sizeof(Pixel),
71   | 	  offset(bright_magenta), XtRString, "violet" },
72   |     { XtNbright_cyan, XtCColor, XtRPixel, sizeof(Pixel),
73   | 	  offset(bright_cyan), XtRString, "cyan" },
74   |     { XtNwhite, XtCColor, XtRPixel, sizeof(Pixel),
75   | 	  offset(white), XtRString, "white" },
76   | 
77   |     { XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
78   | 	  offset(font), XtRString, XtDefaultFont },
79   |     { XtNexposeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
80   | 	  offset(expose_callback), XtRCallback, (char *)0 },
81   |     { XtNcallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
82   | 	  offset(input_callback), XtRCallback, (char *)0 },
83   |     { XtNresizeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
84   | 	  offset(resize_callback), XtRCallback, (char *)0 },
85   | #undef offset
86   | };
87   | 
88   | /* ARGSUSED */
89   | static void no_op(w, event, params, num_params)
90   |     Widget   w;			/* unused */
91   |     XEvent   *event;		/* unused */
92   |     String   *params;		/* unused */
93   |     Cardinal *num_params;	/* unused */
94   | {
95   | }
96   | 
97   | static XtActionsRec actions[] =
98   | {
99   |     {"no-op",	no_op},
100  | };
101  | 
102  | static char translations[] =
103  | "<BtnDown>:     input() \
104  | ";
105  | 
106  | /* ARGSUSED */
107  | static void Redisplay(w, event, region)
108  |     Widget w;
109  |     XEvent *event;
110  |     Region region;	/* unused */
111  | {
112  |     /* This isn't correct - we need to call the callback with region. */
113  |     XtCallCallbacks(w, XtNexposeCallback, (caddr_t) event);
114  | }
115  | 
116  | /* ARGSUSED */
117  | static void Resize(w)
118  |     Widget w;
119  | {
120  |     XtCallCallbacks(w, XtNresizeCallback, (caddr_t) 0);
121  | }
122  | 
123  | 
124  | WindowClassRec windowClassRec = {
125  |   { /* core fields */
126  |     /* superclass		*/	(WidgetClass) &widgetClassRec,
127  |     /* class_name		*/	"Window",
128  |     /* widget_size		*/	sizeof(WindowRec),
129  |     /* class_initialize		*/	0,
130  |     /* class_part_initialize	*/	0,
131  |     /* class_inited		*/	FALSE,
132  |     /* initialize		*/	0,
133  |     /* initialize_hook		*/	0,
134  |     /* realize			*/	XtInheritRealize,
135  |     /* actions			*/	actions,
136  |     /* num_actions		*/	XtNumber(actions),
137  |     /* resources		*/	resources,
138  |     /* num_resources		*/	XtNumber(resources),
139  |     /* xrm_class		*/	NULLQUARK,
140  |     /* compress_motion		*/	TRUE,
141  |     /* compress_exposure	*/	TRUE,
142  |     /* compress_enterleave	*/	TRUE,
143  |     /* visible_interest		*/	FALSE,
144  |     /* destroy			*/	0,
145  |     /* resize			*/	Resize,
146  |     /* expose			*/	Redisplay,
147  |     /* set_values		*/	0,
148  |     /* set_values_hook		*/	0,
149  |     /* set_values_almost	*/	XtInheritSetValuesAlmost,
150  |     /* get_values_hook		*/	0,
151  |     /* accept_focus		*/	0,
152  |     /* version			*/	XtVersion,
153  |     /* callback_private		*/	0,
154  |     /* tm_table			*/	translations,
155  |     /* query_geometry		*/	XtInheritQueryGeometry,
156  |     /* display_accelerator	*/	XtInheritDisplayAccelerator,
157  |     /* extension		*/	0
158  |   },
159  |   { /* window fields */
160  |     /* empty			*/	0
161  |   }
162  | };
163  | 
164  | WidgetClass windowWidgetClass = (WidgetClass)&windowClassRec;
165  | 
166  | Font
167  | WindowFont(w) Widget w; { return ((WindowWidget)w)->window.font->fid; }
168  | 
169  | XFontStruct *
170  | WindowFontStruct(w) Widget w; { return ((WindowWidget)w)->window.font; }