Commit | Line | Data |
---|---|---|
c6a6499f | 1 | /* MS-DOS specific C utilities. -*- coding: raw-text -*- |
0b5538bd | 2 | Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, |
114f9c96 | 3 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
8cabe764 | 4 | Free Software Foundation, Inc. |
1b94449f RS |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
1b94449f | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
1b94449f RS |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
1b94449f | 20 | |
9da6e765 | 21 | /* Contributed by Morten Welinder */ |
f32d4091 | 22 | /* New display, keyboard, and mouse control by Kim F. Storm */ |
9da6e765 | 23 | |
1b94449f RS |
24 | /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */ |
25 | ||
48984716 | 26 | #include <config.h> |
1b94449f RS |
27 | |
28 | #ifdef MSDOS | |
d7306fe6 | 29 | #include <setjmp.h> |
1b94449f RS |
30 | #include "lisp.h" |
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
06b1ea13 | 33 | #include <time.h> |
1b94449f RS |
34 | #include <sys/param.h> |
35 | #include <sys/time.h> | |
36 | #include <dos.h> | |
d21e67b5 | 37 | #include <errno.h> |
a7cf9151 | 38 | #include <string.h> /* for bzero and string functions */ |
d21e67b5 | 39 | #include <sys/stat.h> /* for _fixpath */ |
a7cf9151 | 40 | #include <unistd.h> /* for chdir, dup, dup2, etc. */ |
bf794306 | 41 | #include <dir.h> /* for getdisk */ |
affa509c | 42 | #pragma pack(0) /* dir.h does a pack(4), which isn't GCC's default */ |
1bd7b2c7 | 43 | #include <fcntl.h> |
a7cf9151 | 44 | #include <io.h> /* for setmode */ |
fc171623 KH |
45 | #include <dpmi.h> /* for __dpmi_xxx stuff */ |
46 | #include <sys/farptr.h> /* for _farsetsel, _farnspokeb */ | |
d21e67b5 | 47 | #include <libc/dosio.h> /* for _USE_LFN */ |
a7cf9151 | 48 | #include <conio.h> /* for cputs */ |
1bd7b2c7 | 49 | |
1b94449f RS |
50 | #include "msdos.h" |
51 | #include "systime.h" | |
3e1944a3 | 52 | #include "frame.h" |
1b94449f | 53 | #include "termhooks.h" |
aa9ce936 | 54 | #include "termchar.h" |
87485d6f | 55 | #include "dispextern.h" |
c77f6f1b | 56 | #include "dosfns.h" |
87485d6f | 57 | #include "termopts.h" |
83be827a | 58 | #include "character.h" |
aa9ce936 EZ |
59 | #include "coding.h" |
60 | #include "disptab.h" | |
87485d6f | 61 | #include "window.h" |
fc171623 KH |
62 | #include "buffer.h" |
63 | #include "commands.h" | |
41ad069b | 64 | #include "blockinput.h" |
97dd288b | 65 | #include "keyboard.h" |
6b61353c | 66 | #include "intervals.h" |
1b94449f RS |
67 | #include <go32.h> |
68 | #include <pc.h> | |
69 | #include <ctype.h> | |
70 | /* #include <process.h> */ | |
71 | /* Damn that local process.h! Instead we can define P_WAIT ourselves. */ | |
72 | #define P_WAIT 1 | |
73 | ||
d21e67b5 RS |
74 | #ifndef _USE_LFN |
75 | #define _USE_LFN 0 | |
76 | #endif | |
77 | ||
b36701cc RS |
78 | #ifndef _dos_ds |
79 | #define _dos_ds _go32_info_block.selector_for_linear_memory | |
80 | #endif | |
81 | ||
8748735b | 82 | #include <signal.h> |
417a04bb | 83 | #include "syssignal.h" |
8748735b | 84 | |
1bd7b2c7 RS |
85 | #ifndef SYSTEM_MALLOC |
86 | ||
87 | #ifdef GNU_MALLOC | |
88 | ||
89 | /* If other `malloc' than ours is used, force our `sbrk' behave like | |
90 | Unix programs expect (resize memory blocks to keep them contiguous). | |
91 | If `sbrk' from `ralloc.c' is NOT used, also zero-out sbrk'ed memory, | |
92 | because that's what `gmalloc' expects to get. */ | |
93 | #include <crt0.h> | |
94 | ||
95 | #ifdef REL_ALLOC | |
96 | int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK; | |
97 | #else /* not REL_ALLOC */ | |
98 | int _crt0_startup_flags = (_CRT0_FLAG_UNIX_SBRK | _CRT0_FLAG_FILL_SBRK_MEMORY); | |
99 | #endif /* not REL_ALLOC */ | |
100 | #endif /* GNU_MALLOC */ | |
101 | ||
102 | #endif /* not SYSTEM_MALLOC */ | |
aee81730 RS |
103 | |
104 | static unsigned long | |
105 | event_timestamp () | |
106 | { | |
107 | struct time t; | |
108 | unsigned long s; | |
56e19ec4 | 109 | |
aee81730 RS |
110 | gettime (&t); |
111 | s = t.ti_min; | |
112 | s *= 60; | |
113 | s += t.ti_sec; | |
114 | s *= 1000; | |
115 | s += t.ti_hund * 10; | |
56e19ec4 | 116 | |
aee81730 RS |
117 | return s; |
118 | } | |
119 | ||
f32d4091 KS |
120 | \f |
121 | /* ------------------------ Mouse control --------------------------- | |
122 | * | |
123 | * Coordinates are in screen positions and zero based. | |
124 | * Mouse buttons are numbered from left to right and also zero based. | |
125 | */ | |
1b94449f | 126 | |
0c3cfc51 EZ |
127 | /* This used to be in termhooks.h, but mainstream Emacs code no longer |
128 | uses it, and it was removed... */ | |
129 | #define NUM_MOUSE_BUTTONS (5) | |
130 | ||
f32d4091 KS |
131 | int have_mouse; /* 0: no, 1: enabled, -1: disabled */ |
132 | static int mouse_visible; | |
1b94449f | 133 | |
f32d4091 KS |
134 | static int mouse_last_x; |
135 | static int mouse_last_y; | |
1b94449f | 136 | |
f32d4091 KS |
137 | static int mouse_button_translate[NUM_MOUSE_BUTTONS]; |
138 | static int mouse_button_count; | |
1b94449f | 139 | |
f32d4091 KS |
140 | void |
141 | mouse_on () | |
1b94449f | 142 | { |
1b94449f | 143 | union REGS regs; |
1b94449f | 144 | |
f32d4091 | 145 | if (have_mouse > 0 && !mouse_visible) |
1b94449f | 146 | { |
3e1944a3 EZ |
147 | struct tty_display_info *tty = CURTTY (); |
148 | ||
149 | if (tty->termscript) | |
150 | fprintf (tty->termscript, "<M_ON>"); | |
f32d4091 KS |
151 | regs.x.ax = 0x0001; |
152 | int86 (0x33, ®s, ®s); | |
153 | mouse_visible = 1; | |
1b94449f | 154 | } |
1b94449f RS |
155 | } |
156 | ||
f32d4091 KS |
157 | void |
158 | mouse_off () | |
1b94449f | 159 | { |
f32d4091 | 160 | union REGS regs; |
1b94449f | 161 | |
f32d4091 | 162 | if (have_mouse > 0 && mouse_visible) |
1b94449f | 163 | { |
3e1944a3 EZ |
164 | struct tty_display_info *tty = CURTTY (); |
165 | ||
166 | if (tty->termscript) | |
167 | fprintf (tty->termscript, "<M_OFF>"); | |
f32d4091 KS |
168 | regs.x.ax = 0x0002; |
169 | int86 (0x33, ®s, ®s); | |
170 | mouse_visible = 0; | |
1b94449f | 171 | } |
1b94449f RS |
172 | } |
173 | ||
8f190436 EZ |
174 | static void |
175 | mouse_setup_buttons (int n_buttons) | |
176 | { | |
177 | if (n_buttons == 3) | |
178 | { | |
179 | mouse_button_count = 3; | |
180 | mouse_button_translate[0] = 0; /* Left */ | |
181 | mouse_button_translate[1] = 2; /* Middle */ | |
182 | mouse_button_translate[2] = 1; /* Right */ | |
183 | } | |
184 | else /* two, what else? */ | |
185 | { | |
186 | mouse_button_count = 2; | |
187 | mouse_button_translate[0] = 0; | |
188 | mouse_button_translate[1] = 1; | |
189 | } | |
190 | } | |
191 | ||
192 | DEFUN ("msdos-set-mouse-buttons", Fmsdos_set_mouse_buttons, Smsdos_set_mouse_buttons, | |
193 | 1, 1, "NSet number of mouse buttons to: ", | |
70da46c3 PJ |
194 | doc: /* Set the number of mouse buttons to use by Emacs. |
195 | This is useful with mice that report the number of buttons inconsistently, | |
196 | e.g., if the number of buttons is reported as 3, but Emacs only sees 2 of | |
197 | them. This happens with wheeled mice on Windows 9X, for example. */) | |
198 | (nbuttons) | |
8f190436 EZ |
199 | Lisp_Object nbuttons; |
200 | { | |
e7522695 EZ |
201 | int n; |
202 | ||
b7826503 | 203 | CHECK_NUMBER (nbuttons); |
e7522695 EZ |
204 | n = XINT (nbuttons); |
205 | if (n < 2 || n > 3) | |
ebe061ca KS |
206 | xsignal2 (Qargs_out_of_range, |
207 | build_string ("only 2 or 3 mouse buttons are supported"), | |
208 | nbuttons); | |
e7522695 | 209 | mouse_setup_buttons (n); |
8f190436 EZ |
210 | return Qnil; |
211 | } | |
212 | ||
211c7152 EZ |
213 | static void |
214 | mouse_get_xy (int *x, int *y) | |
215 | { | |
216 | union REGS regs; | |
217 | ||
218 | regs.x.ax = 0x0003; | |
219 | int86 (0x33, ®s, ®s); | |
220 | *x = regs.x.cx / 8; | |
221 | *y = regs.x.dx / 8; | |
222 | } | |
223 | ||
f32d4091 KS |
224 | void |
225 | mouse_moveto (x, y) | |
226 | int x, y; | |
1b94449f | 227 | { |
f32d4091 | 228 | union REGS regs; |
3e1944a3 | 229 | struct tty_display_info *tty = CURTTY (); |
1b94449f | 230 | |
3e1944a3 EZ |
231 | if (tty->termscript) |
232 | fprintf (tty->termscript, "<M_XY=%dx%d>", x, y); | |
f32d4091 KS |
233 | regs.x.ax = 0x0004; |
234 | mouse_last_x = regs.x.cx = x * 8; | |
235 | mouse_last_y = regs.x.dx = y * 8; | |
236 | int86 (0x33, ®s, ®s); | |
1b94449f RS |
237 | } |
238 | ||
f32d4091 KS |
239 | static int |
240 | mouse_pressed (b, xp, yp) | |
241 | int b, *xp, *yp; | |
1b94449f | 242 | { |
f32d4091 | 243 | union REGS regs; |
1b94449f | 244 | |
f32d4091 KS |
245 | if (b >= mouse_button_count) |
246 | return 0; | |
247 | regs.x.ax = 0x0005; | |
248 | regs.x.bx = mouse_button_translate[b]; | |
249 | int86 (0x33, ®s, ®s); | |
250 | if (regs.x.bx) | |
251 | *xp = regs.x.cx / 8, *yp = regs.x.dx / 8; | |
252 | return (regs.x.bx != 0); | |
1b94449f RS |
253 | } |
254 | ||
f32d4091 KS |
255 | static int |
256 | mouse_released (b, xp, yp) | |
257 | int b, *xp, *yp; | |
1b94449f RS |
258 | { |
259 | union REGS regs; | |
260 | ||
f32d4091 KS |
261 | if (b >= mouse_button_count) |
262 | return 0; | |
263 | regs.x.ax = 0x0006; | |
264 | regs.x.bx = mouse_button_translate[b]; | |
265 | int86 (0x33, ®s, ®s); | |
266 | if (regs.x.bx) | |
267 | *xp = regs.x.cx / 8, *yp = regs.x.dx / 8; | |
268 | return (regs.x.bx != 0); | |
1b94449f RS |
269 | } |
270 | ||
0c7bc1aa EZ |
271 | static int |
272 | mouse_button_depressed (b, xp, yp) | |
273 | int b, *xp, *yp; | |
274 | { | |
275 | union REGS regs; | |
276 | ||
277 | if (b >= mouse_button_count) | |
278 | return 0; | |
279 | regs.x.ax = 0x0003; | |
280 | int86 (0x33, ®s, ®s); | |
281 | if ((regs.x.bx & (1 << mouse_button_translate[b])) != 0) | |
282 | { | |
283 | *xp = regs.x.cx / 8; | |
284 | *yp = regs.x.dx / 8; | |
285 | return 1; | |
286 | } | |
287 | return 0; | |
288 | } | |
289 | ||
f32d4091 KS |
290 | void |
291 | mouse_get_pos (f, insist, bar_window, part, x, y, time) | |
292 | FRAME_PTR *f; | |
293 | int insist; | |
294 | Lisp_Object *bar_window, *x, *y; | |
295 | enum scroll_bar_part *part; | |
296 | unsigned long *time; | |
297 | { | |
298 | int ix, iy; | |
211c7152 EZ |
299 | Lisp_Object frame, tail; |
300 | ||
301 | /* Clear the mouse-moved flag for every frame on this display. */ | |
302 | FOR_EACH_FRAME (tail, frame) | |
303 | XFRAME (frame)->mouse_moved = 0; | |
f32d4091 | 304 | |
2d764c78 | 305 | *f = SELECTED_FRAME(); |
f32d4091 KS |
306 | *bar_window = Qnil; |
307 | mouse_get_xy (&ix, &iy); | |
f32d4091 | 308 | *time = event_timestamp (); |
211c7152 EZ |
309 | *x = make_number (mouse_last_x = ix); |
310 | *y = make_number (mouse_last_y = iy); | |
f32d4091 | 311 | } |
1b94449f | 312 | |
f32d4091 KS |
313 | static void |
314 | mouse_check_moved () | |
1b94449f | 315 | { |
aee81730 | 316 | int x, y; |
1b94449f | 317 | |
f32d4091 | 318 | mouse_get_xy (&x, &y); |
2d764c78 | 319 | SELECTED_FRAME()->mouse_moved |= (x != mouse_last_x || y != mouse_last_y); |
f32d4091 KS |
320 | mouse_last_x = x; |
321 | mouse_last_y = y; | |
322 | } | |
1b94449f | 323 | |
97dd288b EZ |
324 | /* Force the mouse driver to ``forget'' about any button clicks until |
325 | now. */ | |
326 | static void | |
327 | mouse_clear_clicks (void) | |
328 | { | |
329 | int b; | |
330 | ||
331 | for (b = 0; b < mouse_button_count; b++) | |
332 | { | |
333 | int dummy_x, dummy_y; | |
334 | ||
335 | (void) mouse_pressed (b, &dummy_x, &dummy_y); | |
336 | (void) mouse_released (b, &dummy_x, &dummy_y); | |
337 | } | |
338 | } | |
339 | ||
f32d4091 KS |
340 | void |
341 | mouse_init () | |
342 | { | |
343 | union REGS regs; | |
3e1944a3 | 344 | struct tty_display_info *tty = CURTTY (); |
647c32eb | 345 | |
3e1944a3 EZ |
346 | if (tty->termscript) |
347 | fprintf (tty->termscript, "<M_INIT>"); | |
1b94449f | 348 | |
f32d4091 KS |
349 | regs.x.ax = 0x0021; |
350 | int86 (0x33, ®s, ®s); | |
091d0bdf | 351 | |
0c7bc1aa EZ |
352 | /* Reset the mouse last press/release info. It seems that Windows |
353 | doesn't do that automatically when function 21h is called, which | |
354 | causes Emacs to ``remember'' the click that switched focus to the | |
355 | window just before Emacs was started from that window. */ | |
97dd288b | 356 | mouse_clear_clicks (); |
0c7bc1aa | 357 | |
f32d4091 KS |
358 | regs.x.ax = 0x0007; |
359 | regs.x.cx = 0; | |
360 | regs.x.dx = 8 * (ScreenCols () - 1); | |
361 | int86 (0x33, ®s, ®s); | |
1b94449f | 362 | |
f32d4091 KS |
363 | regs.x.ax = 0x0008; |
364 | regs.x.cx = 0; | |
365 | regs.x.dx = 8 * (ScreenRows () - 1); | |
366 | int86 (0x33, ®s, ®s); | |
1b94449f | 367 | |
f32d4091 KS |
368 | mouse_moveto (0, 0); |
369 | mouse_visible = 0; | |
370 | } | |
3eb1dbb6 | 371 | \f |
f32d4091 KS |
372 | /* ------------------------- Screen control ---------------------- |
373 | * | |
374 | */ | |
aee81730 | 375 | |
f32d4091 | 376 | static int internal_terminal = 0; |
aee81730 | 377 | |
f32d4091 KS |
378 | #ifndef HAVE_X_WINDOWS |
379 | extern unsigned char ScreenAttrib; | |
380 | static int screen_face; | |
aee81730 | 381 | |
f32d4091 KS |
382 | static int screen_size_X; |
383 | static int screen_size_Y; | |
384 | static int screen_size; | |
1b94449f | 385 | |
f32d4091 KS |
386 | static int current_pos_X; |
387 | static int current_pos_Y; | |
388 | static int new_pos_X; | |
389 | static int new_pos_Y; | |
1b94449f | 390 | |
f32d4091 KS |
391 | static void *startup_screen_buffer; |
392 | static int startup_screen_size_X; | |
393 | static int startup_screen_size_Y; | |
394 | static int startup_pos_X; | |
395 | static int startup_pos_Y; | |
c9adab25 | 396 | static unsigned char startup_screen_attrib; |
1b94449f | 397 | |
06b1ea13 EZ |
398 | static clock_t startup_time; |
399 | ||
f32d4091 | 400 | static int term_setup_done; |
1b94449f | 401 | |
8ba01a32 EZ |
402 | static unsigned short outside_cursor; |
403 | ||
f32d4091 | 404 | /* Similar to the_only_frame. */ |
3e1944a3 | 405 | struct tty_display_info the_only_display_info; |
1b94449f | 406 | |
039274cf EZ |
407 | /* Support for DOS/V (allows Japanese characters to be displayed on |
408 | standard, non-Japanese, ATs). Only supported for DJGPP v2 and later. */ | |
409 | ||
410 | /* Holds the address of the text-mode screen buffer. */ | |
411 | static unsigned long screen_old_address = 0; | |
412 | /* Segment and offset of the virtual screen. If 0, DOS/V is NOT loaded. */ | |
413 | static unsigned short screen_virtual_segment = 0; | |
414 | static unsigned short screen_virtual_offset = 0; | |
68026917 AI |
415 | /* A flag to control how to display unibyte 8-bit characters. */ |
416 | extern int unibyte_display_via_language_environment; | |
039274cf | 417 | |
6b61353c KH |
418 | extern Lisp_Object Qcursor_type; |
419 | extern Lisp_Object Qbar, Qhbar; | |
8ba01a32 | 420 | |
9ccf54e9 | 421 | /* The screen colors of the current frame, which serve as the default |
deece6f5 EZ |
422 | colors for newly-created frames. */ |
423 | static int initial_screen_colors[2]; | |
424 | ||
039274cf EZ |
425 | /* Update the screen from a part of relocated DOS/V screen buffer which |
426 | begins at OFFSET and includes COUNT characters. */ | |
427 | static void | |
428 | dosv_refresh_virtual_screen (int offset, int count) | |
429 | { | |
430 | __dpmi_regs regs; | |
431 | ||
9ab8560d | 432 | if (offset < 0 || count < 0) /* paranoia; invalid values crash DOS/V */ |
40437cf5 EZ |
433 | return; |
434 | ||
039274cf EZ |
435 | regs.h.ah = 0xff; /* update relocated screen */ |
436 | regs.x.es = screen_virtual_segment; | |
437 | regs.x.di = screen_virtual_offset + offset; | |
438 | regs.x.cx = count; | |
439 | __dpmi_int (0x10, ®s); | |
440 | } | |
039274cf | 441 | |
d1d5dc19 | 442 | static void |
f32d4091 | 443 | dos_direct_output (y, x, buf, len) |
56e19ec4 | 444 | int x, y; |
f32d4091 KS |
445 | char *buf; |
446 | int len; | |
1b94449f | 447 | { |
40437cf5 EZ |
448 | int t0 = 2 * (x + y * screen_size_X); |
449 | int t = t0 + (int) ScreenPrimary; | |
039274cf | 450 | int l0 = len; |
fc171623 | 451 | |
fc171623 KH |
452 | /* This is faster. */ |
453 | for (_farsetsel (_dos_ds); --len >= 0; t += 2, buf++) | |
454 | _farnspokeb (t, *buf); | |
039274cf EZ |
455 | |
456 | if (screen_virtual_segment) | |
457 | dosv_refresh_virtual_screen (t0, l0); | |
f32d4091 KS |
458 | } |
459 | #endif | |
460 | ||
461 | #ifndef HAVE_X_WINDOWS | |
462 | ||
b36701cc RS |
463 | static int blink_bit = -1; /* the state of the blink bit at startup */ |
464 | ||
76ac1508 RS |
465 | /* Enable bright background colors. */ |
466 | static void | |
467 | bright_bg (void) | |
468 | { | |
469 | union REGS regs; | |
470 | ||
b36701cc RS |
471 | /* Remember the original state of the blink/bright-background bit. |
472 | It is stored at 0040:0065h in the BIOS data area. */ | |
473 | if (blink_bit == -1) | |
474 | blink_bit = (_farpeekb (_dos_ds, 0x465) & 0x20) == 0x20; | |
475 | ||
76ac1508 RS |
476 | regs.h.bl = 0; |
477 | regs.x.ax = 0x1003; | |
478 | int86 (0x10, ®s, ®s); | |
479 | } | |
480 | ||
b36701cc RS |
481 | /* Disable bright background colors (and enable blinking) if we found |
482 | the video system in that state at startup. */ | |
483 | static void | |
484 | maybe_enable_blinking (void) | |
485 | { | |
486 | if (blink_bit == 1) | |
487 | { | |
488 | union REGS regs; | |
489 | ||
490 | regs.h.bl = 1; | |
491 | regs.x.ax = 0x1003; | |
492 | int86 (0x10, ®s, ®s); | |
493 | } | |
494 | } | |
495 | ||
8ba01a32 EZ |
496 | /* Return non-zero if the system has a VGA adapter. */ |
497 | static int | |
498 | vga_installed (void) | |
499 | { | |
500 | union REGS regs; | |
501 | ||
502 | regs.x.ax = 0x1a00; | |
503 | int86 (0x10, ®s, ®s); | |
504 | if (regs.h.al == 0x1a && regs.h.bl > 5 && regs.h.bl < 13) | |
505 | return 1; | |
506 | return 0; | |
507 | } | |
508 | ||
4a96d4d2 KH |
509 | /* Set the screen dimensions so that it can show no less than |
510 | ROWS x COLS frame. */ | |
48ffe371 | 511 | |
4a96d4d2 KH |
512 | void |
513 | dos_set_window_size (rows, cols) | |
514 | int *rows, *cols; | |
515 | { | |
516 | char video_name[30]; | |
4a96d4d2 | 517 | union REGS regs; |
56e19ec4 EZ |
518 | Lisp_Object video_mode; |
519 | int video_mode_value, have_vga = 0; | |
4a96d4d2 KH |
520 | int current_rows = ScreenRows (), current_cols = ScreenCols (); |
521 | ||
522 | if (*rows == current_rows && *cols == current_cols) | |
523 | return; | |
524 | ||
4a96d4d2 | 525 | mouse_off (); |
8ba01a32 | 526 | have_vga = vga_installed (); |
4a96d4d2 | 527 | |
48ffe371 | 528 | /* If the user specified a special video mode for these dimensions, |
4a96d4d2 KH |
529 | use that mode. */ |
530 | sprintf (video_name, "screen-dimensions-%dx%d", *rows, *cols); | |
531 | video_mode = XSYMBOL (Fintern_soft (build_string (video_name), | |
532 | Qnil))-> value; | |
533 | ||
534 | if (INTEGERP (video_mode) | |
535 | && (video_mode_value = XINT (video_mode)) > 0) | |
536 | { | |
537 | regs.x.ax = video_mode_value; | |
538 | int86 (0x10, ®s, ®s); | |
48ffe371 RS |
539 | |
540 | if (have_mouse) | |
541 | { | |
542 | /* Must hardware-reset the mouse, or else it won't update | |
543 | its notion of screen dimensions for some non-standard | |
544 | video modes. This is *painfully* slow... */ | |
545 | regs.x.ax = 0; | |
546 | int86 (0x33, ®s, ®s); | |
547 | } | |
4a96d4d2 KH |
548 | } |
549 | ||
550 | /* Find one of the dimensions supported by standard EGA/VGA | |
551 | which gives us at least the required dimensions. */ | |
4a96d4d2 KH |
552 | else |
553 | { | |
554 | static struct { | |
56e19ec4 | 555 | int rows, need_vga; |
4a96d4d2 KH |
556 | } std_dimension[] = { |
557 | {25, 0}, | |
558 | {28, 1}, | |
559 | {35, 0}, | |
560 | {40, 1}, | |
561 | {43, 0}, | |
562 | {50, 1} | |
563 | }; | |
564 | int i = 0; | |
565 | ||
566 | while (i < sizeof (std_dimension) / sizeof (std_dimension[0])) | |
567 | { | |
568 | if (std_dimension[i].need_vga <= have_vga | |
569 | && std_dimension[i].rows >= *rows) | |
570 | { | |
571 | if (std_dimension[i].rows != current_rows | |
572 | || *cols != current_cols) | |
48ffe371 | 573 | _set_screen_lines (std_dimension[i].rows); |
4a96d4d2 KH |
574 | break; |
575 | } | |
48ffe371 | 576 | i++; |
4a96d4d2 KH |
577 | } |
578 | } | |
579 | ||
4a96d4d2 KH |
580 | |
581 | if (have_mouse) | |
582 | { | |
4a96d4d2 KH |
583 | mouse_init (); |
584 | mouse_on (); | |
585 | } | |
586 | ||
587 | /* Tell the caller what dimensions have been REALLY set. */ | |
588 | *rows = ScreenRows (); | |
589 | *cols = ScreenCols (); | |
76ac1508 | 590 | |
bed43f1d EZ |
591 | /* Update Emacs' notion of screen dimensions. */ |
592 | screen_size_X = *cols; | |
593 | screen_size_Y = *rows; | |
594 | screen_size = *cols * *rows; | |
595 | ||
41ad069b EZ |
596 | /* If the dimensions changed, the mouse highlight info is invalid. */ |
597 | if (current_rows != *rows || current_cols != *cols) | |
598 | { | |
599 | struct frame *f = SELECTED_FRAME(); | |
3e1944a3 | 600 | struct tty_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
41ad069b EZ |
601 | Lisp_Object window = dpyinfo->mouse_face_window; |
602 | ||
603 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
604 | { | |
605 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
606 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
607 | dpyinfo->mouse_face_window = Qnil; | |
608 | } | |
609 | } | |
41ad069b | 610 | |
76ac1508 RS |
611 | /* Enable bright background colors. */ |
612 | bright_bg (); | |
039274cf EZ |
613 | |
614 | /* FIXME: I'm not sure the above will run at all on DOS/V. But let's | |
615 | be defensive anyway. */ | |
616 | if (screen_virtual_segment) | |
617 | dosv_refresh_virtual_screen (0, *cols * *rows); | |
4a96d4d2 KH |
618 | } |
619 | ||
48ffe371 RS |
620 | /* If we write a character in the position where the mouse is, |
621 | the mouse cursor may need to be refreshed. */ | |
09e2ac30 RS |
622 | |
623 | static void | |
f32d4091 | 624 | mouse_off_maybe () |
09e2ac30 | 625 | { |
f32d4091 | 626 | int x, y; |
56e19ec4 | 627 | |
f32d4091 KS |
628 | if (!mouse_visible) |
629 | return; | |
56e19ec4 | 630 | |
f32d4091 KS |
631 | mouse_get_xy (&x, &y); |
632 | if (y != new_pos_Y || x < new_pos_X) | |
633 | return; | |
56e19ec4 | 634 | |
f32d4091 KS |
635 | mouse_off (); |
636 | } | |
637 | ||
8ba01a32 EZ |
638 | #define DEFAULT_CURSOR_START (-1) |
639 | #define DEFAULT_CURSOR_WIDTH (-1) | |
640 | #define BOX_CURSOR_WIDTH (-32) | |
641 | ||
642 | /* Set cursor to begin at scan line START_LINE in the character cell | |
643 | and extend for WIDTH scan lines. Scan lines are counted from top | |
644 | of the character cell, starting from zero. */ | |
645 | static void | |
646 | msdos_set_cursor_shape (struct frame *f, int start_line, int width) | |
647 | { | |
8ba01a32 EZ |
648 | unsigned desired_cursor; |
649 | __dpmi_regs regs; | |
650 | int max_line, top_line, bot_line; | |
3e1944a3 | 651 | struct tty_display_info *tty = FRAME_TTY (f); |
8ba01a32 EZ |
652 | |
653 | /* Avoid the costly BIOS call if F isn't the currently selected | |
654 | frame. Allow for NULL as unconditionally meaning the selected | |
655 | frame. */ | |
656 | if (f && f != SELECTED_FRAME()) | |
657 | return; | |
658 | ||
3e1944a3 EZ |
659 | if (tty->termscript) |
660 | fprintf (tty->termscript, "\nCURSOR SHAPE=(%d,%d)", start_line, width); | |
b106731c | 661 | |
8ba01a32 EZ |
662 | /* The character cell size in scan lines is stored at 40:85 in the |
663 | BIOS data area. */ | |
664 | max_line = _farpeekw (_dos_ds, 0x485) - 1; | |
665 | switch (max_line) | |
666 | { | |
667 | default: /* this relies on CGA cursor emulation being ON! */ | |
668 | case 7: | |
669 | bot_line = 7; | |
670 | break; | |
671 | case 9: | |
672 | bot_line = 9; | |
673 | break; | |
674 | case 13: | |
675 | bot_line = 12; | |
676 | break; | |
677 | case 15: | |
678 | bot_line = 14; | |
679 | break; | |
680 | } | |
681 | ||
682 | if (width < 0) | |
683 | { | |
684 | if (width == BOX_CURSOR_WIDTH) | |
685 | { | |
686 | top_line = 0; | |
687 | bot_line = max_line; | |
688 | } | |
689 | else if (start_line != DEFAULT_CURSOR_START) | |
690 | { | |
691 | top_line = start_line; | |
692 | bot_line = top_line - width - 1; | |
693 | } | |
694 | else if (width != DEFAULT_CURSOR_WIDTH) | |
695 | { | |
696 | top_line = 0; | |
697 | bot_line = -1 - width; | |
698 | } | |
699 | else | |
700 | top_line = bot_line + 1; | |
701 | } | |
702 | else if (width == 0) | |
703 | { | |
704 | /* [31, 0] seems to DTRT for all screen sizes. */ | |
705 | top_line = 31; | |
706 | bot_line = 0; | |
707 | } | |
708 | else /* WIDTH is positive */ | |
709 | { | |
710 | if (start_line != DEFAULT_CURSOR_START) | |
711 | bot_line = start_line; | |
712 | top_line = bot_line - (width - 1); | |
713 | } | |
714 | ||
715 | /* If the current cursor shape is already what they want, we are | |
716 | history here. */ | |
717 | desired_cursor = ((top_line & 0x1f) << 8) | (bot_line & 0x1f); | |
718 | if (desired_cursor == _farpeekw (_dos_ds, 0x460)) | |
719 | return; | |
720 | ||
721 | regs.h.ah = 1; | |
722 | regs.x.cx = desired_cursor; | |
723 | __dpmi_int (0x10, ®s); | |
8ba01a32 EZ |
724 | } |
725 | ||
726 | static void | |
727 | IT_set_cursor_type (struct frame *f, Lisp_Object cursor_type) | |
728 | { | |
a0738471 | 729 | if (EQ (cursor_type, Qbar) || EQ (cursor_type, Qhbar)) |
8ba01a32 EZ |
730 | { |
731 | /* Just BAR means the normal EGA/VGA cursor. */ | |
732 | msdos_set_cursor_shape (f, DEFAULT_CURSOR_START, DEFAULT_CURSOR_WIDTH); | |
733 | } | |
a0738471 EZ |
734 | else if (CONSP (cursor_type) |
735 | && (EQ (XCAR (cursor_type), Qbar) | |
736 | || EQ (XCAR (cursor_type), Qhbar))) | |
8ba01a32 EZ |
737 | { |
738 | Lisp_Object bar_parms = XCDR (cursor_type); | |
739 | int width; | |
740 | ||
741 | if (INTEGERP (bar_parms)) | |
742 | { | |
743 | /* Feature: negative WIDTH means cursor at the top | |
744 | of the character cell, zero means invisible cursor. */ | |
745 | width = XINT (bar_parms); | |
746 | msdos_set_cursor_shape (f, width >= 0 ? DEFAULT_CURSOR_START : 0, | |
747 | width); | |
748 | } | |
749 | else if (CONSP (bar_parms) | |
750 | && INTEGERP (XCAR (bar_parms)) | |
751 | && INTEGERP (XCDR (bar_parms))) | |
752 | { | |
753 | int start_line = XINT (XCDR (bar_parms)); | |
754 | ||
755 | width = XINT (XCAR (bar_parms)); | |
756 | msdos_set_cursor_shape (f, start_line, width); | |
757 | } | |
758 | } | |
759 | else | |
b106731c EZ |
760 | { |
761 | /* Treat anything unknown as "box cursor". This includes nil, so | |
762 | that a frame which doesn't specify a cursor type gets a box, | |
763 | which is the default in Emacs. */ | |
764 | msdos_set_cursor_shape (f, 0, BOX_CURSOR_WIDTH); | |
765 | } | |
8ba01a32 EZ |
766 | } |
767 | ||
71f65669 | 768 | static void |
3e1944a3 | 769 | IT_ring_bell (struct frame *f) |
f32d4091 KS |
770 | { |
771 | if (visible_bell) | |
aee81730 | 772 | { |
f32d4091 KS |
773 | mouse_off (); |
774 | ScreenVisualBell (); | |
aee81730 | 775 | } |
f32d4091 | 776 | else |
3635be47 RS |
777 | { |
778 | union REGS inregs, outregs; | |
779 | inregs.h.ah = 2; | |
780 | inregs.h.dl = 7; | |
781 | intdos (&inregs, &outregs); | |
782 | } | |
09e2ac30 RS |
783 | } |
784 | ||
c77f6f1b EZ |
785 | /* Given a face id FACE, extract the face parameters to be used for |
786 | display until the face changes. The face parameters (actually, its | |
787 | color) are used to construct the video attribute byte for each | |
788 | glyph during the construction of the buffer that is then blitted to | |
789 | the video RAM. */ | |
f32d4091 KS |
790 | static void |
791 | IT_set_face (int face) | |
792 | { | |
2d764c78 | 793 | struct frame *sf = SELECTED_FRAME(); |
546701f5 EZ |
794 | struct face *fp = FACE_FROM_ID (sf, face); |
795 | struct face *dfp = FACE_FROM_ID (sf, DEFAULT_FACE_ID); | |
796 | unsigned long fg, bg, dflt_fg, dflt_bg; | |
3e1944a3 | 797 | struct tty_display_info *tty = FRAME_TTY (sf); |
f32d4091 | 798 | |
c77f6f1b | 799 | if (!fp) |
e30aee93 | 800 | { |
546701f5 | 801 | fp = dfp; |
e30aee93 EZ |
802 | /* The default face for the frame should always be realized and |
803 | cached. */ | |
804 | if (!fp) | |
805 | abort (); | |
806 | } | |
f32d4091 | 807 | screen_face = face; |
c77f6f1b EZ |
808 | fg = fp->foreground; |
809 | bg = fp->background; | |
546701f5 EZ |
810 | dflt_fg = dfp->foreground; |
811 | dflt_bg = dfp->background; | |
c77f6f1b | 812 | |
abcce93a MB |
813 | /* Don't use invalid colors. In particular, FACE_TTY_DEFAULT_* colors |
814 | mean use the colors of the default face. Note that we assume all | |
815 | 16 colors to be available for the background, since Emacs switches | |
816 | on this mode (and loses the blinking attribute) at startup. */ | |
f9d2fdc4 | 817 | if (fg == FACE_TTY_DEFAULT_COLOR || fg == FACE_TTY_DEFAULT_FG_COLOR) |
3b620731 | 818 | fg = FRAME_FOREGROUND_PIXEL (sf); |
f9d2fdc4 | 819 | else if (fg == FACE_TTY_DEFAULT_BG_COLOR) |
3b620731 EZ |
820 | fg = FRAME_BACKGROUND_PIXEL (sf); |
821 | if (bg == FACE_TTY_DEFAULT_COLOR || bg == FACE_TTY_DEFAULT_BG_COLOR) | |
822 | bg = FRAME_BACKGROUND_PIXEL (sf); | |
f9d2fdc4 | 823 | else if (bg == FACE_TTY_DEFAULT_FG_COLOR) |
3b620731 EZ |
824 | bg = FRAME_FOREGROUND_PIXEL (sf); |
825 | ||
826 | /* Make sure highlighted lines really stand out, come what may. */ | |
abcce93a | 827 | if (fp->tty_reverse_p && (fg == dflt_fg && bg == dflt_bg)) |
3b620731 EZ |
828 | { |
829 | unsigned long tem = fg; | |
830 | ||
831 | fg = bg; | |
832 | bg = tem; | |
833 | } | |
76648534 EZ |
834 | /* If the user requested inverse video, obey. */ |
835 | if (inverse_video) | |
836 | { | |
837 | unsigned long tem2 = fg; | |
838 | ||
839 | fg = bg; | |
840 | bg = tem2; | |
841 | } | |
3e1944a3 EZ |
842 | if (tty->termscript) |
843 | fprintf (tty->termscript, "<FACE %d: %d/%d[FG:%d/BG:%d]>", face, | |
abcce93a | 844 | fp->foreground, fp->background, fg, bg); |
c77f6f1b EZ |
845 | if (fg >= 0 && fg < 16) |
846 | { | |
847 | ScreenAttrib &= 0xf0; | |
848 | ScreenAttrib |= fg; | |
849 | } | |
850 | if (bg >= 0 && bg < 16) | |
851 | { | |
852 | ScreenAttrib &= 0x0f; | |
853 | ScreenAttrib |= ((bg & 0x0f) << 4); | |
854 | } | |
f32d4091 KS |
855 | } |
856 | ||
aff01dd9 EZ |
857 | /* According to RBIL (INTERRUP.A, V-1000), 160 is the maximum possible |
858 | width of a DOS display in any known text mode. We multiply by 2 to | |
859 | accomodate the screen attribute byte. */ | |
860 | #define MAX_SCREEN_BUF 160*2 | |
861 | ||
aa9ce936 | 862 | Lisp_Object Vdos_unsupported_char_glyph; |
3e1944a3 EZ |
863 | extern unsigned char *encode_terminal_code (struct glyph *, int, |
864 | struct coding_system *); | |
71f65669 | 865 | static void |
3e1944a3 | 866 | IT_write_glyphs (struct frame *f, struct glyph *str, int str_len) |
f32d4091 | 867 | { |
aff01dd9 | 868 | unsigned char screen_buf[MAX_SCREEN_BUF], *screen_bp, *bp; |
039274cf | 869 | int offset = 2 * (new_pos_X + screen_size_X * new_pos_Y); |
aa9ce936 | 870 | register int sl = str_len; |
3e1944a3 | 871 | struct tty_display_info *tty = FRAME_TTY (f); |
2d764c78 | 872 | struct frame *sf; |
3e1944a3 | 873 | unsigned char *conversion_buffer; |
87485d6f | 874 | |
52d38ab2 EZ |
875 | /* Do we need to consider conversion of unibyte characters to |
876 | multibyte? */ | |
877 | int convert_unibyte_characters | |
e16bf494 AI |
878 | = (NILP (current_buffer->enable_multibyte_characters) |
879 | && unibyte_display_via_language_environment); | |
52d38ab2 | 880 | |
3e1944a3 EZ |
881 | /* If terminal_coding does any conversion, use it, otherwise use |
882 | safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here | |
883 | because it always returns 1 if terminal_coding.src_multibyte is 1. */ | |
884 | struct coding_system *coding = FRAME_TERMINAL_CODING (f); | |
885 | ||
886 | if (!(coding->common_flags & CODING_REQUIRE_ENCODING_MASK)) | |
887 | coding = &safe_terminal_coding; | |
648648a9 | 888 | |
3b620731 | 889 | if (str_len <= 0) return; |
56e19ec4 | 890 | |
2d764c78 | 891 | sf = SELECTED_FRAME(); |
e30aee93 EZ |
892 | |
893 | /* Since faces get cached and uncached behind our back, we can't | |
894 | rely on their indices in the cache being consistent across | |
895 | invocations. So always reset the screen face to the default | |
896 | face of the frame, before writing glyphs, and let the glyphs | |
897 | set the right face if it's different from the default. */ | |
898 | IT_set_face (DEFAULT_FACE_ID); | |
56e19ec4 | 899 | |
aa9ce936 EZ |
900 | /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at |
901 | the tail. */ | |
3e1944a3 | 902 | coding->mode &= ~CODING_MODE_LAST_BLOCK; |
aff01dd9 | 903 | screen_bp = &screen_buf[0]; |
3e1944a3 | 904 | while (sl > 0) |
aa9ce936 | 905 | { |
3e1944a3 | 906 | int cf; |
aff01dd9 | 907 | int n; |
aa9ce936 | 908 | |
aff01dd9 EZ |
909 | /* If the face of this glyph is different from the current |
910 | screen face, update the screen attribute byte. */ | |
911 | cf = str->face_id; | |
912 | if (cf != screen_face) | |
913 | IT_set_face (cf); /* handles invalid faces gracefully */ | |
914 | ||
915 | /* Identify a run of glyphs with the same face. */ | |
916 | for (n = 1; n < sl; ++n) | |
917 | if (str[n].face_id != cf) | |
918 | break; | |
919 | ||
920 | if (n >= sl) | |
921 | /* This is the last glyph. */ | |
922 | coding->mode |= CODING_MODE_LAST_BLOCK; | |
923 | ||
924 | conversion_buffer = encode_terminal_code (str, n, coding); | |
925 | if (coding->produced > 0) | |
aa9ce936 | 926 | { |
aff01dd9 EZ |
927 | /* Copy the encoded bytes to the screen buffer. */ |
928 | for (bp = conversion_buffer; coding->produced--; bp++) | |
aa9ce936 | 929 | { |
aff01dd9 EZ |
930 | /* Paranoia: discard bytes that would overrun the end of |
931 | the screen buffer. */ | |
932 | if (screen_bp - screen_buf <= MAX_SCREEN_BUF - 2) | |
aa9ce936 | 933 | { |
aff01dd9 EZ |
934 | *screen_bp++ = (unsigned char)*bp; |
935 | *screen_bp++ = ScreenAttrib; | |
aa9ce936 | 936 | } |
aff01dd9 EZ |
937 | if (tty->termscript) |
938 | fputc (*bp, tty->termscript); | |
aa9ce936 EZ |
939 | } |
940 | } | |
aff01dd9 EZ |
941 | /* Update STR and its remaining length. */ |
942 | str += n; | |
943 | sl -= n; | |
aee81730 RS |
944 | } |
945 | ||
aff01dd9 | 946 | /* Dump whatever we have in the screen buffer. */ |
f32d4091 | 947 | mouse_off_maybe (); |
aa9ce936 | 948 | dosmemput (screen_buf, screen_bp - screen_buf, (int)ScreenPrimary + offset); |
039274cf | 949 | if (screen_virtual_segment) |
aa9ce936 EZ |
950 | dosv_refresh_virtual_screen (offset, (screen_bp - screen_buf) / 2); |
951 | new_pos_X += (screen_bp - screen_buf) / 2; | |
f32d4091 | 952 | } |
aee81730 | 953 | |
41ad069b EZ |
954 | /************************************************************************ |
955 | Mouse Highlight (and friends..) | |
956 | ************************************************************************/ | |
957 | ||
ee8ceff8 | 958 | /* Last window where we saw the mouse. Used by mouse-autoselect-window. */ |
9005a471 EZ |
959 | static Lisp_Object last_mouse_window; |
960 | ||
41ad069b EZ |
961 | static int mouse_preempted = 0; /* non-zero when XMenu gobbles mouse events */ |
962 | ||
963 | /* Set the mouse pointer shape according to whether it is in the | |
964 | area where the mouse highlight is in effect. */ | |
965 | static void | |
966 | IT_set_mouse_pointer (int mode) | |
967 | { | |
968 | /* A no-op for now. DOS text-mode mouse pointer doesn't offer too | |
969 | many possibilities to change its shape, and the available | |
970 | functionality pretty much sucks (e.g., almost every reasonable | |
971 | shape will conceal the character it is on). Since the color of | |
972 | the pointer changes in the highlighted area, it is not clear to | |
973 | me whether anything else is required, anyway. */ | |
974 | } | |
975 | ||
976 | /* Display the active region described by mouse_face_* | |
977 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
978 | static void | |
3e1944a3 | 979 | show_mouse_face (struct tty_display_info *dpyinfo, int hl) |
41ad069b EZ |
980 | { |
981 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); | |
982 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
983 | int i; | |
984 | struct face *fp; | |
3e1944a3 | 985 | struct tty_display_info *tty = FRAME_TTY (f); |
41ad069b | 986 | |
56e19ec4 | 987 | |
41ad069b EZ |
988 | /* If window is in the process of being destroyed, don't bother |
989 | doing anything. */ | |
990 | if (w->current_matrix == NULL) | |
991 | goto set_cursor_shape; | |
992 | ||
993 | /* Recognize when we are called to operate on rows that don't exist | |
994 | anymore. This can happen when a window is split. */ | |
995 | if (dpyinfo->mouse_face_end_row >= w->current_matrix->nrows) | |
996 | goto set_cursor_shape; | |
997 | ||
998 | /* There's no sense to do anything if the mouse face isn't realized. */ | |
999 | if (hl > 0) | |
1000 | { | |
abf10ed7 KS |
1001 | if (dpyinfo->mouse_face_hidden) |
1002 | goto set_cursor_shape; | |
1003 | ||
41ad069b EZ |
1004 | fp = FACE_FROM_ID (SELECTED_FRAME(), dpyinfo->mouse_face_face_id); |
1005 | if (!fp) | |
1006 | goto set_cursor_shape; | |
1007 | } | |
1008 | ||
1009 | /* Note that mouse_face_beg_row etc. are window relative. */ | |
1010 | for (i = dpyinfo->mouse_face_beg_row; | |
1011 | i <= dpyinfo->mouse_face_end_row; | |
1012 | i++) | |
1013 | { | |
1014 | int start_hpos, end_hpos; | |
1015 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, i); | |
1016 | ||
1017 | /* Don't do anything if row doesn't have valid contents. */ | |
1018 | if (!row->enabled_p) | |
1019 | continue; | |
1020 | ||
1021 | /* For all but the first row, the highlight starts at column 0. */ | |
1022 | if (i == dpyinfo->mouse_face_beg_row) | |
1023 | start_hpos = dpyinfo->mouse_face_beg_col; | |
1024 | else | |
1025 | start_hpos = 0; | |
1026 | ||
1027 | if (i == dpyinfo->mouse_face_end_row) | |
1028 | end_hpos = dpyinfo->mouse_face_end_col; | |
1029 | else | |
1030 | end_hpos = row->used[TEXT_AREA]; | |
1031 | ||
1032 | if (end_hpos <= start_hpos) | |
1033 | continue; | |
48c14970 EZ |
1034 | /* Record that some glyphs of this row are displayed in |
1035 | mouse-face. */ | |
1036 | row->mouse_face_p = hl > 0; | |
41ad069b EZ |
1037 | if (hl > 0) |
1038 | { | |
c655f6fd KS |
1039 | int vpos = row->y + WINDOW_TOP_EDGE_Y (w); |
1040 | int kstart = start_hpos + WINDOW_LEFT_EDGE_X (w); | |
41ad069b EZ |
1041 | int nglyphs = end_hpos - start_hpos; |
1042 | int offset = ScreenPrimary + 2*(vpos*screen_size_X + kstart) + 1; | |
1043 | int start_offset = offset; | |
1044 | ||
3e1944a3 EZ |
1045 | if (tty->termscript) |
1046 | fprintf (tty->termscript, "\n<MH+ %d-%d:%d>", | |
41ad069b EZ |
1047 | kstart, kstart + nglyphs - 1, vpos); |
1048 | ||
1049 | mouse_off (); | |
1050 | IT_set_face (dpyinfo->mouse_face_face_id); | |
1051 | /* Since we are going to change only the _colors_ of the | |
1052 | displayed text, there's no need to go through all the | |
1053 | pain of generating and encoding the text from the glyphs. | |
1054 | Instead, we simply poke the attribute byte of each | |
1055 | affected position in video memory with the colors | |
1056 | computed by IT_set_face! */ | |
1057 | _farsetsel (_dos_ds); | |
1058 | while (nglyphs--) | |
1059 | { | |
1060 | _farnspokeb (offset, ScreenAttrib); | |
1061 | offset += 2; | |
1062 | } | |
1063 | if (screen_virtual_segment) | |
1064 | dosv_refresh_virtual_screen (start_offset, end_hpos - start_hpos); | |
1065 | mouse_on (); | |
1066 | } | |
1067 | else | |
1068 | { | |
1069 | /* We are removing a previously-drawn mouse highlight. The | |
1070 | safest way to do so is to redraw the glyphs anew, since | |
1071 | all kinds of faces and display tables could have changed | |
1072 | behind our back. */ | |
1073 | int nglyphs = end_hpos - start_hpos; | |
1074 | int save_x = new_pos_X, save_y = new_pos_Y; | |
1075 | ||
1076 | if (end_hpos >= row->used[TEXT_AREA]) | |
1077 | nglyphs = row->used[TEXT_AREA] - start_hpos; | |
1078 | ||
1079 | /* IT_write_glyphs writes at cursor position, so we need to | |
1080 | temporarily move cursor coordinates to the beginning of | |
1081 | the highlight region. */ | |
c655f6fd KS |
1082 | new_pos_X = start_hpos + WINDOW_LEFT_EDGE_X (w); |
1083 | new_pos_Y = row->y + WINDOW_TOP_EDGE_Y (w); | |
41ad069b | 1084 | |
3e1944a3 EZ |
1085 | if (tty->termscript) |
1086 | fprintf (tty->termscript, "<MH- %d-%d:%d>", | |
41ad069b | 1087 | new_pos_X, new_pos_X + nglyphs - 1, new_pos_Y); |
3e1944a3 EZ |
1088 | IT_write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs); |
1089 | if (tty->termscript) | |
1090 | fputs ("\n", tty->termscript); | |
41ad069b EZ |
1091 | new_pos_X = save_x; |
1092 | new_pos_Y = save_y; | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | set_cursor_shape: | |
41ad069b EZ |
1097 | /* Change the mouse pointer shape. */ |
1098 | IT_set_mouse_pointer (hl); | |
1099 | } | |
1100 | ||
1101 | /* Clear out the mouse-highlighted active region. | |
1102 | Redraw it un-highlighted first. */ | |
1103 | static void | |
3e1944a3 | 1104 | clear_mouse_face (struct tty_display_info *dpyinfo) |
41ad069b | 1105 | { |
6b61353c | 1106 | if (!dpyinfo->mouse_face_hidden && ! NILP (dpyinfo->mouse_face_window)) |
41ad069b EZ |
1107 | show_mouse_face (dpyinfo, 0); |
1108 | ||
1109 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
1110 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
1111 | dpyinfo->mouse_face_window = Qnil; | |
1112 | } | |
1113 | ||
1114 | /* Find the glyph matrix position of buffer position POS in window W. | |
1115 | *HPOS and *VPOS are set to the positions found. W's current glyphs | |
1116 | must be up to date. If POS is above window start return (0, 0). | |
1117 | If POS is after end of W, return end of last line in W. */ | |
1118 | static int | |
1119 | fast_find_position (struct window *w, int pos, int *hpos, int *vpos) | |
1120 | { | |
56e19ec4 | 1121 | int i, lastcol, line_start_position, maybe_next_line_p = 0; |
41ad069b | 1122 | int yb = window_text_bottom_y (w); |
56e19ec4 | 1123 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, 0), *best_row = row; |
41ad069b EZ |
1124 | |
1125 | while (row->y < yb) | |
1126 | { | |
1127 | if (row->used[TEXT_AREA]) | |
1128 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
1129 | else | |
1130 | line_start_position = 0; | |
1131 | ||
1132 | if (line_start_position > pos) | |
1133 | break; | |
1134 | /* If the position sought is the end of the buffer, | |
1135 | don't include the blank lines at the bottom of the window. */ | |
1136 | else if (line_start_position == pos | |
1137 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
1138 | { | |
1139 | maybe_next_line_p = 1; | |
1140 | break; | |
1141 | } | |
1142 | else if (line_start_position > 0) | |
1143 | best_row = row; | |
440ffd67 EZ |
1144 | |
1145 | /* Don't overstep the last matrix row, lest we get into the | |
1146 | never-never land... */ | |
1147 | if (row->y + 1 >= yb) | |
1148 | break; | |
56e19ec4 | 1149 | |
41ad069b EZ |
1150 | ++row; |
1151 | } | |
56e19ec4 | 1152 | |
41ad069b EZ |
1153 | /* Find the right column within BEST_ROW. */ |
1154 | lastcol = 0; | |
1155 | row = best_row; | |
1156 | for (i = 0; i < row->used[TEXT_AREA]; i++) | |
1157 | { | |
1158 | struct glyph *glyph = row->glyphs[TEXT_AREA] + i; | |
1159 | int charpos; | |
1160 | ||
1161 | charpos = glyph->charpos; | |
1162 | if (charpos == pos) | |
1163 | { | |
1164 | *hpos = i; | |
1165 | *vpos = row->y; | |
1166 | return 1; | |
1167 | } | |
1168 | else if (charpos > pos) | |
1169 | break; | |
1170 | else if (charpos > 0) | |
1171 | lastcol = i; | |
1172 | } | |
1173 | ||
1174 | /* If we're looking for the end of the buffer, | |
1175 | and we didn't find it in the line we scanned, | |
1176 | use the start of the following line. */ | |
1177 | if (maybe_next_line_p) | |
1178 | { | |
1179 | ++row; | |
1180 | lastcol = 0; | |
1181 | } | |
1182 | ||
1183 | *vpos = row->y; | |
1184 | *hpos = lastcol + 1; | |
1185 | return 0; | |
1186 | } | |
1187 | ||
1188 | /* Take proper action when mouse has moved to the mode or top line of | |
1189 | window W, x-position X. MODE_LINE_P non-zero means mouse is on the | |
1190 | mode line. X is relative to the start of the text display area of | |
377df9e2 | 1191 | W, so the width of fringes and scroll bars must be subtracted |
41ad069b EZ |
1192 | to get a position relative to the start of the mode line. */ |
1193 | static void | |
1194 | IT_note_mode_line_highlight (struct window *w, int x, int mode_line_p) | |
1195 | { | |
1196 | struct frame *f = XFRAME (w->frame); | |
3e1944a3 | 1197 | struct tty_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
41ad069b EZ |
1198 | struct glyph_row *row; |
1199 | ||
1200 | if (mode_line_p) | |
1201 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); | |
1202 | else | |
1203 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); | |
56e19ec4 | 1204 | |
41ad069b EZ |
1205 | if (row->enabled_p) |
1206 | { | |
1207 | extern Lisp_Object Qhelp_echo; | |
1208 | struct glyph *glyph, *end; | |
1209 | Lisp_Object help, map; | |
56e19ec4 | 1210 | |
41ad069b | 1211 | /* Find the glyph under X. */ |
c655f6fd KS |
1212 | glyph = (row->glyphs[TEXT_AREA] |
1213 | + x | |
6b61353c | 1214 | /* in case someone implements scroll bars some day... */ |
c655f6fd | 1215 | - WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w)); |
41ad069b EZ |
1216 | end = glyph + row->used[TEXT_AREA]; |
1217 | if (glyph < end | |
1218 | && STRINGP (glyph->object) | |
d5db4077 | 1219 | && STRING_INTERVALS (glyph->object) |
41ad069b | 1220 | && glyph->charpos >= 0 |
d5db4077 | 1221 | && glyph->charpos < SCHARS (glyph->object)) |
41ad069b EZ |
1222 | { |
1223 | /* If we're on a string with `help-echo' text property, | |
1224 | arrange for the help to be displayed. This is done by | |
1225 | setting the global variable help_echo to the help string. */ | |
1226 | help = Fget_text_property (make_number (glyph->charpos), | |
1227 | Qhelp_echo, glyph->object); | |
b7e80413 | 1228 | if (!NILP (help)) |
48c14970 | 1229 | { |
02d4b97d | 1230 | help_echo_string = help; |
48c14970 EZ |
1231 | XSETWINDOW (help_echo_window, w); |
1232 | help_echo_object = glyph->object; | |
1233 | help_echo_pos = glyph->charpos; | |
1234 | } | |
41ad069b EZ |
1235 | } |
1236 | } | |
1237 | } | |
1238 | ||
1239 | /* Take proper action when the mouse has moved to position X, Y on | |
1240 | frame F as regards highlighting characters that have mouse-face | |
1241 | properties. Also de-highlighting chars where the mouse was before. | |
1242 | X and Y can be negative or out of range. */ | |
1243 | static void | |
1244 | IT_note_mouse_highlight (struct frame *f, int x, int y) | |
1245 | { | |
3e1944a3 | 1246 | struct tty_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
02d4b97d | 1247 | enum window_part part = ON_NOTHING; |
41ad069b EZ |
1248 | Lisp_Object window; |
1249 | struct window *w; | |
1250 | ||
1251 | /* When a menu is active, don't highlight because this looks odd. */ | |
1252 | if (mouse_preempted) | |
1253 | return; | |
1254 | ||
abf10ed7 | 1255 | if (NILP (Vmouse_highlight) |
515d0d0e | 1256 | || !f->glyphs_initialized_p) |
41ad069b EZ |
1257 | return; |
1258 | ||
1259 | dpyinfo->mouse_face_mouse_x = x; | |
1260 | dpyinfo->mouse_face_mouse_y = y; | |
1261 | dpyinfo->mouse_face_mouse_frame = f; | |
1262 | ||
1263 | if (dpyinfo->mouse_face_defer) | |
1264 | return; | |
1265 | ||
1266 | if (gc_in_progress) | |
1267 | { | |
1268 | dpyinfo->mouse_face_deferred_gc = 1; | |
1269 | return; | |
1270 | } | |
1271 | ||
1272 | /* Which window is that in? */ | |
c655f6fd | 1273 | window = window_from_coordinates (f, x, y, &part, &x, &y, 0); |
41ad069b EZ |
1274 | |
1275 | /* If we were displaying active text in another window, clear that. */ | |
1276 | if (! EQ (window, dpyinfo->mouse_face_window)) | |
1277 | clear_mouse_face (dpyinfo); | |
1278 | ||
1279 | /* Not on a window -> return. */ | |
1280 | if (!WINDOWP (window)) | |
1281 | return; | |
1282 | ||
1283 | /* Convert to window-relative coordinates. */ | |
1284 | w = XWINDOW (window); | |
41ad069b | 1285 | |
02d4b97d | 1286 | if (part == ON_MODE_LINE || part == ON_HEADER_LINE) |
41ad069b EZ |
1287 | { |
1288 | /* Mouse is on the mode or top line. */ | |
02d4b97d | 1289 | IT_note_mode_line_highlight (w, x, part == ON_MODE_LINE); |
41ad069b EZ |
1290 | return; |
1291 | } | |
c655f6fd KS |
1292 | |
1293 | IT_set_mouse_pointer (0); | |
41ad069b EZ |
1294 | |
1295 | /* Are we in a window whose display is up to date? | |
1296 | And verify the buffer's text has not changed. */ | |
02d4b97d | 1297 | if (part == ON_TEXT |
41ad069b EZ |
1298 | && EQ (w->window_end_valid, w->buffer) |
1299 | && XFASTINT (w->last_modified) == BUF_MODIFF (XBUFFER (w->buffer)) | |
1300 | && (XFASTINT (w->last_overlay_modified) | |
1301 | == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)))) | |
1302 | { | |
56e19ec4 | 1303 | int pos, i, nrows = w->current_matrix->nrows; |
41ad069b EZ |
1304 | struct glyph_row *row; |
1305 | struct glyph *glyph; | |
1306 | ||
1307 | /* Find the glyph under X/Y. */ | |
1308 | glyph = NULL; | |
440ffd67 | 1309 | if (y >= 0 && y < nrows) |
41ad069b EZ |
1310 | { |
1311 | row = MATRIX_ROW (w->current_matrix, y); | |
440ffd67 EZ |
1312 | /* Give up if some row before the one we are looking for is |
1313 | not enabled. */ | |
1314 | for (i = 0; i <= y; i++) | |
1315 | if (!MATRIX_ROW (w->current_matrix, i)->enabled_p) | |
1316 | break; | |
1317 | if (i > y /* all rows upto and including the one at Y are enabled */ | |
41ad069b EZ |
1318 | && row->displays_text_p |
1319 | && x < window_box_width (w, TEXT_AREA)) | |
1320 | { | |
1321 | glyph = row->glyphs[TEXT_AREA]; | |
1322 | if (x >= row->used[TEXT_AREA]) | |
1323 | glyph = NULL; | |
1324 | else | |
1325 | { | |
1326 | glyph += x; | |
1327 | if (!BUFFERP (glyph->object)) | |
1328 | glyph = NULL; | |
1329 | } | |
1330 | } | |
1331 | } | |
1332 | ||
1333 | /* Clear mouse face if X/Y not over text. */ | |
1334 | if (glyph == NULL) | |
1335 | { | |
1336 | clear_mouse_face (dpyinfo); | |
1337 | return; | |
1338 | } | |
1339 | ||
1340 | if (!BUFFERP (glyph->object)) | |
1341 | abort (); | |
1342 | pos = glyph->charpos; | |
1343 | ||
1344 | /* Check for mouse-face and help-echo. */ | |
1345 | { | |
1346 | extern Lisp_Object Qmouse_face; | |
56e19ec4 | 1347 | Lisp_Object mouse_face, overlay, position, *overlay_vec; |
3b8c0c70 | 1348 | int noverlays, obegv, ozv; |
41ad069b | 1349 | struct buffer *obuf; |
41ad069b EZ |
1350 | |
1351 | /* If we get an out-of-range value, return now; avoid an error. */ | |
1352 | if (pos > BUF_Z (XBUFFER (w->buffer))) | |
1353 | return; | |
1354 | ||
1355 | /* Make the window's buffer temporarily current for | |
1356 | overlays_at and compute_char_face. */ | |
1357 | obuf = current_buffer; | |
1358 | current_buffer = XBUFFER (w->buffer); | |
1359 | obegv = BEGV; | |
1360 | ozv = ZV; | |
1361 | BEGV = BEG; | |
1362 | ZV = Z; | |
1363 | ||
1364 | /* Is this char mouse-active or does it have help-echo? */ | |
1365 | XSETINT (position, pos); | |
1366 | ||
1a8da670 KS |
1367 | /* Put all the overlays we want in a vector in overlay_vec. */ |
1368 | GET_OVERLAYS_AT (pos, overlay_vec, noverlays, NULL, 0); | |
f0a4139c | 1369 | /* Sort overlays into increasing priority order. */ |
41ad069b EZ |
1370 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
1371 | ||
1372 | /* Check mouse-face highlighting. */ | |
1373 | if (! (EQ (window, dpyinfo->mouse_face_window) | |
1374 | && y >= dpyinfo->mouse_face_beg_row | |
1375 | && y <= dpyinfo->mouse_face_end_row | |
1376 | && (y > dpyinfo->mouse_face_beg_row | |
1377 | || x >= dpyinfo->mouse_face_beg_col) | |
1378 | && (y < dpyinfo->mouse_face_end_row | |
1379 | || x < dpyinfo->mouse_face_end_col | |
1380 | || dpyinfo->mouse_face_past_end))) | |
1381 | { | |
1382 | /* Clear the display of the old active region, if any. */ | |
1383 | clear_mouse_face (dpyinfo); | |
1384 | ||
1385 | /* Find highest priority overlay that has a mouse-face prop. */ | |
1386 | overlay = Qnil; | |
f0a4139c | 1387 | for (i = noverlays - 1; i >= 0; --i) |
41ad069b EZ |
1388 | { |
1389 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
1390 | if (!NILP (mouse_face)) | |
1391 | { | |
1392 | overlay = overlay_vec[i]; | |
1393 | break; | |
1394 | } | |
1395 | } | |
1396 | ||
1397 | /* If no overlay applies, get a text property. */ | |
1398 | if (NILP (overlay)) | |
1399 | mouse_face = Fget_text_property (position, Qmouse_face, | |
1400 | w->buffer); | |
1401 | ||
1402 | /* Handle the overlay case. */ | |
1403 | if (! NILP (overlay)) | |
1404 | { | |
1405 | /* Find the range of text around this char that | |
1406 | should be active. */ | |
1407 | Lisp_Object before, after; | |
0f8b27ea | 1408 | EMACS_INT ignore; |
41ad069b EZ |
1409 | |
1410 | before = Foverlay_start (overlay); | |
1411 | after = Foverlay_end (overlay); | |
1412 | /* Record this as the current active region. */ | |
1413 | fast_find_position (w, XFASTINT (before), | |
1414 | &dpyinfo->mouse_face_beg_col, | |
1415 | &dpyinfo->mouse_face_beg_row); | |
1416 | dpyinfo->mouse_face_past_end | |
1417 | = !fast_find_position (w, XFASTINT (after), | |
1418 | &dpyinfo->mouse_face_end_col, | |
1419 | &dpyinfo->mouse_face_end_row); | |
1420 | dpyinfo->mouse_face_window = window; | |
1421 | dpyinfo->mouse_face_face_id | |
1422 | = face_at_buffer_position (w, pos, 0, 0, | |
0d6239f1 | 1423 | &ignore, pos + 1, |
6970f632 CY |
1424 | !dpyinfo->mouse_face_hidden, |
1425 | -1); | |
41ad069b EZ |
1426 | |
1427 | /* Display it as active. */ | |
1428 | show_mouse_face (dpyinfo, 1); | |
1429 | } | |
1430 | /* Handle the text property case. */ | |
1431 | else if (! NILP (mouse_face)) | |
1432 | { | |
1433 | /* Find the range of text around this char that | |
1434 | should be active. */ | |
1435 | Lisp_Object before, after, beginning, end; | |
0f8b27ea | 1436 | EMACS_INT ignore; |
41ad069b EZ |
1437 | |
1438 | beginning = Fmarker_position (w->start); | |
1439 | XSETINT (end, (BUF_Z (XBUFFER (w->buffer)) | |
1440 | - XFASTINT (w->window_end_pos))); | |
1441 | before | |
1442 | = Fprevious_single_property_change (make_number (pos + 1), | |
1443 | Qmouse_face, | |
1444 | w->buffer, beginning); | |
1445 | after | |
1446 | = Fnext_single_property_change (position, Qmouse_face, | |
1447 | w->buffer, end); | |
1448 | /* Record this as the current active region. */ | |
1449 | fast_find_position (w, XFASTINT (before), | |
1450 | &dpyinfo->mouse_face_beg_col, | |
1451 | &dpyinfo->mouse_face_beg_row); | |
1452 | dpyinfo->mouse_face_past_end | |
1453 | = !fast_find_position (w, XFASTINT (after), | |
1454 | &dpyinfo->mouse_face_end_col, | |
1455 | &dpyinfo->mouse_face_end_row); | |
1456 | dpyinfo->mouse_face_window = window; | |
1457 | dpyinfo->mouse_face_face_id | |
1458 | = face_at_buffer_position (w, pos, 0, 0, | |
0d6239f1 | 1459 | &ignore, pos + 1, |
6970f632 CY |
1460 | !dpyinfo->mouse_face_hidden, |
1461 | -1); | |
41ad069b EZ |
1462 | |
1463 | /* Display it as active. */ | |
1464 | show_mouse_face (dpyinfo, 1); | |
1465 | } | |
1466 | } | |
1467 | ||
1468 | /* Look for a `help-echo' property. */ | |
1469 | { | |
1470 | Lisp_Object help; | |
1471 | extern Lisp_Object Qhelp_echo; | |
1472 | ||
1473 | /* Check overlays first. */ | |
1474 | help = Qnil; | |
f0a4139c EZ |
1475 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) |
1476 | { | |
1477 | overlay = overlay_vec[i]; | |
1478 | help = Foverlay_get (overlay, Qhelp_echo); | |
1479 | } | |
56e19ec4 | 1480 | |
b7e80413 | 1481 | if (!NILP (help)) |
48c14970 | 1482 | { |
02d4b97d | 1483 | help_echo_string = help; |
48c14970 | 1484 | help_echo_window = window; |
f0a4139c | 1485 | help_echo_object = overlay; |
48c14970 EZ |
1486 | help_echo_pos = pos; |
1487 | } | |
1488 | /* Try text properties. */ | |
1489 | else if (NILP (help) | |
1490 | && ((STRINGP (glyph->object) | |
1491 | && glyph->charpos >= 0 | |
d5db4077 | 1492 | && glyph->charpos < SCHARS (glyph->object)) |
48c14970 EZ |
1493 | || (BUFFERP (glyph->object) |
1494 | && glyph->charpos >= BEGV | |
1495 | && glyph->charpos < ZV))) | |
1496 | { | |
1497 | help = Fget_text_property (make_number (glyph->charpos), | |
1498 | Qhelp_echo, glyph->object); | |
1499 | if (!NILP (help)) | |
1500 | { | |
02d4b97d | 1501 | help_echo_string = help; |
48c14970 EZ |
1502 | help_echo_window = window; |
1503 | help_echo_object = glyph->object; | |
1504 | help_echo_pos = glyph->charpos; | |
1505 | } | |
1506 | } | |
41ad069b | 1507 | } |
56e19ec4 | 1508 | |
41ad069b EZ |
1509 | BEGV = obegv; |
1510 | ZV = ozv; | |
1511 | current_buffer = obuf; | |
1512 | } | |
1513 | } | |
1514 | } | |
1515 | ||
71f65669 | 1516 | static void |
3e1944a3 | 1517 | IT_clear_end_of_line (struct frame *f, int first_unused) |
f32d4091 KS |
1518 | { |
1519 | char *spaces, *sp; | |
56e19ec4 | 1520 | int i, j, offset = 2 * (new_pos_X + screen_size_X * new_pos_Y); |
aa9ce936 | 1521 | extern int fatal_error_in_progress; |
3e1944a3 | 1522 | struct tty_display_info *tty = FRAME_TTY (f); |
aa9ce936 | 1523 | |
2d764c78 | 1524 | if (new_pos_X >= first_unused || fatal_error_in_progress) |
aa9ce936 | 1525 | return; |
f32d4091 KS |
1526 | |
1527 | IT_set_face (0); | |
2d764c78 | 1528 | i = (j = first_unused - new_pos_X) * 2; |
3e1944a3 EZ |
1529 | if (tty->termscript) |
1530 | fprintf (tty->termscript, "<CLR:EOL[%d..%d)>", new_pos_X, first_unused); | |
f32d4091 | 1531 | spaces = sp = alloca (i); |
56e19ec4 | 1532 | |
f32d4091 | 1533 | while (--j >= 0) |
aee81730 | 1534 | { |
f32d4091 KS |
1535 | *sp++ = ' '; |
1536 | *sp++ = ScreenAttrib; | |
aee81730 RS |
1537 | } |
1538 | ||
f32d4091 | 1539 | mouse_off_maybe (); |
039274cf EZ |
1540 | dosmemput (spaces, i, (int)ScreenPrimary + offset); |
1541 | if (screen_virtual_segment) | |
1542 | dosv_refresh_virtual_screen (offset, i / 2); | |
2d764c78 EZ |
1543 | |
1544 | /* clear_end_of_line_raw on term.c leaves the cursor at first_unused. | |
1545 | Let's follow their lead, in case someone relies on this. */ | |
1546 | new_pos_X = first_unused; | |
aee81730 RS |
1547 | } |
1548 | ||
71f65669 | 1549 | static void |
3e1944a3 | 1550 | IT_clear_screen (struct frame *f) |
f32d4091 | 1551 | { |
3e1944a3 EZ |
1552 | struct tty_display_info *tty = FRAME_TTY (f); |
1553 | ||
1554 | if (tty->termscript) | |
1555 | fprintf (tty->termscript, "<CLR:SCR>"); | |
deece6f5 EZ |
1556 | /* We are sometimes called (from clear_garbaged_frames) when a new |
1557 | frame is being created, but its faces are not yet realized. In | |
1558 | such a case we cannot call IT_set_face, since it will fail to find | |
1559 | any valid faces and will abort. Instead, use the initial screen | |
1560 | colors; that should mimic what a Unix tty does, which simply clears | |
1561 | the screen with whatever default colors are in use. */ | |
1562 | if (FACE_FROM_ID (SELECTED_FRAME (), DEFAULT_FACE_ID) == NULL) | |
1563 | ScreenAttrib = (initial_screen_colors[0] << 4) | initial_screen_colors[1]; | |
1564 | else | |
1565 | IT_set_face (0); | |
f32d4091 KS |
1566 | mouse_off (); |
1567 | ScreenClear (); | |
039274cf EZ |
1568 | if (screen_virtual_segment) |
1569 | dosv_refresh_virtual_screen (0, screen_size); | |
f32d4091 KS |
1570 | new_pos_X = new_pos_Y = 0; |
1571 | } | |
1572 | ||
71f65669 | 1573 | static void |
3e1944a3 | 1574 | IT_clear_to_end (struct frame *f) |
f32d4091 | 1575 | { |
3e1944a3 EZ |
1576 | struct tty_display_info *tty = FRAME_TTY (f); |
1577 | ||
1578 | if (tty->termscript) | |
1579 | fprintf (tty->termscript, "<CLR:EOS>"); | |
f32d4091 KS |
1580 | |
1581 | while (new_pos_Y < screen_size_Y) { | |
1582 | new_pos_X = 0; | |
3e1944a3 | 1583 | IT_clear_end_of_line (f, screen_size_X); |
f32d4091 KS |
1584 | new_pos_Y++; |
1585 | } | |
1586 | } | |
1587 | ||
71f65669 | 1588 | static void |
3e1944a3 | 1589 | IT_cursor_to (struct frame *f, int y, int x) |
f32d4091 | 1590 | { |
3e1944a3 EZ |
1591 | struct tty_display_info *tty = FRAME_TTY (f); |
1592 | ||
1593 | if (tty->termscript) | |
1594 | fprintf (tty->termscript, "\n<XY=%dx%d>", x, y); | |
f32d4091 KS |
1595 | new_pos_X = x; |
1596 | new_pos_Y = y; | |
1597 | } | |
1598 | ||
fc171623 KH |
1599 | static int cursor_cleared; |
1600 | ||
d1d5dc19 | 1601 | static void |
fc171623 KH |
1602 | IT_display_cursor (int on) |
1603 | { | |
3e1944a3 EZ |
1604 | struct tty_display_info *tty = CURTTY (); |
1605 | ||
fc171623 KH |
1606 | if (on && cursor_cleared) |
1607 | { | |
1608 | ScreenSetCursor (current_pos_Y, current_pos_X); | |
1609 | cursor_cleared = 0; | |
b04021eb EZ |
1610 | if (tty->termscript) |
1611 | fprintf (tty->termscript, "\nCURSOR ON"); | |
fc171623 KH |
1612 | } |
1613 | else if (!on && !cursor_cleared) | |
1614 | { | |
1615 | ScreenSetCursor (-1, -1); | |
1616 | cursor_cleared = 1; | |
b04021eb EZ |
1617 | if (tty->termscript) |
1618 | fprintf (tty->termscript, "\nCURSOR OFF"); | |
fc171623 KH |
1619 | } |
1620 | } | |
1621 | ||
1622 | /* Emacs calls cursor-movement functions a lot when it updates the | |
1623 | display (probably a legacy of old terminals where you cannot | |
1624 | update a screen line without first moving the cursor there). | |
1625 | However, cursor movement is expensive on MSDOS (it calls a slow | |
1626 | BIOS function and requires 2 mode switches), while actual screen | |
1627 | updates access the video memory directly and don't depend on | |
1628 | cursor position. To avoid slowing down the redisplay, we cheat: | |
1629 | all functions that move the cursor only set internal variables | |
1630 | which record the cursor position, whereas the cursor is only | |
1631 | moved to its final position whenever screen update is complete. | |
1632 | ||
1633 | `IT_cmgoto' is called from the keyboard reading loop and when the | |
1634 | frame update is complete. This means that we are ready for user | |
1635 | input, so we update the cursor position to show where the point is, | |
1636 | and also make the mouse pointer visible. | |
1637 | ||
1638 | Special treatment is required when the cursor is in the echo area, | |
1639 | to put the cursor at the end of the text displayed there. */ | |
1640 | ||
71f65669 EZ |
1641 | static void |
1642 | IT_cmgoto (FRAME_PTR f) | |
fc171623 KH |
1643 | { |
1644 | /* Only set the cursor to where it should be if the display is | |
1645 | already in sync with the window contents. */ | |
2d764c78 | 1646 | int update_cursor_pos = 1; /* MODIFF == unchanged_modified; */ |
3e1944a3 | 1647 | struct tty_display_info *tty = FRAME_TTY (f); |
2d764c78 EZ |
1648 | |
1649 | /* FIXME: This needs to be rewritten for the new redisplay, or | |
1650 | removed. */ | |
1651 | #if 0 | |
06da1de1 EZ |
1652 | static int previous_pos_X = -1; |
1653 | ||
2d764c78 EZ |
1654 | update_cursor_pos = 1; /* temporary!!! */ |
1655 | ||
06da1de1 EZ |
1656 | /* If the display is in sync, forget any previous knowledge about |
1657 | cursor position. This is primarily for unexpected events like | |
1658 | C-g in the minibuffer. */ | |
1659 | if (update_cursor_pos && previous_pos_X >= 0) | |
1660 | previous_pos_X = -1; | |
1661 | /* If we are in the echo area, put the cursor at the | |
1662 | end of the echo area message. */ | |
fc171623 | 1663 | if (!update_cursor_pos |
c655f6fd | 1664 | && WINDOW_TOP_EDGE_LINE (XWINDOW (FRAME_MINIBUF_WINDOW (f))) <= new_pos_Y) |
fc171623 | 1665 | { |
06da1de1 EZ |
1666 | int tem_X = current_pos_X, dummy; |
1667 | ||
1668 | if (echo_area_glyphs) | |
1669 | { | |
1670 | tem_X = echo_area_glyphs_length; | |
1671 | /* Save current cursor position, to be restored after the | |
1672 | echo area message is erased. Only remember one level | |
1673 | of previous cursor position. */ | |
1674 | if (previous_pos_X == -1) | |
1675 | ScreenGetCursor (&dummy, &previous_pos_X); | |
1676 | } | |
1677 | else if (previous_pos_X >= 0) | |
1678 | { | |
1679 | /* We wind up here after the echo area message is erased. | |
1680 | Restore the cursor position we remembered above. */ | |
1681 | tem_X = previous_pos_X; | |
1682 | previous_pos_X = -1; | |
1683 | } | |
9a599a60 | 1684 | |
06da1de1 | 1685 | if (current_pos_X != tem_X) |
9a599a60 EZ |
1686 | { |
1687 | new_pos_X = tem_X; | |
1688 | update_cursor_pos = 1; | |
1689 | } | |
fc171623 | 1690 | } |
2d764c78 | 1691 | #endif |
fc171623 KH |
1692 | |
1693 | if (update_cursor_pos | |
1694 | && (current_pos_X != new_pos_X || current_pos_Y != new_pos_Y)) | |
1695 | { | |
1696 | ScreenSetCursor (current_pos_Y = new_pos_Y, current_pos_X = new_pos_X); | |
3e1944a3 EZ |
1697 | if (tty->termscript) |
1698 | fprintf (tty->termscript, "\n<CURSOR:%dx%d>", current_pos_X, current_pos_Y); | |
fc171623 KH |
1699 | } |
1700 | ||
1701 | /* Maybe cursor is invisible, so make it visible. */ | |
1702 | IT_display_cursor (1); | |
1703 | ||
1704 | /* Mouse pointer should be always visible if we are waiting for | |
1705 | keyboard input. */ | |
1706 | if (!mouse_visible) | |
1707 | mouse_on (); | |
1708 | } | |
1709 | ||
71f65669 | 1710 | static void |
41ad069b | 1711 | IT_update_begin (struct frame *f) |
f32d4091 | 1712 | { |
3e1944a3 | 1713 | struct tty_display_info *display_info = FRAME_X_DISPLAY_INFO (f); |
b9f80d41 | 1714 | struct frame *mouse_face_frame = display_info->mouse_face_mouse_frame; |
41ad069b | 1715 | |
7ccd1daf EZ |
1716 | if (display_info->termscript) |
1717 | fprintf (display_info->termscript, "\n\n<UPDATE_BEGIN"); | |
1718 | ||
41ad069b EZ |
1719 | BLOCK_INPUT; |
1720 | ||
b9f80d41 | 1721 | if (f && f == mouse_face_frame) |
41ad069b EZ |
1722 | { |
1723 | /* Don't do highlighting for mouse motion during the update. */ | |
1724 | display_info->mouse_face_defer = 1; | |
1725 | ||
1726 | /* If F needs to be redrawn, simply forget about any prior mouse | |
1727 | highlighting. */ | |
1728 | if (FRAME_GARBAGED_P (f)) | |
1729 | display_info->mouse_face_window = Qnil; | |
1730 | ||
1731 | /* Can we tell that this update does not affect the window | |
1732 | where the mouse highlight is? If so, no need to turn off. | |
48c14970 EZ |
1733 | Likewise, don't do anything if none of the enabled rows |
1734 | contains glyphs highlighted in mouse face. */ | |
8ccb9a54 EZ |
1735 | if (!NILP (display_info->mouse_face_window) |
1736 | && WINDOWP (display_info->mouse_face_window)) | |
41ad069b EZ |
1737 | { |
1738 | struct window *w = XWINDOW (display_info->mouse_face_window); | |
1739 | int i; | |
1740 | ||
8ccb9a54 EZ |
1741 | /* If the mouse highlight is in the window that was deleted |
1742 | (e.g., if it was popped by completion), clear highlight | |
1743 | unconditionally. */ | |
1744 | if (NILP (w->buffer)) | |
1745 | display_info->mouse_face_window = Qnil; | |
1746 | else | |
1747 | { | |
1748 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
48c14970 EZ |
1749 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i) |
1750 | && MATRIX_ROW (w->current_matrix, i)->mouse_face_p) | |
8ccb9a54 EZ |
1751 | break; |
1752 | } | |
41ad069b | 1753 | |
8ccb9a54 | 1754 | if (NILP (w->buffer) || i < w->desired_matrix->nrows) |
41ad069b EZ |
1755 | clear_mouse_face (display_info); |
1756 | } | |
1757 | } | |
b9f80d41 | 1758 | else if (mouse_face_frame && !FRAME_LIVE_P (mouse_face_frame)) |
41ad069b EZ |
1759 | { |
1760 | /* If the frame with mouse highlight was deleted, invalidate the | |
1761 | highlight info. */ | |
1762 | display_info->mouse_face_beg_row = display_info->mouse_face_beg_col = -1; | |
1763 | display_info->mouse_face_end_row = display_info->mouse_face_end_col = -1; | |
1764 | display_info->mouse_face_window = Qnil; | |
1765 | display_info->mouse_face_deferred_gc = 0; | |
1766 | display_info->mouse_face_mouse_frame = NULL; | |
1767 | } | |
1768 | ||
1769 | UNBLOCK_INPUT; | |
f32d4091 KS |
1770 | } |
1771 | ||
71f65669 | 1772 | static void |
41ad069b | 1773 | IT_update_end (struct frame *f) |
f32d4091 | 1774 | { |
7ccd1daf EZ |
1775 | struct tty_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
1776 | ||
1777 | if (dpyinfo->termscript) | |
1778 | fprintf (dpyinfo->termscript, "\n<UPDATE_END\n"); | |
1779 | dpyinfo->mouse_face_defer = 0; | |
41ad069b EZ |
1780 | } |
1781 | ||
1782 | static void | |
1783 | IT_frame_up_to_date (struct frame *f) | |
1784 | { | |
3e1944a3 | 1785 | struct tty_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
0c3cfc51 EZ |
1786 | Lisp_Object new_cursor, frame_desired_cursor; |
1787 | struct window *sw; | |
41ad069b EZ |
1788 | |
1789 | if (dpyinfo->mouse_face_deferred_gc | |
b9f80d41 | 1790 | || (f && f == dpyinfo->mouse_face_mouse_frame)) |
41ad069b EZ |
1791 | { |
1792 | BLOCK_INPUT; | |
1793 | if (dpyinfo->mouse_face_mouse_frame) | |
1794 | IT_note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
1795 | dpyinfo->mouse_face_mouse_x, | |
1796 | dpyinfo->mouse_face_mouse_y); | |
1797 | dpyinfo->mouse_face_deferred_gc = 0; | |
1798 | UNBLOCK_INPUT; | |
1799 | } | |
1800 | ||
0c3cfc51 EZ |
1801 | /* Set the cursor type to whatever they wanted. In a minibuffer |
1802 | window, we want the cursor to appear only if we are reading input | |
1803 | from this window, and we want the cursor to be taken from the | |
1804 | frame parameters. For the selected window, we use either its | |
1805 | buffer-local value or the value from the frame parameters if the | |
1806 | buffer doesn't define its local value for the cursor type. */ | |
1807 | sw = XWINDOW (f->selected_window); | |
1808 | frame_desired_cursor = Fcdr (Fassq (Qcursor_type, f->param_alist)); | |
1809 | if (cursor_in_echo_area | |
1810 | && FRAME_HAS_MINIBUF_P (f) | |
1811 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window) | |
1812 | && sw == XWINDOW (echo_area_window)) | |
1813 | new_cursor = frame_desired_cursor; | |
1814 | else | |
1815 | { | |
1816 | struct buffer *b = XBUFFER (sw->buffer); | |
1817 | ||
1818 | if (EQ (b->cursor_type, Qt)) | |
1819 | new_cursor = frame_desired_cursor; | |
1820 | else if (NILP (b->cursor_type)) /* nil means no cursor */ | |
1821 | new_cursor = Fcons (Qbar, make_number (0)); | |
1822 | else | |
1823 | new_cursor = b->cursor_type; | |
1824 | } | |
1825 | ||
1826 | IT_set_cursor_type (f, new_cursor); | |
8ba01a32 | 1827 | |
41ad069b | 1828 | IT_cmgoto (f); /* position cursor when update is done */ |
f32d4091 | 1829 | } |
1b94449f | 1830 | |
c77f6f1b EZ |
1831 | /* Copy LEN glyphs displayed on a single line whose vertical position |
1832 | is YPOS, beginning at horizontal position XFROM to horizontal | |
1833 | position XTO, by moving blocks in the video memory. Used by | |
1834 | functions that insert and delete glyphs. */ | |
1835 | static void | |
1836 | IT_copy_glyphs (int xfrom, int xto, size_t len, int ypos) | |
1837 | { | |
1838 | /* The offsets of source and destination relative to the | |
1839 | conventional memorty selector. */ | |
1840 | int from = 2 * (xfrom + screen_size_X * ypos) + ScreenPrimary; | |
1841 | int to = 2 * (xto + screen_size_X * ypos) + ScreenPrimary; | |
1842 | ||
1843 | if (from == to || len <= 0) | |
1844 | return; | |
1845 | ||
1846 | _farsetsel (_dos_ds); | |
1847 | ||
1848 | /* The source and destination might overlap, so we need to move | |
1849 | glyphs non-destructively. */ | |
1850 | if (from > to) | |
1851 | { | |
1852 | for ( ; len; from += 2, to += 2, len--) | |
1853 | _farnspokew (to, _farnspeekw (from)); | |
1854 | } | |
1855 | else | |
1856 | { | |
1857 | from += (len - 1) * 2; | |
1858 | to += (len - 1) * 2; | |
1859 | for ( ; len; from -= 2, to -= 2, len--) | |
1860 | _farnspokew (to, _farnspeekw (from)); | |
1861 | } | |
1862 | if (screen_virtual_segment) | |
1863 | dosv_refresh_virtual_screen (ypos * screen_size_X * 2, screen_size_X); | |
1864 | } | |
1865 | ||
1866 | /* Insert and delete glyphs. */ | |
aa9ce936 | 1867 | static void |
3e1944a3 EZ |
1868 | IT_insert_glyphs (f, start, len) |
1869 | struct frame *f; | |
c77f6f1b | 1870 | register struct glyph *start; |
aa9ce936 EZ |
1871 | register int len; |
1872 | { | |
c77f6f1b EZ |
1873 | int shift_by_width = screen_size_X - (new_pos_X + len); |
1874 | ||
1875 | /* Shift right the glyphs from the nominal cursor position to the | |
1876 | end of this line. */ | |
1877 | IT_copy_glyphs (new_pos_X, new_pos_X + len, shift_by_width, new_pos_Y); | |
1878 | ||
1879 | /* Now write the glyphs to be inserted. */ | |
3e1944a3 | 1880 | IT_write_glyphs (f, start, len); |
aa9ce936 EZ |
1881 | } |
1882 | ||
1883 | static void | |
3e1944a3 EZ |
1884 | IT_delete_glyphs (f, n) |
1885 | struct frame *f; | |
aa9ce936 EZ |
1886 | register int n; |
1887 | { | |
1888 | abort (); | |
1889 | } | |
1890 | ||
211c7152 | 1891 | /* set-window-configuration on window.c needs this. */ |
3bb1f22f RS |
1892 | void |
1893 | x_set_menu_bar_lines (f, value, oldval) | |
1894 | struct frame *f; | |
1895 | Lisp_Object value, oldval; | |
1896 | { | |
211c7152 EZ |
1897 | set_menu_bar_lines (f, value, oldval); |
1898 | } | |
3bb1f22f | 1899 | |
984f5aaa | 1900 | /* This was copied from xfaces.c */ |
3bb1f22f | 1901 | |
984f5aaa EZ |
1902 | extern Lisp_Object Qbackground_color; |
1903 | extern Lisp_Object Qforeground_color; | |
8ba01a32 | 1904 | Lisp_Object Qreverse; |
211c7152 | 1905 | extern Lisp_Object Qtitle; |
3bb1f22f | 1906 | |
48ffe371 RS |
1907 | /* IT_set_terminal_modes is called when emacs is started, |
1908 | resumed, and whenever the screen is redrawn! */ | |
f32d4091 | 1909 | |
71f65669 | 1910 | static void |
3e1944a3 | 1911 | IT_set_terminal_modes (struct terminal *term) |
f32d4091 | 1912 | { |
3e1944a3 EZ |
1913 | struct tty_display_info *tty; |
1914 | ||
1915 | /* If called with initial terminal, it's too early to do anything | |
1916 | useful. */ | |
1917 | if (term->type == output_initial) | |
1918 | return; | |
1919 | ||
1920 | tty = term->display_info.tty; | |
1921 | ||
1922 | if (tty->termscript) | |
1923 | fprintf (tty->termscript, "\n<SET_TERM>"); | |
f32d4091 KS |
1924 | |
1925 | screen_size_X = ScreenCols (); | |
1926 | screen_size_Y = ScreenRows (); | |
1927 | screen_size = screen_size_X * screen_size_Y; | |
56e19ec4 | 1928 | |
f32d4091 KS |
1929 | new_pos_X = new_pos_Y = 0; |
1930 | current_pos_X = current_pos_Y = -1; | |
1931 | ||
1932 | if (term_setup_done) | |
1933 | return; | |
1934 | term_setup_done = 1; | |
56e19ec4 | 1935 | |
f32d4091 KS |
1936 | startup_screen_size_X = screen_size_X; |
1937 | startup_screen_size_Y = screen_size_Y; | |
c9adab25 | 1938 | startup_screen_attrib = ScreenAttrib; |
f32d4091 | 1939 | |
039274cf EZ |
1940 | /* Is DOS/V (or any other RSIS software which relocates |
1941 | the screen) installed? */ | |
1942 | { | |
1943 | unsigned short es_value; | |
1944 | __dpmi_regs regs; | |
1945 | ||
1946 | regs.h.ah = 0xfe; /* get relocated screen address */ | |
1947 | if (ScreenPrimary == 0xb0000UL || ScreenPrimary == 0xb8000UL) | |
1948 | regs.x.es = (ScreenPrimary >> 4) & 0xffff; | |
1949 | else if (screen_old_address) /* already switched to Japanese mode once */ | |
1950 | regs.x.es = (screen_old_address >> 4) & 0xffff; | |
1951 | else | |
1952 | regs.x.es = ScreenMode () == 7 ? 0xb000 : 0xb800; | |
1953 | regs.x.di = 0; | |
1954 | es_value = regs.x.es; | |
1955 | __dpmi_int (0x10, ®s); | |
1956 | ||
d1d5dc19 | 1957 | if (regs.x.es != es_value) |
039274cf | 1958 | { |
d1d5dc19 EZ |
1959 | /* screen_old_address is only set if ScreenPrimary does NOT |
1960 | already point to the relocated buffer address returned by | |
1961 | the Int 10h/AX=FEh call above. DJGPP v2.02 and later sets | |
1962 | ScreenPrimary to that address at startup under DOS/V. */ | |
1963 | if (regs.x.es != (ScreenPrimary >> 4) & 0xffff) | |
1964 | screen_old_address = ScreenPrimary; | |
039274cf EZ |
1965 | screen_virtual_segment = regs.x.es; |
1966 | screen_virtual_offset = regs.x.di; | |
1967 | ScreenPrimary = (screen_virtual_segment << 4) + screen_virtual_offset; | |
1968 | } | |
1969 | } | |
039274cf | 1970 | |
f32d4091 KS |
1971 | ScreenGetCursor (&startup_pos_Y, &startup_pos_X); |
1972 | ScreenRetrieve (startup_screen_buffer = xmalloc (screen_size * 2)); | |
1973 | ||
76ac1508 | 1974 | bright_bg (); |
f32d4091 KS |
1975 | } |
1976 | ||
48ffe371 RS |
1977 | /* IT_reset_terminal_modes is called when emacs is |
1978 | suspended or killed. */ | |
f32d4091 | 1979 | |
71f65669 | 1980 | static void |
3e1944a3 | 1981 | IT_reset_terminal_modes (struct terminal *term) |
f32d4091 | 1982 | { |
c9adab25 KH |
1983 | int display_row_start = (int) ScreenPrimary; |
1984 | int saved_row_len = startup_screen_size_X * 2; | |
56e19ec4 | 1985 | int update_row_len = ScreenCols () * 2, current_rows = ScreenRows (); |
c9adab25 KH |
1986 | int to_next_row = update_row_len; |
1987 | unsigned char *saved_row = startup_screen_buffer; | |
56e19ec4 | 1988 | int cursor_pos_X = ScreenCols () - 1, cursor_pos_Y = ScreenRows () - 1; |
3e1944a3 | 1989 | struct tty_display_info *tty = term->display_info.tty; |
c9adab25 | 1990 | |
3e1944a3 EZ |
1991 | if (tty->termscript) |
1992 | fprintf (tty->termscript, "\n<RESET_TERM>"); | |
f32d4091 | 1993 | |
f32d4091 KS |
1994 | if (!term_setup_done) |
1995 | return; | |
56e19ec4 | 1996 | |
c9adab25 | 1997 | mouse_off (); |
b36701cc RS |
1998 | |
1999 | /* Leave the video system in the same state as we found it, | |
2000 | as far as the blink/bright-background bit is concerned. */ | |
2001 | maybe_enable_blinking (); | |
06b1ea13 | 2002 | |
c9adab25 KH |
2003 | /* We have a situation here. |
2004 | We cannot just do ScreenUpdate(startup_screen_buffer) because | |
2005 | the luser could have changed screen dimensions inside Emacs | |
2006 | and failed (or didn't want) to restore them before killing | |
2007 | Emacs. ScreenUpdate() uses the *current* screen dimensions and | |
2008 | thus will happily use memory outside what was allocated for | |
2009 | `startup_screen_buffer'. | |
2010 | Thus we only restore as much as the current screen dimensions | |
2011 | can hold, and clear the rest (if the saved screen is smaller than | |
2012 | the current) with the color attribute saved at startup. The cursor | |
2013 | is also restored within the visible dimensions. */ | |
2014 | ||
2015 | ScreenAttrib = startup_screen_attrib; | |
c9adab25 | 2016 | |
06b1ea13 EZ |
2017 | /* Don't restore the screen if we are exiting less than 2 seconds |
2018 | after startup: we might be crashing, and the screen might show | |
2019 | some vital clues to what's wrong. */ | |
2020 | if (clock () - startup_time >= 2*CLOCKS_PER_SEC) | |
c9adab25 | 2021 | { |
06b1ea13 | 2022 | ScreenClear (); |
039274cf | 2023 | if (screen_virtual_segment) |
06b1ea13 EZ |
2024 | dosv_refresh_virtual_screen (0, screen_size); |
2025 | ||
2026 | if (update_row_len > saved_row_len) | |
2027 | update_row_len = saved_row_len; | |
2028 | if (current_rows > startup_screen_size_Y) | |
2029 | current_rows = startup_screen_size_Y; | |
2030 | ||
3e1944a3 EZ |
2031 | if (tty->termscript) |
2032 | fprintf (tty->termscript, "<SCREEN RESTORED (dimensions=%dx%d)>\n", | |
06b1ea13 EZ |
2033 | update_row_len / 2, current_rows); |
2034 | ||
2035 | while (current_rows--) | |
2036 | { | |
2037 | dosmemput (saved_row, update_row_len, display_row_start); | |
2038 | if (screen_virtual_segment) | |
2039 | dosv_refresh_virtual_screen (display_row_start - ScreenPrimary, | |
2040 | update_row_len / 2); | |
2041 | saved_row += saved_row_len; | |
2042 | display_row_start += to_next_row; | |
2043 | } | |
c9adab25 KH |
2044 | } |
2045 | if (startup_pos_X < cursor_pos_X) | |
2046 | cursor_pos_X = startup_pos_X; | |
2047 | if (startup_pos_Y < cursor_pos_Y) | |
2048 | cursor_pos_Y = startup_pos_Y; | |
2049 | ||
2050 | ScreenSetCursor (cursor_pos_Y, cursor_pos_X); | |
2051 | xfree (startup_screen_buffer); | |
3e1944a3 | 2052 | startup_screen_buffer = NULL; |
f32d4091 KS |
2053 | |
2054 | term_setup_done = 0; | |
2055 | } | |
2056 | ||
71f65669 | 2057 | static void |
3e1944a3 | 2058 | IT_set_terminal_window (struct frame *f, int foo) |
f32d4091 KS |
2059 | { |
2060 | } | |
2061 | ||
2d764c78 EZ |
2062 | /* Remember the screen colors of the curent frame, to serve as the |
2063 | default colors for newly-created frames. */ | |
2d764c78 EZ |
2064 | DEFUN ("msdos-remember-default-colors", Fmsdos_remember_default_colors, |
2065 | Smsdos_remember_default_colors, 1, 1, 0, | |
70da46c3 | 2066 | doc: /* Remember the screen colors of the current frame. */) |
2d764c78 EZ |
2067 | (frame) |
2068 | Lisp_Object frame; | |
2069 | { | |
2d764c78 EZ |
2070 | struct frame *f; |
2071 | ||
b7826503 | 2072 | CHECK_FRAME (frame); |
f12dae2f | 2073 | f = XFRAME (frame); |
2d764c78 | 2074 | |
ff12cd1d EZ |
2075 | /* This function is called after applying default-frame-alist to the |
2076 | initial frame. At that time, if reverse-colors option was | |
2077 | specified in default-frame-alist, it was already applied, and | |
f12dae2f EZ |
2078 | frame colors are reversed. */ |
2079 | initial_screen_colors[0] = FRAME_FOREGROUND_PIXEL (f); | |
2080 | initial_screen_colors[1] = FRAME_BACKGROUND_PIXEL (f); | |
2d764c78 EZ |
2081 | } |
2082 | ||
f32d4091 | 2083 | void |
3bb1f22f | 2084 | IT_set_frame_parameters (f, alist) |
c77f6f1b | 2085 | struct frame *f; |
f32d4091 KS |
2086 | Lisp_Object alist; |
2087 | { | |
2088 | Lisp_Object tail; | |
56e19ec4 | 2089 | int i, j, length = XINT (Flength (alist)); |
db722735 RS |
2090 | Lisp_Object *parms |
2091 | = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); | |
2092 | Lisp_Object *values | |
2093 | = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); | |
2d764c78 | 2094 | /* Do we have to reverse the foreground and background colors? */ |
8ba01a32 | 2095 | int reverse = EQ (Fcdr (Fassq (Qreverse, f->param_alist)), Qt); |
56e19ec4 | 2096 | int need_to_reverse, was_reverse = reverse; |
2d764c78 | 2097 | int redraw = 0, fg_set = 0, bg_set = 0; |
56e19ec4 | 2098 | unsigned long orig_fg, orig_bg; |
546701f5 | 2099 | Lisp_Object frame_bg, frame_fg; |
53704a07 | 2100 | extern Lisp_Object Qdefault, QCforeground, QCbackground; |
3e1944a3 | 2101 | struct tty_display_info *tty = FRAME_TTY (f); |
2d764c78 EZ |
2102 | |
2103 | /* If we are creating a new frame, begin with the original screen colors | |
2104 | used for the initial frame. */ | |
238a44a8 | 2105 | if (EQ (alist, Vdefault_frame_alist) |
2d764c78 EZ |
2106 | && initial_screen_colors[0] != -1 && initial_screen_colors[1] != -1) |
2107 | { | |
2108 | FRAME_FOREGROUND_PIXEL (f) = initial_screen_colors[0]; | |
2109 | FRAME_BACKGROUND_PIXEL (f) = initial_screen_colors[1]; | |
f12dae2f | 2110 | init_frame_faces (f); |
2d764c78 EZ |
2111 | } |
2112 | orig_fg = FRAME_FOREGROUND_PIXEL (f); | |
2113 | orig_bg = FRAME_BACKGROUND_PIXEL (f); | |
546701f5 EZ |
2114 | frame_fg = Fcdr (Fassq (Qforeground_color, f->param_alist)); |
2115 | frame_bg = Fcdr (Fassq (Qbackground_color, f->param_alist)); | |
2116 | /* frame_fg and frame_bg could be nil if, for example, | |
2117 | f->param_alist is nil, e.g. if we are called from | |
2118 | Fmake_terminal_frame. */ | |
2119 | if (NILP (frame_fg)) | |
2120 | frame_fg = build_string (unspecified_fg); | |
2121 | if (NILP (frame_bg)) | |
2122 | frame_bg = build_string (unspecified_bg); | |
db722735 RS |
2123 | |
2124 | /* Extract parm names and values into those vectors. */ | |
2125 | i = 0; | |
f32d4091 KS |
2126 | for (tail = alist; CONSP (tail); tail = Fcdr (tail)) |
2127 | { | |
db722735 | 2128 | Lisp_Object elt; |
f32d4091 KS |
2129 | |
2130 | elt = Fcar (tail); | |
db722735 | 2131 | parms[i] = Fcar (elt); |
b7826503 | 2132 | CHECK_SYMBOL (parms[i]); |
db722735 RS |
2133 | values[i] = Fcdr (elt); |
2134 | i++; | |
2135 | } | |
2136 | ||
2d764c78 | 2137 | j = i; |
db722735 | 2138 | |
2d764c78 EZ |
2139 | for (i = 0; i < j; i++) |
2140 | { | |
1e21fe48 EZ |
2141 | Lisp_Object prop, val; |
2142 | ||
2143 | prop = parms[i]; | |
2144 | val = values[i]; | |
2d764c78 | 2145 | |
8ba01a32 | 2146 | if (EQ (prop, Qreverse)) |
2d764c78 EZ |
2147 | reverse = EQ (val, Qt); |
2148 | } | |
546701f5 EZ |
2149 | |
2150 | need_to_reverse = reverse && !was_reverse; | |
3e1944a3 EZ |
2151 | if (tty->termscript && need_to_reverse) |
2152 | fprintf (tty->termscript, "<INVERSE-VIDEO>\n"); | |
2d764c78 EZ |
2153 | |
2154 | /* Now process the alist elements in reverse of specified order. */ | |
db722735 RS |
2155 | for (i--; i >= 0; i--) |
2156 | { | |
56e19ec4 | 2157 | Lisp_Object prop, val, frame; |
1e21fe48 EZ |
2158 | |
2159 | prop = parms[i]; | |
2160 | val = values[i]; | |
f32d4091 | 2161 | |
4e825084 | 2162 | if (EQ (prop, Qforeground_color)) |
f32d4091 | 2163 | { |
546701f5 | 2164 | unsigned long new_color = load_color (f, NULL, val, need_to_reverse |
2d764c78 EZ |
2165 | ? LFACE_BACKGROUND_INDEX |
2166 | : LFACE_FOREGROUND_INDEX); | |
3b620731 EZ |
2167 | if (new_color != FACE_TTY_DEFAULT_COLOR |
2168 | && new_color != FACE_TTY_DEFAULT_FG_COLOR | |
2169 | && new_color != FACE_TTY_DEFAULT_BG_COLOR) | |
f32d4091 | 2170 | { |
546701f5 | 2171 | FRAME_FOREGROUND_PIXEL (f) = new_color; |
1e21fe48 EZ |
2172 | /* Make sure the foreground of the default face for this |
2173 | frame is changed as well. */ | |
2174 | XSETFRAME (frame, f); | |
f12dae2f EZ |
2175 | Finternal_set_lisp_face_attribute (Qdefault, QCforeground, |
2176 | val, frame); | |
2177 | fg_set = 1; | |
f32d4091 | 2178 | redraw = 1; |
3e1944a3 EZ |
2179 | if (tty->termscript) |
2180 | fprintf (tty->termscript, "<FGCOLOR %lu>\n", new_color); | |
f32d4091 KS |
2181 | } |
2182 | } | |
4e825084 | 2183 | else if (EQ (prop, Qbackground_color)) |
f32d4091 | 2184 | { |
546701f5 | 2185 | unsigned long new_color = load_color (f, NULL, val, need_to_reverse |
2d764c78 EZ |
2186 | ? LFACE_FOREGROUND_INDEX |
2187 | : LFACE_BACKGROUND_INDEX); | |
3b620731 EZ |
2188 | if (new_color != FACE_TTY_DEFAULT_COLOR |
2189 | && new_color != FACE_TTY_DEFAULT_FG_COLOR | |
2190 | && new_color != FACE_TTY_DEFAULT_BG_COLOR) | |
f32d4091 | 2191 | { |
546701f5 | 2192 | FRAME_BACKGROUND_PIXEL (f) = new_color; |
1e21fe48 EZ |
2193 | /* Make sure the background of the default face for this |
2194 | frame is changed as well. */ | |
2195 | XSETFRAME (frame, f); | |
f12dae2f EZ |
2196 | Finternal_set_lisp_face_attribute (Qdefault, QCbackground, |
2197 | val, frame); | |
2198 | bg_set = 1; | |
f32d4091 | 2199 | redraw = 1; |
3e1944a3 EZ |
2200 | if (tty->termscript) |
2201 | fprintf (tty->termscript, "<BGCOLOR %lu>\n", new_color); | |
f32d4091 KS |
2202 | } |
2203 | } | |
211c7152 EZ |
2204 | else if (EQ (prop, Qtitle)) |
2205 | { | |
2206 | x_set_title (f, val); | |
3e1944a3 EZ |
2207 | if (tty->termscript) |
2208 | fprintf (tty->termscript, "<TITLE: %s>\n", SDATA (val)); | |
211c7152 | 2209 | } |
8ba01a32 EZ |
2210 | else if (EQ (prop, Qcursor_type)) |
2211 | { | |
2212 | IT_set_cursor_type (f, val); | |
3e1944a3 EZ |
2213 | if (tty->termscript) |
2214 | fprintf (tty->termscript, "<CTYPE: %s>\n", | |
a0738471 EZ |
2215 | EQ (val, Qbar) || EQ (val, Qhbar) |
2216 | || CONSP (val) && (EQ (XCAR (val), Qbar) | |
2217 | || EQ (XCAR (val), Qhbar)) | |
8ba01a32 EZ |
2218 | ? "bar" : "box"); |
2219 | } | |
3e1944a3 EZ |
2220 | else if (EQ (prop, Qtty_type)) |
2221 | { | |
2222 | internal_terminal_init (); | |
2223 | if (tty->termscript) | |
2224 | fprintf (tty->termscript, "<TERM_INIT done, TTY_TYPE: %.*s>\n", | |
2225 | SBYTES (val), SDATA (val)); | |
2226 | } | |
db722735 | 2227 | store_frame_param (f, prop, val); |
2d764c78 | 2228 | } |
db722735 | 2229 | |
2d764c78 EZ |
2230 | /* If they specified "reverse", but not the colors, we need to swap |
2231 | the current frame colors. */ | |
546701f5 | 2232 | if (need_to_reverse) |
2d764c78 | 2233 | { |
1e21fe48 EZ |
2234 | Lisp_Object frame; |
2235 | ||
2d764c78 EZ |
2236 | if (!fg_set) |
2237 | { | |
1e21fe48 | 2238 | XSETFRAME (frame, f); |
ff12cd1d EZ |
2239 | Finternal_set_lisp_face_attribute (Qdefault, QCforeground, |
2240 | tty_color_name (f, orig_bg), | |
53704a07 | 2241 | frame); |
2d764c78 EZ |
2242 | redraw = 1; |
2243 | } | |
2244 | if (!bg_set) | |
2245 | { | |
1e21fe48 | 2246 | XSETFRAME (frame, f); |
ff12cd1d EZ |
2247 | Finternal_set_lisp_face_attribute (Qdefault, QCbackground, |
2248 | tty_color_name (f, orig_fg), | |
53704a07 | 2249 | frame); |
2d764c78 EZ |
2250 | redraw = 1; |
2251 | } | |
f32d4091 KS |
2252 | } |
2253 | ||
2254 | if (redraw) | |
2255 | { | |
2d764c78 EZ |
2256 | face_change_count++; /* forces xdisp.c to recompute basic faces */ |
2257 | if (f == SELECTED_FRAME()) | |
3bb1f22f | 2258 | redraw_frame (f); |
f32d4091 KS |
2259 | } |
2260 | } | |
2261 | ||
a7cf9151 EZ |
2262 | extern void init_frame_faces (FRAME_PTR); |
2263 | ||
f32d4091 KS |
2264 | #endif /* !HAVE_X_WINDOWS */ |
2265 | ||
2266 | ||
48ffe371 RS |
2267 | /* Do we need the internal terminal? */ |
2268 | ||
f32d4091 KS |
2269 | void |
2270 | internal_terminal_init () | |
2271 | { | |
2306a735 | 2272 | static int init_needed = 1; |
56e19ec4 | 2273 | char *term = getenv ("TERM"), *colors; |
2d764c78 | 2274 | struct frame *sf = SELECTED_FRAME(); |
3e1944a3 | 2275 | struct tty_display_info *tty; |
f32d4091 KS |
2276 | |
2277 | #ifdef HAVE_X_WINDOWS | |
2278 | if (!inhibit_window_system) | |
2279 | return; | |
2280 | #endif | |
2281 | ||
3e1944a3 EZ |
2282 | /* If this is the initial terminal, we are done here. */ |
2283 | if (sf->output_method == output_initial) | |
2284 | return; | |
2285 | ||
f32d4091 KS |
2286 | internal_terminal |
2287 | = (!noninteractive) && term && !strcmp (term, "internal"); | |
2288 | ||
f32d4091 KS |
2289 | #ifndef HAVE_X_WINDOWS |
2290 | if (!internal_terminal || inhibit_window_system) | |
2291 | { | |
2d764c78 | 2292 | sf->output_method = output_termcap; |
f32d4091 KS |
2293 | return; |
2294 | } | |
2295 | ||
3e1944a3 | 2296 | tty = FRAME_TTY (sf); |
f12dae2f EZ |
2297 | current_kboard->Vwindow_system = Qpc; |
2298 | sf->output_method = output_msdos_raw; | |
2306a735 | 2299 | if (init_needed) |
3e1944a3 | 2300 | { |
2306a735 EZ |
2301 | if (!tty->termscript && getenv ("EMACSTEST")) |
2302 | tty->termscript = fopen (getenv ("EMACSTEST"), "wt"); | |
2303 | if (tty->termscript) | |
2304 | { | |
2305 | time_t now = time (NULL); | |
2306 | struct tm *tnow = localtime (&now); | |
2307 | char tbuf[100]; | |
3e1944a3 | 2308 | |
2306a735 EZ |
2309 | strftime (tbuf, sizeof (tbuf) - 1, "%a %b %e %Y %H:%M:%S %Z", tnow); |
2310 | fprintf (tty->termscript, "\nEmacs session started at %s\n", tbuf); | |
2311 | fprintf (tty->termscript, "=====================\n\n"); | |
2312 | } | |
3e1944a3 | 2313 | |
2306a735 EZ |
2314 | Vinitial_window_system = Qpc; |
2315 | Vwindow_system_version = make_number (23); /* RE Emacs version */ | |
2316 | tty->terminal->type = output_msdos_raw; | |
039274cf | 2317 | |
2306a735 EZ |
2318 | /* If Emacs was dumped on DOS/V machine, forget the stale VRAM |
2319 | address. */ | |
2320 | screen_old_address = 0; | |
039274cf | 2321 | |
2306a735 EZ |
2322 | /* Forget the stale screen colors as well. */ |
2323 | initial_screen_colors[0] = initial_screen_colors[1] = -1; | |
2d764c78 | 2324 | |
2306a735 EZ |
2325 | FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = 7; /* White */ |
2326 | FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = 0; /* Black */ | |
2327 | bright_bg (); | |
2328 | colors = getenv ("EMACSCOLORS"); | |
2329 | if (colors && strlen (colors) >= 2) | |
2330 | { | |
2331 | /* The colors use 4 bits each (we enable bright background). */ | |
2332 | if (isdigit (colors[0])) | |
2333 | colors[0] -= '0'; | |
2334 | else if (isxdigit (colors[0])) | |
2335 | colors[0] -= (isupper (colors[0]) ? 'A' : 'a') - 10; | |
2336 | if (colors[0] >= 0 && colors[0] < 16) | |
2337 | FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = colors[0]; | |
2338 | if (isdigit (colors[1])) | |
2339 | colors[1] -= '0'; | |
2340 | else if (isxdigit (colors[1])) | |
2341 | colors[1] -= (isupper (colors[1]) ? 'A' : 'a') - 10; | |
2342 | if (colors[1] >= 0 && colors[1] < 16) | |
2343 | FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = colors[1]; | |
2344 | } | |
2345 | the_only_display_info.mouse_face_mouse_frame = NULL; | |
2346 | the_only_display_info.mouse_face_deferred_gc = 0; | |
2347 | the_only_display_info.mouse_face_beg_row = | |
2348 | the_only_display_info.mouse_face_beg_col = -1; | |
2349 | the_only_display_info.mouse_face_end_row = | |
2350 | the_only_display_info.mouse_face_end_col = -1; | |
2351 | the_only_display_info.mouse_face_face_id = DEFAULT_FACE_ID; | |
2352 | the_only_display_info.mouse_face_window = Qnil; | |
2353 | the_only_display_info.mouse_face_mouse_x = | |
2354 | the_only_display_info.mouse_face_mouse_y = 0; | |
2355 | the_only_display_info.mouse_face_defer = 0; | |
2356 | the_only_display_info.mouse_face_hidden = 0; | |
2357 | ||
2358 | if (have_mouse) /* detected in dos_ttraw, which see */ | |
2359 | { | |
2360 | have_mouse = 1; /* enable mouse */ | |
2361 | mouse_visible = 0; | |
2362 | mouse_setup_buttons (mouse_button_count); | |
2363 | tty->terminal->mouse_position_hook = &mouse_get_pos; | |
2364 | mouse_init (); | |
2365 | } | |
f32d4091 | 2366 | |
2306a735 EZ |
2367 | if (tty->termscript && screen_size) |
2368 | fprintf (tty->termscript, "<SCREEN SAVED (dimensions=%dx%d)>\n", | |
2369 | screen_size_X, screen_size_Y); | |
f32d4091 | 2370 | |
f12dae2f | 2371 | init_frame_faces (sf); |
2306a735 EZ |
2372 | init_needed = 0; |
2373 | } | |
f32d4091 KS |
2374 | #endif |
2375 | } | |
2376 | ||
3e1944a3 EZ |
2377 | void |
2378 | initialize_msdos_display (struct terminal *term) | |
2379 | { | |
2380 | term->rif = 0; /* we don't support window-based display */ | |
2381 | term->cursor_to_hook = term->raw_cursor_to_hook = IT_cursor_to; | |
2382 | term->clear_to_end_hook = IT_clear_to_end; | |
2383 | term->clear_frame_hook = IT_clear_screen; | |
2384 | term->clear_end_of_line_hook = IT_clear_end_of_line; | |
2385 | term->ins_del_lines_hook = 0; | |
2386 | term->insert_glyphs_hook = IT_insert_glyphs; | |
2387 | term->write_glyphs_hook = IT_write_glyphs; | |
2388 | term->delete_glyphs_hook = IT_delete_glyphs; | |
2389 | term->ring_bell_hook = IT_ring_bell; | |
2390 | term->reset_terminal_modes_hook = IT_reset_terminal_modes; | |
2391 | term->set_terminal_modes_hook = IT_set_terminal_modes; | |
2392 | term->set_terminal_window_hook = IT_set_terminal_window; | |
2393 | term->update_begin_hook = IT_update_begin; | |
2394 | term->update_end_hook = IT_update_end; | |
2395 | term->frame_up_to_date_hook = IT_frame_up_to_date; | |
2396 | term->mouse_position_hook = 0; /* set later by dos_ttraw */ | |
2397 | term->frame_rehighlight_hook = 0; | |
2398 | term->frame_raise_lower_hook = 0; | |
2399 | term->set_vertical_scroll_bar_hook = 0; | |
2400 | term->condemn_scroll_bars_hook = 0; | |
2401 | term->redeem_scroll_bar_hook = 0; | |
2402 | term->judge_scroll_bars_hook = 0; | |
2403 | term->read_socket_hook = &tty_read_avail_input; /* from keyboard.c */ | |
2404 | } | |
2405 | ||
f32d4091 KS |
2406 | dos_get_saved_screen (screen, rows, cols) |
2407 | char **screen; | |
2408 | int *rows; | |
2409 | int *cols; | |
2410 | { | |
2411 | #ifndef HAVE_X_WINDOWS | |
2412 | *screen = startup_screen_buffer; | |
2413 | *cols = startup_screen_size_X; | |
2414 | *rows = startup_screen_size_Y; | |
039274cf | 2415 | return *screen != (char *)0; |
f32d4091 KS |
2416 | #else |
2417 | return 0; | |
56e19ec4 | 2418 | #endif |
f32d4091 | 2419 | } |
3bb1f22f RS |
2420 | |
2421 | #ifndef HAVE_X_WINDOWS | |
2422 | ||
2423 | /* We are not X, but we can emulate it well enough for our needs... */ | |
2424 | void | |
2425 | check_x (void) | |
2426 | { | |
2d764c78 EZ |
2427 | if (! FRAME_MSDOS_P (SELECTED_FRAME())) |
2428 | error ("Not running under a window system"); | |
3bb1f22f RS |
2429 | } |
2430 | ||
2431 | #endif | |
2432 | ||
5063b150 | 2433 | \f |
f32d4091 KS |
2434 | /* ----------------------- Keyboard control ---------------------- |
2435 | * | |
2436 | * Keymaps reflect the following keyboard layout: | |
2437 | * | |
2438 | * 0 1 2 3 4 5 6 7 8 9 10 11 12 BS | |
2439 | * TAB 15 16 17 18 19 20 21 22 23 24 25 26 (41) | |
2440 | * CLOK 30 31 32 33 34 35 36 37 38 39 40 (41) RET | |
2441 | * SH () 45 46 47 48 49 50 51 52 53 54 SHIFT | |
2442 | * SPACE | |
2443 | */ | |
2444 | ||
d1d5dc19 EZ |
2445 | #define Ignore 0x0000 |
2446 | #define Normal 0x0000 /* normal key - alt changes scan-code */ | |
2447 | #define FctKey 0x1000 /* func key if c == 0, else c */ | |
2448 | #define Special 0x2000 /* func key even if c != 0 */ | |
2449 | #define ModFct 0x3000 /* special if mod-keys, else 'c' */ | |
2450 | #define Map 0x4000 /* alt scan-code, map to unshift/shift key */ | |
2451 | #define KeyPad 0x5000 /* map to insert/kp-0 depending on c == 0xe0 */ | |
2452 | #define Grey 0x6000 /* Grey keypad key */ | |
2453 | ||
2454 | #define Alt 0x0100 /* alt scan-code */ | |
2455 | #define Ctrl 0x0200 /* ctrl scan-code */ | |
2456 | #define Shift 0x0400 /* shift scan-code */ | |
2457 | ||
db9cd97a | 2458 | static int extended_kbd; /* 101 (102) keyboard present. */ |
f32d4091 | 2459 | |
d1d5dc19 EZ |
2460 | struct kbd_translate { |
2461 | unsigned char sc; | |
2462 | unsigned char ch; | |
2463 | unsigned short code; | |
2464 | }; | |
2465 | ||
f32d4091 KS |
2466 | struct dos_keyboard_map |
2467 | { | |
2468 | char *unshifted; | |
2469 | char *shifted; | |
2470 | char *alt_gr; | |
d1d5dc19 | 2471 | struct kbd_translate *translate_table; |
f32d4091 KS |
2472 | }; |
2473 | ||
2474 | ||
2475 | static struct dos_keyboard_map us_keyboard = { | |
2476 | /* 0 1 2 3 4 5 */ | |
2477 | /* 01234567890123456789012345678901234567890 12345678901234 */ | |
2478 | "`1234567890-= qwertyuiop[] asdfghjkl;'\\ zxcvbnm,./ ", | |
2479 | /* 0123456789012345678901234567890123456789 012345678901234 */ | |
2480 | "~!@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"| ZXCVBNM<>? ", | |
d1d5dc19 EZ |
2481 | 0, /* no Alt-Gr key */ |
2482 | 0 /* no translate table */ | |
f32d4091 KS |
2483 | }; |
2484 | ||
2485 | static struct dos_keyboard_map fr_keyboard = { | |
2486 | /* 0 1 2 3 4 5 */ | |
2487 | /* 012 3456789012345678901234567890123456789012345678901234 */ | |
2488 |