diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/jstest_main.c | 16 | ||||
-rw-r--r-- | apps/pdfapp.c | 22 | ||||
-rw-r--r-- | apps/pdfapp.h | 1 | ||||
-rw-r--r-- | apps/win_main.c | 56 | ||||
-rw-r--r-- | apps/x11_main.c | 16 |
5 files changed, 111 insertions, 0 deletions
diff --git a/apps/jstest_main.c b/apps/jstest_main.c index bb2f4afd..a6ff06d1 100644 --- a/apps/jstest_main.c +++ b/apps/jstest_main.c @@ -37,6 +37,22 @@ void winerror(pdfapp_t *app, char *msg) exit(1); } +void winalert(pdfapp_t *app, fz_alert_event *alert) +{ + fprintf(stderr, "Alert %s: %s", alert->title, alert->message); + switch (alert->button_group_type) + { + case FZ_ALERT_BUTTON_GROUP_OK: + case FZ_ALERT_BUTTON_GROUP_OK_CANCEL: + alert->button_pressed = FZ_ALERT_BUTTON_OK; + break; + case FZ_ALERT_BUTTON_GROUP_YES_NO: + case FZ_ALERT_BUTTON_GROUP_YES_NO_CANCEL: + alert->button_pressed = FZ_ALERT_BUTTON_YES; + break; + } +} + static char pd_password[256] = ""; static char td_textinput[LONGLINE] = ""; diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 3468e07d..0a87565a 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -101,6 +101,21 @@ void pdfapp_invert(pdfapp_t *app, fz_bbox rect) fz_invert_pixmap_rect(app->image, rect); } +static void event_cb(fz_doc_event *event, void *data) +{ + pdfapp_t *app = (pdfapp_t *)data; + + switch (event->type) + { + case FZ_DOCUMENT_EVENT_ALERT: + { + fz_alert_event *alert = fz_access_alert_event(event); + winalert(app, alert); + } + break; + } +} + void pdfapp_open(pdfapp_t *app, char *filename, int reload) { fz_context *ctx = app->ctx; @@ -108,8 +123,15 @@ void pdfapp_open(pdfapp_t *app, char *filename, int reload) fz_try(ctx) { + fz_interactive *idoc; + app->doc = fz_open_document(ctx, filename); + idoc = fz_interact(app->doc); + + if (idoc) + fz_set_doc_event_callback(idoc, event_cb, app); + if (fz_needs_password(app->doc)) { int okay = fz_authenticate_password(app->doc, password); diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 43bc7b3b..46dcf291 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -37,6 +37,7 @@ extern void winhelp(pdfapp_t*); extern void winfullscreen(pdfapp_t*, int state); extern int winsavequery(pdfapp_t*); extern int wingetsavepath(pdfapp_t*, char *buf, int len); +extern void winalert(pdfapp_t *, fz_alert_event *alert); struct pdfapp_s { diff --git a/apps/win_main.c b/apps/win_main.c index 025e38db..97f927f2 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -99,6 +99,62 @@ void winerror(pdfapp_t *app, char *msg) exit(1); } +void winalert(pdfapp_t *app, fz_alert_event *alert) +{ + int buttons = MB_OK; + int icon = MB_ICONWARNING; + int pressed = FZ_ALERT_BUTTON_NONE; + + switch (alert->icon_type) + { + case FZ_ALERT_ICON_ERROR: + icon = MB_ICONERROR; + break; + case FZ_ALERT_ICON_WARNING: + icon = MB_ICONWARNING; + break; + case FZ_ALERT_ICON_QUESTION: + icon = MB_ICONQUESTION; + break; + case FZ_ALERT_ICON_STATUS: + icon = MB_ICONINFORMATION; + break; + } + + switch (alert->button_group_type) + { + case FZ_ALERT_BUTTON_GROUP_OK: + buttons = MB_OK; + break; + case FZ_ALERT_BUTTON_GROUP_OK_CANCEL: + buttons = MB_OKCANCEL; + break; + case FZ_ALERT_BUTTON_GROUP_YES_NO: + buttons = MB_YESNO; + break; + case FZ_ALERT_BUTTON_GROUP_YES_NO_CANCEL: + buttons = MB_YESNOCANCEL; + break; + } + + pressed = MessageBoxA(hwndframe, alert->message, alert->title, icon|buttons); + + switch (pressed) + { + case IDOK: + alert->button_pressed = FZ_ALERT_BUTTON_OK; + break; + case IDCANCEL: + alert->button_pressed = FZ_ALERT_BUTTON_CANCEL; + break; + case IDNO: + alert->button_pressed = FZ_ALERT_BUTTON_NO; + break; + case IDYES: + alert->button_pressed = FZ_ALERT_BUTTON_YES; + } +} + int winsavequery(pdfapp_t *app) { switch(MessageBoxA(hwndframe, "File has unsaved changes. Do you want to save", "MuPDF", MB_YESNOCANCEL)) diff --git a/apps/x11_main.c b/apps/x11_main.c index 623187fa..182aadb4 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -110,6 +110,22 @@ void winwarn(pdfapp_t *app, char *msg) fprintf(stderr, "mupdf: warning: %s\n", msg); } +void winalert(pdfapp_t *app, fz_alert_event *alert) +{ + fprintf(stderr, "Alert %s: %s", alert->title, alert->message); + switch (alert->button_group_type) + { + case FZ_ALERT_BUTTON_GROUP_OK: + case FZ_ALERT_BUTTON_GROUP_OK_CANCEL: + alert->button_pressed = FZ_ALERT_BUTTON_OK; + break; + case FZ_ALERT_BUTTON_GROUP_YES_NO: + case FZ_ALERT_BUTTON_GROUP_YES_NO_CANCEL: + alert->button_pressed = FZ_ALERT_BUTTON_YES; + break; + } +} + char *winpassword(pdfapp_t *app, char *filename) { char *r = password; |