1 /* NetHack 3.6	Window.c	$NHDT-Date: 1432512808 2015/05/25 00:13:28 $  $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
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 #include "lint.h"
36 
37 static XtResource resources[] = {
38 #define offset(field) XtOffset(WindowWidget, window.field)
39     /* {name, class, type, size, offset, default_type, default_addr}, */
40     { nhStr(XtNrows), nhStr(XtCRows), XtRDimension, sizeof(Dimension),
41       offset(rows), XtRImmediate, (XtPointer) 21 },
42     { nhStr(XtNcolumns), nhStr(XtCColumns), XtRDimension, sizeof(Dimension),
43       offset(columns), XtRImmediate, (XtPointer) 80 },
44     { nhStr(XtNforeground), XtCForeground, XtRPixel, sizeof(Pixel),
45       offset(foreground), XtRString, (XtPointer) XtDefaultForeground },
46 
47     { nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel), offset(black),
48       XtRString, (XtPointer) "black" },
49     { nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel), offset(red),
50       XtRString, (XtPointer) "red" },
51     { nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel), offset(green),
52       XtRString, (XtPointer) "pale green" },
53     { nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel), offset(brown),
54       XtRString, (XtPointer) "brown" },
55     { nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel), offset(blue),
56       XtRString, (XtPointer) "blue" },
57     { nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel), offset(magenta),
58       XtRString, (XtPointer) "magenta" },
59     { nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel), offset(cyan),
60       XtRString, (XtPointer) "light cyan" },
61     { nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel), offset(gray),
62       XtRString, (XtPointer) "gray" },
63     { nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel), offset(orange),
64       XtRString, (XtPointer) "orange" },
65     { nhStr(XtNbright_green), XtCColor, XtRPixel, sizeof(Pixel),
66       offset(bright_green), XtRString, (XtPointer) "green" },
67     { nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel), offset(yellow),
68       XtRString, (XtPointer) "yellow" },
69     { nhStr(XtNbright_blue), XtCColor, XtRPixel, sizeof(Pixel),
70       offset(bright_blue), XtRString, (XtPointer) "royal blue" },
71     { nhStr(XtNbright_magenta), XtCColor, XtRPixel, sizeof(Pixel),
72       offset(bright_magenta), XtRString, (XtPointer) "violet" },
73     { nhStr(XtNbright_cyan), XtCColor, XtRPixel, sizeof(Pixel),
74       offset(bright_cyan), XtRString, (XtPointer) "cyan" },
75     { nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel), offset(white),
76       XtRString, (XtPointer) "white" },
77 
78     { nhStr(XtNfont), XtCFont, XtRFontStruct, sizeof(XFontStruct *),
79       offset(font), XtRString, (XtPointer) XtDefaultFont },
80     { nhStr(XtNexposeCallback), XtCCallback, XtRCallback,
81       sizeof(XtCallbackList), offset(expose_callback), XtRCallback,
82       (char *) 0 },
83     { nhStr(XtNcallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
84       offset(input_callback), XtRCallback, (char *) 0 },
85     { nhStr(XtNresizeCallback), XtCCallback, XtRCallback,
86       sizeof(XtCallbackList), offset(resize_callback), XtRCallback,
87       (char *) 0 },
88 #undef offset
89 };
90 
91 /* ARGSUSED */
92 static void
no_op(w,event,params,num_params)93 no_op(w, event, params, num_params)
94 Widget w;             /* unused */
95 XEvent *event;        /* unused */
96 String *params;       /* unused */
97 Cardinal *num_params; /* unused */
98 {
99     nhUse(w);
100     nhUse(event);
101     nhUse(params);
102     nhUse(num_params);
103 
104     return;
105 }
106 
107 static XtActionsRec actions[] = {
108     { nhStr("no-op"), no_op },
109 };
110 
111 static char translations[] = "<BtnDown>:     input() \
112 ";
113 
114 /* ARGSUSED */
115 static void
Redisplay(w,event,region)116 Redisplay(w, event, region)
117 Widget w;
118 XEvent *event;
119 Region region; /* unused */
120 {
121     nhUse(region);
122 
123     /* This isn't correct - we need to call the callback with region. */
124     XtCallCallbacks(w, XtNexposeCallback, (XtPointer)event);
125 }
126 
127 /* ARGSUSED */
128 static void
Resize(w)129 Resize(w)
130 Widget w;
131 {
132     XtCallCallbacks(w, XtNresizeCallback, (XtPointer) 0);
133 }
134 
135 WindowClassRec windowClassRec = {
136     { /* core fields */
137       /* superclass		*/ (WidgetClass) &widgetClassRec,
138       /* class_name		*/ nhStr("Window"),
139       /* widget_size		*/ sizeof(WindowRec),
140       /* class_initialize		*/ 0,
141       /* class_part_initialize	*/ 0,
142       /* class_inited		*/ FALSE,
143       /* initialize		*/ 0,
144       /* initialize_hook		*/ 0,
145       /* realize			*/ XtInheritRealize,
146       /* actions			*/ actions,
147       /* num_actions		*/ XtNumber(actions),
148       /* resources		*/ resources,
149       /* num_resources		*/ XtNumber(resources),
150       /* xrm_class		*/ NULLQUARK,
151       /* compress_motion		*/ TRUE,
152       /* compress_exposure	*/ TRUE,
153       /* compress_enterleave	*/ TRUE,
154       /* visible_interest		*/ FALSE,
155       /* destroy			*/ 0,
156       /* resize			*/ Resize,
157       /* expose			*/ Redisplay,
158       /* set_values		*/ 0,
159       /* set_values_hook		*/ 0,
160       /* set_values_almost	*/ XtInheritSetValuesAlmost,
161       /* get_values_hook		*/ 0,
162       /* accept_focus		*/ 0,
163       /* version			*/ XtVersion,
164       /* callback_private		*/ 0,
165       /* tm_table			*/ translations,
166       /* query_geometry		*/ XtInheritQueryGeometry,
167       /* display_accelerator	*/ XtInheritDisplayAccelerator,
168       /* extension		*/ 0 },
169     { /* window fields */
170       /* empty			*/ 0 }
171 };
172 
173 WidgetClass windowWidgetClass = (WidgetClass) &windowClassRec;
174 
175 Font
WindowFont(w)176 WindowFont(w)
177 Widget w;
178 {
179     return ((WindowWidget) w)->window.font->fid;
180 }
181 
182 XFontStruct *
WindowFontStruct(w)183 WindowFontStruct(w)
184 Widget w;
185 {
186     return ((WindowWidget) w)->window.font;
187 }
188