diff options
| author | YAMAMOTO Mitsuharu | 2008-04-19 01:24:47 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-04-19 01:24:47 +0000 |
| commit | d421d4d8fccc7f49bceae903014413c15ce6b097 (patch) | |
| tree | 718da21c63746cf5155003aab2e3d44b53decaf7 /src | |
| parent | e4651d75ff6d19fdf867dd508efb5fb9b656f3aa (diff) | |
| download | emacs-d421d4d8fccc7f49bceae903014413c15ce6b097.tar.gz emacs-d421d4d8fccc7f49bceae903014413c15ce6b097.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mac.c | 151 |
1 files changed, 49 insertions, 102 deletions
| @@ -817,7 +817,7 @@ init_coercion_handler () | |||
| 817 | } | 817 | } |
| 818 | 818 | ||
| 819 | #if TARGET_API_MAC_CARBON | 819 | #if TARGET_API_MAC_CARBON |
| 820 | static OSErr | 820 | OSErr |
| 821 | create_apple_event (class, id, result) | 821 | create_apple_event (class, id, result) |
| 822 | AEEventClass class; | 822 | AEEventClass class; |
| 823 | AEEventID id; | 823 | AEEventID id; |
| @@ -842,129 +842,76 @@ create_apple_event (class, id, result) | |||
| 842 | return err; | 842 | return err; |
| 843 | } | 843 | } |
| 844 | 844 | ||
| 845 | OSStatus | 845 | Lisp_Object |
| 846 | create_apple_event_from_event_ref (event, num_params, names, types, result) | 846 | mac_event_parameters_to_lisp (event, num_params, names, types) |
| 847 | EventRef event; | 847 | EventRef event; |
| 848 | UInt32 num_params; | 848 | UInt32 num_params; |
| 849 | const EventParamName *names; | 849 | const EventParamName *names; |
| 850 | const EventParamType *types; | 850 | const EventParamType *types; |
| 851 | AppleEvent *result; | ||
| 852 | { | 851 | { |
| 853 | OSStatus err; | 852 | OSStatus err; |
| 854 | UInt32 i, size; | 853 | Lisp_Object result = Qnil; |
| 854 | UInt32 i; | ||
| 855 | ByteCount size; | ||
| 856 | #ifdef MAC_OSX | ||
| 855 | CFStringRef string; | 857 | CFStringRef string; |
| 856 | CFDataRef data; | 858 | CFDataRef data; |
| 857 | char *buf = NULL; | ||
| 858 | |||
| 859 | err = create_apple_event (0, 0, result); /* Dummy class and ID. */ | ||
| 860 | if (err != noErr) | ||
| 861 | return err; | ||
| 862 | |||
| 863 | for (i = 0; i < num_params; i++) | ||
| 864 | switch (types[i]) | ||
| 865 | { | ||
| 866 | #ifdef MAC_OSX | ||
| 867 | case typeCFStringRef: | ||
| 868 | err = GetEventParameter (event, names[i], typeCFStringRef, NULL, | ||
| 869 | sizeof (CFStringRef), NULL, &string); | ||
| 870 | if (err != noErr) | ||
| 871 | break; | ||
| 872 | data = CFStringCreateExternalRepresentation (NULL, string, | ||
| 873 | kCFStringEncodingUTF8, | ||
| 874 | '?'); | ||
| 875 | if (data == NULL) | ||
| 876 | break; | ||
| 877 | AEPutParamPtr (result, names[i], typeUTF8Text, | ||
| 878 | CFDataGetBytePtr (data), CFDataGetLength (data)); | ||
| 879 | CFRelease (data); | ||
| 880 | break; | ||
| 881 | #endif | 859 | #endif |
| 882 | |||
| 883 | default: | ||
| 884 | err = GetEventParameter (event, names[i], types[i], NULL, | ||
| 885 | 0, &size, NULL); | ||
| 886 | if (err != noErr) | ||
| 887 | break; | ||
| 888 | buf = xrealloc (buf, size); | ||
| 889 | err = GetEventParameter (event, names[i], types[i], NULL, | ||
| 890 | size, NULL, buf); | ||
| 891 | if (err == noErr) | ||
| 892 | AEPutParamPtr (result, names[i], types[i], buf, size); | ||
| 893 | break; | ||
| 894 | } | ||
| 895 | if (buf) | ||
| 896 | xfree (buf); | ||
| 897 | |||
| 898 | return noErr; | ||
| 899 | } | ||
| 900 | |||
| 901 | OSErr | ||
| 902 | create_apple_event_from_drag_ref (drag, num_types, types, result) | ||
| 903 | DragRef drag; | ||
| 904 | UInt32 num_types; | ||
| 905 | const FlavorType *types; | ||
| 906 | AppleEvent *result; | ||
| 907 | { | ||
| 908 | OSErr err; | ||
| 909 | UInt16 num_items; | ||
| 910 | AppleEvent items; | ||
| 911 | long index; | ||
| 912 | char *buf = NULL; | 860 | char *buf = NULL; |
| 913 | 861 | ||
| 914 | err = CountDragItems (drag, &num_items); | 862 | for (i = 0; i < num_params; i++) |
| 915 | if (err != noErr) | ||
| 916 | return err; | ||
| 917 | err = AECreateList (NULL, 0, false, &items); | ||
| 918 | if (err != noErr) | ||
| 919 | return err; | ||
| 920 | |||
| 921 | for (index = 1; index <= num_items; index++) | ||
| 922 | { | 863 | { |
| 923 | ItemReference item; | 864 | EventParamName name = names[i]; |
| 924 | DescType desc_type = typeNull; | 865 | EventParamType type = types[i]; |
| 925 | Size size; | ||
| 926 | 866 | ||
| 927 | err = GetDragItemReferenceNumber (drag, index, &item); | 867 | switch (type) |
| 928 | if (err == noErr) | ||
| 929 | { | 868 | { |
| 930 | int i; | 869 | #ifdef MAC_OSX |
| 870 | case typeCFStringRef: | ||
| 871 | err = GetEventParameter (event, name, typeCFStringRef, NULL, | ||
| 872 | sizeof (CFStringRef), NULL, &string); | ||
| 873 | if (err != noErr) | ||
| 874 | break; | ||
| 875 | data = CFStringCreateExternalRepresentation (NULL, string, | ||
| 876 | kCFStringEncodingUTF8, | ||
| 877 | '?'); | ||
| 878 | if (data == NULL) | ||
| 879 | break; | ||
| 880 | name = EndianU32_NtoB (name); | ||
| 881 | type = EndianU32_NtoB (typeUTF8Text); | ||
| 882 | result = | ||
| 883 | Fcons (Fcons (make_unibyte_string ((char *) &name, 4), | ||
| 884 | Fcons (make_unibyte_string ((char *) &type, 4), | ||
| 885 | make_unibyte_string (CFDataGetBytePtr (data), | ||
| 886 | CFDataGetLength (data)))), | ||
| 887 | result); | ||
| 888 | CFRelease (data); | ||
| 889 | break; | ||
| 890 | #endif | ||
| 931 | 891 | ||
| 932 | for (i = 0; i < num_types; i++) | 892 | default: |
| 893 | err = GetEventParameter (event, name, type, NULL, 0, &size, NULL); | ||
| 894 | if (err != noErr) | ||
| 895 | break; | ||
| 896 | buf = xrealloc (buf, size); | ||
| 897 | err = GetEventParameter (event, name, type, NULL, size, NULL, buf); | ||
| 898 | if (err == noErr) | ||
| 933 | { | 899 | { |
| 934 | err = GetFlavorDataSize (drag, item, types[i], &size); | 900 | name = EndianU32_NtoB (name); |
| 935 | if (err == noErr) | 901 | type = EndianU32_NtoB (type); |
| 936 | { | 902 | result = |
| 937 | buf = xrealloc (buf, size); | 903 | Fcons (Fcons (make_unibyte_string ((char *) &name, 4), |
| 938 | err = GetFlavorData (drag, item, types[i], buf, &size, 0); | 904 | Fcons (make_unibyte_string ((char *) &type, 4), |
| 939 | } | 905 | make_unibyte_string (buf, size))), |
| 940 | if (err == noErr) | 906 | result); |
| 941 | { | ||
| 942 | desc_type = types[i]; | ||
| 943 | break; | ||
| 944 | } | ||
| 945 | } | 907 | } |
| 908 | break; | ||
| 946 | } | 909 | } |
| 947 | err = AEPutPtr (&items, index, desc_type, | ||
| 948 | desc_type != typeNull ? buf : NULL, | ||
| 949 | desc_type != typeNull ? size : 0); | ||
| 950 | if (err != noErr) | ||
| 951 | break; | ||
| 952 | } | 910 | } |
| 953 | if (buf) | 911 | if (buf) |
| 954 | xfree (buf); | 912 | xfree (buf); |
| 955 | 913 | ||
| 956 | if (err == noErr) | 914 | return result; |
| 957 | { | ||
| 958 | err = create_apple_event (0, 0, result); /* Dummy class and ID. */ | ||
| 959 | if (err == noErr) | ||
| 960 | err = AEPutParamDesc (result, keyDirectObject, &items); | ||
| 961 | if (err != noErr) | ||
| 962 | AEDisposeDesc (result); | ||
| 963 | } | ||
| 964 | |||
| 965 | AEDisposeDesc (&items); | ||
| 966 | |||
| 967 | return err; | ||
| 968 | } | 915 | } |
| 969 | #endif /* TARGET_API_MAC_CARBON */ | 916 | #endif /* TARGET_API_MAC_CARBON */ |
| 970 | 917 | ||