diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/mupdf-internal.h | 4 | ||||
-rw-r--r-- | pdf/pdf_form.c | 52 | ||||
-rw-r--r-- | pdf/pdf_js.c | 2 |
3 files changed, 41 insertions, 17 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index 1bbd9e35..fe1bf0ad 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -567,7 +567,7 @@ void pdf_free_annot(fz_context *ctx, pdf_annot *link); int pdf_field_getType(pdf_document *doc, pdf_obj *field); char *pdf_field_getValue(pdf_document *doc, pdf_obj *field); -void pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text); +int pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text); char *pdf_field_getBorderStyle(pdf_document *doc, pdf_obj *field); void pdf_field_setBorderStyle(pdf_document *doc, pdf_obj *field, char *text); void pdf_field_buttonSetCaption(pdf_document *doc, pdf_obj *field, char *text); @@ -615,7 +615,7 @@ fz_widget *pdf_next_widget(fz_widget *previous); char *pdf_widget_text_get_text(pdf_document *doc, fz_widget *tw); int pdf_widget_text_get_max_len(pdf_document *doc, fz_widget *tw); int pdf_widget_text_get_content_type(pdf_document *doc, fz_widget *tw); -void pdf_widget_text_set_text(pdf_document *doc, fz_widget *tw, char *text); +int pdf_widget_text_set_text(pdf_document *doc, fz_widget *tw, char *text); int pdf_widget_choice_get_options(pdf_document *doc, fz_widget *tw, char *opts[]); int pdf_widget_choice_is_multiselect(pdf_document *doc, fz_widget *tw); int pdf_widget_choice_get_value(pdf_document *doc, fz_widget *tw, char *opts[]); diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 710d8c2a..e3ac7e8f 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -1899,34 +1899,31 @@ static void recalculate(pdf_document *doc) } } -void pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text) +int pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text) { - pdf_obj *k, *v; - doc->dirty = 1; - - k = pdf_dict_getp(field, "AA/K"); - v = pdf_dict_getp(field, "AA/V"); + pdf_obj *v = pdf_dict_getp(field, "AA/V"); - if (k || v) + if (v) { pdf_js_event e; e.target = field; e.value = text; pdf_js_setup_event(doc->js, &e); + execute_action(doc, field, v); - if (k) - execute_action(doc, field, k); - - if (v) - execute_action(doc, field, v); + if (!e.rc) + return 0; text = pdf_js_get_event(doc->js)->value; } + doc->dirty = 1; update_text_field_value(doc->ctx, field, text); recalculate(doc); pdf_field_mark_dirty(doc->ctx, field); + + return 1; } char *pdf_field_getBorderStyle(pdf_document *doc, pdf_obj *field) @@ -2116,19 +2113,46 @@ int pdf_widget_text_get_content_type(pdf_document *doc, fz_widget *tw) return type; } -void pdf_widget_text_set_text(pdf_document *doc, fz_widget *tw, char *text) +static int run_keystroke(pdf_document *doc, pdf_obj *field, char **text) +{ + pdf_obj *k = pdf_dict_getp(field, "AA/K"); + + if (k) + { + pdf_js_event e; + + e.target = field; + e.value = *text; + pdf_js_setup_event(doc->js, &e); + execute_action(doc, field, k); + + if (!e.rc) + return 0; + + *text = pdf_js_get_event(doc->js)->value; + } + + return 1; +} + +int pdf_widget_text_set_text(pdf_document *doc, fz_widget *tw, char *text) { pdf_annot *annot = (pdf_annot *)tw; fz_context *ctx = doc->ctx; + int accepted = 0; fz_try(ctx) { - pdf_field_setValue(doc, annot->obj, text); + accepted = run_keystroke(doc, annot->obj, &text); + if (accepted) + accepted = pdf_field_setValue(doc, annot->obj, text); } fz_catch(ctx) { fz_warn(ctx, "fz_widget_text_set_text failed"); } + + return accepted; } int pdf_widget_choice_get_options(pdf_document *doc, fz_widget *tw, char *opts[]) diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index 2b2d479b..59f5fd9d 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -148,7 +148,7 @@ static void field_setValue(void *jsctx, void *obj, pdf_jsimp_obj *val) pdf_js *js = (pdf_js *)jsctx; pdf_obj *field = (pdf_obj *)obj; - pdf_field_setValue(js->doc, field, pdf_jsimp_toString(js->imp, val)); + (void)pdf_field_setValue(js->doc, field, pdf_jsimp_toString(js->imp, val)); } static pdf_jsimp_obj *event_getTarget(void *jsctx, void *obj) |