diff --git a/frontends/windows/Makefile b/frontends/windows/Makefile index f6995910d..d22e17112 100644 --- a/frontends/windows/Makefile +++ b/frontends/windows/Makefile @@ -33,11 +33,15 @@ WSCFLAGS := -std=c99 -Dnswin32 -DCURL_STATICLIB -DCARES_STATICLIB -g CFLAGS += $(WSCFLAGS) LDFLAGS += $(WSCFLAGS) +# The filter and target for split messages +MESSAGES_FILTER=win +MESSAGES_TARGET=$(FRONTEND_RESOURCES_DIR) + # ---------------------------------------------------------------------------- # built-in resource setup # ---------------------------------------------------------------------------- -$(OBJROOT)/windows_resource.o: $(FRONTEND_RESOURCES_DIR)/resource.rc +$(OBJROOT)/windows_resource.o: $(FRONTEND_RESOURCES_DIR)/resource.rc $(addsuffix /Messages,$(addprefix $(MESSAGES_TARGET)/,$(MESSAGES_LANGUAGES))) $(VQ)echo " WINDRES: compiling windows resources" ${Q}$(WINDRES) $< -O coff -o $@ @@ -49,7 +53,7 @@ S_RESOURCES := windows_resource.o # sources purely for the windows build S_FRONTEND := main.c window.c gui.c drawable.c plot.c findfile.c \ - font.c bitmap.c about.c prefs.c download.c filetype.c file.c \ + font.c bitmap.c about.c prefs.c download.c fetch.c file.c \ local_history.c schedule.c windbg.c pointers.c login.c \ corewindow.c hotlist.c cookies.c global_history.c ssl_cert.c diff --git a/frontends/windows/filetype.c b/frontends/windows/fetch.c similarity index 55% rename from frontends/windows/filetype.c rename to frontends/windows/fetch.c index a5fd9e95e..f69d7ad19 100644 --- a/frontends/windows/filetype.c +++ b/frontends/windows/fetch.c @@ -1,5 +1,5 @@ /* - * Copyright 2003 James Bursa + * Copyright 2018 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -25,10 +25,13 @@ #include #include "utils/log.h" +#include "utils/file.h" +#include "utils/filepath.h" #include "content/fetch.h" #include "netsurf/fetch.h" -#include "windows/filetype.h" +#include "windows/fetch.h" +#include "windows/gui.h" /** * determine the MIME type of a local file. @@ -60,9 +63,71 @@ static const char *fetch_filetype(const char *unix_path) return "text/html"; } +/** + * Translate resource to full win32 url. + * + * Transforms a resource: path into a full URL. The returned URL + * is used as the target for a redirect. The caller takes ownership of + * the returned nsurl including unrefing it when finished with it. + * + * \param path The path of the resource to locate. + * \return A string containing the full URL of the target object or + * NULL if no suitable resource can be found. + */ +static nsurl *nsw32_get_resource_url(const char *path) +{ + char buf[PATH_MAX]; + nsurl *url = NULL; + + netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); + + return url; +} + + +/* exported interface documented in windows/fetch.h */ +nserror +nsw32_get_resource_data(const char *path, + const uint8_t **data_out, + size_t *data_len_out) +{ + HRSRC reshandle; + HGLOBAL datahandle; + uint8_t *data; + DWORD data_len; + + reshandle = FindResource(NULL, path, "USER"); + if (reshandle == NULL) { + return NSERROR_NOT_FOUND; + } + + data_len = SizeofResource(NULL, reshandle); + if (data_len == 0) { + return NSERROR_NOT_FOUND; + } + + datahandle = LoadResource(NULL, reshandle); + if (datahandle == NULL) { + return NSERROR_NOT_FOUND; + } + data = LockResource(datahandle); + if (data == NULL) { + return NSERROR_NOT_FOUND; + } + + *data_out = data; + *data_len_out = data_len; + + return NSERROR_OK; +} + + /** win32 fetch operation table */ static struct gui_fetch_table fetch_table = { .filetype = fetch_filetype, + + .get_resource_url = nsw32_get_resource_url, + .get_resource_data = nsw32_get_resource_data, }; struct gui_fetch_table *win32_fetch_table = &fetch_table; diff --git a/frontends/windows/filetype.h b/frontends/windows/fetch.h similarity index 63% rename from frontends/windows/filetype.h rename to frontends/windows/fetch.h index f71a0b2da..20984f14a 100644 --- a/frontends/windows/filetype.h +++ b/frontends/windows/fetch.h @@ -19,6 +19,22 @@ #ifndef _NETSURF_WINDOWS_FILETYPE_H_ #define _NETSURF_WINDOWS_FILETYPE_H_ +/** + * win32 API fetch operation table + */ struct gui_fetch_table *win32_fetch_table; +/** + * Translate resource to win32 resource data. + * + * Obtains the data for a resource directly + * + * \param path The path of the resource to locate. + * \param data Pointer to recive data into + * \param data_len Pointer to length of returned data + * \return NSERROR_OK and the data and length values updated + * else appropriate error code. + */ +nserror nsw32_get_resource_data(const char *path, const uint8_t **data_out, size_t *data_len_out); + #endif diff --git a/frontends/windows/gui.c b/frontends/windows/gui.c index 674484fea..bafe5a4b7 100644 --- a/frontends/windows/gui.c +++ b/frontends/windows/gui.c @@ -40,7 +40,6 @@ #include "windows/schedule.h" #include "windows/window.h" -#include "windows/filetype.h" #include "windows/gui.h" /** diff --git a/frontends/windows/gui.h b/frontends/windows/gui.h index 5fd9decb2..95dcfc1b2 100644 --- a/frontends/windows/gui.h +++ b/frontends/windows/gui.h @@ -28,6 +28,9 @@ extern HINSTANCE hinst; /** Directory where all configuration files are held. */ extern char *nsw32_config_home; +/** resource search path vector. */ +extern char **respaths; + /* bounding box */ typedef struct bbox_s { int x0; diff --git a/frontends/windows/main.c b/frontends/windows/main.c index 5dd1e7316..fd22ae1fe 100644 --- a/frontends/windows/main.c +++ b/frontends/windows/main.c @@ -51,12 +51,12 @@ #include "windows/window.h" #include "windows/schedule.h" #include "windows/font.h" -#include "windows/filetype.h" +#include "windows/fetch.h" #include "windows/pointers.h" #include "windows/bitmap.h" #include "windows/gui.h" -static char **respaths; /** resource search path vector. */ +char **respaths; /** exported global defined in windows/gui.h */ char *nsw32_config_home; /* exported global defined in windows/gui.h */ @@ -119,15 +119,6 @@ static void die(const char *error) } -static nsurl *gui_get_resource_url(const char *path) -{ - char buf[PATH_MAX]; - nsurl *url = NULL; - - netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); - - return url; -} /** * Ensures output logging stream is available @@ -135,7 +126,7 @@ static nsurl *gui_get_resource_url(const char *path) static bool nslog_ensure(FILE *fptr) { /* mwindows compile flag normally invalidates standard io unless - * already redirected + * already redirected */ if (_get_osfhandle(fileno(fptr)) == -1) { AllocConsole(); @@ -206,7 +197,7 @@ static nserror set_defaults(struct nsoption_s *defaults) } free(buf); - + /* ensure homepage option has a default */ nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE)); @@ -269,6 +260,32 @@ static nserror nsw32_option_init(int *pargc, char** argv) return NSERROR_OK; } +/** + * Initialise messages + */ +static nserror nsw32_messages_init(char **respaths) +{ + char *messages; + nserror res; + const uint8_t *data; + size_t data_size; + + res = nsw32_get_resource_data("messages", &data, &data_size); + if (res == NSERROR_OK) { + res = messages_add_from_inline(data, data_size); + } else { + /* Obtain path to messages */ + messages = filepath_find(respaths, "messages"); + if (messages == NULL) { + res = NSERROR_NOT_FOUND; + } else { + res = messages_add_from_file(messages); + free(messages); + } + } + + return res; +} static struct gui_misc_table win32_misc_table = { .schedule = win32_schedule, @@ -288,7 +305,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) int argc = 0, argctemp = 0; size_t len; LPWSTR *argvw; - char *messages; nserror ret; const char *addr; nsurl *url; @@ -303,7 +319,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) .bitmap = win32_bitmap_table, .layout = win32_layout_table, }; - win32_fetch_table->get_resource_url = gui_get_resource_url; ret = netsurf_register(&win32_table); if (ret != NSERROR_OK) { @@ -339,7 +354,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) } /* initialise logging - not fatal if it fails but not much we - * can do about it + * can do about it */ nslog_init(nslog_ensure, &argc, argv); @@ -361,10 +376,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH); - /* message init */ - messages = filepath_find(respaths, "messages"); - messages_add_from_file(messages); - free(messages); + /* Initialise translated messages */ + ret = nsw32_messages_init(respaths); + if (ret != NSERROR_OK) { + fprintf(stderr, "Unable to load translated messages (%s)\n", + messages_get_errorcode(ret)); + NSLOG(netsurf, INFO, "Unable to load translated messages"); + /** \todo decide if message load faliure should be fatal */ + } /* common initialisation */ ret = netsurf_init(NULL); diff --git a/frontends/windows/pointers.c b/frontends/windows/pointers.c index a730e4bd2..333ef1a9a 100644 --- a/frontends/windows/pointers.c +++ b/frontends/windows/pointers.c @@ -33,7 +33,6 @@ #include "windows/schedule.h" #include "windows/window.h" -#include "windows/filetype.h" #include "windows/pointers.h" struct nsws_pointers { diff --git a/frontends/windows/res/icons/arrow-l.png b/frontends/windows/res/icons/arrow-l.png new file mode 120000 index 000000000..6e580c561 --- /dev/null +++ b/frontends/windows/res/icons/arrow-l.png @@ -0,0 +1 @@ +../../../../resources/icons/arrow-l.png \ No newline at end of file diff --git a/frontends/windows/res/icons/content.png b/frontends/windows/res/icons/content.png new file mode 120000 index 000000000..dd71532dc --- /dev/null +++ b/frontends/windows/res/icons/content.png @@ -0,0 +1 @@ +../../../../resources/icons/content.png \ No newline at end of file diff --git a/frontends/windows/res/icons/directory.png b/frontends/windows/res/icons/directory.png new file mode 120000 index 000000000..71aee69d5 --- /dev/null +++ b/frontends/windows/res/icons/directory.png @@ -0,0 +1 @@ +../../../../resources/icons/directory.png \ No newline at end of file diff --git a/frontends/windows/res/icons/directory2.png b/frontends/windows/res/icons/directory2.png new file mode 120000 index 000000000..4daa093d0 --- /dev/null +++ b/frontends/windows/res/icons/directory2.png @@ -0,0 +1 @@ +../../../../resources/icons/directory2.png \ No newline at end of file diff --git a/frontends/windows/res/icons/hotlist-add.png b/frontends/windows/res/icons/hotlist-add.png new file mode 120000 index 000000000..5039509fc --- /dev/null +++ b/frontends/windows/res/icons/hotlist-add.png @@ -0,0 +1 @@ +../../../../resources/icons/hotlist-add.png \ No newline at end of file diff --git a/frontends/windows/res/icons/hotlist-rmv.png b/frontends/windows/res/icons/hotlist-rmv.png new file mode 120000 index 000000000..2b592cd13 --- /dev/null +++ b/frontends/windows/res/icons/hotlist-rmv.png @@ -0,0 +1 @@ +../../../../resources/icons/hotlist-rmv.png \ No newline at end of file diff --git a/frontends/windows/res/icons/search.png b/frontends/windows/res/icons/search.png new file mode 120000 index 000000000..e30f7bee8 --- /dev/null +++ b/frontends/windows/res/icons/search.png @@ -0,0 +1 @@ +../../../../resources/icons/search.png \ No newline at end of file diff --git a/frontends/windows/res/resource.rc b/frontends/windows/res/resource.rc index 8160bce33..e41a705a5 100644 --- a/frontends/windows/res/resource.rc +++ b/frontends/windows/res/resource.rc @@ -17,38 +17,6 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDR_NETSURF_BANNER BITMAP "banner.bmp" -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME0_BITMAP BITMAP "throbber/throbber0.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME1_BITMAP BITMAP "throbber/throbber1.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME2_BITMAP BITMAP "throbber/throbber2.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME3_BITMAP BITMAP "throbber/throbber3.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME4_BITMAP BITMAP "throbber/throbber4.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME5_BITMAP BITMAP "throbber/throbber5.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME6_BITMAP BITMAP "throbber/throbber6.bmp" - - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -IDR_THROBBER_FRAME7_BITMAP BITMAP "throbber/throbber7.bmp" - - LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDR_TOOLBAR_BITMAP BITMAP "toolbar.bmp" @@ -60,7 +28,8 @@ IDR_TOOLBAR_BITMAP_GREY BITMAP "toolbarg.bmp" LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDR_TOOLBAR_BITMAP_HOT BITMAP "toolbarh.bmp" - +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +IDR_THROBBER_AVI AVI "throbber.avi" // // Menu resources @@ -315,3 +284,43 @@ FONT 8, "MS Shell Dlg", 0, 0, 1 // LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDR_NETSURF_ICON ICON "NetSurf.ico" + + +// +// User resources +// + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +default.css USER "default.css" +adblock.css USER "adblock.css" +internal.css USER "internal.css" +quirks.css USER "quirks.css" +welcome.html USER "welcome.html" +licence.html USER "licence.html" +credits.html USER "credits.html" +netsurf.png USER "netsurf.png" +icons/arrow-l.png USER "icons/arrow-l.png" +icons/content.png USER "icons/content.png" +icons/directory.png USER "icons/directory.png" +icons/directory2.png USER "icons/directory2.png" +icons/hotlist-add.png USER "icons/hotlist-add.png" +icons/hotlist-rmv.png USER "icons/hotlist-rmv.png" +icons/search.png USER "icons/search.png" + +/* translated messages */ + +/* english is the fallback */ +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT +messages USER "en/Messages" + +LANGUAGE LANG_FRENCH, SUBLANG_DEFAULT +messages USER "fr/Messages" + +LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT +messages USER "de/Messages" + +LANGUAGE LANG_ITALIAN, SUBLANG_DEFAULT +messages USER "it/Messages" + +LANGUAGE LANG_DUTCH, SUBLANG_DEFAULT +messages USER "nl/Messages" diff --git a/frontends/windows/resourceid.h b/frontends/windows/resourceid.h index 9e70d6342..e86d8eedb 100644 --- a/frontends/windows/resourceid.h +++ b/frontends/windows/resourceid.h @@ -24,20 +24,13 @@ #endif #define IDR_NETSURF_ICON 100 +#define IDR_THROBBER_AVI 101 #define IDR_TOOLBAR_BITMAP 102 #define IDR_TOOLBAR_BITMAP_GREY 103 #define IDR_TOOLBAR_BITMAP_HOT 104 #define IDR_NETSURF_BANNER 105 #define IDR_HOME_BITMAP 106 -#define IDR_THROBBER_FRAME0_BITMAP 110 -#define IDR_THROBBER_FRAME1_BITMAP 111 -#define IDR_THROBBER_FRAME2_BITMAP 112 -#define IDR_THROBBER_FRAME3_BITMAP 113 -#define IDR_THROBBER_FRAME4_BITMAP 114 -#define IDR_THROBBER_FRAME5_BITMAP 115 -#define IDR_THROBBER_FRAME6_BITMAP 116 -#define IDR_THROBBER_FRAME7_BITMAP 117 #define IDD_ABOUT 1000 #define IDC_IMG1 1001 diff --git a/frontends/windows/window.c b/frontends/windows/window.c index 3ccf8295e..681b2e282 100644 --- a/frontends/windows/window.c +++ b/frontends/windows/window.c @@ -534,7 +534,6 @@ nsws_window_throbber_create(HINSTANCE hInstance, struct gui_window *gw) { HWND hwnd; - char avi[PATH_MAX]; int urlx, urly, urlwidth, urlheight; urlbar_dimensions(hWndParent, @@ -554,9 +553,8 @@ nsws_window_throbber_create(HINSTANCE hInstance, hInstance, NULL); - nsws_find_resource(avi, "throbber.avi", "windows/res/throbber.avi"); - NSLOG(netsurf, INFO, "setting throbber avi as %s", avi); - Animate_Open(hwnd, avi); + Animate_Open(hwnd, MAKEINTRESOURCE(IDR_THROBBER_AVI)); + if (gw->throbbing) { Animate_Play(hwnd, 0, -1, -1); } else { diff --git a/resources/FatMessages b/resources/FatMessages index 1fbf1302b..243ce6c83 100644 --- a/resources/FatMessages +++ b/resources/FatMessages @@ -2866,6 +2866,7 @@ de.all.Form_Many:(Viele) fr.all.Form_Many:(Plusieurs) it.all.Form_Many:(Molti) nl.all.Form_Many:(Veel) +en.all.Form_Drop:Drop file here en.gtk.Form_Drop:Click to select file fr.gtk.Form_Drop:Cliquer pour sélectionner fichier nl.gtk.Form_Drop:Klik om bestand te selecteren