diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-09-08 16:14:02 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-10-06 11:21:23 +0200 |
commit | 36ad0a6f567192d676d128628eb461204984e070 (patch) | |
tree | 62b0dcc27837f15a1edfd5e56e5e736aea46767b | |
parent | 5ae0871d6e950f5afad17c01362b9d95ecec6a9d (diff) | |
download | mupdf-36ad0a6f567192d676d128628eb461204984e070.tar.xz |
gl: Windows stuff.
* Add icons to application and window.
* Open file dialog if no command line argument.
* Install file type associations.
-rw-r--r-- | platform/gl/gl-app.h | 6 | ||||
-rw-r--r-- | platform/gl/gl-main.c | 35 | ||||
-rw-r--r-- | platform/gl/gl-win32.c | 98 | ||||
-rw-r--r-- | platform/gl/gl-winres.rc | 2 | ||||
-rw-r--r-- | platform/win32/mupdf-gl.vcproj | 8 |
5 files changed, 136 insertions, 13 deletions
diff --git a/platform/gl/gl-app.h b/platform/gl/gl-app.h index 2a16cfdb..3889d92c 100644 --- a/platform/gl/gl-app.h +++ b/platform/gl/gl-app.h @@ -1,3 +1,9 @@ +#ifdef _WIN32 +#include <windows.h> +void win_install(void); +int win_open_file(char *buf, int len); +#endif + #include "mupdf/fitz.h" #include <GLFW/glfw3.h> diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c index 88eaf5b0..8396029e 100644 --- a/platform/gl/gl-main.c +++ b/platform/gl/gl-main.c @@ -1,10 +1,3 @@ -#ifdef _WIN32 -#include <windows.h> -#ifdef _MSC_VER -#define main main_utf8 -#endif -#endif - #include "gl-app.h" struct ui ui; @@ -131,7 +124,6 @@ static int zoom_out(int oldres) #define MAXRES (zoom_list[nelem(zoom_list)-1]) #define DEFRES 96 -static const char *filename = ""; static const char *title = "MuPDF/GL"; static fz_document *doc = NULL; static fz_outline *outline = NULL; @@ -379,7 +371,7 @@ static void do_copy_region(fz_rect *sel, int xofs, int yofs, float zoom, float r saw_text = 1; if (need_newline) { -#if defined(_WIN32) || defined(_WIN64) +#ifdef _WIN32 fz_write_buffer_rune(ctx, buf, '\r'); #endif fz_write_buffer_rune(ctx, buf, '\n'); @@ -1199,14 +1191,31 @@ static void on_error(int error, const char *msg) fprintf(stderr, "gl error %d: %s\n", error, msg); } + +#ifdef _MSC_VER +int main_utf8(int argc, char **argv) +#else int main(int argc, char **argv) +#endif { - if (argc < 2) { + char filename[2048]; + + if (argc < 2) + { +#ifdef _WIN32 + win_install(); + if (!win_open_file(filename, sizeof filename)); + exit(0); +#else fprintf(stderr, "usage: mupdf-gl input.pdf\n"); exit(1); +#endif + } + else + { + fz_strlcpy(filename, argv[1], sizeof filename); } - filename = argv[1]; title = strrchr(filename, '/'); if (!title) title = strrchr(filename, '\\'); @@ -1251,7 +1260,7 @@ int main(int argc, char **argv) ui_init_fonts(ctx, ui.fontsize); - doc = fz_open_document(ctx, argv[1]); + doc = fz_open_document(ctx, filename); render_page(currentpage, currentzoom, currentrotate); update_title(); @@ -1288,7 +1297,7 @@ int main(int argc, char **argv) int wmain(int argc, wchar_t *wargv[]) { char **argv = fz_argv_from_wargv(argc, wargv); - int ret = main(argc, argv); + int ret = main_utf8(argc, argv); fz_free_argv(argc, argv); return ret; } diff --git a/platform/gl/gl-win32.c b/platform/gl/gl-win32.c new file mode 100644 index 00000000..d5830337 --- /dev/null +++ b/platform/gl/gl-win32.c @@ -0,0 +1,98 @@ +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <commdlg.h> +#include <shellapi.h> +#include <stdio.h> + +#define OPEN_KEY(parent, name, ptr) \ + RegCreateKeyExA(parent, name, 0, 0, 0, KEY_WRITE, 0, ptr, 0) +#define SET_VALUE(parent, name, value) \ + RegSetValueExA(parent, name, 0, REG_SZ, (const BYTE *)(value), (DWORD)strlen(value) + 1) + +void win_install(void) +{ + char command_str[2048], argv0[2048]; + HKEY software, classes, mupdf; + HKEY supported_types, shell, open, command; + HKEY dotpdf, dotxps, dotcbz, dotepub; + HKEY pdf_progids, xps_progids, cbz_progids, epub_progids; + + GetModuleFileNameA(NULL, argv0, sizeof argv0); + _snprintf(command_str, sizeof command_str, "\"%s\" \"%%1\"", argv0); + + OPEN_KEY(HKEY_CURRENT_USER, "Software", &software); + OPEN_KEY(software, "Classes", &classes); + { + OPEN_KEY(classes, "MuPDF", &mupdf); + { + OPEN_KEY(mupdf, "SupportedTypes", &supported_types); + { + SET_VALUE(supported_types, ".pdf", ""); + SET_VALUE(supported_types, ".xps", ""); + SET_VALUE(supported_types, ".cbz", ""); + SET_VALUE(supported_types, ".epub", ""); + } + RegCloseKey(supported_types); + OPEN_KEY(mupdf, "shell", &shell); + OPEN_KEY(shell, "open", &open); + OPEN_KEY(open, "command", &command); + { + SET_VALUE(open, "FriendlyAppName", "MuPDF"); + SET_VALUE(command, "", command_str); + } + RegCloseKey(command); + RegCloseKey(open); + RegCloseKey(shell); + } + RegCloseKey(mupdf); + + OPEN_KEY(classes, ".pdf", &dotpdf); + OPEN_KEY(classes, ".xps", &dotxps); + OPEN_KEY(classes, ".cbz", &dotcbz); + OPEN_KEY(classes, ".epub", &dotepub); + { + OPEN_KEY(dotpdf, "OpenWithProgids", &pdf_progids); + OPEN_KEY(dotxps, "OpenWithProgids", &xps_progids); + OPEN_KEY(dotcbz, "OpenWithProgids", &cbz_progids); + OPEN_KEY(dotepub, "OpenWithProgids", &epub_progids); + { + SET_VALUE(pdf_progids, "MuPDF", ""); + SET_VALUE(xps_progids, "MuPDF", ""); + SET_VALUE(cbz_progids, "MuPDF", ""); + SET_VALUE(epub_progids, "MuPDF", ""); + } + RegCloseKey(pdf_progids); + RegCloseKey(xps_progids); + RegCloseKey(cbz_progids); + RegCloseKey(epub_progids); + } + RegCloseKey(dotpdf); + RegCloseKey(dotxps); + RegCloseKey(dotcbz); + RegCloseKey(dotepub); + } + RegCloseKey(classes); + RegCloseKey(software); +} + +int win_open_file(char *buf, int len) +{ + wchar_t wbuf[2048]; + OPENFILENAME ofn; + int code; + wbuf[0] = 0; + memset(&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.lpstrFile = wbuf; + ofn.nMaxFile = 2048; + ofn.lpstrTitle = L"MuPDF: Open PDF file"; + ofn.lpstrFilter = L"Documents (*.pdf;*.xps;*.cbz;*.epub;*.zip;*.png;*.jpeg;*.tiff)\0*.zip;*.cbz;*.xps;*.epub;*.pdf;*.jpe;*.jpg;*.jpeg;*.jfif;*.tif;*.tiff\0PDF Files (*.pdf)\0*.pdf\0XPS Files (*.xps)\0*.xps\0CBZ Files (*.cbz;*.zip)\0*.zip;*.cbz\0EPUB Files (*.epub)\0*.epub\0Image Files (*.png;*.jpeg;*.tiff)\0*.png;*.jpg;*.jpe;*.jpeg;*.jfif;*.tif;*.tiff\0All Files\0*\0\0"; + ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + code = GetOpenFileNameW(&ofn); + if (code) + WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, buf, len, NULL, NULL); + return code; +} + +#endif diff --git a/platform/gl/gl-winres.rc b/platform/gl/gl-winres.rc new file mode 100644 index 00000000..081cff94 --- /dev/null +++ b/platform/gl/gl-winres.rc @@ -0,0 +1,2 @@ +IDI_ICONAPP ICON "mupdf.ico" +GLFW_ICON ICON "mupdf.ico" diff --git a/platform/win32/mupdf-gl.vcproj b/platform/win32/mupdf-gl.vcproj index 05665433..062dd2d2 100644 --- a/platform/win32/mupdf-gl.vcproj +++ b/platform/win32/mupdf-gl.vcproj @@ -189,6 +189,14 @@ RelativePath="..\gl\gl-main.c" > </File> + <File + RelativePath="..\gl\gl-win32.c" + > + </File> + <File + RelativePath="..\gl\gl-winres.rc" + > + </File> </Files> <Globals> </Globals> |