diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/gl/gl-annotate.c | 58 | ||||
-rw-r--r-- | platform/gl/gl-app.h | 5 | ||||
-rw-r--r-- | platform/gl/gl-file.c | 2 | ||||
-rw-r--r-- | platform/gl/gl-form.c | 158 | ||||
-rw-r--r-- | platform/gl/gl-main.c | 24 | ||||
-rw-r--r-- | platform/win32/mupdf-gl.vcproj | 4 |
6 files changed, 183 insertions, 68 deletions
diff --git a/platform/gl/gl-annotate.c b/platform/gl/gl-annotate.c index 40e36a31..31fc20ae 100644 --- a/platform/gl/gl-annotate.c +++ b/platform/gl/gl-annotate.c @@ -62,7 +62,7 @@ static void save_pdf_dialog(void) } fz_catch(ctx) { - ui_show_warning_dialog(fz_caught_message(ctx)); + ui_show_warning_dialog("%s", fz_caught_message(ctx)); } } } @@ -357,60 +357,6 @@ static void do_annotate_contents(void) pdf_set_annot_contents(ctx, selected_annot, input.text); } -static void do_widget_value(void) -{ - int ff, type; - char *value; - - ff = pdf_get_field_flags(ctx, selected_annot->page->doc, selected_annot->obj); - type = pdf_field_type(ctx, selected_annot->page->doc, selected_annot->obj); - - if (type == PDF_WIDGET_TYPE_TEXT) - { - static pdf_annot *last_annot = NULL; - static struct input input; - ui_label("Value:"); - if (selected_annot != last_annot) - { - last_annot = selected_annot; - value = pdf_field_value(ctx, selected_annot->page->doc, selected_annot->obj); - ui_input_init(&input, value); - fz_free(ctx, value); - } - if (ui_input(&input, 0, (ff & Ff_Multiline) ? 5 : 1) >= UI_INPUT_EDIT) - { - pdf_field_set_value(ctx, selected_annot->page->doc, selected_annot->obj, input.text); - if (pdf_update_page(ctx, selected_annot->page)) - render_page(); - } - } - else if (type == PDF_WIDGET_TYPE_COMBOBOX || type == PDF_WIDGET_TYPE_LISTBOX) - { - const char **options; - int n, choice; - ui_label("Value:"); - n = pdf_choice_widget_options(ctx, selected_annot->page->doc, selected_annot, 0, NULL); - options = fz_malloc_array(ctx, n, sizeof(char*)); - pdf_choice_widget_options(ctx, selected_annot->page->doc, selected_annot, 0, options); - value = pdf_field_value(ctx, selected_annot->page->doc, selected_annot->obj); - choice = ui_select("Widget/Ch", value, (const char **)options, n); - if (choice >= 0) - { - pdf_field_set_value(ctx, selected_annot->page->doc, selected_annot->obj, options[choice]); - if (pdf_update_page(ctx, selected_annot->page)) - render_page(); - } - fz_free(ctx, value); - fz_free(ctx, options); - } - else - { - value = pdf_field_value(ctx, selected_annot->page->doc, selected_annot->obj); - ui_label("Value: %s", value); - fz_free(ctx, value); - } -} - static const char *file_attachment_icons[] = { "Graph", "Paperclip", "PushPin", "Tag" }; static const char *sound_icons[] = { "Speaker", "Mic" }; static const char *stamp_icons[] = { @@ -568,7 +514,7 @@ void do_annotate_panel(void) ui_spacer(); if (subtype == PDF_ANNOT_WIDGET) - do_widget_value(); + do_widget_panel(); else do_annotate_contents(); diff --git a/platform/gl/gl-app.h b/platform/gl/gl-app.h index 64c9335f..8b4cbe74 100644 --- a/platform/gl/gl-app.h +++ b/platform/gl/gl-app.h @@ -201,8 +201,8 @@ int ui_open_file(char filename[]); void ui_init_save_file(const char *path, int (*filter)(const char *fn)); int ui_save_file(char filename[], void (*extra_panel)(void)); -void ui_show_warning_dialog(const char *message); -void ui_show_error_dialog(const char *message); +void ui_show_warning_dialog(const char *fmt, ...); +void ui_show_error_dialog(const char *fmt, ...); /* Theming */ @@ -242,6 +242,7 @@ extern char filename[]; void run_main_loop(void); void do_annotate_panel(void); void do_annotate_canvas(fz_irect canvas_area); +void do_widget_panel(void); void render_page(void); void update_title(void); void reload(void); diff --git a/platform/gl/gl-file.c b/platform/gl/gl-file.c index 6fc34f5d..f04b5cac 100644 --- a/platform/gl/gl-file.c +++ b/platform/gl/gl-file.c @@ -295,7 +295,7 @@ static void list_drives(void) void ui_init_open_file(const char *dir, int (*filter)(const char *fn)) { fc.filter = filter; - load_dir("."); + load_dir(dir); } int ui_open_file(char filename[PATH_MAX]) diff --git a/platform/gl/gl-form.c b/platform/gl/gl-form.c new file mode 100644 index 00000000..f9083f71 --- /dev/null +++ b/platform/gl/gl-form.c @@ -0,0 +1,158 @@ +#include "gl-app.h" + +#include <string.h> +#include <stdio.h> + +#ifndef PATH_MAX +#define PATH_MAX 2048 +#endif + +#include "mupdf/helpers/pkcs7-check.h" +#include "mupdf/helpers/pkcs7-openssl.h" + +static char cert_filename[PATH_MAX]; +static struct input cert_password; + +static void do_sign(void) +{ + pdf_pkcs7_signer *signer = NULL; + + fz_var(signer); + + fz_try(ctx) + { + signer = pkcs7_openssl_read_pfx(ctx, cert_filename, cert_password.text); + pdf_sign_signature(ctx, pdf, selected_annot, signer); + ui_show_warning_dialog("Signed document successfully."); + } + fz_always(ctx) + { + if (signer) + signer->drop(signer); + } + fz_catch(ctx) + ui_show_warning_dialog("%s", fz_caught_message(ctx)); + + if (pdf_update_page(ctx, selected_annot->page)) + render_page(); +} + +static void cert_password_dialog(void) +{ + int is; + ui_dialog_begin(400, (ui.gridsize+4)*3); + { + ui_layout(T, X, NW, 2, 2); + ui_label("Password:"); + is = ui_input(&cert_password, 200, 1); + + ui_layout(B, X, NW, 2, 2); + ui_panel_begin(0, ui.gridsize, 0, 0, 0); + { + ui_layout(R, NONE, S, 0, 0); + if (ui_button("Cancel")) + ui.dialog = NULL; + ui_spacer(); + if (ui_button("Okay") || is == UI_INPUT_ACCEPT) + { + ui.dialog = NULL; + do_sign(); + } + } + ui_panel_end(); + } + ui_dialog_end(); +} + +static int cert_file_filter(const char *fn) +{ + return !!strstr(fn, ".pfx"); +} + +static void cert_file_dialog(void) +{ + if (ui_open_file(cert_filename)) + { + if (cert_filename[0] != 0) + { + ui_input_init(&cert_password, ""); + ui.focus = &cert_password; + ui.dialog = cert_password_dialog; + } + else + ui.dialog = NULL; + } +} + +void do_widget_panel(void) +{ + int ff, type; + char *value; + + ff = pdf_get_field_flags(ctx, selected_annot->page->doc, selected_annot->obj); + type = pdf_field_type(ctx, selected_annot->page->doc, selected_annot->obj); + + if (type == PDF_WIDGET_TYPE_TEXT) + { + static pdf_annot *last_annot = NULL; + static struct input input; + ui_label("Value:"); + if (selected_annot != last_annot) + { + last_annot = selected_annot; + value = pdf_field_value(ctx, selected_annot->page->doc, selected_annot->obj); + ui_input_init(&input, value); + fz_free(ctx, value); + } + if (ui_input(&input, 0, (ff & Ff_Multiline) ? 5 : 1) >= UI_INPUT_EDIT) + { + pdf_field_set_value(ctx, selected_annot->page->doc, selected_annot->obj, input.text); + if (pdf_update_page(ctx, selected_annot->page)) + render_page(); + } + } + else if (type == PDF_WIDGET_TYPE_COMBOBOX || type == PDF_WIDGET_TYPE_LISTBOX) + { + const char **options; + int n, choice; + ui_label("Value:"); + n = pdf_choice_widget_options(ctx, selected_annot->page->doc, selected_annot, 0, NULL); + options = fz_malloc_array(ctx, n, sizeof(char*)); + pdf_choice_widget_options(ctx, selected_annot->page->doc, selected_annot, 0, options); + value = pdf_field_value(ctx, selected_annot->page->doc, selected_annot->obj); + choice = ui_select("Widget/Ch", value, (const char **)options, n); + if (choice >= 0) + { + pdf_field_set_value(ctx, selected_annot->page->doc, selected_annot->obj, options[choice]); + if (pdf_update_page(ctx, selected_annot->page)) + render_page(); + } + fz_free(ctx, value); + fz_free(ctx, options); + } + else if (type == PDF_WIDGET_TYPE_SIGNATURE) + { + if (ui_button("Verify")) + { + char status[100]; + int result; + result = pdf_check_signature(ctx, pdf, selected_annot, status, sizeof status); + if (result) + ui_show_warning_dialog("Signature is valid.\n%s", status); + else + ui_show_warning_dialog("Could not verify signature:\n%s", status); + } + if (ui_button("Sign")) + { + fz_strlcpy(cert_filename, filename, sizeof cert_filename); + ui_init_open_file(".", cert_file_filter); + ui.dialog = cert_file_dialog; + } + } + else + { + value = pdf_field_value(ctx, pdf, selected_annot->obj); + ui_label("Value: %s", value); + fz_free(ctx, value); + } +} diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c index 46566f2f..ed1591e4 100644 --- a/platform/gl/gl-main.c +++ b/platform/gl/gl-main.c @@ -147,7 +147,7 @@ static fz_quad search_hit_quads[5000]; static char error_message[256]; static void error_dialog(void) { - ui_dialog_begin(500, (ui.gridsize+4)*3); + ui_dialog_begin(500, (ui.gridsize+4)*4); ui_layout(T, NONE, NW, 2, 2); ui_label("%C %s", 0x1f4a3, error_message); /* BOMB */ ui_layout(B, NONE, S, 2, 2); @@ -155,16 +155,19 @@ static void error_dialog(void) exit(1); ui_dialog_end(); } -void ui_show_error_dialog(const char *message) +void ui_show_error_dialog(const char *fmt, ...) { - fz_strlcpy(error_message, message, sizeof error_message); + va_list ap; + va_start(ap, fmt); + fz_vsnprintf(error_message, sizeof error_message, fmt, ap); + va_end(ap); ui.dialog = error_dialog; } static char warning_message[256]; static void warning_dialog(void) { - ui_dialog_begin(500, (ui.gridsize+4)*3); + ui_dialog_begin(500, (ui.gridsize+4)*4); ui_layout(T, NONE, NW, 2, 2); ui_label("%C %s", 0x26a0, warning_message); /* WARNING SIGN */ ui_layout(B, NONE, S, 2, 2); @@ -172,9 +175,12 @@ static void warning_dialog(void) ui.dialog = NULL; ui_dialog_end(); } -void ui_show_warning_dialog(const char *message) +void ui_show_warning_dialog(const char *fmt, ...) { - fz_strlcpy(warning_message, message, sizeof warning_message); + va_list ap; + va_start(ap, fmt); + fz_vsnprintf(warning_message, sizeof warning_message, fmt, ap); + va_end(ap); ui.dialog = warning_dialog; } @@ -1265,7 +1271,7 @@ void run_main_loop(void) do_main(); } fz_catch(ctx) - ui_show_error_dialog(fz_caught_message(ctx)); + ui_show_error_dialog("%s", fz_caught_message(ctx)); ui_end(); } @@ -1364,7 +1370,7 @@ int main(int argc, char **argv) } fz_catch(ctx) { - ui_show_error_dialog(fz_caught_message(ctx)); + ui_show_error_dialog("%s", fz_caught_message(ctx)); } fz_try(ctx) @@ -1377,7 +1383,7 @@ int main(int argc, char **argv) } fz_catch(ctx) { - ui_show_error_dialog(fz_caught_message(ctx)); + ui_show_error_dialog("%s", fz_caught_message(ctx)); } } else diff --git a/platform/win32/mupdf-gl.vcproj b/platform/win32/mupdf-gl.vcproj index 3ed7f42a..3f48e261 100644 --- a/platform/win32/mupdf-gl.vcproj +++ b/platform/win32/mupdf-gl.vcproj @@ -947,6 +947,10 @@ > </File> <File + RelativePath="..\gl\gl-form.c" + > + </File> + <File RelativePath="..\gl\gl-input.c" > </File> |