From: YAMAMOTO Mitsuharu Date: Fri, 5 May 2006 06:44:01 +0000 (+0000) Subject: (mac_aelist_to_lisp, mac_aedesc_to_lisp): Change arg 1 to X-Git-Tag: emacs-pretest-22.0.90~2812 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b99934e6ee11b725630081bfecc7e266eafb2805;p=emacs.git (mac_aelist_to_lisp, mac_aedesc_to_lisp): Change arg 1 to `const AEDesc *'. [TARGET_API_MAC_CARBON] (create_apple_event): New function. [TARGET_API_MAC_CARBON] (create_apple_event_from_event_ref): Use it. Use xrealloc instead of repeated xmalloc/xfree. [TARGET_API_MAC_CARBON] (create_apple_event_from_drag_ref): New function. --- diff --git a/src/mac.c b/src/mac.c index 444320322c3..c23fc1d582e 100644 --- a/src/mac.c +++ b/src/mac.c @@ -272,7 +272,7 @@ static Lisp_Object Qundecoded_file_name; static Lisp_Object mac_aelist_to_lisp (desc_list) - AEDescList *desc_list; + const AEDescList *desc_list; { OSErr err; long count; @@ -337,7 +337,7 @@ mac_aelist_to_lisp (desc_list) Lisp_Object mac_aedesc_to_lisp (desc) - AEDesc *desc; + const AEDesc *desc; { OSErr err = noErr; DescType desc_type = desc->descriptorType; @@ -665,33 +665,46 @@ init_coercion_handler () } #if TARGET_API_MAC_CARBON -OSErr -create_apple_event_from_event_ref (event, num_params, names, types, result) - EventRef event; - UInt32 num_params; - EventParamName *names; - EventParamType *types; +static OSErr +create_apple_event (class, id, result) + AEEventClass class; + AEEventID id; AppleEvent *result; { OSErr err; static const ProcessSerialNumber psn = {0, kCurrentProcess}; AEAddressDesc address_desc; - UInt32 i, size; - CFStringRef string; - CFDataRef data; - char *buf; err = AECreateDesc (typeProcessSerialNumber, &psn, sizeof (ProcessSerialNumber), &address_desc); if (err == noErr) { - err = AECreateAppleEvent (0, 0, /* Dummy class and ID. */ + err = AECreateAppleEvent (class, id, &address_desc, /* NULL is not allowed on Mac OS Classic. */ kAutoGenerateReturnID, kAnyTransactionID, result); AEDisposeDesc (&address_desc); } + + return err; +} + +OSErr +create_apple_event_from_event_ref (event, num_params, names, types, result) + EventRef event; + UInt32 num_params; + EventParamName *names; + EventParamType *types; + AppleEvent *result; +{ + OSErr err; + UInt32 i, size; + CFStringRef string; + CFDataRef data; + char *buf = NULL; + + err = create_apple_event (0, 0, result); /* Dummy class and ID. */ if (err != noErr) return err; @@ -721,19 +734,88 @@ create_apple_event_from_event_ref (event, num_params, names, types, result) 0, &size, NULL); if (err != noErr) break; - buf = xmalloc (size); + buf = xrealloc (buf, size); err = GetEventParameter (event, names[i], types[i], NULL, size, NULL, buf); if (err == noErr) AEPutParamPtr (result, names[i], types[i], buf, size); - xfree (buf); break; } + if (buf) + xfree (buf); return noErr; } -#endif +OSErr +create_apple_event_from_drag_ref (drag, num_types, types, result) + DragRef drag; + UInt32 num_types; + FlavorType *types; + AppleEvent *result; +{ + OSErr err; + UInt16 num_items; + AppleEvent items; + long index; + char *buf = NULL; + + err = CountDragItems (drag, &num_items); + if (err != noErr) + return err; + err = AECreateList (NULL, 0, false, &items); + if (err != noErr) + return err; + + for (index = 1; index <= num_items; index++) + { + ItemReference item; + DescType desc_type = typeNull; + Size size; + + err = GetDragItemReferenceNumber (drag, index, &item); + if (err == noErr) + { + int i; + + for (i = 0; i < num_types; i++) + { + err = GetFlavorDataSize (drag, item, types[i], &size); + if (err == noErr) + { + buf = xrealloc (buf, size); + err = GetFlavorData (drag, item, types[i], buf, &size, 0); + } + if (err == noErr) + { + desc_type = types[i]; + break; + } + } + } + err = AEPutPtr (&items, index, desc_type, + desc_type != typeNull ? buf : NULL, + desc_type != typeNull ? size : 0); + if (err != noErr) + break; + } + if (buf) + xfree (buf); + + if (err == noErr) + { + err = create_apple_event (0, 0, result); /* Dummy class and ID. */ + if (err == noErr) + err = AEPutParamDesc (result, keyDirectObject, &items); + if (err != noErr) + AEDisposeDesc (result); + } + + AEDisposeDesc (&items); + + return err; +} +#endif /* TARGET_API_MAC_CARBON */ /*********************************************************************** Conversion between Lisp and Core Foundation objects