Mercurial > emacs
comparison src/w32console.c @ 91204:53108e6cea98
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-294
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 06 Dec 2007 09:51:45 +0000 |
parents | bdb3fe0ba9fa 0f135bf21932 |
children | 606f2d163a64 |
comparison
equal
deleted
inserted
replaced
91203:db40129142b2 | 91204:53108e6cea98 |
---|---|
33 | 33 |
34 #include "lisp.h" | 34 #include "lisp.h" |
35 #include "character.h" | 35 #include "character.h" |
36 #include "coding.h" | 36 #include "coding.h" |
37 #include "disptab.h" | 37 #include "disptab.h" |
38 /* Disable features in frame.h that require a Window System. */ | |
39 #undef HAVE_WINDOW_SYSTEM | |
40 #include "frame.h" | 38 #include "frame.h" |
41 #include "termhooks.h" | 39 #include "termhooks.h" |
42 #include "termchar.h" | 40 #include "termchar.h" |
43 #include "dispextern.h" | 41 #include "dispextern.h" |
44 #include "w32inevt.h" | 42 #include "w32inevt.h" |
74 | 72 |
75 #ifndef USE_SEPARATE_SCREEN | 73 #ifndef USE_SEPARATE_SCREEN |
76 static CONSOLE_CURSOR_INFO prev_console_cursor; | 74 static CONSOLE_CURSOR_INFO prev_console_cursor; |
77 #endif | 75 #endif |
78 | 76 |
77 extern Lisp_Object Vtty_defined_color_alist; | |
78 | |
79 /* Determine whether to make frame dimensions match the screen buffer, | 79 /* Determine whether to make frame dimensions match the screen buffer, |
80 or the current window size. The former is desirable when running | 80 or the current window size. The former is desirable when running |
81 over telnet, while the latter is more useful when working directly at | 81 over telnet, while the latter is more useful when working directly at |
82 the console with a large scroll-back buffer. */ | 82 the console with a large scroll-back buffer. */ |
83 int w32_use_full_screen_buffer; | 83 int w32_use_full_screen_buffer; |
162 static void | 162 static void |
163 w32con_ins_del_lines (struct frame *f, int vpos, int n) | 163 w32con_ins_del_lines (struct frame *f, int vpos, int n) |
164 { | 164 { |
165 int i, nb; | 165 int i, nb; |
166 SMALL_RECT scroll; | 166 SMALL_RECT scroll; |
167 SMALL_RECT clip; | |
167 COORD dest; | 168 COORD dest; |
168 CHAR_INFO fill; | 169 CHAR_INFO fill; |
169 | 170 |
170 if (n < 0) | 171 if (n < 0) |
171 { | 172 { |
177 { | 178 { |
178 scroll.Top = vpos; | 179 scroll.Top = vpos; |
179 scroll.Bottom = FRAME_LINES (f) - n; | 180 scroll.Bottom = FRAME_LINES (f) - n; |
180 dest.Y = vpos + n; | 181 dest.Y = vpos + n; |
181 } | 182 } |
182 scroll.Left = 0; | 183 clip.Top = clip.Left = scroll.Left = 0; |
183 scroll.Right = FRAME_COLS (f); | 184 clip.Right = scroll.Right = FRAME_COLS (f); |
185 clip.Bottom = FRAME_LINES (f); | |
184 | 186 |
185 dest.X = 0; | 187 dest.X = 0; |
186 | 188 |
187 fill.Char.AsciiChar = 0x20; | 189 fill.Char.AsciiChar = 0x20; |
188 fill.Attributes = char_attr_normal; | 190 fill.Attributes = char_attr_normal; |
189 | 191 |
190 ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); | 192 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill); |
191 | 193 |
192 /* Here we have to deal with a w32 console flake: If the scroll | 194 /* Here we have to deal with a w32 console flake: If the scroll |
193 region looks like abc and we scroll c to a and fill with d we get | 195 region looks like abc and we scroll c to a and fill with d we get |
194 cbd... if we scroll block c one line at a time to a, we get cdd... | 196 cbd... if we scroll block c one line at a time to a, we get cdd... |
195 Emacs expects cdd consistently... So we have to deal with that | 197 Emacs expects cdd consistently... So we have to deal with that |
233 static void | 235 static void |
234 scroll_line (struct frame *f, int dist, int direction) | 236 scroll_line (struct frame *f, int dist, int direction) |
235 { | 237 { |
236 /* The idea here is to implement a horizontal scroll in one line to | 238 /* The idea here is to implement a horizontal scroll in one line to |
237 implement delete and half of insert. */ | 239 implement delete and half of insert. */ |
238 SMALL_RECT scroll; | 240 SMALL_RECT scroll, clip; |
239 COORD dest; | 241 COORD dest; |
240 CHAR_INFO fill; | 242 CHAR_INFO fill; |
241 | 243 |
242 scroll.Top = cursor_coords.Y; | 244 clip.Top = scroll.Top = clip.Bottom = scroll.Bottom = cursor_coords.Y; |
243 scroll.Bottom = cursor_coords.Y; | 245 clip.Left = 0; |
246 clip.Right = FRAME_COLS (f); | |
244 | 247 |
245 if (direction == LEFT) | 248 if (direction == LEFT) |
246 { | 249 { |
247 scroll.Left = cursor_coords.X + dist; | 250 scroll.Left = cursor_coords.X + dist; |
248 scroll.Right = FRAME_COLS (f) - 1; | 251 scroll.Right = FRAME_COLS (f) - 1; |
257 dest.Y = cursor_coords.Y; | 260 dest.Y = cursor_coords.Y; |
258 | 261 |
259 fill.Char.AsciiChar = 0x20; | 262 fill.Char.AsciiChar = 0x20; |
260 fill.Attributes = char_attr_normal; | 263 fill.Attributes = char_attr_normal; |
261 | 264 |
262 ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); | 265 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill); |
263 } | 266 } |
264 | 267 |
265 | 268 |
266 /* If start is zero insert blanks instead of a string at start ?. */ | 269 /* If start is zero insert blanks instead of a string at start ?. */ |
267 static void | 270 static void |
288 | 291 |
289 static void | 292 static void |
290 w32con_write_glyphs (struct frame *f, register struct glyph *string, | 293 w32con_write_glyphs (struct frame *f, register struct glyph *string, |
291 register int len) | 294 register int len) |
292 { | 295 { |
293 int produced, consumed; | |
294 DWORD r; | 296 DWORD r; |
295 WORD char_attr; | 297 WORD char_attr; |
296 unsigned char *conversion_buffer; | 298 unsigned char *conversion_buffer; |
297 struct coding_system *coding; | 299 struct coding_system *coding; |
298 | 300 |
416 } | 418 } |
417 | 419 |
418 static void | 420 static void |
419 w32con_reset_terminal_modes (struct terminal *t) | 421 w32con_reset_terminal_modes (struct terminal *t) |
420 { | 422 { |
423 COORD dest; | |
424 CONSOLE_SCREEN_BUFFER_INFO info; | |
425 int n; | |
426 DWORD r; | |
427 | |
428 /* Clear the complete screen buffer. This is required because Emacs | |
429 sets the cursor position to the top of the buffer, but there might | |
430 be other output below the bottom of the Emacs frame if the screen buffer | |
431 is larger than the window size. */ | |
432 GetConsoleScreenBufferInfo (cur_screen, &info); | |
433 dest.X = 0; | |
434 dest.Y = 0; | |
435 n = info.dwSize.X * info.dwSize.Y; | |
436 | |
437 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r); | |
438 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r); | |
439 /* Now that the screen is clear, put the cursor at the top. */ | |
440 SetConsoleCursorPosition (cur_screen, dest); | |
441 | |
421 #ifdef USE_SEPARATE_SCREEN | 442 #ifdef USE_SEPARATE_SCREEN |
422 SetConsoleActiveScreenBuffer (prev_screen); | 443 SetConsoleActiveScreenBuffer (prev_screen); |
423 #else | 444 #else |
424 SetConsoleCursorInfo (prev_screen, &prev_console_cursor); | 445 SetConsoleCursorInfo (prev_screen, &prev_console_cursor); |
425 #endif | 446 #endif |
447 | |
426 SetConsoleMode (keyboard_handle, prev_console_mode); | 448 SetConsoleMode (keyboard_handle, prev_console_mode); |
427 } | 449 } |
428 | 450 |
429 static void | 451 static void |
430 w32con_set_terminal_modes (struct terminal *t) | 452 w32con_set_terminal_modes (struct terminal *t) |
482 | 504 |
483 xassert (face != NULL); | 505 xassert (face != NULL); |
484 | 506 |
485 char_attr = char_attr_normal; | 507 char_attr = char_attr_normal; |
486 | 508 |
487 if (face->foreground != FACE_TTY_DEFAULT_FG_COLOR | 509 /* Reverse the default color if requested. If background and |
488 && face->foreground != FACE_TTY_DEFAULT_COLOR) | 510 foreground are specified, then they have been reversed already. */ |
489 char_attr = (char_attr & 0xfff0) + (face->foreground % 16); | |
490 | |
491 if (face->background != FACE_TTY_DEFAULT_BG_COLOR | |
492 && face->background != FACE_TTY_DEFAULT_COLOR) | |
493 char_attr = (char_attr & 0xff0f) + ((face->background % 16) << 4); | |
494 | |
495 | |
496 /* NTEMACS_TODO: Faces defined during startup get both foreground | |
497 and background of 0. Need a better way around this - for now detect | |
498 the problem and invert one of the faces to make the text readable. */ | |
499 if (((char_attr & 0x00f0) >> 4) == (char_attr & 0x000f)) | |
500 char_attr ^= 0x0007; | |
501 | |
502 if (face->tty_reverse_p) | 511 if (face->tty_reverse_p) |
503 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4) | 512 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4) |
504 + ((char_attr & 0x00f0) >> 4); | 513 + ((char_attr & 0x00f0) >> 4); |
505 | 514 |
515 /* Before the terminal is properly initialized, all colors map to 0. | |
516 Don't try to resolve them. */ | |
517 if (NILP (Vtty_defined_color_alist)) | |
518 return char_attr; | |
519 | |
520 /* Colors should be in the range 0...15 unless they are one of | |
521 FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or | |
522 FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are | |
523 invalid, so it is better to use the default color if they ever | |
524 get through to here. */ | |
525 if (face->foreground >= 0 && face->foreground < 16) | |
526 char_attr = (char_attr & 0xfff0) + face->foreground; | |
527 | |
528 if (face->background >= 0 && face->background < 16) | |
529 char_attr = (char_attr & 0xff0f) + (face->background << 4); | |
530 | |
506 return char_attr; | 531 return char_attr; |
507 } | 532 } |
508 | 533 |
509 | |
510 /* Emulation of some X window features from xfns.c and xfaces.c. */ | |
511 | |
512 extern char unspecified_fg[], unspecified_bg[]; | |
513 | 534 |
514 | 535 |
515 /* Given a color index, return its standard name. */ | 536 /* Given a color index, return its standard name. */ |
516 Lisp_Object | 537 Lisp_Object |
517 vga_stdcolor_name (int idx) | 538 vga_stdcolor_name (int idx) |