(Line Truncation): Add reference to Continuation Lines.
[bpt/emacs.git] / src / w32xfns.c
index 9117f7e..682876c 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  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,9 +15,7 @@ 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>
@@ -38,7 +37,7 @@ extern HANDLE keyboard_handle;
 HANDLE input_available = NULL;
 HANDLE interrupt_handle = NULL;
 
-void 
+void
 init_crit ()
 {
   InitializeCriticalSection (&critsect);
@@ -47,16 +46,16 @@ 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 
+void
 delete_crit ()
 {
   DeleteCriticalSection (&critsect);
@@ -76,7 +75,7 @@ delete_crit ()
 void
 signal_quit ()
 {
-  /* 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);
 }
@@ -90,7 +89,7 @@ select_palette (FRAME_PTR f, HDC hdc)
     return;
 
   if (display_info->palette == 0)
-    abort ();
+    return;
 
   if (!NILP (Vw32_enable_palette))
     f->output_data.w32->old_palette =
@@ -122,6 +121,9 @@ get_frame_dc (FRAME_PTR f)
 {
   HDC hdc;
 
+  if (f->output_method != output_w32)
+    abort ();
+
   enter_crit ();
 
   hdc = GetDC (f->output_data.w32->window_desc);
@@ -157,50 +159,91 @@ int_msg *lpHead = NULL;
 int_msg *lpTail = NULL;
 int nQueue = 0;
 
-BOOL 
+BOOL
 get_next_msg (lpmsg, bWait)
      W32Msg * lpmsg;
      BOOL bWait;
 {
   BOOL bRet = FALSE;
-  
+
   enter_crit ();
-  
+
   /* The while loop takes care of multiple sets */
-  
+
   while (!nQueue && bWait)
     {
       leave_crit ();
       WaitForSingleObject (input_available, INFINITE);
       enter_crit ();
     }
-  
+
   if (nQueue)
     {
       bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg));
 
       {
        int_msg * lpCur = lpHead;
-           
+
        lpHead = lpHead->lpNext;
-           
+
        myfree (lpCur);
       }
 
       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;
     }
 
   if (nQueue == 0)
     ResetEvent (input_available);
-  
+
   leave_crit ();
-  
+
   return (bRet);
 }
 
-BOOL 
+BOOL
 post_msg (lpmsg)
      W32Msg * lpmsg;
 {
@@ -218,14 +261,14 @@ post_msg (lpmsg)
     {
       lpTail->lpNext = lpNew;
     }
-  else 
+  else
     {
       lpHead = lpNew;
     }
 
   lpTail = lpNew;
   SetEvent (input_available);
-    
+
   leave_crit ();
 
   return (TRUE);
@@ -274,7 +317,7 @@ drain_message_queue ()
  *   It returns a bitmask that indicates which of the four values
  *   were actually found in the string.  For each value found,
  *   the corresponding argument is updated;  for each value
- *   not found, the corresponding argument is left unchanged. 
+ *   not found, the corresponding argument is left unchanged.
  */
 
 static int
@@ -284,7 +327,7 @@ read_integer (string, NextString)
 {
   register int Result = 0;
   int Sign = 1;
-  
+
   if (*string == '+')
     string++;
   else if (*string == '-')
@@ -303,7 +346,7 @@ read_integer (string, NextString)
     return (-Result);
 }
 
-int 
+int
 XParseGeometry (string, x, y, width, height)
      char *string;
      int *x, *y;
@@ -314,23 +357,23 @@ XParseGeometry (string, x, y, width, height)
   unsigned int tempWidth, tempHeight;
   int tempX, tempY;
   char *nextCharacter;
-  
+
   if ((string == NULL) || (*string == '\0')) return (mask);
   if (*string == '=')
     string++;  /* ignore possible '=' at beg of geometry spec */
-  
+
   strind = (char *)string;
-  if (*strind != '+' && *strind != '-' && *strind != 'x') 
+  if (*strind != '+' && *strind != '-' && *strind != 'x')
     {
       tempWidth = read_integer (strind, &nextCharacter);
-      if (strind == nextCharacter) 
+      if (strind == nextCharacter)
        return (0);
       strind = nextCharacter;
       mask |= WidthValue;
     }
-  
-  if (*strind == 'x' || *strind == 'X') 
-    {  
+
+  if (*strind == 'x' || *strind == 'X')
+    {
       strind++;
       tempHeight = read_integer (strind, &nextCharacter);
       if (strind == nextCharacter)
@@ -338,10 +381,10 @@ XParseGeometry (string, x, y, width, height)
       strind = nextCharacter;
       mask |= HeightValue;
     }
-  
-  if ((*strind == '+') || (*strind == '-')) 
+
+  if ((*strind == '+') || (*strind == '-'))
     {
-      if (*strind == '-') 
+      if (*strind == '-')
        {
          strind++;
          tempX = -read_integer (strind, &nextCharacter);
@@ -352,7 +395,7 @@ XParseGeometry (string, x, y, width, height)
 
        }
       else
-       {       
+       {
          strind++;
          tempX = read_integer (strind, &nextCharacter);
          if (strind == nextCharacter)
@@ -360,9 +403,9 @@ XParseGeometry (string, x, y, width, height)
          strind = nextCharacter;
        }
       mask |= XValue;
-      if ((*strind == '+') || (*strind == '-')) 
+      if ((*strind == '+') || (*strind == '-'))
        {
-         if (*strind == '-') 
+         if (*strind == '-')
            {
              strind++;
              tempY = -read_integer (strind, &nextCharacter);
@@ -383,12 +426,12 @@ XParseGeometry (string, x, y, width, height)
          mask |= YValue;
        }
     }
-  
+
   /* If strind isn't at the end of the string the it's an invalid
      geometry specification. */
-  
+
   if (*strind != '\0') return (0);
-  
+
   if (mask & XValue)
     *x = tempX;
   if (mask & YValue)
@@ -406,3 +449,6 @@ x_sync (f)
      void *f;
 {
 }
+
+/* arch-tag: 4fab3695-4ad3-4cc6-a2b1-fd2c67dc46be
+   (do not change this comment) */