summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/jstest_main.c5
-rw-r--r--apps/pdfapp.c13
-rw-r--r--apps/pdfapp.h2
-rw-r--r--apps/win_main.c15
-rw-r--r--apps/win_res.rc1
-rw-r--r--apps/x11_main.c6
-rw-r--r--fitz/doc_interactive.c4
-rw-r--r--fitz/fitz.h4
-rw-r--r--pdf/mupdf-internal.h4
-rw-r--r--pdf/pdf_form.c52
-rw-r--r--pdf/pdf_js.c2
11 files changed, 81 insertions, 27 deletions
diff --git a/apps/jstest_main.c b/apps/jstest_main.c
index cc61b89c..686fc088 100644
--- a/apps/jstest_main.c
+++ b/apps/jstest_main.c
@@ -47,8 +47,11 @@ char *winpassword(pdfapp_t *app, char *filename)
return pd_password;
}
-char *wintextinput(pdfapp_t *app, char *inittext)
+char *wintextinput(pdfapp_t *app, char *inittext, int retry)
{
+ if (retry)
+ return NULL;
+
if (td_textinput[0] != 0)
return td_textinput;
return inittext;
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 57bc3e33..d4d292da 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -1102,10 +1102,17 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta
case FZ_WIDGET_TYPE_TEXT:
{
char *text = fz_widget_text_get_text(idoc, widget);
- char *newtext = wintextinput(app, text);
+ char *current_text = text;
+ int retry = 0;
+
+ do
+ {
+ current_text = wintextinput(app, current_text, retry);
+ retry = 1;
+ }
+ while (current_text && !fz_widget_text_set_text(idoc, widget, current_text));
+
fz_free(app->ctx, text);
- if (newtext)
- fz_widget_text_set_text(idoc, widget, newtext);
}
break;
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index ecdabcfc..43bc7b3b 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -25,7 +25,7 @@ extern void winresize(pdfapp_t*, int w, int h);
extern void winrepaint(pdfapp_t*);
extern void winrepaintsearch(pdfapp_t*);
extern char *winpassword(pdfapp_t*, char *filename);
-extern char *wintextinput(pdfapp_t*, char *inittext);
+extern char *wintextinput(pdfapp_t*, char *inittext, int retry);
extern int winchoiceinput(pdfapp_t*, int nopts, char *opts[], int *nvals, char *vals[]);
extern void winopenuri(pdfapp_t*, char *s);
extern void wincursor(pdfapp_t*, int curs);
diff --git a/apps/win_main.c b/apps/win_main.c
index a232d2f2..025e38db 100644
--- a/apps/win_main.c
+++ b/apps/win_main.c
@@ -156,6 +156,7 @@ int wingetsavepath(pdfapp_t *app, char *buf, int len)
static char pd_filename[256] = "The file is encrypted.";
static char pd_password[256] = "";
static char td_textinput[1024] = "";
+static int td_retry = 0;
static int cd_nopts;
static int *cd_nvals;
static char **cd_opts;
@@ -195,6 +196,8 @@ dlogtextproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
SetDlgItemTextA(hwnd, 3, td_textinput);
+ if (!td_retry)
+ ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
return TRUE;
case WM_COMMAND:
switch(wParam)
@@ -210,6 +213,15 @@ dlogtextproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
break;
+ case WM_CTLCOLORSTATIC:
+ if ((HWND)lParam == GetDlgItem(hwnd, 4))
+ {
+ SetTextColor((HDC)wParam, RGB(255,0,0));
+ SetBkMode((HDC)wParam, TRANSPARENT);
+
+ return (INT)GetStockObject(NULL_BRUSH);
+ }
+ break;
}
return FALSE;
}
@@ -281,9 +293,10 @@ char *winpassword(pdfapp_t *app, char *filename)
return NULL;
}
-char *wintextinput(pdfapp_t *app, char *inittext)
+char *wintextinput(pdfapp_t *app, char *inittext, int retry)
{
int code;
+ td_retry = retry;
strncpy(td_textinput, inittext?inittext:"", sizeof(td_textinput));
code = DialogBoxW(NULL, L"IDD_DLOGTEXT", hwndframe, dlogtextproc);
if (code <= 0)
diff --git a/apps/win_res.rc b/apps/win_res.rc
index 3cf601a3..499aff02 100644
--- a/apps/win_res.rc
+++ b/apps/win_res.rc
@@ -57,6 +57,7 @@ BEGIN
EDITTEXT 3,8,7,183,50,0x1004
DEFPUSHBUTTON "Okay",1,89,64,50,14
PUSHBUTTON "Cancel",2,147,64,50,14
+ LTEXT "** Invalid value **",4,11,65,62,8
END
IDD_DLOGLIST DIALOG 50, 50, 204, 85
diff --git a/apps/x11_main.c b/apps/x11_main.c
index f927e6d0..623187fa 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -117,9 +117,13 @@ char *winpassword(pdfapp_t *app, char *filename)
return r;
}
-char *wintextinput(pdfapp_t *app, char *inittext)
+char *wintextinput(pdfapp_t *app, char *inittext, int retry)
{
static char buf[256];
+
+ if (retry)
+ return NULL;
+
printf("> [%s] ", inittext);
fgets(buf, sizeof buf, stdin);
return buf;
diff --git a/fitz/doc_interactive.c b/fitz/doc_interactive.c
index 61f2f4f1..724ad8d1 100644
--- a/fitz/doc_interactive.c
+++ b/fitz/doc_interactive.c
@@ -51,9 +51,9 @@ int fz_widget_text_get_content_type(fz_interactive *idoc, fz_widget *tw)
return pdf_widget_text_get_content_type((pdf_document *)idoc, tw);
}
-void fz_widget_text_set_text(fz_interactive *idoc, fz_widget *tw, char *text)
+int fz_widget_text_set_text(fz_interactive *idoc, fz_widget *tw, char *text)
{
- pdf_widget_text_set_text((pdf_document *)idoc, tw, text);
+ return pdf_widget_text_set_text((pdf_document *)idoc, tw, text);
}
int fz_widget_choice_get_options(fz_interactive *idoc, fz_widget *tw, char *opts[])
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 8bbc2ec4..90ae2717 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -2497,8 +2497,10 @@ int fz_widget_text_get_content_type(fz_interactive *idoc, fz_widget *tw);
/*
fz_widget_text_set_text: Update the text of a text widget.
+ The text is first validated and accepted only if it passes. The
+ function returns whether validation passed.
*/
-void fz_widget_text_set_text(fz_interactive *idoc, fz_widget *tw, char *text);
+int fz_widget_text_set_text(fz_interactive *idoc, fz_widget *tw, char *text);
/*
fz_widget_choice_get_options: get the list of options for a list
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)