diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2012-10-11 12:03:15 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2012-10-11 12:03:15 +0100 |
commit | 31791f3ebe049af8dccacd5871c0aeac7dc86b29 (patch) | |
tree | 535b0770f9204dc18a960d6c1824f3966286e097 /android/jni | |
parent | 84f84d86e6d7f079e12139fa3306c3bc71713f77 (diff) | |
download | mupdf-31791f3ebe049af8dccacd5871c0aeac7dc86b29.tar.xz |
Android: support entry of text into forms
Diffstat (limited to 'android/jni')
-rw-r--r-- | android/jni/mupdf.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c index d4105115..2ec02bf8 100644 --- a/android/jni/mupdf.c +++ b/android/jni/mupdf.c @@ -22,6 +22,14 @@ #define MAX_SEARCH_HITS (500) +enum +{ + NONE, + TEXT, + LISTBOX, + COMBOBOX +}; + /* Globals */ fz_colorspace *colorspace; fz_document *doc; @@ -769,3 +777,87 @@ Java_com_artifex_mupdf_MuPDFCore_passClickEventInternal(JNIEnv * env, jobject th return changed; } + +JNIEXPORT jstring JNICALL +Java_com_artifex_mupdf_MuPDFCore_getFocusedWidgetTextInternal(JNIEnv * env, jobject thiz) +{ + char *text = ""; + + fz_try(ctx) + { + fz_interactive *idoc = fz_interact(doc); + + if (idoc) + { + fz_widget *focus = fz_focused_widget(idoc); + + if (focus) + text = fz_text_widget_text(idoc, focus); + } + } + fz_catch(ctx) + { + LOGE("getFocusedWidgetText failed: %s", ctx->error->message); + } + + return (*env)->NewStringUTF(env, text); +} + +JNIEXPORT int JNICALL +Java_com_artifex_mupdf_MuPDFCore_setFocusedWidgetTextInternal(JNIEnv * env, jobject thiz, jstring jtext) +{ + const char *text; + int result = 0; + + text = (*env)->GetStringUTFChars(env, jtext, NULL); + if (text == NULL) + { + LOGE("Failed to get text"); + return 0; + } + + fz_try(ctx) + { + fz_interactive *idoc = fz_interact(doc); + + if (idoc) + { + fz_widget *focus = fz_focused_widget(idoc); + + if (focus) + result = fz_text_widget_set_text(idoc, focus, text); + } + } + fz_catch(ctx) + { + LOGE("setFocusedWidgetText failed: %s", ctx->error->message); + } + + (*env)->ReleaseStringUTFChars(env, jtext, text); + + return result; +} + +JNIEXPORT int JNICALL +Java_com_artifex_mupdf_MuPDFCore_getFocusedWidgetTypeInternal(JNIEnv * env, jobject thiz) +{ + fz_interactive *idoc = fz_interact(doc); + fz_widget *focus; + + if (idoc == NULL) + return NONE; + + focus = fz_focused_widget(idoc); + + if (focus == NULL) + return NONE; + + switch (fz_widget_get_type(focus)) + { + case FZ_WIDGET_TYPE_TEXT: return TEXT; + case FZ_WIDGET_TYPE_LISTBOX: return LISTBOX; + case FZ_WIDGET_TYPE_COMBOBOX: return COMBOBOX; + } + + return NONE; +} |