Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
[bpt/emacs.git] / src / w32xfns.c
index 9f9a645..8fee42d 100644 (file)
@@ -1,12 +1,13 @@
 /* Functions taken directly from X sources for use with the Microsoft W32 API.
-   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1999 Free Software Foundation.
+   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1999, 2001, 2002, 2003,
+                 2004, 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,13 +15,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 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, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <signal.h>
 #include <stdio.h>
+#include <setjmp.h>
 #include "lisp.h"
 #include "keyboard.h"
 #include "frame.h"
@@ -39,7 +39,7 @@ HANDLE input_available = NULL;
 HANDLE interrupt_handle = NULL;
 
 void
-init_crit ()
+init_crit (void)
 {
   InitializeCriticalSection (&critsect);
 
@@ -47,17 +47,17 @@ init_crit ()
      when the input queue is empty, so make it a manual reset event. */
   keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
 
-  /* interrupt_handle is signalled when quit (C-g) is detected, so that
+  /* interrupt_handle is signaled when quit (C-g) is detected, so that
      blocking system calls can be interrupted.  We make it a manual
      reset event, so that if we should ever have multiple threads
      performing system calls, they will all be interrupted (I'm guessing
      that would the right response).  Note that we use PulseEvent to
-     signal this event, so that it never remains signalled.  */
+     signal this event, so that it never remains signaled.  */
   interrupt_handle = CreateEvent (NULL, TRUE, FALSE, NULL);
 }
 
 void
-delete_crit ()
+delete_crit (void)
 {
   DeleteCriticalSection (&critsect);
 
@@ -74,9 +74,9 @@ delete_crit ()
 }
 
 void
-signal_quit ()
+signal_quit (void)
 {
-  /* Make sure this event never remains signalled; if the main thread
+  /* Make sure this event never remains signaled; if the main thread
      isn't in a blocking call, then this should do nothing.  */
   PulseEvent (interrupt_handle);
 }
@@ -161,9 +161,7 @@ int_msg *lpTail = NULL;
 int nQueue = 0;
 
 BOOL
-get_next_msg (lpmsg, bWait)
-     W32Msg * lpmsg;
-     BOOL bWait;
+get_next_msg (W32Msg * lpmsg, BOOL bWait)
 {
   BOOL bRet = FALSE;
 
@@ -180,7 +178,7 @@ get_next_msg (lpmsg, bWait)
 
   if (nQueue)
     {
-      bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg));
+      memcpy (lpmsg, &lpHead->w32msg, sizeof (W32Msg));
 
       {
        int_msg * lpCur = lpHead;
@@ -191,6 +189,47 @@ get_next_msg (lpmsg, bWait)
       }
 
       nQueue--;
+      /* Consolidate WM_PAINT messages to optimise redrawing.  */
+      if (lpmsg->msg.message == WM_PAINT && nQueue)
+        {
+          int_msg * lpCur = lpHead;
+          int_msg * lpPrev = NULL;
+          int_msg * lpNext = NULL;
+
+          while (lpCur && nQueue)
+            {
+              lpNext = lpCur->lpNext;
+              if (lpCur->w32msg.msg.message == WM_PAINT)
+                {
+                  /* Remove this message from the queue.  */
+                  if (lpPrev)
+                    lpPrev->lpNext = lpNext;
+                  else
+                    lpHead = lpNext;
+
+                  if (lpCur == lpTail)
+                    lpTail = lpPrev;
+
+                  /* Adjust clip rectangle to cover both.  */
+                  if (!UnionRect (&(lpmsg->rect), &(lpmsg->rect),
+                                  &(lpCur->w32msg.rect)))
+                    {
+                      SetRectEmpty (&(lpmsg->rect));
+                    }
+
+                  myfree (lpCur);
+
+                  nQueue--;
+
+                  lpCur = lpNext;
+                }
+              else
+                {
+                  lpPrev = lpCur;
+                  lpCur = lpNext;
+                }
+            }
+        }
 
       bRet = TRUE;
     }
@@ -204,15 +243,14 @@ get_next_msg (lpmsg, bWait)
 }
 
 BOOL
-post_msg (lpmsg)
-     W32Msg * lpmsg;
+post_msg (W32Msg * lpmsg)
 {
   int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
 
   if (!lpNew)
     return (FALSE);
 
-  bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
+  memcpy (&lpNew->w32msg, lpmsg, sizeof (W32Msg));
   lpNew->lpNext = NULL;
 
   enter_crit ();
@@ -242,7 +280,7 @@ prepend_msg (W32Msg *lpmsg)
   if (!lpNew)
     return (FALSE);
 
-  bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
+  memcpy (&lpNew->w32msg, lpmsg, sizeof (W32Msg));
 
   enter_crit ();
 
@@ -257,7 +295,7 @@ prepend_msg (W32Msg *lpmsg)
 
 /* Process all messages in the current thread's queue.  */
 void
-drain_message_queue ()
+drain_message_queue (void)
 {
   MSG msg;
   while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
@@ -281,9 +319,7 @@ drain_message_queue ()
  */
 
 static int
-read_integer (string, NextString)
-     register char *string;
-     char **NextString;
+read_integer (register char *string, char **NextString)
 {
   register int Result = 0;
   int Sign = 1;
@@ -307,10 +343,9 @@ read_integer (string, NextString)
 }
 
 int
-XParseGeometry (string, x, y, width, height)
-     char *string;
-     int *x, *y;
-     unsigned int *width, *height;    /* RETURN */
+XParseGeometry (char *string,
+               int *x, int *y,
+               unsigned int *width, unsigned int *height)
 {
   int mask = NoValue;
   register char *strind;
@@ -405,8 +440,7 @@ XParseGeometry (string, x, y, width, height)
 
 /* x_sync is a no-op on W32.  */
 void
-x_sync (f)
-     void *f;
+x_sync (void *f)
 {
 }