aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/w32console.c171
1 files changed, 91 insertions, 80 deletions
diff --git a/src/w32console.c b/src/w32console.c
index d2f0e06a64d..a9647dcb449 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -35,11 +35,12 @@ Boston, MA 02110-1301, USA.
35#include "charset.h" 35#include "charset.h"
36#include "coding.h" 36#include "coding.h"
37#include "disptab.h" 37#include "disptab.h"
38#include "termhooks.h"
39#include "dispextern.h"
40/* Disable features in frame.h that require a Window System. */ 38/* Disable features in frame.h that require a Window System. */
41#undef HAVE_WINDOW_SYSTEM 39#undef HAVE_WINDOW_SYSTEM
42#include "frame.h" 40#include "frame.h"
41#include "termhooks.h"
42#include "termchar.h"
43#include "dispextern.h"
43#include "w32inevt.h" 44#include "w32inevt.h"
44 45
45/* from window.c */ 46/* from window.c */
@@ -51,21 +52,17 @@ extern int detect_input_pending ();
51/* from sysdep.c */ 52/* from sysdep.c */
52extern int read_input_pending (); 53extern int read_input_pending ();
53 54
54extern struct frame * updating_frame; 55static void w32con_move_cursor (struct frame *f, int row, int col);
55extern int meta_key; 56static void w32con_clear_to_end (struct frame *f);
56 57static void w32con_clear_frame (struct frame *f);
57static void w32con_move_cursor (int row, int col); 58static void w32con_clear_end_of_line (struct frame *f, int);
58static void w32con_clear_to_end (void); 59static void w32con_ins_del_lines (struct frame *f, int vpos, int n);
59static void w32con_clear_frame (void); 60static void w32con_insert_glyphs (struct frame *f, struct glyph *start, int len);
60static void w32con_clear_end_of_line (int); 61static void w32con_write_glyphs (struct frame *f, struct glyph *string, int len);
61static void w32con_ins_del_lines (int vpos, int n); 62static void w32con_delete_glyphs (struct frame *f, int n);
62static void w32con_insert_glyphs (struct glyph *start, int len); 63static void w32con_reset_terminal_modes (struct terminal *t);
63static void w32con_write_glyphs (struct glyph *string, int len); 64static void w32con_set_terminal_modes (struct terminal *t);
64static void w32con_delete_glyphs (int n); 65static void w32con_set_terminal_window (struct frame *f, int size);
65void w32_sys_ring_bell (void);
66static void w32con_reset_terminal_modes (void);
67static void w32con_set_terminal_modes (void);
68static void w32con_set_terminal_window (int size);
69static void w32con_update_begin (struct frame * f); 66static void w32con_update_begin (struct frame * f);
70static void w32con_update_end (struct frame * f); 67static void w32con_update_end (struct frame * f);
71static WORD w32_face_attributes (struct frame *f, int face_id); 68static WORD w32_face_attributes (struct frame *f, int face_id);
@@ -99,38 +96,31 @@ ctrl_c_handler (unsigned long type)
99 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT)); 96 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
100} 97}
101 98
102/* If we're updating a frame, use it as the current frame
103 Otherwise, use the selected frame. */
104#define PICK_FRAME() (updating_frame ? updating_frame : SELECTED_FRAME ())
105 99
106/* Move the cursor to (row, col). */ 100/* Move the cursor to (ROW, COL) on FRAME. */
107static void 101static void
108w32con_move_cursor (int row, int col) 102w32con_move_cursor (struct frame *f, int row, int col)
109{ 103{
110 cursor_coords.X = col; 104 cursor_coords.X = col;
111 cursor_coords.Y = row; 105 cursor_coords.Y = row;
112 106
113 if (updating_frame == (struct frame *) NULL) 107 /* TODO: for multi-tty support, cur_screen should be replaced with a
114 { 108 reference to the terminal for this frame. */
115 SetConsoleCursorPosition (cur_screen, cursor_coords); 109 SetConsoleCursorPosition (cur_screen, cursor_coords);
116 }
117} 110}
118 111
119/* Clear from cursor to end of screen. */ 112/* Clear from cursor to end of screen. */
120static void 113static void
121w32con_clear_to_end (void) 114w32con_clear_to_end (struct frame *f)
122{ 115{
123 struct frame * f = PICK_FRAME (); 116 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
124 117 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
125 w32con_clear_end_of_line (FRAME_COLS (f) - 1);
126 w32con_ins_del_lines (cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
127} 118}
128 119
129/* Clear the frame. */ 120/* Clear the frame. */
130static void 121static void
131w32con_clear_frame (void) 122w32con_clear_frame (struct frame *f)
132{ 123{
133 struct frame * f = PICK_FRAME ();
134 COORD dest; 124 COORD dest;
135 int n; 125 int n;
136 DWORD r; 126 DWORD r;
@@ -145,7 +135,7 @@ w32con_clear_frame (void)
145 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r); 135 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
146 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r); 136 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
147 137
148 w32con_move_cursor (0, 0); 138 w32con_move_cursor (f, 0, 0);
149} 139}
150 140
151 141
@@ -154,7 +144,7 @@ static BOOL ceol_initialized = FALSE;
154 144
155/* Clear from Cursor to end (what's "standout marker"?). */ 145/* Clear from Cursor to end (what's "standout marker"?). */
156static void 146static void
157w32con_clear_end_of_line (int end) 147w32con_clear_end_of_line (struct frame *f, int end)
158{ 148{
159 if (!ceol_initialized) 149 if (!ceol_initialized)
160 { 150 {
@@ -165,18 +155,17 @@ w32con_clear_end_of_line (int end)
165 } 155 }
166 ceol_initialized = TRUE; 156 ceol_initialized = TRUE;
167 } 157 }
168 w32con_write_glyphs (glyph_base, end - cursor_coords.X); /* fencepost ? */ 158 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
169} 159}
170 160
171/* Insert n lines at vpos. if n is negative delete -n lines. */ 161/* Insert n lines at vpos. if n is negative delete -n lines. */
172static void 162static void
173w32con_ins_del_lines (int vpos, int n) 163w32con_ins_del_lines (struct frame *f, int vpos, int n)
174{ 164{
175 int i, nb; 165 int i, nb;
176 SMALL_RECT scroll; 166 SMALL_RECT scroll;
177 COORD dest; 167 COORD dest;
178 CHAR_INFO fill; 168 CHAR_INFO fill;
179 struct frame * f = PICK_FRAME ();
180 169
181 if (n < 0) 170 if (n < 0)
182 { 171 {
@@ -213,8 +202,8 @@ w32con_ins_del_lines (int vpos, int n)
213 { 202 {
214 for (i = scroll.Bottom; i < dest.Y; i++) 203 for (i = scroll.Bottom; i < dest.Y; i++)
215 { 204 {
216 w32con_move_cursor (i, 0); 205 w32con_move_cursor (f, i, 0);
217 w32con_clear_end_of_line (FRAME_COLS (f)); 206 w32con_clear_end_of_line (f, FRAME_COLS (f));
218 } 207 }
219 } 208 }
220 } 209 }
@@ -226,8 +215,8 @@ w32con_ins_del_lines (int vpos, int n)
226 { 215 {
227 for (i = nb; i < scroll.Top; i++) 216 for (i = nb; i < scroll.Top; i++)
228 { 217 {
229 w32con_move_cursor (i, 0); 218 w32con_move_cursor (f, i, 0);
230 w32con_clear_end_of_line (FRAME_COLS (f)); 219 w32con_clear_end_of_line (f, FRAME_COLS (f));
231 } 220 }
232 } 221 }
233 } 222 }
@@ -242,14 +231,13 @@ w32con_ins_del_lines (int vpos, int n)
242#define RIGHT 0 231#define RIGHT 0
243 232
244static void 233static void
245scroll_line (int dist, int direction) 234scroll_line (struct frame *f, int dist, int direction)
246{ 235{
247 /* The idea here is to implement a horizontal scroll in one line to 236 /* The idea here is to implement a horizontal scroll in one line to
248 implement delete and half of insert. */ 237 implement delete and half of insert. */
249 SMALL_RECT scroll; 238 SMALL_RECT scroll;
250 COORD dest; 239 COORD dest;
251 CHAR_INFO fill; 240 CHAR_INFO fill;
252 struct frame * f = PICK_FRAME ();
253 241
254 scroll.Top = cursor_coords.Y; 242 scroll.Top = cursor_coords.Y;
255 scroll.Bottom = cursor_coords.Y; 243 scroll.Bottom = cursor_coords.Y;
@@ -277,9 +265,9 @@ scroll_line (int dist, int direction)
277 265
278/* If start is zero insert blanks instead of a string at start ?. */ 266/* If start is zero insert blanks instead of a string at start ?. */
279static void 267static void
280w32con_insert_glyphs (register struct glyph *start, register int len) 268w32con_insert_glyphs (struct frame *f, register struct glyph *start, register int len)
281{ 269{
282 scroll_line (len, RIGHT); 270 scroll_line (f, len, RIGHT);
283 271
284 /* Move len chars to the right starting at cursor_coords, fill with blanks */ 272 /* Move len chars to the right starting at cursor_coords, fill with blanks */
285 if (start) 273 if (start)
@@ -287,11 +275,11 @@ w32con_insert_glyphs (register struct glyph *start, register int len)
287 /* Print the first len characters of start, cursor_coords.X adjusted 275 /* Print the first len characters of start, cursor_coords.X adjusted
288 by write_glyphs. */ 276 by write_glyphs. */
289 277
290 w32con_write_glyphs (start, len); 278 w32con_write_glyphs (f, start, len);
291 } 279 }
292 else 280 else
293 { 281 {
294 w32con_clear_end_of_line (cursor_coords.X + len); 282 w32con_clear_end_of_line (f, cursor_coords.X + len);
295 } 283 }
296} 284}
297 285
@@ -299,11 +287,11 @@ extern unsigned char *encode_terminal_code P_ ((struct glyph *, int,
299 struct coding_system *)); 287 struct coding_system *));
300 288
301static void 289static void
302w32con_write_glyphs (register struct glyph *string, register int len) 290w32con_write_glyphs (struct frame *f, register struct glyph *string,
291 register int len)
303{ 292{
304 int produced, consumed; 293 int produced, consumed;
305 DWORD r; 294 DWORD r;
306 struct frame * f = PICK_FRAME ();
307 WORD char_attr; 295 WORD char_attr;
308 unsigned char *conversion_buffer; 296 unsigned char *conversion_buffer;
309 struct coding_system *coding; 297 struct coding_system *coding;
@@ -314,11 +302,11 @@ w32con_write_glyphs (register struct glyph *string, register int len)
314 /* If terminal_coding does any conversion, use it, otherwise use 302 /* If terminal_coding does any conversion, use it, otherwise use
315 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 303 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
316 because it always return 1 if the member src_multibyte is 1. */ 304 because it always return 1 if the member src_multibyte is 1. */
317 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 305 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
318 ? &terminal_coding : &safe_terminal_coding); 306 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
319 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 307 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
320 the tail. */ 308 the tail. */
321 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; 309 coding->mode &= ~CODING_MODE_LAST_BLOCK;
322 310
323 while (len > 0) 311 while (len > 0)
324 { 312 {
@@ -360,7 +348,7 @@ w32con_write_glyphs (register struct glyph *string, register int len)
360 } 348 }
361 349
362 cursor_coords.X += coding->produced; 350 cursor_coords.X += coding->produced;
363 w32con_move_cursor (cursor_coords.Y, cursor_coords.X); 351 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
364 } 352 }
365 len -= n; 353 len -= n;
366 string += n; 354 string += n;
@@ -369,20 +357,20 @@ w32con_write_glyphs (register struct glyph *string, register int len)
369 357
370 358
371static void 359static void
372w32con_delete_glyphs (int n) 360w32con_delete_glyphs (struct frame *f, int n)
373{ 361{
374 /* delete chars means scroll chars from cursor_coords.X + n to 362 /* delete chars means scroll chars from cursor_coords.X + n to
375 cursor_coords.X, anything beyond the edge of the screen should 363 cursor_coords.X, anything beyond the edge of the screen should
376 come out empty... */ 364 come out empty... */
377 365
378 scroll_line (n, LEFT); 366 scroll_line (f, n, LEFT);
379} 367}
380 368
381static unsigned int sound_type = 0xFFFFFFFF; 369static unsigned int sound_type = 0xFFFFFFFF;
382#define MB_EMACS_SILENT (0xFFFFFFFF - 1) 370#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
383 371
384void 372void
385w32_sys_ring_bell (void) 373w32_sys_ring_bell (struct frame *f)
386{ 374{
387 if (sound_type == 0xFFFFFFFF) 375 if (sound_type == 0xFFFFFFFF)
388 { 376 {
@@ -428,7 +416,7 @@ SOUND is nil to use the normal beep. */)
428} 416}
429 417
430static void 418static void
431w32con_reset_terminal_modes (void) 419w32con_reset_terminal_modes (struct terminal *t)
432{ 420{
433#ifdef USE_SEPARATE_SCREEN 421#ifdef USE_SEPARATE_SCREEN
434 SetConsoleActiveScreenBuffer (prev_screen); 422 SetConsoleActiveScreenBuffer (prev_screen);
@@ -439,7 +427,7 @@ w32con_reset_terminal_modes (void)
439} 427}
440 428
441static void 429static void
442w32con_set_terminal_modes (void) 430w32con_set_terminal_modes (struct terminal *t)
443{ 431{
444 CONSOLE_CURSOR_INFO cci; 432 CONSOLE_CURSOR_INFO cci;
445 433
@@ -473,7 +461,7 @@ w32con_update_end (struct frame * f)
473} 461}
474 462
475static void 463static void
476w32con_set_terminal_window (int size) 464w32con_set_terminal_window (struct frame *f, int size)
477{ 465{
478} 466}
479 467
@@ -546,29 +534,34 @@ vga_stdcolor_name (int idx)
546 534
547typedef int (*term_hook) (); 535typedef int (*term_hook) ();
548 536
537/* TEMPORARY HACK to get w32console compiling. To support multiple consoles,
538 this needs to go! */
539struct terminal one_and_only_w32cons;
540
549void 541void
550initialize_w32_display (void) 542initialize_w32_display (void)
551{ 543{
552 CONSOLE_SCREEN_BUFFER_INFO info; 544 CONSOLE_SCREEN_BUFFER_INFO info;
553 545 struct terminal *term = &one_and_only_w32cons;
554 cursor_to_hook = w32con_move_cursor; 546
555 raw_cursor_to_hook = w32con_move_cursor; 547 term->cursor_to_hook = w32con_move_cursor;
556 clear_to_end_hook = w32con_clear_to_end; 548 term->raw_cursor_to_hook = w32con_move_cursor;
557 clear_frame_hook = w32con_clear_frame; 549 term->clear_to_end_hook = w32con_clear_to_end;
558 clear_end_of_line_hook = w32con_clear_end_of_line; 550 term->clear_frame_hook = w32con_clear_frame;
559 ins_del_lines_hook = w32con_ins_del_lines; 551 term->clear_end_of_line_hook = w32con_clear_end_of_line;
560 insert_glyphs_hook = w32con_insert_glyphs; 552 term->ins_del_lines_hook = w32con_ins_del_lines;
561 write_glyphs_hook = w32con_write_glyphs; 553 term->insert_glyphs_hook = w32con_insert_glyphs;
562 delete_glyphs_hook = w32con_delete_glyphs; 554 term->write_glyphs_hook = w32con_write_glyphs;
563 ring_bell_hook = w32_sys_ring_bell; 555 term->delete_glyphs_hook = w32con_delete_glyphs;
564 reset_terminal_modes_hook = w32con_reset_terminal_modes; 556 term->ring_bell_hook = w32_sys_ring_bell;
565 set_terminal_modes_hook = w32con_set_terminal_modes; 557 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
566 set_terminal_window_hook = w32con_set_terminal_window; 558 term->set_terminal_modes_hook = w32con_set_terminal_modes;
567 update_begin_hook = w32con_update_begin; 559 term->set_terminal_window_hook = w32con_set_terminal_window;
568 update_end_hook = w32con_update_end; 560 term->update_begin_hook = w32con_update_begin;
569 561 term->update_end_hook = w32con_update_end;
570 read_socket_hook = w32_console_read_socket; 562
571 mouse_position_hook = w32_console_mouse_position; 563 term->read_socket_hook = w32_console_read_socket;
564 term->mouse_position_hook = w32_console_mouse_position;
572 565
573 /* Initialize interrupt_handle. */ 566 /* Initialize interrupt_handle. */
574 init_crit (); 567 init_crit ();
@@ -633,7 +626,6 @@ initialize_w32_display (void)
633 626
634 GetConsoleScreenBufferInfo (cur_screen, &info); 627 GetConsoleScreenBufferInfo (cur_screen, &info);
635 628
636 meta_key = 1;
637 char_attr_normal = info.wAttributes; 629 char_attr_normal = info.wAttributes;
638 630
639 /* Determine if the info returned by GetConsoleScreenBufferInfo 631 /* Determine if the info returned by GetConsoleScreenBufferInfo
@@ -674,6 +666,25 @@ initialize_w32_display (void)
674 666
675} 667}
676 668
669/* Initialize the tty-dependent part of frame F. The frame must
670 already have its device initialized. */
671void
672create_w32cons_output(struct frame *f)
673{
674 struct tty_output *tty;
675
676 if (! FRAME_TERMCAP_P (f))
677 abort ();
678
679 tty = xmalloc (sizeof (struct tty_output));
680 bzero (tty, sizeof (struct tty_output));
681
682 tty->display_info = FRAME_TERMINAL (f)->display_info.tty;
683 tty->display_info->meta_key = 1;
684
685 f->output_data.tty = tty;
686}
687
677DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0, 688DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
678 doc: /* Set screen colors. */) 689 doc: /* Set screen colors. */)
679 (foreground, background) 690 (foreground, background)