1#include "mupdf/fitz.h"
2#include "mupdf/pdf.h"
3
4typedef struct
5{
6 pdf_doc_event base;
7 pdf_alert_event alert;
8} pdf_alert_event_internal;
9
10/*
11 access the details of an alert event
12 The returned pointer and all the data referred to by the
13 structure are owned by mupdf and need not be freed by the
14 caller.
15*/
16pdf_alert_event *pdf_access_alert_event(fz_context *ctx, pdf_doc_event *event)
17{
18 pdf_alert_event *alert = NULL;
19
20 if (event->type == PDF_DOCUMENT_EVENT_ALERT)
21 alert = &((pdf_alert_event_internal *)event)->alert;
22
23 return alert;
24}
25
26void pdf_event_issue_alert(fz_context *ctx, pdf_document *doc, pdf_alert_event *alert)
27{
28 if (doc->event_cb)
29 {
30 pdf_alert_event_internal ievent;
31 ievent.base.type = PDF_DOCUMENT_EVENT_ALERT;
32 ievent.alert = *alert;
33
34 doc->event_cb(ctx, doc, (pdf_doc_event *)&ievent, doc->event_cb_data);
35
36 *alert = ievent.alert;
37 }
38}
39
40void pdf_event_issue_print(fz_context *ctx, pdf_document *doc)
41{
42 pdf_doc_event e;
43
44 e.type = PDF_DOCUMENT_EVENT_PRINT;
45
46 if (doc->event_cb)
47 doc->event_cb(ctx, doc, &e, doc->event_cb_data);
48}
49
50typedef struct
51{
52 pdf_doc_event base;
53 const char *item;
54} pdf_exec_menu_item_event_internal;
55
56/*
57 access the details of am execMenuItem
58 event, which consists of just the name of the menu item
59*/
60const char *pdf_access_exec_menu_item_event(fz_context *ctx, pdf_doc_event *event)
61{
62 const char *item = NULL;
63
64 if (event->type == PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM)
65 item = ((pdf_exec_menu_item_event_internal *)event)->item;
66
67 return item;
68}
69
70void pdf_event_issue_exec_menu_item(fz_context *ctx, pdf_document *doc, const char *item)
71{
72 if (doc->event_cb)
73 {
74 pdf_exec_menu_item_event_internal ievent;
75 ievent.base.type = PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM;
76 ievent.item = item;
77
78 doc->event_cb(ctx, doc, (pdf_doc_event *)&ievent, doc->event_cb_data);
79 }
80}
81
82typedef struct
83{
84 pdf_doc_event base;
85 pdf_launch_url_event launch_url;
86} pdf_launch_url_event_internal;
87
88/*
89 access the details of a launch-url
90 event. The returned pointer and all data referred to by the structure
91 are owned by mupdf and need not be freed by the caller.
92*/
93pdf_launch_url_event *pdf_access_launch_url_event(fz_context *ctx, pdf_doc_event *event)
94{
95 pdf_launch_url_event *launch_url = NULL;
96
97 if (event->type == PDF_DOCUMENT_EVENT_LAUNCH_URL)
98 launch_url = &((pdf_launch_url_event_internal *)event)->launch_url;
99
100 return launch_url;
101}
102
103void pdf_event_issue_launch_url(fz_context *ctx, pdf_document *doc, const char *url, int new_frame)
104{
105 if (doc->event_cb)
106 {
107 pdf_launch_url_event_internal e;
108
109 e.base.type = PDF_DOCUMENT_EVENT_LAUNCH_URL;
110 e.launch_url.url = url;
111 e.launch_url.new_frame = new_frame;
112 doc->event_cb(ctx, doc, (pdf_doc_event *)&e, doc->event_cb_data);
113 }
114}
115
116typedef struct
117{
118 pdf_doc_event base;
119 pdf_mail_doc_event mail_doc;
120} pdf_mail_doc_event_internal;
121
122pdf_mail_doc_event *pdf_access_mail_doc_event(fz_context *ctx, pdf_doc_event *event)
123{
124 pdf_mail_doc_event *mail_doc = NULL;
125
126 if (event->type == PDF_DOCUMENT_EVENT_MAIL_DOC)
127 mail_doc = &((pdf_mail_doc_event_internal *)event)->mail_doc;
128
129 return mail_doc;
130}
131
132void pdf_event_issue_mail_doc(fz_context *ctx, pdf_document *doc, pdf_mail_doc_event *event)
133{
134 if (doc->event_cb)
135 {
136 pdf_mail_doc_event_internal e;
137
138 e.base.type = PDF_DOCUMENT_EVENT_MAIL_DOC;
139 e.mail_doc = *event;
140
141 doc->event_cb(ctx, doc, (pdf_doc_event *)&e, doc->event_cb_data);
142 }
143}
144
145void pdf_set_doc_event_callback(fz_context *ctx, pdf_document *doc, pdf_doc_event_cb *fn, void *data)
146{
147 doc->event_cb = fn;
148 doc->event_cb_data = data;
149}
150
151void *pdf_get_doc_event_callback_data(fz_context *ctx, pdf_document *doc)
152{
153 return doc->event_cb_data;
154}
155