diff options
Diffstat (limited to 'frontends/windows/window.c')
-rw-r--r-- | frontends/windows/window.c | 560 |
1 files changed, 347 insertions, 213 deletions
diff --git a/frontends/windows/window.c b/frontends/windows/window.c index 90d076812..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); @@ -534,7 +562,6 @@ nsws_window_throbber_create(HINSTANCE hInstance, struct gui_window *gw) { HWND hwnd; - char avi[PATH_MAX]; int urlx, urly, urlwidth, urlheight; urlbar_dimensions(hWndParent, @@ -554,9 +581,8 @@ nsws_window_throbber_create(HINSTANCE hInstance, hInstance, NULL); - nsws_find_resource(avi, "throbber.avi", "windows/res/throbber.avi"); - NSLOG(netsurf, INFO, "setting throbber avi as %s", avi); - Animate_Open(hwnd, avi); + Animate_Open(hwnd, MAKEINTRESOURCE(IDR_THROBBER_AVI)); + if (gw->throbbing) { Animate_Play(hwnd, 0, -1, -1); } else { @@ -647,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, @@ -712,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; } @@ -909,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; @@ -925,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. @@ -1058,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: @@ -1135,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, @@ -1168,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: @@ -1176,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: @@ -1260,26 +1250,27 @@ 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: - nsws_about_dialog_init(hinst, gw->main); + nsw32_about_dialog_init(hinst, gw->main); break; case IDC_MAIN_LAUNCH_URL: { nsurl *url; + nserror err; if (GetFocus() != gw->urlbar) break; @@ -1289,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, @@ -1375,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, @@ -1400,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. * @@ -1414,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), @@ -1456,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); } @@ -1487,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); @@ -1551,6 +1608,8 @@ static void win32_window_destroy(struct gui_window *w) DestroyAcceleratorTable(w->acceltable); + destroy_page_info_bitmaps(w); + free(w); w = NULL; } @@ -1562,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; @@ -1584,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); } @@ -1599,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; @@ -1607,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); } @@ -1678,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); } @@ -1765,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 = { @@ -1774,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; @@ -1823,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, @@ -1949,7 +2083,7 @@ nserror nsws_create_main_class(HINSTANCE hinstance) { nserror ret = NSERROR_OK; - WNDCLASSEX wc; + WNDCLASSEXW wc; /* main window */ wc.cbSize = sizeof(WNDCLASSEX); @@ -1965,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; } |