/* Send an ANDROID_CONFIGURE_NOTIFY event. The values of all the
functions below are the serials of the events sent. */
- public static native long sendConfigureNotify (short window, long time,
+ public static native long sendConfigureNotify (long window, long time,
int x, int y, int width,
int height);
/* Send an ANDROID_KEY_PRESS event. */
- public static native long sendKeyPress (short window, long time, int state,
+ public static native long sendKeyPress (long window, long time, int state,
int keyCode, int unicodeChar);
/* Send an ANDROID_KEY_RELEASE event. */
- public static native long sendKeyRelease (short window, long time, int state,
+ public static native long sendKeyRelease (long window, long time, int state,
int keyCode, int unicodeChar);
/* Send an ANDROID_FOCUS_IN event. */
- public static native long sendFocusIn (short window, long time);
+ public static native long sendFocusIn (long window, long time);
/* Send an ANDROID_FOCUS_OUT event. */
- public static native long sendFocusOut (short window, long time);
+ public static native long sendFocusOut (long window, long time);
/* Send an ANDROID_WINDOW_ACTION event. */
- public static native long sendWindowAction (short window, int action);
+ public static native long sendWindowAction (long window, int action);
/* Send an ANDROID_ENTER_NOTIFY event. */
- public static native long sendEnterNotify (short window, int x, int y,
+ public static native long sendEnterNotify (long window, int x, int y,
long time);
/* Send an ANDROID_LEAVE_NOTIFY event. */
- public static native long sendLeaveNotify (short window, int x, int y,
+ public static native long sendLeaveNotify (long window, int x, int y,
long time);
/* Send an ANDROID_MOTION_NOTIFY event. */
- public static native long sendMotionNotify (short window, int x, int y,
+ public static native long sendMotionNotify (long window, int x, int y,
long time);
/* Send an ANDROID_BUTTON_PRESS event. */
- public static native long sendButtonPress (short window, int x, int y,
+ public static native long sendButtonPress (long window, int x, int y,
long time, int state,
int button);
/* Send an ANDROID_BUTTON_RELEASE event. */
- public static native long sendButtonRelease (short window, int x, int y,
+ public static native long sendButtonRelease (long window, int x, int y,
long time, int state,
int button);
/* Send an ANDROID_TOUCH_DOWN event. */
- public static native long sendTouchDown (short window, int x, int y,
+ public static native long sendTouchDown (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_TOUCH_UP event. */
- public static native long sendTouchUp (short window, int x, int y,
+ public static native long sendTouchUp (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_TOUCH_MOVE event. */
- public static native long sendTouchMove (short window, int x, int y,
+ public static native long sendTouchMove (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_WHEEL event. */
- public static native long sendWheel (short window, int x, int y,
+ public static native long sendWheel (long window, int x, int y,
long time, int state,
float xDelta, float yDelta);
/* Send an ANDROID_ICONIFIED event. */
- public static native long sendIconified (short window);
+ public static native long sendIconified (long window);
/* Send an ANDROID_DEICONIFIED event. */
- public static native long sendDeiconified (short window);
+ public static native long sendDeiconified (long window);
/* Send an ANDROID_CONTEXT_MENU event. */
- public static native long sendContextMenu (short window, int menuEventID,
+ public static native long sendContextMenu (long window, int menuEventID,
int menuEventSerial);
/* Send an ANDROID_EXPOSE event. */
- public static native long sendExpose (short window, int x, int y,
+ public static native long sendExpose (long window, int x, int y,
int width, int height);
/* Send an ANDROID_DND_DRAG event. */
- public static native long sendDndDrag (short window, int x, int y);
+ public static native long sendDndDrag (long window, int x, int y);
/* Send an ANDROID_DND_URI event. */
- public static native long sendDndUri (short window, int x, int y,
+ public static native long sendDndUri (long window, int x, int y,
String text);
/* Send an ANDROID_DND_TEXT event. */
- public static native long sendDndText (short window, int x, int y,
+ public static native long sendDndText (long window, int x, int y,
String text);
/* Send an ANDROID_NOTIFICATION_CANCELED event. */
/* Input connection functions. These mostly correspond to their
counterparts in Android's InputConnection. */
- public static native void beginBatchEdit (short window);
- public static native void endBatchEdit (short window);
- public static native void commitCompletion (short window, String text,
+ public static native void beginBatchEdit (long window);
+ public static native void endBatchEdit (long window);
+ public static native void commitCompletion (long window, String text,
int position);
- public static native void commitText (short window, String text,
+ public static native void commitText (long window, String text,
int position);
- public static native void deleteSurroundingText (short window,
+ public static native void deleteSurroundingText (long window,
int leftLength,
int rightLength);
- public static native void finishComposingText (short window);
- public static native void replaceText (short window, int start, int end,
+ public static native void finishComposingText (long window);
+ public static native void replaceText (long window, int start, int end,
String text, int newCursorPosition,
TextAttribute attributes);
- public static native String getSelectedText (short window, int flags);
- public static native String getTextAfterCursor (short window, int length,
+ public static native String getSelectedText (long window, int flags);
+ public static native String getTextAfterCursor (long window, int length,
int flags);
- public static native String getTextBeforeCursor (short window, int length,
+ public static native String getTextBeforeCursor (long window, int length,
int flags);
- public static native void setComposingText (short window, String text,
+ public static native void setComposingText (long window, String text,
int newCursorPosition);
- public static native void setComposingRegion (short window, int start,
+ public static native void setComposingRegion (long window, int start,
int end);
- public static native void setSelection (short window, int start, int end);
- public static native void performEditorAction (short window,
+ public static native void setSelection (long window, int start, int end);
+ public static native void performEditorAction (long window,
int editorAction);
- public static native void performContextMenuAction (short window,
+ public static native void performContextMenuAction (long window,
int contextMenuAction);
- public static native ExtractedText getExtractedText (short window,
+ public static native ExtractedText getExtractedText (long window,
ExtractedTextRequest req,
int flags);
- public static native void requestSelectionUpdate (short window);
- public static native void requestCursorUpdates (short window, int mode);
- public static native void clearInputFlags (short window);
- public static native SurroundingText getSurroundingText (short window,
+ public static native void requestSelectionUpdate (long window);
+ public static native void requestCursorUpdates (long window, int mode);
+ public static native void clearInputFlags (long window);
+ public static native SurroundingText getSurroundingText (long window,
int left, int right,
int flags);
- public static native TextSnapshot takeSnapshot (short window);
+ public static native TextSnapshot takeSnapshot (long window);
\f
/* Return the current value of the selection, or -1 upon
failure. */
- public static native int[] getSelection (short window);
+ public static native int[] getSelection (long window);
\f
/* Graphics functions used as replacements for potentially buggy
jmethodID get_dead_char;
};
+struct android_emacs_handle
+{
+ jclass class;
+ jmethodID destroy_handle;
+ jfieldID handle;
+};
+
/* The API level of the current device. */
static int android_api_level;
/* Various methods associated with the KeyCharacterMap class. */
static struct android_key_character_map key_character_map_class;
+/* Various methods and fields associated with the EmacsHandleObject
+ class. */
+static struct android_emacs_handle handle_class;
+
/* The time at which Emacs was installed, which also supplies the
mtime of asset files. */
struct timespec emacs_installation_time;
"Lorg/gnu/emacs/EmacsGC;II)V");
FIND_METHOD (ring_bell, "ringBell", "(I)V");
FIND_METHOD (query_tree, "queryTree",
- "(Lorg/gnu/emacs/EmacsWindow;)[S");
+ "(Lorg/gnu/emacs/EmacsWindow;)[J");
FIND_METHOD (get_screen_width, "getScreenWidth", "(Z)I");
FIND_METHOD (get_screen_height, "getScreenHeight", "(Z)I");
FIND_METHOD (detect_mouse, "detectMouse", "()Z");
name, signature); \
eassert (pixmap_class.c_name);
- FIND_METHOD (constructor_mutable, "<init>", "(SIII)V");
+ FIND_METHOD (constructor_mutable, "<init>", "(III)V");
#undef FIND_METHOD
}
name, signature); \
eassert (cursor_class.c_name);
- FIND_METHOD (constructor, "<init>", "(SI)V");
+ FIND_METHOD (constructor, "<init>", "(I)V");
#undef FIND_METHOD
}
eassert (key_character_map_class.get_dead_char);
}
+static void
+android_init_emacs_handle (void)
+{
+ jclass old;
+
+ handle_class.class
+ = (*android_java_env)->FindClass (android_java_env,
+ "org/gnu/emacs/EmacsHandleObject");
+ eassert (handle_class.class);
+
+ old = handle_class.class;
+ handle_class.class
+ = (jclass) (*android_java_env)->NewGlobalRef (android_java_env,
+ (jobject) old);
+ ANDROID_DELETE_LOCAL_REF (old);
+
+ if (!handle_class.class)
+ emacs_abort ();
+
+#define FIND_METHOD(c_name, name, signature) \
+ handle_class.c_name \
+ = (*android_java_env)->GetMethodID (android_java_env, \
+ handle_class.class, \
+ name, signature); \
+ eassert (handle_class.c_name);
+
+ FIND_METHOD (destroy_handle, "destroyHandle", "()V");
+#undef FIND_METHOD
+
+ handle_class.handle
+ = (*android_java_env)->GetFieldID (android_java_env,
+ handle_class.class,
+ "handle", "J");
+ eassert (handle_class.handle);
+}
+
JNIEXPORT void JNICALL
NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv,
jobject dump_file_object)
android_init_emacs_window ();
android_init_emacs_cursor ();
android_init_key_character_map ();
+ android_init_emacs_handle ();
/* Set HOME to the app data directory. */
setenv ("HOME", android_files_dir, 1);
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
- jshort window, jlong time,
+ jlong window, jlong time,
jint x, jint y, jint width,
jint height)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object,
- jshort window, jlong time,
+ jlong window, jlong time,
jint state, jint keycode,
jint unicode_char)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object,
- jshort window, jlong time,
+ jlong window, jlong time,
jint state, jint keycode,
jint unicode_char)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object,
- jshort window, jlong time)
+ jlong window, jlong time)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object,
- jshort window, jlong time)
+ jlong window, jlong time)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object,
- jshort window, jint action)
+ jlong window, jint action)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint state,
jint button)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint state,
jint button)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint pointer_id,
jint flags)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint pointer_id,
jint flags)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint pointer_id,
jint flags)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jlong time, jint state,
jfloat x_delta, jfloat y_delta)
{
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object,
- jshort window)
+ jlong window)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object,
- jshort window)
+ jlong window)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object,
- jshort window, jint menu_event_id,
+ jlong window, jint menu_event_id,
jint menu_event_serial)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendExpose) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jint width, jint height)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendDndDrag) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y)
+ jlong window, jint x, jint y)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendDndUri) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jstring string)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendDndText) (JNIEnv *env, jobject object,
- jshort window, jint x, jint y,
+ jlong window, jint x, jint y,
jstring string)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
x2 = MAX (x2, 0);
y2 = MAX (y2, 0);
-
if (x1 >= src_info.width
|| x1 >= dest_info.width)
x1 = MIN (dest_info.width - 1, src_info.width - 1);
This means that every local reference must be explicitly destroyed
with DeleteLocalRef. A helper macro is provided to do this. */
-struct android_handle_entry
-{
- /* The type. */
- enum android_handle_type type;
-
- /* The handle. */
- jobject handle;
-};
-
-/* Table of handles MAX_HANDLE long. */
-struct android_handle_entry android_handles[USHRT_MAX];
-
-/* The largest handle ID currently known, but subject to
- wraparound. */
-static android_handle max_handle;
-
-/* Allocate a new, unused, handle identifier. If Emacs is out of
- identifiers, return 0. */
-
-static android_handle
-android_alloc_id (void)
-{
- android_handle handle;
-
- /* 0 is never a valid handle ID. */
-
- if (!max_handle)
- max_handle++;
-
- /* See if the handle is already occupied. */
-
- if (android_handles[max_handle].handle)
- {
- /* Look for a fresh unoccupied handle. */
-
- handle = max_handle;
- max_handle++;
-
- while (handle != max_handle)
- {
- ++max_handle;
-
- /* Make sure the handle is valid. */
- if (!max_handle)
- ++max_handle;
-
- if (!android_handles[max_handle].handle)
- return max_handle++;
- }
-
- return ANDROID_NONE;
- }
-
- return max_handle++;
-}
-
/* Destroy the specified handle and mark it as free on the Java side
as well. */
static jclass old, class;
static jmethodID method;
- if (!android_handles[handle].handle)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Trying to destroy free handle!");
- emacs_abort ();
- }
-
if (!class)
{
class
ANDROID_DELETE_LOCAL_REF (old);
}
- (*android_java_env)->CallVoidMethod (android_java_env,
- android_handles[handle].handle,
+ (*android_java_env)->CallVoidMethod (android_java_env, (jobject) handle,
method);
/* Just clear any exception thrown. If destroying the handle
(*android_java_env)->ExceptionClear (android_java_env);
/* Delete the global reference regardless of any error. */
- (*android_java_env)->DeleteGlobalRef (android_java_env,
- android_handles[handle].handle);
- android_handles[handle].handle = NULL;
-}
-
-jobject
-android_resolve_handle (android_handle handle,
- enum android_handle_type type)
-{
- if (!handle)
- /* ANDROID_NONE. */
- return NULL;
-
- /* CheckJNI will normally ensure that the handle exists and is
- the right type, but with a less informative error message.
- Don't waste cycles doing our own checking here. */
-
-#ifdef ENABLE_CHECKING
-
- if (!android_handles[handle].handle)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Trying to resolve free handle!");
- emacs_abort ();
- }
-
- if (android_handles[handle].type != type)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Handle has wrong type!");
- emacs_abort ();
- }
-
-#endif /* ENABLE_CHECKING */
-
- return android_handles[handle].handle;
-}
-
-static jobject
-android_resolve_handle2 (android_handle handle,
- enum android_handle_type type,
- enum android_handle_type type2)
-{
- if (!handle)
- return NULL;
-
- /* CheckJNI will normally ensure that the handle exists and is
- the right type, but with a less informative error message.
- Don't waste cycles doing our own checking here. */
-
-#ifdef ENABLE_CHECKING
-
- if (!android_handles[handle].handle)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Trying to resolve free handle!");
- emacs_abort ();
- }
-
- if (android_handles[handle].type != type
- && android_handles[handle].type != type2)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Handle has wrong type!");
- emacs_abort ();
- }
-
-#endif /* ENABLE_CHECKING */
-
- return android_handles[handle].handle;
+ (*android_java_env)->DeleteGlobalRef (android_java_env, (jobject) handle);
}
void
jobject window;
jint pixel;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
if (value_mask & ANDROID_CW_BACK_PIXEL)
{
}
}
+/* Return a reference to the local reference HANDLE suitable for
+ indefinite retention and save its value into HANDLE, deleting HANDLE,
+ or signal an error if such a reference cannot be allocated. */
+
+static android_handle
+android_globalize_reference (jobject handle)
+{
+ jobject global;
+
+ /* Though Android 8.0 and later can support an unlimited number of
+ active local references, they remain inappropriate in threading
+ configurations for being local to the current thread. */
+
+ global = (*android_java_env)->NewGlobalRef (android_java_env,
+ handle);
+ (*android_java_env)->ExceptionClear (android_java_env);
+ ANDROID_DELETE_LOCAL_REF (handle);
+
+ if (__builtin_expect (global == NULL, 0))
+ error ("JNI global reference reserves exhausted");
+
+ /* Save the value of this handle into HANDLE. */
+ (*android_java_env)->SetLongField (android_java_env, global,
+ handle_class.handle,
+ (jlong) global);
+ verify (sizeof (jlong) >= sizeof (intptr_t));
+ return (intptr_t) global;
+}
+
/* Create a new window with the given width, height and
attributes. */
static jmethodID constructor;
jobject object, parent_object, old;
android_window window;
- android_handle prev_max_handle;
bool override_redirect;
- parent_object = android_resolve_handle (parent, ANDROID_HANDLE_WINDOW);
-
- prev_max_handle = max_handle;
- window = android_alloc_id ();
+ parent_object = android_resolve_handle (parent);
- if (!window)
- error ("Out of window handles!");
if (!class)
{
constructor
= (*android_java_env)->GetMethodID (android_java_env, class, "<init>",
- "(SLorg/gnu/emacs/EmacsWindow;"
+ "(Lorg/gnu/emacs/EmacsWindow;"
"IIIIZ)V");
eassert (constructor != NULL);
&& attrs->override_redirect);
object = (*android_java_env)->NewObject (android_java_env, class,
- constructor, (jshort) window,
- parent_object, (jint) x, (jint) y,
+ constructor, parent_object,
+ (jint) x, (jint) y,
(jint) width, (jint) height,
(jboolean) override_redirect);
- if (!object)
- {
- (*android_java_env)->ExceptionClear (android_java_env);
-
- max_handle = prev_max_handle;
- memory_full (0);
- }
-
- android_handles[window].type = ANDROID_HANDLE_WINDOW;
- android_handles[window].handle
- = (*android_java_env)->NewGlobalRef (android_java_env,
- object);
- (*android_java_env)->ExceptionClear (android_java_env);
- ANDROID_DELETE_LOCAL_REF (object);
-
- if (!android_handles[window].handle)
- memory_full (0);
-
+ android_exception_check ();
+ window = android_globalize_reference (object);
android_change_window_attributes (window, value_mask, attrs);
return window;
}
void
android_destroy_window (android_window window)
{
- if (android_handles[window].type != ANDROID_HANDLE_WINDOW)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Trying to destroy something not a window!");
- emacs_abort ();
- }
-
android_destroy_handle (window);
}
emacs_gc_constructor
= (*android_java_env)->GetMethodID (android_java_env,
emacs_gc_class,
- "<init>", "(S)V");
+ "<init>", "()V");
eassert (emacs_gc_constructor);
emacs_gc_mark_dirty
struct android_gc_values *values)
{
struct android_gc *gc;
- android_handle prev_max_handle;
jobject object;
android_init_emacs_gc_class ();
gc = xmalloc (sizeof *gc);
- prev_max_handle = max_handle;
- gc->gcontext = android_alloc_id ();
+ gc->gcontext = 0;
gc->foreground = 0;
gc->background = 0xffffff;
gc->clip_rects = NULL;
gc->dashes = NULL;
gc->n_segments = 0;
- if (!gc->gcontext)
- {
- xfree (gc);
- error ("Out of GContext handles!");
- }
-
object = (*android_java_env)->NewObject (android_java_env,
emacs_gc_class,
- emacs_gc_constructor,
- (jshort) gc->gcontext);
-
- if (!object)
- {
- (*android_java_env)->ExceptionClear (android_java_env);
-
- max_handle = prev_max_handle;
- memory_full (0);
- }
-
- android_handles[gc->gcontext].type = ANDROID_HANDLE_GCONTEXT;
- android_handles[gc->gcontext].handle
- = (*android_java_env)->NewGlobalRef (android_java_env, object);
- (*android_java_env)->ExceptionClear (android_java_env);
- ANDROID_DELETE_LOCAL_REF (object);
-
- if (!android_handles[gc->gcontext].handle)
- memory_full (0);
+ emacs_gc_constructor);
+ android_exception_check ();
+ gc->gcontext = android_globalize_reference (object);
android_change_gc (gc, mask, values);
return gc;
}
clip_changed = false;
android_init_emacs_gc_class ();
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ gcontext = android_resolve_handle (gc->gcontext);
if (mask & ANDROID_GC_FOREGROUND)
{
if (mask & ANDROID_GC_CLIP_MASK)
{
- what = android_resolve_handle (values->clip_mask,
- ANDROID_HANDLE_PIXMAP);
+ what = android_resolve_handle (values->clip_mask);
(*android_java_env)->SetObjectField (android_java_env,
gcontext,
emacs_gc_clip_mask,
if (mask & ANDROID_GC_STIPPLE)
{
- what = android_resolve_handle (values->stipple,
- ANDROID_HANDLE_PIXMAP);
+ what = android_resolve_handle (values->stipple);
(*android_java_env)->SetObjectField (android_java_env,
gcontext,
emacs_gc_stipple,
android_init_android_rect_class ();
android_init_emacs_gc_class ();
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ gcontext = android_resolve_handle (gc->gcontext);
array = (*android_java_env)->NewObjectArray (android_java_env,
n_clip_rects,
int i;
jobject array, gcontext;
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ gcontext = android_resolve_handle (gc->gcontext);
if (n == gc->n_segments
&& (!gc->dashes || !memcmp (gc->dashes, dash_list,
jobject window, parent;
jmethodID method;
- window = android_resolve_handle (w, ANDROID_HANDLE_WINDOW);
- parent = android_resolve_handle (parent_handle,
- ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (w);
+ parent = android_resolve_handle (parent_handle);
method = window_class.reparent_to;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window,
{
jobject window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
window,
jobject window;
jmethodID map_window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
map_window = window_class.map_window;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject window;
jmethodID unmap_window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
unmap_window = window_class.unmap_window;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject window;
jmethodID resize_window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
resize_window = window_class.resize_window;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject window;
jmethodID move_window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
move_window = window_class.move_window;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
for (i = 0; i < num_windows; ++i)
{
- window = android_resolve_handle (swap_info[i].swap_window,
- ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (swap_info[i].swap_window);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
window,
window_class.class,
{
jobject drawable, gcontext;
- drawable = android_resolve_handle2 (handle,
- ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ drawable = android_resolve_handle (handle);
+ gcontext = android_resolve_handle (gc->gcontext);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
/* Now damage the destination drawable accordingly, should it be a
window. */
- if (android_handles[dest].type == ANDROID_HANDLE_WINDOW)
+ if ((*android_java_env)->IsInstanceOf (android_java_env,
+ (jobject) dest,
+ window_class.class))
android_damage_window (dest, &bounds);
fail2:
jobject point, drawable_object, gcontext;
int i;
- drawable_object = android_resolve_handle2 (drawable,
- ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ drawable_object = android_resolve_handle (drawable);
+ gcontext = android_resolve_handle (gc->gcontext);
array = (*android_java_env)->NewObjectArray (android_java_env,
npoints,
{
jobject drawable, gcontext;
- drawable = android_resolve_handle2 (handle,
- ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ drawable = android_resolve_handle (handle);
+ gcontext = android_resolve_handle (gc->gcontext);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
{
jobject drawable, gcontext;
- drawable = android_resolve_handle2 (handle,
- ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ drawable = android_resolve_handle (handle);
+ gcontext = android_resolve_handle (gc->gcontext);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
{
jobject drawable, gcontext;
- drawable = android_resolve_handle2 (handle,
- ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
- gcontext = android_resolve_handle (gc->gcontext,
- ANDROID_HANDLE_GCONTEXT);
+ drawable = android_resolve_handle (handle);
+ gcontext = android_resolve_handle (gc->gcontext);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
android_create_pixmap (unsigned int width, unsigned int height,
int depth)
{
- android_handle prev_max_handle;
jobject object;
- android_pixmap pixmap;
-
- /* First, allocate the pixmap handle. */
- prev_max_handle = max_handle;
- pixmap = android_alloc_id ();
-
- if (!pixmap)
- error ("Out of pixmap handles!");
object = (*android_java_env)->NewObject (android_java_env,
pixmap_class.class,
pixmap_class.constructor_mutable,
- (jshort) pixmap,
(jint) width, (jint) height,
(jint) depth);
-
- if (!object)
- {
- (*android_java_env)->ExceptionClear (android_java_env);
- max_handle = prev_max_handle;
- memory_full (0);
- }
-
- android_handles[pixmap].type = ANDROID_HANDLE_PIXMAP;
- android_handles[pixmap].handle
- = (*android_java_env)->NewGlobalRef (android_java_env, object);
- (*android_java_env)->ExceptionClear (android_java_env);
- ANDROID_DELETE_LOCAL_REF (object);
-
- if (!android_handles[pixmap].handle)
- memory_full (0);
-
- return pixmap;
+ android_exception_check ();
+ return android_globalize_reference (object);
}
void
{
jobject window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
window,
unsigned char *data1, *data2;
int i, x;
- drawable = android_resolve_handle2 (handle, ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
+ drawable = android_resolve_handle (handle);
/* Look up the drawable and get the bitmap corresponding to it.
Then, lock the bitmap's bits. */
unsigned char *data_1, *data_2;
int i, x;
- drawable = android_resolve_handle (handle, ANDROID_HANDLE_PIXMAP);
+ drawable = android_resolve_handle (handle);
/* Look up the drawable and get the bitmap corresponding to it.
Then, lock the bitmap's bits. */
jobject window;
jmethodID make_input_focus;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
make_input_focus = window_class.make_input_focus;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject window;
jmethodID raise;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
raise = window_class.raise;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject window;
jmethodID lower;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
lower = window_class.lower;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
{
jobject sibling, window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
if (!(value_mask & ANDROID_CW_STACK_MODE))
return;
sibling = NULL;
if (value_mask & ANDROID_CW_SIBLING)
- sibling = android_resolve_handle (values->sibling,
- ANDROID_HANDLE_WINDOW);
+ sibling = android_resolve_handle (values->sibling);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
window,
jobject window, array;
jsize nelements, i;
android_window *children;
- jshort *shorts;
+ jlong *longs;
jmethodID method;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
/* window can be NULL, so this is a service method. */
method = service_class.query_tree;
/* Now fill in the children. */
children = xnmalloc (nelements - 1, sizeof *children);
- shorts
- = (*android_java_env)->GetShortArrayElements (android_java_env, array,
- NULL);
- android_exception_check_nonnull (shorts, array);
+ longs
+ = (*android_java_env)->GetLongArrayElements (android_java_env, array,
+ NULL);
+ android_exception_check_nonnull (longs, array);
for (i = 1; i < nelements; ++i)
/* Subtract one from the index into children, since the parent is
not included. */
- children[i - 1] = shorts[i];
+ children[i - 1] = longs[i];
/* Finally, return the parent and other values. */
*root_return = 0;
- *parent_return = shorts[0];
+ *parent_return = longs[0];
*children_return = children;
*nchildren_return = nelements - 1;
/* Release the array contents. */
- (*android_java_env)->ReleaseShortArrayElements (android_java_env, array,
- shorts, JNI_ABORT);
+ (*android_java_env)->ReleaseLongArrayElements (android_java_env, array,
+ longs, JNI_ABORT);
ANDROID_DELETE_LOCAL_REF (array);
return 1;
jmethodID get_geometry;
jint *ints;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
get_geometry = window_class.get_window_geometry;
window_geometry
jmethodID method;
jint *ints;
- window = android_resolve_handle (src, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (src);
method = window_class.translate_coordinates;
coordinates
= (*android_java_env)->CallNonvirtualObjectMethod (android_java_env,
/* Now look up the window. */
rc = 0;
- if (!android_handles[event->window].handle
- || (android_handles[event->window].type
- != ANDROID_HANDLE_WINDOW))
+ window = android_resolve_handle (event->window);
+ string
+ = (*env)->CallNonvirtualObjectMethod (env, window,
+ window_class.class,
+ window_class.lookup_string,
+ (jint) event->serial);
+ android_exception_check ();
+
+ if (!string)
status = ANDROID_LOOKUP_NONE;
else
{
- window = android_handles[event->window].handle;
- string
- = (*env)->CallNonvirtualObjectMethod (env, window,
- window_class.class,
- window_class.lookup_string,
- (jint) event->serial);
- android_exception_check ();
-
- if (!string)
- status = ANDROID_LOOKUP_NONE;
- else
- {
- /* Now return this input method string. */
- characters = (*env)->GetStringChars (env, string, NULL);
- android_exception_check_nonnull ((void *) characters, string);
+ /* Now return this input method string. */
+ characters = (*env)->GetStringChars (env, string, NULL);
+ android_exception_check_nonnull ((void *) characters, string);
- /* Establish the size of the the string. */
- size = (*env)->GetStringLength (env, string);
+ /* Establish the size of the the string. */
+ size = (*env)->GetStringLength (env, string);
- /* Copy over the string data. */
- for (i = 0; i < MIN ((unsigned int) wchars_buffer, size); ++i)
- buffer_return[i] = characters[i];
+ /* Copy over the string data. */
+ for (i = 0; i < MIN ((unsigned int) wchars_buffer, size); ++i)
+ buffer_return[i] = characters[i];
- if (i < size)
- status = ANDROID_BUFFER_OVERFLOW;
- else
- status = ANDROID_LOOKUP_CHARS;
+ if (i < size)
+ status = ANDROID_BUFFER_OVERFLOW;
+ else
+ status = ANDROID_LOOKUP_CHARS;
- /* Return the number of characters that should have been
- written. */
+ /* Return the number of characters that should have been
+ written. */
- if (size > INT_MAX)
- rc = INT_MAX;
- else
- rc = size;
+ if (size > INT_MAX)
+ rc = INT_MAX;
+ else
+ rc = size;
- (*env)->ReleaseStringChars (env, string, characters);
- ANDROID_DELETE_LOCAL_REF (string);
- }
+ (*env)->ReleaseStringChars (env, string, characters);
+ ANDROID_DELETE_LOCAL_REF (string);
}
*status_return = status;
jobject object, bitmap;
void *data;
- object = android_resolve_handle2 (drawable, ANDROID_HANDLE_WINDOW,
- ANDROID_HANDLE_PIXMAP);
+ object = android_resolve_handle (drawable);
/* Look up the drawable and get the bitmap corresponding to it.
Then, lock the bitmap's bits. */
{
jobject drawable;
- drawable = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ drawable = android_resolve_handle (handle);
/* Post the damage to the drawable. */
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jmethodID method;
jobject window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
method = window_class.set_dont_focus_on_map;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window,
jmethodID method;
jobject window;
- window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW);
+ window = android_resolve_handle (handle);
method = window_class.set_dont_accept_focus;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window,
jobject object;
jmethodID method;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
method = window_class.toggle_on_screen_keyboard;
/* Now display the on screen keyboard. */
if global_foo cannot be allocated, and after the global reference
is created. */
-#if __GNUC__ >= 3
#define likely(cond) __builtin_expect (cond, 1)
-#else /* __GNUC__ < 3 */
-#define likely(cond) (cond)
-#endif /* __GNUC__ >= 3 */
/* Check for JNI exceptions and call memory_full in that
situation. */
jobject object;
jmethodID method;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
method = window_class.recreate_activity;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env, object,
{
jobject object;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
{
jobject object;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
emacs_service,
jobject object;
jmethodID method;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
method = service_class.update_extracted_text;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
jobject object;
jmethodID method;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
method = service_class.update_cursor_anchor_info;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
if (android_api_level < 16)
return 1;
- object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ object = android_resolve_handle (window);
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
object,
android_cursor
android_create_font_cursor (enum android_cursor_shape shape)
{
- android_cursor id;
- short prev_max_handle;
jobject object;
- /* First, allocate the cursor handle. */
- prev_max_handle = max_handle;
- id = android_alloc_id ();
-
- if (!id)
- error ("Out of cursor handles!");
-
/* Next, create the cursor. */
object = (*android_java_env)->NewObject (android_java_env,
cursor_class.class,
cursor_class.constructor,
- (jshort) id,
(jint) shape);
- if (!object)
- {
- (*android_java_env)->ExceptionClear (android_java_env);
- max_handle = prev_max_handle;
- memory_full (0);
- }
-
- android_handles[id].type = ANDROID_HANDLE_CURSOR;
- android_handles[id].handle
- = (*android_java_env)->NewGlobalRef (android_java_env, object);
- (*android_java_env)->ExceptionClear (android_java_env);
- ANDROID_DELETE_LOCAL_REF (object);
-
- if (!android_handles[id].handle)
- memory_full (0);
-
- return id;
+ android_exception_check ();
+ return android_globalize_reference (object);
}
void
jobject window1, cursor1;
jmethodID method;
- window1 = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
- cursor1 = android_resolve_handle (cursor, ANDROID_HANDLE_CURSOR);
+ window1 = android_resolve_handle (window);
+ cursor1 = android_resolve_handle (cursor);
method = window_class.define_cursor;
(*android_java_env)->CallNonvirtualVoidMethod (android_java_env,
void
android_free_cursor (android_cursor cursor)
{
- if (android_handles[cursor].type != ANDROID_HANDLE_CURSOR)
- {
- __android_log_print (ANDROID_LOG_ERROR, __func__,
- "Trying to destroy something not a CURSOR!");
- emacs_abort ();
- }
-
android_destroy_handle (cursor);
}