(describe_command): Use quotes around symbol name.
[bpt/emacs.git] / src / w32xfns.c
index 9929248..5436ff2 100644 (file)
@@ -1,4 +1,4 @@
-/* Functions taken directly from X sources
+/* Functions taken directly from X sources for use with the Microsoft W32 API.
    Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
 
 This file is part of GNU Emacs.
@@ -30,83 +30,89 @@ Boston, MA 02111-1307, USA.  */
 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
 #define myfree(lp) GlobalFreePtr (lp)
 
-CRITICAL_SECTION critsect[ CRIT_TOTAL ];
+CRITICAL_SECTION critsect;
 extern HANDLE keyboard_handle;
-HANDLE h_input_available = NULL;
+HANDLE input_available = NULL;
 
 void 
 init_crit ()
 {
-  int i;
+  InitializeCriticalSection (&critsect);
 
-  for (i = 0; i < CRIT_TOTAL; i++)
-    InitializeCriticalSection (&critsect[i]);
-  /* For safety, h_input_available should only be reset by get_next_msg
+  /* For safety, input_available should only be reset by get_next_msg
      when the input queue is empty, so make it a manual reset event. */
-  keyboard_handle = h_input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
+  keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
 }
 
 void 
 delete_crit ()
 {
-  int i;
+  DeleteCriticalSection (&critsect);
 
-  for (i = 0; i < CRIT_TOTAL; i++)
-    DeleteCriticalSection (&critsect[i]);
-  if (h_input_available)
+  if (input_available)
     {
-      CloseHandle (h_input_available);
-      h_input_available = NULL;
+      CloseHandle (input_available);
+      input_available = NULL;
     }
 }
 
+void
+select_palette (FRAME_PTR f, HDC hdc)
+{
+  if (!NILP (Vw32_enable_palette))
+    f->output_data.w32->old_palette =
+      SelectPalette (hdc, one_w32_display_info.palette, FALSE);
+  else
+    f->output_data.w32->old_palette = NULL;
+
+  if (RealizePalette (hdc))
+  {
+    Lisp_Object frame, framelist;
+    FOR_EACH_FRAME (framelist, frame)
+    {
+      SET_FRAME_GARBAGED (XFRAME (frame));
+    }
+  }
+}
+
+void
+deselect_palette (FRAME_PTR f, HDC hdc)
+{
+  if (f->output_data.w32->old_palette)
+    SelectPalette (hdc, f->output_data.w32->old_palette, FALSE);
+}
+
 /* Get a DC for frame and select palette for drawing; force an update of
    all frames if palette's mapping changes.  */
 HDC
-GetFrameDC (FRAME_PTR f)
+get_frame_dc (FRAME_PTR f)
 {
-  HDC hDC;
-
-  enter_crit (CRIT_GDI);
+  HDC hdc;
 
-  hDC = GetDC (f->output_data.win32->window_desc);
+  enter_crit ();
 
-  if (!NILP (Vwin32_enable_palette))
-    f->output_data.win32->h_old_palette =
-      SelectPalette (hDC, one_win32_display_info.h_palette, FALSE);
-  else
-    f->output_data.win32->h_old_palette = NULL;
-
-  if (RealizePalette (hDC))
-    {
-      Lisp_Object frame, framelist;
-      FOR_EACH_FRAME (framelist, frame)
-       {
-         SET_FRAME_GARBAGED (XFRAME (frame));
-       }
-    }
+  hdc = GetDC (f->output_data.w32->window_desc);
+  select_palette (f, hdc);
 
-  return hDC;
+  return hdc;
 }
 
 int
-ReleaseFrameDC (FRAME_PTR f, HDC hDC)
+release_frame_dc (FRAME_PTR f, HDC hdc)
 {
   int ret;
 
-  if (f->output_data.win32->h_old_palette)
-    SelectPalette (hDC, f->output_data.win32->h_old_palette, FALSE);
+  deselect_palette (f, hdc);
+  ret = ReleaseDC (f->output_data.w32->window_desc, hdc);
 
-  ret = ReleaseDC (f->output_data.win32->window_desc, hDC);
-
-  leave_crit (CRIT_GDI);
+  leave_crit ();
 
   return ret;
 }
 
 typedef struct int_msg
 {
-  Win32Msg w32msg;
+  W32Msg w32msg;
   struct int_msg *lpNext;
 } int_msg;
 
@@ -116,25 +122,25 @@ int nQueue = 0;
 
 BOOL 
 get_next_msg (lpmsg, bWait)
-     Win32Msg * lpmsg;
+     W32Msg * lpmsg;
      BOOL bWait;
 {
   BOOL bRet = FALSE;
   
-  enter_crit (CRIT_MSG);
+  enter_crit ();
   
   /* The while loop takes care of multiple sets */
   
   while (!nQueue && bWait)
     {
-      leave_crit (CRIT_MSG);
-      WaitForSingleObject (h_input_available, INFINITE);
-      enter_crit (CRIT_MSG);
+      leave_crit ();
+      WaitForSingleObject (input_available, INFINITE);
+      enter_crit ();
     }
   
   if (nQueue)
     {
-      bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
+      bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg));
 
       {
        int_msg * lpCur = lpHead;
@@ -150,36 +156,61 @@ get_next_msg (lpmsg, bWait)
     }
 
   if (nQueue == 0)
-    ResetEvent (h_input_available);
+    ResetEvent (input_available);
   
-  leave_crit (CRIT_MSG);
+  leave_crit ();
   
   return (bRet);
 }
 
 BOOL 
 post_msg (lpmsg)
-     Win32Msg * lpmsg;
+     W32Msg * lpmsg;
 {
   int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
 
   if (!lpNew)
     return (FALSE);
 
-  bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
+  bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
   lpNew->lpNext = NULL;
 
-  enter_crit (CRIT_MSG);
+  enter_crit ();
 
   if (nQueue++)
-    lpTail->lpNext = lpNew;
+    {
+      lpTail->lpNext = lpNew;
+    }
   else 
-    lpHead = lpNew;
+    {
+      lpHead = lpNew;
+    }
 
   lpTail = lpNew;
-  SetEvent (h_input_available);
+  SetEvent (input_available);
     
-  leave_crit (CRIT_MSG);
+  leave_crit ();
+
+  return (TRUE);
+}
+
+BOOL
+prepend_msg (W32Msg *lpmsg)
+{
+  int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
+
+  if (!lpNew)
+    return (FALSE);
+
+  bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
+
+  enter_crit ();
+
+  nQueue++;
+  lpNew->lpNext = lpHead;
+  lpHead = lpNew;
+
+  leave_crit ();
 
   return (TRUE);
 }
@@ -319,14 +350,7 @@ XParseGeometry (string, x, y, width, height)
   return (mask);
 }
 
-/* We can use mouse menus when we wish.  */
-int
-have_menus_p (void)
-{
-  return 1;
-}
-
-/* x_sync is a no-op on Win32.  */
+/* x_sync is a no-op on W32.  */
 void
 x_sync (f)
      void *f;