]> code.delx.au - gnu-emacs/blobdiff - src/w32console.c
(Fbyte_code): Harmonize arguments with documentation.
[gnu-emacs] / src / w32console.c
index 53e8e2cbcdaf1b52a328ac31206be290e1a022a6..f7dc3ab27ed10de871f1ec8c184e4b3d5c5cee33 100644 (file)
 */
 
 
+#include <config.h>
+
 #include <stdlib.h>
 #include <stdio.h>
-
-#include "config.h"
-
 #include <windows.h>
 
 #include "lisp.h"
@@ -36,7 +35,7 @@
 
 #include "ntinevt.h"
 
-/* frrom window.c */
+/* from window.c */
 extern Lisp_Object Frecenter ();
 
 /* from keyboard.c */
@@ -58,7 +57,7 @@ static void reassert_line_highlight (int, int);
 static void insert_glyphs (GLYPH *start, int len);
 static void write_glyphs (GLYPH *string, int len);
 static void delete_glyphs (int n);
-static void ring_bell (void);
+void nt_ring_bell (void);
 static void reset_terminal_modes (void);
 static void set_terminal_modes (void);
 static void set_terminal_window (int size);
@@ -83,11 +82,13 @@ HANDLE  keyboard_handle;
 
 
 /* Setting this as the ctrl handler prevents emacs from being killed when
- * someone hits ^C in a 'suspended' session (child shell).  */
+   someone hits ^C in a 'suspended' session (child shell).
+   Also ignore Ctrl-Break signals.  */
+
 BOOL
 ctrl_c_handler (unsigned long type)
 {
-  return (type == CTRL_C_EVENT) ? TRUE : FALSE;
+  return (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT);
 }
 
 /* If we're updating a frame, use it as the current frame
@@ -101,7 +102,7 @@ move_cursor (int row, int col)
   cursor_coords.X = col;
   cursor_coords.Y = row;
   
-  if (updating_frame == NULL)
+  if (updating_frame == (FRAME_PTR) NULL)
     {
       SetConsoleCursorPosition (cur_screen, cursor_coords);
     }
@@ -366,8 +367,10 @@ write_glyphs (register GLYPH *string, register int len)
          continue;
        }
       GLYPH_FOLLOW_ALIASES (glyph_table, glyph_len, glyph);
+#ifndef HAVE_NTGUI
       if (GLYPH_FACE (fixfix, glyph) != 0)
        printf ("Glyph face is %d\n", GLYPH_FACE (fixfix, glyph));
+#endif /* !HAVE_NTGUI */
       if (GLYPH_SIMPLE_P (glyph_table, glyph_len, glyph))
         {
          *ptr++ = glyph & 0xFF;
@@ -383,19 +386,20 @@ write_glyphs (register GLYPH *string, register int len)
   len = ptr-chars;
   
   /* Fill in the attributes for these characters.  */
-  memset (attrs, char_attr, len*sizeof (*attrs));
+  for (i = 0; i < len; i++)
+    attrs[i] = char_attr;
   
   /* Write the attributes.  */
   if (!WriteConsoleOutputAttribute (cur_screen, attrs, len, cursor_coords, &i))
     {
-      printf ("Failed writing console attributes.\n");
+      printf ("Failed writing console attributes: %d\n", GetLastError ());
       fflush (stdout);
     }
 
   /* Write the characters.  */
   if (!WriteConsoleOutputCharacter (cur_screen, chars, len, cursor_coords, &i))
     {
-      printf ("Failed writing console characters.\n");
+      printf ("Failed writing console characters: %d\n", GetLastError ());
       fflush (stdout);
     }
   
@@ -413,19 +417,43 @@ delete_glyphs (int n)
   scroll_line (n, LEFT);
 }
 
+static unsigned int sound_type = 0xFFFFFFFF;
+
 void
-ring_bell (void)
+nt_ring_bell (void)
 {
-  Beep (666, 100);
+  if (sound_type == 0xFFFFFFFF) 
+      Beep (666, 100);
+  else
+      MessageBeep (sound_type);
 }
 
-/* Reset to the original console mode but don't get rid of our console
-   For suspending emacs.  */
-void
-restore_console (void)
+DEFUN ("set-message-beep", Fset_message_beep, Sset_message_beep, 1, 1, 0,
+       "Set the sound generated when the bell is rung.\n\
+SOUND is 'asterisk, 'exclamation, 'hand, 'question, or 'ok\n\
+to use the corresponding system sound for the bell.\n\
+SOUND is nil to use the normal beep.")
+     (sound)
+     Lisp_Object sound;
 {
-  unset_kbd ();
-  SetConsoleActiveScreenBuffer (prev_screen);
+  CHECK_SYMBOL (sound, 0);
+
+  if (NILP (sound)) 
+      sound_type = 0xFFFFFFFF;
+  else if (EQ (sound, intern ("asterisk")))
+      sound_type = MB_ICONASTERISK;
+  else if (EQ (sound, intern ("exclamation"))) 
+      sound_type = MB_ICONEXCLAMATION;
+  else if (EQ (sound, intern ("hand"))) 
+      sound_type = MB_ICONHAND;
+  else if (EQ (sound, intern ("question"))) 
+      sound_type = MB_ICONQUESTION;
+  else if (EQ (sound, intern ("ok"))) 
+      sound_type = MB_OK;
+  else
+      sound_type = 0xFFFFFFFF;
+
+  return sound;
 }
 
 /* Put our console back up, for ending a suspended session.  */
@@ -441,8 +469,6 @@ reset_terminal_modes (void)
 {
   unset_kbd ();
   SetConsoleActiveScreenBuffer (prev_screen);
-  CloseHandle (cur_screen);
-  cur_screen = NULL;
 }
 
 void
@@ -468,8 +494,8 @@ set_terminal_modes (void)
 
       SetConsoleActiveScreenBuffer (cur_screen);
 
-      /* make cursor big and visible */
-      cci.dwSize = 100;
+      /* make cursor big and visible (100 on Win95 makes it disappear)  */
+      cci.dwSize = 99;
       cci.bVisible = TRUE;
       (void) SetConsoleCursorInfo (cur_screen, &cci);
     }
@@ -527,7 +553,7 @@ initialize_win_nt_display (void)
   insert_glyphs_hook           = (term_hook) insert_glyphs;
   write_glyphs_hook            = (term_hook) write_glyphs;
   delete_glyphs_hook           = (term_hook) delete_glyphs;
-  ring_bell_hook               = (term_hook) ring_bell;
+  ring_bell_hook               = (term_hook) nt_ring_bell;
   reset_terminal_modes_hook    = (term_hook) reset_terminal_modes;
   set_terminal_modes_hook      = (term_hook) set_terminal_modes;
   set_terminal_window_hook     = (term_hook) set_terminal_window;
@@ -582,6 +608,7 @@ DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
   return Qt;
 }
 
+#ifndef HAVE_NTGUI
 void
 pixel_to_glyph_coords (FRAME_PTR f, int pix_x, int pix_y, int *x, int *y,
                      void *bounds, int noclip)
@@ -596,10 +623,12 @@ glyph_to_pixel_coords (FRAME_PTR f, int x, int y, int *pix_x, int *pix_y)
   *pix_x = x;
   *pix_y = y;
 }
+#endif /* !HAVE_NTGUI */
 
-_VOID_
+void
 syms_of_ntterm ()
 {
   defsubr (&Sset_screen_color);
   defsubr (&Sset_cursor_size);
+  defsubr (&Sset_message_beep);
 }