diff options
| author | Po Lu | 2024-05-18 20:45:35 +0800 |
|---|---|---|
| committer | Po Lu | 2024-05-18 20:45:35 +0800 |
| commit | 8dc00dc22250b383e7692fc761cbca25b014aa8a (patch) | |
| tree | a016100ec536856ccbb3c7334b63e0595b8b549f /src/androidselect.c | |
| parent | 5ec4c1a7d3f0d184982f4efa0c01bc9a76197533 (diff) | |
| download | emacs-8dc00dc22250b383e7692fc761cbca25b014aa8a.tar.gz emacs-8dc00dc22250b383e7692fc761cbca25b014aa8a.zip | |
Housekeeping around androidselect.c
* java/org/gnu/emacs/EmacsClipboard.java (setClipboard)
(getClipboard):
* java/org/gnu/emacs/EmacsSdk11Clipboard.java (setClipboard)
(getClipboard):
* java/org/gnu/emacs/EmacsSdk8Clipboard.java (setClipboard)
(getClipboard): Save and return Strings rather than byte arrays.
* src/androidselect.c (android_init_emacs_clipboard)
(Fandroid_set_clipboard, Fandroid_get_clipboard): Adjust to
match.
Diffstat (limited to 'src/androidselect.c')
| -rw-r--r-- | src/androidselect.c | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/src/androidselect.c b/src/androidselect.c index 7c93607848a..50982738743 100644 --- a/src/androidselect.c +++ b/src/androidselect.c | |||
| @@ -94,10 +94,10 @@ android_init_emacs_clipboard (void) | |||
| 94 | name, signature); \ | 94 | name, signature); \ |
| 95 | eassert (clipboard_class.c_name); | 95 | eassert (clipboard_class.c_name); |
| 96 | 96 | ||
| 97 | FIND_METHOD (set_clipboard, "setClipboard", "([B)V"); | 97 | FIND_METHOD (set_clipboard, "setClipboard", "(Ljava/lang/String;)V"); |
| 98 | FIND_METHOD (owns_clipboard, "ownsClipboard", "()I"); | 98 | FIND_METHOD (owns_clipboard, "ownsClipboard", "()I"); |
| 99 | FIND_METHOD (clipboard_exists, "clipboardExists", "()Z"); | 99 | FIND_METHOD (clipboard_exists, "clipboardExists", "()Z"); |
| 100 | FIND_METHOD (get_clipboard, "getClipboard", "()[B"); | 100 | FIND_METHOD (get_clipboard, "getClipboard", "()Ljava/lang/String;"); |
| 101 | FIND_METHOD (get_clipboard_targets, "getClipboardTargets", | 101 | FIND_METHOD (get_clipboard_targets, "getClipboardTargets", |
| 102 | "()[Ljava/lang/String;"); | 102 | "()[Ljava/lang/String;"); |
| 103 | FIND_METHOD (get_clipboard_data, "getClipboardData", | 103 | FIND_METHOD (get_clipboard_data, "getClipboardData", |
| @@ -151,28 +151,26 @@ DEFUN ("android-set-clipboard", Fandroid_set_clipboard, | |||
| 151 | doc: /* Set the clipboard text to STRING. */) | 151 | doc: /* Set the clipboard text to STRING. */) |
| 152 | (Lisp_Object string) | 152 | (Lisp_Object string) |
| 153 | { | 153 | { |
| 154 | jarray bytes; | 154 | jstring text; |
| 155 | 155 | ||
| 156 | if (!android_init_gui) | 156 | if (!android_init_gui) |
| 157 | error ("Accessing clipboard without display connection"); | 157 | error ("Accessing clipboard without display connection"); |
| 158 | 158 | ||
| 159 | CHECK_STRING (string); | 159 | CHECK_STRING (string); |
| 160 | string = ENCODE_UTF_8 (string); | 160 | string = code_convert_string_norecord (string, Qandroid_jni, |
| 161 | true); | ||
| 161 | 162 | ||
| 162 | bytes = (*android_java_env)->NewByteArray (android_java_env, | 163 | text = (*android_java_env)->NewStringUTF (android_java_env, |
| 163 | SBYTES (string)); | 164 | SSDATA (string)); |
| 164 | android_exception_check (); | 165 | android_exception_check (); |
| 165 | 166 | ||
| 166 | (*android_java_env)->SetByteArrayRegion (android_java_env, bytes, | ||
| 167 | 0, SBYTES (string), | ||
| 168 | (jbyte *) SDATA (string)); | ||
| 169 | (*android_java_env)->CallVoidMethod (android_java_env, | 167 | (*android_java_env)->CallVoidMethod (android_java_env, |
| 170 | clipboard, | 168 | clipboard, |
| 171 | clipboard_class.set_clipboard, | 169 | clipboard_class.set_clipboard, |
| 172 | bytes); | 170 | text); |
| 173 | android_exception_check_1 (bytes); | 171 | android_exception_check_1 (text); |
| 172 | ANDROID_DELETE_LOCAL_REF (text); | ||
| 174 | 173 | ||
| 175 | ANDROID_DELETE_LOCAL_REF (bytes); | ||
| 176 | return Qnil; | 174 | return Qnil; |
| 177 | } | 175 | } |
| 178 | 176 | ||
| @@ -185,39 +183,39 @@ Alternatively, return nil if the clipboard is empty. */) | |||
| 185 | (void) | 183 | (void) |
| 186 | { | 184 | { |
| 187 | Lisp_Object string; | 185 | Lisp_Object string; |
| 188 | jarray bytes; | 186 | jstring text; |
| 189 | jmethodID method; | 187 | jmethodID method; |
| 190 | size_t length; | 188 | jsize length; |
| 191 | jbyte *data; | 189 | const char *data; |
| 192 | 190 | ||
| 193 | if (!android_init_gui) | 191 | if (!android_init_gui) |
| 194 | error ("No Android display connection!"); | 192 | error ("No Android display connection!"); |
| 195 | 193 | ||
| 196 | method = clipboard_class.get_clipboard; | 194 | method = clipboard_class.get_clipboard; |
| 197 | bytes | 195 | text |
| 198 | = (*android_java_env)->CallObjectMethod (android_java_env, | 196 | = (*android_java_env)->CallObjectMethod (android_java_env, |
| 199 | clipboard, | 197 | clipboard, |
| 200 | method); | 198 | method); |
| 201 | android_exception_check (); | 199 | android_exception_check (); |
| 202 | 200 | ||
| 203 | if (!bytes) | 201 | if (!text) |
| 204 | return Qnil; | 202 | return Qnil; |
| 205 | 203 | ||
| 206 | length = (*android_java_env)->GetArrayLength (android_java_env, | 204 | /* Retrieve a pointer to the raw JNI-encoded bytes of the string. */ |
| 207 | bytes); | 205 | length = (*android_java_env)->GetStringUTFLength (android_java_env, |
| 208 | data = (*android_java_env)->GetByteArrayElements (android_java_env, | 206 | text); |
| 209 | bytes, NULL); | 207 | data = (*android_java_env)->GetStringUTFChars (android_java_env, text, |
| 210 | android_exception_check_nonnull (data, bytes); | 208 | NULL); |
| 211 | 209 | android_exception_check_nonnull ((void *) data, text); | |
| 212 | string = make_unibyte_string ((char *) data, length); | ||
| 213 | 210 | ||
| 214 | (*android_java_env)->ReleaseByteArrayElements (android_java_env, | 211 | /* Copy them into a unibyte string for decoding. */ |
| 215 | bytes, data, | 212 | string = make_unibyte_string (data, length); |
| 216 | JNI_ABORT); | 213 | (*android_java_env)->ReleaseStringUTFChars (android_java_env, text, |
| 217 | ANDROID_DELETE_LOCAL_REF (bytes); | 214 | data); |
| 215 | ANDROID_DELETE_LOCAL_REF (text); | ||
| 218 | 216 | ||
| 219 | /* Now decode the resulting string. */ | 217 | /* Now decode the resulting string. */ |
| 220 | return code_convert_string_norecord (string, Qutf_8, false); | 218 | return code_convert_string_norecord (string, Qandroid_jni, false); |
| 221 | } | 219 | } |
| 222 | 220 | ||
| 223 | DEFUN ("android-clipboard-exists-p", Fandroid_clipboard_exists_p, | 221 | DEFUN ("android-clipboard-exists-p", Fandroid_clipboard_exists_p, |