Add 2010 to copyright years.
[bpt/emacs.git] / src / xselect.c
index 53debec..e202773 100644 (file)
@@ -1,13 +1,13 @@
 /* X Selection processing for Emacs.
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+                 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 3, 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
@@ -15,15 +15,14 @@ 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., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 /* Rewritten by jwz */
 
 #include <config.h>
 #include <stdio.h>      /* termhooks.h needs this */
+#include <setjmp.h>
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -810,7 +809,7 @@ x_reply_selection_request (event, format, data, size, type)
        {
           int i = ((bytes_remaining < max_bytes)
                    ? bytes_remaining
-                   : max_bytes);
+                   : max_bytes) / format_bytes;
 
          BLOCK_INPUT;
 
@@ -818,15 +817,18 @@ x_reply_selection_request (event, format, data, size, type)
            = expect_property_change (display, window, reply.property,
                                      PropertyDelete);
 
-         TRACE1 ("Sending increment of %d bytes", i);
+         TRACE1 ("Sending increment of %d elements", i);
          TRACE1 ("Set %s to increment data",
                  XGetAtomName (display, reply.property));
 
          /* Append the next chunk of data to the property.  */
          XChangeProperty (display, window, reply.property, type, format,
-                          PropModeAppend, data, i / format_bytes);
-         bytes_remaining -= i;
-         data += i;
+                          PropModeAppend, data, i);
+         bytes_remaining -= i * format_bytes;
+         if (format == 32)
+           data += i * sizeof (long);
+         else
+           data += i * format_bytes;
          XFlush (display);
          had_errors = x_had_errors_p (display);
          UNBLOCK_INPUT;
@@ -1014,7 +1016,6 @@ x_handle_selection_clear (event)
 
   TRACE0 ("x_handle_selection_clear");
 
-#ifdef MULTI_KBOARD  
   /* If the new selection owner is also Emacs,
      don't clear the new selection.  */
   BLOCK_INPUT;
@@ -1033,7 +1034,6 @@ x_handle_selection_clear (event)
          }
       }
   UNBLOCK_INPUT;
-#endif
   
   selection_symbol = x_atom_to_symbol (display, selection);
 
@@ -1472,7 +1472,7 @@ x_get_foreign_selection (selection_symbol, target_type, time_stamp)
   if (NILP (XCAR (reading_selection_reply)))
     error ("Timed out waiting for reply from selection owner");
   if (EQ (XCAR (reading_selection_reply), Qlambda))
-    error ("No `%s' selection", SDATA (SYMBOL_NAME (selection_symbol)));
+    return Qnil;
 
   /* Otherwise, the selection is waiting for us on the requested property.  */
   return
@@ -1672,7 +1672,7 @@ receive_incremental_selection (display, window, property, target_type,
            XSelectInput (display, window, STANDARD_EVENT_SET);
          /* Use xfree, not XFree, because x_get_window_property
             calls xmalloc itself.  */
-         if (tmp_data) xfree (tmp_data);
+         xfree (tmp_data);
          break;
        }
 
@@ -2370,7 +2370,7 @@ DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal,
 {
   Window window;
   Atom buffer_atom;
-  unsigned char *data;
+  unsigned char *data = NULL;
   int bytes;
   Atom type;
   int format;
@@ -2393,8 +2393,12 @@ DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal,
 
   x_get_window_property (display, window, buffer_atom, &data, &bytes,
                         &type, &format, &size, 0);
+
   if (!data || !format)
-    return Qnil;
+    {
+      xfree (data);
+      return Qnil;
+    }
 
   if (format != 8 || type != XA_STRING)
     signal_error ("Cut buffer doesn't contain 8-bit data",
@@ -2476,8 +2480,8 @@ DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal,
 
 DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal,
        Sx_rotate_cut_buffers_internal, 1, 1, 0,
-       doc: /* Rotate the values of the cut buffers by the given number of step.
-Positive means shift the values forward, negative means backward.  */)
+       doc: /* Rotate the values of the cut buffers by N steps.
+Positive means shift the values forward, negative means backward.  */)
      (n)
      Lisp_Object n;
 {
@@ -2791,15 +2795,15 @@ x_handle_dnd_message (f, event, dpyinfo, bufp)
     }
 
   vec = Fmake_vector (make_number (4), Qnil);
-  AREF (vec, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
-                                                 event->message_type));
-  AREF (vec, 1) = frame;
-  AREF (vec, 2) = make_number (event->format);
-  AREF (vec, 3) = x_property_data_to_lisp (f,
-                                           data,
-                                           event->message_type,
-                                           event->format,
-                                           size);
+  ASET (vec, 0, SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
+                                              event->message_type)));
+  ASET (vec, 1, frame);
+  ASET (vec, 2, make_number (event->format));
+  ASET (vec, 3, x_property_data_to_lisp (f,
+                                        data,
+                                        event->message_type,
+                                        event->format,
+                                        size));
 
   mouse_position_for_drop (f, &x, &y);
   bufp->kind = DRAG_N_DROP_EVENT;
@@ -2825,7 +2829,7 @@ If DEST is a cons, it is converted to a 32 bit number
 with the high 16 bits from the car and the lower 16 bit from the cdr.  That
 number is then used as a window id.
 If DEST is a frame the event is sent to the outer window of that frame.
-Nil means the currently selected frame.
+A value of nil means the currently selected frame.
 If DEST is the string "PointerWindow" the event is sent to the window that
 contains the pointer.  If DEST is the string "InputFocus" the event is
 sent to the window that has the input focus.
@@ -3006,38 +3010,38 @@ A value of 0 means wait as long as necessary.  This is initialized from the
 \"*selectionTimeout\" resource.  */);
   x_selection_timeout = 0;
 
-  QPRIMARY   = intern ("PRIMARY");     staticpro (&QPRIMARY);
-  QSECONDARY = intern ("SECONDARY");   staticpro (&QSECONDARY);
-  QSTRING    = intern ("STRING");      staticpro (&QSTRING);
-  QINTEGER   = intern ("INTEGER");     staticpro (&QINTEGER);
-  QCLIPBOARD = intern ("CLIPBOARD");   staticpro (&QCLIPBOARD);
-  QTIMESTAMP = intern ("TIMESTAMP");   staticpro (&QTIMESTAMP);
-  QTEXT      = intern ("TEXT");        staticpro (&QTEXT);
-  QCOMPOUND_TEXT = intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT);
-  QUTF8_STRING = intern ("UTF8_STRING"); staticpro (&QUTF8_STRING);
-  QDELETE    = intern ("DELETE");      staticpro (&QDELETE);
-  QMULTIPLE  = intern ("MULTIPLE");    staticpro (&QMULTIPLE);
-  QINCR      = intern ("INCR");                staticpro (&QINCR);
-  QEMACS_TMP = intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP);
-  QTARGETS   = intern ("TARGETS");     staticpro (&QTARGETS);
-  QATOM             = intern ("ATOM");         staticpro (&QATOM);
-  QATOM_PAIR = intern ("ATOM_PAIR");   staticpro (&QATOM_PAIR);
-  QNULL             = intern ("NULL");         staticpro (&QNULL);
-  Qcompound_text_with_extensions = intern ("compound-text-with-extensions");
+  QPRIMARY   = intern_c_string ("PRIMARY");    staticpro (&QPRIMARY);
+  QSECONDARY = intern_c_string ("SECONDARY");  staticpro (&QSECONDARY);
+  QSTRING    = intern_c_string ("STRING");     staticpro (&QSTRING);
+  QINTEGER   = intern_c_string ("INTEGER");    staticpro (&QINTEGER);
+  QCLIPBOARD = intern_c_string ("CLIPBOARD");  staticpro (&QCLIPBOARD);
+  QTIMESTAMP = intern_c_string ("TIMESTAMP");  staticpro (&QTIMESTAMP);
+  QTEXT      = intern_c_string ("TEXT");       staticpro (&QTEXT);
+  QCOMPOUND_TEXT = intern_c_string ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT);
+  QUTF8_STRING = intern_c_string ("UTF8_STRING"); staticpro (&QUTF8_STRING);
+  QDELETE    = intern_c_string ("DELETE");     staticpro (&QDELETE);
+  QMULTIPLE  = intern_c_string ("MULTIPLE");   staticpro (&QMULTIPLE);
+  QINCR      = intern_c_string ("INCR");               staticpro (&QINCR);
+  QEMACS_TMP = intern_c_string ("_EMACS_TMP_");        staticpro (&QEMACS_TMP);
+  QTARGETS   = intern_c_string ("TARGETS");    staticpro (&QTARGETS);
+  QATOM             = intern_c_string ("ATOM");                staticpro (&QATOM);
+  QATOM_PAIR = intern_c_string ("ATOM_PAIR");  staticpro (&QATOM_PAIR);
+  QNULL             = intern_c_string ("NULL");                staticpro (&QNULL);
+  Qcompound_text_with_extensions = intern_c_string ("compound-text-with-extensions");
   staticpro (&Qcompound_text_with_extensions);
 
 #ifdef CUT_BUFFER_SUPPORT
-  QCUT_BUFFER0 = intern ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0);
-  QCUT_BUFFER1 = intern ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1);
-  QCUT_BUFFER2 = intern ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2);
-  QCUT_BUFFER3 = intern ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3);
-  QCUT_BUFFER4 = intern ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4);
-  QCUT_BUFFER5 = intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5);
-  QCUT_BUFFER6 = intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6);
-  QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7);
+  QCUT_BUFFER0 = intern_c_string ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0);
+  QCUT_BUFFER1 = intern_c_string ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1);
+  QCUT_BUFFER2 = intern_c_string ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2);
+  QCUT_BUFFER3 = intern_c_string ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3);
+  QCUT_BUFFER4 = intern_c_string ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4);
+  QCUT_BUFFER5 = intern_c_string ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5);
+  QCUT_BUFFER6 = intern_c_string ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6);
+  QCUT_BUFFER7 = intern_c_string ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7);
 #endif
 
-  Qforeign_selection = intern ("foreign-selection");
+  Qforeign_selection = intern_c_string ("foreign-selection");
   staticpro (&Qforeign_selection);
 }