summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2012-09-25 17:14:10 +0100
committerPaul Gardiner <paulg.artifex@glidos.net>2012-09-25 17:14:10 +0100
commitdf58406d637fe3404b2142234898558c42969ee6 (patch)
treeaa0827bce5bee1e55e01d77cddbf727e1b4c8b1d /pdf
parent3e7f093001706a622afc63861841e2fa642f8a0a (diff)
downloadmupdf-df58406d637fe3404b2142234898558c42969ee6.tar.xz
Forms: support doc.mailDoc.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/mupdf-internal.h1
-rw-r--r--pdf/pdf_event.c29
-rw-r--r--pdf/pdf_js.c101
3 files changed, 131 insertions, 0 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h
index c0fffcf5..20503604 100644
--- a/pdf/mupdf-internal.h
+++ b/pdf/mupdf-internal.h
@@ -637,6 +637,7 @@ void pdf_event_issue_print(pdf_document *doc);
void pdf_event_issue_exec_menu_item(pdf_document *doc, char *item);
void pdf_event_issue_exec_dialog(pdf_document *doc);
void pdf_event_issue_launch_url(pdf_document *doc, char *url, int new_frame);
+void pdf_event_issue_mail_doc(pdf_document *doc, fz_mail_doc_event *event);
/*
* Javascript handler
diff --git a/pdf/pdf_event.c b/pdf/pdf_event.c
index f76058ce..8923b942 100644
--- a/pdf/pdf_event.c
+++ b/pdf/pdf_event.c
@@ -108,6 +108,35 @@ void pdf_event_issue_launch_url(pdf_document *doc, char *url, int new_frame)
}
}
+typedef struct
+{
+ fz_doc_event base;
+ fz_mail_doc_event mail_doc;
+} fz_mail_doc_event_internal;
+
+fz_mail_doc_event *fz_access_mail_doc_event(fz_doc_event *event)
+{
+ fz_mail_doc_event *mail_doc = NULL;
+
+ if (event->type == FZ_DOCUMENT_EVENT_MAIL_DOC)
+ mail_doc = &((fz_mail_doc_event_internal *)event)->mail_doc;
+
+ return mail_doc;
+}
+
+void pdf_event_issue_mail_doc(pdf_document *doc, fz_mail_doc_event *event)
+{
+ if (doc->event_cb)
+ {
+ fz_mail_doc_event_internal e;
+
+ e.base.type = FZ_DOCUMENT_EVENT_MAIL_DOC;
+ e.mail_doc = *event;
+
+ doc->event_cb((fz_doc_event *)&e, doc->event_cb_data);
+ }
+}
+
void pdf_set_doc_event_callback(pdf_document *doc, fz_doc_event_cb *fn, void *data)
{
doc->event_cb = fn;
diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c
index e690ad09..d8efe74e 100644
--- a/pdf/pdf_js.c
+++ b/pdf/pdf_js.c
@@ -568,6 +568,106 @@ static pdf_jsimp_obj *doc_print(void *jsctx, void *obj, int argc, pdf_jsimp_obj
return NULL;
}
+static pdf_jsimp_obj *doc_mailDoc(void *jsctx, void *obj, int argc, pdf_jsimp_obj *args[])
+{
+ pdf_js *js = (pdf_js *)jsctx;
+ fz_context *ctx = js->doc->ctx;
+ pdf_jsimp_obj *bUI_obj = NULL;
+ pdf_jsimp_obj *cTo_obj = NULL;
+ pdf_jsimp_obj *cCc_obj = NULL;
+ pdf_jsimp_obj *cBcc_obj = NULL;
+ pdf_jsimp_obj *cSubject_obj = NULL;
+ pdf_jsimp_obj *cMessage_obj = NULL;
+ fz_mail_doc_event event;
+ int arg_is_obj = 0;
+
+ if (argc < 1 || argc > 6)
+ return NULL;
+
+ event.ask_user = 1;
+ event.to = "";
+ event.cc = "";
+ event.bcc = "";
+ event.subject = "";
+ event.message = "";
+
+ fz_var(bUI_obj);
+ fz_var(cTo_obj);
+ fz_var(cCc_obj);
+ fz_var(cBcc_obj);
+ fz_var(cSubject_obj);
+ fz_var(cMessage_obj);
+ fz_try(ctx)
+ {
+ arg_is_obj = (argc == 1 && pdf_jsimp_to_type(js->imp, args[0]) != JS_TYPE_BOOLEAN);
+ if (arg_is_obj)
+ {
+ bUI_obj = pdf_jsimp_property(js->imp, args[0], "bUI");
+ cTo_obj = pdf_jsimp_property(js->imp, args[0], "cTo");
+ cCc_obj = pdf_jsimp_property(js->imp, args[0], "cCc");
+ cBcc_obj = pdf_jsimp_property(js->imp, args[0], "cBcc");
+ cSubject_obj = pdf_jsimp_property(js->imp, args[0], "cSubject");
+ cMessage_obj = pdf_jsimp_property(js->imp, args[0], "cMessage");
+ }
+ else
+ {
+ switch (argc)
+ {
+ case 6:
+ cMessage_obj = args[5];
+ case 5:
+ cSubject_obj = args[4];
+ case 4:
+ cBcc_obj = args[3];
+ case 3:
+ cCc_obj = args[2];
+ case 2:
+ cTo_obj = args[1];
+ case 1:
+ bUI_obj = args[0];
+ }
+ }
+
+ if (bUI_obj)
+ event.ask_user = (int)pdf_jsimp_to_number(js->imp, bUI_obj);
+
+ if (cTo_obj)
+ event.to = pdf_jsimp_to_string(js->imp, cTo_obj);
+
+ if (cCc_obj)
+ event.cc = pdf_jsimp_to_string(js->imp, cCc_obj);
+
+ if (cBcc_obj)
+ event.bcc = pdf_jsimp_to_string(js->imp, cBcc_obj);
+
+ if (cSubject_obj)
+ event.subject = pdf_jsimp_to_string(js->imp, cSubject_obj);
+
+ if (cMessage_obj)
+ event.message = pdf_jsimp_to_string(js->imp, cMessage_obj);
+
+ pdf_event_issue_mail_doc(js->doc, &event);
+ }
+ fz_always(ctx)
+ {
+ if (arg_is_obj)
+ {
+ pdf_jsimp_drop_obj(js->imp, bUI_obj);
+ pdf_jsimp_drop_obj(js->imp, cTo_obj);
+ pdf_jsimp_drop_obj(js->imp, cCc_obj);
+ pdf_jsimp_drop_obj(js->imp, cBcc_obj);
+ pdf_jsimp_drop_obj(js->imp, cSubject_obj);
+ pdf_jsimp_drop_obj(js->imp, cMessage_obj);
+ }
+ }
+ fz_catch(ctx)
+ {
+ fz_rethrow(ctx);
+ }
+
+ return NULL;
+}
+
static void declare_dom(pdf_js *js)
{
pdf_jsimp *imp = js->imp;
@@ -577,6 +677,7 @@ static void declare_dom(pdf_js *js)
pdf_jsimp_addmethod(imp, js->doctype, "getField", doc_getField);
pdf_jsimp_addmethod(imp, js->doctype, "resetForm", doc_resetForm);
pdf_jsimp_addmethod(imp, js->doctype, "print", doc_print);
+ pdf_jsimp_addmethod(imp, js->doctype, "mailDoc", doc_mailDoc);
pdf_jsimp_addproperty(imp, js->doctype, "event", doc_getEvent, doc_setEvent);
pdf_jsimp_addproperty(imp, js->doctype, "app", doc_getApp, doc_setApp);