changeset 80454:98811b17d3b9

[!TARGET_API_MAC_CARBON]: Don't include Scrap.h. (Selection): Move typedef to macgui.h. (Vselection_converter_alist, Qmac_scrap_name, Qmac_ostype) (Vmac_apple_event_map, Qmac_apple_event_class, Qmac_apple_event_id): Make variables non-static. (Vmac_dnd_known_types) [TARGET_API_MAC_CARBON]: Likewise. (mac_handle_apple_event, cleanup_all_suspended_apple_events): Make functions non-static. (Vmac_service_selection) [MAC_OSX]: Likewise. (mac_get_selection_from_symbol, get_flavor_type_from_symbol) (mac_valid_selection_target_p, mac_clear_selection) (mac_get_selection_ownership_info, mac_valid_selection_value_p) (mac_put_selection_value, mac_selection_has_target_p) (mac_get_selection_value, mac_get_selection_target_list) (init_apple_event_handler, install_drag_handler, remove_drag_handler): Move functions to mactoolbox.c. (mac_do_track_drag, mac_do_receive_drag) [TARGET_API_MAC_CARBON]: Likewise. (copy_scrap_flavor_data, mac_handle_service_event) (install_service_handler) [MAC_OSX]: Likewise. (syms_of_macselect) <Vmac_dnd_known_types>: Use mac_dnd_default_known_types.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sun, 06 Apr 2008 01:58:39 +0000
parents 07666d9ede23
children 4b3759b14cc7
files src/macselect.c
diffstat 1 files changed, 12 insertions(+), 756 deletions(-) [+]
line wrap: on
line diff
--- a/src/macselect.c	Sun Apr 06 01:58:19 2008 +0000
+++ b/src/macselect.c	Sun Apr 06 01:58:39 2008 +0000
@@ -25,38 +25,15 @@
 #include "blockinput.h"
 #include "keymap.h"
 
-#if TARGET_API_MAC_CARBON
-typedef ScrapRef Selection;
-#else  /* !TARGET_API_MAC_CARBON */
-#include <Scrap.h>
+#if !TARGET_API_MAC_CARBON
 #include <Endian.h>
-typedef int Selection;
-#endif /* !TARGET_API_MAC_CARBON */
+#endif
 
-static OSStatus mac_get_selection_from_symbol P_ ((Lisp_Object, int,
-						   Selection *));
-static ScrapFlavorType get_flavor_type_from_symbol P_ ((Lisp_Object,
-							Selection));
-static int mac_valid_selection_target_p P_ ((Lisp_Object));
-static OSStatus mac_clear_selection P_ ((Selection *));
-static Lisp_Object mac_get_selection_ownership_info P_ ((Selection));
-static int mac_valid_selection_value_p P_ ((Lisp_Object, Lisp_Object));
-static OSStatus mac_put_selection_value P_ ((Selection, Lisp_Object,
-					     Lisp_Object));
-static int mac_selection_has_target_p P_ ((Selection, Lisp_Object));
-static Lisp_Object mac_get_selection_value P_ ((Selection, Lisp_Object));
-static Lisp_Object mac_get_selection_target_list P_ ((Selection));
 static void x_own_selection P_ ((Lisp_Object, Lisp_Object));
 static Lisp_Object x_get_local_selection P_ ((Lisp_Object, Lisp_Object, int));
 static Lisp_Object x_get_foreign_selection P_ ((Lisp_Object,
                                                 Lisp_Object,
                                                 Lisp_Object));
-EXFUN (Fx_selection_owner_p, 1);
-#ifdef MAC_OSX
-static OSStatus mac_handle_service_event P_ ((EventHandlerCallRef,
-					      EventRef, void *));
-void init_service_handler P_ ((void));
-#endif
 
 Lisp_Object QPRIMARY, QSECONDARY, QTIMESTAMP, QTARGETS;
 
@@ -98,302 +75,13 @@
    selection value to a string representing the given selection type.
    This is for Lisp-level extension of the emacs selection
    handling.  */
-static Lisp_Object Vselection_converter_alist;
+Lisp_Object Vselection_converter_alist;
 
 /* A selection name (represented as a Lisp symbol) can be associated
    with a named scrap via `mac-scrap-name' property.  Likewise for a
    selection type with a scrap flavor type via `mac-ostype'.  */
-static Lisp_Object Qmac_scrap_name, Qmac_ostype;
-
-#ifdef MAC_OSX
-/* Selection name for communication via Services menu.  */
-static Lisp_Object Vmac_service_selection;
-#endif
-
-/* Get a reference to the selection corresponding to the symbol SYM.
-   The reference is set to *SEL, and it becomes NULL if there's no
-   corresponding selection.  Clear the selection if CLEAR_P is
-   non-zero.  */
-
-static OSStatus
-mac_get_selection_from_symbol (sym, clear_p, sel)
-     Lisp_Object sym;
-     int clear_p;
-     Selection *sel;
-{
-  OSStatus err = noErr;
-  Lisp_Object str = Fget (sym, Qmac_scrap_name);
-
-  if (!STRINGP (str))
-    *sel = NULL;
-  else
-    {
-#if TARGET_API_MAC_CARBON
-#ifdef MAC_OSX
-      CFStringRef scrap_name = cfstring_create_with_string (str);
-      OptionBits options = (clear_p ? kScrapClearNamedScrap
-			    : kScrapGetNamedScrap);
-
-      err = GetScrapByName (scrap_name, options, sel);
-      CFRelease (scrap_name);
-#else	/* !MAC_OSX */
-      if (clear_p)
-	err = ClearCurrentScrap ();
-      if (err == noErr)
-	err = GetCurrentScrap (sel);
-#endif	/* !MAC_OSX */
-#else	/* !TARGET_API_MAC_CARBON */
-      if (clear_p)
-	err = ZeroScrap ();
-      if (err == noErr)
-	*sel = 1;
-#endif	/* !TARGET_API_MAC_CARBON */
-    }
-
-  return err;
-}
-
-/* Get a scrap flavor type from the symbol SYM.  Return 0 if no
-   corresponding flavor type.  If SEL is non-zero, the return value is
-   non-zero only when the SEL has the flavor type.  */
-
-static ScrapFlavorType
-get_flavor_type_from_symbol (sym, sel)
-     Lisp_Object sym;
-     Selection sel;
-{
-  Lisp_Object str = Fget (sym, Qmac_ostype);
-  ScrapFlavorType flavor_type;
-
-  if (STRINGP (str) && SBYTES (str) == 4)
-    flavor_type = EndianU32_BtoN (*((UInt32 *) SDATA (str)));
-  else
-    flavor_type = 0;
-
-  if (flavor_type && sel)
-    {
-#if TARGET_API_MAC_CARBON
-      OSStatus err;
-      ScrapFlavorFlags flags;
-
-      err = GetScrapFlavorFlags (sel, flavor_type, &flags);
-      if (err != noErr)
-	flavor_type = 0;
-#else  /* !TARGET_API_MAC_CARBON */
-      SInt32 size, offset;
-
-      size = GetScrap (NULL, flavor_type, &offset);
-      if (size < 0)
-	flavor_type = 0;
-#endif	/* !TARGET_API_MAC_CARBON */
-    }
-
-  return flavor_type;
-}
-
-/* Check if the symbol SYM has a corresponding selection target type.  */
-
-static int
-mac_valid_selection_target_p (sym)
-     Lisp_Object sym;
-{
-  return get_flavor_type_from_symbol (sym, 0) != 0;
-}
-
-/* Clear the selection whose reference is *SEL.  */
-
-static OSStatus
-mac_clear_selection (sel)
-     Selection *sel;
-{
-#if TARGET_API_MAC_CARBON
-#ifdef MAC_OSX
-  return ClearScrap (sel);
-#else
-  OSStatus err;
-
-  err = ClearCurrentScrap ();
-  if (err == noErr)
-    err = GetCurrentScrap (sel);
-  return err;
-#endif
-#else  /* !TARGET_API_MAC_CARBON */
-  return ZeroScrap ();
-#endif	/* !TARGET_API_MAC_CARBON */
-}
-
-/* Get ownership information for SEL.  Emacs can detect a change of
-   the ownership by comparing saved and current values of the
-   ownership information.  */
-
-static Lisp_Object
-mac_get_selection_ownership_info (sel)
-     Selection sel;
-{
-#if TARGET_API_MAC_CARBON
-  return long_to_cons ((unsigned long) sel);
-#else  /* !TARGET_API_MAC_CARBON */
-  ScrapStuffPtr scrap_info = InfoScrap ();
-
-  return make_number (scrap_info->scrapCount);
-#endif	/* !TARGET_API_MAC_CARBON */
-}
-
-/* Return non-zero if VALUE is a valid selection value for TARGET.  */
-
-static int
-mac_valid_selection_value_p (value, target)
-     Lisp_Object value, target;
-{
-  return STRINGP (value);
-}
+Lisp_Object Qmac_scrap_name, Qmac_ostype;
 
-/* Put Lisp Object VALUE to the selection SEL.  The target type is
-   specified by TARGET. */
-
-static OSStatus
-mac_put_selection_value (sel, target, value)
-     Selection sel;
-     Lisp_Object target, value;
-{
-  ScrapFlavorType flavor_type = get_flavor_type_from_symbol (target, 0);
-
-  if (flavor_type == 0 || !STRINGP (value))
-    return noTypeErr;
-
-#if TARGET_API_MAC_CARBON
-  return PutScrapFlavor (sel, flavor_type, kScrapFlavorMaskNone,
-			 SBYTES (value), SDATA (value));
-#else  /* !TARGET_API_MAC_CARBON */
-  return PutScrap (SBYTES (value), flavor_type, SDATA (value));
-#endif	/* !TARGET_API_MAC_CARBON */
-}
-
-/* Check if data for the target type TARGET is available in SEL.  */
-
-static int
-mac_selection_has_target_p (sel, target)
-     Selection sel;
-     Lisp_Object target;
-{
-  return get_flavor_type_from_symbol (target, sel) != 0;
-}
-
-/* Get data for the target type TARGET from SEL and create a Lisp
-   string.  Return nil if failed to get data.  */
-
-static Lisp_Object
-mac_get_selection_value (sel, target)
-     Selection sel;
-     Lisp_Object target;
-{
-  OSStatus err;
-  Lisp_Object result = Qnil;
-  ScrapFlavorType flavor_type = get_flavor_type_from_symbol (target, sel);
-#if TARGET_API_MAC_CARBON
-  Size size;
-
-  if (flavor_type)
-    {
-      err = GetScrapFlavorSize (sel, flavor_type, &size);
-      if (err == noErr)
-	{
-	  do
-	    {
-	      result = make_uninit_string (size);
-	      err = GetScrapFlavorData (sel, flavor_type,
-					&size, SDATA (result));
-	      if (err != noErr)
-		result = Qnil;
-	      else if (size < SBYTES (result))
-		result = make_unibyte_string (SDATA (result), size);
-	    }
-	  while (STRINGP (result) && size > SBYTES (result));
-	}
-    }
-#else
-  Handle handle;
-  SInt32 size, offset;
-
-  if (flavor_type)
-    size = GetScrap (NULL, flavor_type, &offset);
-  if (size >= 0)
-    {
-      handle = NewHandle (size);
-      HLock (handle);
-      size = GetScrap (handle, flavor_type, &offset);
-      if (size >= 0)
-	result = make_unibyte_string (*handle, size);
-      DisposeHandle (handle);
-    }
-#endif
-
-  return result;
-}
-
-/* Get the list of target types in SEL.  The return value is a list of
-   target type symbols possibly followed by scrap flavor type
-   strings.  */
-
-static Lisp_Object
-mac_get_selection_target_list (sel)
-     Selection sel;
-{
-  Lisp_Object result = Qnil, rest, target;
-#if TARGET_API_MAC_CARBON
-  OSStatus err;
-  UInt32 count, i, type;
-  ScrapFlavorInfo *flavor_info = NULL;
-  Lisp_Object strings = Qnil;
-
-  err = GetScrapFlavorCount (sel, &count);
-  if (err == noErr)
-    flavor_info = xmalloc (sizeof (ScrapFlavorInfo) * count);
-  err = GetScrapFlavorInfoList (sel, &count, flavor_info);
-  if (err != noErr)
-    {
-      xfree (flavor_info);
-      flavor_info = NULL;
-    }
-  if (flavor_info == NULL)
-    count = 0;
-#endif
-  for (rest = Vselection_converter_alist; CONSP (rest); rest = XCDR (rest))
-    {
-      ScrapFlavorType flavor_type = 0;
-
-      if (CONSP (XCAR (rest))
-	  && (target = XCAR (XCAR (rest)),
-	      SYMBOLP (target))
-	  && (flavor_type = get_flavor_type_from_symbol (target, sel)))
-	{
-	  result = Fcons (target, result);
-#if TARGET_API_MAC_CARBON
-	  for (i = 0; i < count; i++)
-	    if (flavor_info[i].flavorType == flavor_type)
-	      {
-		flavor_info[i].flavorType = 0;
-		break;
-	      }
-#endif
-	}
-    }
-#if TARGET_API_MAC_CARBON
-  if (flavor_info)
-    {
-      for (i = 0; i < count; i++)
-	if (flavor_info[i].flavorType)
-	  {
-	    type = EndianU32_NtoB (flavor_info[i].flavorType);
-	    strings = Fcons (make_unibyte_string ((char *) &type, 4), strings);
-	  }
-      result = nconc2 (result, strings);
-      xfree (flavor_info);
-    }
-#endif
-
-  return result;
-}
 
 /* Do protocol to assert ourself as a selection owner.
    Update the Vselection_alist so that we can reply to later requests for
@@ -892,8 +580,8 @@
 			 Apple event support
 ***********************************************************************/
 int mac_ready_for_apple_events = 0;
-static Lisp_Object Vmac_apple_event_map;
-static Lisp_Object Qmac_apple_event_class, Qmac_apple_event_id;
+Lisp_Object Vmac_apple_event_map;
+Lisp_Object Qmac_apple_event_class, Qmac_apple_event_id;
 static Lisp_Object Qemacs_suspension_id;
 extern Lisp_Object Qundefined;
 extern void mac_store_apple_event P_ ((Lisp_Object, Lisp_Object,
@@ -1095,7 +783,7 @@
   return err;
 }
 
-static pascal OSErr
+pascal OSErr
 mac_handle_apple_event (apple_event, reply, refcon)
      const AppleEvent *apple_event;
      AppleEvent *reply;
@@ -1173,40 +861,13 @@
   return nresumed;
 }
 
-static void
+void
 cleanup_all_suspended_apple_events ()
 {
   cleanup_suspended_apple_events (&deferred_apple_events, 1);
   cleanup_suspended_apple_events (&suspended_apple_events, 1);
 }
 
-void
-init_apple_event_handler ()
-{
-  OSErr err;
-  long result;
-
-  /* Make sure we have Apple events before starting.  */
-  err = Gestalt (gestaltAppleEventsAttr, &result);
-  if (err != noErr)
-    abort ();
-
-  if (!(result & (1 << gestaltAppleEventsPresent)))
-    abort ();
-
-  err = AEInstallEventHandler (typeWildCard, typeWildCard,
-#if TARGET_API_MAC_CARBON
-			       NewAEEventHandlerUPP (mac_handle_apple_event),
-#else
-			       NewAEEventHandlerProc (mac_handle_apple_event),
-#endif
-			       0L, false);
-  if (err != noErr)
-    abort ();
-
-  atexit (cleanup_all_suspended_apple_events);
-}
-
 static UInt32
 get_suspension_id (apple_event)
      Lisp_Object apple_event;
@@ -1399,419 +1060,18 @@
                       Drag and drop support
 ***********************************************************************/
 #if TARGET_API_MAC_CARBON
-static Lisp_Object Vmac_dnd_known_types;
-static pascal OSErr mac_do_track_drag P_ ((DragTrackingMessage, WindowRef,
-					   void *, DragRef));
-static pascal OSErr mac_do_receive_drag P_ ((WindowRef, void *, DragRef));
-static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL;
-static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL;
-
-extern void mac_store_drag_event P_ ((WindowRef, Point, SInt16,
-				      const AEDesc *));
-
-static pascal OSErr
-mac_do_track_drag (message, window, refcon, drag)
-     DragTrackingMessage message;
-     WindowRef window;
-     void *refcon;
-     DragRef drag;
-{
-  OSErr err = noErr;
-  static int can_accept;
-  UInt16 num_items, index;
-
-  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
-    return dragNotAcceptedErr;
-
-  switch (message)
-    {
-    case kDragTrackingEnterHandler:
-      err = CountDragItems (drag, &num_items);
-      if (err != noErr)
-	break;
-      can_accept = 0;
-      for (index = 1; index <= num_items; index++)
-	{
-	  ItemReference item;
-	  FlavorFlags flags;
-	  Lisp_Object rest;
-
-	  err = GetDragItemReferenceNumber (drag, index, &item);
-	  if (err != noErr)
-	    continue;
-	  for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
-	    {
-	      Lisp_Object str;
-	      FlavorType type;
-
-	      str = XCAR (rest);
-	      if (!(STRINGP (str) && SBYTES (str) == 4))
-		continue;
-	      type = EndianU32_BtoN (*((UInt32 *) SDATA (str)));
-
-	      err = GetFlavorFlags (drag, item, type, &flags);
-	      if (err == noErr)
-		{
-		  can_accept = 1;
-		  break;
-		}
-	    }
-	}
-      break;
-
-    case kDragTrackingEnterWindow:
-      if (can_accept)
-	{
-	  RgnHandle hilite_rgn = NewRgn ();
-
-	  if (hilite_rgn)
-	    {
-	      Rect r;
-
-	      GetWindowPortBounds (window, &r);
-	      OffsetRect (&r, -r.left, -r.top);
-	      RectRgn (hilite_rgn, &r);
-	      ShowDragHilite (drag, hilite_rgn, true);
-	      DisposeRgn (hilite_rgn);
-	    }
-	  SetThemeCursor (kThemeCopyArrowCursor);
-	}
-      break;
-
-    case kDragTrackingInWindow:
-      break;
-
-    case kDragTrackingLeaveWindow:
-      if (can_accept)
-	{
-	  HideDragHilite (drag);
-	  SetThemeCursor (kThemeArrowCursor);
-	}
-      break;
-
-    case kDragTrackingLeaveHandler:
-      break;
-    }
-
-  if (err != noErr)
-    return dragNotAcceptedErr;
-  return noErr;
-}
-
-static pascal OSErr
-mac_do_receive_drag (window, refcon, drag)
-     WindowRef window;
-     void *refcon;
-     DragRef drag;
-{
-  OSErr err;
-  int num_types, i;
-  Lisp_Object rest, str;
-  FlavorType *types;
-  AppleEvent apple_event;
-  Point mouse_pos;
-  SInt16 modifiers;
-
-  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
-    return dragNotAcceptedErr;
-
-  num_types = 0;
-  for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
-    {
-      str = XCAR (rest);
-      if (STRINGP (str) && SBYTES (str) == 4)
-	num_types++;
-    }
-
-  types = xmalloc (sizeof (FlavorType) * num_types);
-  i = 0;
-  for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
-    {
-      str = XCAR (rest);
-      if (STRINGP (str) && SBYTES (str) == 4)
-	types[i++] = EndianU32_BtoN (*((UInt32 *) SDATA (str)));
-    }
-
-  err = create_apple_event_from_drag_ref (drag, num_types, types,
-					  &apple_event);
-  xfree (types);
-
-  if (err == noErr)
-    err = GetDragMouse (drag, &mouse_pos, NULL);
-  if (err == noErr)
-    {
-      GlobalToLocal (&mouse_pos);
-      err = GetDragModifiers (drag, NULL, NULL, &modifiers);
-    }
-  if (err == noErr)
-    {
-      UInt32 key_modifiers = modifiers;
-
-      err = AEPutParamPtr (&apple_event, kEventParamKeyModifiers,
-			   typeUInt32, &key_modifiers, sizeof (UInt32));
-    }
-
-  if (err == noErr)
-    {
-      mac_store_drag_event (window, mouse_pos, 0, &apple_event);
-      AEDisposeDesc (&apple_event);
-      mac_wakeup_from_rne ();
-      return noErr;
-    }
-  else
-    return dragNotAcceptedErr;
-}
+Lisp_Object Vmac_dnd_known_types;
 #endif	/* TARGET_API_MAC_CARBON */
 
-OSErr
-install_drag_handler (window)
-     WindowRef window;
-{
-  OSErr err = noErr;
-
-#if TARGET_API_MAC_CARBON
-  if (mac_do_track_dragUPP == NULL)
-    mac_do_track_dragUPP = NewDragTrackingHandlerUPP (mac_do_track_drag);
-  if (mac_do_receive_dragUPP == NULL)
-    mac_do_receive_dragUPP = NewDragReceiveHandlerUPP (mac_do_receive_drag);
-
-  err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL);
-  if (err == noErr)
-    err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL);
-#endif
-
-  return err;
-}
-
-void
-remove_drag_handler (window)
-     WindowRef window;
-{
-#if TARGET_API_MAC_CARBON
-  if (mac_do_track_dragUPP)
-    RemoveTrackingHandler (mac_do_track_dragUPP, window);
-  if (mac_do_receive_dragUPP)
-    RemoveReceiveHandler (mac_do_receive_dragUPP, window);
-#endif
-}
-
 
 /***********************************************************************
 			Services menu support
 ***********************************************************************/
 #ifdef MAC_OSX
-OSStatus
-install_service_handler ()
-{
-  static const EventTypeSpec specs[] =
-    {{kEventClassService, kEventServiceGetTypes},
-     {kEventClassService, kEventServiceCopy},
-     {kEventClassService, kEventServicePaste},
-     {kEventClassService, kEventServicePerform}};
-
-  return InstallApplicationEventHandler (NewEventHandlerUPP
-					 (mac_handle_service_event),
-					 GetEventTypeCount (specs),
-					 specs, NULL, NULL);
-}
-
-extern OSStatus mac_store_service_event P_ ((EventRef));
-
-static OSStatus
-copy_scrap_flavor_data (from_scrap, to_scrap, flavor_type)
-     ScrapRef from_scrap, to_scrap;
-     ScrapFlavorType flavor_type;
-{
-  OSStatus err;
-  Size size, size_allocated;
-  char *buf = NULL;
-
-  err = GetScrapFlavorSize (from_scrap, flavor_type, &size);
-  if (err == noErr)
-    buf = xmalloc (size);
-  while (buf)
-    {
-      size_allocated = size;
-      err = GetScrapFlavorData (from_scrap, flavor_type, &size, buf);
-      if (err != noErr)
-	{
-	  xfree (buf);
-	  buf = NULL;
-	}
-      else if (size_allocated < size)
-	buf = xrealloc (buf, size);
-      else
-	break;
-    }
-  if (err == noErr)
-    {
-      if (buf == NULL)
-	err = memFullErr;
-      else
-	{
-	  err = PutScrapFlavor (to_scrap, flavor_type, kScrapFlavorMaskNone,
-				size, buf);
-	  xfree (buf);
-	}
-    }
-
-  return err;
-}
-
-static OSStatus
-mac_handle_service_event (call_ref, event, data)
-     EventHandlerCallRef call_ref;
-     EventRef event;
-     void *data;
-{
-  OSStatus err = noErr;
-  ScrapRef cur_scrap, specific_scrap;
-  UInt32 event_kind = GetEventKind (event);
-  CFMutableArrayRef copy_types, paste_types;
-  CFStringRef type;
-  Lisp_Object rest;
-  ScrapFlavorType flavor_type;
-
-  /* Check if Vmac_service_selection is a valid selection that has a
-     corresponding scrap.  */
-  if (!SYMBOLP (Vmac_service_selection))
-    err = eventNotHandledErr;
-  else
-    err = mac_get_selection_from_symbol (Vmac_service_selection, 0, &cur_scrap);
-  if (!(err == noErr && cur_scrap))
-    return eventNotHandledErr;
-
-  switch (event_kind)
-    {
-    case kEventServiceGetTypes:
-      /* Set paste types. */
-      err = GetEventParameter (event, kEventParamServicePasteTypes,
-			       typeCFMutableArrayRef, NULL,
-			       sizeof (CFMutableArrayRef), NULL,
-			       &paste_types);
-      if (err != noErr)
-	break;
-
-      for (rest = Vselection_converter_alist; CONSP (rest);
-	   rest = XCDR (rest))
-	if (CONSP (XCAR (rest)) && SYMBOLP (XCAR (XCAR (rest)))
-	    && (flavor_type =
-		get_flavor_type_from_symbol (XCAR (XCAR (rest)), 0)))
-	  {
-	    type = CreateTypeStringWithOSType (flavor_type);
-	    if (type)
-	      {
-		CFArrayAppendValue (paste_types, type);
-		CFRelease (type);
-	      }
-	  }
-
-      /* Set copy types.  */
-      err = GetEventParameter (event, kEventParamServiceCopyTypes,
-			       typeCFMutableArrayRef, NULL,
-			       sizeof (CFMutableArrayRef), NULL,
-			       &copy_types);
-      if (err != noErr)
-	break;
-
-      if (NILP (Fx_selection_owner_p (Vmac_service_selection)))
-	break;
-      else
-	goto copy_all_flavors;
-
-    case kEventServiceCopy:
-      err = GetEventParameter (event, kEventParamScrapRef,
-			       typeScrapRef, NULL,
-			       sizeof (ScrapRef), NULL, &specific_scrap);
-      if (err != noErr
-	  || NILP (Fx_selection_owner_p (Vmac_service_selection)))
-	{
-	  err = eventNotHandledErr;
-	  break;
-	}
-
-    copy_all_flavors:
-      {
-	UInt32 count, i;
-	ScrapFlavorInfo *flavor_info = NULL;
-	ScrapFlavorFlags flags;
-
-	err = GetScrapFlavorCount (cur_scrap, &count);
-	if (err == noErr)
-	  flavor_info = xmalloc (sizeof (ScrapFlavorInfo) * count);
-	err = GetScrapFlavorInfoList (cur_scrap, &count, flavor_info);
-	if (err != noErr)
-	  {
-	    xfree (flavor_info);
-	    flavor_info = NULL;
-	  }
-	if (flavor_info == NULL)
-	  break;
-
-	for (i = 0; i < count; i++)
-	  {
-	    flavor_type = flavor_info[i].flavorType;
-	    err = GetScrapFlavorFlags (cur_scrap, flavor_type, &flags);
-	    if (err == noErr && !(flags & kScrapFlavorMaskSenderOnly))
-	      {
-		if (event_kind == kEventServiceCopy)
-		  err = copy_scrap_flavor_data (cur_scrap, specific_scrap,
-						flavor_type);
-		else	     /* event_kind == kEventServiceGetTypes */
-		  {
-		    type = CreateTypeStringWithOSType (flavor_type);
-		    if (type)
-		      {
-			CFArrayAppendValue (copy_types, type);
-			CFRelease (type);
-		      }
-		  }
-	      }
-	  }
-	xfree (flavor_info);
-      }
-      break;
-
-    case kEventServicePaste:
-    case kEventServicePerform:
-      {
-	int data_exists_p = 0;
-
-        err = GetEventParameter (event, kEventParamScrapRef, typeScrapRef,
-				 NULL, sizeof (ScrapRef), NULL,
-				 &specific_scrap);
-	if (err == noErr)
-	  err = mac_clear_selection (&cur_scrap);
-	if (err == noErr)
-	  for (rest = Vselection_converter_alist; CONSP (rest);
-	       rest = XCDR (rest))
-	    {
-	      if (! (CONSP (XCAR (rest)) && SYMBOLP (XCAR (XCAR (rest)))))
-		continue;
-	      flavor_type = get_flavor_type_from_symbol (XCAR (XCAR (rest)),
-							 specific_scrap);
-	      if (flavor_type == 0)
-		continue;
-	      err = copy_scrap_flavor_data (specific_scrap, cur_scrap,
-					    flavor_type);
-	      if (err == noErr)
-		data_exists_p = 1;
-	    }
-	if (!data_exists_p)
-	  err = eventNotHandledErr;
-	else
-	  err = mac_store_service_event (event);
-      }
-      break;
-    }
-
-  if (err != noErr)
-    err = eventNotHandledErr;
-  return err;
-}
+/* Selection name for communication via Services menu.  */
+Lisp_Object Vmac_service_selection;
 #endif
 
-
 void
 syms_of_macselect ()
 {
@@ -1870,11 +1130,7 @@
   DEFVAR_LISP ("mac-dnd-known-types", &Vmac_dnd_known_types,
 	       doc: /* The types accepted by default for dropped data.
 The types are chosen in the order they appear in the list.  */);
-  Vmac_dnd_known_types = list4 (build_string ("hfs "), build_string ("utxt"),
-				build_string ("TEXT"), build_string ("TIFF"));
-#ifdef MAC_OSX
-  Vmac_dnd_known_types = Fcons (build_string ("furl"), Vmac_dnd_known_types);
-#endif
+  Vmac_dnd_known_types = mac_dnd_default_known_types ();
 #endif
 
 #ifdef MAC_OSX