make windows frontend use

svn path=/trunk/netsurf/; revision=12146
This commit is contained in:
Vincent Sanders 2011-03-29 20:38:40 +00:00
parent 27ce150648
commit 402aaeb368
6 changed files with 135 additions and 82 deletions

View File

@ -33,6 +33,7 @@
#include "utils/config.h"
#include "utils/filepath.h"
#include "utils/log.h"
/** maximum number of elements in the resource vector */
#define MAX_RESPATH 128
@ -116,8 +117,11 @@ char *filepath_sfind(char **respathv, char *filepath, const char *filename)
return NULL;
while (respathv[respathc] != NULL) {
if (filepath_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL)
if (filepath_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL) {
LOG(("ret\"%s\"",filepath));
return filepath;
}
respathc++;
}
@ -143,6 +147,8 @@ char *filepath_find(char **respathv, const char *filename)
if (ret == NULL)
free(filepath);
LOG(("ret\"%s\"",ret));
return ret;
}
@ -211,9 +217,9 @@ filepath_generate(char * const *pathv, const char * const *langv)
/* expand ${} in a string into environment variables */
static char *
expand_path(const char *path)
expand_path(const char *path, int pathlen)
{
char *exp = strdup(path);
char *exp;
int explen;
int cstart = -1;
int cloop = 0;
@ -221,10 +227,14 @@ expand_path(const char *path)
int envlen;
int replen; /* length of replacement */
exp = malloc(pathlen + 1);
if (exp == NULL)
return NULL;
explen = strlen(exp) + 1;
memcpy(exp, path, pathlen);
exp[pathlen] = 0;
explen = strlen(exp);
while (exp[cloop] != 0) {
if ((exp[cloop] == '$') &&
@ -241,14 +251,14 @@ expand_path(const char *path)
if (envv == NULL) {
memmove(exp + cstart,
exp + cloop + 1,
explen - cloop - 1);
explen - cloop);
explen -= replen;
} else {
envlen = strlen(envv);
exp = realloc(exp, explen + envlen - replen);
memmove(exp + cstart + envlen,
exp + cloop + 1,
explen - cloop - 1);
explen - cloop );
memmove(exp + cstart, envv, envlen);
explen += envlen - replen;
}
@ -259,6 +269,11 @@ expand_path(const char *path)
cloop++;
}
if (explen == 1) {
free(exp);
exp = NULL;
}
return exp;
}
@ -268,37 +283,40 @@ filepath_path_to_strvec(const char *path)
{
char **strvec;
int strc = 0;
const char *estart; /* path element start */
const char *eend; /* path element end */
int elen;
strvec = calloc(MAX_RESPATH, sizeof(char *));
if (strvec == NULL)
return NULL;
strvec[strc] = expand_path(path);
if (strvec[strc] == NULL) {
free(strvec);
return NULL;
}
strc++;
estart = eend = path;
strvec[strc] = strchr(strvec[0], ':');
while ((strc < (MAX_RESPATH - 2)) &&
(strvec[strc] != NULL)) {
/* null terminate previous entry */
*strvec[strc] = 0;
strvec[strc]++;
while (strc < (MAX_RESPATH - 2)) {
while ( (*eend != 0) && (*eend != ':') )
eend++;
elen = eend - estart;
if (elen > 1) {
/* more than an empty colon */
strvec[strc] = expand_path(estart, elen);
if (strvec[strc] != NULL) {
/* successfully expanded an element */
strc++;
}
}
/* skip colons */
while (*strvec[strc] == ':')
strvec[strc]++;
while (*eend == ':')
eend++;
if (*strvec[strc] == 0)
break; /* string is terminated */
strc++;
strvec[strc] = strchr(strvec[strc - 1], ':');
/* check for termination */
if (*eend == 0)
break;
estart = eend;
}
return strvec;
}

View File

@ -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

View File

@ -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 */

View File

@ -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_ */

View File

@ -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
@ -568,28 +571,6 @@ static void nsws_window_set_accels(struct gui_window *w)
w->acceltable = CreateAcceleratorTable(accels, nitems);
}
/**
* 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
*/
@ -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;
}

View File

@ -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;