diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-03-13 14:32:06 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-03-13 14:32:06 +0000 |
commit | 8525c857da966580c57aa595ec44ba1c4fc2326a (patch) | |
tree | 952b61909ac17ad4666f82c005e4470ea20ff3f4 | |
parent | a487f7e611550b0058a780cf673480eb8de6f799 (diff) | |
download | netsurf-8525c857da966580c57aa595ec44ba1c4fc2326a.tar.gz netsurf-8525c857da966580c57aa595ec44ba1c4fc2326a.tar.bz2 |
Clean up more windows frontend issues and split out more functionality
-rw-r--r-- | windows/Makefile.target | 2 | ||||
-rw-r--r-- | windows/about.c | 7 | ||||
-rw-r--r-- | windows/download.c | 37 | ||||
-rw-r--r-- | windows/filetype.c | 13 | ||||
-rw-r--r-- | windows/filetype.h | 2 | ||||
-rw-r--r-- | windows/font.h | 13 | ||||
-rw-r--r-- | windows/gui.c | 81 | ||||
-rw-r--r-- | windows/gui.h | 31 | ||||
-rw-r--r-- | windows/localhistory.c | 18 | ||||
-rw-r--r-- | windows/main.c | 11 | ||||
-rw-r--r-- | windows/pointers.c | 128 | ||||
-rw-r--r-- | windows/pointers.h | 40 | ||||
-rw-r--r-- | windows/window.c | 117 | ||||
-rw-r--r-- | windows/window.h | 23 |
14 files changed, 303 insertions, 220 deletions
diff --git a/windows/Makefile.target b/windows/Makefile.target index a4aaba1e4..4d6fa074e 100644 --- a/windows/Makefile.target +++ b/windows/Makefile.target @@ -64,7 +64,7 @@ S_RESOURCES := windows_resource.o # S_WINDOWS are sources purely for the windows build 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 schedule.c thumbnail.c windbg.c + localhistory.c schedule.c thumbnail.c windbg.c pointers.c S_WINDOWS := $(addprefix windows/,$(S_WINDOWS)) # This is the final source build list diff --git a/windows/about.c b/windows/about.c index fca417ade..904a6ef8c 100644 --- a/windows/about.c +++ b/windows/about.c @@ -16,6 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/** + * \file + * This is The win32 API about dialog implementation. + */ + #include <stdio.h> #include "utils/config.h" @@ -27,7 +32,7 @@ #include "desktop/version.h" #include "utils/log.h" -#include "windows/gui.h" +#include "windows/window.h" #include "windows/about.h" #include "windows/resourceid.h" diff --git a/windows/download.c b/windows/download.c index 463a8368c..ed7b10832 100644 --- a/windows/download.c +++ b/windows/download.c @@ -34,6 +34,7 @@ #include "desktop/download.h" #include "windows/download.h" +#include "windows/window.h" #include "windows/gui.h" #include "windows/resourceid.h" #include "windows/schedule.h" @@ -41,13 +42,24 @@ static bool downloading = false; static struct gui_download_window *download1; -static bool nsws_download_window_up(struct gui_download_window *w); BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static void nsws_download_update_label(void *p); static void nsws_download_update_progress(void *p); static void nsws_download_clear_data(struct gui_download_window *w); +static bool nsws_download_window_up(struct gui_download_window *w) +{ + w->hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD), + gui_window_main_window(w->window), + nsws_download_event_callback); + if (w->hwnd == NULL) { + return false; + } + ShowWindow(w->hwnd, SW_SHOW); + return true; +} + static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *gui) { @@ -142,23 +154,20 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui) } download1 = w; - nsws_download_window_up(w); - return w; -} - -bool nsws_download_window_up(struct gui_download_window *w) -{ - w->hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD), - gui_window_main_window(w->window), - nsws_download_event_callback); - if (w->hwnd == NULL) { + if (nsws_download_window_up(w) == false) { warn_user(messages_get("NoMemory"), 0); - return false; + free(destination); + free(domain); + free(filename); + free(w->total_size); + free(w->time_left); + free(w); + return NULL; } - ShowWindow(w->hwnd, SW_SHOW); - return true; + return w; } + BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { diff --git a/windows/filetype.c b/windows/filetype.c index 996e0755e..281a3d7a3 100644 --- a/windows/filetype.c +++ b/windows/filetype.c @@ -18,17 +18,18 @@ #include <stdlib.h> #include <string.h> -#include "content/fetch.h" + #include "utils/log.h" #include "utils/utils.h" +#include "content/fetch.h" +#include "desktop/gui_fetch.h" #include "windows/filetype.h" /** * filetype -- determine the MIME type of a local file */ - -const char *fetch_filetype(const char *unix_path) +static const char *fetch_filetype(const char *unix_path) { int l; LOG(("unix path %s", unix_path)); @@ -51,3 +52,9 @@ const char *fetch_filetype(const char *unix_path) return "image/x-ms-bmp"; return "text/html"; } + +static struct gui_fetch_table fetch_table = { + .filetype = fetch_filetype, +}; + +struct gui_fetch_table *win32_fetch_table = &fetch_table; diff --git a/windows/filetype.h b/windows/filetype.h index 084e97493..f71a0b2da 100644 --- a/windows/filetype.h +++ b/windows/filetype.h @@ -19,6 +19,6 @@ #ifndef _NETSURF_WINDOWS_FILETYPE_H_ #define _NETSURF_WINDOWS_FILETYPE_H_ -const char *fetch_filetype(const char *unix_path); +struct gui_fetch_table *win32_fetch_table; #endif diff --git a/windows/font.h b/windows/font.h index 263d005af..ec596f384 100644 --- a/windows/font.h +++ b/windows/font.h @@ -17,6 +17,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/** + * \file + * The interface to the win32 font and utf8 handling. + */ + #ifndef _NETSURF_WINDOWS_FONT_H_ #define _NETSURF_WINDOWS_FONT_H_ @@ -28,11 +33,19 @@ struct font_desc { const char *encoding; }; +struct gui_utf8_table *win32_utf8_table; + extern nserror utf8_to_font_encoding(const struct font_desc* font, const char *string, size_t len, char **result); +/** + * generate a win32 font handle from a generic font style + * + * \param style The font style. + * \return The win32 font handle + */ HFONT get_font(const plot_font_style_t *style); #endif /* NETSURF_WINDOWS_FONT_H */ diff --git a/windows/gui.c b/windows/gui.c index 304e999bc..408cd49d4 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -32,8 +32,6 @@ #include "utils/file.h" #include "desktop/browser.h" #include "desktop/gui_clipboard.h" -#include "desktop/gui_fetch.h" -#include "desktop/gui_misc.h" #include "windows/schedule.h" #include "windows/window.h" @@ -44,8 +42,6 @@ static bool win32_quit = false; HINSTANCE hInstance; /** win32 application instance handle. */ -/** current pointer */ -static struct nsws_pointers nsws_pointer; void win32_set_quit(bool q) { @@ -92,74 +88,8 @@ void win32_run(void) } -bool -nsws_window_go(HWND hwnd, const char *urltxt) -{ - struct gui_window *gw; - nsurl *url; - - gw = nsws_get_gui_window(hwnd); - if (gw == NULL) - return false; - - if (nsurl_create(urltxt, &url) != NSERROR_OK) { - warn_user("NoMemory", 0); - } else { - browser_window_navigate(gw->bw, - url, - NULL, - BW_NAVIGATE_HISTORY, - NULL, - NULL, - NULL); - nsurl_unref(url); - } - - return true; -} - - -/** - * cache pointers for quick swapping - */ -void nsws_window_init_pointers(HINSTANCE hinstance) -{ - nsws_pointer.hand = LoadCursor(NULL, IDC_HAND); - nsws_pointer.ibeam = LoadCursor(NULL, IDC_IBEAM); - nsws_pointer.cross = LoadCursor(NULL, IDC_CROSS); - nsws_pointer.sizeall = LoadCursor(NULL, IDC_SIZEALL); - nsws_pointer.sizewe = LoadCursor(NULL, IDC_SIZEWE); - nsws_pointer.sizens = LoadCursor(NULL, IDC_SIZENS); - nsws_pointer.sizenesw = LoadCursor(NULL, IDC_SIZENESW); - nsws_pointer.sizenwse = LoadCursor(NULL, IDC_SIZENWSE); - nsws_pointer.wait = LoadCursor(NULL, IDC_WAIT); - nsws_pointer.appstarting = LoadCursor(NULL, IDC_APPSTARTING); - nsws_pointer.no = LoadCursor(NULL, IDC_NO); - nsws_pointer.help = LoadCursor(NULL, IDC_HELP); - nsws_pointer.arrow = LoadCursor(NULL, IDC_ARROW); -} - - -HWND gui_window_main_window(struct gui_window *w) -{ - if (w == NULL) - return NULL; - return w->main; -} - - -struct nsws_localhistory *gui_window_localhistory(struct gui_window *w) -{ - if (w == NULL) - return NULL; - return w->localhistory; -} -struct nsws_pointers *nsws_get_pointers(void) -{ - return &nsws_pointer; -} /** @@ -488,14 +418,3 @@ static struct gui_clipboard_table clipboard_table = { struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; -static struct gui_fetch_table fetch_table = { - .filetype = fetch_filetype, -}; -struct gui_fetch_table *win32_fetch_table = &fetch_table; - - -static struct gui_browser_table browser_table = { - .schedule = win32_schedule, -}; - -struct gui_browser_table *win32_browser_table = &browser_table; diff --git a/windows/gui.h b/windows/gui.h index e4b69e0c2..690cd9333 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -23,9 +23,6 @@ struct gui_window; struct gui_file_table *win32_file_table; struct gui_clipboard_table *win32_clipboard_table; -struct gui_fetch_table *win32_fetch_table; -struct gui_browser_table *win32_browser_table; -struct gui_utf8_table *win32_utf8_table; extern HINSTANCE hInstance; @@ -37,40 +34,12 @@ typedef struct bbox_s { int y1; } bbox_t; -struct nsws_pointers { - HCURSOR hand; - HCURSOR ibeam; - HCURSOR cross; - HCURSOR sizeall; - HCURSOR sizewe; - HCURSOR sizens; - HCURSOR sizenesw; - HCURSOR sizenwse; - HCURSOR wait; - HCURSOR appstarting; - HCURSOR no; - HCURSOR help; - HCURSOR arrow; -}; extern char *options_file_location; -HWND gui_window_main_window(struct gui_window *); -struct nsws_localhistory *gui_window_localhistory(struct gui_window *); -void nsws_window_init_pointers(HINSTANCE hinstance); -struct nsws_pointers *nsws_get_pointers(void); - - -/** - * Cause a browser window to navigate to a url - * - * \param hwnd The win32 handle to the browser window or one of its decendants. - * \param url The URL to navigate to. - */ -bool nsws_window_go(HWND hwnd, const char *url); /** * Run the win32 message loop with scheduling diff --git a/windows/localhistory.c b/windows/localhistory.c index fb582b4aa..dfca4a4e1 100644 --- a/windows/localhistory.c +++ b/windows/localhistory.c @@ -107,24 +107,6 @@ static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window } -/* - 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) { struct nsws_localhistory *l = gui_window_localhistory(w); diff --git a/windows/main.c b/windows/main.c index c2feeffa6..c762c52db 100644 --- a/windows/main.c +++ b/windows/main.c @@ -31,6 +31,7 @@ #include "utils/nsoption.h" #include "desktop/browser.h" #include "desktop/gui_fetch.h" +#include "desktop/gui_misc.h" #include "desktop/netsurf.h" #include "windows/findfile.h" @@ -38,6 +39,10 @@ #include "windows/download.h" #include "windows/localhistory.h" #include "windows/window.h" +#include "windows/schedule.h" +#include "windows/font.h" +#include "windows/filetype.h" +#include "windows/pointers.h" #include "windows/gui.h" static char **respaths; /** resource search path vector. */ @@ -98,6 +103,10 @@ static nserror set_defaults(struct nsoption_s *defaults) } +static struct gui_browser_table win32_browser_table = { + .schedule = win32_schedule, +}; + /** * Entry point from operating system @@ -114,7 +123,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) const char *addr; nsurl *url; struct netsurf_table win32_table = { - .browser = win32_browser_table, + .browser = &win32_browser_table, .window = win32_window_table, .clipboard = win32_clipboard_table, .download = win32_download_table, diff --git a/windows/pointers.c b/windows/pointers.c new file mode 100644 index 000000000..b5b74545d --- /dev/null +++ b/windows/pointers.c @@ -0,0 +1,128 @@ +/* + * Copyright 2015 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdbool.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <windows.h> + +#include "utils/errors.h" +#include "utils/nsurl.h" +#include "utils/log.h" +#include "utils/utils.h" +#include "utils/corestrings.h" +#include "utils/url.h" +#include "utils/file.h" +#include "desktop/browser.h" +#include "desktop/gui_clipboard.h" + +#include "windows/schedule.h" +#include "windows/window.h" +#include "windows/filetype.h" +#include "windows/pointers.h" + +struct nsws_pointers { + HCURSOR hand; + HCURSOR ibeam; + HCURSOR cross; + HCURSOR sizeall; + HCURSOR sizewe; + HCURSOR sizens; + HCURSOR sizenesw; + HCURSOR sizenwse; + HCURSOR wait; + HCURSOR appstarting; + HCURSOR no; + HCURSOR help; + HCURSOR arrow; +}; + +/** pre loaded pointer cursors */ +static struct nsws_pointers nsws_pointer; + +/* exported interface documented in windows/pointers.h */ +void nsws_window_init_pointers(HINSTANCE hinstance) +{ + nsws_pointer.hand = LoadCursor(NULL, IDC_HAND); + nsws_pointer.ibeam = LoadCursor(NULL, IDC_IBEAM); + nsws_pointer.cross = LoadCursor(NULL, IDC_CROSS); + nsws_pointer.sizeall = LoadCursor(NULL, IDC_SIZEALL); + nsws_pointer.sizewe = LoadCursor(NULL, IDC_SIZEWE); + nsws_pointer.sizens = LoadCursor(NULL, IDC_SIZENS); + nsws_pointer.sizenesw = LoadCursor(NULL, IDC_SIZENESW); + nsws_pointer.sizenwse = LoadCursor(NULL, IDC_SIZENWSE); + nsws_pointer.wait = LoadCursor(NULL, IDC_WAIT); + nsws_pointer.appstarting = LoadCursor(NULL, IDC_APPSTARTING); + nsws_pointer.no = LoadCursor(NULL, IDC_NO); + nsws_pointer.help = LoadCursor(NULL, IDC_HELP); + nsws_pointer.arrow = LoadCursor(NULL, IDC_ARROW); +} + +/* exported interface documented in windows/pointers.h */ +HCURSOR nsws_get_pointer(gui_pointer_shape shape) +{ + switch (shape) { + case GUI_POINTER_POINT: /* link */ + case GUI_POINTER_MENU: + return nsws_pointer.hand; + + case GUI_POINTER_CARET: /* input */ + return nsws_pointer.ibeam; + + case GUI_POINTER_CROSS: + return nsws_pointer.cross; + + case GUI_POINTER_MOVE: + return nsws_pointer.sizeall; + + case GUI_POINTER_RIGHT: + case GUI_POINTER_LEFT: + return nsws_pointer.sizewe; + + case GUI_POINTER_UP: + case GUI_POINTER_DOWN: + return nsws_pointer.sizens; + + case GUI_POINTER_RU: + case GUI_POINTER_LD: + return nsws_pointer.sizenesw; + + case GUI_POINTER_RD: + case GUI_POINTER_LU: + return nsws_pointer.sizenwse; + + case GUI_POINTER_WAIT: + return nsws_pointer.wait; + + case GUI_POINTER_PROGRESS: + return nsws_pointer.appstarting; + + case GUI_POINTER_NO_DROP: + case GUI_POINTER_NOT_ALLOWED: + return nsws_pointer.no; + + case GUI_POINTER_HELP: + return nsws_pointer.help; + + default: + break; + } + + return nsws_pointer.arrow; +} diff --git a/windows/pointers.h b/windows/pointers.h new file mode 100644 index 000000000..cf91de993 --- /dev/null +++ b/windows/pointers.h @@ -0,0 +1,40 @@ +/* + * Copyright 2008 Vincent Sanders <vince@simtec.co.uk> + * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file + * Windows mouse cursor interface. + */ + +#ifndef _NETSURF_WINDOWS_POINTERS_H_ +#define _NETSURF_WINDOWS_POINTERS_H_ + + +/** + * initialise the list of mouse cursors + */ +void nsws_window_init_pointers(HINSTANCE hinstance); + +/** + * get a win32 cursor handle for a pointer shape + */ +HCURSOR nsws_get_pointer(gui_pointer_shape shape); + + +#endif diff --git a/windows/window.c b/windows/window.c index 11df12aa8..3ea2afde9 100644 --- a/windows/window.c +++ b/windows/window.c @@ -36,6 +36,7 @@ #include "desktop/textinput.h" #include "windows/gui.h" +#include "windows/pointers.h" #include "windows/about.h" #include "windows/resourceid.h" #include "windows/findfile.h" @@ -59,7 +60,6 @@ static const char windowclassname_main[] = "nswsmainwindow"; static int open_windows = 0; - /** * Obtain the DPI of the display. */ @@ -1512,74 +1512,10 @@ static void win32_window_set_status(struct gui_window *w, const char *text) /** * set the pointer shape */ -static void win32_window_set_pointer(struct gui_window *w, gui_pointer_shape shape) +static void win32_window_set_pointer(struct gui_window *w, + gui_pointer_shape shape) { - struct nsws_pointers *pointers; - - if (w == NULL) - return; - - pointers = nsws_get_pointers(); - - switch (shape) { - case GUI_POINTER_POINT: /* link */ - case GUI_POINTER_MENU: - SetCursor(pointers->hand); - break; - - case GUI_POINTER_CARET: /* input */ - SetCursor(pointers->ibeam); - break; - - case GUI_POINTER_CROSS: - SetCursor(pointers->cross); - break; - - case GUI_POINTER_MOVE: - SetCursor(pointers->sizeall); - break; - - case GUI_POINTER_RIGHT: - case GUI_POINTER_LEFT: - SetCursor(pointers->sizewe); - break; - - case GUI_POINTER_UP: - case GUI_POINTER_DOWN: - SetCursor(pointers->sizens); - break; - - case GUI_POINTER_RU: - case GUI_POINTER_LD: - SetCursor(pointers->sizenesw); - break; - - case GUI_POINTER_RD: - case GUI_POINTER_LU: - SetCursor(pointers->sizenwse); - break; - - case GUI_POINTER_WAIT: - SetCursor(pointers->wait); - break; - - case GUI_POINTER_PROGRESS: - SetCursor(pointers->appstarting); - break; - - case GUI_POINTER_NO_DROP: - case GUI_POINTER_NOT_ALLOWED: - SetCursor(pointers->no); - break; - - case GUI_POINTER_HELP: - SetCursor(pointers->help); - break; - - default: - SetCursor(pointers->arrow); - break; - } + SetCursor(nsws_get_pointer(shape)); } @@ -1716,3 +1652,48 @@ struct gui_window *nsws_get_gui_window(HWND hwnd) return gw; } + + +/* exported interface documented in windows/window.h */ +bool nsws_window_go(HWND hwnd, const char *urltxt) +{ + struct gui_window *gw; + nsurl *url; + + gw = nsws_get_gui_window(hwnd); + if (gw == NULL) + return false; + + if (nsurl_create(urltxt, &url) != NSERROR_OK) { + warn_user("NoMemory", 0); + } else { + browser_window_navigate(gw->bw, + url, + NULL, + BW_NAVIGATE_HISTORY, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + + return true; +} + + +/* exported interface documented in windows/window.h */ +HWND gui_window_main_window(struct gui_window *w) +{ + if (w == NULL) + return NULL; + return w->main; +} + + +/* exported interface documented in windows/window.h */ +struct nsws_localhistory *gui_window_localhistory(struct gui_window *w) +{ + if (w == NULL) + return NULL; + return w->localhistory; +} diff --git a/windows/window.h b/windows/window.h index 3e0399859..72c6ec53b 100644 --- a/windows/window.h +++ b/windows/window.h @@ -19,6 +19,9 @@ #ifndef _NETSURF_WINDOWS_WINDOW_H_ #define _NETSURF_WINDOWS_WINDOW_H_ +/** The window operation function table for win32 */ +extern struct gui_window_table *win32_window_table; + #include "desktop/mouse.h" struct browser_mouse { @@ -79,10 +82,28 @@ struct gui_window { */ struct gui_window *nsws_get_gui_window(HWND hwnd); +/** + * Cause a browser window to navigate to a url + * + * \param hwnd The win32 handle to the browser window or one of its decendants. + * \param url The URL to navigate to. + */ +bool nsws_window_go(HWND hwnd, const char *urltxt); + void win32_window_set_scroll(struct gui_window *w, int sx, int sy); nserror nsws_create_main_class(HINSTANCE hinstance); -extern struct gui_window_table *win32_window_table; +/** + * Get the main win32 window handle from a gui window + */ +HWND gui_window_main_window(struct gui_window *); + + +/** + * Get the localhistory win32 window handle from a gui window + */ +struct nsws_localhistory *gui_window_localhistory(struct gui_window *); + #endif /* _NETSURF_WINDOWS_WINDOW_H_ */ |