1 /* -*-C-*-
2 
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
6     Institute of Technology
7 
8 This file is part of MIT/GNU Scheme.
9 
10 MIT/GNU Scheme is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
14 
15 MIT/GNU Scheme is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with MIT/GNU Scheme; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 
25 */
26 
27 #ifndef SCM_NTSCREEN_H
28 #define SCM_NTSCREEN_H
29 
30 #include <windows.h>
31 #include <commdlg.h>
32 
33 typedef struct tagSCREENINFO *SCREEN;
34 typedef unsigned char SCREEN_ATTRIBUTE;
35 
36 /* Events */
37 
38 /* Mode flags: */
39 
40 /* a) mask of interesting events */
41 #define	SCREEN_EVENT_TYPE_RESIZE	0x000001
42 #define	SCREEN_EVENT_TYPE_KEY		0x000002
43 #define	SCREEN_EVENT_TYPE_MOUSE		0x000004
44 #define	SCREEN_EVENT_TYPE_CLOSE		0x000008
45 #define	SCREEN_EVENT_TYPE_FOCUS		0x000010
46 #define	SCREEN_EVENT_TYPE_VISIBILITY	0x000020
47 #define SCREEN_EVENT_TYPE_MASK		0x00003F
48 
49 /* b) flags for screen behaviour */
50 #define SCREEN_MODE_AUTOWRAP		0x001000
51 #define SCREEN_MODE_ECHO		0x002000
52 #define SCREEN_MODE_CR_NEWLINES		0x004000
53 #define SCREEN_MODE_LINE_INPUT		0x008000
54 #define SCREEN_MODE_PROCESS_OUTPUT	0x010000
55 #define SCREEN_MODE_EAGER_UPDATE	0x020000
56 #define SCREEN_MODE_EDWIN		0x040000
57 #define SCREEN_MODE_NEWLINE_CRS		0x080000
58 #define SCREEN_MODE_VK_KEYS		0x100000
59 #define SCREEN_MODE_MASK		0x1FF000
60 
61 /* Kludge: */
62 #define SCREEN_EDWIN_RESIZE_COMMAND	0323		/* M-S */
63 
64 typedef unsigned long SCREEN_EVENT_TYPE;
65 
66 typedef struct
67 {
68   unsigned int rows;
69   unsigned int columns;
70 } SCREEN_RESIZE_EVENT_RECORD;
71 
72 typedef struct
73 {
74   unsigned int repeat_count;
75   int virtual_keycode;
76   unsigned int virtual_scancode;
77   int ch;
78   unsigned int control_key_state : 9;
79   unsigned int key_down : 1;
80 } SCREEN_KEY_EVENT_RECORD;
81 
82 typedef struct
83 {
84   unsigned int row;
85   unsigned int column;
86   unsigned int control_key_state : 9;
87   unsigned int button_state : 3;	/* the button being pressed */
88   unsigned int up : 1;                  /* set for mouse *BUTTONUP messages */
89   unsigned int mouse_moved : 1;		/* if neither then single click */
90   unsigned int double_click : 1;
91 } SCREEN_MOUSE_EVENT_RECORD;
92 
93 typedef struct
94 {
95   unsigned int gained_p : 1;
96 } SCREEN_FOCUS_EVENT_RECORD;
97 
98 typedef struct
99 {
100   unsigned int show_p : 1;
101 } SCREEN_VISIBILITY_EVENT_RECORD;
102 
103 typedef struct
104 {
105   HWND handle;
106   SCREEN_EVENT_TYPE type;
107   union
108     {
109       SCREEN_KEY_EVENT_RECORD key;
110       SCREEN_RESIZE_EVENT_RECORD resize;
111       SCREEN_MOUSE_EVENT_RECORD mouse;
112       SCREEN_FOCUS_EVENT_RECORD focus;
113       SCREEN_VISIBILITY_EVENT_RECORD visibility;
114     } event;
115 } SCREEN_EVENT;
116 
117 /* control_key_state flags.  Only used for effective modifiers (i.e.
118    not set when already incorporated into a character translation.  */
119 
120 #define SCREEN_ALT_PRESSED            0x0001 /* An Alt key is pressed. */
121 #define SCREEN_CONTROL_PRESSED        0x0002 /* A Ctrl key is pressed. */
122 #define SCREEN_SHIFT_PRESSED          0x0004 /* A Shift key is pressed. */
123 #define SCREEN_CAPSLOCK_ON            0x0008
124 #define SCREEN_LEFT_CONTROL_PRESSED   0x0010
125 #define SCREEN_RIGHT_CONTROL_PRESSED  0x0020
126 #define SCREEN_LEFT_ALT_PRESSED       0x0040
127 #define SCREEN_RIGHT_ALT_PRESSED      0x0080
128 #define SCREEN_NUMLOCK_ON             0x0100
129 #define SCREEN_SCROLLLOCK_ON          0x0200
130 #define SCREEN_ANY_ALT_KEY_MASK	      SCREEN_ALT_PRESSED
131 
132 /* button_state flags */
133 #define SCREEN_MOUSE_EVENT_LEFT_PRESSED   0x01
134 #define SCREEN_MOUSE_EVENT_RIGHT_PRESSED  0x02
135 #define SCREEN_MOUSE_EVENT_MIDDLE_PRESSED 0x04
136 
137 /* Messages */
138 
139 #ifndef SCREEN_COMMAND_FIRST
140 #define SCREEN_COMMAND_FIRST	(WM_USER + 10)
141 #endif
142 
143 #define SCREEN_WRITE		(SCREEN_COMMAND_FIRST+0)
144   /* text = (LPSTR)lParam */
145   /* len  = (int)wParam */
146 
147 #define SCREEN_SETPOSITION	(SCREEN_COMMAND_FIRST+1)
148   /* column = LOWORD(lParam) */
149   /* row    = HIWORD(lParam) */
150 
151 #define SCREEN_GETPOSITION	(SCREEN_COMMAND_FIRST+2)
152   /* return  column = LOWORD(retval) */
153   /* return  row    = HIWORD(retval) */
154 
155 #define SCREEN_SETATTRIBUTE	(SCREEN_COMMAND_FIRST+3)
156   /* attribute = wParam */
157 
158 #define SCREEN_GETATTRIBUTE	(SCREEN_COMMAND_FIRST+4)
159   /* return  attribute = retval */
160 
161 #define SCREEN_PEEKEVENT	(SCREEN_COMMAND_FIRST+5)
162   /* count  = wParam */
163   /* buffer = (SCREEN_EVENT*) lParam */
164   /* returns #of events peeked */
165   /* if buffer is NULL, can be used to count events pending */
166 
167 #define SCREEN_READEVENT		(SCREEN_COMMAND_FIRST+6)
168   /* count  = wParam */
169   /* buffer = (SCREEN_EVENT*) lParam */
170   /* returns #of events */
171   /* if buffer is NULL, events are discarded */
172 
173 #define SCREEN_SETMODES		(SCREEN_COMMAND_FIRST+7)
174   /* modes = (WORD) wParam */
175 
176 #define SCREEN_GETMODES		(SCREEN_COMMAND_FIRST+8)
177   /* return  modes */
178 
179 /* A window has commands, which may be bound to thunks.
180    Control characters may be bound to commands.
181    Thus commands may be invoked by keypress and by menu action.  */
182 
183 typedef LRESULT (* COMMAND_HANDLER) (HWND, WORD);
184 
185 #define SCREEN_SETCOMMAND	(SCREEN_COMMAND_FIRST+9)
186   /* command = wParam */
187   /* handler = COMMAND_HANDLER = lParam;  NULL=disable */
188   /* returns old handler, or -1 on space error */
189 
190 #define SCREEN_GETCOMMAND	(SCREEN_COMMAND_FIRST+10)
191   /* command = wParam */
192   /* return  handler for char */
193 
194 #define SCREEN_SETBINDING	(SCREEN_COMMAND_FIRST+11)
195   /* char = wParam */
196   /* command = lParam; */
197 
198 #define SCREEN_GETBINDING	(SCREEN_COMMAND_FIRST+12)
199   /* char = wParam */
200   /* return command */
201 
202 #define SCREEN_SETMENU		(SCREEN_COMMAND_FIRST+13)
203   /* hMenu = (HMENU)lParam */
204 
205 #define SCREEN_READ		(SCREEN_COMMAND_FIRST+14)
206   /* buffer = (LPSTR) lParam */
207   /* length = wParam */
208   /* return  characters read */
209   /* (-1) if read would block in line-mode */
210 
211 #define SCREEN_CLEAR		(SCREEN_COMMAND_FIRST+15)
212   /* kind = wParam */
213   /* kind=0  : whole screen */
214   /* kind=1  : to eol */
215 
216 /* Predefined commands for SCREEN_SETBINDING etc */
217 
218 #define SCREEN_COMMAND_CHOOSEFONT	0x400
219 #define SCREEN_COMMAND_CLOSE		0x401
220 #define SCREEN_COMMAND_CHOOSEBACKCOLOR	0x402
221 
222 struct screen_write_char_s
223 {
224   RECT rect;
225   unsigned int row;
226   unsigned int col;
227 };
228 
229 /* Do user-level timer interrupts by using WM_TIMER.  */
230 #define USE_WM_TIMER
231 
232 extern FILE * win32_trace_file;
233 extern unsigned long win32_trace_level;
234 #ifndef WIN32_TRACE_FILENAME
235 #define WIN32_TRACE_FILENAME "w32trace.out"
236 #endif
237 
238 #ifdef __WATCOMC__
239 #define _fastcall
240 #endif
241 
242 extern VOID _fastcall clear_screen_rectangle (SCREEN, int, int, int, int);
243 extern VOID Screen_CR_to_RECT (RECT *, SCREEN, int, int, int, int);
244 extern VOID _fastcall scroll_screen_vertically
245   (SCREEN, int, int, int, int, int);
246 extern VOID _fastcall Screen_WriteCharUninterpreted
247   (SCREEN, int, struct screen_write_char_s *);
248 extern VOID _fastcall Screen_SetAttributeDirect (SCREEN, SCREEN_ATTRIBUTE);
249 extern VOID WriteScreenBlock_NoInvalidRect (SCREEN, int, int, LPSTR, int);
250 extern void Enable_Cursor (SCREEN, BOOL);
251 extern HICON ScreenSetIcon (SCREEN, HICON);
252 extern BOOL ScreenSetFont (SCREEN, char *);
253 extern BOOL ScreenSetForegroundColour (SCREEN, DWORD);
254 extern BOOL ScreenSetBackgroundColour (SCREEN, DWORD);
255 extern BOOL ScreenSetFont (SCREEN, char *);
256 extern BOOL ScreenSetDefaultFont (char *);
257 
258 extern BOOL Screen_InitApplication (HANDLE hInstance);
259 extern BOOL Screen_InitInstance (HANDLE hInstance, int nCmdShow);
260 
261 extern HANDLE Screen_Create (HANDLE, LPCSTR, int);
262 extern VOID Screen_Destroy (BOOL, HANDLE);
263 extern HWND ScreenCurrentFocus (void);
264 extern BOOL Screen_SetPosition (SCREEN, int, int);
265 
266 extern void Screen_SetAttribute (HANDLE, SCREEN_ATTRIBUTE);
267 extern void Screen_WriteChar (HANDLE, char);
268 extern void Screen_WriteText (HANDLE, char*);
269 extern int  Screen_Read (HANDLE, BOOL, char *, int);
270 extern void Screen_SetCursorPosition (HANDLE, int line, int column);
271 extern void Screen_SetMenu (SCREEN, HMENU);
272 extern void Screen_SetMode (HANDLE, int);
273 extern int  Screen_GetMode (HANDLE);
274 extern VOID Screen_GetSize (HWND, int *rows, int *columns);
275 extern void screen_char_dimensions (HWND, int *, int *);
276 
277 /* The following return zero iff no events */
278 extern int Screen_read_event (SCREEN_EVENT *);
279 extern int Screen_pending_events_p (void);
280 
281 #endif /* SCM_NTSCREEN_H */
282