From 2ca6e9a3e6bd7450cd1fb80db3a777956c804e11 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 3 Apr 2011 22:01:37 +0000 Subject: split out drawable window handling extensive cleanups fix localhistory svn path=/trunk/netsurf/; revision=12153 --- windows/Makefile.target | 7 +- windows/download.c | 2 +- windows/drawable.c | 621 +++++++++++++++++++++++++++++++++ windows/drawable.h | 25 ++ windows/gui.c | 907 +++++------------------------------------------- windows/gui.h | 17 +- windows/localhistory.c | 558 ++++++++++++++--------------- windows/localhistory.h | 12 +- windows/main.c | 163 +++++++++ windows/plot.c | 82 ++--- windows/windbg.h | 2 +- windows/window.c | 52 +++ windows/window.h | 83 +++++ 13 files changed, 1366 insertions(+), 1165 deletions(-) create mode 100644 windows/drawable.c create mode 100644 windows/drawable.h create mode 100644 windows/main.c create mode 100644 windows/window.c create mode 100644 windows/window.h diff --git a/windows/Makefile.target b/windows/Makefile.target index 332d1df09..c0a7a757e 100644 --- a/windows/Makefile.target +++ b/windows/Makefile.target @@ -59,9 +59,10 @@ S_RESOURCES := windows_resource.o # ---------------------------------------------------------------------------- # S_WINDOWS are sources purely for the windows build -S_WINDOWS := about.c bitmap.c download.c filetype.c findfile.c font.c \ - gui.c localhistory.c login.c misc.c plot.c prefs.c schedule.c \ - thumbnail.c tree.c windbg.c system_colour.c +S_WINDOWS := main.c window.c gui.c drawable.c misc.c plot.c findfile.c \ + font.c bitmap.c about.c prefs.c download.c filetype.c \ + localhistory.c login.c schedule.c thumbnail.c tree.c \ + windbg.c system_colour.c S_WINDOWS := $(addprefix windows/,$(S_WINDOWS)) SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_WINDOWS) $(S_RESOURCES) diff --git a/windows/download.c b/windows/download.c index 21e816087..e9ab28b97 100644 --- a/windows/download.c +++ b/windows/download.c @@ -137,7 +137,7 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui) bool nsws_download_window_up(struct gui_download_window *w) { - w->hwnd = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD), + w->hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD), gui_window_main_window(w->window), nsws_download_event_callback); if (w->hwnd == NULL) { diff --git a/windows/drawable.c b/windows/drawable.c new file mode 100644 index 000000000..0082da91b --- /dev/null +++ b/windows/drawable.c @@ -0,0 +1,621 @@ +/* + * Copyright 2011 Vincent Sanders + * + * 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 . + */ + +#include + +#include +#include + +#include "desktop/browser.h" +#include "desktop/textinput.h" +#include "utils/errors.h" +#include "utils/log.h" +#include "utils/utils.h" + +#include "windows/windbg.h" +#include "windows/plot.h" +#include "windows/window.h" +#include "windows/localhistory.h" +#include "windows/drawable.h" + +static const char windowclassname_drawable[] = "nswsdrawablewindow"; + +/** + * Handle wheel scroll messages. + */ +static LRESULT +nsws_drawable_wheel(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ + int i, z = GET_WHEEL_DELTA_WPARAM(wparam) / WHEEL_DELTA; + int key = LOWORD(wparam); + DWORD command; + unsigned int newmessage = WM_VSCROLL; + + if (key == MK_SHIFT) { + command = (z > 0) ? SB_LINERIGHT : SB_LINELEFT; + newmessage = WM_HSCROLL; + } else { + /* add MK_CONTROL -> zoom */ + command = (z > 0) ? SB_LINEUP : SB_LINEDOWN; + } + + z = (z < 0) ? -1 * z : z; + + for (i = 0; i < z; i++) { + SendMessage(hwnd, newmessage, MAKELONG(command, 0), 0); + } + + return 0; +} + +/** + * Handle vertical scroll messages. + */ +static LRESULT +nsws_drawable_vscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ + SCROLLINFO si; + int mem; + + LOG(("VSCROLL %d", gw->requestscrolly)); + + if (gw->requestscrolly != 0) + return 0; + + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + GetScrollInfo(hwnd, SB_VERT, &si); + mem = si.nPos; + + switch (LOWORD(wparam)) { + case SB_TOP: + si.nPos = si.nMin; + break; + + case SB_BOTTOM: + si.nPos = si.nMax; + break; + + case SB_LINEUP: + si.nPos -= 30; + break; + + case SB_LINEDOWN: + si.nPos += 30; + break; + + case SB_PAGEUP: + si.nPos -= gw->height; + break; + + case SB_PAGEDOWN: + si.nPos += gw->height; + break; + + case SB_THUMBTRACK: + si.nPos = si.nTrackPos; + break; + + default: + break; + } + + si.fMask = SIF_POS; + if ((gw->bw != NULL) && (gw->bw->current_content != NULL)) { + si.nPos = min(si.nPos, + content_get_height(gw->bw->current_content) * + gw->bw->scale - gw->height); + } + + si.nPos = max(si.nPos, 0); + SetScrollInfo(hwnd, SB_VERT, &si, TRUE); + GetScrollInfo(hwnd, SB_VERT, &si); + if (si.nPos != mem) { + gui_window_set_scroll(gw, gw->scrollx, gw->scrolly + + gw->requestscrolly + si.nPos - mem); + } + + return 0; +} + + +/** + * Handle horizontal scroll messages. + */ +static LRESULT +nsws_drawable_hscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ + SCROLLINFO si; + int mem; + + LOG(("HSCROLL %d", gw->requestscrollx)); + + if (gw->requestscrollx != 0) + return 0; + + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + GetScrollInfo(hwnd, SB_HORZ, &si); + mem = si.nPos; + + switch (LOWORD(wparam)) { + case SB_LINELEFT: + si.nPos -= 30; + break; + + case SB_LINERIGHT: + si.nPos += 30; + break; + + case SB_PAGELEFT: + si.nPos -= gw->width; + break; + + case SB_PAGERIGHT: + si.nPos += gw->width; + break; + + case SB_THUMBTRACK: + si.nPos = si.nTrackPos; + break; + + default: + break; + } + + si.fMask = SIF_POS; + + if ((gw->bw != NULL) && (gw->bw->current_content != NULL)) { + si.nPos = min(si.nPos, + content_get_width(gw->bw->current_content) * + gw->bw->scale - gw->width); + } + si.nPos = max(si.nPos, 0); + SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); + GetScrollInfo(hwnd, SB_HORZ, &si); + if (si.nPos != mem) { + gui_window_set_scroll(gw, + gw->scrollx + gw->requestscrollx + si.nPos - mem, + gw->scrolly); + } + + return 0; +} + +/** + * Handle resize events. + */ +static LRESULT +nsws_drawable_resize(struct gui_window *gw) +{ + browser_window_reformat(gw->bw, gw->width, gw->height); + return 0; +} + +/** + * Handle key press messages. + */ +static LRESULT +nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam) +{ + if (GetFocus() != hwnd) + return 0 ; + + uint32_t i; + bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); + bool capslock = ((GetKeyState(VK_CAPITAL) & 1) == 1); + + switch(wparam) { + case VK_LEFT: + i = KEY_LEFT; + if (shift) + SendMessage(hwnd, WM_HSCROLL, + MAKELONG(SB_LINELEFT, 0), 0); + break; + + case VK_RIGHT: + i = KEY_RIGHT; + if (shift) + SendMessage(hwnd, WM_HSCROLL, + MAKELONG(SB_LINERIGHT, 0), 0); + break; + + case VK_UP: + i = KEY_UP; + if (shift) + SendMessage(hwnd, WM_VSCROLL, + MAKELONG(SB_LINEUP, 0), 0); + break; + + case VK_DOWN: + i = KEY_DOWN; + if (shift) + SendMessage(hwnd, WM_VSCROLL, + MAKELONG(SB_LINEDOWN, 0), 0); + break; + + case VK_HOME: + i = KEY_LINE_START; + if (shift) + SendMessage(hwnd, WM_HSCROLL, + MAKELONG(SB_PAGELEFT, 0), 0); + break; + + case VK_END: + i = KEY_LINE_END; + if (shift) + SendMessage(hwnd, WM_HSCROLL, + MAKELONG(SB_PAGERIGHT, 0), 0); + break; + + case VK_DELETE: + i = KEY_DELETE_RIGHT; + break; + + case VK_NEXT: + i = wparam; + SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), + 0); + break; + + case VK_PRIOR: + i = wparam; + SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), + 0); + break; + + default: + i = wparam; + break; + } + + if ((i >= 'A') && + (i <= 'Z') && + (((!capslock) && (!shift)) || ((capslock) && (shift)))) { + i += 'a' - 'A'; + } + + if (gw != NULL) + browser_window_key_press(gw->bw, i); + + return 0; +} + + +/** + * Handle paint messages. + */ +static LRESULT +nsws_drawable_paint(struct gui_window *gw, HWND hwnd) +{ + struct rect clip; + PAINTSTRUCT ps; + + BeginPaint(hwnd, &ps); + + if (gw != NULL) { + plot_hdc = ps.hdc; + + clip.x0 = ps.rcPaint.left; + clip.y0 = ps.rcPaint.top; + clip.x1 = ps.rcPaint.right; + clip.y1 = ps.rcPaint.bottom; + + browser_window_redraw(gw->bw, + -gw->scrollx / gw->bw->scale, + -gw->scrolly / gw->bw->scale, + &clip); + } + + EndPaint(hwnd, &ps); + + return 0; +} + + +/** + * Handle mouse button up messages. + */ +static LRESULT +nsws_drawable_mouseup(struct gui_window *gw, + int x, + int y, + browser_mouse_state press, + browser_mouse_state click) +{ + bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); + bool ctrl = ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000); + bool alt = ((GetKeyState(VK_MENU) & 0x8000) == 0x8000); + + if ((gw == NULL) || + (gw->mouse == NULL) || + (gw->bw == NULL)) + return 0; + + LOG(("state 0x%x, press 0x%x", gw->mouse->state, press)); + if ((gw->mouse->state & press) != 0) { + gw->mouse->state &= ~press; + gw->mouse->state |= click; + } + + if (((gw->mouse->state & BROWSER_MOUSE_MOD_1) != 0) && !shift) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_1; + if (((gw->mouse->state & BROWSER_MOUSE_MOD_2) != 0) && !ctrl) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_2; + if (((gw->mouse->state & BROWSER_MOUSE_MOD_3) != 0) && !alt) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_3; + + if ((gw->mouse->state & click) != 0) { + LOG(("mouse click bw %p, state 0x%x, x %f, y %f",gw->bw, + gw->mouse->state, + (x + gw->scrollx) / gw->bw->scale, + (y + gw->scrolly) / gw->bw->scale)); + + browser_window_mouse_click(gw->bw, + gw->mouse->state, + (x + gw->scrollx) / gw->bw->scale, + (y + gw->scrolly) / gw->bw->scale); + } else { + browser_window_mouse_drag_end(gw->bw, + 0, + (x + gw->scrollx) / gw->bw->scale, + (y + gw->scrolly) / gw->bw->scale); + } + + gw->mouse->state = 0; + return 0; +} + + +/** + * Handle mouse button down messages. + */ +static LRESULT +nsws_drawable_mousedown(struct gui_window *gw, + int x, int y, + browser_mouse_state button) +{ + if ((gw == NULL) || + (gw->mouse == NULL) || + (gw->bw == NULL)) { + nsws_localhistory_close(gw); + return 0; + } + + gw->mouse->state = button; + if ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000) + gw->mouse->state |= BROWSER_MOUSE_MOD_1; + if ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000) + gw->mouse->state |= BROWSER_MOUSE_MOD_2; + if ((GetKeyState(VK_MENU) & 0x8000) == 0x8000) + gw->mouse->state |= BROWSER_MOUSE_MOD_3; + + gw->mouse->pressed_x = (x + gw->scrollx) / gw->bw->scale; + gw->mouse->pressed_y = (y + gw->scrolly) / gw->bw->scale; + + LOG(("mouse click bw %p, state %x, x %f, y %f", gw->bw, + gw->mouse->state, + (x + gw->scrollx) / gw->bw->scale, + (y + gw->scrolly) / gw->bw->scale)); + + browser_window_mouse_click(gw->bw, gw->mouse->state, + (x + gw->scrollx) / gw->bw->scale , + (y + gw->scrolly) / gw->bw->scale); + + return 0; +} + +/** + * Handle mouse movement messages. + */ +static LRESULT +nsws_drawable_mousemove(struct gui_window *gw, int x, int y) +{ + bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); + bool ctrl = ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000); + bool alt = ((GetKeyState(VK_MENU) & 0x8000) == 0x8000); + + if ((gw == NULL) || (gw->mouse == NULL) || (gw->bw == NULL)) + return 0; + + /* scale co-ordinates */ + x = (x + gw->scrollx) / gw->bw->scale; + y = (y + gw->scrolly) / gw->bw->scale; + + /* if mouse button held down and pointer moved more than + * minimum distance drag is happening */ + if (((gw->mouse->state & (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_PRESS_2)) != 0) && + (abs(x - gw->mouse->pressed_x) >= 5) && + (abs(y - gw->mouse->pressed_y) >= 5)) { + + LOG(("Drag start state 0x%x", gw->mouse->state)); + + if ((gw->mouse->state & BROWSER_MOUSE_PRESS_1) != 0) { + browser_window_mouse_click(gw->bw, BROWSER_MOUSE_DRAG_1, + gw->mouse->pressed_x, + gw->mouse->pressed_y); + gw->mouse->state &= ~BROWSER_MOUSE_PRESS_1; + gw->mouse->state |= BROWSER_MOUSE_HOLDING_1 | + BROWSER_MOUSE_DRAG_ON; + } + else if ((gw->mouse->state & BROWSER_MOUSE_PRESS_2) != 0) { + browser_window_mouse_click(gw->bw, BROWSER_MOUSE_DRAG_2, + gw->mouse->pressed_x, + gw->mouse->pressed_y); + gw->mouse->state &= ~BROWSER_MOUSE_PRESS_2; + gw->mouse->state |= BROWSER_MOUSE_HOLDING_2 | + BROWSER_MOUSE_DRAG_ON; + } + } + + if (((gw->mouse->state & BROWSER_MOUSE_MOD_1) != 0) && !shift) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_1; + if (((gw->mouse->state & BROWSER_MOUSE_MOD_2) != 0) && !ctrl) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_2; + if (((gw->mouse->state & BROWSER_MOUSE_MOD_3) != 0) && !alt) + gw->mouse->state &= ~BROWSER_MOUSE_MOD_3; + + + browser_window_mouse_track(gw->bw, gw->mouse->state, x, y); + + return 0; +} + +/** + * Called when activity occours within the drawable window. + */ +static LRESULT CALLBACK +nsws_window_drawable_event_callback(HWND hwnd, + UINT msg, + WPARAM wparam, + LPARAM lparam) +{ + struct gui_window *gw; + + LOG_WIN_MSG(hwnd, msg, wparam, lparam); + + gw = nsws_get_gui_window(hwnd); + if (gw == NULL) { + LOG(("Unable to find gui window structure for hwnd %p", hwnd)); + return DefWindowProc(hwnd, msg, wparam, lparam); + } + + switch(msg) { + + case WM_MOUSEMOVE: + return nsws_drawable_mousemove(gw, + GET_X_LPARAM(lparam), + GET_Y_LPARAM(lparam)); + + case WM_LBUTTONDOWN: + nsws_drawable_mousedown(gw, + GET_X_LPARAM(lparam), + GET_Y_LPARAM(lparam), + BROWSER_MOUSE_PRESS_1); + SetFocus(hwnd); + nsws_localhistory_close(gw); + return 0; + break; + + case WM_RBUTTONDOWN: + nsws_drawable_mousedown(gw, + GET_X_LPARAM(lparam), + GET_Y_LPARAM(lparam), + BROWSER_MOUSE_PRESS_2); + SetFocus(hwnd); + return 0; + break; + + case WM_LBUTTONUP: + return nsws_drawable_mouseup(gw, + GET_X_LPARAM(lparam), + GET_Y_LPARAM(lparam), + BROWSER_MOUSE_PRESS_1, + BROWSER_MOUSE_CLICK_1); + + case WM_RBUTTONUP: + return nsws_drawable_mouseup(gw, + GET_X_LPARAM(lparam), + GET_Y_LPARAM(lparam), + BROWSER_MOUSE_PRESS_2, + BROWSER_MOUSE_CLICK_2); + + case WM_ERASEBKGND: /* ignore as drawable window is redrawn on paint */ + return 0; + + case WM_PAINT: /* redraw the exposed part of the window */ + return nsws_drawable_paint(gw, hwnd); + + case WM_KEYDOWN: + return nsws_drawable_key(gw, hwnd, wparam); + + case WM_SIZE: + return nsws_drawable_resize(gw); + + case WM_HSCROLL: + return nsws_drawable_hscroll(gw, hwnd, wparam); + + case WM_VSCROLL: + return nsws_drawable_vscroll(gw, hwnd, wparam); + + case WM_MOUSEWHEEL: + return nsws_drawable_wheel(gw, hwnd, wparam); + + } + return DefWindowProc(hwnd, msg, wparam, lparam); +} + +/** + * Create a drawable window. + */ +HWND +nsws_window_create_drawable(HINSTANCE hinstance, + HWND hparent, + struct gui_window *gw) +{ + HWND hwnd; + hwnd = CreateWindow(windowclassname_drawable, + NULL, + WS_VISIBLE | WS_CHILD, + 0, 0, 0, 0, + hparent, + NULL, + hinstance, + NULL); + + if (hwnd == NULL) { + win_perror("WindowCreateDrawable"); + LOG(("Window creation failed")); + return NULL; + } + + /* set the gui window associated with this toolbar */ + SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw); + + return hwnd; +} + +/** + * Create the drawable window class. + */ +nserror +nsws_create_drawable_class(HINSTANCE hinstance) { + nserror ret = NSERROR_OK; + WNDCLASSEX w; + + /* drawable area */ + w.cbSize = sizeof(WNDCLASSEX); + w.style = 0; + w.lpfnWndProc = nsws_window_drawable_event_callback; + w.cbClsExtra = 0; + w.cbWndExtra = 0; + w.hInstance = hinstance; + w.hIcon = NULL; + w.hCursor = NULL; + w.hbrBackground = (HBRUSH)(COLOR_MENU + 1); + w.lpszMenuName = NULL; + w.lpszClassName = windowclassname_drawable; + w.hIconSm = NULL; + + if (RegisterClassEx(&w) == 0) { + win_perror("DrawableClass"); + ret = NSERROR_INIT_FAILED; + } + + return ret; +} diff --git a/windows/drawable.h b/windows/drawable.h new file mode 100644 index 000000000..e770f94b2 --- /dev/null +++ b/windows/drawable.h @@ -0,0 +1,25 @@ +/* + * Copyright 2011 Vincent Sanders + * + * 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 . + */ + +#ifndef _NETSURF_WINDOWS_DRAWABLE_H_ +#define _NETSURF_WINDOWS_DRAWABLE_H_ + +nserror nsws_create_drawable_class(HINSTANCE hinstance); +HWND nsws_window_create_drawable(HINSTANCE hinstance, HWND hparent, struct gui_window *gw); + +#endif /* _NETSURF_WINDOWS_DRAWABLE_H_ */ diff --git a/windows/gui.c b/windows/gui.c index e8f1adff8..4e87c0739 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -20,10 +20,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -31,9 +29,7 @@ #include "content/urldb.h" #include "content/fetch.h" -#include "content/fetchers/resource.h" #include "css/utils.h" -#include "desktop/gui.h" #include "desktop/history_core.h" #include "desktop/mouse.h" #include "desktop/netsurf.h" @@ -43,102 +39,39 @@ #include "desktop/selection.h" #include "desktop/textinput.h" #include "render/html.h" -#include "utils/url.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" -#include "utils/filepath.h" +#include "windows/window.h" #include "windows/about.h" #include "windows/gui.h" -#include "windows/findfile.h" +#include "windows/drawable.h" #include "windows/font.h" #include "windows/localhistory.h" #include "windows/plot.h" #include "windows/prefs.h" #include "windows/resourceid.h" #include "windows/schedule.h" +#include "windows/findfile.h" +#include "windows/windbg.h" -#include "windbg.h" - -char *default_stylesheet_url; -char *adblock_stylesheet_url; -char *quirks_stylesheet_url; -char *options_file_location; +HINSTANCE hInstance; /** win32 application instance handle. */ struct gui_window *input_window = NULL; struct gui_window *search_current_window; struct gui_window *window_list = NULL; HWND font_hwnd; -static char default_page[] = "http://www.netsurf-browser.org/welcome/"; -static HICON hIcon, hIconS; static int open_windows = 0; static const char windowclassname_main[] = "nswsmainwindow"; -static const char windowclassname_drawable[] = "nswsdrawablewindow"; #define NSWS_THROBBER_WIDTH 24 #define NSWS_URL_ENTER (WM_USER) -struct gui_window { - /* The front's private data connected to a browser window */ - /* currently 1<->1 gui_window<->windows window [non-tabbed] */ - struct browser_window *bw; /** the browser_window */ - - HWND main; /**< handle to the actual window */ - HWND toolbar; /**< toolbar handle */ - HWND urlbar; /**< url bar handle */ - HWND throbber; /** throbber handle */ - HWND drawingarea; /**< drawing area handle */ - HWND statusbar; /**< status bar handle */ - HWND vscroll; /**< vertical scrollbar handle */ - HWND hscroll; /**< horizontal scrollbar handle */ - - HMENU mainmenu; /**< the main menu */ - HMENU rclick; /**< the right-click menu */ - struct nsws_localhistory *localhistory; /**< handle to local history window */ - int width; /**< width of window */ - int height; /**< height of drawing area */ - - int toolbuttonc; /**< number of toolbar buttons */ - int toolbuttonsize; /**< width, height of buttons */ - bool throbbing; /**< whether currently throbbing */ - - struct browser_mouse *mouse; /**< mouse state */ - - HACCEL acceltable; /**< accelerators */ - - float scale; /**< scale of content */ - - int scrollx; /**< current scroll location */ - int scrolly; /**< current scroll location */ - - RECT *fullscreen; /**< memorize non-fullscreen area */ - RECT redraw; /**< Area needing redraw. */ - int requestscrollx, requestscrolly; /**< scolling requested. */ - struct gui_window *next, *prev; /**< global linked list */ -}; - static struct nsws_pointers nsws_pointer; -static char **respaths; /** resource search path vector */ - -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -LRESULT CALLBACK nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); -LRESULT CALLBACK nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); -LRESULT CALLBACK nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); -LRESULT CALLBACK nsws_window_drawable_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); - -HINSTANCE hinstance; - void gui_multitask(void) { /* LOG(("gui_multitask")); */ @@ -182,34 +115,6 @@ void gui_poll(bool active) } } -/* obtain gui window structure from windows window handle */ -static struct gui_window * -nsws_get_gui_window(HWND hwnd) -{ - struct gui_window *gw = NULL; - HWND phwnd = hwnd; - - /* scan the window hierachy for gui window */ - while (phwnd != NULL) { - gw = GetProp(phwnd, TEXT("GuiWnd")); - if (gw != NULL) - break; - phwnd = GetParent(phwnd); - } - - if (gw == NULL) { - /* try again looking for owner windows instead */ - phwnd = hwnd; - while (phwnd != NULL) { - gw = GetProp(phwnd, TEXT("GuiWnd")); - if (gw != NULL) - break; - phwnd = GetWindow(phwnd, GW_OWNER); - } - } - - return gw; -} bool nsws_window_go(HWND hwnd, const char *url) @@ -228,7 +133,7 @@ nsws_window_go(HWND hwnd, const char *url) /** * callback for url bar events */ -LRESULT CALLBACK +static LRESULT CALLBACK nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { struct gui_window *gw; @@ -356,7 +261,7 @@ nsws_window_toolbar_command(struct gui_window *gw, /** * callback for toolbar events */ -LRESULT CALLBACK +static LRESULT CALLBACK nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { struct gui_window *gw; @@ -589,7 +494,7 @@ nsws_window_throbber_create(struct gui_window *w) NSWS_THROBBER_WIDTH, w->main, (HMENU) IDC_MAIN_THROBBER, - hinstance, + hInstance, NULL); nsws_find_resource(avi, "throbber.avi", "windows/res/throbber.avi"); @@ -604,18 +509,32 @@ nsws_window_throbber_create(struct gui_window *w) } static HIMAGELIST -nsws_set_imagelist(HWND hwnd, UINT msg, int resid, int bsize, int bcnt) +get_imagelist(int resid, int bsize, int bcnt) { HIMAGELIST hImageList; HBITMAP hScrBM; + LOG(("resource id %d, bzize %d, bcnt %d",resid, bsize, bcnt)); + hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0, bcnt); - hScrBM = LoadImage(hinstance, MAKEINTRESOURCE(resid), + if (hImageList == NULL) + return NULL; + + hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); - ImageList_AddMasked(hImageList, hScrBM, 0xcccccc); + + if (hScrBM == NULL) { + win_perror("LoadImage"); + return NULL; + } + + if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) { + /* failed to add masked bitmap */ + ImageList_Destroy(hImageList); + hImageList = NULL; + } DeleteObject(hScrBM); - SendMessage(hwnd, msg, (WPARAM)0, (LPARAM)hImageList); return hImageList; } @@ -647,7 +566,7 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent) urlheight, hwndparent, (HMENU)IDC_MAIN_URLBAR, - hinstance, + hInstance, 0); if (hwnd == NULL) { @@ -678,8 +597,9 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent) /* create a toolbar add controls and message handler */ static HWND -nsws_window_toolbar_create(struct gui_window *gw, HWND hWndParent) +nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent) { + HIMAGELIST hImageList; HWND hWndToolbar; /* Toolbar buttons */ TBBUTTON tbButtons[] = { @@ -716,13 +636,19 @@ nsws_window_toolbar_create(struct gui_window *gw, HWND hWndParent) gw->toolbuttonc = sizeof(tbButtons) / sizeof(TBBUTTON); /* Create the standard image list and assign to toolbar. */ - nsws_set_imagelist(hWndToolbar, TB_SETIMAGELIST, IDR_TOOLBAR_BITMAP, gw->toolbuttonsize, gw->toolbuttonc); + hImageList = get_imagelist(IDR_TOOLBAR_BITMAP, gw->toolbuttonsize, gw->toolbuttonc); + if (hImageList != NULL) + SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList); /* Create the disabled image list and assign to toolbar. */ - nsws_set_imagelist(hWndToolbar, TB_SETDISABLEDIMAGELIST, IDR_TOOLBAR_BITMAP_GREY, gw->toolbuttonsize, gw->toolbuttonc); + hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_GREY, gw->toolbuttonsize, gw->toolbuttonc); + if (hImageList != NULL) + SendMessage(hWndToolbar, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)hImageList); /* Create the hot image list and assign to toolbar. */ - nsws_set_imagelist(hWndToolbar, TB_SETHOTIMAGELIST, IDR_TOOLBAR_BITMAP_HOT, gw->toolbuttonsize, gw->toolbuttonc); + hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_HOT, gw->toolbuttonsize, gw->toolbuttonc); + if (hImageList != NULL) + SendMessage(hWndToolbar, TB_SETHOTIMAGELIST, 0, (LPARAM)hImageList); /* Add buttons. */ SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); @@ -735,496 +661,6 @@ nsws_window_toolbar_create(struct gui_window *gw, HWND hWndParent) return hWndToolbar; } - - - -static LRESULT nsws_drawable_mousemove(struct gui_window *gw, int x, int y) -{ - bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); - bool ctrl = ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000); - bool alt = ((GetKeyState(VK_MENU) & 0x8000) == 0x8000); - - if ((gw == NULL) || - (gw->mouse == NULL) || - (gw->bw == NULL)) - return 0; - - /* scale co-ordinates */ - x = (x + gw->scrollx) / gw->bw->scale; - y = (y + gw->scrolly) / gw->bw->scale; - - /* if mouse button held down and pointer moved more than - * minimum distance drag is happening */ - if (((gw->mouse->state & (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_PRESS_2)) != 0) && - (abs(x - gw->mouse->pressed_x) >= 5) && - (abs(y - gw->mouse->pressed_y) >= 5)) { - - LOG(("Drag start state 0x%x", gw->mouse->state)); - - if ((gw->mouse->state & BROWSER_MOUSE_PRESS_1) != 0) { - browser_window_mouse_click(gw->bw, BROWSER_MOUSE_DRAG_1, - gw->mouse->pressed_x, - gw->mouse->pressed_y); - gw->mouse->state &= ~BROWSER_MOUSE_PRESS_1; - gw->mouse->state |= BROWSER_MOUSE_HOLDING_1 | - BROWSER_MOUSE_DRAG_ON; - } - else if ((gw->mouse->state & BROWSER_MOUSE_PRESS_2) != 0) { - browser_window_mouse_click(gw->bw, BROWSER_MOUSE_DRAG_2, - gw->mouse->pressed_x, - gw->mouse->pressed_y); - gw->mouse->state &= ~BROWSER_MOUSE_PRESS_2; - gw->mouse->state |= BROWSER_MOUSE_HOLDING_2 | - BROWSER_MOUSE_DRAG_ON; - } - } - - if (((gw->mouse->state & BROWSER_MOUSE_MOD_1) != 0) && !shift) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_1; - if (((gw->mouse->state & BROWSER_MOUSE_MOD_2) != 0) && !ctrl) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_2; - if (((gw->mouse->state & BROWSER_MOUSE_MOD_3) != 0) && !alt) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_3; - - - browser_window_mouse_track(gw->bw, gw->mouse->state, x, y); - - return 0; -} - -static LRESULT -nsws_drawable_mousedown(struct gui_window *gw, - int x, int y, - browser_mouse_state button) -{ - if ((gw == NULL) || - (gw->mouse == NULL) || - (gw->bw == NULL)) { - nsws_localhistory_close(gw); - return 0; - } - - gw->mouse->state = button; - if ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000) - gw->mouse->state |= BROWSER_MOUSE_MOD_1; - if ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000) - gw->mouse->state |= BROWSER_MOUSE_MOD_2; - if ((GetKeyState(VK_MENU) & 0x8000) == 0x8000) - gw->mouse->state |= BROWSER_MOUSE_MOD_3; - - gw->mouse->pressed_x = (x + gw->scrollx) / gw->bw->scale; - gw->mouse->pressed_y = (y + gw->scrolly) / gw->bw->scale; - - LOG(("mouse click bw %p, state %x, x %f, y %f",gw->bw, - gw->mouse->state, - (x + gw->scrollx) / gw->bw->scale, - (y + gw->scrolly) / gw->bw->scale)); - - browser_window_mouse_click(gw->bw, gw->mouse->state, - (x + gw->scrollx) / gw->bw->scale , - (y + gw->scrolly) / gw->bw->scale); - - return 0; -} - -static LRESULT -nsws_drawable_mouseup(struct gui_window *gw, - int x, - int y, - browser_mouse_state press, - browser_mouse_state click) -{ - bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); - bool ctrl = ((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000); - bool alt = ((GetKeyState(VK_MENU) & 0x8000) == 0x8000); - - if ((gw == NULL) || - (gw->mouse == NULL) || - (gw->bw == NULL)) - return 0; - - LOG(("state 0x%x, press 0x%x", gw->mouse->state, press)); - if ((gw->mouse->state & press) != 0) { - gw->mouse->state &= ~press; - gw->mouse->state |= click; - } - - if (((gw->mouse->state & BROWSER_MOUSE_MOD_1) != 0) && !shift) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_1; - if (((gw->mouse->state & BROWSER_MOUSE_MOD_2) != 0) && !ctrl) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_2; - if (((gw->mouse->state & BROWSER_MOUSE_MOD_3) != 0) && !alt) - gw->mouse->state &= ~BROWSER_MOUSE_MOD_3; - - if ((gw->mouse->state & click) != 0) { - LOG(("mouse click bw %p, state 0x%x, x %f, y %f",gw->bw, - gw->mouse->state, - (x + gw->scrollx) / gw->bw->scale, - (y + gw->scrolly) / gw->bw->scale)); - - browser_window_mouse_click(gw->bw, - gw->mouse->state, - (x + gw->scrollx) / gw->bw->scale, - (y + gw->scrolly) / gw->bw->scale); - } else { - browser_window_mouse_drag_end(gw->bw, - 0, - (x + gw->scrollx) / gw->bw->scale, - (y + gw->scrolly) / gw->bw->scale); - } - - gw->mouse->state = 0; - return 0; -} - -static LRESULT -nsws_drawable_paint(struct gui_window *gw, HWND hwnd) -{ - struct rect clip; - PAINTSTRUCT ps; - - BeginPaint(hwnd, &ps); - - if (gw != NULL) { - - plot_hdc = ps.hdc; - - clip.x0 = ps.rcPaint.left; - clip.y0 = ps.rcPaint.top; - clip.x1 = ps.rcPaint.right; - clip.y1 = ps.rcPaint.bottom; - - browser_window_redraw(gw->bw, - -gw->scrollx / gw->bw->scale, - -gw->scrolly / gw->bw->scale, - &clip); - - } - - EndPaint(hwnd, &ps); - - return 0; -} - -static LRESULT -nsws_drawable_hscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam) -{ - SCROLLINFO si; - int mem; - - LOG(("HSCROLL %d", gw->requestscrollx)); - - if (gw->requestscrollx != 0) - return 0; - - si.cbSize = sizeof(si); - si.fMask = SIF_ALL; - GetScrollInfo(hwnd, SB_HORZ, &si); - mem = si.nPos; - switch (LOWORD(wparam)) { - case SB_LINELEFT: - si.nPos -= 30; - break; - - case SB_LINERIGHT: - si.nPos += 30; - break; - - case SB_PAGELEFT: - si.nPos -= gw->width; - break; - - case SB_PAGERIGHT: - si.nPos += gw->width; - break; - - case SB_THUMBTRACK: - si.nPos = si.nTrackPos; - break; - - default: - break; - } - - si.fMask = SIF_POS; - - if ((gw->bw != NULL) && - (gw->bw->current_content != NULL)) { - si.nPos = MIN(si.nPos, - content_get_width(gw->bw->current_content) * - gw->bw->scale - gw->width); - } - si.nPos = MAX(si.nPos, 0); - SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); - GetScrollInfo(hwnd, SB_HORZ, &si); - if (si.nPos != mem) { - gui_window_set_scroll(gw, - gw->scrollx + gw->requestscrollx + si.nPos - mem, - gw->scrolly); - } - - return 0; -} - -static LRESULT -nsws_drawable_vscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam) -{ - SCROLLINFO si; - int mem; - - LOG(("VSCROLL %d", gw->requestscrolly)); - - if (gw->requestscrolly != 0) - return 0; - - si.cbSize = sizeof(si); - si.fMask = SIF_ALL; - GetScrollInfo(hwnd, SB_VERT, &si); - mem = si.nPos; - switch (LOWORD(wparam)) { - case SB_TOP: - si.nPos = si.nMin; - break; - - case SB_BOTTOM: - si.nPos = si.nMax; - break; - - case SB_LINEUP: - si.nPos -= 30; - break; - - case SB_LINEDOWN: - si.nPos += 30; - break; - - case SB_PAGEUP: - si.nPos -= gw->height; - break; - - case SB_PAGEDOWN: - si.nPos += gw->height; - break; - - case SB_THUMBTRACK: - si.nPos = si.nTrackPos; - break; - - default: - break; - } - si.fMask = SIF_POS; - if ((gw->bw != NULL) && - (gw->bw->current_content != NULL)) { - si.nPos = MIN(si.nPos, - content_get_height(gw->bw->current_content) * - gw->bw->scale - gw->height); - } - si.nPos = MAX(si.nPos, 0); - SetScrollInfo(hwnd, SB_VERT, &si, TRUE); - GetScrollInfo(hwnd, SB_VERT, &si); - if (si.nPos != mem) { - gui_window_set_scroll(gw, gw->scrollx, gw->scrolly + - gw->requestscrolly + si.nPos - mem); - } - - return 0; -} - -static LRESULT -nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam) -{ - if (GetFocus() != hwnd) - return 0 ; - - uint32_t i; - bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000); - bool capslock = ((GetKeyState(VK_CAPITAL) & 1) == 1); - - switch(wparam) { - case VK_LEFT: - i = KEY_LEFT; - if (shift) - SendMessage(hwnd, WM_HSCROLL, - MAKELONG(SB_LINELEFT, 0), 0); - break; - - case VK_RIGHT: - i = KEY_RIGHT; - if (shift) - SendMessage(hwnd, WM_HSCROLL, - MAKELONG(SB_LINERIGHT, 0), 0); - break; - - case VK_UP: - i = KEY_UP; - if (shift) - SendMessage(hwnd, WM_VSCROLL, - MAKELONG(SB_LINEUP, 0), 0); - break; - - case VK_DOWN: - i = KEY_DOWN; - if (shift) - SendMessage(hwnd, WM_VSCROLL, - MAKELONG(SB_LINEDOWN, 0), 0); - break; - - case VK_HOME: - i = KEY_LINE_START; - if (shift) - SendMessage(hwnd, WM_HSCROLL, - MAKELONG(SB_PAGELEFT, 0), 0); - break; - - case VK_END: - i = KEY_LINE_END; - if (shift) - SendMessage(hwnd, WM_HSCROLL, - MAKELONG(SB_PAGERIGHT, 0), 0); - break; - - case VK_DELETE: - i = KEY_DELETE_RIGHT; - break; - - case VK_NEXT: - i = wparam; - SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), - 0); - break; - - case VK_PRIOR: - i = wparam; - SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), - 0); - break; - - default: - i = wparam; - break; - } - - if ((i >= 'A') && (i <= 'Z') && - (((!capslock) && (!shift)) || - ((capslock) && (shift)))) - i += 'a' - 'A'; - - if (gw != NULL) - browser_window_key_press(gw->bw, i); - - return 0; -} - -static LRESULT -nsws_drawable_wheel(struct gui_window *gw, HWND hwnd, WPARAM wparam) -{ - int i, z = GET_WHEEL_DELTA_WPARAM(wparam) / WHEEL_DELTA; - int key = LOWORD(wparam); - DWORD command; - unsigned int newmessage = WM_VSCROLL; - if (key == MK_SHIFT) { - command = (z > 0) ? SB_LINERIGHT : SB_LINELEFT; - newmessage = WM_HSCROLL; - } else - /* add MK_CONTROL -> zoom */ - command = (z > 0) ? SB_LINEUP : SB_LINEDOWN; - z = (z < 0) ? -1 * z : z; - for (i = 0; i < z; i++) - SendMessage(hwnd, newmessage, MAKELONG(command, 0), 0); - - return 0; -} - -static LRESULT -nsws_drawable_resize(struct gui_window *gw) -{ - browser_window_reformat(gw->bw, gw->width, gw->height); - return 0; -} - -/* Called when activity occours within the drawable window. */ -LRESULT CALLBACK -nsws_window_drawable_event_callback(HWND hwnd, - UINT msg, - WPARAM wparam, - LPARAM lparam) -{ - struct gui_window *gw; - - LOG_WIN_MSG(hwnd, msg, wparam, lparam); - - gw = nsws_get_gui_window(hwnd); - if (gw == NULL) { - LOG(("Unable to find gui window structure for hwnd %p", hwnd)); - return DefWindowProc(hwnd, msg, wparam, lparam); - } - - switch(msg) { - - case WM_MOUSEMOVE: - return nsws_drawable_mousemove(gw, - GET_X_LPARAM(lparam), - GET_Y_LPARAM(lparam)); - - case WM_LBUTTONDOWN: - nsws_drawable_mousedown(gw, - GET_X_LPARAM(lparam), - GET_Y_LPARAM(lparam), - BROWSER_MOUSE_PRESS_1); - SetFocus(hwnd); - nsws_localhistory_close(gw); - return 0; - break; - - case WM_RBUTTONDOWN: - nsws_drawable_mousedown(gw, - GET_X_LPARAM(lparam), - GET_Y_LPARAM(lparam), - BROWSER_MOUSE_PRESS_2); - SetFocus(hwnd); - return 0; - break; - - case WM_LBUTTONUP: - return nsws_drawable_mouseup(gw, - GET_X_LPARAM(lparam), - GET_Y_LPARAM(lparam), - BROWSER_MOUSE_PRESS_1, - BROWSER_MOUSE_CLICK_1); - - case WM_RBUTTONUP: - return nsws_drawable_mouseup(gw, - GET_X_LPARAM(lparam), - GET_Y_LPARAM(lparam), - BROWSER_MOUSE_PRESS_2, - BROWSER_MOUSE_CLICK_2); - - case WM_ERASEBKGND: /* ignore as drawable window is redrawn on paint */ - return 0; - - case WM_PAINT: /* redraw the exposed part of the window */ - return nsws_drawable_paint(gw, hwnd); - - case WM_KEYDOWN: - return nsws_drawable_key(gw, hwnd, wparam); - - case WM_SIZE: - return nsws_drawable_resize(gw); - - case WM_HSCROLL: - return nsws_drawable_hscroll(gw, hwnd, wparam); - - case WM_VSCROLL: - return nsws_drawable_vscroll(gw, hwnd, wparam); - - case WM_MOUSEWHEEL: - return nsws_drawable_wheel(gw, hwnd, wparam); - - } - return DefWindowProc(hwnd, msg, wparam, lparam); -} - static LRESULT nsws_window_resize(struct gui_window *gw, HWND hwnd, @@ -1379,7 +815,7 @@ nsws_window_command(HWND hwnd, break; case IDM_EDIT_PREFERENCES: - nsws_prefs_dialog_init(hinstance, gw->main); + nsws_prefs_dialog_init(hInstance, gw->main); break; case IDM_NAV_BACK: @@ -1399,7 +835,7 @@ nsws_window_command(HWND hwnd, break; case IDM_NAV_HOME: - browser_window_go(gw->bw, default_page, 0, true); + browser_window_go(gw->bw, option_homepage_url, 0, true); break; case IDM_NAV_STOP: @@ -1411,7 +847,7 @@ nsws_window_command(HWND hwnd, break; case IDM_NAV_LOCALHISTORY: - nsws_localhistory_init(gw); + gw->localhistory = nsws_window_create_localhistory(gw); break; case IDM_NAV_GLOBALHISTORY: @@ -1538,7 +974,7 @@ nsws_window_command(HWND hwnd, break; case IDM_HELP_ABOUT: - nsws_about_dialog_init(hinstance, gw->main); + nsws_about_dialog_init(hInstance, gw->main); break; case IDC_MAIN_LAUNCH_URL: @@ -1565,11 +1001,11 @@ nsws_window_command(HWND hwnd, /** * callback for window events generally */ -LRESULT CALLBACK +static LRESULT CALLBACK nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { struct gui_window *gw; - RECT rmain; + RECT rmain; LOG_WIN_MSG(hwnd, msg, wparam, lparam); @@ -1624,39 +1060,12 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } -static void create_local_windows_classes(void) { - WNDCLASSEX w; - - /* main window */ - w.cbSize = sizeof(WNDCLASSEX); - w.style = 0; - w.lpfnWndProc = nsws_window_event_callback; - w.cbClsExtra = 0; - w.cbWndExtra = 0; - w.hInstance = hinstance; - w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); - w.hCursor = NULL; - w.hbrBackground = (HBRUSH)(COLOR_MENU + 1); - w.lpszMenuName = NULL; - w.lpszClassName = windowclassname_main; - w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); - RegisterClassEx(&w); - /* drawable area */ - w.lpfnWndProc = nsws_window_drawable_event_callback; - w.hIcon = NULL; - w.lpszMenuName = NULL; - w.lpszClassName = windowclassname_drawable; - w.hIconSm = NULL; - - RegisterClassEx(&w); - -} /** * creation of status bar */ -static HWND nsws_window_statusbar_create(struct gui_window *w) +static HWND nsws_window_create_statusbar(struct gui_window *w) { HWND hwnd = CreateWindowEx(0, STATUSCLASSNAME, @@ -1665,7 +1074,7 @@ static HWND nsws_window_statusbar_create(struct gui_window *w) 0, 0, 0, 0, w->main, (HMENU)IDC_MAIN_STATUSBAR, - hinstance, + hInstance, NULL); SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf"); return hwnd; @@ -1705,10 +1114,10 @@ static HWND nsws_window_create(struct gui_window *gw) #endif InitCommonControlsEx(&icc); - gw->mainmenu = LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU_MAIN)); - gw->rclick = LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT)); + gw->mainmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN)); + gw->rclick = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT)); - LOG(("creating window for hInstance %p", hinstance)); + LOG(("creating window for hInstance %p", hInstance)); hwnd = CreateWindowEx(0, windowclassname_main, "NetSurf Browser", @@ -1719,7 +1128,7 @@ static HWND nsws_window_create(struct gui_window *gw) gw->height, NULL, gw->mainmenu, - hinstance, + hInstance, NULL); if (hwnd == NULL) { @@ -1799,22 +1208,11 @@ gui_create_browser_window(struct browser_window *bw, switch(bw->browser_window_type) { case BROWSER_WINDOW_NORMAL: gw->main = nsws_window_create(gw); - gw->toolbar = nsws_window_toolbar_create(gw, gw->main); - gw->statusbar = nsws_window_statusbar_create(gw); - - gw->drawingarea = CreateWindow(windowclassname_drawable, - NULL, - WS_VISIBLE | WS_CHILD, - 0, 0, 0, 0, - gw->main, - NULL, - hinstance, - NULL); - LOG(("BROWSER_WINDOW_NORMAL: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea)); - + gw->toolbar = nsws_window_create_toolbar(gw, gw->main); + gw->statusbar = nsws_window_create_statusbar(gw); + gw->drawingarea = nsws_window_create_drawable(hInstance, gw->main, gw); - /* set the gui window associated with this toolbar */ - SetProp(gw->drawingarea, TEXT("GuiWnd"), (HANDLE)gw); + LOG(("BROWSER_WINDOW_NORMAL: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea)); font_hwnd = gw->drawingarea; input_window = gw; @@ -1823,19 +1221,12 @@ gui_create_browser_window(struct browser_window *bw, break; case BROWSER_WINDOW_FRAME: - gw->drawingarea = CreateWindow(windowclassname_drawable, - NULL, - WS_VISIBLE | WS_CHILD, - 0, 0, 0, 0, - bw->parent->window->drawingarea, - NULL, - hinstance, - NULL); - /* set the gui window associated with this toolbar */ - SetProp(gw->drawingarea, TEXT("GuiWnd"), (HANDLE)gw); + gw->drawingarea = nsws_window_create_drawable(hInstance, bw->parent->window->drawingarea, gw); ShowWindow(gw->drawingarea, SW_SHOWNORMAL); - LOG(("create frame")); + + LOG(("BROWSER_WINDOW_FRAME: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea)); + break; case BROWSER_WINDOW_FRAMESET: @@ -1843,20 +1234,12 @@ gui_create_browser_window(struct browser_window *bw, break; case BROWSER_WINDOW_IFRAME: - LOG(("create iframe")); - gw->drawingarea = CreateWindow(windowclassname_drawable, - NULL, - WS_VISIBLE | WS_CHILD, - 0, 0, 0, 0, - bw->parent->window->drawingarea, - NULL, - hinstance, - NULL); - - /* set the gui window associated with this toolbar */ - SetProp(gw->drawingarea, TEXT("GuiWnd"), (HANDLE)gw); + gw->drawingarea = nsws_window_create_drawable(hInstance, bw->parent->window->drawingarea, gw); ShowWindow(gw->drawingarea, SW_SHOWNORMAL); + + LOG(("BROWSER_WINDOW_IFRAME: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea)); + break; default: @@ -1869,18 +1252,11 @@ gui_create_browser_window(struct browser_window *bw, -HICON nsws_window_get_ico(bool large) -{ - return large ? hIcon : hIconS; -} - - - /** * cache pointers for quick swapping */ -static void nsws_window_init_pointers(void) +void nsws_window_init_pointers(HINSTANCE hinstance) { nsws_pointer.hand = LoadCursor(NULL, IDC_HAND); nsws_pointer.ibeam = LoadCursor(NULL, IDC_IBEAM); @@ -1941,12 +1317,6 @@ struct nsws_localhistory *gui_window_localhistory(struct gui_window *w) return w->localhistory; } -void gui_window_set_localhistory(struct gui_window *w, - struct nsws_localhistory *l) -{ - if (w != NULL) - w->localhistory = l; -} RECT *gui_window_redraw_rect(struct gui_window *w) { @@ -2110,8 +1480,8 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) si.nMin = 0; si.nMax = (content_get_height(w->bw->current_content) * w->bw->scale) - 1; si.nPage = w->height; - si.nPos = MAX(w->scrolly + w->requestscrolly, 0); - si.nPos = MIN(si.nPos, content_get_height(w->bw->current_content) * w->bw->scale - w->height); + si.nPos = max(w->scrolly + w->requestscrolly, 0); + si.nPos = min(si.nPos, content_get_height(w->bw->current_content) * w->bw->scale - w->height); SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE); LOG(("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos)); @@ -2121,8 +1491,8 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) si.nMin = 0; si.nMax = (content_get_width(w->bw->current_content) * w->bw->scale) -1; si.nPage = w->width; - si.nPos = MAX(w->scrollx + w->requestscrollx, 0); - si.nPos = MIN(si.nPos, content_get_width(w->bw->current_content) * w->bw->scale - w->width); + si.nPos = max(w->scrollx + w->requestscrollx, 0); + si.nPos = min(si.nPos, content_get_width(w->bw->current_content) * w->bw->scale - w->width); SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE); LOG(("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos)); @@ -2148,8 +1518,7 @@ void gui_window_set_scroll(struct gui_window *w, int sx, int sy) void gui_window_scroll_visible(struct gui_window *w, int x0, int y0, int x1, int y1) { - LOG(("scroll visible %s:(%p, %d, %d, %d, %d)", __func__, w, x0, - y0, x1, y1)); + LOG(("scroll visible (%p, %d, %d, %d, %d)", w, x0, y0, x1, y1)); } void gui_window_position_frame(struct gui_window *w, int x0, int y0, @@ -2197,7 +1566,6 @@ void gui_window_set_pointer(struct gui_window *w, gui_pointer_shape shape) if (w == NULL) return; - LOG(("shape %d", shape)); switch (shape) { case GUI_POINTER_POINT: /* link */ case GUI_POINTER_MENU: @@ -2522,9 +1890,6 @@ void gui_create_form_select_menu(struct browser_window *bw, { } -void gui_launch_url(const char *url) -{ -} void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, unsigned long num, @@ -2533,120 +1898,34 @@ void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, cb(false, cbpw); } +/** + * Create the main window class. + */ +nserror +nsws_create_main_class(HINSTANCE hinstance) { + nserror ret = NSERROR_OK; + WNDCLASSEX w; -void gui_quit(void) -{ - LOG(("gui_quit")); -} - -char* gui_get_resource_url(const char *filename) -{ - char buf[PATH_MAX]; - return path_to_url(filepath_sfind(respaths, buf, filename)); -} - -static void gui_init(int argc, char** argv) -{ - struct browser_window *bw; - const char *addr = NETSURF_HOMEPAGE; - - LOG(("argc %d, argv %p", argc, argv)); - - /* set up stylesheet urls */ - default_stylesheet_url = strdup("resource:default.css"); - LOG(("Using '%s' as Default CSS URL", default_stylesheet_url)); - - quirks_stylesheet_url = strdup("resource:quirks.css"); - LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url)); - - adblock_stylesheet_url = strdup("resource:adblock.css"); - LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url)); - - create_local_windows_classes(); - - option_target_blank = false; - - nsws_window_init_pointers(); - - /* ensure homepage option has a default */ - if (option_homepage_url == NULL || option_homepage_url[0] == '\0') - option_homepage_url = strdup(default_page); - - /* If there is a url specified on the command line use it */ - if (argc > 1) - addr = argv[1]; - else - addr = option_homepage_url; - - LOG(("calling browser_window_create")); - bw = browser_window_create(addr, 0, 0, true, false); - -} - -void gui_stdout(void) -{ - /* mwindows compile flag normally invalidates stdout unless - already redirected */ - if (_get_osfhandle(fileno(stderr)) == -1) { - AllocConsole(); - freopen("CONOUT$", "w", stderr); - } -} - -/* OS program entry point */ -int WINAPI -WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) -{ - char **argv = NULL; - int argc = 0, argctemp = 0; - size_t len; - LPWSTR *argvw; - char *messages; - - if (SLEN(lpcli) > 0) { - argvw = CommandLineToArgvW(GetCommandLineW(), &argc); - } - - hinstance = hInstance; - setbuf(stderr, NULL); - - /* Construct a unix style argc/argv */ - argv = malloc(sizeof(char *) * argc); - while (argctemp < argc) { - len = wcstombs(NULL, argvw[argctemp], 0) + 1; - if (len > 0) { - argv[argctemp] = malloc(len); - } + /* main window */ + w.cbSize = sizeof(WNDCLASSEX); + w.style = 0; + w.lpfnWndProc = nsws_window_event_callback; + w.cbClsExtra = 0; + w.cbWndExtra = 0; + w.hInstance = hinstance; + w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); + w.hCursor = NULL; + w.hbrBackground = (HBRUSH)(COLOR_MENU + 1); + w.lpszMenuName = NULL; + w.lpszClassName = windowclassname_main; + w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); - 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++; + if (RegisterClassEx(&w) == 0) { + win_perror("DrawableClass"); + ret = NSERROR_INIT_FAILED; } - respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\res:"NETSURF_WINDOWS_RESPATH); - - messages = filepath_find(respaths, "messages"); - - options_file_location = filepath_find(respaths, "preferences"); - - /* initialise netsurf */ - netsurf_init(&argc, &argv, options_file_location, messages); - - free(messages); - - gui_init(argc, argv); + hInstance = hinstance; - netsurf_main_loop(); - - netsurf_exit(); - - free(options_file_location); - - return 0; + return ret; } diff --git a/windows/gui.h b/windows/gui.h index 957d9a520..9bcba592e 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -24,7 +24,7 @@ #include "desktop/gui.h" #include "windows/localhistory.h" -extern HINSTANCE hinstance; +extern HINSTANCE hInstance; /* bounding box */ typedef struct bbox_s { @@ -50,15 +50,6 @@ struct nsws_pointers { HCURSOR arrow; }; -struct browser_mouse { - struct gui_window *gui; - struct box *box; - - double pressed_x; - double pressed_y; - bool waiting; - browser_mouse_state state; -}; extern struct gui_window *window_list; extern char *options_file_location; @@ -84,8 +75,12 @@ int gui_window_scrollingy(struct gui_window *w); struct gui_window *gui_window_iterate(struct gui_window *); struct browser_window *gui_window_browser_window(struct gui_window *); + struct nsws_pointers *nsws_get_pointers(void); -HICON nsws_window_get_ico(bool); + +void nsws_window_init_pointers(HINSTANCE hinstance); + +nserror nsws_create_main_class(HINSTANCE hinstance); /** * Cause a browser window to navigate to a url diff --git a/windows/localhistory.c b/windows/localhistory.c index 8f6235354..bd59f4c8a 100644 --- a/windows/localhistory.c +++ b/windows/localhistory.c @@ -26,377 +26,387 @@ #include "utils/utils.h" #include "utils/log.h" #include "utils/messages.h" + +#include "windows/window.h" #include "windows/localhistory.h" #include "windows/gui.h" #include "windows/plot.h" +#include "windows/resourceid.h" +#include "windows/windbg.h" -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif +static const char windowclassname_localhistory[] = "nswslocalhistorywindow"; struct nsws_localhistory { - HWND hwnd; /**< the window handle */ - int width; /**< the width of the memory history */ - int height; /**< the height of the memory history */ - int guiwidth; /**< the width of the history window */ - int guiheight; /**< the height of the history window */ - int vscroll; /**< the vertical scroll location */ - int hscroll; /**< the horizontal scroll location */ + HWND hwnd; /**< the window handle */ + int width; /**< the width of the memory history */ + int height; /**< the height of the memory history */ + int guiwidth; /**< the width of the history window */ + int guiheight; /**< the height of the history window */ + int vscroll; /**< the vertical scroll location */ + int hscroll; /**< the horizontal scroll location */ }; -static struct nsws_localhistory localhistory; -LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg, - WPARAM wparam, LPARAM lparam); -static void nsws_localhistory_scroll_check(struct gui_window *w); -static void nsws_localhistory_clear(struct gui_window *w); +static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct gui_window *gw) +{ + SCROLLINFO si; + + if ((gw->bw == NULL) || (l->hwnd == NULL)) + return; -void nsws_localhistory_init(struct gui_window *w) + history_size(gw->bw->history, &(l->width), &(l->height)); + + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + si.nMin = 0; + si.nMax = l->height; + si.nPage = l->guiheight; + si.nPos = 0; + SetScrollInfo(l->hwnd, SB_VERT, &si, TRUE); + + si.nMax = l->width; + si.nPage = l->guiwidth; + SetScrollInfo(l->hwnd, SB_HORZ, &si, TRUE); + if (l->guiheight >= l->height) + l->vscroll = 0; + if (l->guiwidth >= l->width) + l->hscroll = 0; + SendMessage(l->hwnd, WM_PAINT, 0, 0); +} + + + +static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw) { - LOG(("gui window %p", w)); - static const char localhistorywindowclassname[] = "nsws_localhistory_window"; - WNDCLASSEX we; - HWND mainhwnd = gui_window_main_window(w); - INITCOMMONCONTROLSEX icc; - HICON hIcon = nsws_window_get_ico(true); - HICON hIconS = nsws_window_get_ico(false); - struct browser_window *bw = gui_window_browser_window(w); - int margin = 50; - RECT r; - - localhistory.width = 0; - localhistory.height = 0; + HDC tmp_hdc; - if ((bw != NULL) && (bw->history != NULL)) - history_size(bw->history, &(localhistory.width), - &(localhistory.height)); - - GetWindowRect(mainhwnd, &r); - SetWindowPos(mainhwnd, HWND_NOTOPMOST, 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE); + LOG(("gui window %p", gw)); - localhistory.guiwidth = MIN(r.right - r.left - margin, - localhistory.width + margin); - localhistory.guiheight = MIN(r.bottom - r.top - margin, - localhistory.height + margin); + l->vscroll = 0; + l->hscroll = 0; - icc.dwSize = sizeof(icc); - icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES; -#if WINVER > 0x0501 - icc.dwICC |= ICC_STANDARD_CLASSES; -#endif - InitCommonControlsEx(&icc); - - we.cbSize = sizeof(WNDCLASSEX); - we.style = 0; - we.lpfnWndProc = nsws_localhistory_event_callback; - we.cbClsExtra = 0; - we.cbWndExtra = 0; - we.hInstance = hinstance; - we.hIcon = (hIcon == NULL) ? - LoadIcon(NULL, IDI_APPLICATION) : hIcon; - we.hCursor = LoadCursor(NULL, IDC_ARROW); - we.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - we.lpszMenuName = NULL; - we.lpszClassName = localhistorywindowclassname; - we.hIconSm = (hIconS == NULL) ? - LoadIcon(NULL, IDI_APPLICATION) : hIconS; - RegisterClassEx(&we); - LOG(("creating local history window for hInstance %p", hinstance)); - localhistory.hwnd = CreateWindow(localhistorywindowclassname, - "NetSurf History",WS_THICKFRAME | WS_HSCROLL | - WS_VSCROLL | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | - CS_DBLCLKS, r.left + margin/2, r.top + margin/2, - localhistory.guiwidth, localhistory.guiheight, NULL, - NULL, hinstance, NULL); - LOG(("gui_window %p width %d height %d hwnd %p", w, - localhistory.guiwidth, localhistory.guiheight, - localhistory.hwnd)); - - ShowWindow(localhistory.hwnd, SW_SHOWNORMAL); - UpdateWindow(localhistory.hwnd); - gui_window_set_localhistory(w, &localhistory); - nsws_localhistory_up(w); + if (gw->bw != NULL) { + /* set global HDC for the plotters */ + tmp_hdc = plot_hdc; + plot_hdc = GetDC(l->hwnd); + + history_redraw(gw->bw->history); + + ReleaseDC(l->hwnd, plot_hdc); + + plot_hdc = tmp_hdc; + } + + nsws_localhistory_scroll_check(l, gw); } -LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg, - WPARAM wparam, LPARAM lparam) + +/* + void history_gui_set_pointer(gui_pointer_shape shape, void *p) + { + struct nsws_pointers *pointers = nsws_get_pointers(); + if (pointers == NULL) + return; + switch(shape) { + case GUI_POINTER_POINT: + SetCursor(pointers->hand); + break; + default: + SetCursor(pointers->arrow); + break; + } + } +*/ + + +void nsws_localhistory_close(struct gui_window *w) { - bool match = false; - struct gui_window *w = window_list; - struct browser_window *bw = NULL; - struct nsws_localhistory *local; - while (w != NULL) { - local = gui_window_localhistory(w); - if ((local != NULL) && (local->hwnd == hwnd)) { - match = true; - break; - } - w = gui_window_iterate(w); + struct nsws_localhistory *l = gui_window_localhistory(w); + if (l != NULL) + CloseWindow(l->hwnd); +} + +static LRESULT CALLBACK +nsws_localhistory_event_callback(HWND hwnd, UINT msg, + WPARAM wparam, LPARAM lparam) +{ + int x,y; + struct gui_window *gw; + + LOG_WIN_MSG(hwnd, msg, wparam, lparam); + + gw = nsws_get_gui_window(hwnd); + if (gw == NULL) { + LOG(("Unable to find gui window structure for hwnd %p", hwnd)); + return DefWindowProc(hwnd, msg, wparam, lparam); } - if (match) - bw = gui_window_browser_window(w); switch(msg) { + case WM_CREATE: - nsws_localhistory_scroll_check(w); + nsws_localhistory_scroll_check(gw->localhistory, gw); break; case WM_SIZE: - localhistory.guiheight = HIWORD(lparam); - localhistory.guiwidth = LOWORD(lparam); - nsws_localhistory_scroll_check(w); -/* current_hwnd = hwnd; - plot.rectangle(0, 0, localhistory.guiwidth, - localhistory.guiheight, plot_style_fill_white); -*/ break; - -/* case WM_MOVE: { - RECT r, rmain; - if (w != NULL) { - current_hwnd = gui_window_main_window(w); - GetWindowRect(hwnd, &r); - GetWindowRect(current_hwnd, &rmain); - gui_window_redraw(w, - MIN(r.top - rmain.top , 0), - MIN(r.left - rmain.left, 0), - gui_window_height(w) - - MIN(rmain.bottom - r.bottom, 0), - gui_window_width(w) - - MIN(rmain.right - r.right, 0)); - current_hwnd = hwnd; - return DefWindowProc(hwnd, msg, wparam, lparam); - } - } -*/ case WM_LBUTTONUP: { - int x,y; + gw->localhistory->guiheight = HIWORD(lparam); + gw->localhistory->guiwidth = LOWORD(lparam); + nsws_localhistory_scroll_check(gw->localhistory, gw); + break; + + case WM_LBUTTONUP: + if (gw->bw == NULL) + break; + x = GET_X_LPARAM(lparam); y = GET_Y_LPARAM(lparam); - if (bw == NULL) - break; - if ((bw != NULL) && - (history_click(bw, - bw->history, - localhistory.hscroll + x, - localhistory.vscroll + y, - false))) { + if (history_click(gw->bw, + gw->bw->history, + gw->localhistory->hscroll + x, + gw->localhistory->vscroll + y, + false)) { DestroyWindow(hwnd); } - } - case WM_MOUSEMOVE: { - int x,y; + + break; + + case WM_MOUSEMOVE: x = GET_X_LPARAM(lparam); y = GET_Y_LPARAM(lparam); -/* if (bw != NULL) - history_hover(bw->history, x, y, (void *)hwnd);*/ +/* if (gw->bw != NULL) + history_hover(gw->bw->history, x, y, (void *)hwnd);*/ return DefWindowProc(hwnd, msg, wparam, lparam); break; - } + + case WM_VSCROLL: { - if ((w == NULL) || (bw == NULL)) - break; SCROLLINFO si; int mem; si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); mem = si.nPos; - switch (LOWORD(wparam)) - { - case SB_TOP: - si.nPos = si.nMin; - break; - case SB_BOTTOM: - si.nPos = si.nMax; - break; - case SB_LINEUP: - si.nPos -= 30; - break; - case SB_LINEDOWN: - si.nPos += 30; - break; - case SB_PAGEUP: - si.nPos -= localhistory.guiheight; - break; - case SB_PAGEDOWN: - si.nPos += localhistory.guiheight; - break; - case SB_THUMBTRACK: - si.nPos = si.nTrackPos; - break; - default: - break; + switch (LOWORD(wparam)) { + case SB_TOP: + si.nPos = si.nMin; + break; + case SB_BOTTOM: + si.nPos = si.nMax; + break; + case SB_LINEUP: + si.nPos -= 30; + break; + case SB_LINEDOWN: + si.nPos += 30; + break; + case SB_PAGEUP: + si.nPos -= gw->localhistory->guiheight; + break; + case SB_PAGEDOWN: + si.nPos += gw->localhistory->guiheight; + break; + case SB_THUMBTRACK: + si.nPos = si.nTrackPos; + break; + default: + break; } - si.nPos = MIN(si.nPos, localhistory.height); - si.nPos = MAX(si.nPos, 0); + si.nPos = min(si.nPos, gw->localhistory->height); + si.nPos = min(si.nPos, 0); si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); if (si.nPos != mem) { - localhistory.vscroll += si.nPos - mem; + gw->localhistory->vscroll += si.nPos - mem; ScrollWindowEx(hwnd, 0, -(si.nPos - mem), NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE); } break; } + case WM_HSCROLL: { - if ((w == NULL) || (bw == NULL)) - break; SCROLLINFO si; int mem; + si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_HORZ, &si); mem = si.nPos; - switch (LOWORD(wparam)) - { - case SB_LINELEFT: - si.nPos -= 30; - break; - case SB_LINERIGHT: - si.nPos += 30; - break; - case SB_PAGELEFT: - si.nPos -= localhistory.guiwidth; - break; - case SB_PAGERIGHT: - si.nPos += localhistory.guiwidth; - break; - case SB_THUMBTRACK: - si.nPos = si.nTrackPos; - break; - default: - break; + + switch (LOWORD(wparam)) { + case SB_LINELEFT: + si.nPos -= 30; + break; + case SB_LINERIGHT: + si.nPos += 30; + break; + case SB_PAGELEFT: + si.nPos -= gw->localhistory->guiwidth; + break; + case SB_PAGERIGHT: + si.nPos += gw->localhistory->guiwidth; + break; + case SB_THUMBTRACK: + si.nPos = si.nTrackPos; + break; + default: + break; } - si.nPos = MIN(si.nPos, localhistory.width); - si.nPos = MAX(si.nPos, 0); + si.nPos = min(si.nPos, gw->localhistory->width); + si.nPos = max(si.nPos, 0); si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); GetScrollInfo(hwnd, SB_HORZ, &si); if (si.nPos != mem) { - localhistory.hscroll += si.nPos - mem; + gw->localhistory->hscroll += si.nPos - mem; ScrollWindowEx(hwnd, -(si.nPos - mem), 0, NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE); } break; - } + } + case WM_PAINT: { PAINTSTRUCT ps; HDC hdc, tmp_hdc; hdc = BeginPaint(hwnd, &ps); - if (bw != NULL) { + if (gw->bw != NULL) { /* set global HDC for the plotters */ tmp_hdc = plot_hdc; plot_hdc = hdc; - - history_redraw_rectangle(bw->history, - localhistory.hscroll + ps.rcPaint.left, - localhistory.vscroll + ps.rcPaint.top, - localhistory.hscroll + (ps.rcPaint.right - ps.rcPaint.left), - localhistory.vscroll + (ps.rcPaint.bottom - ps.rcPaint.top), - ps.rcPaint.left, - ps.rcPaint.top); + + history_redraw_rectangle(gw->bw->history, + gw->localhistory->hscroll + ps.rcPaint.left, + gw->localhistory->vscroll + ps.rcPaint.top, + gw->localhistory->hscroll + (ps.rcPaint.right - ps.rcPaint.left), + gw->localhistory->vscroll + (ps.rcPaint.bottom - ps.rcPaint.top), + ps.rcPaint.left, + ps.rcPaint.top); plot_hdc = tmp_hdc; } EndPaint(hwnd, &ps); - return DefWindowProc(hwnd, msg, wparam, lparam); + break; } + case WM_CLOSE: - nsws_localhistory_clear(w); - DestroyWindow(hwnd); - break; + DestroyWindow(hwnd); + return 1; case WM_DESTROY: - nsws_localhistory_clear(w); - PostQuitMessage(0); + free(gw->localhistory); + gw->localhistory = NULL; break; default: return DefWindowProc(hwnd, msg, wparam, lparam); + } return 0; } -void nsws_localhistory_up(struct gui_window *w) +/* exported method documented in windows/localhistory.h */ +struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw) { - LOG(("gui window %p", w)); - HDC hdc = GetDC(NULL); - struct browser_window *bw = gui_window_browser_window(w); - - localhistory.vscroll = 0; - localhistory.hscroll = 0; - - if (bw != NULL) - history_redraw(bw->history); - - nsws_localhistory_scroll_check(w); + struct nsws_localhistory *localhistory; + INITCOMMONCONTROLSEX icc; + int margin = 50; + RECT r; - ReleaseDC(localhistory.hwnd, hdc); -} + LOG(("gui window %p", gw)); -void nsws_localhistory_scroll_check(struct gui_window *w) -{ - if (w == NULL) - return; - struct browser_window *bw = gui_window_browser_window(w); - if ((bw == NULL) || (localhistory.hwnd == NULL)) - return; - history_size(bw->history, &(localhistory.width), &(localhistory.height)); - - SCROLLINFO si; - si.cbSize = sizeof(si); - si.fMask = SIF_ALL; - si.nMin = 0; - si.nMax = localhistory.height; - si.nPage = localhistory.guiheight; - si.nPos = 0; - SetScrollInfo(localhistory.hwnd, SB_VERT, &si, TRUE); - - si.nMax = localhistory.width; - si.nPage = localhistory.guiwidth; - SetScrollInfo(localhistory.hwnd, SB_HORZ, &si, TRUE); - if (localhistory.guiheight >= localhistory.height) - localhistory.vscroll = 0; - if (localhistory.guiwidth >= localhistory.width) - localhistory.hscroll = 0; - SendMessage(localhistory.hwnd, WM_PAINT, 0, 0); -} + /* if we already have a window, just update and re-show it */ + if (gw->localhistory != NULL) { + nsws_localhistory_up(gw->localhistory, gw); + UpdateWindow(gw->localhistory->hwnd); + ShowWindow(gw->localhistory->hwnd, SW_SHOWNORMAL); + return gw->localhistory; + } -/* -void history_gui_set_pointer(gui_pointer_shape shape, void *p) -{ - struct nsws_pointers *pointers = nsws_get_pointers(); - if (pointers == NULL) - return; - switch(shape) { - case GUI_POINTER_POINT: - SetCursor(pointers->hand); - break; - default: - SetCursor(pointers->arrow); - break; + localhistory = calloc(1, sizeof(struct nsws_localhistory)); + + if (localhistory == NULL) { + return NULL; } -} -*/ + gw->localhistory = localhistory; -void nsws_localhistory_close(struct gui_window *w) -{ - struct nsws_localhistory *l = gui_window_localhistory(w); - if (l != NULL) - DestroyWindow(l->hwnd); -} + localhistory->width = 0; + localhistory->height = 0; -void nsws_localhistory_clear(struct gui_window *w) -{ - if (w != NULL) - gui_window_set_localhistory(w, NULL); + if ((gw->bw != NULL) && (gw->bw->history != NULL)) { + history_size(gw->bw->history, + &(localhistory->width), + &(localhistory->height)); + } + + GetWindowRect(gw->main, &r); + SetWindowPos(gw->main, HWND_NOTOPMOST, 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE); + + localhistory->guiwidth = min(r.right - r.left - margin, + localhistory->width + margin); + localhistory->guiheight = min(r.bottom - r.top - margin, + localhistory->height + margin); + + icc.dwSize = sizeof(icc); + icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES; +#if WINVER > 0x0501 + icc.dwICC |= ICC_STANDARD_CLASSES; +#endif + InitCommonControlsEx(&icc); + + + LOG(("creating local history window for hInstance %p", hInstance)); + localhistory->hwnd = CreateWindow(windowclassname_localhistory, + "NetSurf History", + WS_THICKFRAME | WS_HSCROLL | + WS_VSCROLL | WS_CLIPCHILDREN | + WS_CLIPSIBLINGS | WS_SYSMENU | CS_DBLCLKS, + r.left + margin/2, + r.top + margin/2, + localhistory->guiwidth, + localhistory->guiheight, + NULL, NULL, hInstance, NULL); + + /* set the gui window associated with this browser */ + SetProp(localhistory->hwnd, TEXT("GuiWnd"), (HANDLE)gw); + + LOG(("gui_window %p width %d height %d hwnd %p", gw, + localhistory->guiwidth, localhistory->guiheight, + localhistory->hwnd)); + + nsws_localhistory_up(localhistory, gw); + UpdateWindow(localhistory->hwnd); + ShowWindow(localhistory->hwnd, SW_SHOWNORMAL); + + return localhistory; } +/* exported method documented in windows/localhistory.h */ +nserror +nsws_create_localhistory_class(HINSTANCE hinstance) { + nserror ret = NSERROR_OK; + WNDCLASSEX w; + + /* localhistory window */ + w.cbSize = sizeof(WNDCLASSEX); + w.style = 0; + w.lpfnWndProc = nsws_localhistory_event_callback; + w.cbClsExtra = 0; + w.cbWndExtra = 0; + w.hInstance = hinstance; + w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); + w.hCursor = LoadCursor(NULL, IDC_ARROW); + w.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + w.lpszMenuName = NULL; + w.lpszClassName = windowclassname_localhistory; + w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); + + if (RegisterClassEx(&w) == 0) { + win_perror("DrawableClass"); + ret = NSERROR_INIT_FAILED; + } + + return ret; +} diff --git a/windows/localhistory.h b/windows/localhistory.h index 422619239..4f1920dbd 100644 --- a/windows/localhistory.h +++ b/windows/localhistory.h @@ -19,12 +19,14 @@ #ifndef _NETSURF_WINDOWS_LOCALHISTORY_H_ #define _NETSURF_WINDOWS_LOCALHISTORY_H_ -#include "desktop/browser.h" - struct nsws_localhistory; -void nsws_localhistory_init(struct gui_window *); -void nsws_localhistory_up(struct gui_window *); -void nsws_localhistory_close(struct gui_window *); +void nsws_localhistory_open(struct gui_window *gw); +void nsws_localhistory_close(struct gui_window *gw); + +/* creates localhistory window */ +struct nsws_localhistory * nsws_window_create_localhistory(struct gui_window *gw); + +nserror nsws_create_localhistory_class(HINSTANCE hinstance); #endif diff --git a/windows/main.c b/windows/main.c new file mode 100644 index 000000000..1a38f815e --- /dev/null +++ b/windows/main.c @@ -0,0 +1,163 @@ +/* + * Copyright 2011 Vincent Sanders + * + * 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 . + */ + +#include +#include +#include + +#include "desktop/gui.h" +#include "desktop/options.h" +#include "desktop/browser.h" +#include "utils/utils.h" +#include "utils/log.h" +#include "utils/url.h" +#include "utils/filepath.h" +#include "content/fetchers/resource.h" + +#include "windows/findfile.h" +#include "windows/drawable.h" +#include "windows/gui.h" + +static char **respaths; /** resource search path vector. */ + +char *default_stylesheet_url; +char *adblock_stylesheet_url; +char *quirks_stylesheet_url; + +char *options_file_location; + +char* gui_get_resource_url(const char *filename) +{ + char buf[PATH_MAX]; + return path_to_url(filepath_sfind(respaths, buf, filename)); +} + +void gui_launch_url(const char *url) +{ +} + +void gui_quit(void) +{ + LOG(("gui_quit")); +} + +/** + * Ensures output stdio stream is available + */ +bool nslog_ensure(FILE *fptr) +{ + /* mwindows compile flag normally invalidates standard io unless + * already redirected + */ + if (_get_osfhandle(fileno(fptr)) == -1) { + AllocConsole(); + freopen("CONOUT$", "w", fptr); + } + return true; +} + +/** + * Entry point from operating system + **/ +int WINAPI +WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) +{ + char **argv = NULL; + int argc = 0, argctemp = 0; + size_t len; + LPWSTR *argvw; + char *messages; + nserror ret; + struct browser_window *bw; + const char *addr = NETSURF_HOMEPAGE; + + if (SLEN(lpcli) > 0) { + argvw = CommandLineToArgvW(GetCommandLineW(), &argc); + } + + setbuf(stderr, NULL); + + /* Construct a unix style argc/argv */ + 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++; + } + + respaths = nsws_init_resource("${APPDATA}\\NetSurf:${HOME}\\.netsurf:${NETSURFRES}:${PROGRAMFILES}\\NetSurf\\res:"NETSURF_WINDOWS_RESPATH); + + messages = filepath_find(respaths, "messages"); + + options_file_location = filepath_find(respaths, "preferences"); + + /* initialise netsurf */ + netsurf_init(&argc, &argv, options_file_location, messages); + + free(messages); + + /* set up stylesheet urls */ + default_stylesheet_url = strdup("resource:default.css"); + LOG(("Using '%s' as Default CSS URL", default_stylesheet_url)); + + quirks_stylesheet_url = strdup("resource:quirks.css"); + LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url)); + + adblock_stylesheet_url = strdup("resource:adblock.css"); + LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url)); + + ret = nsws_create_main_class(hInstance); + ret = nsws_create_drawable_class(hInstance); + ret = nsws_create_localhistory_class(hInstance); + + option_target_blank = false; + + nsws_window_init_pointers(hInstance); + + /* ensure homepage option has a default */ + if (option_homepage_url == NULL || option_homepage_url[0] == '\0') + option_homepage_url = strdup(NETSURF_HOMEPAGE); + + /* If there is a url specified on the command line use it */ + if (argc > 1) + addr = argv[1]; + else + addr = option_homepage_url; + + LOG(("calling browser_window_create")); + bw = browser_window_create(addr, 0, 0, true, false); + + netsurf_main_loop(); + + netsurf_exit(); + + free(options_file_location); + + return 0; +} diff --git a/windows/plot.c b/windows/plot.c index 8e242f2f4..491b89bcc 100644 --- a/windows/plot.c +++ b/windows/plot.c @@ -35,27 +35,23 @@ #include "windows/gui.h" #include "windows/plot.h" -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif /* set NSWS_PLOT_DEBUG to 0 for no debugging, 1 for debugging */ -#define NSWS_PLOT_DEBUG 0 +/* #define NSWS_PLOT_DEBUG */ -HDC plot_hdc; +#ifdef NSWS_PLOT_DEBUG +#define PLOT_LOG(x) LOG(x) +#else +#define PLOT_LOG(x) +#endif +HDC plot_hdc; static RECT plot_clip; /* currently set clipping rectangle */ static bool clip(const struct rect *clip) { -#if NSWS_PLOT_DEBUG - LOG(("clip %d,%d to %d,%d", clip->x0, clip->y0, clip->x1, clip->y1)); -#endif + PLOT_LOG(("clip %d,%d to %d,%d", clip->x0, clip->y0, clip->x1, clip->y1)); plot_clip.left = clip->x0; plot_clip.top = clip->y0; @@ -67,9 +63,7 @@ static bool clip(const struct rect *clip) static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("from %d,%d to %d,%d", x0, y0, x1, y1)); -#endif + PLOT_LOG(("from %d,%d to %d,%d", x0, y0, x1, y1)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -123,9 +117,7 @@ static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style) static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("rectangle from %d,%d to %d,%d", x0, y0, x1, y1)); -#endif + PLOT_LOG(("rectangle from %d,%d to %d,%d", x0, y0, x1, y1)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -192,9 +184,7 @@ static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) static bool polygon(const int *p, unsigned int n, const plot_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("polygon %d points", n)); -#endif + PLOT_LOG(("polygon %d points", n)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -242,9 +232,7 @@ static bool polygon(const int *p, unsigned int n, const plot_style_t *style) points[i].x = (long) p[2 * i]; points[i].y = (long) p[2 * i + 1]; -#if NSWS_PLOT_DEBUG - printf ("%ld,%ld ", points[i].x, points[i].y); -#endif + PLOT_LOG(("%ld,%ld ", points[i].x, points[i].y)); } SelectClipRgn(plot_hdc, clipregion); @@ -260,9 +248,6 @@ static bool polygon(const int *p, unsigned int n, const plot_style_t *style) DeleteObject(pen); DeleteObject(brush); -#if NSWS_PLOT_DEBUG - printf("\n"); -#endif return true; } @@ -270,9 +255,7 @@ static bool polygon(const int *p, unsigned int n, const plot_style_t *style) static bool text(int x, int y, const char *text, size_t length, const plot_font_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("words %s at %d,%d", text, x, y)); -#endif + PLOT_LOG(("words %s at %d,%d", text, x, y)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -330,9 +313,7 @@ static bool text(int x, int y, const char *text, size_t length, static bool disc(int x, int y, int radius, const plot_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("disc at %d,%d radius %d", x, y, radius)); -#endif + PLOT_LOG(("disc at %d,%d radius %d", x, y, radius)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -401,10 +382,8 @@ static bool disc(int x, int y, int radius, const plot_style_t *style) static bool arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) { -#if NSWS_PLOT_DEBUG - LOG(("arc centre %d,%d radius %d from %d to %d", x, y, radius, + PLOT_LOG(("arc centre %d,%d radius %d from %d to %d", x, y, radius, angle1, angle2)); -#endif /* ensure the plot HDC is set */ if (plot_hdc == NULL) { @@ -579,10 +558,8 @@ plot_alpha_bitmap(HDC hdc, BITMAPINFO *bmi; HBITMAP MemBMh; -#if NSWS_PLOT_DEBUG - LOG(("%p bitmap %d,%d width %d height %d", bitmap, x, y, width, height)); - LOG(("clipped %ld,%ld to %ld,%ld",plot_clip.left, plot_clip.top, plot_clip.right, plot_clip.bottom)); -#endif + PLOT_LOG(("%p bitmap %d,%d width %d height %d", bitmap, x, y, width, height)); + PLOT_LOG(("clipped %ld,%ld to %ld,%ld",plot_clip.left, plot_clip.top, plot_clip.right, plot_clip.bottom)); Memhdc = CreateCompatibleDC(hdc); if (Memhdc == NULL) { @@ -591,7 +568,7 @@ plot_alpha_bitmap(HDC hdc, if ((bitmap->width != width) || (bitmap->height != height)) { - LOG(("scaling from %d,%d to %d,%d", + PLOT_LOG(("scaling from %d,%d to %d,%d", bitmap->width, bitmap->height, width, height)); bitmap = bitmap_scale(bitmap, width, height); if (bitmap == NULL) @@ -751,7 +728,7 @@ plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height) bltres = plot_alpha_bitmap(plot_hdc, bitmap, x, y, width, height); } - /* LOG(("bltres = %d", bltres)); */ + PLOT_LOG(("bltres = %d", bltres)); DeleteObject(clipregion); @@ -771,7 +748,7 @@ windows_plot_bitmap(int x, int y, /* Bail early if we can */ - LOG(("Plotting %p at %d,%d by %d,%d",bitmap, x,y,width,height)); + PLOT_LOG(("Plotting %p at %d,%d by %d,%d",bitmap, x,y,width,height)); if (bitmap == NULL) { LOG(("Passed null bitmap!")); @@ -827,10 +804,9 @@ windows_plot_bitmap(int x, int y, plot_clip.bottom); } } -/* - LOG(("Tiled plotting %d,%d by %d,%d",x,y,width,height)); - LOG(("clipped %ld,%ld to %ld,%ld",plot_clip.left, plot_clip.top, plot_clip.right, plot_clip.bottom)); -*/ + + PLOT_LOG(("Tiled plotting %d,%d by %d,%d",x,y,width,height)); + PLOT_LOG(("clipped %ld,%ld to %ld,%ld",plot_clip.left, plot_clip.top, plot_clip.right, plot_clip.bottom)); /* get left most tile position */ if (repeat_x) @@ -840,9 +816,7 @@ windows_plot_bitmap(int x, int y, if (repeat_y) for (; y > plot_clip.top; y -= height); -/* - LOG(("repeat from %d,%d to %ld,%ld", x, y, plot_clip.right, plot_clip.bottom)); -*/ + PLOT_LOG(("repeat from %d,%d to %ld,%ld", x, y, plot_clip.right, plot_clip.bottom)); /* tile down and across to extents */ for (xf = x; xf < plot_clip.right; xf += width) { @@ -861,18 +835,14 @@ windows_plot_bitmap(int x, int y, static bool flush(void) { -#if NSWS_PLOT_DEBUG - LOG(("flush unimplemented")); -#endif + PLOT_LOG(("flush unimplemented")); return true; } static bool path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]) { -#if NSWS_PLOT_DEBUG - LOG(("path unimplemented")); -#endif + PLOT_LOG(("path unimplemented")); return true; } diff --git a/windows/windbg.h b/windows/windbg.h index 6d2ab1aab..f75206ae4 100644 --- a/windows/windbg.h +++ b/windows/windbg.h @@ -22,7 +22,7 @@ #include "utils/log.h" const char *msg_num_to_name(int msg); -void win_perror(const char * lpszFunction); +void win_perror(const char *lpszFunction); #define LOG_WIN_MSG(h, m, w, l) \ if (((m) != WM_SETCURSOR) && \ diff --git a/windows/window.c b/windows/window.c new file mode 100644 index 000000000..7fb755d2b --- /dev/null +++ b/windows/window.c @@ -0,0 +1,52 @@ +/* + * Copyright 2011 Vincent Sanders + * + * 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 . + */ + +#include + +#include + +#include "windows/window.h" + +/* documented in windows/window.h */ +struct gui_window * +nsws_get_gui_window(HWND hwnd) +{ + struct gui_window *gw = NULL; + HWND phwnd = hwnd; + + /* scan the window hierachy for gui window */ + while (phwnd != NULL) { + gw = GetProp(phwnd, TEXT("GuiWnd")); + if (gw != NULL) + break; + phwnd = GetParent(phwnd); + } + + if (gw == NULL) { + /* try again looking for owner windows instead */ + phwnd = hwnd; + while (phwnd != NULL) { + gw = GetProp(phwnd, TEXT("GuiWnd")); + if (gw != NULL) + break; + phwnd = GetWindow(phwnd, GW_OWNER); + } + } + + return gw; +} diff --git a/windows/window.h b/windows/window.h new file mode 100644 index 000000000..39b3ed5df --- /dev/null +++ b/windows/window.h @@ -0,0 +1,83 @@ +/* + * Copyright 2011 Vincent Sanders + * + * 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 . + */ + +#ifndef _NETSURF_WINDOWS_WINDOW_H_ +#define _NETSURF_WINDOWS_WINDOW_H_ + +#include "desktop/mouse.h" + +struct browser_mouse { + struct gui_window *gui; + struct box *box; + + double pressed_x; + double pressed_y; + bool waiting; + browser_mouse_state state; +}; + +struct gui_window { + /* The front's private data connected to a browser window */ + /* currently 1<->1 gui_window<->windows window [non-tabbed] */ + struct browser_window *bw; /** the browser_window */ + + HWND main; /**< handle to the actual window */ + HWND toolbar; /**< toolbar handle */ + HWND urlbar; /**< url bar handle */ + HWND throbber; /** throbber handle */ + HWND drawingarea; /**< drawing area handle */ + HWND statusbar; /**< status bar handle */ + HWND vscroll; /**< vertical scrollbar handle */ + HWND hscroll; /**< horizontal scrollbar handle */ + + HMENU mainmenu; /**< the main menu */ + HMENU rclick; /**< the right-click menu */ + struct nsws_localhistory *localhistory; /**< handle to local history window */ + int width; /**< width of window */ + int height; /**< height of drawing area */ + + int toolbuttonc; /**< number of toolbar buttons */ + int toolbuttonsize; /**< width, height of buttons */ + bool throbbing; /**< whether currently throbbing */ + + struct browser_mouse *mouse; /**< mouse state */ + + HACCEL acceltable; /**< accelerators */ + + float scale; /**< scale of content */ + + int scrollx; /**< current scroll location */ + int scrolly; /**< current scroll location */ + + RECT *fullscreen; /**< memorize non-fullscreen area */ + RECT redraw; /**< Area needing redraw. */ + int requestscrollx, requestscrolly; /**< scolling requested. */ + struct gui_window *next, *prev; /**< global linked list */ +}; + + +/** + * Obtain gui window structure from window handle. + * + * \param hwnd The window handle. + * \return The gui window associated with the window handle. + */ +struct gui_window *nsws_get_gui_window(HWND hwnd); + + +#endif /* _NETSURF_WINDOWS_WINDOW_H_ */ -- cgit v1.2.3