Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/source/pdf/pdf-event.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // Copyright (C) 2004-2021 Artifex Software, Inc. | |
| 2 // | |
| 3 // This file is part of MuPDF. | |
| 4 // | |
| 5 // MuPDF is free software: you can redistribute it and/or modify it under the | |
| 6 // terms of the GNU Affero General Public License as published by the Free | |
| 7 // Software Foundation, either version 3 of the License, or (at your option) | |
| 8 // any later version. | |
| 9 // | |
| 10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | |
| 13 // details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU Affero General Public License | |
| 16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html> | |
| 17 // | |
| 18 // Alternative licensing terms are available from the licensor. | |
| 19 // For commercial licensing, see <https://www.artifex.com/> or contact | |
| 20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, | |
| 21 // CA 94129, USA, for further information. | |
| 22 | |
| 23 #include "mupdf/fitz.h" | |
| 24 #include "mupdf/pdf.h" | |
| 25 | |
| 26 typedef struct | |
| 27 { | |
| 28 pdf_doc_event base; | |
| 29 pdf_alert_event alert; | |
| 30 } pdf_alert_event_internal; | |
| 31 | |
| 32 pdf_alert_event *pdf_access_alert_event(fz_context *ctx, pdf_doc_event *evt) | |
| 33 { | |
| 34 pdf_alert_event *alert = NULL; | |
| 35 | |
| 36 if (evt->type == PDF_DOCUMENT_EVENT_ALERT) | |
| 37 alert = &((pdf_alert_event_internal *)evt)->alert; | |
| 38 | |
| 39 return alert; | |
| 40 } | |
| 41 | |
| 42 void pdf_event_issue_alert(fz_context *ctx, pdf_document *doc, pdf_alert_event *alert) | |
| 43 { | |
| 44 if (doc->event_cb) | |
| 45 { | |
| 46 pdf_alert_event_internal ievent; | |
| 47 ievent.base.type = PDF_DOCUMENT_EVENT_ALERT; | |
| 48 ievent.alert = *alert; | |
| 49 | |
| 50 doc->event_cb(ctx, doc, (pdf_doc_event *)&ievent, doc->event_cb_data); | |
| 51 | |
| 52 *alert = ievent.alert; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void pdf_event_issue_print(fz_context *ctx, pdf_document *doc) | |
| 57 { | |
| 58 pdf_doc_event e; | |
| 59 | |
| 60 e.type = PDF_DOCUMENT_EVENT_PRINT; | |
| 61 | |
| 62 if (doc->event_cb) | |
| 63 doc->event_cb(ctx, doc, &e, doc->event_cb_data); | |
| 64 } | |
| 65 | |
| 66 typedef struct | |
| 67 { | |
| 68 pdf_doc_event base; | |
| 69 const char *item; | |
| 70 } pdf_exec_menu_item_event_internal; | |
| 71 | |
| 72 const char *pdf_access_exec_menu_item_event(fz_context *ctx, pdf_doc_event *evt) | |
| 73 { | |
| 74 const char *item = NULL; | |
| 75 | |
| 76 if (evt->type == PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM) | |
| 77 item = ((pdf_exec_menu_item_event_internal *)evt)->item; | |
| 78 | |
| 79 return item; | |
| 80 } | |
| 81 | |
| 82 void pdf_event_issue_exec_menu_item(fz_context *ctx, pdf_document *doc, const char *item) | |
| 83 { | |
| 84 if (doc->event_cb) | |
| 85 { | |
| 86 pdf_exec_menu_item_event_internal ievent; | |
| 87 ievent.base.type = PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM; | |
| 88 ievent.item = item; | |
| 89 | |
| 90 doc->event_cb(ctx, doc, (pdf_doc_event *)&ievent, doc->event_cb_data); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 typedef struct | |
| 95 { | |
| 96 pdf_doc_event base; | |
| 97 pdf_launch_url_event launch_url; | |
| 98 } pdf_launch_url_event_internal; | |
| 99 | |
| 100 pdf_launch_url_event *pdf_access_launch_url_event(fz_context *ctx, pdf_doc_event *evt) | |
| 101 { | |
| 102 pdf_launch_url_event *launch_url = NULL; | |
| 103 | |
| 104 if (evt->type == PDF_DOCUMENT_EVENT_LAUNCH_URL) | |
| 105 launch_url = &((pdf_launch_url_event_internal *)evt)->launch_url; | |
| 106 | |
| 107 return launch_url; | |
| 108 } | |
| 109 | |
| 110 void pdf_event_issue_launch_url(fz_context *ctx, pdf_document *doc, const char *url, int new_frame) | |
| 111 { | |
| 112 if (doc->event_cb) | |
| 113 { | |
| 114 pdf_launch_url_event_internal e; | |
| 115 | |
| 116 e.base.type = PDF_DOCUMENT_EVENT_LAUNCH_URL; | |
| 117 e.launch_url.url = url; | |
| 118 e.launch_url.new_frame = new_frame; | |
| 119 doc->event_cb(ctx, doc, (pdf_doc_event *)&e, doc->event_cb_data); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 typedef struct | |
| 124 { | |
| 125 pdf_doc_event base; | |
| 126 pdf_mail_doc_event mail_doc; | |
| 127 } pdf_mail_doc_event_internal; | |
| 128 | |
| 129 pdf_mail_doc_event *pdf_access_mail_doc_event(fz_context *ctx, pdf_doc_event *evt) | |
| 130 { | |
| 131 pdf_mail_doc_event *mail_doc = NULL; | |
| 132 | |
| 133 if (evt->type == PDF_DOCUMENT_EVENT_MAIL_DOC) | |
| 134 mail_doc = &((pdf_mail_doc_event_internal *)evt)->mail_doc; | |
| 135 | |
| 136 return mail_doc; | |
| 137 } | |
| 138 | |
| 139 void pdf_event_issue_mail_doc(fz_context *ctx, pdf_document *doc, pdf_mail_doc_event *evt) | |
| 140 { | |
| 141 if (doc->event_cb) | |
| 142 { | |
| 143 pdf_mail_doc_event_internal e; | |
| 144 | |
| 145 e.base.type = PDF_DOCUMENT_EVENT_MAIL_DOC; | |
| 146 e.mail_doc = *evt; | |
| 147 | |
| 148 doc->event_cb(ctx, doc, (pdf_doc_event *)&e, doc->event_cb_data); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 void pdf_set_doc_event_callback(fz_context *ctx, pdf_document *doc, pdf_doc_event_cb *event_cb, pdf_free_doc_event_data_cb *free_event_data_cb, void *data) | |
| 153 { | |
| 154 if (doc->free_event_data_cb) | |
| 155 doc->free_event_data_cb(ctx, doc->event_cb_data); | |
| 156 doc->event_cb = event_cb; | |
| 157 doc->free_event_data_cb = free_event_data_cb; | |
| 158 doc->event_cb_data = data; | |
| 159 } | |
| 160 | |
| 161 void *pdf_get_doc_event_callback_data(fz_context *ctx, pdf_document *doc) | |
| 162 { | |
| 163 return doc->event_cb_data; | |
| 164 } |
