(describe_command): Use quotes around symbol name.
[bpt/emacs.git] / src / w32xfns.c
index 0fda8c8..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.
@@ -15,12 +15,14 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #include <signal.h>
 #include <config.h>
 #include <stdio.h>
 #include "lisp.h"
+#include "frame.h"
 #include "blockinput.h"
 #include "w32term.h"
 #include "windowsx.h"
@@ -30,41 +32,87 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 CRITICAL_SECTION critsect;
 extern HANDLE keyboard_handle;
-HANDLE hEvent = NULL;
+HANDLE input_available = NULL;
 
 void 
 init_crit ()
 {
   InitializeCriticalSection (&critsect);
-  keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
-}
 
-void 
-enter_crit ()
-{
-  EnterCriticalSection (&critsect);
+  /* 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 = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
 }
 
 void 
-leave_crit ()
+delete_crit ()
 {
-  LeaveCriticalSection (&critsect);
+  DeleteCriticalSection (&critsect);
+
+  if (input_available)
+    {
+      CloseHandle (input_available);
+      input_available = NULL;
+    }
 }
 
-void 
-delete_crit ()
+void
+select_palette (FRAME_PTR f, HDC hdc)
 {
-  DeleteCriticalSection (&critsect);
-  if (hEvent)
+  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)
     {
-      CloseHandle (hEvent);
-      hEvent = NULL;
+      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
+get_frame_dc (FRAME_PTR f)
+{
+  HDC hdc;
+
+  enter_crit ();
+
+  hdc = GetDC (f->output_data.w32->window_desc);
+  select_palette (f, hdc);
+
+  return hdc;
+}
+
+int
+release_frame_dc (FRAME_PTR f, HDC hdc)
+{
+  int ret;
+
+  deselect_palette (f, hdc);
+  ret = ReleaseDC (f->output_data.w32->window_desc, hdc);
+
+  leave_crit ();
+
+  return ret;
 }
 
 typedef struct int_msg
 {
-  Win32Msg w32msg;
+  W32Msg w32msg;
   struct int_msg *lpNext;
 } int_msg;
 
@@ -74,7 +122,7 @@ int nQueue = 0;
 
 BOOL 
 get_next_msg (lpmsg, bWait)
-     Win32Msg * lpmsg;
+     W32Msg * lpmsg;
      BOOL bWait;
 {
   BOOL bRet = FALSE;
@@ -86,13 +134,13 @@ get_next_msg (lpmsg, bWait)
   while (!nQueue && bWait)
     {
       leave_crit ();
-      WaitForSingleObject (hEvent, INFINITE);
+      WaitForSingleObject (input_available, INFINITE);
       enter_crit ();
     }
   
   if (nQueue)
     {
-      bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
+      bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg));
 
       {
        int_msg * lpCur = lpHead;
@@ -106,6 +154,9 @@ get_next_msg (lpmsg, bWait)
 
       bRet = TRUE;
     }
+
+  if (nQueue == 0)
+    ResetEvent (input_available);
   
   leave_crit ();
   
@@ -114,13 +165,14 @@ get_next_msg (lpmsg, bWait)
 
 BOOL 
 post_msg (lpmsg)
-     Win32Msg * lpmsg;
+     W32Msg * lpmsg;
 {
   int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
 
-  if (!lpNew) return (FALSE);
+  if (!lpNew)
+    return (FALSE);
 
-  bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
+  bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
   lpNew->lpNext = NULL;
 
   enter_crit ();
@@ -132,16 +184,37 @@ post_msg (lpmsg)
   else 
     {
       lpHead = lpNew;
-      SetEvent (hEvent);
     }
 
   lpTail = lpNew;
+  SetEvent (input_available);
     
   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);
+}
+
 /*
  *    XParseGeometry parses strings of the form
  *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
@@ -277,14 +350,7 @@ XParseGeometry (string, x, y, width, height)
   return (mask);
 }
 
-/* The semantics of the use of using_x_p is really using_a_window_system.  */
-int
-using_x_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;