Mercurial > emacs
changeset 80513:e58dfb854c06
(create_apple_event) [TARGET_API_MAC_CARBON]:
Make function non-static.
(create_apple_event_from_event_ref) [TARGET_API_MAC_CARBON]:
Remove function.
(create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]:
Move to mactoolbox.c.
(mac_event_parameters_to_lisp) [TARGET_API_MAC_CARBON]: New function.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Sat, 19 Apr 2008 01:24:47 +0000 |
parents | 444a87e05509 |
children | fbe5484e7555 |
files | src/mac.c |
diffstat | 1 files changed, 51 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/src/mac.c Fri Apr 18 18:27:25 2008 +0000 +++ b/src/mac.c Sat Apr 19 01:24:47 2008 +0000 @@ -817,7 +817,7 @@ } #if TARGET_API_MAC_CARBON -static OSErr +OSErr create_apple_event (class, id, result) AEEventClass class; AEEventID id; @@ -842,129 +842,76 @@ return err; } -OSStatus -create_apple_event_from_event_ref (event, num_params, names, types, result) +Lisp_Object +mac_event_parameters_to_lisp (event, num_params, names, types) EventRef event; UInt32 num_params; const EventParamName *names; const EventParamType *types; - AppleEvent *result; { OSStatus err; - UInt32 i, size; + Lisp_Object result = Qnil; + UInt32 i; + ByteCount size; +#ifdef MAC_OSX CFStringRef string; CFDataRef data; +#endif char *buf = NULL; - err = create_apple_event (0, 0, result); /* Dummy class and ID. */ - if (err != noErr) - return err; - for (i = 0; i < num_params; i++) - switch (types[i]) - { + { + EventParamName name = names[i]; + EventParamType type = types[i]; + + switch (type) + { #ifdef MAC_OSX - case typeCFStringRef: - err = GetEventParameter (event, names[i], typeCFStringRef, NULL, - sizeof (CFStringRef), NULL, &string); - if (err != noErr) - break; - data = CFStringCreateExternalRepresentation (NULL, string, - kCFStringEncodingUTF8, - '?'); - if (data == NULL) - break; - AEPutParamPtr (result, names[i], typeUTF8Text, - CFDataGetBytePtr (data), CFDataGetLength (data)); - CFRelease (data); - break; -#endif - - default: - err = GetEventParameter (event, names[i], types[i], NULL, - 0, &size, NULL); - if (err != noErr) + case typeCFStringRef: + err = GetEventParameter (event, name, typeCFStringRef, NULL, + sizeof (CFStringRef), NULL, &string); + if (err != noErr) + break; + data = CFStringCreateExternalRepresentation (NULL, string, + kCFStringEncodingUTF8, + '?'); + if (data == NULL) + break; + name = EndianU32_NtoB (name); + type = EndianU32_NtoB (typeUTF8Text); + result = + Fcons (Fcons (make_unibyte_string ((char *) &name, 4), + Fcons (make_unibyte_string ((char *) &type, 4), + make_unibyte_string (CFDataGetBytePtr (data), + CFDataGetLength (data)))), + result); + CFRelease (data); break; - 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); - break; - } - if (buf) - xfree (buf); - - return noErr; -} - -OSErr -create_apple_event_from_drag_ref (drag, num_types, types, result) - DragRef drag; - UInt32 num_types; - const 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++) +#endif + + default: + err = GetEventParameter (event, name, type, NULL, 0, &size, NULL); + if (err != noErr) + break; + buf = xrealloc (buf, size); + err = GetEventParameter (event, name, type, NULL, size, NULL, buf); + if (err == noErr) { - 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; - } + name = EndianU32_NtoB (name); + type = EndianU32_NtoB (type); + result = + Fcons (Fcons (make_unibyte_string ((char *) &name, 4), + Fcons (make_unibyte_string ((char *) &type, 4), + make_unibyte_string (buf, size))), + result); } + 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; + return result; } #endif /* TARGET_API_MAC_CARBON */