diff options
Diffstat (limited to 'windows')
-rw-r--r-- | windows/Makefile.target | 5 | ||||
-rw-r--r-- | windows/findfile.c | 48 | ||||
-rw-r--r-- | windows/findfile.h | 6 | ||||
-rw-r--r-- | windows/gui.c | 72 | ||||
-rw-r--r-- | windows/prefs.c | 14 |
5 files changed, 90 insertions, 55 deletions
diff --git a/windows/Makefile.target b/windows/Makefile.target index d81e7d7ea..332d1df09 100644 --- a/windows/Makefile.target +++ b/windows/Makefile.target @@ -33,6 +33,11 @@ CFLAGS += '-D_WIN32_WINNT=0x0501' CFLAGS += '-D_WIN32_WINDOWS=0x0501' CFLAGS += '-D_WIN32_IE=0x0501' + + #installed resource path + CFLAGS += '-DNETSURF_WINDOWS_RESPATH="$(NETSURF_WINDOWS_RESPATH)"' + + WSCFLAGS := -std=c99 \ $(WARNFLAGS) -I. -I${MINGW_INSTALL_ENV}/include/ \ -DCURL_STATICLIB -DLIBXML_STATIC -g diff --git a/windows/findfile.c b/windows/findfile.c index 54fb5f4b4..b7b5bea6d 100644 --- a/windows/findfile.c +++ b/windows/findfile.c @@ -17,6 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <windows.h> #include <limits.h> #include <unistd.h> #include <stdbool.h> @@ -29,9 +30,56 @@ #include "utils/url.h" #include "utils/log.h" #include "utils/utils.h" +#include "utils/filepath.h" #include "windows/findfile.h" +/** Create an array of valid paths to search for resources. + * + * The idea is that all the complex path computation to find resources + * is performed here, once, rather than every time a resource is + * searched for. + */ +char ** +nsws_init_resource(const char *resource_path) +{ + char **pathv; /* resource path string vector */ + char **respath; /* resource paths vector */ + const char *lang = NULL; + char *winpath; + int pathi; + char *slsh; + + pathv = filepath_path_to_strvec(resource_path); + if (pathv == NULL) + return NULL; + + winpath = malloc(MAX_PATH); + GetModuleFileName(NULL, winpath, MAX_PATH); + slsh = strrchr(winpath, '\\'); + if (slsh != NULL) + *slsh=0; + strncat(winpath, "\\windows\\res", MAX_PATH); + + pathi = 0; + while (pathv[pathi] != NULL) + pathi++; + pathv[pathi] = winpath; + + + pathi = 0; + while (pathv[pathi] != NULL) { + LOG(("pathv[%d] = \"%s\"",pathi, pathv[pathi])); + pathi++; + } + + respath = filepath_generate(pathv, &lang); + + filepath_free_strvec(pathv); + + return respath; +} + static char *realpath(const char *path, char *resolved_path) { /* useless, but there we go */ diff --git a/windows/findfile.h b/windows/findfile.h index fcc2da94d..5f8c7290c 100644 --- a/windows/findfile.h +++ b/windows/findfile.h @@ -19,9 +19,9 @@ #ifndef _NETSURF_WINDOWS_FINDFILE_H_ #define _NETSURF_WINDOWS_FINDFILE_H_ -#define NETSURF_WINDOWS_RESPATH "C:" +extern char *nsws_find_resource(char *buf, const char *filename, const char *def); + +char **nsws_init_resource(const char *resource_path); -extern char *nsws_find_resource(char *buf, const char *filename, - const char *def); #endif /* _NETSURF_WINDOWS_FINDFILE_H_ */ diff --git a/windows/gui.c b/windows/gui.c index bcc8fa28d..58c749808 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -47,6 +47,7 @@ #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" +#include "utils/filepath.h" #include "windows/about.h" #include "windows/gui.h" @@ -121,6 +122,8 @@ struct gui_window { static struct nsws_pointers nsws_pointer; +static char **respaths; /** resource search path vector */ + #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif @@ -569,28 +572,6 @@ static void nsws_window_set_accels(struct gui_window *w) } /** - * set window icons - */ -static void nsws_window_set_ico(struct gui_window *w) -{ - char ico[PATH_MAX]; - - nsws_find_resource(ico, "NetSurf32.ico", "windows/res/NetSurf32.ico"); - LOG(("setting ico as %s", ico)); - hIcon = LoadImage(NULL, ico, IMAGE_ICON, 32, 32, LR_LOADFROMFILE); - - if (hIcon != NULL) - SendMessage(w->main, WM_SETICON, ICON_BIG, (LPARAM) hIcon); - nsws_find_resource(ico, "NetSurf16.ico", "windows/res/NetSurf16.ico"); - LOG(("setting ico as %s", ico)); - hIconS = LoadImage(NULL, ico, IMAGE_ICON, 16, 16, LR_LOADFROMFILE); - - if (hIconS != NULL) - SendMessage(w->main, WM_SETICON, ICON_SMALL, (LPARAM)hIconS); -} - - -/** * creation of throbber */ static HWND @@ -1765,7 +1746,6 @@ static HWND nsws_window_create(struct gui_window *gw) } nsws_window_set_accels(gw); - nsws_window_set_ico(gw); return hwnd; } @@ -2561,40 +2541,32 @@ void gui_quit(void) char* gui_get_resource_url(const char *filename) { - return NULL; + char buf[PATH_MAX]; + return path_to_url(filepath_sfind(respaths, buf, filename)); } static void gui_init(int argc, char** argv) { - char buf[PATH_MAX], sbuf[PATH_MAX]; - int len; struct browser_window *bw; const char *addr = NETSURF_HOMEPAGE; LOG(("argc %d, argv %p", argc, argv)); /* set up stylesheet urls */ - getcwd(sbuf, PATH_MAX); - len = strlen(sbuf); - strncat(sbuf, "windows/res/default.css", PATH_MAX - len); - nsws_find_resource(buf, "default.css", sbuf); - default_stylesheet_url = path_to_url(buf); + default_stylesheet_url = strdup("resource:default.css"); LOG(("Using '%s' as Default CSS URL", default_stylesheet_url)); - getcwd(sbuf, PATH_MAX); - len = strlen(sbuf); - strncat(sbuf, "windows/res/quirks.css", PATH_MAX - len); - nsws_find_resource(buf, "quirks.css", sbuf); - quirks_stylesheet_url = path_to_url(buf); - LOG(("Using '%s' as quirks stylesheet url", quirks_stylesheet_url )); + quirks_stylesheet_url = strdup("resource:quirks.css"); + LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url)); + adblock_stylesheet_url = strdup("resource:adblock.css"); + LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url)); create_local_windows_classes(); option_target_blank = false; nsws_window_init_pointers(); - LOG(("argc %d, argv %p", argc, argv)); /* ensure homepage option has a default */ if (option_homepage_url == NULL || option_homepage_url[0] == '\0') @@ -2615,9 +2587,9 @@ void gui_stdout(void) { /* mwindows compile flag normally invalidates stdout unless already redirected */ - if (_get_osfhandle(fileno(stdout)) == -1) { + if (_get_osfhandle(fileno(stderr)) == -1) { AllocConsole(); - freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); } } @@ -2629,8 +2601,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) int argc = 0, argctemp = 0; size_t len; LPWSTR *argvw; - char options[PATH_MAX]; - char messages[PATH_MAX]; + char *messages; + + verbose_log = true; if (SLEN(lpcli) > 0) { argvw = CommandLineToArgvW(GetCommandLineW(), &argc); @@ -2658,15 +2631,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) argctemp++; } - /* load browser messages */ - nsws_find_resource(messages, "messages", "./windows/res/messages"); + respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\res:"NETSURF_WINDOWS_RESPATH); - /* load browser options */ - nsws_find_resource(options, "preferences", "~/.netsurf/preferences"); - options_file_location = strdup(options); + messages = filepath_find(respaths, "messages"); + options_file_location = filepath_find(respaths, "preferences"); + /* initialise netsurf */ - netsurf_init(&argc, &argv, options, messages); + netsurf_init(&argc, &argv, options_file_location, messages); + + free(messages); gui_init(argc, argv); @@ -2674,5 +2648,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) netsurf_exit(); + free(options_file_location); + return 0; } diff --git a/windows/prefs.c b/windows/prefs.c index 3a04a5925..d7cc51afa 100644 --- a/windows/prefs.c +++ b/windows/prefs.c @@ -113,6 +113,8 @@ static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd, char *temp, number[6]; HWND sub; + LOG_WIN_MSG(hwnd, msg, wparam, lParam); + switch (msg) { case WM_INITDIALOG: sub = GetDlgItem(hwnd, IDC_PREFS_FONTDEF); @@ -401,6 +403,8 @@ static BOOL CALLBACK options_connections_dialog_handler(HWND hwnd, char *temp, number[6]; HWND sub; + LOG_WIN_MSG(hwnd, msg, wparam, lParam); + switch (msg) { case WM_INITDIALOG: sub = GetDlgItem(hwnd, IDC_PREFS_PROXYTYPE); @@ -561,6 +565,8 @@ static BOOL CALLBACK options_general_dialog_handler(HWND hwnd, { HWND sub; + LOG_WIN_MSG(hwnd, msg, wparam, lParam); + switch (msg) { case WM_INITDIALOG: /* homepage url */ @@ -629,7 +635,7 @@ void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent) PROPSHEETHEADER psh; psp[0].dwSize = sizeof(PROPSHEETPAGE); - psp[0].dwFlags = PSP_USEICONID; + psp[0].dwFlags = 0;/*PSP_USEICONID*/ psp[0].hInstance = hinst; psp[0].pszTemplate = MAKEINTRESOURCE(IDD_DLG_OPTIONS_GENERAL); psp[0].pfnDlgProc = options_general_dialog_handler; @@ -637,7 +643,7 @@ void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent) psp[0].pfnCallback = NULL; psp[1].dwSize = sizeof(PROPSHEETPAGE); - psp[1].dwFlags = PSP_USEICONID; + psp[1].dwFlags = 0;/*PSP_USEICONID*/ psp[1].hInstance = hinst; psp[1].pszTemplate = MAKEINTRESOURCE(IDD_DLG_OPTIONS_CONNECTIONS); psp[1].pfnDlgProc = options_connections_dialog_handler; @@ -645,7 +651,7 @@ void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent) psp[1].pfnCallback = NULL; psp[2].dwSize = sizeof(PROPSHEETPAGE); - psp[2].dwFlags = PSP_USEICONID; + psp[2].dwFlags = 0;/*PSP_USEICONID*/ psp[2].hInstance = hinst; psp[2].pszTemplate = MAKEINTRESOURCE(IDD_DLG_OPTIONS_APPERANCE); psp[2].pfnDlgProc = options_appearance_dialog_handler; @@ -657,7 +663,7 @@ void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent) psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID | PSH_PROPSHEETPAGE; psh.hwndParent = parent; psh.hInstance = hinst; -// psh.pszIcon = MAKEINTRESOURCE(IDI_CELL_PROPERTIES); + psh.pszIcon = MAKEINTRESOURCE(IDR_NETSURF_ICON); psh.pszCaption = (LPSTR) "NetSurf Options"; psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE); psh.nStartPage = 0; |