diff options
| author | Jason Rumney | 2000-01-30 18:53:22 +0000 |
|---|---|---|
| committer | Jason Rumney | 2000-01-30 18:53:22 +0000 |
| commit | 338b1bb23dc6c3a2f07927842cc70a15e2e3dcfb (patch) | |
| tree | a67dc685411571413e79216c9b99b79288c5c991 /src | |
| parent | c03fb88c2754f1aee3de3ad0010f4589cf17cf85 (diff) | |
| download | emacs-338b1bb23dc6c3a2f07927842cc70a15e2e3dcfb.tar.gz emacs-338b1bb23dc6c3a2f07927842cc70a15e2e3dcfb.zip | |
(turn_on_face, turn_off_face): Removed.
(w32_face_attributes): New function.
(Global_variables): Reduce scope where possible.
(clear_frame, ins_del_lines, scroll_line): Use char_attr_normal as
fill attribute.
(hl_mode): Don't modify text attributes.
(write_glyphs): Don't do anything if len <= 0. Use
w32_face_attributes to get attributes for drawing. Write
terminating codes using char_attr_normal.
(reset_terminal_modes, set_terminal_modes): Turn off highlight.
(update_begin, update_end): Likewise.
(vga_stdcolor_name): New function.
(initialize_w32_display): Remove char_attr_reverse and char_attr.
(Fset_screen_color): Remove char_attr_reverse.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32console.c | 124 |
1 files changed, 73 insertions, 51 deletions
diff --git a/src/w32console.c b/src/w32console.c index 187e3e9852b..f067501f71b 100644 --- a/src/w32console.c +++ b/src/w32console.c | |||
| @@ -28,11 +28,11 @@ Boston, MA 02111-1307, USA. | |||
| 28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> | 29 | #include <stdio.h> |
| 30 | #include <windows.h> | 30 | #include <windows.h> |
| 31 | #include <string.h> | ||
| 31 | 32 | ||
| 32 | /* Disable features in headers that require a Window System for | 33 | /* Disable features in headers that require a Window System for |
| 33 | console mode. */ | 34 | console mode. */ |
| 34 | #undef HAVE_WINDOW_SYSTEM | 35 | #undef HAVE_WINDOW_SYSTEM |
| 35 | |||
| 36 | #include "lisp.h" | 36 | #include "lisp.h" |
| 37 | #include "charset.h" | 37 | #include "charset.h" |
| 38 | #include "coding.h" | 38 | #include "coding.h" |
| @@ -70,18 +70,16 @@ static void set_terminal_modes (void); | |||
| 70 | static void set_terminal_window (int size); | 70 | static void set_terminal_window (int size); |
| 71 | static void update_begin (struct frame * f); | 71 | static void update_begin (struct frame * f); |
| 72 | static void update_end (struct frame * f); | 72 | static void update_end (struct frame * f); |
| 73 | static int hl_mode (int new_highlight); | 73 | static WORD w32_face_attributes (struct frame *f, int face_id); |
| 74 | static void turn_on_face P_ ((struct frame *, int face_id)); | 74 | static int hl_mode (int new_highlight); |
| 75 | static void turn_off_face P_ ((struct frame *, int face_id)); | ||
| 76 | 75 | ||
| 77 | COORD cursor_coords; | 76 | static COORD cursor_coords; |
| 78 | HANDLE prev_screen, cur_screen; | 77 | static HANDLE prev_screen, cur_screen; |
| 79 | UCHAR char_attr, char_attr_normal, char_attr_reverse; | 78 | static WORD char_attr_normal; |
| 80 | HANDLE keyboard_handle; | 79 | static DWORD prev_console_mode; |
| 81 | DWORD prev_console_mode; | ||
| 82 | 80 | ||
| 83 | #ifndef USE_SEPARATE_SCREEN | 81 | #ifndef USE_SEPARATE_SCREEN |
| 84 | CONSOLE_CURSOR_INFO prev_console_cursor; | 82 | static CONSOLE_CURSOR_INFO prev_console_cursor; |
| 85 | #endif | 83 | #endif |
| 86 | 84 | ||
| 87 | /* Determine whether to make frame dimensions match the screen buffer, | 85 | /* Determine whether to make frame dimensions match the screen buffer, |
| @@ -89,6 +87,7 @@ CONSOLE_CURSOR_INFO prev_console_cursor; | |||
| 89 | over telnet, while the latter is more useful when working directly at | 87 | over telnet, while the latter is more useful when working directly at |
| 90 | the console with a large scroll-back buffer. */ | 88 | the console with a large scroll-back buffer. */ |
| 91 | int w32_use_full_screen_buffer; | 89 | int w32_use_full_screen_buffer; |
| 90 | HANDLE keyboard_handle; | ||
| 92 | 91 | ||
| 93 | 92 | ||
| 94 | /* Setting this as the ctrl handler prevents emacs from being killed when | 93 | /* Setting this as the ctrl handler prevents emacs from being killed when |
| @@ -142,12 +141,12 @@ clear_frame (void) | |||
| 142 | GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info); | 141 | GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info); |
| 143 | 142 | ||
| 144 | hl_mode (0); | 143 | hl_mode (0); |
| 145 | 144 | ||
| 146 | /* Remember that the screen buffer might be wider than the window. */ | 145 | /* Remember that the screen buffer might be wider than the window. */ |
| 147 | n = FRAME_HEIGHT (f) * info.dwSize.X; | 146 | n = FRAME_HEIGHT (f) * info.dwSize.X; |
| 148 | dest.X = dest.Y = 0; | 147 | dest.X = dest.Y = 0; |
| 149 | 148 | ||
| 150 | FillConsoleOutputAttribute (cur_screen, char_attr, n, dest, &r); | 149 | FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r); |
| 151 | FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r); | 150 | FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r); |
| 152 | 151 | ||
| 153 | move_cursor (0, 0); | 152 | move_cursor (0, 0); |
| @@ -203,7 +202,7 @@ ins_del_lines (int vpos, int n) | |||
| 203 | save_highlight = hl_mode (0); | 202 | save_highlight = hl_mode (0); |
| 204 | 203 | ||
| 205 | fill.Char.AsciiChar = 0x20; | 204 | fill.Char.AsciiChar = 0x20; |
| 206 | fill.Attributes = char_attr; | 205 | fill.Attributes = char_attr_normal; |
| 207 | 206 | ||
| 208 | ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); | 207 | ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); |
| 209 | 208 | ||
| @@ -254,14 +253,7 @@ hl_mode (int new_highlight) | |||
| 254 | 253 | ||
| 255 | old_highlight = highlight; | 254 | old_highlight = highlight; |
| 256 | highlight = (new_highlight != 0); | 255 | highlight = (new_highlight != 0); |
| 257 | if (highlight) | 256 | |
| 258 | { | ||
| 259 | char_attr = char_attr_reverse; | ||
| 260 | } | ||
| 261 | else | ||
| 262 | { | ||
| 263 | char_attr = char_attr_normal; | ||
| 264 | } | ||
| 265 | return old_highlight; | 257 | return old_highlight; |
| 266 | } | 258 | } |
| 267 | 259 | ||
| @@ -318,8 +310,8 @@ scroll_line (int dist, int direction) | |||
| 318 | dest.Y = cursor_coords.Y; | 310 | dest.Y = cursor_coords.Y; |
| 319 | 311 | ||
| 320 | fill.Char.AsciiChar = 0x20; | 312 | fill.Char.AsciiChar = 0x20; |
| 321 | fill.Attributes = char_attr; | 313 | fill.Attributes = char_attr_normal; |
| 322 | 314 | ||
| 323 | ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); | 315 | ScrollConsoleScreenBuffer (cur_screen, &scroll, NULL, dest, &fill); |
| 324 | } | 316 | } |
| 325 | 317 | ||
| @@ -349,6 +341,10 @@ write_glyphs (register struct glyph *string, register int len) | |||
| 349 | { | 341 | { |
| 350 | int produced, consumed, i; | 342 | int produced, consumed, i; |
| 351 | struct frame * f = PICK_FRAME (); | 343 | struct frame * f = PICK_FRAME (); |
| 344 | WORD char_attr; | ||
| 345 | |||
| 346 | if (len <= 0) | ||
| 347 | return; | ||
| 352 | 348 | ||
| 353 | /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at | 349 | /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at |
| 354 | the tail. */ | 350 | the tail. */ |
| @@ -365,7 +361,7 @@ write_glyphs (register struct glyph *string, register int len) | |||
| 365 | break; | 361 | break; |
| 366 | 362 | ||
| 367 | /* Turn appearance modes of the face of the run on. */ | 363 | /* Turn appearance modes of the face of the run on. */ |
| 368 | turn_on_face (f, face_id); | 364 | char_attr = w32_face_attributes (f, face_id); |
| 369 | 365 | ||
| 370 | while (n > 0) | 366 | while (n > 0) |
| 371 | { | 367 | { |
| @@ -402,9 +398,6 @@ write_glyphs (register struct glyph *string, register int len) | |||
| 402 | n -= consumed; | 398 | n -= consumed; |
| 403 | string += consumed; | 399 | string += consumed; |
| 404 | } | 400 | } |
| 405 | |||
| 406 | /* Turn appearance modes off. */ | ||
| 407 | turn_off_face (f, face_id); | ||
| 408 | } | 401 | } |
| 409 | 402 | ||
| 410 | /* We may have to output some codes to terminate the writing. */ | 403 | /* We may have to output some codes to terminate the writing. */ |
| @@ -415,7 +408,7 @@ write_glyphs (register struct glyph *string, register int len) | |||
| 415 | 0, conversion_buffer_size); | 408 | 0, conversion_buffer_size); |
| 416 | if (terminal_coding.produced > 0) | 409 | if (terminal_coding.produced > 0) |
| 417 | { | 410 | { |
| 418 | if (!FillConsoleOutputAttribute (cur_screen, char_attr, | 411 | if (!FillConsoleOutputAttribute (cur_screen, char_attr_normal, |
| 419 | terminal_coding.produced, | 412 | terminal_coding.produced, |
| 420 | cursor_coords, &i)) | 413 | cursor_coords, &i)) |
| 421 | { | 414 | { |
| @@ -499,6 +492,8 @@ SOUND is nil to use the normal beep.") | |||
| 499 | void | 492 | void |
| 500 | reset_terminal_modes (void) | 493 | reset_terminal_modes (void) |
| 501 | { | 494 | { |
| 495 | hl_mode (0); | ||
| 496 | |||
| 502 | #ifdef USE_SEPARATE_SCREEN | 497 | #ifdef USE_SEPARATE_SCREEN |
| 503 | SetConsoleActiveScreenBuffer (prev_screen); | 498 | SetConsoleActiveScreenBuffer (prev_screen); |
| 504 | #else | 499 | #else |
| @@ -512,6 +507,8 @@ set_terminal_modes (void) | |||
| 512 | { | 507 | { |
| 513 | CONSOLE_CURSOR_INFO cci; | 508 | CONSOLE_CURSOR_INFO cci; |
| 514 | 509 | ||
| 510 | hl_mode (0); | ||
| 511 | |||
| 515 | /* make cursor big and visible (100 on Win95 makes it disappear) */ | 512 | /* make cursor big and visible (100 on Win95 makes it disappear) */ |
| 516 | cci.dwSize = 99; | 513 | cci.dwSize = 99; |
| 517 | cci.bVisible = TRUE; | 514 | cci.bVisible = TRUE; |
| @@ -533,11 +530,13 @@ set_terminal_modes (void) | |||
| 533 | void | 530 | void |
| 534 | update_begin (struct frame * f) | 531 | update_begin (struct frame * f) |
| 535 | { | 532 | { |
| 533 | hl_mode (0); | ||
| 536 | } | 534 | } |
| 537 | 535 | ||
| 538 | void | 536 | void |
| 539 | update_end (struct frame * f) | 537 | update_end (struct frame * f) |
| 540 | { | 538 | { |
| 539 | hl_mode (0); | ||
| 541 | SetConsoleCursorPosition (cur_screen, cursor_coords); | 540 | SetConsoleCursorPosition (cur_screen, cursor_coords); |
| 542 | } | 541 | } |
| 543 | 542 | ||
| @@ -553,43 +552,68 @@ set_terminal_window (int size) | |||
| 553 | 552 | ||
| 554 | /* Turn appearances of face FACE_ID on tty frame F on. */ | 553 | /* Turn appearances of face FACE_ID on tty frame F on. */ |
| 555 | 554 | ||
| 556 | static void | 555 | static WORD |
| 557 | turn_on_face (f, face_id) | 556 | w32_face_attributes (f, face_id) |
| 558 | struct frame *f; | 557 | struct frame *f; |
| 559 | int face_id; | 558 | int face_id; |
| 560 | { | 559 | { |
| 560 | WORD char_attr; | ||
| 561 | int highlight_on_p; | ||
| 561 | struct face *face = FACE_FROM_ID (f, face_id); | 562 | struct face *face = FACE_FROM_ID (f, face_id); |
| 562 | 563 | ||
| 564 | highlight_on_p = hl_mode (0); | ||
| 565 | hl_mode (highlight_on_p); | ||
| 566 | |||
| 563 | xassert (face != NULL); | 567 | xassert (face != NULL); |
| 564 | 568 | ||
| 565 | char_attr = char_attr_normal; | 569 | char_attr = char_attr_normal; |
| 566 | 570 | ||
| 567 | if (face->foreground != FACE_TTY_DEFAULT_COLOR) | 571 | if (face->foreground != FACE_TTY_DEFAULT_FG_COLOR |
| 568 | char_attr = (char_attr & 0xf0) + face->foreground; | 572 | && face->foreground != FACE_TTY_DEFAULT_COLOR) |
| 573 | char_attr = (char_attr & 0xfff0) + (face->foreground % 16); | ||
| 574 | |||
| 575 | if (face->background != FACE_TTY_DEFAULT_BG_COLOR | ||
| 576 | && face->background != FACE_TTY_DEFAULT_COLOR) | ||
| 577 | char_attr = (char_attr & 0xff0f) + ((face->background % 16) * 16); | ||
| 578 | |||
| 569 | 579 | ||
| 570 | if (face->background != FACE_TTY_DEFAULT_COLOR) | 580 | /* Ensure readability (temporary measure until this all works) */ |
| 571 | char_attr = (face->background << 4) + char_attr & 0x0f; | 581 | if (((char_attr & 0x00f0) >> 4) == (char_attr & 0x000f)) |
| 582 | char_attr ^= 0x0007; | ||
| 572 | 583 | ||
| 573 | if (face->tty_reverse_p) | 584 | if (face->tty_reverse_p || highlight_on_p) |
| 574 | char_attr = ((char_attr & 0x0f) << 4) + ((char_attr & 0xf0) >> 4); | 585 | char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4) |
| 586 | + ((char_attr & 0x00f0) >> 4); | ||
| 575 | 587 | ||
| 576 | /* Ensure readability */ | 588 | return char_attr; |
| 577 | if (((char_attr & 0xf0) >> 4) == (char_attr * 0x0f)) | ||
| 578 | char_attr ^= 0x0f; | ||
| 579 | } | 589 | } |
| 580 | 590 | ||
| 581 | 591 | ||
| 582 | /* Turn off appearances of face FACE_ID on tty frame F. */ | 592 | /* Emulation of some X window features from xfns.c and xfaces.c. */ |
| 583 | 593 | ||
| 584 | static void | 594 | extern char unspecified_fg[], unspecified_bg[]; |
| 585 | turn_off_face (f, face_id) | 595 | |
| 586 | struct frame *f; | 596 | |
| 587 | int face_id; | 597 | /* Given a color index, return its standard name. */ |
| 598 | Lisp_Object | ||
| 599 | vga_stdcolor_name (int idx) | ||
| 588 | { | 600 | { |
| 589 | if (hl_mode (0)) | 601 | /* Standard VGA colors, in the order of their standard numbering |
| 590 | hl_mode (1); | 602 | in the default VGA palette. */ |
| 603 | static char *vga_colors[16] = { | ||
| 604 | "black", "blue", "green", "cyan", "red", "magenta", "brown", | ||
| 605 | "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan", | ||
| 606 | "lightred", "lightmagenta", "yellow", "white" | ||
| 607 | }; | ||
| 608 | |||
| 609 | extern Lisp_Object Qunspecified; | ||
| 610 | |||
| 611 | if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0])) | ||
| 612 | return build_string (vga_colors[idx]); | ||
| 613 | else | ||
| 614 | return Qunspecified; /* meaning the default */ | ||
| 591 | } | 615 | } |
| 592 | 616 | ||
| 593 | typedef int (*term_hook) (); | 617 | typedef int (*term_hook) (); |
| 594 | 618 | ||
| 595 | void | 619 | void |
| @@ -683,9 +707,8 @@ initialize_w32_display (void) | |||
| 683 | GetConsoleScreenBufferInfo (cur_screen, &info); | 707 | GetConsoleScreenBufferInfo (cur_screen, &info); |
| 684 | 708 | ||
| 685 | meta_key = 1; | 709 | meta_key = 1; |
| 686 | char_attr = info.wAttributes & 0xFF; | 710 | char_attr_normal = info.wAttributes; |
| 687 | char_attr_normal = char_attr; | 711 | hl_mode (0); |
| 688 | char_attr_reverse = ((char_attr & 0xf) << 4) + ((char_attr & 0xf0) >> 4); | ||
| 689 | 712 | ||
| 690 | if (w32_use_full_screen_buffer) | 713 | if (w32_use_full_screen_buffer) |
| 691 | { | 714 | { |
| @@ -710,7 +733,6 @@ DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0, | |||
| 710 | Lisp_Object background; | 733 | Lisp_Object background; |
| 711 | { | 734 | { |
| 712 | char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4); | 735 | char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4); |
| 713 | char_attr_reverse = XFASTINT (background) + (XFASTINT (foreground) << 4); | ||
| 714 | 736 | ||
| 715 | Frecenter (Qnil); | 737 | Frecenter (Qnil); |
| 716 | return Qt; | 738 | return Qt; |