diff options
Diffstat (limited to 'frontends/windows')
39 files changed, 1021 insertions, 1464 deletions
diff --git a/frontends/windows/Makefile b/frontends/windows/Makefile index d22e17112..524f716fe 100644 --- a/frontends/windows/Makefile +++ b/frontends/windows/Makefile @@ -52,10 +52,10 @@ 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 \ +S_FRONTEND := main.c window.c gui.c clipboard.c drawable.c plot.c findfile.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 + local_history.c schedule.c windbg.c pointers.c \ + corewindow.c hotlist.c cookies.c global_history.c # This is the final source build list # Note this is deliberately *not* expanded here as common and image @@ -86,12 +86,11 @@ NSIS_VERBOSE := 0 endif # installer messages generation -$(OBJROOT)/messages-en: resources/FatMessages - $(VQ)echo "MSGSPLIT: Language: en Filter: win" - $(Q)$(RM) $@ - $(Q)$(SPLIT_MESSAGES) -l en -p win -f messages -o $@ $< +$(OBJROOT)/messages-en: $(MESSAGES_TARGET)/en/Messages + $(VQ)echo " MSGCP: $< $@" + $(Q)$(INSTALL) -m 644 -T $< $@ -netsurf-installer.exe: $(EXETARGET) $(WIN_RES_INS_OBJ) +netsurf-installer.exe: $(EXETARGET) $(POSTEXES) $(WIN_RES_INS_OBJ) $(VQ)echo "MAKENSIS: $@" $(Q)makensis -V$(NSIS_VERBOSE) -NOCD -DOBJROOT=$(OBJROOT) -DRESDIR=$(FRONTEND_RESOURCES_DIR) -DVERSIONMAJOR=$(VERSION_MAJ) -DVERSIONMINOR=$(VERSION_MIN) -DOUTFNAME=$@ $(FRONTEND_RESOURCES_DIR)/installer.nsi diff --git a/frontends/windows/Makefile.defaults b/frontends/windows/Makefile.defaults index 1d844f112..51e71accb 100644 --- a/frontends/windows/Makefile.defaults +++ b/frontends/windows/Makefile.defaults @@ -3,8 +3,8 @@ # ---------------------------------------------------------------------------- # Where to search for NetSurf's resources after looking in ~/.netsurf and -# $NETSURFRES. It must have a trailing backslash -NETSURF_WINDOWS_RESPATH := +# ${APPDATA}\NetSurf. It must have a trailing backslash +NETSURF_WINDOWS_RESPATH := $${NETSURFRES} # Enable NetSurf's use of librosprite for displaying RISC OS Sprites # Valid options: YES, NO, AUTO diff --git a/frontends/windows/Makefile.tools b/frontends/windows/Makefile.tools new file mode 100644 index 000000000..24f0f7fbd --- /dev/null +++ b/frontends/windows/Makefile.tools @@ -0,0 +1,19 @@ +# -*- mode: makefile-gmake -*- +## +## windows (win32) target tool setup +## + +ifneq ($(HOST),windows) + # Set Mingw defaults + GCCSDK_INSTALL_ENV ?= /opt/netsurf/i686-w64-mingw32/env + GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/i686-w64-mingw32/cross/bin + + CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc) + WINDRES := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*windres) + + PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config +else + # Building on Windows + CC := gcc + PKG_CONFIG := pkg-config +endif diff --git a/frontends/windows/bitmap.c b/frontends/windows/bitmap.c index eed3d3a15..a52f29ad9 100644 --- a/frontends/windows/bitmap.c +++ b/frontends/windows/bitmap.c @@ -41,19 +41,19 @@ * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param state flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *win32_bitmap_create(int width, int height, unsigned int state) +static void *win32_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; BITMAPV5HEADER *pbmi; HBITMAP windib; uint8_t *pixdata; - NSLOG(netsurf, INFO, "width %d, height %d, state %u", width, height, - state); + NSLOG(netsurf, INFO, "width %d, height %d, flags %u", width, height, + (unsigned)flags); pbmi = calloc(1, sizeof(BITMAPV5HEADER)); if (pbmi == NULL) { @@ -91,7 +91,7 @@ void *win32_bitmap_create(int width, int height, unsigned int state) bitmap->windib = windib; bitmap->pbmi = pbmi; bitmap->pixdata = pixdata; - if ((state & BITMAP_OPAQUE) != 0) { + if ((flags & BITMAP_OPAQUE) != 0) { bitmap->opaque = true; } else { bitmap->opaque = false; @@ -164,20 +164,6 @@ void win32_bitmap_destroy(void *bitmap) /** - * Save a bitmap in the platform's native format. - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \param path pathname for file - * \param flags flags controlling how the bitmap is saved. - * \return true on success, false on error and error reported - */ -static bool bitmap_save(void *bitmap, const char *path, unsigned flags) -{ - return true; -} - - -/** * The bitmap image has changed, so flush any persistant cache. * * \param bitmap a bitmap, as returned by bitmap_create() @@ -207,35 +193,6 @@ static void bitmap_set_opaque(void *bitmap, bool opaque) /** - * Tests whether a bitmap has an opaque alpha channel - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \return whether the bitmap is opaque - */ -static bool bitmap_test_opaque(void *bitmap) -{ - int tst; - struct bitmap *bm = bitmap; - - if (bitmap == NULL) { - NSLOG(netsurf, INFO, "NULL bitmap!"); - return false; - } - - tst = bm->width * bm->height; - - while (tst-- > 0) { - if (bm->pixdata[(tst << 2) + 3] != 0xff) { - NSLOG(netsurf, INFO, "bitmap %p has transparency", bm); - return false; - } - } - NSLOG(netsurf, INFO, "bitmap %p is opaque", bm); - return true; -} - - -/** * Gets whether a bitmap should be plotted opaque * * \param bitmap a bitmap, as returned by bitmap_create() @@ -276,11 +233,6 @@ static int bitmap_get_height(void *bitmap) return(bm->height); } -static size_t bitmap_get_bpp(void *bitmap) -{ - return 4; -} - struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height) { struct bitmap *ret = malloc(sizeof(struct bitmap)); @@ -346,7 +298,7 @@ bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content) } /* create a full size bitmap and plot into it */ - fsbitmap = win32_bitmap_create(width, height, BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE); + fsbitmap = win32_bitmap_create(width, height, BITMAP_CLEAR | BITMAP_OPAQUE); SelectObject(bufferdc, fsbitmap->windib); @@ -375,13 +327,10 @@ static struct gui_bitmap_table bitmap_table = { .destroy = win32_bitmap_destroy, .set_opaque = bitmap_set_opaque, .get_opaque = bitmap_get_opaque, - .test_opaque = bitmap_test_opaque, .get_buffer = bitmap_get_buffer, .get_rowstride = bitmap_get_rowstride, .get_width = bitmap_get_width, .get_height = bitmap_get_height, - .get_bpp = bitmap_get_bpp, - .save = bitmap_save, .modified = bitmap_modified, .render = bitmap_render, }; diff --git a/frontends/windows/bitmap.h b/frontends/windows/bitmap.h index c723159e1..a370dd619 100644 --- a/frontends/windows/bitmap.h +++ b/frontends/windows/bitmap.h @@ -20,7 +20,7 @@ #ifndef _NETSURF_WINDOWS_BITMAP_H_ #define _NETSURF_WINDOWS_BITMAP_H_ -struct gui_bitmap_table *win32_bitmap_table; +extern struct gui_bitmap_table *win32_bitmap_table; struct bitmap { HBITMAP windib; @@ -33,8 +33,6 @@ struct bitmap { struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height); -void *win32_bitmap_create(int width, int height, unsigned int state); - void win32_bitmap_destroy(void *bitmap); #endif diff --git a/frontends/windows/clipboard.c b/frontends/windows/clipboard.c new file mode 100644 index 000000000..bc52a4594 --- /dev/null +++ b/frontends/windows/clipboard.c @@ -0,0 +1,131 @@ +/* + * Copyright 2019 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file + * win32 clipboard implementation. + */ + +#include <windows.h> + +#include "utils/log.h" +#include "netsurf/clipboard.h" + +#include "windows/clipboard.h" + +/** + * Core asks front end for clipboard contents. + * + * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core + * \param length Byte length of UTF-8 text in buffer + */ +static void gui_get_clipboard(char **buffer, size_t *length) +{ + HANDLE clipboard_handle; + wchar_t *content; + + if (OpenClipboard(NULL)) { + clipboard_handle = GetClipboardData(CF_UNICODETEXT); + if (clipboard_handle != NULL) { + content = GlobalLock(clipboard_handle); + if (content != NULL) { + int required_len; + size_t content_len; + + content_len = wcslen(content); + + /* compute length */ + required_len = WideCharToMultiByte( + CP_UTF8, + WC_NO_BEST_FIT_CHARS, + content, + content_len, + NULL, + 0, + NULL, + NULL); + /* allocate buffer and do conversion */ + *buffer = malloc(required_len); + *length = WideCharToMultiByte( + CP_UTF8, + WC_NO_BEST_FIT_CHARS, + content, + content_len, + *buffer, + required_len, + NULL, + NULL); + + GlobalUnlock(clipboard_handle); + } + } + CloseClipboard(); + } +} + + +/** + * Core tells front end to put given text in clipboard + * + * \param buffer UTF-8 text, owned by core + * \param length Byte length of UTF-8 text in buffer + * \param styles Array of styles given to text runs, owned by core, or NULL + * \param n_styles Number of text run styles in array + */ +static void +gui_set_clipboard(const char *buffer, + size_t length, + nsclipboard_styles styles[], + int n_styles) +{ + HGLOBAL hglbCopy; + wchar_t *content; /* clipboard content */ + int content_len; /* characters in content */ + + if (OpenClipboard(NULL)) { + EmptyClipboard(); + content_len = MultiByteToWideChar(CP_UTF8, + MB_PRECOMPOSED, + buffer, length, + NULL, 0); + + hglbCopy = GlobalAlloc(GMEM_MOVEABLE, + ((content_len + 1) * sizeof(wchar_t))); + if (hglbCopy != NULL) { + content = GlobalLock(hglbCopy); + MultiByteToWideChar(CP_UTF8, + MB_PRECOMPOSED, + buffer, length, + content, content_len); + content[content_len] = 0; /* null terminate */ + + GlobalUnlock(hglbCopy); + SetClipboardData(CF_UNICODETEXT, hglbCopy); + } + CloseClipboard(); + } +} + + + +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; diff --git a/frontends/windows/login.h b/frontends/windows/clipboard.h index 411306230..92f096b8e 100644 --- a/frontends/windows/login.h +++ b/frontends/windows/clipboard.h @@ -1,5 +1,5 @@ /* - * Copyright 2018 Vincent Sanders <vince@netsurf-browser.org> + * Copyright 2019 Vincent Sanders <vince@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -16,24 +16,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** - * \file - * Basic authentication login interfaces. - */ - -#ifndef NSW32_LOGIN_H -#define NSW32_LOGIN_H +#ifndef NETSURF_WINDOWS_CLIPBOARD_H +#define NETSURF_WINDOWS_CLIPBOARD_H /** - * login window request. + * The clipboard operation function table for win32 */ -extern nserror nsw32_401login(nsurl *url, - const char *realm, - const char *username, - const char *password, - nserror (*cb)(const char *username, - const char *password, - void *cbctx), - void *cbctx); +extern struct gui_clipboard_table *win32_clipboard_table; #endif diff --git a/frontends/windows/cookies.c b/frontends/windows/cookies.c index b3c56da8c..e83e83c10 100644 --- a/frontends/windows/cookies.c +++ b/frontends/windows/cookies.c @@ -34,6 +34,7 @@ #include "windows/plot.h" #include "windows/corewindow.h" #include "windows/cookies.h" +#include "windows/gui.h" struct nsw32_cookie_window { @@ -153,8 +154,7 @@ static nserror nsw32_cookie_init(HINSTANCE hInstance) return res; } - res = cookie_manager_init(ncwin->core.cb_table, - (struct core_window *)ncwin); + res = cookie_manager_init((struct core_window *)ncwin); if (res != NSERROR_OK) { free(ncwin); return res; @@ -170,13 +170,16 @@ static nserror nsw32_cookie_init(HINSTANCE hInstance) /* exported interface documented in windows/cookie.h */ -nserror nsw32_cookies_present(HINSTANCE hInstance) +nserror nsw32_cookies_present(const char *search_term) { nserror res; - res = nsw32_cookie_init(hInstance); + res = nsw32_cookie_init(hinst); if (res == NSERROR_OK) { ShowWindow(cookie_window->core.hWnd, SW_SHOWNORMAL); + if (search_term != NULL) { + res = cookie_manager_set_search_string(search_term); + } } return res; } diff --git a/frontends/windows/cookies.h b/frontends/windows/cookies.h index 8500c7821..dd7ae4279 100644 --- a/frontends/windows/cookies.h +++ b/frontends/windows/cookies.h @@ -35,7 +35,7 @@ * * \return NSERROR_OK on success else appropriate error code on faliure. */ -nserror nsw32_cookies_present(HINSTANCE hinstance); +nserror nsw32_cookies_present(const char *search_term); /** * Free any resources allocated for the cookie window. diff --git a/frontends/windows/corewindow.c b/frontends/windows/corewindow.c index 7d88ce7c4..c7e241d21 100644 --- a/frontends/windows/corewindow.c +++ b/frontends/windows/corewindow.c @@ -443,7 +443,7 @@ nsw32_cw_invalidate_area(struct core_window *cw, const struct rect *rect) /** * Callback from the core to update the content area size */ -static void +static nserror nsw32_cw_update_size(struct core_window *cw, int width, int height) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; @@ -453,13 +453,23 @@ nsw32_cw_update_size(struct core_window *cw, int width, int height) NSLOG(netsurf, INFO, "new content size w:%d h:%d", width, height); update_scrollbars(nsw32_cw); + return NSERROR_OK; } -static void -nsw32_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +nsw32_cw_set_scroll(struct core_window *cw, int x, int y) { /** /todo call setscroll apropriately */ + return NSERROR_OK; +} + + +static nserror +nsw32_cw_get_scroll(const struct core_window *cw, int *x, int *y) +{ + /** /todo call getscroll apropriately */ + return NSERROR_NOT_IMPLEMENTED; } @@ -470,8 +480,9 @@ nsw32_cw_scroll_visible(struct core_window *cw, const struct rect *r) * \param[out] width to be set to viewport width in px * \param[out] height to be set to viewport height in px */ -static void -nsw32_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) +static nserror +nsw32_cw_get_window_dimensions(const struct core_window *cw, + int *width, int *height) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; @@ -479,25 +490,30 @@ nsw32_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) GetClientRect(nsw32_cw->hWnd, &rc); *width = rc.right; *height = rc.bottom; + return NSERROR_OK; } -static void +static nserror nsw32_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; nsw32_cw->drag_status = ds; + return NSERROR_OK; } -struct core_window_callback_table nsw32_cw_cb_table = { +struct core_window_table nsw32_cw_cb_table = { .invalidate = nsw32_cw_invalidate_area, - .update_size = nsw32_cw_update_size, - .scroll_visible = nsw32_cw_scroll_visible, - .get_window_dimensions = nsw32_cw_get_window_dimensions, + .set_extent = nsw32_cw_update_size, + .set_scroll = nsw32_cw_set_scroll, + .get_scroll = nsw32_cw_get_scroll, + .get_dimensions = nsw32_cw_get_window_dimensions, .drag_status = nsw32_cw_drag_status }; +struct core_window_table *win32_core_window_table = &nsw32_cw_cb_table; + /* exported function documented nsw32/corewindow.h */ nserror nsw32_corewindow_init(HINSTANCE hInstance, @@ -507,7 +523,6 @@ nsw32_corewindow_init(HINSTANCE hInstance, DWORD dwStyle; /* setup the core window callback table */ - nsw32_cw->cb_table = &nsw32_cw_cb_table; nsw32_cw->drag_status = CORE_WINDOW_DRAG_NONE; /* start with the content area being as small as possible */ diff --git a/frontends/windows/corewindow.h b/frontends/windows/corewindow.h index cffae3cbd..53f47fd89 100644 --- a/frontends/windows/corewindow.h +++ b/frontends/windows/corewindow.h @@ -21,6 +21,8 @@ #include "netsurf/core_window.h" +extern struct core_window_table *win32_core_window_table; + /** * nsw32 core window state */ @@ -39,9 +41,6 @@ struct nsw32_corewindow { /** drag status set by core */ core_window_drag_status drag_status; - - /** table of callbacks for core window operations */ - struct core_window_callback_table *cb_table; /** * callback to draw on drawable area of nsw32 core window diff --git a/frontends/windows/download.c b/frontends/windows/download.c index f0163cef7..cfd2bbbb7 100644 --- a/frontends/windows/download.c +++ b/frontends/windows/download.c @@ -169,6 +169,7 @@ nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDOK: if (download1->downloaded != download1->size) return TRUE; + fallthrough; case IDCANCEL: nsws_download_clear_data(download1); diff --git a/frontends/windows/drawable.c b/frontends/windows/drawable.c index f491e0a2a..84b11ed78 100644 --- a/frontends/windows/drawable.c +++ b/frontends/windows/drawable.c @@ -41,7 +41,7 @@ #include "windows/local_history.h" #include "windows/drawable.h" -static const char windowclassname_drawable[] = "nswsdrawablewindow"; +static const wchar_t *windowclassname_drawable = L"nswsdrawablewindow"; /** @@ -223,19 +223,71 @@ nsws_drawable_resize(struct gui_window *gw) return 0; } +/** + * Handle unicode character messages. + */ +static LRESULT +nsws_drawable_unichar(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ + uint32_t nskey; + + if (wparam == UNICODE_NOCHAR) { + return 1; + } + + nskey = wparam; + browser_window_key_press(gw->bw, nskey); + return 0; +} /** - * Handle key press messages. + * Handle character messages. + * + * WM_CHAR is generated when WM_KEYDOWN message are passed to + * TranslateMessage; wParam is UTF-16. If the codepoint is 4 + * bytes, there are 2 WM_CHAR message, one with the high + * surrogate and one with the low surrogate. */ static LRESULT -nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam) +nsws_drawable_char(struct gui_window *gw, HWND hwnd, WPARAM wparam) { - if (GetFocus() != hwnd) - return 0 ; + uint32_t nskey; + + nskey = wparam; + + const uint32_t utf16_hi_surrogate_start = 0xD800; + const uint32_t utf16_lo_surrogate_start = 0xDC00; + const uint32_t utf16_surrogate_end = 0xDFFF; + static uint32_t highSurrogate = 0; + + if ((nskey >= utf16_hi_surrogate_start) && + (nskey < utf16_lo_surrogate_start) ) { + highSurrogate = nskey; + } else { + if ((nskey >= utf16_lo_surrogate_start) && + (nskey <= utf16_surrogate_end)) { + uint32_t lowSurrogate = nskey; + nskey = (highSurrogate - utf16_hi_surrogate_start) << 10; + nskey |= ( lowSurrogate - utf16_lo_surrogate_start ); + nskey += 0x10000; + } + highSurrogate = 0; + + browser_window_key_press(gw->bw, nskey); + } + + return 0; +} + +/** + * Handle keydown messages. + */ +static LRESULT +nsws_drawable_keydown(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ uint32_t i; bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); - bool capslock = ((GetKeyState(VK_CAPITAL) & 1) == 1); switch(wparam) { case VK_LEFT: @@ -285,30 +337,18 @@ nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam) break; case VK_NEXT: - i = wparam; - SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), - 0); - break; + SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0); + return 1; case VK_PRIOR: - i = wparam; - SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), - 0); - break; + SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), 0); + return 1; default: - i = wparam; - break; + return 1; } - if ((i >= 'A') && - (i <= 'Z') && - (((!capslock) && (!shift)) || ((capslock) && (shift)))) { - i += 'a' - 'A'; - } - - if (gw != NULL) - browser_window_key_press(gw->bw, i); + browser_window_key_press(gw->bw, i); return 0; } @@ -338,10 +378,15 @@ nsws_drawable_paint(struct gui_window *gw, HWND hwnd) clip.x1 = ps.rcPaint.right; clip.y1 = ps.rcPaint.bottom; + /** + * \todo work out why the heck scroll needs scaling + */ + browser_window_redraw(gw->bw, - -gw->scrollx / gw->scale, - -gw->scrolly / gw->scale, - &clip, &ctx); + -gw->scrollx, + -gw->scrolly, + &clip, + &ctx); } EndPaint(hwnd, &ps); @@ -385,19 +430,21 @@ nsws_drawable_mouseup(struct gui_window *gw, if ((gw->mouse->state & click) != 0) { NSLOG(netsurf, INFO, - "mouse click bw %p, state 0x%x, x %f, y %f", gw->bw, - gw->mouse->state, (x + gw->scrollx) / gw->scale, - (y + gw->scrolly) / gw->scale); + "mouse click bw %p, state 0x%x, x %d, y %d", + gw->bw, + gw->mouse->state, + x + gw->scrollx, + y + gw->scrolly); browser_window_mouse_click(gw->bw, gw->mouse->state, - (x + gw->scrollx) / gw->scale, - (y + gw->scrolly) / gw->scale); + x + gw->scrollx, + y + gw->scrolly); } else { browser_window_mouse_track(gw->bw, 0, - (x + gw->scrollx) / gw->scale, - (y + gw->scrolly) / gw->scale); + x + gw->scrollx, + y + gw->scrolly); } gw->mouse->state = 0; @@ -428,16 +475,19 @@ nsws_drawable_mousedown(struct gui_window *gw, if ((GetKeyState(VK_MENU) & 0x8000) == 0x8000) gw->mouse->state |= BROWSER_MOUSE_MOD_3; - gw->mouse->pressed_x = (x + gw->scrollx) / gw->scale; - gw->mouse->pressed_y = (y + gw->scrolly) / gw->scale; + gw->mouse->pressed_x = x + gw->scrollx; + gw->mouse->pressed_y = y + gw->scrolly; - NSLOG(netsurf, INFO, "mouse click bw %p, state %x, x %f, y %f", - gw->bw, gw->mouse->state, (x + gw->scrollx) / gw->scale, - (y + gw->scrolly) / gw->scale); + NSLOG(netsurf, INFO, "mouse click bw %p, state %x, x %d, y %d", + gw->bw, + gw->mouse->state, + x + gw->scrollx, + y + gw->scrolly); - browser_window_mouse_click(gw->bw, gw->mouse->state, - (x + gw->scrollx) / gw->scale, - (y + gw->scrolly) / gw->scale); + browser_window_mouse_click(gw->bw, + gw->mouse->state, + x + gw->scrollx, + y + gw->scrolly); return 0; } @@ -456,9 +506,9 @@ nsws_drawable_mousemove(struct gui_window *gw, int x, int y) if ((gw == NULL) || (gw->mouse == NULL) || (gw->bw == NULL)) return 0; - /* scale co-ordinates */ - x = (x + gw->scrollx) / gw->scale; - y = (y + gw->scrolly) / gw->scale; + /* add scroll offsets */ + x = x + gw->scrollx; + y = y + gw->scrolly; /* if mouse button held down and pointer moved more than * minimum distance drag is happening */ @@ -544,7 +594,6 @@ nsws_window_drawable_event_callback(HWND hwnd, BROWSER_MOUSE_PRESS_2); SetFocus(hwnd); return 0; - break; case WM_LBUTTONUP: return nsws_drawable_mouseup(gw, @@ -567,7 +616,16 @@ nsws_window_drawable_event_callback(HWND hwnd, return nsws_drawable_paint(gw, hwnd); case WM_KEYDOWN: - return nsws_drawable_key(gw, hwnd, wparam); + if (nsws_drawable_keydown(gw, hwnd, wparam) == 0) { + return 0; + } + break; + + case WM_CHAR: + return nsws_drawable_char(gw, hwnd, wparam); + + case WM_UNICHAR: + return nsws_drawable_unichar(gw, hwnd, wparam); case WM_SIZE: return nsws_drawable_resize(gw); @@ -581,6 +639,29 @@ nsws_window_drawable_event_callback(HWND hwnd, case WM_MOUSEWHEEL: return nsws_drawable_wheel(gw, hwnd, wparam); + case WM_PASTE: + browser_window_key_press(gw->bw, NS_KEY_PASTE); + return 0; + + case WM_COPY: + browser_window_key_press(gw->bw, NS_KEY_COPY_SELECTION); + return 0; + + case WM_CUT: + browser_window_key_press(gw->bw, NS_KEY_CUT_SELECTION); + return 0; + + case WM_CLEAR: + /** + * \todo win32 clear operation deletes the contents of + * the selection but ns clear selection only + * removes the highlight. + */ + browser_window_key_press(gw->bw, NS_KEY_CLEAR_SELECTION); + return 0; + + + } return DefWindowProc(hwnd, msg, wparam, lparam); } @@ -595,14 +676,16 @@ nsws_window_create_drawable(HINSTANCE hinstance, struct gui_window *gw) { HWND hwnd; - hwnd = CreateWindow(windowclassname_drawable, - NULL, - WS_VISIBLE | WS_CHILD, - 0, 0, 0, 0, - hparent, - NULL, - hinstance, - NULL); + hwnd = CreateWindowExW(0, + windowclassname_drawable, + NULL, + WS_VISIBLE | WS_CHILD, + 0, 0, + 0, 0, + hparent, + NULL, + hinstance, + NULL); if (hwnd == NULL) { win_perror("WindowCreateDrawable"); @@ -623,7 +706,7 @@ nsws_window_create_drawable(HINSTANCE hinstance, nserror nsws_create_drawable_class(HINSTANCE hinstance) { nserror ret = NSERROR_OK; - WNDCLASSEX w; + WNDCLASSEXW w; /* drawable area */ w.cbSize = sizeof(WNDCLASSEX); @@ -639,7 +722,7 @@ nsws_create_drawable_class(HINSTANCE hinstance) { w.lpszClassName = windowclassname_drawable; w.hIconSm = NULL; - if (RegisterClassEx(&w) == 0) { + if (RegisterClassExW(&w) == 0) { win_perror("DrawableClass"); ret = NSERROR_INIT_FAILED; } diff --git a/frontends/windows/fetch.c b/frontends/windows/fetch.c index f69d7ad19..287f20f6c 100644 --- a/frontends/windows/fetch.c +++ b/frontends/windows/fetch.c @@ -79,7 +79,7 @@ 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); + netsurf_path_to_nsurl(filepath_sfind(G_resource_pathv, buf, path), &url); return url; } diff --git a/frontends/windows/fetch.h b/frontends/windows/fetch.h index 20984f14a..e85402ac3 100644 --- a/frontends/windows/fetch.h +++ b/frontends/windows/fetch.h @@ -22,7 +22,7 @@ /** * win32 API fetch operation table */ -struct gui_fetch_table *win32_fetch_table; +extern struct gui_fetch_table *win32_fetch_table; /** * Translate resource to win32 resource data. diff --git a/frontends/windows/file.h b/frontends/windows/file.h index 5262dde2c..19dfba3b1 100644 --- a/frontends/windows/file.h +++ b/frontends/windows/file.h @@ -24,6 +24,6 @@ #ifndef _NETSURF_WINDOWS_FILE_H_ #define _NETSURF_WINDOWS_FILE_H_ -struct gui_file_table *win32_file_table; +extern struct gui_file_table *win32_file_table; #endif diff --git a/frontends/windows/font.c b/frontends/windows/font.c index 7389bd8c1..3e81a80a1 100644 --- a/frontends/windows/font.c +++ b/frontends/windows/font.c @@ -93,23 +93,31 @@ HFONT get_font(const plot_font_style_t *style) { char *face = NULL; DWORD family; + int nHeight; + HDC hdc; + HFONT font; + switch(style->family) { case PLOT_FONT_FAMILY_SERIF: face = strdup(nsoption_charp(font_serif)); family = FF_ROMAN | DEFAULT_PITCH; break; + case PLOT_FONT_FAMILY_MONOSPACE: face = strdup(nsoption_charp(font_mono)); family = FF_MODERN | DEFAULT_PITCH; break; + case PLOT_FONT_FAMILY_CURSIVE: face = strdup(nsoption_charp(font_cursive)); family = FF_SCRIPT | DEFAULT_PITCH; break; + case PLOT_FONT_FAMILY_FANTASY: face = strdup(nsoption_charp(font_fantasy)); family = FF_DECORATIVE | DEFAULT_PITCH; break; + case PLOT_FONT_FAMILY_SANS_SERIF: default: face = strdup(nsoption_charp(font_sans)); @@ -117,30 +125,30 @@ HFONT get_font(const plot_font_style_t *style) break; } - int nHeight = -10; + nHeight = -10; - HDC hdc = GetDC(font_hwnd); + hdc = GetDC(font_hwnd); nHeight = -MulDiv(style->size, GetDeviceCaps(hdc, LOGPIXELSY), 72 * PLOT_STYLE_SCALE); ReleaseDC(font_hwnd, hdc); - HFONT font = CreateFont( - nHeight, /* height */ - 0, /* width */ - 0, /* escapement*/ - 0, /* orientation */ - style->weight, - (style->flags & FONTF_ITALIC) ? TRUE : FALSE, - FALSE, /* underline */ - FALSE, /* strike */ - DEFAULT_CHARSET, /* for locale */ - OUT_DEFAULT_PRECIS, /* general 'best match' */ - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - family, - face /* name of font face */ - ); - if (face != NULL) + font = CreateFont(nHeight, /* height */ + 0, /* width */ + 0, /* escapement*/ + 0, /* orientation */ + style->weight, + (style->flags & FONTF_ITALIC) ? TRUE : FALSE, + FALSE, /* underline */ + FALSE, /* strike */ + DEFAULT_CHARSET, /* for locale */ + OUT_DEFAULT_PRECIS, /* general 'best match' */ + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + family, + face); /* name of font face */ + + if (face != NULL) { free(face); + } if (font == NULL) { if (style->family == PLOT_FONT_FAMILY_MONOSPACE) { @@ -149,50 +157,67 @@ HFONT get_font(const plot_font_style_t *style) font = (HFONT) GetStockObject(ANSI_VAR_FONT); } } - if (font == NULL) + + if (font == NULL) { font = (HFONT) GetStockObject(SYSTEM_FONT); + } + return font; } +/* size of temporary wide character string for computing string width */ +#define WSTRLEN 4096 + /** * Measure the width of a string. * * \param[in] style plot style for this text - * \param[in] string UTF-8 string to measure - * \param[in] length length of string, in bytes + * \param[in] utf8str string encoded in UTF-8 to measure + * \param[in] utf8len length of string, in bytes * \param[out] width updated to width of string[0..length) * \return NSERROR_OK on success otherwise appropriate error code */ static nserror win32_font_width(const plot_font_style_t *style, - const char *string, - size_t length, + const char *utf8str, + size_t utf8len, int *width) { + nserror ret = NSERROR_OK; HDC hdc; HFONT font; HFONT fontbak; - SIZE s; - nserror ret = NSERROR_OK; + SIZE sizl; /* size in logical units */ + BOOL wres; + int wclen; /* wide char length */ + static WCHAR wstr[WSTRLEN]; /* temporary wide char string */ - if (length == 0) { + if (utf8len == 0) { *width = 0; - } else { - hdc = GetDC(NULL); - font = get_font(style); - fontbak = SelectObject(hdc, font); + return ret; + } - /* may well need to convert utf-8 to lpctstr */ - if (GetTextExtentPoint32A(hdc, string, length, &s) != 0) { - *width = s.cx; + hdc = GetDC(NULL); + font = get_font(style); + fontbak = SelectObject(hdc, font); + + wclen = MultiByteToWideChar(CP_UTF8, 0, utf8str, utf8len, wstr, WSTRLEN); + if (wclen != 0) { + wres = GetTextExtentPoint32W(hdc, wstr, wclen, &sizl); + if (wres == FALSE) { + ret = NSERROR_INVALID; } else { - ret = NSERROR_UNKNOWN; + *width = sizl.cx; } - font = SelectObject(hdc, fontbak); - DeleteObject(font); - ReleaseDC(NULL, hdc); + } else { + ret = NSERROR_NOSPACE; } + + font = SelectObject(hdc, fontbak); + DeleteObject(font); + ReleaseDC(NULL, hdc); + return ret; } @@ -200,19 +225,19 @@ win32_font_width(const plot_font_style_t *style, /** * Find the position in a string where an x coordinate falls. * - * \param style css_style for this text, with style->font_size.size == + * \param style css_style for this text, with style->font_size.size == * CSS_FONT_SIZE_LENGTH - * \param string UTF-8 string to measure - * \param length length of string - * \param x x coordinate to search for - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x + * \param utf8str string to measure encoded in UTF-8 + * \param utf8len length of string + * \param x coordinate to search for + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x * \return NSERROR_OK on success otherwise appropriate error code */ static nserror win32_font_position(const plot_font_style_t *style, - const char *string, - size_t length, + const char *utf8str, + size_t utf8len, int x, size_t *char_offset, int *actual_x) @@ -224,26 +249,29 @@ win32_font_position(const plot_font_style_t *style, int offset; nserror ret = NSERROR_OK; - if ((length == 0) || (x < 1)) { + /* deal with zero length input or invalid search co-ordiate */ + if ((utf8len == 0) || (x < 1)) { *char_offset = 0; *actual_x = 0; + return ret; + } + + hdc = GetDC(NULL); + font = get_font(style); + fontbak = SelectObject(hdc, font); + + if ((GetTextExtentExPointA(hdc, utf8str, utf8len, x, &offset, NULL, &s) != 0) && + (GetTextExtentPoint32A(hdc, utf8str, offset, &s) != 0)) { + *char_offset = (size_t)offset; + *actual_x = s.cx; } else { - hdc = GetDC(NULL); - font = get_font(style); - fontbak = SelectObject(hdc, font); - - if ((GetTextExtentExPointA(hdc, string, length, x, &offset, NULL,&s) != 0) && - (GetTextExtentPoint32A(hdc, string, offset, &s) != 0)) { - *char_offset = (size_t)offset; - *actual_x = s.cx; - } else { - ret = NSERROR_UNKNOWN; - } - font = SelectObject(hdc, fontbak); - DeleteObject(font); - ReleaseDC(NULL, hdc); + ret = NSERROR_UNKNOWN; } + font = SelectObject(hdc, fontbak); + DeleteObject(font); + ReleaseDC(NULL, hdc); + return ret; } @@ -256,7 +284,7 @@ win32_font_position(const plot_font_style_t *style, * \param string UTF-8 string to measure * \param length length of string * \param x width available - * \param char_offset updated to offset in string of actual_x, [0..length] + * \param[out] offset updated to offset in string of actual_x, [0..length] * \param actual_x updated to x coordinate of character closest to x * \return NSERROR_OK on success otherwise appropriate error code * @@ -269,52 +297,48 @@ win32_font_split(const plot_font_style_t *style, const char *string, size_t length, int x, - size_t *char_offset, + size_t *offset, int *actual_x) { + nserror res; int c_off; - nserror ret = NSERROR_UNKNOWN; - - if (win32_font_position(style, - string, - length, - x, - char_offset, - actual_x) == NSERROR_OK) { - c_off = *char_offset; - if (*char_offset == length) { - ret = NSERROR_OK; - } else { - bool success; - while ((string[*char_offset] != ' ') && - (*char_offset > 0)) { - (*char_offset)--; - } - - if (*char_offset == 0) { - *char_offset = c_off; - while ((*char_offset < length) && - (string[*char_offset] != ' ')) { - (*char_offset)++; - } - } - - success = win32_font_width(style, - string, - *char_offset, - actual_x); - if (success) { - ret = NSERROR_OK; - } + + /* get the offset into teh string on the proposed position */ + res = win32_font_position(style, string, length, x, offset, actual_x); + if (res != NSERROR_OK) { + return res; + } + + /* return the whole string fits in the proposed length */ + if (*offset == length) { + return NSERROR_OK; + } + + c_off = *offset; + + /* walk backwards through string looking for space to break on */ + while ((string[*offset] != ' ') && + (*offset > 0)) { + (*offset)--; + } + + /* walk forwards through string looking for space if back failed */ + if (*offset == 0) { + *offset = c_off; + while ((*offset < length) && + (string[*offset] != ' ')) { + (*offset)++; } } + /* find the actual string width of the break */ + res = win32_font_width(style, string, *offset, actual_x); NSLOG(netsurf, DEEPDEBUG, "ret %d Split %u chars at %ipx: Split at char %i (%ipx) - %.*s", - ret, length, x, *char_offset, *actual_x, *char_offset, string); + res, length, x, *offset, *actual_x, *offset, string); - return ret; + return res; } diff --git a/frontends/windows/font.h b/frontends/windows/font.h index ec2c262ff..8219e4c76 100644 --- a/frontends/windows/font.h +++ b/frontends/windows/font.h @@ -35,8 +35,8 @@ struct font_desc { const char *encoding; }; -struct gui_layout_table *win32_layout_table; -struct gui_utf8_table *win32_utf8_table; +extern struct gui_layout_table *win32_layout_table; +extern struct gui_utf8_table *win32_utf8_table; /** * convert from utf-8 to win32 font encoding. diff --git a/frontends/windows/global_history.c b/frontends/windows/global_history.c index dcc75ba21..5a53426a3 100644 --- a/frontends/windows/global_history.c +++ b/frontends/windows/global_history.c @@ -143,8 +143,7 @@ static nserror nsw32_global_history_init(HINSTANCE hInstance) return res; } - res = global_history_init(ncwin->core.cb_table, - (struct core_window *)ncwin); + res = global_history_init((struct core_window *)ncwin); if (res != NSERROR_OK) { free(ncwin); return res; diff --git a/frontends/windows/gui.c b/frontends/windows/gui.c index bafe5a4b7..9a2c13b23 100644 --- a/frontends/windows/gui.c +++ b/frontends/windows/gui.c @@ -36,19 +36,20 @@ #include "utils/file.h" #include "utils/messages.h" #include "netsurf/browser_window.h" -#include "netsurf/clipboard.h" #include "windows/schedule.h" #include "windows/window.h" #include "windows/gui.h" -/** - * win32 application instance handle. - * - * This handle is set in the main windows entry point. - */ +/* exported global defined in windows/gui.h */ HINSTANCE hinst; +/* exported global defined in windows/gui.h */ +char **G_resource_pathv; + +/* exported global defined in windows/gui.h */ +char *G_config_path; + static bool win32_quit = false; struct dialog_list_entry { @@ -181,65 +182,17 @@ nserror win32_warning(const char *warning, const char *detail) } -/** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ -static void gui_get_clipboard(char **buffer, size_t *length) +/* exported function documented in windows/gui.h */ +nserror +win32_report_nserror(nserror error, const char *detail) { - /* TODO: Implement this */ - HANDLE clipboard_handle; - char *content; - - clipboard_handle = GetClipboardData(CF_TEXT); - if (clipboard_handle != NULL) { - content = GlobalLock(clipboard_handle); - NSLOG(netsurf, INFO, "pasting %s", content); - GlobalUnlock(clipboard_handle); - } -} - + size_t len = 1 + + strlen(messages_get_errorcode(error)) + + ((detail != 0) ? strlen(detail) : 0); + char message[len]; + snprintf(message, len, messages_get_errorcode(error), detail); + MessageBox(NULL, message, "Warning", MB_ICONWARNING); -/** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ -static void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles) -{ - /* TODO: Implement this */ - HANDLE hnew; - char *new, *original; - HANDLE h = GetClipboardData(CF_TEXT); - if (h == NULL) - original = (char *)""; - else - original = GlobalLock(h); - - size_t len = strlen(original) + 1; - hnew = GlobalAlloc(GHND, length + len); - new = (char *)GlobalLock(hnew); - snprintf(new, length + len, "%s%s", original, buffer); - - if (h != NULL) { - GlobalUnlock(h); - EmptyClipboard(); - } - GlobalUnlock(hnew); - SetClipboardData(CF_TEXT, hnew); + return NSERROR_OK; } - - -static struct gui_clipboard_table clipboard_table = { - .get = gui_get_clipboard, - .set = gui_set_clipboard, -}; - -struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; diff --git a/frontends/windows/gui.h b/frontends/windows/gui.h index 95dcfc1b2..957280ae4 100644 --- a/frontends/windows/gui.h +++ b/frontends/windows/gui.h @@ -17,19 +17,27 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _NETSURF_WINDOWS_GUI_H_ -#define _NETSURF_WINDOWS_GUI_H_ +#ifndef NETSURF_WINDOWS_GUI_H +#define NETSURF_WINDOWS_GUI_H struct gui_window; -struct gui_clipboard_table *win32_clipboard_table; +/** + * win32 application instance handle. + * + * This handle is set in the main windows entry point. + */ extern HINSTANCE hinst; -/** Directory where all configuration files are held. */ -extern char *nsw32_config_home; +/** + * path to where all user config files are held. + */ +extern char *G_config_path; -/** resource search path vector. */ -extern char **respaths; +/** + * resource search path vector. + */ +extern char **G_resource_pathv; /* bounding box */ typedef struct bbox_s { @@ -60,6 +68,16 @@ void win32_set_quit(bool q); nserror win32_warning(const char *warning, const char *detail); /** + * Warn the user of an unexpected nserror. + * + * \param[in] error The nserror to report + * \param[in] detail Additional text to be displayed or NULL. + * \return NSERROR_OK on success or error code if there was a + * faliure displaying the message to the user. + */ +nserror win32_report_nserror(nserror error, const char *detail); + +/** * add a modeless dialog to the special handling list */ nserror nsw32_add_dialog(HWND hwndDlg); diff --git a/frontends/windows/hotlist.c b/frontends/windows/hotlist.c index e8dd90b34..3f05b79fd 100644 --- a/frontends/windows/hotlist.c +++ b/frontends/windows/hotlist.c @@ -147,8 +147,7 @@ static nserror nsw32_hotlist_init(HINSTANCE hInstance) return res; } - res = hotlist_manager_init(ncwin->core.cb_table, - (struct core_window *)ncwin); + res = hotlist_manager_init((struct core_window *)ncwin); if (res != NSERROR_OK) { free(ncwin); return res; diff --git a/frontends/windows/local_history.c b/frontends/windows/local_history.c index 722d365e7..a8e055aec 100644 --- a/frontends/windows/local_history.c +++ b/frontends/windows/local_history.c @@ -160,8 +160,7 @@ nsw32_local_history_init(HINSTANCE hInstance, return res; } - res = local_history_init(ncwin->core.cb_table, - (struct core_window *)ncwin, + res = local_history_init((struct core_window *)ncwin, bw, &ncwin->session); if (res != NSERROR_OK) { @@ -215,6 +214,7 @@ nsw32_local_history_present(HWND hWndParent, struct browser_window *bw) width, height, SWP_SHOWWINDOW); + local_history_scroll_to_cursor(local_history_window->session); } return res; } diff --git a/frontends/windows/login.c b/frontends/windows/login.c deleted file mode 100644 index ca6c9163d..000000000 --- a/frontends/windows/login.c +++ /dev/null @@ -1,297 +0,0 @@ -/* -* Copyright 2018 Vincent Sanders <vince@netsurf-browser.org> -* -* This file is part of NetSurf, http://www.netsurf-browser.org/ -* -* NetSurf is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; version 2 of the License. -* -* NetSurf is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** - * \file - * This is The win32 API basic authentication login dialog implementation. - */ - -#include <stdio.h> - -#include "utils/config.h" - -#include <windows.h> - -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/nsurl.h" -#include "desktop/version.h" - -#include "windows/gui.h" -#include "windows/window.h" -#include "windows/login.h" -#include "windows/resourceid.h" - -#include "windbg.h" - -struct login_ctx { - char *username; - char *password; - char *description; - nserror (*cb)(const char *username, const char *password, void *cbctx); - void *cbctx; -}; - - -/** - * free login dialog context - */ -static nserror -free_loginctx(struct login_ctx *ctx) -{ - free(ctx->username); - free(ctx->password); - free(ctx->description); - free(ctx); - - return NSERROR_OK; -} - - -/** - * generate the description of the login request - */ -static nserror -get_login_description(struct nsurl *url, - const char *realm, - char **out_str) -{ - char *url_s; - size_t url_l; - nserror res; - const char *fmt = "The site %s is requesting your username and password. The realm is \"%s\""; - char *str = NULL; - int strlen; - - res = nsurl_get(url, NSURL_SCHEME | NSURL_HOST, &url_s, &url_l); - if (res != NSERROR_OK) { - return res; - } - - strlen = snprintf(str, 0, fmt, url_s, realm) + 1; - str = malloc(strlen); - if (str == NULL) { - res = NSERROR_NOMEM; - } else { - snprintf(str, strlen, fmt, url_s, realm); - *out_str = str; - } - - free(url_s); - - return res; -} - -/** - * win32 login dialog initialisation handler - */ -static BOOL -login_dialog_init(HWND hwndDlg, WPARAM wParam, LPARAM lParam) -{ - struct login_ctx *ctx; - HWND hwndOwner; - RECT rc, rcDlg, rcOwner; - ctx = (struct login_ctx *)lParam; - - /* make context available in future calls */ - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - /* set default contents */ - SetDlgItemText(hwndDlg, IDC_LOGIN_USERNAME, ctx->username); - SetDlgItemText(hwndDlg, IDC_LOGIN_PASSWORD, ctx->password); - SetDlgItemText(hwndDlg, IDC_LOGIN_DESCRIPTION, ctx->description); - - /* Get the owner window and dialog box rectangles. */ - if ((hwndOwner = GetParent(hwndDlg)) == NULL) { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - /* Offset the owner and dialog box rectangles so that right - * and bottom values represent the width and height, and then - * offset the owner again to discard space taken up by the - * dialog box. - */ - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - /* The new position is the sum of half the remaining space and - * the owner's original position. - */ - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, /* Ignores size arguments. */ - SWP_NOSIZE); - - /* ensure username gets focus */ - if (GetDlgCtrlID((HWND) wParam) != IDC_LOGIN_USERNAME) { - SetFocus(GetDlgItem(hwndDlg, IDC_LOGIN_USERNAME)); - return FALSE; - } - - return TRUE; -} - - -/** - * win32 login dialog ok handler - */ -static BOOL -login_dialog_ok(HWND hwndDlg, struct login_ctx *ctx) -{ - char username[255]; - char password[255]; - - if (GetDlgItemText(hwndDlg, - IDC_LOGIN_USERNAME, - username, - sizeof(username)) == 0) { - username[0]=0; - } - - if (GetDlgItemText(hwndDlg, - IDC_LOGIN_PASSWORD, - password, - sizeof(password)) == 0) { - password[0]=0; - } - - NSLOG(netsurf, DEBUG, - "context %p, user:\"%s\" pw:\"%s\"", ctx, username, password); - - ctx->cb(username, password, ctx->cbctx); - - DestroyWindow(hwndDlg); - - nsw32_del_dialog(hwndDlg); - - free_loginctx(ctx); - - return TRUE; -} - - -/** - * win32 login dialog cancel handler - */ -static BOOL -login_dialog_cancel(HWND hwndDlg, struct login_ctx *ctx) -{ - NSLOG(netsurf, DEBUG, "context %p", ctx); - - ctx->cb(NULL, NULL, ctx->cbctx); - - DestroyWindow(hwndDlg); - - nsw32_del_dialog(hwndDlg); - - free_loginctx(ctx); - - return TRUE; -} - - -/** - * win32 API callback for login dialog - */ -static BOOL CALLBACK -login_dialog_callback(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - struct login_ctx *ctx; - - LOG_WIN_MSG(hwndDlg, message, wParam, lParam); - - /* obtain login dialog context */ - ctx = (struct login_ctx *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (message) { - case WM_INITDIALOG: - return login_dialog_init(hwndDlg, wParam, lParam); - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDOK: - return login_dialog_ok(hwndDlg, ctx); - - case IDCANCEL: - return login_dialog_cancel(hwndDlg, ctx); - } - } - return FALSE; -} - - -/** - * Request credentials for http login - */ -nserror -nsw32_401login(nsurl *url, - const char *realm, - const char *username, - const char *password, - nserror (*cb)(const char *username, - const char *password, - void *cbctx), - void *cbctx) -{ - HWND hwndDlg; - struct login_ctx *nctx; - struct gui_window *gw; - nserror res; - - /* locate parent window */ - gw = nsws_get_gui_window(GetActiveWindow()); - if (gw == NULL) { - return NSERROR_INIT_FAILED; - } - - /* setup context for parameters */ - nctx = calloc(1, sizeof(struct login_ctx)); - if (nctx == NULL) { - return NSERROR_NOMEM; - } - - nctx->username = strdup(username); - nctx->password = strdup(password); - nctx->cb = cb; - nctx->cbctx = cbctx; - - res = get_login_description(url, realm, &nctx->description); - if (res != NSERROR_OK) { - free_loginctx(nctx); - return res; - } - - /* create modeless dialog */ - hwndDlg = CreateDialogParam(NULL, - MAKEINTRESOURCE(IDD_LOGIN), - gw->main, - login_dialog_callback, - (LPARAM)nctx); - - nsw32_add_dialog(hwndDlg); - - return NSERROR_OK; -} diff --git a/frontends/windows/main.c b/frontends/windows/main.c index fd22ae1fe..561ebe848 100644 --- a/frontends/windows/main.c +++ b/frontends/windows/main.c @@ -34,6 +34,7 @@ #include "utils/nsoption.h" #include "netsurf/url_db.h" #include "netsurf/cookie_db.h" +#include "netsurf/browser.h" #include "netsurf/browser_window.h" #include "netsurf/fetch.h" #include "netsurf/misc.h" @@ -42,10 +43,9 @@ #include "windows/findfile.h" #include "windows/file.h" +#include "windows/cookies.h" #include "windows/drawable.h" #include "windows/corewindow.h" -#include "windows/ssl_cert.h" -#include "windows/login.h" #include "windows/download.h" #include "windows/local_history.h" #include "windows/window.h" @@ -54,11 +54,29 @@ #include "windows/fetch.h" #include "windows/pointers.h" #include "windows/bitmap.h" +#include "windows/clipboard.h" #include "windows/gui.h" -char **respaths; /** exported global defined in windows/gui.h */ -char *nsw32_config_home; /* exported global defined in windows/gui.h */ +/** + * Obtain the DPI of the display. + * + * \return The DPI of the device the window is displayed on. + */ +static int get_screen_dpi(void) +{ + HDC screendc = GetDC(0); + int dpi = GetDeviceCaps(screendc, LOGPIXELSY); + ReleaseDC(0, screendc); + + if (dpi <= 10) { + dpi = 96; /* 96DPI is the default */ + } + + NSLOG(netsurf, INFO, "FIX DPI %d", dpi); + + return dpi; +} /** * Get the path to the config directory. @@ -172,6 +190,11 @@ static nserror set_defaults(struct nsoption_s *defaults) &ptr); if (res_len > 0) { nsoption_setnull_charp(ca_bundle, strdup(buf)); + } else { + ptr = filepath_sfind(G_resource_pathv, buf, "ca-bundle.crt"); + if (ptr != NULL) { + nsoption_setnull_charp(ca_bundle, strdup(buf)); + } } @@ -203,28 +226,28 @@ static nserror set_defaults(struct nsoption_s *defaults) /* cookie file default */ fname = NULL; - netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Cookies"); + netsurf_mkpath(&fname, NULL, 2, G_config_path, "Cookies"); if (fname != NULL) { nsoption_setnull_charp(cookie_file, fname); } /* cookie jar default */ fname = NULL; - netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Cookies"); + netsurf_mkpath(&fname, NULL, 2, G_config_path, "Cookies"); if (fname != NULL) { nsoption_setnull_charp(cookie_jar, fname); } /* url database default */ fname = NULL; - netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "URLs"); + netsurf_mkpath(&fname, NULL, 2, G_config_path, "URLs"); if (fname != NULL) { nsoption_setnull_charp(url_file, fname); } /* bookmark database default */ fname = NULL; - netsurf_mkpath(&fname, NULL, 2, nsw32_config_home, "Hotlist"); + netsurf_mkpath(&fname, NULL, 2, G_config_path, "Hotlist"); if (fname != NULL) { nsoption_setnull_charp(hotlist_path, fname); } @@ -236,11 +259,16 @@ static nserror set_defaults(struct nsoption_s *defaults) /** * Initialise user options location and contents */ -static nserror nsw32_option_init(int *pargc, char** argv) +static nserror +nsw32_option_init(int *pargc, char** argv, char **respaths, char *config_path) { nserror ret; char *choices = NULL; + /* set the globals that will be used in the set_defaults() callback */ + G_resource_pathv = respaths; + G_config_path = config_path; + /* user options setup */ ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); if (ret != NSERROR_OK) { @@ -248,7 +276,7 @@ static nserror nsw32_option_init(int *pargc, char** argv) } /* Attempt to load the user choices */ - ret = netsurf_mkpath(&choices, NULL, 2, nsw32_config_home, "Choices"); + ret = netsurf_mkpath(&choices, NULL, 2, config_path, "Choices"); if (ret == NSERROR_OK) { nsoption_read(choices, nsoptions); free(choices); @@ -287,12 +315,63 @@ static nserror nsw32_messages_init(char **respaths) return res; } + +/** + * Construct a unix style argc/argv + * + * \param argc_out number of commandline arguments + * \param argv_out string vector of command line arguments + * \return NSERROR_OK on success else error code + */ +static nserror win32_to_unix_commandline(int *argc_out, char ***argv_out) +{ + int argc = 0; + char **argv; + int cura; + LPWSTR *argvw; + size_t len; + + argvw = CommandLineToArgvW(GetCommandLineW(), &argc); + if (argvw == NULL) { + return NSERROR_INVALID; + } + + argv = malloc(sizeof(char *) * argc); + if (argv == NULL) { + return NSERROR_NOMEM; + } + + for (cura = 0; cura < argc; cura++) { + + len = wcstombs(NULL, argvw[cura], 0) + 1; + if (len > 0) { + argv[cura] = malloc(len); + if (argv[cura] == NULL) { + free(argv); + return NSERROR_NOMEM; + } + } else { + free(argv); + return NSERROR_INVALID; + } + + wcstombs(argv[cura], argvw[cura], len); + /* alter windows-style forward slash flags to hyphen flags. */ + if (argv[cura][0] == '/') { + argv[cura][0] = '-'; + } + } + + *argc_out = argc; + *argv_out = argv; + + return NSERROR_OK; +} + + static struct gui_misc_table win32_misc_table = { .schedule = win32_schedule, - .warning = win32_warning, - - .cert_verify = nsw32_cert_verify, - .login = nsw32_401login, + .present_cookies = nsw32_cookies_present, }; /** @@ -301,16 +380,17 @@ static struct gui_misc_table win32_misc_table = { int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) { - char **argv = NULL; - int argc = 0, argctemp = 0; - size_t len; - LPWSTR *argvw; + int argc; + char **argv; + char **respaths; + char *nsw32_config_home = NULL; nserror ret; const char *addr; nsurl *url; struct netsurf_table win32_table = { .misc = &win32_misc_table, .window = win32_window_table, + .corewindow = win32_core_window_table, .clipboard = win32_clipboard_table, .download = win32_download_table, .fetch = win32_fetch_table, @@ -330,27 +410,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) setbuf(stderr, NULL); - /* Construct a unix style argc/argv */ - if (SLEN(lpcli) > 0) { - argvw = CommandLineToArgvW(GetCommandLineW(), &argc); - } - - argv = malloc(sizeof(char *) * argc); - while (argctemp < argc) { - len = wcstombs(NULL, argvw[argctemp], 0) + 1; - if (len > 0) { - argv[argctemp] = malloc(len); - } - - if (argv[argctemp] != NULL) { - wcstombs(argv[argctemp], argvw[argctemp], len); - /* alter windows-style forward slash flags to - * hyphen flags. - */ - if (argv[argctemp][0] == '/') - argv[argctemp][0] = '-'; - } - argctemp++; + ret = win32_to_unix_commandline(&argc, &argv); + if (ret != NSERROR_OK) { + /* no log as logging requires this for initialisation */ + return 1; } /* initialise logging - not fatal if it fails but not much we @@ -358,24 +421,24 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) */ nslog_init(nslog_ensure, &argc, argv); + /* build resource path string vector */ + respaths = nsws_init_resource("${APPDATA}\\NetSurf:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH); + /* Locate the correct user configuration directory path */ ret = get_config_home(&nsw32_config_home); if (ret != NSERROR_OK) { NSLOG(netsurf, INFO, "Unable to locate a configuration directory."); - nsw32_config_home = NULL; } /* Initialise user options */ - ret = nsw32_option_init(&argc, argv); + ret = nsw32_option_init(&argc, argv, respaths, nsw32_config_home); if (ret != NSERROR_OK) { - NSLOG(netsurf, INFO, "Options failed to initialise (%s)\n", + NSLOG(netsurf, ERROR, "Options failed to initialise (%s)\n", messages_get_errorcode(ret)); return 1; } - respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\NetSurf\\:"NETSURF_WINDOWS_RESPATH); - /* Initialise translated messages */ ret = nsw32_messages_init(respaths); if (ret != NSERROR_OK) { @@ -392,6 +455,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) return 1; } + browser_set_dpi(get_screen_dpi()); + urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); hotlist_init(nsoption_charp(hotlist_path), @@ -400,7 +465,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) ret = nsws_create_main_class(hInstance); ret = nsws_create_drawable_class(hInstance); ret = nsw32_create_corewindow_class(hInstance); - ret = nsws_create_cert_verify_class(hInstance); nsoption_set_bool(target_blank, false); diff --git a/frontends/windows/prefs.c b/frontends/windows/prefs.c index b2cb7b2d6..d6855f5da 100644 --- a/frontends/windows/prefs.c +++ b/frontends/windows/prefs.c @@ -230,13 +230,6 @@ static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd, sub = GetDlgItem(hwnd, IDC_PREFS_NOANIMATION); SendMessage(sub, BM_SETCHECK, (WPARAM)((nsoption_bool(animate_images)) ? BST_UNCHECKED : BST_CHECKED), 0); - - if (nsoption_int(minimum_gif_delay) != 0) { - sub = GetDlgItem(hwnd, IDC_PREFS_ANIMATIONDELAY); - snprintf(number, 6, "%.1f", nsoption_int(minimum_gif_delay) / - 100.0); - SendMessage(sub, WM_SETTEXT, 0, (LPARAM)number); - } break; case WM_NOTIFY: @@ -268,18 +261,6 @@ static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd, nsoption_set_bool(animate_images, (IsDlgButtonChecked(hwnd, IDC_PREFS_NOANIMATION) == BST_CHECKED) ? true : false); - - sub = GetDlgItem(hwnd, IDC_PREFS_ANIMATIONDELAY); - len = SendMessage(sub, WM_GETTEXTLENGTH, 0, 0); - temp = malloc(len + 1); - if (temp != NULL) { - SendMessage(sub, WM_GETTEXT, (WPARAM) - (len + 1), (LPARAM) temp); - nsoption_set_int(minimum_gif_delay, - (int)(100 * strtod(temp, NULL))); - free(temp); - } - break; case UDN_DELTAPOS: { @@ -292,15 +273,11 @@ static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd, case IDC_PREFS_FONT_MINSIZE_SPIN: change_spinner(GetDlgItem(hwnd, IDC_PREFS_FONT_MINSIZE), 0.1 * ud->iDelta, 1.0, 50.0); return TRUE; - - case IDC_PREFS_ANIMATIONDELAY_SPIN: - change_spinner(GetDlgItem(hwnd, IDC_PREFS_ANIMATIONDELAY), 0.1 * ud->iDelta, 0.1, 100.0); - return TRUE; - } } break; } + break; case WM_COMMAND: @@ -699,7 +676,7 @@ nserror nsws_prefs_save(void) char *choices = NULL; nserror res; - res = netsurf_mkpath(&choices, NULL, 2, nsw32_config_home, "Choices"); + res = netsurf_mkpath(&choices, NULL, 2, G_config_path, "Choices"); if (res == NSERROR_OK) { nsoption_write(choices, NULL, NULL); free(choices); diff --git a/frontends/windows/res/installer.nsi b/frontends/windows/res/installer.nsi index 5d2e60004..2f8b757d8 100644 --- a/frontends/windows/res/installer.nsi +++ b/frontends/windows/res/installer.nsi @@ -13,16 +13,16 @@ !define VERSIONMAJOR 3 !endif !ifndef VERSIONMINOR - !define VERSIONMINOR 8 + !define VERSIONMINOR 11 !endif !ifndef VERSIONBUILD !define VERSIONBUILD 0 !endif # These will be displayed by the "Click here for support information" link in "Add/Remove Programs" -!define HELPURL "http://www.netsurf-browser.org/" # "Support Information" link -!define UPDATEURL "http://www.netsurf-browser.org/" # "Product Updates" link -!define ABOUTURL "http://www.netsurf-browser.org/" # "Publisher" link +!define HELPURL "https://www.netsurf-browser.org/" # "Support Information" link +!define UPDATEURL "https://www.netsurf-browser.org/" # "Product Updates" link +!define ABOUTURL "https://www.netsurf-browser.org/" # "Publisher" link # This is the size (in kB) of all the files copied into "Program Files" !define INSTALLSIZE 9000 diff --git a/frontends/windows/res/page-info-insecure.bmp b/frontends/windows/res/page-info-insecure.bmp Binary files differnew file mode 100644 index 000000000..d8e15c318 --- /dev/null +++ b/frontends/windows/res/page-info-insecure.bmp diff --git a/frontends/windows/res/page-info-internal.bmp b/frontends/windows/res/page-info-internal.bmp Binary files differnew file mode 100644 index 000000000..b9b4eabd5 --- /dev/null +++ b/frontends/windows/res/page-info-internal.bmp diff --git a/frontends/windows/res/page-info-local.bmp b/frontends/windows/res/page-info-local.bmp Binary files differnew file mode 100644 index 000000000..51cd5964b --- /dev/null +++ b/frontends/windows/res/page-info-local.bmp diff --git a/frontends/windows/res/page-info-secure.bmp b/frontends/windows/res/page-info-secure.bmp Binary files differnew file mode 100644 index 000000000..b08809c66 --- /dev/null +++ b/frontends/windows/res/page-info-secure.bmp diff --git a/frontends/windows/res/page-info-warning.bmp b/frontends/windows/res/page-info-warning.bmp Binary files differnew file mode 100644 index 000000000..8e6b3afeb --- /dev/null +++ b/frontends/windows/res/page-info-warning.bmp diff --git a/frontends/windows/res/resource.rc b/frontends/windows/res/resource.rc index e41a705a5..9e9927b0c 100644 --- a/frontends/windows/res/resource.rc +++ b/frontends/windows/res/resource.rc @@ -28,9 +28,31 @@ 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"
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_PAGEINFO_INSECURE BITMAP "page-info-insecure.bmp"
+
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_PAGEINFO_SECURE BITMAP "page-info-secure.bmp"
+
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_PAGEINFO_INTERNAL BITMAP "page-info-internal.bmp"
+
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_PAGEINFO_WARNING BITMAP "page-info-warning.bmp"
+
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_PAGEINFO_LOCAL BITMAP "page-info-local.bmp"
+
+
//
// Menu resources
//
@@ -220,9 +242,6 @@ FONT 8, "MS Shell Dlg", 0, 0, 1 LTEXT "Animation", IDC_STATIC, 7, 148, 36, 8, NOT WS_GROUP | SS_LEFT, WS_EX_LEFT
CONTROL "", IDC_STATIC, WC_STATIC, SS_ETCHEDFRAME, 43, 152, 170, 1, WS_EX_LEFT
AUTOCHECKBOX "Disable", IDC_PREFS_NOANIMATION, 43, 163, 39, 10, 0, WS_EX_LEFT
- LTEXT "Minimum delay:", IDC_STATIC, 55, 180, 56, 8, SS_LEFT, WS_EX_LEFT
- EDITTEXT IDC_PREFS_ANIMATIONDELAY, 113, 177, 35, 14, NOT WS_BORDER, WS_EX_CLIENTEDGE
- CONTROL "Min delay", IDC_PREFS_ANIMATIONDELAY_SPIN, UPDOWN_CLASS, UDS_ALIGNRIGHT | UDS_AUTOBUDDY, 43, 210, 11, 15, WS_EX_LEFT
}
diff --git a/frontends/windows/resourceid.h b/frontends/windows/resourceid.h index e86d8eedb..db275913b 100644 --- a/frontends/windows/resourceid.h +++ b/frontends/windows/resourceid.h @@ -30,7 +30,12 @@ #define IDR_TOOLBAR_BITMAP_HOT 104 #define IDR_NETSURF_BANNER 105 #define IDR_HOME_BITMAP 106 - +#define IDC_PAGEINFO 107 +#define IDB_PAGEINFO_INSECURE 108 +#define IDB_PAGEINFO_SECURE 109 +#define IDB_PAGEINFO_INTERNAL 110 +#define IDB_PAGEINFO_WARNING 111 +#define IDB_PAGEINFO_LOCAL 112 #define IDD_ABOUT 1000 #define IDC_IMG1 1001 @@ -83,13 +88,6 @@ #define IDC_PREFS_FANTASY 1219 #define IDC_PREFS_FONTDEF 1220 #define IDC_PREFS_NOANIMATION 1227 -#define IDC_PREFS_ANIMATIONDELAY 1228 -#define IDC_PREFS_ANIMATIONDELAY_SPIN 1229 - -#define IDD_SSLCERT 1600 -#define IDC_SSLCERT_IMG1 1601 -#define IDC_SSLCERT_BTN_ACCEPT 1602 -#define IDC_SSLCERT_BTN_REJECT 1603 #define IDD_LOGIN 1700 #define IDC_LOGIN_USERNAME 1701 diff --git a/frontends/windows/ssl_cert.c b/frontends/windows/ssl_cert.c deleted file mode 100644 index 4db061626..000000000 --- a/frontends/windows/ssl_cert.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * \file - * Implementation of win32 certificate viewing using nsw32 core windows. - */ - -#include <stdint.h> -#include <stdlib.h> -#include <windows.h> - -#include "utils/log.h" -#include "utils/nsoption.h" -#include "netsurf/keypress.h" -#include "netsurf/plotters.h" -#include "desktop/sslcert_viewer.h" - -#include "windows/windbg.h" -#include "windows/plot.h" -#include "windows/corewindow.h" -#include "windows/gui.h" -#include "windows/resourceid.h" -#include "windows/ssl_cert.h" - -/* spacing and sizes for dialog elements from - * https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486(v=vs.85).aspx#sizingandspacing - */ -/** dialog margin */ -#define DLG_MRGN 11 -/** warning icon height */ -#define WRN_ICO_H 32 -/** comand button width */ -#define CMD_BTN_W 75 -/** command button height */ -#define CMD_BTN_H 23 - -static const char windowclassname_sslcert[] = "nswssslcertwindow"; - -/** win32 ssl certificate view context */ -struct nsw32_sslcert_window { - struct nsw32_corewindow core; - - /** SSL certificate viewer context data */ - struct sslcert_session_data *ssl_data; - - /** dialog window handle */ - HWND hWnd; - - /** accept button handle */ - HWND hAccept; - - /** reject button handle */ - HWND hReject; - - /** warning text handle */ - HWND hTxt; -}; - - -/** - * callback for keypress on ssl certificate window - * - * \param nsw32_cw The nsw32 core window structure. - * \param nskey The netsurf key code - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsw32_sslcert_viewer_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey) -{ - struct nsw32_sslcert_window *crtvrfy_win; - - /* technically degenerate container of */ - crtvrfy_win = (struct nsw32_sslcert_window *)nsw32_cw; - - if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) { - return NSERROR_OK; - } - return NSERROR_NOT_IMPLEMENTED; -} - - -/** - * callback for mouse action on ssl certificate window - * - * \param nsw32_cw The nsw32 core window structure. - * \param mouse_state netsurf mouse state on event - * \param x location of event - * \param y location of event - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsw32_sslcert_viewer_mouse(struct nsw32_corewindow *nsw32_cw, - browser_mouse_state mouse_state, - int x, int y) -{ - struct nsw32_sslcert_window *crtvrfy_win; - - /* technically degenerate container of */ - crtvrfy_win = (struct nsw32_sslcert_window *)nsw32_cw; - - sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y); - - return NSERROR_OK; -} - - -/** - * callback on draw event for ssl certificate window - * - * \param nsw32_cw The nsw32 core window structure. - * \param scrollx The horizontal scroll offset. - * \param scrolly The vertical scroll offset. - * \param r The rectangle of the window that needs updating. - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsw32_sslcert_viewer_draw(struct nsw32_corewindow *nsw32_cw, - int scrollx, - int scrolly, - struct rect *r) -{ - struct nsw32_sslcert_window *crtvrfy_win; - struct redraw_context ctx = { - .interactive = true, - .background_images = true, - .plot = &win_plotters - }; - - /* technically degenerate container of */ - crtvrfy_win = (struct nsw32_sslcert_window *)nsw32_cw; - - sslcert_viewer_redraw(crtvrfy_win->ssl_data, - -scrollx, -scrolly, - r, &ctx); - - return NSERROR_OK; -} - - -/** - * callback on close event for ssl certificate window - * - * \param nsw32_cw The nsw32 core window structure. - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror -nsw32_sslcert_viewer_close(struct nsw32_corewindow *nsw32_cw) -{ - DestroyWindow(nsw32_cw->hWnd); - - return NSERROR_OK; -} - - -/* exported interface documented in nsw32/ssl_cert.h */ -nserror nsw32_cert_verify(struct nsurl *url, - const struct ssl_cert_info *certs, - unsigned long num, - nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - struct nsw32_sslcert_window *ncwin; - nserror res; - - ncwin = malloc(sizeof(struct nsw32_sslcert_window)); - if (ncwin == NULL) { - return NSERROR_NOMEM; - } - - /* initialise certificate viewing interface */ - res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs, - &ncwin->ssl_data); - if (res != NSERROR_OK) { - free(ncwin); - return res; - } - - NSLOG(netsurf, INFO, "creating hInstance %p SSL window", hinst); - ncwin->hWnd = CreateWindowEx(0, - windowclassname_sslcert, - "SSL Certificate viewer", - WS_OVERLAPPEDWINDOW | - WS_CLIPSIBLINGS | - WS_CLIPCHILDREN | - CS_DBLCLKS, - CW_USEDEFAULT, - CW_USEDEFAULT, - 500, - 400, - NULL, - NULL, - hinst, - NULL); - if (ncwin->hWnd == NULL) { - NSLOG(netsurf, INFO, "Window create failed"); - return NSERROR_NOMEM; - } - - ncwin->core.title = NULL; - ncwin->core.draw = nsw32_sslcert_viewer_draw; - ncwin->core.key = nsw32_sslcert_viewer_key; - ncwin->core.mouse = nsw32_sslcert_viewer_mouse; - ncwin->core.close = nsw32_sslcert_viewer_close; - - res = nsw32_corewindow_init(hinst, ncwin->hWnd, &ncwin->core); - if (res != NSERROR_OK) { - free(ncwin); - return res; - } - - res = sslcert_viewer_init(ncwin->core.cb_table, - (struct core_window *)ncwin, - ncwin->ssl_data); - if (res != NSERROR_OK) { - free(ncwin); - return res; - } - - ncwin->hAccept = CreateWindowEx(0, - "BUTTON", - "Accept", - WS_TABSTOP|WS_VISIBLE| - WS_CHILD|BS_DEFPUSHBUTTON, - CW_USEDEFAULT, - CW_USEDEFAULT, - CMD_BTN_W, - CMD_BTN_H, - ncwin->hWnd, - (HMENU)IDC_SSLCERT_BTN_ACCEPT, - hinst, - NULL); - HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT); - SendMessage(ncwin->hAccept, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0)); - ncwin->hReject = CreateWindowEx(0, - "BUTTON", - "Reject", - WS_TABSTOP|WS_VISIBLE| - WS_CHILD|BS_DEFPUSHBUTTON, - CW_USEDEFAULT, - CW_USEDEFAULT, - CMD_BTN_W, - CMD_BTN_H, - ncwin->hWnd, - (HMENU)IDC_SSLCERT_BTN_REJECT, - hinst, - NULL); - SendMessage(ncwin->hReject, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0)); - - CreateWindowEx(0, - "STATIC", - IDI_WARNING, - WS_VISIBLE | WS_CHILD | SS_ICON, - DLG_MRGN, - DLG_MRGN, - CMD_BTN_W, - CMD_BTN_H, - ncwin->hWnd, - NULL, - NULL, - NULL); - ncwin->hTxt = CreateWindowEx(0, - "STATIC", - "NetSurf failed to verify the authenticity of an SSL certificate. Verify the certificate details", - WS_VISIBLE | WS_CHILD | SS_LEFT, - DLG_MRGN + WRN_ICO_H + DLG_MRGN, - DLG_MRGN + 5, - 400, - WRN_ICO_H - 5, - ncwin->hWnd, - NULL, - NULL, - NULL); - SendMessage(ncwin->hTxt, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0)); - - SetProp(ncwin->hWnd, TEXT("CertWnd"), (HANDLE)ncwin); - - ShowWindow(ncwin->hWnd, SW_SHOWNORMAL); - - return NSERROR_OK; -} - - -/** - * position and size ssl cert window widgets. - * - * \param hwnd The win32 handle of the window - * \param certwin The certificate viewer context - */ -static void -nsw32_window_ssl_cert_size(HWND hwnd, struct nsw32_sslcert_window *certwin) -{ - RECT rc; - GetClientRect(hwnd, &rc); - /* position certificate drawable */ - MoveWindow(certwin->core.hWnd, - DLG_MRGN, - DLG_MRGN + WRN_ICO_H + DLG_MRGN, - rc.right - (DLG_MRGN + DLG_MRGN), - rc.bottom - (DLG_MRGN + WRN_ICO_H + DLG_MRGN + DLG_MRGN + CMD_BTN_H + DLG_MRGN), - TRUE); - /* position accept button */ - MoveWindow(certwin->hAccept, - rc.right - (DLG_MRGN + CMD_BTN_W), - rc.bottom - (DLG_MRGN + CMD_BTN_H), - CMD_BTN_W, - CMD_BTN_H, - TRUE); - /* position reject button */ - MoveWindow(certwin->hReject, - rc.right - (DLG_MRGN + CMD_BTN_W + 7 + CMD_BTN_W), - rc.bottom - (DLG_MRGN + CMD_BTN_H), - CMD_BTN_W, - CMD_BTN_H, - TRUE); - /* position text */ - MoveWindow(certwin->hTxt, - DLG_MRGN + WRN_ICO_H + DLG_MRGN, - DLG_MRGN + 5, - rc.right - (DLG_MRGN + WRN_ICO_H + DLG_MRGN + DLG_MRGN), - WRN_ICO_H - 5, - TRUE); -} - - -/** - * Destroy a certificate viewing window - * - * \param crtwin The certificate viewer context - * \return NSERROR_OK on success otherwise appropriate error code - */ -static nserror nsw32_crtvrfy_destroy(struct nsw32_sslcert_window *crtwin) -{ - nserror res; - - res = sslcert_viewer_fini(crtwin->ssl_data); - if (res == NSERROR_OK) { - res = nsw32_corewindow_fini(&crtwin->core); - DestroyWindow(crtwin->hWnd); - free(crtwin); - } - return res; -} - - -/** - * handle command message on ssl certificate viewing window. - * - * \param hwnd The win32 window handle. - * \param crtwin certificate window context. - * \param notification_code notifiction code - * \param identifier notification identifier - * \param ctrl_window The win32 control window handle - * \return appropriate response for command - */ -static LRESULT -nsw32_window_ssl_cert_command(HWND hwnd, - struct nsw32_sslcert_window *crtwin, - int notification_code, - int identifier, - HWND ctrl_window) -{ - NSLOG(netsurf, INFO, - "notification_code %x identifier %x ctrl_window %p", - notification_code, - identifier, - ctrl_window); - - switch(identifier) { - case IDC_SSLCERT_BTN_ACCEPT: - sslcert_viewer_accept(crtwin->ssl_data); - nsw32_crtvrfy_destroy(crtwin); - break; - - case IDC_SSLCERT_BTN_REJECT: - sslcert_viewer_reject(crtwin->ssl_data); - nsw32_crtvrfy_destroy(crtwin); - break; - - default: - return 1; /* unhandled */ - } - return 0; /* control message handled */ -} - - -/** - * callback for SSL certificate window win32 events - * - * \param hwnd The win32 window handle - * \param msg The win32 message identifier - * \param wparam The w win32 parameter - * \param lparam The l win32 parameter - */ -static LRESULT CALLBACK -nsw32_window_ssl_cert_event_callback(HWND hwnd, - UINT msg, - WPARAM wparam, - LPARAM lparam) -{ - struct nsw32_sslcert_window *crtwin; - crtwin = GetProp(hwnd, TEXT("CertWnd")); - if (crtwin != NULL) { - switch (msg) { - case WM_SIZE: - nsw32_window_ssl_cert_size(hwnd, crtwin); - break; - - case WM_COMMAND: - if (nsw32_window_ssl_cert_command(hwnd, - crtwin, - HIWORD(wparam), - LOWORD(wparam), - (HWND)lparam) == 0) { - return 0; - } - break; - - case WM_CLOSE: - sslcert_viewer_reject(crtwin->ssl_data); - nsw32_crtvrfy_destroy(crtwin); - return 0; - } - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - - -/* exported interface documented in nsw32/ssl_cert.h */ -nserror nsws_create_cert_verify_class(HINSTANCE hInstance) -{ - nserror ret = NSERROR_OK; - WNDCLASSEX wc; - - /* drawable area */ - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = 0; - wc.lpfnWndProc = nsw32_window_ssl_cert_event_callback; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = (HBRUSH)(COLOR_MENU + 1); - wc.lpszMenuName = NULL; - wc.lpszClassName = windowclassname_sslcert; - wc.hIconSm = NULL; - - if (RegisterClassEx(&wc) == 0) { - win_perror("CertVerifyClass"); - ret = NSERROR_INIT_FAILED; - } - - return ret; -} diff --git a/frontends/windows/ssl_cert.h b/frontends/windows/ssl_cert.h deleted file mode 100644 index 6c1f0415a..000000000 --- a/frontends/windows/ssl_cert.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * \file - * Interface to win32 certificate viewing using nsw32 core windows. - */ - -#ifndef NETSURF_WINDOWS_SSL_CERT_H -#define NETSURF_WINDOWS_SSL_CERT_H 1 - -struct nsurl; -struct ssl_cert_info; - -/** - * Prompt the user to verify a certificate with issuse. - * - * \param url The URL being verified. - * \param certs The certificate to be verified - * \param num The number of certificates to be verified. - * \param cb Callback upon user decision. - * \param cbpw Context pointer passed to cb - * \return NSERROR_OK or error code if prompt creation failed. - */ -nserror nsw32_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); - -/** - * Create the ssl viewer window class. - * - * \param hinstance The application instance - * \return NSERROR_OK on success or NSERROR_INIT_FAILED if the class - * creation failed. - */ -nserror nsws_create_cert_verify_class(HINSTANCE hinstance); - -#endif diff --git a/frontends/windows/windbg.h b/frontends/windows/windbg.h index 6cd9f97f8..f09cea9e6 100644 --- a/frontends/windows/windbg.h +++ b/frontends/windows/windbg.h @@ -16,20 +16,25 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _NETSURF_WINDOWS_WINDBG_H_ -#define _NETSURF_WINDOWS_WINDBG_H_ +#ifndef NETSURF_WINDOWS_WINDBG_H +#define NETSURF_WINDOWS_WINDBG_H #include "utils/log.h" const char *msg_num_to_name(int msg); void win_perror(const char *lpszFunction); +/** + * log windows message + * + * log a windows message with symbols converted to human redable + */ #define LOG_WIN_MSG(h, m, w, l) \ if (((m) != WM_SETCURSOR) && \ ((m) != WM_MOUSEMOVE) && \ ((m) != WM_NCHITTEST) && \ ((m) != WM_ENTERIDLE)) \ - NSLOG(netsurf, INFO, \ + NSLOG(netsurf, DEBUG, \ "%s, hwnd %p, w 0x%x, l 0x%Ix", \ msg_num_to_name(m), h, w, l) diff --git a/frontends/windows/window.c b/frontends/windows/window.c index 681b2e282..00e5a7e05 100644 --- a/frontends/windows/window.c +++ b/frontends/windows/window.c @@ -55,43 +55,35 @@ #include "windows/global_history.h" #include "windows/window.h" -/** List of all our gui windows */ +/** + * List of all gui windows + */ static struct gui_window *window_list = NULL; -/** The main window class name */ -static const char windowclassname_main[] = "nswsmainwindow"; +/** + * The main window class name + */ +static const LPCWSTR windowclassname_main = L"nswsmainwindow"; -/** width of the throbber element */ +/** + * width of the throbber element + */ #define NSWS_THROBBER_WIDTH 24 -/** height of the url entry box */ +/** + * height of the url entry box + */ #define NSWS_URLBAR_HEIGHT 23 -/** Number of open windows */ -static int open_windows = 0; - - /** - * Obtain the DPI of the display. - * - * \param hwnd A win32 window handle to get the DPI for - * \return The DPI of the device the window is displayed on. + * height of the Page Information bitmap button */ -static int get_window_dpi(HWND hwnd) -{ - HDC hdc = GetDC(hwnd); - int dpi = GetDeviceCaps(hdc, LOGPIXELSY); - - if (dpi <= 10) { - dpi = 96; /* 96DPI is the default */ - } +#define NSW32_PGIBUTTON_HEIGHT 16 - ReleaseDC(hwnd, hdc); - - NSLOG(netsurf, INFO, "FIX DPI %d", dpi); - - return dpi; -} +/** + * Number of open windows + */ +static int open_windows = 0; /** @@ -152,6 +144,23 @@ static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw) { HWND hwnd; INITCOMMONCONTROLSEX icc; + int xpos = CW_USEDEFAULT; + int ypos = CW_USEDEFAULT; + int width = CW_USEDEFAULT; + int height = CW_USEDEFAULT; + + if ((nsoption_int(window_width) >= 100) && + (nsoption_int(window_height) >= 100) && + (nsoption_int(window_x) >= 0) && + (nsoption_int(window_y) >= 0)) { + xpos = nsoption_int(window_x); + ypos = nsoption_int(window_y); + width = nsoption_int(window_width); + height = nsoption_int(window_height); + + NSLOG(netsurf, DEBUG, "Setting Window position %d,%d %d,%d", + xpos, ypos, width, height); + } icc.dwSize = sizeof(icc); icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES; @@ -163,53 +172,28 @@ static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw) gw->mainmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN)); gw->rclick = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT)); - NSLOG(netsurf, INFO, - "creating hInstance %p GUI window %p", - hInstance, gw); - hwnd = CreateWindowEx(0, - windowclassname_main, - "NetSurf Browser", - WS_OVERLAPPEDWINDOW | - WS_CLIPCHILDREN | - WS_CLIPSIBLINGS | - CS_DBLCLKS, - CW_USEDEFAULT, - CW_USEDEFAULT, - gw->width, - gw->height, - NULL, - gw->mainmenu, - hInstance, - NULL); + hwnd = CreateWindowExW(0, + windowclassname_main, + L"NetSurf Browser", + WS_OVERLAPPEDWINDOW | + WS_CLIPCHILDREN | + WS_CLIPSIBLINGS | + CS_DBLCLKS, + xpos, + ypos, + width, + height, + NULL, + gw->mainmenu, + hInstance, + (LPVOID)gw); if (hwnd == NULL) { NSLOG(netsurf, INFO, "Window create failed"); - return NULL; - } - - /* set the gui window associated with this browser */ - SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw); - - browser_set_dpi(get_window_dpi(hwnd)); - - if ((nsoption_int(window_width) >= 100) && - (nsoption_int(window_height) >= 100) && - (nsoption_int(window_x) >= 0) && - (nsoption_int(window_y) >= 0)) { - NSLOG(netsurf, INFO, - "Setting Window position %d,%d %d,%d", - nsoption_int(window_x), nsoption_int(window_y), - nsoption_int(window_width), nsoption_int(window_height)); - SetWindowPos(hwnd, HWND_TOP, - nsoption_int(window_x), - nsoption_int(window_y), - nsoption_int(window_width), - nsoption_int(window_height), - SWP_SHOWWINDOW); + } else { + nsws_window_set_accels(gw); } - nsws_window_set_accels(gw); - return hwnd; } @@ -230,7 +214,7 @@ nsws_window_toolbar_command(struct gui_window *gw, int identifier, HWND ctrl_window) { - NSLOG(netsurf, INFO, + NSLOG(netsurf, DEBUG, "notification_code %d identifier %d ctrl_window %p", notification_code, identifier, @@ -241,39 +225,39 @@ nsws_window_toolbar_command(struct gui_window *gw, case IDC_MAIN_URLBAR: switch (notification_code) { case EN_CHANGE: - NSLOG(netsurf, INFO, "EN_CHANGE"); + NSLOG(netsurf, DEBUG, "EN_CHANGE"); break; case EN_ERRSPACE: - NSLOG(netsurf, INFO, "EN_ERRSPACE"); + NSLOG(netsurf, DEBUG, "EN_ERRSPACE"); break; case EN_HSCROLL: - NSLOG(netsurf, INFO, "EN_HSCROLL"); + NSLOG(netsurf, DEBUG, "EN_HSCROLL"); break; case EN_KILLFOCUS: - NSLOG(netsurf, INFO, "EN_KILLFOCUS"); + NSLOG(netsurf, DEBUG, "EN_KILLFOCUS"); break; case EN_MAXTEXT: - NSLOG(netsurf, INFO, "EN_MAXTEXT"); + NSLOG(netsurf, DEBUG, "EN_MAXTEXT"); break; case EN_SETFOCUS: - NSLOG(netsurf, INFO, "EN_SETFOCUS"); + NSLOG(netsurf, DEBUG, "EN_SETFOCUS"); break; case EN_UPDATE: - NSLOG(netsurf, INFO, "EN_UPDATE"); + NSLOG(netsurf, DEBUG, "EN_UPDATE"); break; case EN_VSCROLL: - NSLOG(netsurf, INFO, "EN_VSCROLL"); + NSLOG(netsurf, DEBUG, "EN_VSCROLL"); break; default: - NSLOG(netsurf, INFO, "Unknown notification_code"); + NSLOG(netsurf, DEBUG, "Unknown notification_code"); break; } break; @@ -320,7 +304,7 @@ urlbar_dimensions(HWND hWndParent, /** * callback for toolbar events * - * message handler for toolbar window + * subclass message handler for toolbar window * * \param hwnd win32 window handle message arrived for * \param msg The message ID @@ -336,7 +320,11 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) LOG_WIN_MSG(hwnd, msg, wparam, lparam); + toolproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc")); + assert(toolproc != NULL); + gw = nsws_get_gui_window(hwnd); + assert(gw != NULL); switch (msg) { case WM_SIZE: @@ -372,19 +360,15 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return 0; } break; - } - /* remove properties if window is being destroyed */ - if (msg == WM_NCDESTROY) { + case WM_NCDESTROY: + /* remove properties if window is being destroyed */ RemoveProp(hwnd, TEXT("GuiWnd")); - toolproc = (WNDPROC)RemoveProp(hwnd, TEXT("OrigMsgProc")); - } else { - toolproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc")); - } + RemoveProp(hwnd, TEXT("OrigMsgProc")); + /* put the original message handler back */ + SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)toolproc); + break; - if (toolproc == NULL) { - /* the original toolbar procedure is not available */ - return DefWindowProc(hwnd, msg, wparam, lparam); } /* chain to the next handler */ @@ -392,10 +376,21 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } +static void set_urlbar_edit_size(HWND hwnd) +{ + RECT rc; + GetClientRect(hwnd, &rc); + rc.left += NSW32_PGIBUTTON_HEIGHT; + SendMessage(hwnd, EM_SETRECT, 0, (LPARAM)&rc); + NSLOG(netsurf, DEBUG, "left:%ld right:%ld top:%ld bot:%ld", + rc.left,rc.right,rc.top,rc.bottom); +} + + /** * callback for url bar events * - * message handler for urlbar window + * subclass message handler for urlbar window * * \param hwnd win32 window handle message arrived for * \param msg The message ID @@ -408,17 +403,24 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) struct gui_window *gw; WNDPROC urlproc; HFONT hFont; + LRESULT result; LOG_WIN_MSG(hwnd, msg, wparam, lparam); - gw = nsws_get_gui_window(hwnd); - urlproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc")); + assert(urlproc != NULL); + + gw = nsws_get_gui_window(hwnd); + assert(gw != NULL); /* override messages */ switch (msg) { case WM_CHAR: - if (wparam == 13) { + if (wparam == 1) { + /* handle ^A */ + SendMessage(hwnd, EM_SETSEL, 0, -1); + return 1; + } else if (wparam == 13) { SendMessage(gw->main, WM_COMMAND, IDC_MAIN_LAUNCH_URL, 0); return 0; } @@ -430,25 +432,27 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) NSLOG(netsurf, INFO, "Destroyed font object"); DeleteObject(hFont); } - + fallthrough; case WM_NCDESTROY: /* remove properties if window is being destroyed */ RemoveProp(hwnd, TEXT("GuiWnd")); RemoveProp(hwnd, TEXT("OrigMsgProc")); + /* put the original message handler back */ + SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)urlproc); break; - } - if (urlproc == NULL) { - /* the original toolbar procedure is not available */ - return DefWindowProc(hwnd, msg, wparam, lparam); + case WM_SIZE: + result = CallWindowProc(urlproc, hwnd, msg, wparam, lparam); + set_urlbar_edit_size(hwnd); + return result; + } /* chain to the next handler */ return CallWindowProc(urlproc, hwnd, msg, wparam, lparam); } - /** * create a urlbar and message handler * @@ -466,6 +470,7 @@ nsws_window_urlbar_create(HINSTANCE hInstance, { int urlx, urly, urlwidth, urlheight; HWND hwnd; + HWND hbutton; WNDPROC urlproc; HFONT hFont; @@ -478,7 +483,8 @@ nsws_window_urlbar_create(HINSTANCE hInstance, hwnd = CreateWindowEx(0L, TEXT("Edit"), NULL, - WS_CHILD | WS_BORDER | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL, + WS_CHILD | WS_BORDER | WS_VISIBLE | + ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE, urlx, urly, urlwidth, @@ -486,7 +492,7 @@ nsws_window_urlbar_create(HINSTANCE hInstance, hWndParent, (HMENU)IDC_MAIN_URLBAR, hInstance, - 0); + NULL); if (hwnd == NULL) { return NULL; @@ -512,6 +518,28 @@ nsws_window_urlbar_create(HINSTANCE hInstance, SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0); } + + /* Create the page info button */ + hbutton = CreateWindowEx(0L, + TEXT("BUTTON"), + NULL, + WS_CHILD | WS_VISIBLE | BS_BITMAP | BS_FLAT, + (NSWS_URLBAR_HEIGHT - NSW32_PGIBUTTON_HEIGHT) /2, + (NSWS_URLBAR_HEIGHT - NSW32_PGIBUTTON_HEIGHT) /2, + NSW32_PGIBUTTON_HEIGHT, + NSW32_PGIBUTTON_HEIGHT, + hwnd, + (HMENU)IDC_PAGEINFO, + hInstance, + NULL); + + /* put a property on the parent toolbar so it can set the page info */ + SetProp(hWndParent, TEXT("hPGIbutton"), (HANDLE)hbutton); + + SendMessageW(hbutton, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)gw->hPageInfo[PAGE_STATE_UNKNOWN]); + + set_urlbar_edit_size(hwnd); + NSLOG(netsurf, INFO, "Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d", hwnd, urlx, urly, urlwidth, urlheight); @@ -645,7 +673,7 @@ nsws_window_create_toolbar(HINSTANCE hInstance, hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, "Toolbar", - WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT, + WS_CHILD | TBSTYLE_FLAT, 0, 0, 0, 0, hWndParent, NULL, @@ -710,15 +738,21 @@ nsws_window_create_toolbar(HINSTANCE hInstance, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); + SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)gw->toolbuttonc, (LPARAM)&tbButtons); + /* create url widget */ gw->urlbar = nsws_window_urlbar_create(hInstance, hWndToolbar, gw); + /* create throbber widget */ gw->throbber = nsws_window_throbber_create(hInstance, hWndToolbar, gw); + SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0); + ShowWindow(hWndToolbar, TRUE); + return hWndToolbar; } @@ -907,8 +941,8 @@ win32_window_invalidate_area(struct gui_window *gw, const struct rect *rect) if (rect != NULL) { redrawrectp = &redrawrect; - redrawrect.left = (long)rect->x0 - (gw->scrollx / gw->scale); - redrawrect.top = (long)rect->y0 - (gw->scrolly / gw->scale); + redrawrect.left = (long)rect->x0 - gw->scrollx; + redrawrect.top = (long)rect->y0 - gw->scrolly; redrawrect.right =(long)rect->x1; redrawrect.bottom = (long)rect->y1; @@ -923,36 +957,6 @@ win32_window_invalidate_area(struct gui_window *gw, const struct rect *rect) /** - * Set scale of a win32 browser window - * - * \param gw win32 frontend window context - * \param scale The new scale - */ -static void nsws_set_scale(struct gui_window *gw, float scale) -{ - struct rect rect; - - assert(gw != NULL); - - if (gw->scale == scale) { - return; - } - - rect.x0 = rect.x1 = gw->scrollx; - rect.y0 = rect.y1 = gw->scrolly; - - gw->scale = scale; - - if (gw->bw != NULL) { - browser_window_set_scale(gw->bw, scale, true); - } - - win32_window_invalidate_area(gw, NULL); - win32_window_set_scroll(gw, &rect); -} - - -/** * Create a new window due to menu selection * * \param gw frontends graphical window. @@ -1056,48 +1060,35 @@ nsws_window_command(HWND hwnd, break; case IDM_EDIT_CUT: - OpenClipboard(gw->main); - EmptyClipboard(); - CloseClipboard(); if (GetFocus() == gw->urlbar) { SendMessage(gw->urlbar, WM_CUT, 0, 0); - } else if (gw->bw != NULL) { - browser_window_key_press(gw->bw, NS_KEY_CUT_SELECTION); + } else { + SendMessage(gw->drawingarea, WM_CUT, 0, 0); } break; case IDM_EDIT_COPY: - OpenClipboard(gw->main); - EmptyClipboard(); - CloseClipboard(); if (GetFocus() == gw->urlbar) { SendMessage(gw->urlbar, WM_COPY, 0, 0); - } else if (gw->bw != NULL) { - browser_window_key_press(gw->bw, NS_KEY_COPY_SELECTION); + } else { + SendMessage(gw->drawingarea, WM_COPY, 0, 0); } break; case IDM_EDIT_PASTE: { - OpenClipboard(gw->main); - HANDLE h = GetClipboardData(CF_TEXT); - if (h != NULL) { - char *content = GlobalLock(h); - NSLOG(netsurf, INFO, "pasting %s\n", content); - GlobalUnlock(h); - } - CloseClipboard(); - if (GetFocus() == gw->urlbar) + if (GetFocus() == gw->urlbar) { SendMessage(gw->urlbar, WM_PASTE, 0, 0); - else - browser_window_key_press(gw->bw, NS_KEY_PASTE); + } else { + SendMessage(gw->drawingarea, WM_PASTE, 0, 0); + } break; } case IDM_EDIT_DELETE: if (GetFocus() == gw->urlbar) - SendMessage(gw->urlbar, WM_CUT, 0, 0); + SendMessage(gw->urlbar, WM_CLEAR, 0, 0); else - browser_window_key_press(gw->bw, NS_KEY_DELETE_RIGHT); + SendMessage(gw->drawingarea, WM_CLEAR, 0, 0); break; case IDM_EDIT_SELECT_ALL: @@ -1133,9 +1124,10 @@ nsws_window_command(HWND hwnd, case IDM_NAV_HOME: { nsurl *url; + ret = nsurl_create(nsoption_charp(homepage_url), &url); - if (nsurl_create(nsoption_charp(homepage_url), &url) != NSERROR_OK) { - win32_warning("NoMemory", 0); + if (ret != NSERROR_OK) { + win32_report_nserror(ret, 0); } else { browser_window_navigate(gw->bw, url, @@ -1166,7 +1158,7 @@ nsws_window_command(HWND hwnd, break; case IDM_TOOLS_COOKIES: - nsw32_cookies_present(hinst); + nsw32_cookies_present(NULL); break; case IDM_NAV_BOOKMARKS: @@ -1174,15 +1166,15 @@ nsws_window_command(HWND hwnd, break; case IDM_VIEW_ZOOMPLUS: - nsws_set_scale(gw, gw->scale * 1.1); + browser_window_set_scale(gw->bw, 0.1, false); break; case IDM_VIEW_ZOOMMINUS: - nsws_set_scale(gw, gw->scale * 0.9); + browser_window_set_scale(gw->bw, -0.1, false); break; case IDM_VIEW_ZOOMNORMAL: - nsws_set_scale(gw, 1.0); + browser_window_set_scale(gw->bw, 1.0, true); break; case IDM_VIEW_SOURCE: @@ -1258,17 +1250,17 @@ nsws_window_command(HWND hwnd, case IDM_HELP_CONTENTS: nsws_window_go(hwnd, - "http://www.netsurf-browser.org/documentation/"); + "https://www.netsurf-browser.org/documentation/"); break; case IDM_HELP_GUIDE: nsws_window_go(hwnd, - "http://www.netsurf-browser.org/documentation/guide"); + "https://www.netsurf-browser.org/documentation/guide"); break; case IDM_HELP_INFO: nsws_window_go(hwnd, - "http://www.netsurf-browser.org/documentation/info"); + "https://www.netsurf-browser.org/documentation/info"); break; case IDM_HELP_ABOUT: @@ -1278,6 +1270,7 @@ nsws_window_command(HWND hwnd, case IDC_MAIN_LAUNCH_URL: { nsurl *url; + nserror err; if (GetFocus() != gw->urlbar) break; @@ -1287,8 +1280,10 @@ nsws_window_command(HWND hwnd, SendMessage(gw->urlbar, WM_GETTEXT, (WPARAM)(len + 1), (LPARAM)addr); NSLOG(netsurf, INFO, "launching %s\n", addr); - if (nsurl_create(addr, &url) != NSERROR_OK) { - win32_warning("NoMemory", 0); + err = nsurl_create(addr, &url); + + if (err != NSERROR_OK) { + win32_report_nserror(err, 0); } else { browser_window_navigate(gw->bw, url, @@ -1373,8 +1368,6 @@ nsws_window_resize(struct gui_window *gw, } nsws_window_update_forward_back(gw); - browser_window_update(gw->bw, false); - if (gw->toolbar != NULL) { SendMessage(gw->toolbar, TB_SETSTATE, (WPARAM) IDM_NAV_STOP, @@ -1398,12 +1391,30 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { struct gui_window *gw; RECT rmain; + LPCREATESTRUCTW createstruct; LOG_WIN_MSG(hwnd, msg, wparam, lparam); - /* deal with window creation as a special case */ - if (msg == WM_CREATE) { - /* To cause all the component child windows to be + gw = nsws_get_gui_window(hwnd); + + switch (msg) { + case WM_NCCREATE: /* non client area create */ + /* gw is passed as the lpParam from createwindowex() */ + createstruct = (LPCREATESTRUCTW)lparam; + gw = (struct gui_window *)createstruct->lpCreateParams; + + /* set the gui window associated with this window handle */ + SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw); + + NSLOG(netsurf, INFO, + "created hWnd:%p hInstance %p GUI window %p", + hwnd, createstruct->hInstance, gw); + + break; + + case WM_CREATE: + /* + * To cause all the component child windows to be * re-sized correctly a WM_SIZE message of the actual * created size must be sent. * @@ -1412,19 +1423,9 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) * until after the WM_CREATE message is dispatched. */ GetClientRect(hwnd, &rmain); - PostMessage(hwnd, WM_SIZE, 0, MAKELPARAM(rmain.right, rmain.bottom)); - return DefWindowProc(hwnd, msg, wparam, lparam); - } - - - gw = nsws_get_gui_window(hwnd); - if (gw == NULL) { - NSLOG(netsurf, INFO, - "Unable to find gui window structure for hwnd %p", hwnd); - return DefWindowProc(hwnd, msg, wparam, lparam); - } - - switch (msg) { + PostMessage(hwnd, WM_SIZE, 0, + MAKELPARAM(rmain.right, rmain.bottom)); + break; case WM_CONTEXTMENU: if (nsws_ctx_menu(gw, hwnd, GET_X_LPARAM(lparam), @@ -1454,7 +1455,64 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } - return DefWindowProc(hwnd, msg, wparam, lparam); + return DefWindowProcW(hwnd, msg, wparam, lparam); +} + +static void destroy_page_info_bitmaps(struct gui_window *gw) +{ + DeleteObject(gw->hPageInfo[PAGE_STATE_UNKNOWN]); + DeleteObject(gw->hPageInfo[PAGE_STATE_INTERNAL]); + DeleteObject(gw->hPageInfo[PAGE_STATE_LOCAL]); + DeleteObject(gw->hPageInfo[PAGE_STATE_INSECURE]); + DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE_OVERRIDE]); + DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE_ISSUES]); + DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE]); +} + +static void load_page_info_bitmaps(HINSTANCE hInstance, struct gui_window *gw) +{ + gw->hPageInfo[PAGE_STATE_UNKNOWN] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_INTERNAL), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_INTERNAL] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_INTERNAL), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_LOCAL] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_LOCAL), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_INSECURE] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_INSECURE), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_SECURE_OVERRIDE] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_WARNING), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_SECURE_ISSUES] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_WARNING), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); + gw->hPageInfo[PAGE_STATE_SECURE] = LoadImage(hInstance, + MAKEINTRESOURCE(IDB_PAGEINFO_SECURE), + IMAGE_BITMAP, + 0, + 0, + LR_DEFAULTCOLOR); } @@ -1485,12 +1543,13 @@ win32_window_create(struct browser_window *bw, gw->width = 800; gw->height = 600; - gw->scale = 1.0; gw->toolbuttonsize = 24; gw->requestscrollx = 0; gw->requestscrolly = 0; gw->localhistory = NULL; + load_page_info_bitmaps(hinst, gw); + gw->mouse = malloc(sizeof(struct browser_mouse)); if (gw->mouse == NULL) { free(gw); @@ -1549,6 +1608,8 @@ static void win32_window_destroy(struct gui_window *w) DestroyAcceleratorTable(w->acceltable); + destroy_page_info_bitmaps(w); + free(w); w = NULL; } @@ -1560,12 +1621,10 @@ static void win32_window_destroy(struct gui_window *w) * \param gw gui_window to measure * \param width receives width of window * \param height receives height of window - * \param scaled whether to return scaled values + * \return NSERROR_OK and width and height updated */ static nserror -win32_window_get_dimensions(struct gui_window *gw, - int *width, int *height, - bool scaled) +win32_window_get_dimensions(struct gui_window *gw, int *width, int *height) { *width = gw->width; *height = gw->height; @@ -1582,9 +1641,12 @@ win32_window_get_dimensions(struct gui_window *gw, * * \param w gui_window to update the extent of */ -static void win32_window_update_extent(struct gui_window *w) +static void win32_window_update_extent(struct gui_window *gw) { - + struct rect rect; + rect.x0 = rect.x1 = gw->scrollx; + rect.y0 = rect.y1 = gw->scrolly; + win32_window_set_scroll(gw, &rect); } @@ -1597,6 +1659,8 @@ static void win32_window_update_extent(struct gui_window *w) static void win32_window_set_title(struct gui_window *w, const char *title) { char *fulltitle; + int wlen; + LPWSTR enctitle; if (w == NULL) { return; @@ -1605,14 +1669,32 @@ static void win32_window_set_title(struct gui_window *w, const char *title) NSLOG(netsurf, INFO, "%p, title %s", w, title); fulltitle = malloc(strlen(title) + SLEN(" - NetSurf") + 1); if (fulltitle == NULL) { - win32_warning("NoMemory", 0); + NSLOG(netsurf, ERROR, "%s", + messages_get_errorcode(NSERROR_NOMEM)); return; } strcpy(fulltitle, title); strcat(fulltitle, " - NetSurf"); - SendMessage(w->main, WM_SETTEXT, 0, (LPARAM)fulltitle); + wlen = MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, NULL, 0); + if (wlen == 0) { + NSLOG(netsurf, ERROR, "failed encoding \"%s\"", fulltitle); + free(fulltitle); + return; + } + + enctitle = malloc(2 * (wlen + 1)); + if (enctitle == NULL) { + NSLOG(netsurf, ERROR, "%s encoding \"%s\" len %d", + messages_get_errorcode(NSERROR_NOMEM), fulltitle, wlen); + free(fulltitle); + return; + } + + MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, enctitle, wlen); + SetWindowTextW(w->main, enctitle); + free(enctitle); free(fulltitle); } @@ -1676,9 +1758,8 @@ win32_window_place_caret(struct gui_window *w, int x, int y, return; } - CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height * w->scale); - SetCaretPos(x * w->scale - w->scrollx, - y * w->scale - w->scrolly); + CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height ); + SetCaretPos(x - w->scrollx, y - w->scrolly); ShowCaret(w->drawingarea); } @@ -1763,6 +1844,62 @@ static void win32_window_stop_throbber(struct gui_window *w) /** + * win32 page info change. + * + * \param gw window to chnage info on + */ +static void win32_window_page_info_change(struct gui_window *gw) +{ + HWND hbutton; + browser_window_page_info_state pistate; + + hbutton = GetProp(gw->toolbar, TEXT("hPGIbutton")); + + pistate = browser_window_get_page_info_state(gw->bw); + + SendMessageW(hbutton, BM_SETIMAGE, IMAGE_BITMAP, + (LPARAM)gw->hPageInfo[pistate]); +} + + +/** + * process miscellaneous window events + * + * \param gw The window receiving the event. + * \param event The event code. + * \return NSERROR_OK when processed ok + */ +static nserror +win32_window_event(struct gui_window *gw, enum gui_window_event event) +{ + switch (event) { + case GW_EVENT_UPDATE_EXTENT: + win32_window_update_extent(gw); + break; + + case GW_EVENT_REMOVE_CARET: + win32_window_remove_caret(gw); + break; + + case GW_EVENT_START_THROBBER: + win32_window_start_throbber(gw); + break; + + case GW_EVENT_STOP_THROBBER: + win32_window_stop_throbber(gw); + break; + + case GW_EVENT_PAGE_INFO_CHANGE: + win32_window_page_info_change(gw); + break; + + default: + break; + } + return NSERROR_OK; +} + +/** * win32 frontend browser window handling operation table */ static struct gui_window_table window_table = { @@ -1772,16 +1909,13 @@ static struct gui_window_table window_table = { .get_scroll = win32_window_get_scroll, .set_scroll = win32_window_set_scroll, .get_dimensions = win32_window_get_dimensions, - .update_extent = win32_window_update_extent, + .event = win32_window_event, .set_title = win32_window_set_title, .set_url = win32_window_set_url, .set_status = win32_window_set_status, .set_pointer = win32_window_set_pointer, .place_caret = win32_window_place_caret, - .remove_caret = win32_window_remove_caret, - .start_throbber = win32_window_start_throbber, - .stop_throbber = win32_window_stop_throbber, }; struct gui_window_table *win32_window_table = &window_table; @@ -1821,13 +1955,15 @@ bool nsws_window_go(HWND hwnd, const char *urltxt) { struct gui_window *gw; nsurl *url; + nserror ret; gw = nsws_get_gui_window(hwnd); if (gw == NULL) return false; + ret = nsurl_create(urltxt, &url); - if (nsurl_create(urltxt, &url) != NSERROR_OK) { - win32_warning("NoMemory", 0); + if (ret != NSERROR_OK) { + win32_report_nserror(ret, 0); } else { browser_window_navigate(gw->bw, url, @@ -1947,7 +2083,7 @@ nserror nsws_create_main_class(HINSTANCE hinstance) { nserror ret = NSERROR_OK; - WNDCLASSEX wc; + WNDCLASSEXW wc; /* main window */ wc.cbSize = sizeof(WNDCLASSEX); @@ -1963,7 +2099,7 @@ nsws_create_main_class(HINSTANCE hinstance) wc.lpszClassName = windowclassname_main; wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); - if (RegisterClassEx(&wc) == 0) { + if (RegisterClassExW(&wc) == 0) { win_perror("MainWindowClass"); ret = NSERROR_INIT_FAILED; } diff --git a/frontends/windows/window.h b/frontends/windows/window.h index 3cdb9aefe..97be710f3 100644 --- a/frontends/windows/window.h +++ b/frontends/windows/window.h @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _NETSURF_WINDOWS_WINDOW_H_ -#define _NETSURF_WINDOWS_WINDOW_H_ +#ifndef NETSURF_WINDOWS_WINDOW_H_ +#define NETSURF_WINDOWS_WINDOW_H_ /** The window operation function table for win32 */ extern struct gui_window_table *win32_window_table; @@ -26,8 +26,7 @@ extern struct gui_window_table *win32_window_table; struct browser_mouse { struct gui_window *gui; - struct box *box; - + double pressed_x; double pressed_y; bool waiting; @@ -62,7 +61,7 @@ struct gui_window { HACCEL acceltable; /**< accelerators */ - float scale; /**< scale of content */ + HBITMAP hPageInfo[8]; /**< page info handles */ int scrollx; /**< current scroll location */ int scrolly; /**< current scroll location */ |