diff src/w32xfns.c @ 15153:c1494aa589e8

Include frame.h. (hEvent): Renamed to h_input_available. (init_crit, delete_crit, get_next_msg, post_msg): Use h_input_available. (GetFrameDC, ReleaseFrameDC): New functions. (leave_crit): Function removed.
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 03 May 1996 18:49:20 +0000
parents 61fc696a0c6a
children 481b7874a1e9
line wrap: on
line diff
--- a/src/w32xfns.c	Fri May 03 18:48:05 1996 +0000
+++ b/src/w32xfns.c	Fri May 03 18:49:20 1996 +0000
@@ -22,6 +22,7 @@
 #include <config.h>
 #include <stdio.h>
 #include "lisp.h"
+#include "frame.h"
 #include "blockinput.h"
 #include "w32term.h"
 #include "windowsx.h"
@@ -31,36 +32,82 @@
 
 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);
-}
-
-void 
-leave_crit ()
-{
-  LeaveCriticalSection (&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 
 delete_crit ()
 {
   DeleteCriticalSection (&critsect);
-  if (hEvent)
+
+  if (input_available)
+    {
+      CloseHandle (input_available);
+      input_available = NULL;
+    }
+}
+
+void
+select_palette (FRAME_PTR f, HDC hdc)
+{
+  if (!NILP (Vwin32_enable_palette))
+    f->output_data.win32->old_palette =
+      SelectPalette (hdc, one_win32_display_info.palette, FALSE);
+  else
+    f->output_data.win32->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.win32->old_palette)
+    SelectPalette (hdc, f->output_data.win32->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.win32->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.win32->window_desc, hdc);
+
+  leave_crit ();
+
+  return ret;
 }
 
 typedef struct int_msg
@@ -87,7 +134,7 @@
   while (!nQueue && bWait)
     {
       leave_crit ();
-      WaitForSingleObject (hEvent, INFINITE);
+      WaitForSingleObject (input_available, INFINITE);
       enter_crit ();
     }
   
@@ -107,6 +154,9 @@
 
       bRet = TRUE;
     }
+
+  if (nQueue == 0)
+    ResetEvent (input_available);
   
   leave_crit ();
   
@@ -119,7 +169,8 @@
 {
   int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
 
-  if (!lpNew) return (FALSE);
+  if (!lpNew)
+    return (FALSE);
 
   bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
   lpNew->lpNext = NULL;
@@ -133,10 +184,10 @@
   else 
     {
       lpHead = lpNew;
-      SetEvent (hEvent);
     }
 
   lpTail = lpNew;
+  SetEvent (input_available);
     
   leave_crit ();