r10891 vince - in /trunk/netsurf: Makefile.sources utils/log.c utils/log.h utils/utils.c utils/utils.h windows/findfile.c windows/gui.c windows/plot.c windows/resourceid.h
by netsurf@semichrome.net
Author: vince
Date: Sat Oct 16 19:08:35 2010
New Revision: 10891
URL: http://source.netsurf-browser.org?rev=10891&view=rev
Log:
Fix windows url bar
Clean up toolbar and urlbar creation and subclassing
Added:
trunk/netsurf/utils/log.c
Modified:
trunk/netsurf/Makefile.sources
trunk/netsurf/utils/log.h
trunk/netsurf/utils/utils.c
trunk/netsurf/utils/utils.h
trunk/netsurf/windows/findfile.c
trunk/netsurf/windows/gui.c
trunk/netsurf/windows/plot.c
trunk/netsurf/windows/resourceid.h
Modified: trunk/netsurf/Makefile.sources
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile.sources?rev=1089...
==============================================================================
--- trunk/netsurf/Makefile.sources (original)
+++ trunk/netsurf/Makefile.sources Sat Oct 16 19:08:35 2010
@@ -12,7 +12,7 @@
font.c form.c html.c html_interaction.c html_redraw.c \
hubbub_binding.c imagemap.c layout.c list.c table.c textplain.c
S_UTILS := base64.c filename.c hashtable.c http.c locale.c messages.c \
- talloc.c url.c utf8.c utils.c useragent.c findresource.c
+ talloc.c url.c utf8.c utils.c useragent.c findresource.c log.c
S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \
options.c plot_style.c print.c search.c searchweb.c scroll.c \
sslcert.c textarea.c tree.c tree_url_node.c version.c \
Added: trunk/netsurf/utils/log.c
URL: http://source.netsurf-browser.org/trunk/netsurf/utils/log.c?rev=10891&vie...
==============================================================================
--- trunk/netsurf/utils/log.c (added)
+++ trunk/netsurf/utils/log.c Sat Oct 16 19:08:35 2010
@@ -1,0 +1,47 @@
+/*
+ * Copyright 2007 Rob Kendrick <rjek(a)netsurf-browser.org>
+ * Copyright 2004-2007 James Bursa <bursa(a)users.sourceforge.net>
+ * Copyright 2003 Phil Mellor <monkeyson(a)users.sourceforge.net>
+ * Copyright 2003 John M Bell <jmb202(a)ecs.soton.ac.uk>
+ * Copyright 2004 John Tytgat <joty(a)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 <stdio.h>
+#include <sys/time.h>
+#include "desktop/netsurf.h"
+
+#include "utils/utils.h"
+#include "utils/log.h"
+
+static struct timeval start_tv;
+static char buff[32];
+
+const char *nslog_gettime(void)
+{
+ struct timeval tv;
+ struct timeval now_tv;
+
+ if (!timerisset(&start_tv)) {
+ gettimeofday(&start_tv, NULL);
+ }
+ gettimeofday(&now_tv, NULL);
+
+ timeval_subtract(&tv, &now_tv, &start_tv);
+
+ snprintf(buff, sizeof(buff),"(%ld.%ld)", tv.tv_sec, tv.tv_usec);
+ return buff;
+}
Modified: trunk/netsurf/utils/log.h
URL: http://source.netsurf-browser.org/trunk/netsurf/utils/log.h?rev=10891&r1=...
==============================================================================
--- trunk/netsurf/utils/log.h (original)
+++ trunk/netsurf/utils/log.h Sat Oct 16 19:08:35 2010
@@ -21,22 +21,13 @@
#define _NETSURF_LOG_H_
#include <stdio.h>
-#include <sys/time.h>
#include "desktop/netsurf.h"
#ifdef NDEBUG
# define LOG(x) ((void) 0)
#else
-static inline const char *nslog_gettime(void)
-{
- static char buff[32];
- static struct timeval tv;
-
- gettimeofday(&tv, NULL);
- snprintf(buff, sizeof(buff),"(%ld.%ld)", tv.tv_sec, tv.tv_usec);
- return buff;
-}
+extern const char *nslog_gettime(void);
# ifdef __GNUC__
# define LOG(x) do { if (verbose_log) (printf("%s " __FILE__ " %s %i: ", nslog_gettime(), __PRETTY_FUNCTION__, __LINE__), printf x, fputc('\n', stdout)); } while (0)
Modified: trunk/netsurf/utils/utils.c
URL: http://source.netsurf-browser.org/trunk/netsurf/utils/utils.c?rev=10891&r...
==============================================================================
--- trunk/netsurf/utils/utils.c (original)
+++ trunk/netsurf/utils/utils.c Sat Oct 16 19:08:35 2010
@@ -281,6 +281,34 @@
return 0;
return ((tv.tv_sec * 100) + (tv.tv_usec / 10000));
+}
+
+/* Subtract the `struct timeval' values X and Y,
+ storing the result in RESULT.
+ Return 1 if the difference is negative, otherwise 0.
+*/
+
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
+{
+ /* Perform the carry for the later subtraction by updating y. */
+ if (x->tv_usec < y->tv_usec) {
+ int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
+ y->tv_usec -= 1000000 * nsec;
+ y->tv_sec += nsec;
+ }
+ if (x->tv_usec - y->tv_usec > 1000000) {
+ int nsec = (x->tv_usec - y->tv_usec) / 1000000;
+ y->tv_usec += 1000000 * nsec;
+ y->tv_sec -= nsec;
+ }
+
+ /* Compute the time remaining to wait.
+ tv_usec is certainly positive. */
+ result->tv_sec = x->tv_sec - y->tv_sec;
+ result->tv_usec = x->tv_usec - y->tv_usec;
+
+ /* Return 1 if result is negative. */
+ return x->tv_sec < y->tv_sec;
}
#ifndef HAVE_STRCASESTR
Modified: trunk/netsurf/utils/utils.h
URL: http://source.netsurf-browser.org/trunk/netsurf/utils/utils.h?rev=10891&r...
==============================================================================
--- trunk/netsurf/utils/utils.h (original)
+++ trunk/netsurf/utils/utils.h Sat Oct 16 19:08:35 2010
@@ -25,6 +25,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <regex.h>
#include <assert.h>
@@ -105,6 +106,7 @@
char *human_friendly_bytesize(unsigned long bytesize);
const char *rfc1123_date(time_t t);
unsigned int wallclock(void);
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
/**
* Return a hex digit for the given numerical value.
Modified: trunk/netsurf/windows/findfile.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/findfile.c?rev=10...
==============================================================================
--- trunk/netsurf/windows/findfile.c (original)
+++ trunk/netsurf/windows/findfile.c Sat Oct 16 19:08:35 2010
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
+#include <curl/curl.h>
#include "utils/url.h"
#include "utils/log.h"
Modified: trunk/netsurf/windows/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/gui.c?rev=10891&r...
==============================================================================
--- trunk/netsurf/windows/gui.c (original)
+++ trunk/netsurf/windows/gui.c Sat Oct 16 19:08:35 2010
@@ -72,9 +72,6 @@
struct gui_window *window_list = NULL;
HWND font_hwnd;
-FARPROC urlproc;
-WNDPROC toolproc;
-
static char default_page[] = "http://www.netsurf-browser.org/welcome/";
static HICON hIcon, hIconS;
static int open_windows = 0;
@@ -134,16 +131,7 @@
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
-typedef enum {
- NSWS_ID_TOOLBAR = 1111,
- NSWS_ID_URLBAR,
- NSWS_ID_THROBBER,
- NSWS_ID_DRAWINGAREA,
- NSWS_ID_STATUSBAR,
- NSWS_ID_LAUNCH_URL,
-} nsws_constants ;
-
-LRESULT CALLBACK nsws_window_url_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+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);
@@ -165,6 +153,7 @@
TranslateMessage(&Msg);
}
*/
+ TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
@@ -172,22 +161,81 @@
}
+/* obtain gui window structure from windows window handle */
+static struct gui_window *
+nsws_get_gui_window(HWND hwnd)
+{
+ struct gui_window *gw;
+ HWND phwnd;
+
+ gw = GetProp(hwnd, TEXT("GuiWnd"));
+
+ if (gw == NULL) {
+ /* try the parent window instead */
+ phwnd = GetParent(hwnd);
+ gw = GetProp(phwnd, TEXT("GuiWnd"));
+ }
+
+ if (gw == NULL) {
+ /* unable to fetch from property, try searching the
+ * gui window list
+ */
+ gw = window_list;
+ while (gw != NULL) {
+ if ((gw->main == hwnd) ||
+ (gw->drawingarea == hwnd) ||
+ (gw->urlbar == hwnd) ||
+ (gw->toolbar == hwnd)) {
+ break;
+ }
+ gw = gw->next;
+ }
+ }
+
+ return gw;
+}
/**
* callback for url bar events
*/
LRESULT CALLBACK
-nsws_window_url_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
-{
- DWORD i, ii;
- SendMessage(hwnd, EM_GETSEL, (WPARAM)&i, (LPARAM)&ii);
-
- if (msg == WM_PAINT) {
- SendMessage(hwnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
- SendMessage(hwnd, EM_SETSEL, (WPARAM)i, (LPARAM)ii);
- }
- return CallWindowProc((WNDPROC) urlproc, hwnd, msg, wparam, lparam);
+nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ struct gui_window *gw;
+ WNDPROC urlproc;
+
+ gw = nsws_get_gui_window(hwnd);
+
+ LOG(("%s, hwnd %p, gw %p, wparam %d, lparam %ld",
+ msg_num_to_name(msg), hwnd, gw, wparam, lparam));
+
+ /* override messages */
+ switch (msg) {
+ case WM_CHAR:
+ if (wparam == 13) {
+ SendMessage(gw->main, WM_COMMAND, NSWS_ID_LAUNCH_URL, 0);
+ return 0;
+ }
+ break;
+
+ }
+
+ /* remove properties if window is being destroyed */
+ if (msg == WM_NCDESTROY) {
+ RemoveProp(hwnd, TEXT("GuiWnd"));
+ urlproc = (WNDPROC)RemoveProp(hwnd, TEXT("OrigMsgProc"));
+ } else {
+ urlproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc"));
+ }
+
+ if (urlproc == NULL) {
+ /* the original toolbar procedure is not available */
+ return DefWindowProc(hwnd, msg, wparam, lparam);
+ }
+
+ /* chain to the next handler */
+ return CallWindowProc(urlproc, hwnd, msg, wparam, lparam);
}
/* calculate the dimensions of the url bar relative to the parent toolbar */
@@ -210,37 +258,63 @@
*height = cy_edit;
}
-/* obtain gui window structure from windows window handle */
-static struct gui_window *
-nsws_get_gui_window(HWND hwnd)
-{
- struct gui_window *gw;
- HWND phwnd;
-
- gw = GetProp(hwnd, TEXT("GuiWnd"));
-
- if (gw == NULL) {
- /* try the parent window instead */
- phwnd = GetParent(hwnd);
- gw = GetProp(phwnd, TEXT("GuiWnd"));
- }
-
- if (gw == NULL) {
- /* unable to fetch from property, try searching the
- * gui window list
- */
- gw = window_list;
- while (gw != NULL) {
- if ((gw->main == hwnd) ||
- (gw->drawingarea == hwnd) ||
- (gw->toolbar == hwnd)) {
- break;
- }
- gw = gw->next;
+
+static LRESULT
+nsws_window_toolbar_command(struct gui_window *gw,
+ int notification_code,
+ int identifier,
+ HWND ctrl_window)
+{
+ LOG(("notification_code %d identifier %d ctrl_window %p",
+ notification_code, identifier, ctrl_window));
+
+ switch(identifier) {
+
+ case NSWS_ID_URLBAR:
+ switch (notification_code) {
+ case EN_CHANGE:
+ LOG(("EN_CHANGE"));
+ break;
+
+ case EN_ERRSPACE:
+ LOG(("EN_ERRSPACE"));
+ break;
+
+ case EN_HSCROLL:
+ LOG(("EN_HSCROLL"));
+ break;
+
+ case EN_KILLFOCUS:
+ LOG(("EN_KILLFOCUS"));
+ break;
+
+ case EN_MAXTEXT:
+ LOG(("EN_MAXTEXT"));
+ break;
+
+ case EN_SETFOCUS:
+ LOG(("EN_SETFOCUS"));
+ break;
+
+ case EN_UPDATE:
+ LOG(("EN_UPDATE"));
+ break;
+
+ case EN_VSCROLL:
+ LOG(("EN_VSCROLL"));
+ break;
+
+ default:
+ LOG(("Unknown notification_code"));
+ break;
}
- }
-
- return gw;
+ break;
+
+ default:
+ return 1; /* unhandled */
+
+ }
+ return 0; /* control message handled */
}
/**
@@ -251,9 +325,14 @@
{
struct gui_window *gw;
int urlx, urly, urlwidth, urlheight;
-
- if (msg == WM_SIZE) {
- gw = nsws_get_gui_window(hwnd);
+ WNDPROC toolproc;
+
+ gw = nsws_get_gui_window(hwnd);
+
+ LOG(("%s, hwnd %p, gw %p", msg_num_to_name(msg), hwnd, gw));
+
+ switch (msg) {
+ case WM_SIZE:
urlbar_dimensions(hwnd,
gw->toolbuttonsize,
@@ -272,11 +351,33 @@
NSWS_THROBBER_WIDTH, NSWS_THROBBER_WIDTH,
true);
}
-
- }
-
+ break;
+
+ case WM_COMMAND:
+ if (nsws_window_toolbar_command(gw,
+ HIWORD(wparam),
+ LOWORD(wparam),
+ (HWND)lparam) == 0)
+ return 0;
+ break;
+ }
+
+ /* remove properties if window is being destroyed */
+ if (msg == WM_NCDESTROY) {
+ RemoveProp(hwnd, TEXT("GuiWnd"));
+ toolproc = (WNDPROC)RemoveProp(hwnd, TEXT("OrigMsgProc"));
+ } else {
+ toolproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc"));
+ }
+
+ if (toolproc == NULL) {
+ /* the original toolbar procedure is not available */
+ return DefWindowProc(hwnd, msg, wparam, lparam);
+ }
+
/* chain to the next handler */
return CallWindowProc(toolproc, hwnd, msg, wparam, lparam);
+
}
/**
@@ -459,7 +560,8 @@
/**
* creation of throbber
*/
-static void nsws_window_throbber_create(struct gui_window *w)
+static HWND
+nsws_window_throbber_create(struct gui_window *w)
{
HWND hwnd;
char avi[PATH_MAX];
@@ -484,7 +586,7 @@
else
Animate_Seek(hwnd, 0);
ShowWindow(hwnd, SW_SHOWNORMAL);
- w->throbber = hwnd;
+ return hwnd;
}
static HIMAGELIST
@@ -503,8 +605,59 @@
return hImageList;
}
+/** create a urlbar and message handler
+ *
+ * Create an Edit control for enerting urls
+ */
static HWND
-nsws_window_toolbar_create(struct gui_window *gw)
+nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
+{
+ int urlx, urly, urlwidth, urlheight;
+ HWND hwnd;
+ WNDPROC urlproc;
+
+ urlbar_dimensions(hwndparent,
+ gw->toolbuttonsize,
+ gw->toolbuttonc,
+ &urlx, &urly, &urlwidth, &urlheight);
+
+ /* Create the edit control */
+ hwnd = CreateWindowEx(0L,
+ TEXT("Edit"),
+ NULL,
+ WS_CHILD | WS_BORDER | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL,
+ urlx,
+ urly,
+ urlwidth,
+ urlheight,
+ hwndparent,
+ (HMENU)NSWS_ID_URLBAR,
+ hinstance,
+ 0);
+
+ if (hwnd == NULL) {
+ return NULL;
+ }
+
+ /* set the gui window associated with this control */
+ SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw);
+
+ /* subclass the message handler */
+ urlproc = (WNDPROC)SetWindowLongPtr(hwnd,
+ GWLP_WNDPROC,
+ (LONG_PTR)nsws_window_urlbar_callback);
+
+ /* save the real handler */
+ SetProp(hwnd, TEXT("OrigMsgProc"), (HANDLE)urlproc);
+
+ LOG(("Created url bar hwnd %p", hwnd));
+
+ return hwnd;
+}
+
+/* create a toolbar add controls and message handler */
+static HWND
+nsws_window_toolbar_create(struct gui_window *gw, HWND hWndParent)
{
HWND hWndToolbar;
/* Toolbar buttons */
@@ -515,9 +668,9 @@
{3, NSWS_ID_NAV_RELOAD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
{4, NSWS_ID_NAV_STOP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
};
- HWND hWndParent = gw->main;
-
- /* Create the toolbar child window. */
+ WNDPROC toolproc;
+
+ /* Create the toolbar window and subclass its message handler. */
hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, "Toolbar",
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT,
0, 0, 0, 0,
@@ -527,6 +680,19 @@
return NULL;
}
+ /* set the gui window associated with this toolbar */
+ SetProp(hWndToolbar, TEXT("GuiWnd"), (HANDLE)gw);
+
+ /* subclass the message handler */
+ toolproc = (WNDPROC)SetWindowLongPtr(hWndToolbar,
+ GWLP_WNDPROC,
+ (LONG_PTR)nsws_window_toolbar_callback);
+
+ /* save the real handler */
+ SetProp(hWndToolbar, TEXT("OrigMsgProc"), (HANDLE)toolproc);
+
+
+
/* remember how many buttons are being created */
gw->toolbuttonc = sizeof(tbButtons) / sizeof(TBBUTTON);
@@ -543,36 +709,10 @@
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)gw->toolbuttonc, (LPARAM)&tbButtons);
-
- int urlx, urly, urlwidth, urlheight;
- urlbar_dimensions(hWndToolbar, gw->toolbuttonsize, gw->toolbuttonc, &urlx, &urly, &urlwidth, &urlheight);
-
- // Create the edit control child window.
- gw->urlbar = CreateWindowEx(0L, "Edit", NULL,
- WS_CHILD | WS_BORDER | WS_VISIBLE | ES_LEFT
- | ES_AUTOVSCROLL | ES_MULTILINE,
- urlx,
- urly,
- urlwidth,
- urlheight,
- hWndToolbar,
- (HMENU)NSWS_ID_URLBAR,
- hinstance, 0 );
-
- if (!gw->urlbar) {
- DestroyWindow(hWndToolbar);
- return NULL;
- }
-
- nsws_window_throbber_create(gw);
-
- /* set the gui window associated with this toolbar */
- SetProp(hWndToolbar, TEXT("GuiWnd"), (HANDLE)gw);
-
- /* subclass the message handler */
- toolproc = (WNDPROC)SetWindowLongPtr(hWndToolbar, GWLP_WNDPROC, (LONG_PTR)nsws_window_toolbar_callback);
-
- /* Return the completed toolbar */
+ gw->urlbar = nsws_window_urlbar_create(gw, hWndToolbar);
+
+ gw->throbber = nsws_window_throbber_create(gw);
+
return hWndToolbar;
}
@@ -1119,12 +1259,15 @@
return 0;
}
+
static LRESULT
nsws_window_command(struct gui_window *gw,
int notification_code,
int identifier,
HWND ctrl_window)
{
+ LOG(("notification_code %x identifier %x ctrl_window %p",
+ notification_code, identifier, ctrl_window));
switch(identifier) {
@@ -1133,10 +1276,9 @@
struct gui_window *w;
w = window_list;
while (w != NULL) {
- browser_window_destroy(w->bw);
+ PostMessage(w->main, WM_CLOSE, 0, 0);
w = w->next;
}
- netsurf_quit = true;
break;
}
@@ -1397,11 +1539,10 @@
break;
}
- case NSWS_ID_URLBAR:
- break;
default:
- break;
+ return 1; /* unhandled */
+
}
return 0; /* control message handled */
}
@@ -1412,8 +1553,6 @@
LRESULT CALLBACK
nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
- bool match = false;
- bool historyactive = false;
struct gui_window *gw;
gw = nsws_get_gui_window(hwnd);
@@ -1450,27 +1589,28 @@
case WM_ENTERMENULOOP:
nsws_update_edit(w);
return DefWindowProc(hwnd, msg, wparam, lparam);
+*/
case WM_CONTEXTMENU:
- if (!nsws_ctx_menu(w, hwnd, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)))
- return DefWindowProc(hwnd, msg, wparam, lparam);
-
-
- break;
-
-*/
+ if (nsws_ctx_menu(gw, hwnd, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)))
+ return 0;
+ break;
case WM_COMMAND:
- return nsws_window_command(gw, HIWORD(wparam), LOWORD(wparam), (HWND)lparam);
+ if (nsws_window_command(gw, HIWORD(wparam), LOWORD(wparam), (HWND)lparam) == 0)
+ return 0;
+ break;
+
case WM_SIZE:
return nsws_window_resize(gw, hwnd, wparam, lparam);
- case WM_CLOSE:
+ case WM_NCDESTROY:
+ RemoveProp(hwnd, TEXT("GuiWnd"));
+ browser_window_destroy(gw->bw);
if (--open_windows <= 0) {
netsurf_quit = true;
}
- browser_window_destroy(gw->bw);
break;
}
@@ -1627,7 +1767,7 @@
switch(bw->browser_window_type) {
case BROWSER_WINDOW_NORMAL:
gw->main = nsws_window_create(gw);
- gw->toolbar = nsws_window_toolbar_create(gw);
+ gw->toolbar = nsws_window_toolbar_create(gw, gw->main);
gw->statusbar = nsws_window_statusbar_create(gw);
gw->drawingarea = CreateWindow(windowclassname_drawable,
NULL,
@@ -1841,8 +1981,6 @@
DestroyAcceleratorTable(w->acceltable);
- DestroyWindow(w->main);
-
free(w);
w = NULL;
}
@@ -2388,13 +2526,16 @@
{
char buf[PATH_MAX], sbuf[PATH_MAX];
int len;
+ hubbub_error he;
+ struct browser_window *bw;
+ const char *addr = NETSURF_HOMEPAGE;
LOG(("argc %d, argv %p", argc, argv));
nsws_find_resource(buf, "Aliases", "./windows/res/Aliases");
LOG(("Using '%s' as Aliases file", buf));
- hubbub_error he = hubbub_initialise(buf, ns_realloc, NULL);
+ he = hubbub_initialise(buf, ns_realloc, NULL);
LOG(("hubbub init %d", he));
if (he != HUBBUB_OK)
die("Unable to initialise HTML parsing library.\n");
@@ -2419,13 +2560,6 @@
option_target_blank = false;
-}
-
-static void gui_init2(int argc, char** argv)
-{
- struct browser_window *bw;
- const char *addr = NETSURF_HOMEPAGE;
-
nsws_window_init_pointers();
LOG(("argc %d, argv %p", argc, argv));
@@ -2439,6 +2573,7 @@
LOG(("calling browser_window_create"));
bw = browser_window_create(addr, 0, 0, true, false);
+
}
void gui_stdout(void)
@@ -2458,7 +2593,7 @@
char **argv = NULL;
int argc = 0, argctemp = 0;
size_t len;
- LPWSTR * argvw;
+ LPWSTR *argvw;
char options[PATH_MAX];
char messages[PATH_MAX];
@@ -2500,8 +2635,6 @@
gui_init(argc, argv);
- gui_init2(argc, argv);
-
netsurf_main_loop();
netsurf_exit();
Modified: trunk/netsurf/windows/plot.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/plot.c?rev=10891&...
==============================================================================
--- trunk/netsurf/windows/plot.c (original)
+++ trunk/netsurf/windows/plot.c Sat Oct 16 19:08:35 2010
@@ -44,7 +44,7 @@
#endif
/* set NSWS_PLOT_DEBUG to 0 for no debugging, 1 for debugging */
-#define NSWS_PLOT_DEBUG 1
+#define NSWS_PLOT_DEBUG 0
HDC plot_hdc;
Modified: trunk/netsurf/windows/resourceid.h
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/resourceid.h?rev=...
==============================================================================
--- trunk/netsurf/windows/resourceid.h (original)
+++ trunk/netsurf/windows/resourceid.h Sat Oct 16 19:08:35 2010
@@ -28,6 +28,14 @@
#define NSWS_ID_TOOLBAR_BITMAP 107
#define NSWS_ID_TOOLBAR_GREY_BITMAP 108
#define NSWS_ID_TOOLBAR_HOT_BITMAP 109
+
+#define NSWS_ID_TOOLBAR 1111
+#define NSWS_ID_URLBAR 1112
+#define NSWS_ID_THROBBER 1113
+#define NSWS_ID_DRAWINGAREA 1114
+#define NSWS_ID_STATUSBAR 1115
+#define NSWS_ID_LAUNCH_URL 1116
+
#define NSWS_ID_ABOUT_DIALOG 11111
#define NSWS_ID_ABOUT_CONTENT 11112
#define NSWS_ID_PREFS_DIALOG 11113
12 years, 7 months
r10890 chris_y - in /trunk/netsurf: desktop/tree_url_node.c render/box.c render/box_construct.c
by netsurf@semichrome.net
Author: chris_y
Date: Sat Oct 16 10:26:28 2010
New Revision: 10890
URL: http://source.netsurf-browser.org?rev=10890&view=rev
Log:
Add some missing CONTENT_WEBPs. WebP images in HTML docs now display correctly.
Modified:
trunk/netsurf/desktop/tree_url_node.c
trunk/netsurf/render/box.c
trunk/netsurf/render/box_construct.c
Modified: trunk/netsurf/desktop/tree_url_node.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/tree_url_node.c?r...
==============================================================================
--- trunk/netsurf/desktop/tree_url_node.c (original)
+++ trunk/netsurf/desktop/tree_url_node.c Sat Oct 16 10:26:28 2010
@@ -89,6 +89,9 @@
#endif
#ifdef WITH_NS_SVG
{CONTENT_SVG, NULL},
+#endif
+#ifdef WITH_WEBP
+ {CONTENT_WEBP, NULL},
#endif
{CONTENT_UNKNOWN, NULL},
Modified: trunk/netsurf/render/box.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/box.c?rev=10890&r1...
==============================================================================
--- trunk/netsurf/render/box.c (original)
+++ trunk/netsurf/render/box.c Sat Oct 16 10:26:28 2010
@@ -1160,6 +1160,9 @@
content_get_type(box->object) == CONTENT_JNG ||
content_get_type(box->object) == CONTENT_MNG ||
#endif
+#ifdef WITH_WEBP
+ content_get_type(box->object) == CONTENT_WEBP ||
+#endif
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
content_get_type(box->object) == CONTENT_SPRITE ||
#endif
Modified: trunk/netsurf/render/box_construct.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/box_construct.c?re...
==============================================================================
--- trunk/netsurf/render/box_construct.c (original)
+++ trunk/netsurf/render/box_construct.c Sat Oct 16 10:26:28 2010
@@ -80,6 +80,9 @@
#endif
#ifdef WITH_ARTWORKS
CONTENT_ARTWORKS,
+#endif
+#ifdef WITH_WEBP
+ CONTENT_WEBP,
#endif
CONTENT_UNKNOWN };
12 years, 7 months
r10889 chris_y - /trunk/netsurf/image/webp.c
by netsurf@semichrome.net
Author: chris_y
Date: Sat Oct 16 09:46:41 2010
New Revision: 10889
URL: http://source.netsurf-browser.org?rev=10889&view=rev
Log:
Simplify
Modified:
trunk/netsurf/image/webp.c
Modified: trunk/netsurf/image/webp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.c?rev=10889&r1...
==============================================================================
--- trunk/netsurf/image/webp.c (original)
+++ trunk/netsurf/image/webp.c Sat Oct 16 09:46:41 2010
@@ -50,7 +50,7 @@
unsigned long size;
uint8 *Y = NULL, *U = NULL, *V = NULL;
int width = 0, height = 0;
- long x = 0, y = 0, offset = 0;
+ uint32 offset = 0;
uint8 r, g, b, a;
char title[100];
WebPResult res = webp_success;
@@ -88,18 +88,16 @@
/* Decoded data is RGBA on both big- and little-endian platforms,
* so ensure correct byte order. */
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- offset = 4 * (y * width + x);
- imagebufptr = imagebuf + offset;
+ size = width * height * 4;
- a = imagebuf[offset+3];
- b = imagebuf[offset+2];
- g = imagebuf[offset+1];
- r = imagebuf[offset];
+ for (offset = 0; offset < size; offset += 4) {
+ a = imagebuf[offset+3];
+ b = imagebuf[offset+2];
+ g = imagebuf[offset+1];
+ r = imagebuf[offset];
- *imagebufptr = r << 24 | g << 16 | b << 8 | a;
- }
+ imagebufptr = imagebuf + offset;
+ *imagebufptr = r << 24 | g << 16 | b << 8 | a;
}
c->width = width;
12 years, 7 months
r10888 chris_y - /trunk/netsurf/image/webp.c
by netsurf@semichrome.net
Author: chris_y
Date: Sat Oct 16 09:37:37 2010
New Revision: 10888
URL: http://source.netsurf-browser.org?rev=10888&view=rev
Log:
Make properly endian-safe
Fix warnings
Modified:
trunk/netsurf/image/webp.c
Modified: trunk/netsurf/image/webp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.c?rev=10888&r1...
==============================================================================
--- trunk/netsurf/image/webp.c (original)
+++ trunk/netsurf/image/webp.c Sat Oct 16 09:37:37 2010
@@ -44,16 +44,18 @@
bool webp_convert(struct content *c)
{
union content_msg_data msg_data;
- const char *data;
+ const uint8 *data;
+ unsigned char *imagebuf = NULL;
+ uint32 *imagebufptr = NULL;
unsigned long size;
uint8 *Y = NULL, *U = NULL, *V = NULL;
- uint32 width = 0, height = 0;
- uint32 x = 0, y = 0, offset = 0;
+ int width = 0, height = 0;
+ long x = 0, y = 0, offset = 0;
uint8 r, g, b, a;
char title[100];
WebPResult res = webp_success;
- data = content__get_source_data(c, &size);
+ data = (uint8 *)content__get_source_data(c, &size);
res = WebPDecode(data, size, &Y, &U, &V, &width, &height);
if (res != webp_success) {
@@ -70,7 +72,7 @@
if(Y) free(Y);
return false;
}
- unsigned char* imagebuf = bitmap_get_buffer(c->bitmap);
+ imagebuf = bitmap_get_buffer(c->bitmap);
if (!imagebuf) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@@ -79,24 +81,24 @@
}
unsigned int row_width = bitmap_get_rowstride(c->bitmap) / 4;
- YUV420toRGBA(Y, U, V, row_width, width, height, imagebuf);
+ YUV420toRGBA(Y, U, V, row_width, width, height, (uint32 *)imagebuf);
if(Y) free(Y);
- /* Data is RGBA on both big- and little-endian platforms,
- * so reverse the byte order. */
+ /* Decoded data is RGBA on both big- and little-endian platforms,
+ * so ensure correct byte order. */
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
offset = 4 * (y * width + x);
- r = imagebuf[offset+3];
- g = imagebuf[offset+2];
- b = imagebuf[offset+1];
- a = imagebuf[offset];
- imagebuf[offset] = r;
- imagebuf[offset+1] = g;
- imagebuf[offset+2] = b;
- imagebuf[offset+3] = a;
+ imagebufptr = imagebuf + offset;
+
+ a = imagebuf[offset+3];
+ b = imagebuf[offset+2];
+ g = imagebuf[offset+1];
+ r = imagebuf[offset];
+
+ *imagebufptr = r << 24 | g << 16 | b << 8 | a;
}
}
@@ -109,6 +111,7 @@
bitmap_modified(c->bitmap);
c->status = CONTENT_STATUS_DONE;
+ content_set_status(c, "");
return true;
}
12 years, 7 months
r10886 chris_y - in /trunk/netsurf: Makefile Makefile.defaults gtk/gtk_filetype.c image/webp.c
by netsurf@semichrome.net
Author: chris_y
Date: Sat Oct 16 08:50:35 2010
New Revision: 10886
URL: http://source.netsurf-browser.org?rev=10886&view=rev
Log:
Fix WebP images for little-endian processors, and enable for gtk build.
Direct links work, images embedded in web pages are not showing up -
test page at http://www.unsatisfactorysoftware.co.uk/netsurf/webptest/
Modified:
trunk/netsurf/Makefile
trunk/netsurf/Makefile.defaults
trunk/netsurf/gtk/gtk_filetype.c
trunk/netsurf/image/webp.c
Modified: trunk/netsurf/Makefile
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile?rev=10886&r1=108...
==============================================================================
--- trunk/netsurf/Makefile (original)
+++ trunk/netsurf/Makefile Sat Oct 16 08:50:35 2010
@@ -442,6 +442,7 @@
NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP
NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF
NETSURF_FEATURE_PNG_CFLAGS := -DWITH_PNG
+ NETSURF_FEATURE_WEBP_CFLAGS := -DWITH_WEBP
# add a line similar to below for each optional pkg-configed lib here
$(eval $(call pkg_config_find_and_add,RSVG,librsvg-2.0,SVG))
@@ -450,6 +451,9 @@
$(eval $(call pkg_config_find_and_add,BMP,libnsbmp,BMP))
$(eval $(call pkg_config_find_and_add,GIF,libnsgif,GIF))
$(eval $(call pkg_config_find_and_add,PNG,libpng,PNG ))
+
+ # no pkg-config for this library
+ $(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp -lvpx,WebP (libwebp)))
GTKCFLAGS := -std=c99 -Dgtk -Dnsgtk \
-DGTK_DISABLE_DEPRECATED \
Modified: trunk/netsurf/Makefile.defaults
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile.defaults?rev=108...
==============================================================================
--- trunk/netsurf/Makefile.defaults (original)
+++ trunk/netsurf/Makefile.defaults Sat Oct 16 08:50:35 2010
@@ -51,7 +51,7 @@
# Enable NetSurf's use of libmng for displaying MNGs, JNGs and PNGs
# Valid options: YES, NO (at least one of PNG/MNG highly recommended)
-NETSURF_USE_MNG := YES
+NETSURF_USE_MNG := NO
# Enable NetSurf's use of libwebp/libvpx for displaying WebPs
# Valid options: YES, NO
@@ -145,6 +145,10 @@
# Enable NetSurf's use of librosprite for displaying RISC OS Sprites
# Valid options: YES, NO, AUTO
NETSURF_USE_ROSPRITE := AUTO
+
+ # Enable NetSurf's use of libwebp/libvpx for displaying WebPs
+ # Valid options: YES, NO
+ NETSURF_USE_WEBP := YES
# Configuration overrides for Mac OS X
ifeq ($(HOST),macosx)
Modified: trunk/netsurf/gtk/gtk_filetype.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_filetype.c?rev=10...
==============================================================================
--- trunk/netsurf/gtk/gtk_filetype.c (original)
+++ trunk/netsurf/gtk/gtk_filetype.c Sat Oct 16 08:50:35 2010
@@ -64,6 +64,8 @@
hash_add(mime_hash, "gif", "image/gif");
hash_add(mime_hash, "png", "image/png");
hash_add(mime_hash, "jng", "image/jng");
+ hash_add(mime_hash, "mng", "image/mng");
+ hash_add(mime_hash, "webp", "image/webp");
hash_add(mime_hash, "spr", "image/x-riscos-sprite");
if (fh == NULL) {
Modified: trunk/netsurf/image/webp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.c?rev=10886&r1...
==============================================================================
--- trunk/netsurf/image/webp.c (original)
+++ trunk/netsurf/image/webp.c Sat Oct 16 08:50:35 2010
@@ -48,6 +48,8 @@
unsigned long size;
uint8 *Y = NULL, *U = NULL, *V = NULL;
uint32 width = 0, height = 0;
+ uint32 x = 0, y = 0, offset = 0;
+ uint8 r, g, b, a;
char title[100];
WebPResult res = webp_success;
@@ -81,8 +83,22 @@
if(Y) free(Y);
- /* I think we may need to reverse the byte order here, as it is fixed
- * to RGBA on both big- and little-endian platforms. */
+ /* Data is RGBA on both big- and little-endian platforms,
+ * so reverse the byte order. */
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ offset = 4 * (y * width + x);
+ r = imagebuf[offset+3];
+ g = imagebuf[offset+2];
+ b = imagebuf[offset+1];
+ a = imagebuf[offset];
+ imagebuf[offset] = r;
+ imagebuf[offset+1] = g;
+ imagebuf[offset+2] = b;
+ imagebuf[offset+3] = a;
+ }
+ }
c->width = width;
c->height = height;
12 years, 7 months
r10885 vince - in /trunk/netsurf/windows: font.c gui.c gui.h localhistory.c plot.c plot.h thumbnail.c
by netsurf@semichrome.net
Author: vince
Date: Thu Oct 14 14:33:00 2010
New Revision: 10885
URL: http://source.netsurf-browser.org?rev=10885&view=rev
Log:
fix thumbnailing and localhistory
Modified:
trunk/netsurf/windows/font.c
trunk/netsurf/windows/gui.c
trunk/netsurf/windows/gui.h
trunk/netsurf/windows/localhistory.c
trunk/netsurf/windows/plot.c
trunk/netsurf/windows/plot.h
trunk/netsurf/windows/thumbnail.c
Modified: trunk/netsurf/windows/font.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/font.c?rev=10885&...
==============================================================================
--- trunk/netsurf/windows/font.c (original)
+++ trunk/netsurf/windows/font.c Thu Oct 14 14:33:00 2010
@@ -76,9 +76,9 @@
int nHeight = -10;
- HDC hdc = GetDC(current_hwnd);
+ HDC hdc = GetDC(font_hwnd);
nHeight = -MulDiv(style->size, GetDeviceCaps(hdc, LOGPIXELSY), 72 * FONT_SIZE_SCALE);
- ReleaseDC(current_hwnd, hdc);
+ ReleaseDC(font_hwnd, hdc);
HFONT font = CreateFont(
nHeight, /* height */
Modified: trunk/netsurf/windows/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/gui.c?rev=10885&r...
==============================================================================
--- trunk/netsurf/windows/gui.c (original)
+++ trunk/netsurf/windows/gui.c Thu Oct 14 14:33:00 2010
@@ -70,6 +70,7 @@
struct gui_window *input_window = NULL;
struct gui_window *search_current_window;
struct gui_window *window_list = NULL;
+HWND font_hwnd;
FARPROC urlproc;
WNDPROC toolproc;
@@ -119,7 +120,6 @@
RECT *fullscreen; /**< memorize non-fullscreen area */
RECT redraw; /**< Area needing redraw. */
- RECT clip; /**< current clip rectangle */
int requestscrollx, requestscrolly; /**< scolling requested. */
struct gui_window *next, *prev; /**< global linked list */
};
@@ -159,11 +159,12 @@
{
MSG Msg;
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) {
- if (!((current_gui == NULL) ||
+/* if (!((current_gui == NULL) ||
(TranslateAccelerator(current_gui->main,
current_gui->acceltable, &Msg)))) {
TranslateMessage(&Msg);
- }
+ }
+*/
DispatchMessage(&Msg);
}
@@ -721,15 +722,16 @@
nsws_drawable_paint(struct gui_window *gw, HWND hwnd)
{
PAINTSTRUCT ps;
-
- BeginPaint(hwnd, &ps);
+ HDC hdc, tmp_hdc;
+
+ hdc = BeginPaint(hwnd, &ps);
if ((gw != NULL) &&
(gw->bw != NULL) &&
(gw->bw->current_content != NULL)) {
- /* set globals for the plotters */
- current_hwnd = hwnd;
- current_gui = gw;
+ /* set global HDC for the plotters */
+ tmp_hdc = hdc;
+ plot_hdc = hdc;
content_redraw(gw->bw->current_content,
-gw->scrollx / gw->bw->scale,
@@ -743,6 +745,7 @@
gw->bw->scale,
0xFFFFFF);
+ plot_hdc = tmp_hdc;
}
EndPaint(hwnd, &ps);
@@ -1422,8 +1425,6 @@
return DefWindowProc(hwnd, msg, wparam, lparam);
}
- current_gui = gw;
-
switch(msg) {
/*
@@ -1640,7 +1641,7 @@
/* set the gui window associated with this toolbar */
SetProp(gw->drawingarea, TEXT("GuiWnd"), (HANDLE)gw);
-
+ font_hwnd = gw->drawingarea;
input_window = gw;
open_windows++;
ShowWindow(gw->main, SW_SHOWNORMAL);
@@ -1780,13 +1781,6 @@
return &(w->redraw);
}
-RECT *gui_window_clip_rect(struct gui_window *w)
-{
- if (w == NULL)
- return NULL;
- return &(w->clip);
-}
-
int gui_window_width(struct gui_window *w)
{
if (w == NULL)
Modified: trunk/netsurf/windows/gui.h
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/gui.h?rev=10885&r...
==============================================================================
--- trunk/netsurf/windows/gui.h (original)
+++ trunk/netsurf/windows/gui.h Thu Oct 14 14:33:00 2010
@@ -63,6 +63,8 @@
extern struct gui_window *window_list;
extern char *options_file_location;
+extern HWND font_hwnd;
+
HWND gui_window_main_window(struct gui_window *);
HWND gui_window_toolbar(struct gui_window *);
HWND gui_window_urlbar(struct gui_window *);
@@ -73,7 +75,6 @@
struct nsws_localhistory *);
RECT *gui_window_redraw_rect(struct gui_window *);
-RECT *gui_window_clip_rect(struct gui_window *w);
int gui_window_voffset(struct gui_window *);
int gui_window_width(struct gui_window *);
Modified: trunk/netsurf/windows/localhistory.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/localhistory.c?re...
==============================================================================
--- trunk/netsurf/windows/localhistory.c (original)
+++ trunk/netsurf/windows/localhistory.c Thu Oct 14 14:33:00 2010
@@ -71,8 +71,7 @@
localhistory.width = 0;
localhistory.height = 0;
- current_gui = NULL;
- current_hwnd = NULL;
+
if ((bw != NULL) && (bw->history != NULL))
history_size(bw->history, &(localhistory.width),
&(localhistory.height));
@@ -118,7 +117,7 @@
LOG(("gui_window %p width %d height %d hwnd %p", w,
localhistory.guiwidth, localhistory.guiheight,
localhistory.hwnd));
- current_hwnd = localhistory.hwnd;
+
ShowWindow(localhistory.hwnd, SW_SHOWNORMAL);
UpdateWindow(localhistory.hwnd);
gui_window_set_localhistory(w, &localhistory);
@@ -142,23 +141,24 @@
}
if (match)
bw = gui_window_browser_window(w);
+
switch(msg) {
case WM_CREATE:
nsws_localhistory_scroll_check(w);
break;
+
case WM_SIZE:
localhistory.guiheight = HIWORD(lparam);
localhistory.guiwidth = LOWORD(lparam);
nsws_localhistory_scroll_check(w);
- current_gui = NULL;
- current_hwnd = hwnd;
+/* current_hwnd = hwnd;
plot.rectangle(0, 0, localhistory.guiwidth,
localhistory.guiheight, plot_style_fill_white);
- break;
- case WM_MOVE: {
+*/ break;
+
+/* case WM_MOVE: {
RECT r, rmain;
if (w != NULL) {
- current_gui = w;
current_hwnd = gui_window_main_window(w);
GetWindowRect(hwnd, &r);
GetWindowRect(current_hwnd, &rmain);
@@ -169,24 +169,24 @@
MIN(rmain.bottom - r.bottom, 0),
gui_window_width(w) -
MIN(rmain.right - r.right, 0));
- current_gui = NULL;
current_hwnd = hwnd;
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
- case WM_LBUTTONUP: {
+*/ case WM_LBUTTONUP: {
int x,y;
x = GET_X_LPARAM(lparam);
y = GET_Y_LPARAM(lparam);
if (bw == NULL)
break;
- current_hwnd = gui_window_main_window(w);
- current_gui = w;
- if ((bw != NULL) && (history_click(bw, bw->history, x, y, false)))
+
+ if ((bw != NULL) &&
+ (history_click(bw,
+ bw->history,
+ localhistory.hscroll + x,
+ localhistory.vscroll + y,
+ false))) {
DestroyWindow(hwnd);
- else {
- current_hwnd = hwnd;
- current_gui = NULL;
}
}
case WM_MOUSEMOVE: {
@@ -234,26 +234,14 @@
default:
break;
}
- si.nPos = MIN(si.nPos, localhistory.width);
+ si.nPos = MIN(si.nPos, localhistory.height);
si.nPos = MAX(si.nPos, 0);
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
GetScrollInfo(hwnd, SB_VERT, &si);
if (si.nPos != mem) {
- current_gui = NULL;
- current_hwnd = hwnd;
localhistory.vscroll += si.nPos - mem;
- plot.rectangle(0, 0, localhistory.guiwidth,
- localhistory.guiheight,
- plot_style_fill_white);
- history_redraw_rectangle(bw->history,
- localhistory.hscroll,
- localhistory.vscroll,
- localhistory.guiwidth +
- localhistory.hscroll,
- localhistory.guiheight
- + localhistory.vscroll,
- 0, 0);
+ ScrollWindowEx(hwnd, 0, -(si.nPos - mem), NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE);
}
break;
}
@@ -287,43 +275,37 @@
default:
break;
}
- si.nPos = MIN(si.nPos, localhistory.height);
+ si.nPos = MIN(si.nPos, 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) {
- current_gui = NULL;
- current_hwnd = hwnd;
localhistory.hscroll += si.nPos - mem;
- if (bw == NULL)
- break;
- plot.rectangle(0, 0, localhistory.guiwidth,
- localhistory.guiheight,
- plot_style_fill_white);
- history_redraw_rectangle(bw->history,
- localhistory.hscroll,
- localhistory.vscroll,
- localhistory.guiwidth +
- localhistory.hscroll,
- localhistory.guiheight
- + localhistory.vscroll,
- 0, 0);
+ ScrollWindowEx(hwnd, -(si.nPos - mem), 0, NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE);
}
break;
}
case WM_PAINT: {
- current_gui = NULL;
- current_hwnd = hwnd;
PAINTSTRUCT ps;
- BeginPaint(hwnd, &ps);
- if (bw != NULL)
+ HDC hdc, tmp_hdc;
+ hdc = BeginPaint(hwnd, &ps);
+ if (bw != NULL) {
+ /* set global HDC for the plotters */
+ tmp_hdc = plot_hdc;
+ plot_hdc = hdc;
+
history_redraw_rectangle(bw->history,
- localhistory.hscroll,
- localhistory.vscroll,
- localhistory.hscroll + localhistory.guiwidth,
- localhistory.vscroll + localhistory.guiheight,
- 0, 0);
+ 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);
+
+ plot_hdc = tmp_hdc;
+
+ }
EndPaint(hwnd, &ps);
return DefWindowProc(hwnd, msg, wparam, lparam);
break;
@@ -332,10 +314,12 @@
nsws_localhistory_clear(w);
DestroyWindow(hwnd);
break;
+
case WM_DESTROY:
nsws_localhistory_clear(w);
PostQuitMessage(0);
break;
+
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
Modified: trunk/netsurf/windows/plot.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/plot.c?rev=10885&...
==============================================================================
--- trunk/netsurf/windows/plot.c (original)
+++ trunk/netsurf/windows/plot.c Thu Oct 14 14:33:00 2010
@@ -44,37 +44,20 @@
#endif
/* set NSWS_PLOT_DEBUG to 0 for no debugging, 1 for debugging */
-#define NSWS_PLOT_DEBUG 0
-
-HWND current_hwnd;
-struct gui_window *current_gui;
-bool thumbnail = false;
+#define NSWS_PLOT_DEBUG 1
+
+HDC plot_hdc;
+
static float nsws_plot_scale = 1.0;
-static RECT localhistory_clip;
-
-
-static RECT plot_clip;
+
+static RECT plot_clip; /* currently set clipping rectangle */
static bool clip(int x0, int y0, int x1, int y1)
{
#if NSWS_PLOT_DEBUG
- LOG(("clip %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1, thumbnail));
-#endif
- RECT *clip = gui_window_clip_rect(current_gui);
- if (clip == NULL)
- clip = &localhistory_clip;
- x0 = MAX(x0, 0);
- y0 = MAX(y0, 0);
- if (!((current_gui == NULL) || (thumbnail))) {
- x1 = MIN(x1, gui_window_width(current_gui));
- y1 = MIN(y1, gui_window_height(current_gui));
- }
- clip->left = x0;
- clip->top = y0 ;
- clip->right = x1;
- clip->bottom = y1;
-
+ LOG(("clip %d,%d to %d,%d", x0, y0, x1, y1));
+#endif
plot_clip.left = x0;
plot_clip.top = y0;
@@ -87,22 +70,20 @@
static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
#if NSWS_PLOT_DEBUG
- LOG(("ligne from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1,
- thumbnail));
-#endif
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
+ LOG(("from %d,%d to %d,%d", x0, y0, x1, y1));
+#endif
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
return false;
}
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
- return false;
- }
COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF);
/* windows 0x00bbggrr */
DWORD penstyle = PS_GEOMETRIC | ((style->stroke_type ==
@@ -113,16 +94,12 @@
HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL);
if (pen == NULL) {
DeleteObject(clipregion);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ bak = SelectObject(hdc, (HGDIOBJ) pen);
+ return false;
+ }
+ HGDIOBJ bak = SelectObject(plot_hdc, (HGDIOBJ) pen);
if (bak == NULL) {
DeleteObject(pen);
DeleteObject(clipregion);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
RECT r;
@@ -131,35 +108,41 @@
r.right = x1;
r.bottom = y1;
- SelectClipRgn(hdc, clipregion);
-
- MoveToEx(hdc, x0, y0, (LPPOINT) NULL);
-
- LineTo(hdc, x1, y1);
-
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
- pen = SelectObject(hdc, bak);
+ SelectClipRgn(plot_hdc, clipregion);
+
+ MoveToEx(plot_hdc, x0, y0, (LPPOINT) NULL);
+
+ LineTo(plot_hdc, x1, y1);
+
+ SelectClipRgn(plot_hdc, NULL);
+ pen = SelectObject(plot_hdc, bak);
+
DeleteObject(pen);
DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
return true;
}
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
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
+ return false;
+ }
+
x1++;
y1++;
-#if NSWS_PLOT_DEBUG
- LOG(("rectangle from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1,
- thumbnail));
-#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- return false;
- }
+
COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF);
DWORD penstyle = PS_GEOMETRIC |
(style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT :
@@ -173,42 +156,38 @@
HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL);
if (pen == NULL) {
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ penbak = SelectObject(hdc, (HGDIOBJ) pen);
+ return false;
+ }
+ HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen);
if (penbak == NULL) {
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
HBRUSH brush = CreateBrushIndirect(&lb1);
if (brush == NULL) {
- SelectObject(hdc, penbak);
- DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush);
+ SelectObject(plot_hdc, penbak);
+ DeleteObject(pen);
+ return false;
+ }
+ HGDIOBJ brushbak = SelectObject(plot_hdc, (HGDIOBJ) brush);
if (brushbak == NULL) {
- SelectObject(hdc, penbak);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
DeleteObject(brush);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
-
- Rectangle(hdc, x0, y0, x1, y1);
-
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ return false;
+ }
+
+ SelectClipRgn(plot_hdc, clipregion);
+
+ Rectangle(plot_hdc, x0, y0, x1, y1);
+
+ pen = SelectObject(plot_hdc, penbak);
+ brush = SelectObject(plot_hdc, brushbak);
+ SelectClipRgn(plot_hdc, NULL);
DeleteObject(pen);
DeleteObject(brush);
-
- ReleaseDC(current_hwnd, hdc);
+ DeleteObject(clipregion);
+
return true;
}
@@ -216,59 +195,51 @@
static bool polygon(const int *p, unsigned int n, const plot_style_t *style)
{
#if NSWS_PLOT_DEBUG
- LOG(("polygon %d points thumbnail %d", n, thumbnail));
-#endif
+ LOG(("polygon %d points", n));
+#endif
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
POINT points[n];
unsigned int i;
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- return false;
- }
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
+ return false;
+ }
+
COLORREF pencol = (DWORD)(style->fill_colour & 0x00FFFFFF);
COLORREF brushcol = (DWORD)(style->fill_colour & 0x00FFFFFF);
HPEN pen = CreatePen(PS_GEOMETRIC | PS_NULL, 1, pencol);
if (pen == NULL) {
DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HPEN penbak = SelectObject(hdc, pen);
+ return false;
+ }
+ HPEN penbak = SelectObject(plot_hdc, pen);
if (penbak == NULL) {
DeleteObject(clipregion);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
HBRUSH brush = CreateSolidBrush(brushcol);
if (brush == NULL) {
DeleteObject(clipregion);
- SelectObject(hdc, penbak);
- DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HBRUSH brushbak = SelectObject(hdc, brush);
+ SelectObject(plot_hdc, penbak);
+ DeleteObject(pen);
+ return false;
+ }
+ HBRUSH brushbak = SelectObject(plot_hdc, brush);
if (brushbak == NULL) {
DeleteObject(clipregion);
- SelectObject(hdc, penbak);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
DeleteObject(brush);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- SetPolyFillMode(hdc, WINDING);
+ return false;
+ }
+ SetPolyFillMode(plot_hdc, WINDING);
for (i = 0; i < n; i++) {
points[i].x = (long) p[2 * i];
points[i].y = (long) p[2 * i + 1];
@@ -278,20 +249,19 @@
#endif
}
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
if (n >= 2)
- Polygon(hdc, points, n);
-
- SelectClipRgn(hdc, NULL);
-
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ Polygon(plot_hdc, points, n);
+
+ SelectClipRgn(plot_hdc, NULL);
+
+ pen = SelectObject(plot_hdc, penbak);
+ brush = SelectObject(plot_hdc, brushbak);
DeleteObject(clipregion);
DeleteObject(pen);
DeleteObject(brush);
- ReleaseDC(current_hwnd, hdc);
#if NSWS_PLOT_DEBUG
printf("\n");
#endif
@@ -303,48 +273,45 @@
const plot_font_style_t *style)
{
#if NSWS_PLOT_DEBUG
- LOG(("words %s at %d,%d thumbnail %d", text, x, y, thumbnail));
-#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- return false;
- }
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
+ LOG(("words %s at %d,%d", text, x, y));
+#endif
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
- ReleaseDC(current_hwnd, hdc);
return false;
}
HFONT fontbak, font = get_font(style);
if (font == NULL) {
DeleteObject(clipregion);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
int wlen;
SIZE s;
LPWSTR wstring;
RECT r;
- fontbak = (HFONT) SelectObject(hdc, font);
- GetTextExtentPoint(hdc, text, length, &s);
+ fontbak = (HFONT) SelectObject(plot_hdc, font);
+ GetTextExtentPoint(plot_hdc, text, length, &s);
r.left = x;
r.top = y - (3 * s.cy) / 4;
r.right = x + s.cx;
r.bottom = y + s.cy / 4;
- SelectClipRgn(hdc, clipregion);
-
- SetTextAlign(hdc, TA_BASELINE | TA_LEFT);
+ SelectClipRgn(plot_hdc, clipregion);
+
+ SetTextAlign(plot_hdc, TA_BASELINE | TA_LEFT);
if ((style->background & 0xFF000000) != 0x01000000)
/* 100% alpha */
- SetBkColor(hdc, (DWORD) (style->background & 0x00FFFFFF));
- SetBkMode(hdc, TRANSPARENT);
- SetTextColor(hdc, (DWORD) (style->foreground & 0x00FFFFFF));
+ SetBkColor(plot_hdc, (DWORD) (style->background & 0x00FFFFFF));
+ SetBkMode(plot_hdc, TRANSPARENT);
+ SetTextColor(plot_hdc, (DWORD) (style->foreground & 0x00FFFFFF));
wlen = MultiByteToWideChar(CP_UTF8, 0, text, length, NULL, 0);
wstring = malloc(2 * (wlen + 1));
@@ -352,36 +319,31 @@
return false;
}
MultiByteToWideChar(CP_UTF8, 0, text, length, wstring, wlen);
- TextOutW(hdc, x, y, wstring, wlen);
-
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
+ TextOutW(plot_hdc, x, y, wstring, wlen);
+
+ SelectClipRgn(plot_hdc, NULL);
free(wstring);
- font = SelectObject(hdc, fontbak);
+ font = SelectObject(plot_hdc, fontbak);
DeleteObject(clipregion);
DeleteObject(font);
- ReleaseDC(current_hwnd, hdc);
return true;
}
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 thumbnail %d", x, y, radius, thumbnail));
-#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- return false;
- }
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
+ LOG(("disc at %d,%d radius %d", x, y, radius));
+#endif
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
@@ -390,35 +352,27 @@
HPEN pen = CreatePen(PS_GEOMETRIC | PS_SOLID, 1, col);
if (pen == NULL) {
DeleteObject(clipregion);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ penbak = SelectObject(hdc, (HGDIOBJ) pen);
+ return false;
+ }
+ HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen);
if (penbak == NULL) {
DeleteObject(clipregion);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
HBRUSH brush = CreateSolidBrush(col);
if (brush == NULL) {
DeleteObject(clipregion);
- SelectObject(hdc, penbak);
- DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush);
+ SelectObject(plot_hdc, penbak);
+ DeleteObject(pen);
+ return false;
+ }
+ HGDIOBJ brushbak = SelectObject(plot_hdc, (HGDIOBJ) brush);
if (brushbak == NULL) {
DeleteObject(clipregion);
- SelectObject(hdc, penbak);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
DeleteObject(brush);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
RECT r;
@@ -427,25 +381,22 @@
r.right = x + radius;
r.bottom = y + radius;
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
if (style->fill_type == PLOT_OP_TYPE_NONE)
- Arc(hdc, x - radius, y - radius, x + radius, y + radius,
+ Arc(plot_hdc, x - radius, y - radius, x + radius, y + radius,
x - radius, y - radius,
x - radius, y - radius);
else
- Ellipse(hdc, x - radius, y - radius, x + radius, y + radius);
-
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ Ellipse(plot_hdc, x - radius, y - radius, x + radius, y + radius);
+
+ SelectClipRgn(plot_hdc, NULL);
+ pen = SelectObject(plot_hdc, penbak);
+ brush = SelectObject(plot_hdc, brushbak);
DeleteObject(clipregion);
DeleteObject(pen);
DeleteObject(brush);
- ReleaseDC(current_hwnd, hdc);
return true;
}
@@ -456,33 +407,28 @@
LOG(("arc centre %d,%d radius %d from %d to %d", x, y, radius,
angle1, angle2));
#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- return false;
- }
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
+ return false;
+ }
+
COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF);
HPEN pen = CreatePen(PS_GEOMETRIC | PS_SOLID, 1, col);
if (pen == NULL) {
DeleteObject(clipregion);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HGDIOBJ penbak = SelectObject(hdc, (HGDIOBJ) pen);
+ return false;
+ }
+ HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen);
if (penbak == NULL) {
DeleteObject(clipregion);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
RECT r;
@@ -544,27 +490,23 @@
r.right = x + radius;
r.bottom = y + radius;
- SelectClipRgn(hdc, clipregion);
-
- Arc(hdc, x - radius, y - radius, x + radius, y + radius,
+ SelectClipRgn(plot_hdc, clipregion);
+
+ Arc(plot_hdc, x - radius, y - radius, x + radius, y + radius,
x + (int)(a1 * radius), y + (int)(b1 * radius),
x + (int)(a2 * radius), y + (int)(b2 * radius));
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
- pen = SelectObject(hdc, penbak);
+ SelectClipRgn(plot_hdc, NULL);
+ pen = SelectObject(plot_hdc, penbak);
DeleteObject(clipregion);
DeleteObject(pen);
- ReleaseDC(current_hwnd, hdc);
return true;
}
static bool
plot_block(COLORREF col, int x, int y, int width, int height)
{
- HDC hdc;
HRGN clipregion;
HGDIOBJ original = NULL;
@@ -577,32 +519,32 @@
return true;
}
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
return false;
}
- hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
- return false;
- }
-
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
/* Saving the original pen object */
- original = SelectObject(hdc,GetStockObject(DC_PEN));
-
- SelectObject(hdc, GetStockObject(DC_PEN));
- SelectObject(hdc, GetStockObject(DC_BRUSH));
- SetDCPenColor(hdc, col);
- SetDCBrushColor(hdc, col);
- Rectangle(hdc,x,y,width,height);
-
- SelectObject(hdc,original); /* Restoring the original pen object */
+ original = SelectObject(plot_hdc,GetStockObject(DC_PEN));
+
+ SelectObject(plot_hdc, GetStockObject(DC_PEN));
+ SelectObject(plot_hdc, GetStockObject(DC_BRUSH));
+ SetDCPenColor(plot_hdc, col);
+ SetDCBrushColor(plot_hdc, col);
+ Rectangle(plot_hdc, x, y, width, height);
+
+ SelectObject(plot_hdc,original); /* Restoring the original pen object */
DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
+
return true;
}
@@ -614,6 +556,22 @@
int x, int y,
int width, int height)
{
+#ifdef WINDOWS_GDI_ALPHA_WORKED
+ BLENDFUNCTION blnd = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA };
+ HDC bmihdc;
+ bool bltres;
+ bmihdc = CreateCompatibleDC(hdc);
+ SelectObject(bmihdc, bitmap->windib);
+ bltres = AlphaBlend(hdc,
+ x, y,
+ width, height,
+ bmihdc,
+ 0, 0,
+ bitmap->width, bitmap->height,
+ blnd);
+ DeleteDC(bmihdc);
+ return bltres;
+#else
HDC Memhdc;
BITMAPINFOHEADER bmih;
int v, vv, vi, h, hh, width4, transparency;
@@ -627,8 +585,6 @@
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
-
- assert(bitmap != NULL);
Memhdc = CreateCompatibleDC(hdc);
if (Memhdc == NULL) {
@@ -731,6 +687,7 @@
DeleteObject(MemBMh);
DeleteDC(Memhdc);
return true;
+#endif
}
@@ -738,7 +695,6 @@
plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height)
{
int bltres;
- HDC hdc;
HRGN clipregion;
/* Bail early if we can */
@@ -750,25 +706,25 @@
return true;
}
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
+ return false;
+ }
+
clipregion = CreateRectRgnIndirect(&plot_clip);
if (clipregion == NULL) {
return false;
}
- hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
- return false;
- }
-
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
if (bitmap->opaque) {
/* opaque bitmap */
if ((bitmap->width == width) &&
(bitmap->height == height)) {
/* unscaled */
- bltres = SetDIBitsToDevice(hdc,
+ bltres = SetDIBitsToDevice(plot_hdc,
x, y,
width, height,
0, 0,
@@ -779,8 +735,8 @@
DIB_RGB_COLORS);
} else {
/* scaled */
- SetStretchBltMode(hdc, COLORONCOLOR);
- bltres = StretchDIBits(hdc,
+ SetStretchBltMode(plot_hdc, COLORONCOLOR);
+ bltres = StretchDIBits(plot_hdc,
x, y,
width, height,
0, 0,
@@ -794,28 +750,13 @@
}
} else {
/* Bitmap with alpha.*/
-#ifdef WINDOWS_GDI_ALPHA_WORKED
- BLENDFUNCTION blnd = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA };
- HDC bmihdc;
- bmihdc = CreateCompatibleDC(hdc);
- SelectObject(bmihdc, bitmap->windib);
- bltres = AlphaBlend(hdc,
- x, y,
- width, height,
- bmihdc,
- 0, 0,
- bitmap->width, bitmap->height,
- blnd);
- DeleteDC(bmihdc);
-#else
- bltres = plot_alpha_bitmap(hdc, bitmap, x, y, width, height);
- LOG(("bltres = %d", bltres));
-#endif
-
- }
+ bltres = plot_alpha_bitmap(plot_hdc, bitmap, x, y, width, height);
+ }
+
+ /* LOG(("bltres = %d", bltres)); */
DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
+
return true;
}
@@ -831,6 +772,13 @@
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
/* Bail early if we can */
+
+ LOG(("Plotting %p at %d,%d by %d,%d",bitmap, x,y,width,height));
+
+ if (bitmap == NULL) {
+ LOG(("Passed null bitmap!"));
+ return true;
+ }
/* check if nothing to plot */
if (width == 0 || height == 0)
Modified: trunk/netsurf/windows/plot.h
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/plot.h?rev=10885&...
==============================================================================
--- trunk/netsurf/windows/plot.h (original)
+++ trunk/netsurf/windows/plot.h Thu Oct 14 14:33:00 2010
@@ -19,9 +19,7 @@
#include <windows.h>
#include "desktop/gui.h"
-extern HWND current_hwnd;
-extern struct gui_window *current_gui;
-extern bool thumbnail;
+extern HDC plot_hdc;
void nsws_plot_set_scale(float s);
float nsws_plot_get_scale(void);
Modified: trunk/netsurf/windows/thumbnail.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/thumbnail.c?rev=1...
==============================================================================
--- trunk/netsurf/windows/thumbnail.c (original)
+++ trunk/netsurf/windows/thumbnail.c Thu Oct 14 14:33:00 2010
@@ -21,6 +21,7 @@
#include "content/urldb.h"
#include "desktop/browser.h"
#include "utils/log.h"
+#include "image/bitmap.h"
#include "windows/bitmap.h"
#include "windows/gui.h"
@@ -33,121 +34,54 @@
struct bitmap *bitmap,
const char *url)
{
- int width = content_get_width(content);
- int height = content_get_height(content);
- int i;
- uint8_t *pixdata;
- HDC hdc, minidc;
- HBITMAP bufferbm, minibm, minibm2;
- BITMAPINFO *bmi;
- BITMAPINFOHEADER bmih;
+ int width;
+ int height;
+ HDC hdc, bufferdc, minidc;
- LOG(("creating thumbnail %p for url %s content %p", bitmap, url, content));
- return false;
- bmi = malloc(sizeof(BITMAPINFOHEADER) + (bitmap->width * bitmap->height * 4));
- if (bmi == NULL) {
+ struct bitmap *fsbitmap;
+
+ width = min(content_get_width(content), 800);
+ height = min(content_get_height(content), 600);
+
+ LOG(("bitmap %p for url %s content %p width %d, height %d",
+ bitmap, url, content, width, height));
+
+ /* create two memory device contexts to put the bitmaps in */
+ bufferdc = CreateCompatibleDC(NULL);
+ if ((bufferdc == NULL)) {
return false;
}
- bmih.biSize = sizeof(bmih);
- bmih.biWidth = bitmap->width;
- bmih.biHeight = - bitmap->height;
- bmih.biPlanes = 1;
- bmih.biBitCount = 32;
- bmih.biCompression = BI_RGB;
- bmih.biSizeImage = 4 * bitmap->height * bitmap->width;
- bmih.biXPelsPerMeter = 3600; /* 100 dpi */
- bmih.biYPelsPerMeter = 3600;
- bmih.biClrUsed = 0;
- bmih.biClrImportant = 0;
- bmi->bmiHeader = bmih;
-/*
- doublebuffering = true;
-
- if (bufferdc != NULL)
+ minidc = CreateCompatibleDC(NULL);
+ if ((minidc == NULL)) {
DeleteDC(bufferdc);
- hdc = GetDC(current_hwnd);
-
- bufferdc = CreateCompatibleDC(hdc);
- if ((bufferdc == NULL) || (bmi == NULL)) {
- doublebuffering = false;
- ReleaseDC(current_hwnd, hdc);
return false;
}
- bufferbm = CreateCompatibleBitmap(hdc, width, height);
- if (bufferbm == NULL) {
- doublebuffering = false;
- ReleaseDC(current_hwnd, hdc);
- free(bmi);
- return false;
- }
- SelectObject(bufferdc, bufferbm);
- thumbnail = true;
+ /* create a full size bitmap and plot into it */
+ fsbitmap = bitmap_create(width, height, BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE | BITMAP_PERSISTENT);
+
+ SelectObject(bufferdc, fsbitmap->windib);
+
+ hdc = plot_hdc;
+ plot_hdc = bufferdc;
content_redraw(content, 0, 0, width, height, 0, 0,
width, height, 1.0, 0xFFFFFF);
- thumbnail = false;
-*/
-/* scale bufferbm to minibm */
-/*
- minidc = CreateCompatibleDC(hdc);
- if (minidc == NULL) {
- doublebuffering = false;
- DeleteObject(bufferbm);
- ReleaseDC(current_hwnd, hdc);
- free(bmi);
- return false;
- }
+ plot_hdc = hdc;
- minibm = CreateCompatibleBitmap(hdc, bitmap->width, bitmap->height);
- if (minibm == NULL) {
- doublebuffering = false;
- DeleteObject(bufferbm);
- DeleteDC(minidc);
- ReleaseDC(current_hwnd, hdc);
- free(bmi);
- return false;
- }
- ReleaseDC(current_hwnd, hdc);
+ /* scale bitmap bufferbm into minibm */
+ SelectObject(minidc, bitmap->windib);
+
+ bitmap->opaque = true;
+
+ StretchBlt(minidc, 0, 0, bitmap->width, bitmap->height, bufferdc, 0, 0, width, height, SRCCOPY);
- SelectObject(minidc, minibm);
-
- StretchBlt(minidc, 0, 0, bitmap->width, bitmap->height, bufferdc, 0, 0,
- width, height, SRCCOPY);
- minibm2 = CreateCompatibleBitmap(minidc, bitmap->width,
- bitmap->height);
- if (minibm2 == NULL) {
- doublebuffering = false;
- DeleteObject(bufferbm);
- DeleteObject(minibm);
- DeleteDC(minidc);
- free(bmi);
- return false;
- }
- SelectObject(minidc, minibm2);
-*/
-/* save data from minibm bmi */
-/* GetDIBits(minidc, minibm, 0, 1 - bitmap->height,
- bmi->bmiColors, bmi, DIB_RGB_COLORS);
+ DeleteDC(bufferdc);
+ DeleteDC(minidc);
+ bitmap_destroy(fsbitmap);
- pixdata = (uint8_t *)(bitmap->pixdata);
- for (i = 0; i < bitmap->width * bitmap->height; i++) {
- pixdata[4 * i] = bmi->bmiColors[i].rgbRed;
- pixdata[4 * i + 1] = bmi->bmiColors[i].rgbGreen;
- pixdata[4 * i + 2] = bmi->bmiColors[i].rgbBlue;
- pixdata[4 * i + 3] = 0xFF;
- }
- doublebuffering = false;
-
- DeleteObject(bufferbm);
- DeleteObject(minibm);
- DeleteObject(minibm2);
- DeleteDC(minidc);
- free(bmi);
if (url)
urldb_set_thumbnail(url, bitmap);
- doublebuffering = false;
return true;
-*/
}
12 years, 7 months
r10884 vince - in /trunk/netsurf: desktop/frames.c windows/gui.c
by netsurf@semichrome.net
Author: vince
Date: Wed Oct 13 19:59:39 2010
New Revision: 10884
URL: http://source.netsurf-browser.org?rev=10884&view=rev
Log:
ensure iframe stuff does not de-reference null pointers
Modified:
trunk/netsurf/desktop/frames.c
trunk/netsurf/windows/gui.c
Modified: trunk/netsurf/desktop/frames.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/frames.c?rev=1088...
==============================================================================
--- trunk/netsurf/desktop/frames.c (original)
+++ trunk/netsurf/desktop/frames.c Wed Oct 13 19:59:39 2010
@@ -124,7 +124,8 @@
int bw_width, bw_height;
int index;
- assert(bw);
+ assert(bw != NULL);
+ assert(bw->window != NULL);
/* update window dimensions */
gui_window_get_dimensions(bw->window, &bw_width, &bw_height, false);
@@ -137,9 +138,15 @@
for (index = 0; index < bw->iframe_count; index++) {
window = &(bw->iframes[index]);
- box_bounds(window->box, &rect);
- gui_window_position_frame(window->window, rect.x0, rect.y0,
- rect.x1, rect.y1);
+
+ if ((window != NULL) && (window->box != NULL)) {
+ box_bounds(window->box, &rect);
+ gui_window_position_frame(window->window,
+ rect.x0, rect.y0,
+ rect.x1, rect.y1);
+ } else {
+ LOG(("Bad IFrame window=%p, box=%p",window,window->box));
+ }
}
}
Modified: trunk/netsurf/windows/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/gui.c?rev=10884&r...
==============================================================================
--- trunk/netsurf/windows/gui.c (original)
+++ trunk/netsurf/windows/gui.c Wed Oct 13 19:59:39 2010
@@ -2006,6 +2006,8 @@
void gui_window_position_frame(struct gui_window *w, int x0, int y0,
int x1, int y1)
{
+ if (w == NULL)
+ return;
LOG(("position frame %s: %d, %d, %d, %d", w->bw->name,
x0, y0, x1, y1));
MoveWindow(w->drawingarea, x0, y0, x1-x0, y1-y0, true);
@@ -2014,9 +2016,11 @@
void gui_window_get_dimensions(struct gui_window *w, int *width, int *height,
bool scaled)
{
+ if (w == NULL)
+ return;
+
LOG(("get dimensions %p w=%d h=%d", w, w->width, w->height));
- if (w == NULL)
- return;
+
*width = w->width;
*height = w->height;
}
12 years, 7 months
r10883 vince - /trunk/netsurf/windows/plot.c
by netsurf@semichrome.net
Author: vince
Date: Wed Oct 13 19:59:01 2010
New Revision: 10883
URL: http://source.netsurf-browser.org?rev=10883&view=rev
Log:
ensure transparency is unset
Modified:
trunk/netsurf/windows/plot.c
Modified: trunk/netsurf/windows/plot.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/plot.c?rev=10883&...
==============================================================================
--- trunk/netsurf/windows/plot.c (original)
+++ trunk/netsurf/windows/plot.c Wed Oct 13 19:59:01 2010
@@ -848,7 +848,7 @@
if ((*(bitmap->pixdata + 3) & 0xff) == 0) {
return true;
}
- return plot_block(*(COLORREF *)bitmap->pixdata, x, y, x + width, y + height);
+ return plot_block((*(COLORREF *)bitmap->pixdata) & 0xffffff, x, y, x + width, y + height);
} else {
return plot_bitmap(bitmap, x, y, width, height);
@@ -859,7 +859,7 @@
* of the area. Can only be done when image is fully opaque. */
if ((bitmap->width == 1) && (bitmap->height == 1)) {
if ((*(COLORREF *)bitmap->pixdata & 0xff000000) != 0) {
- return plot_block(*(COLORREF *)bitmap->pixdata,
+ return plot_block((*(COLORREF *)bitmap->pixdata) & 0xffffff,
plot_clip.left,
plot_clip.top,
plot_clip.right,
@@ -874,7 +874,7 @@
if (bitmap->opaque) {
/** TODO: Currently using top left pixel. Maybe centre
* pixel or average value would be better. */
- return plot_block(*(COLORREF *)bitmap->pixdata,
+ return plot_block((*(COLORREF *)bitmap->pixdata) & 0xffffff,
plot_clip.left,
plot_clip.top,
plot_clip.right,
12 years, 7 months
r10882 vince - in /trunk/netsurf: Makefile windows/bitmap.c windows/bitmap.h windows/gui.c windows/plot.c windows/thumbnail.c
by netsurf@semichrome.net
Author: vince
Date: Wed Oct 13 15:29:30 2010
New Revision: 10882
URL: http://source.netsurf-browser.org?rev=10882&view=rev
Log:
fix bitmap plotting
Modified:
trunk/netsurf/Makefile
trunk/netsurf/windows/bitmap.c
trunk/netsurf/windows/bitmap.h
trunk/netsurf/windows/gui.c
trunk/netsurf/windows/plot.c
trunk/netsurf/windows/thumbnail.c
Modified: trunk/netsurf/Makefile
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile?rev=10882&r1=108...
==============================================================================
--- trunk/netsurf/Makefile (original)
+++ trunk/netsurf/Makefile Wed Oct 13 15:29:30 2010
@@ -498,6 +498,8 @@
-lparserutils -lssl -lcrypto -lregex -liconv -lcss -lwapcaplet \
-lgdi32 -lcomctl32 -lws2_32 -lmsimg32 -mwindows
CFLAGS += -U__STRICT_ANSI__ -mwin32
+ # only windows versions after 2000 are supported
+ CFLAGS += '-DWINVER=0x0500'
WSCFLAGS := -std=c99 \
$(WARNFLAGS) -I. -I/${MINGW_INSTALL_ENV}/include \
-DCURL_STATICLIB \
Modified: trunk/netsurf/windows/bitmap.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/bitmap.c?rev=1088...
==============================================================================
--- trunk/netsurf/windows/bitmap.c (original)
+++ trunk/netsurf/windows/bitmap.c Wed Oct 13 15:29:30 2010
@@ -20,6 +20,7 @@
#include <inttypes.h>
#include <sys/types.h>
#include <string.h>
+#include <windows.h>
#include "image/bitmap.h"
#include "windows/bitmap.h"
@@ -38,19 +39,49 @@
void *bitmap_create(int width, int height, unsigned int state)
{
struct bitmap *bitmap;
+ BITMAPV5HEADER *pbmi;
+ BITMAP *windib;
+ uint8_t *pixdata;
+
LOG(("width %d, height %d, state %u",width,height,state));
+
+ pbmi = calloc(1, sizeof(BITMAPV5HEADER));
+ if (pbmi == NULL) {
+ return NULL;
+ }
+ pbmi->bV5Size = sizeof(BITMAPV5HEADER);
+ pbmi->bV5Width = width;
+ pbmi->bV5Height = -height;
+ pbmi->bV5Planes = 1;
+ pbmi->bV5BitCount = 32;
+ pbmi->bV5Compression = BI_BITFIELDS;
+
+ pbmi->bV5RedMask = 0xff; /* red mask */
+ pbmi->bV5GreenMask = 0xff00; /* green mask */
+ pbmi->bV5BlueMask = 0xff0000; /* blue mask */
+ pbmi->bV5AlphaMask = 0xff000000; /* alpha mask */
+
+ windib = CreateDIBSection(NULL, (BITMAPINFO *)pbmi, DIB_RGB_COLORS, &pixdata, NULL, 0);
+
+
+ if (windib == NULL) {
+ free(pbmi);
+ return NULL;
+ }
+
bitmap = calloc(1 , sizeof(struct bitmap));
- if (bitmap) {
- bitmap->pixdata = calloc(width * height, 4);
- if (bitmap->pixdata != NULL) {
- bitmap->width = width;
- bitmap->height = height;
- bitmap->opaque = false;
- } else {
- free(bitmap);
- bitmap=NULL;
- }
- }
+ if (bitmap == NULL) {
+ DeleteObject(windib);
+ free(pbmi);
+ return NULL;
+ }
+
+ bitmap->width = width;
+ bitmap->height = height;
+ bitmap->windib = windib;
+ bitmap->pbmi = pbmi;
+ bitmap->pixdata = pixdata;
+ bitmap->opaque = false;
LOG(("bitmap %p", bitmap));
@@ -114,8 +145,9 @@
LOG(("NULL bitmap!"));
return;
}
-
- free(bm->pixdata);
+
+ DeleteObject(bm->windib);
+ free(bm->pbmi);
free(bm);
}
Modified: trunk/netsurf/windows/bitmap.h
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/bitmap.h?rev=1088...
==============================================================================
--- trunk/netsurf/windows/bitmap.h (original)
+++ trunk/netsurf/windows/bitmap.h Wed Oct 13 15:29:30 2010
@@ -23,6 +23,8 @@
#include "desktop/plotters.h"
struct bitmap {
+ BITMAP *windib;
+ BITMAPV5HEADER *pbmi;
int width;
int height;
uint8_t *pixdata;
Modified: trunk/netsurf/windows/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/gui.c?rev=10882&r...
==============================================================================
--- trunk/netsurf/windows/gui.c (original)
+++ trunk/netsurf/windows/gui.c Wed Oct 13 15:29:30 2010
@@ -728,7 +728,7 @@
(gw->bw != NULL) &&
(gw->bw->current_content != NULL)) {
/* set globals for the plotters */
- current_hwnd = gw->drawingarea;
+ current_hwnd = hwnd;
current_gui = gw;
content_redraw(gw->bw->current_content,
Modified: trunk/netsurf/windows/plot.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/plot.c?rev=10882&...
==============================================================================
--- trunk/netsurf/windows/plot.c (original)
+++ trunk/netsurf/windows/plot.c Wed Oct 13 15:29:30 2010
@@ -53,6 +53,8 @@
static RECT localhistory_clip;
+static RECT plot_clip;
+
static bool clip(int x0, int y0, int x1, int y1)
{
@@ -72,7 +74,13 @@
clip->top = y0 ;
clip->right = x1;
clip->bottom = y1;
-
+
+
+ plot_clip.left = x0;
+ plot_clip.top = y0;
+ plot_clip.right = x1 + 1; /* rectangle co-ordinates are exclusive */
+ plot_clip.bottom = y1 + 1; /* rectangle co-ordinates are exclusive */
+
return true;
}
@@ -122,16 +130,16 @@
r.top = y0;
r.right = x1;
r.bottom = y1;
-
+
SelectClipRgn(hdc, clipregion);
-
+
MoveToEx(hdc, x0, y0, (LPPOINT) NULL);
LineTo(hdc, x1, y1);
-
+
SelectClipRgn(hdc, NULL);
/* ValidateRect(current_hwnd, &r);
- */
+ */
pen = SelectObject(hdc, bak);
DeleteObject(pen);
DeleteObject(clipregion);
@@ -140,19 +148,11 @@
return true;
}
-static bool rectangle(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)
{
x1++;
y1++;
-/* x0 = MAX(x0, 0);
- y0 = MAX(y0, 0);
- if (!((current_gui == NULL) || (thumbnail))) {
- x1 = MIN(x1, gui_window_width(current_gui));
- y1 = MIN(y1, gui_window_height(current_gui));
- }
-*/
-#if NSWS_PLOT_DEBUG
+#if NSWS_PLOT_DEBUG
LOG(("rectangle from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1,
thumbnail));
#endif
@@ -160,37 +160,24 @@
if (hdc == NULL) {
return false;
}
-/* RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
- if (clipregion == NULL) {
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
-*/
COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF);
- DWORD penstyle = PS_GEOMETRIC |
+ DWORD penstyle = PS_GEOMETRIC |
(style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT :
(style->stroke_type == PLOT_OP_TYPE_DASH ? PS_DASH :
- (style->stroke_type == PLOT_OP_TYPE_NONE ? PS_NULL :
+ (style->stroke_type == PLOT_OP_TYPE_NONE ? PS_NULL :
0)));
LOGBRUSH lb = {BS_SOLID, pencol, 0};
LOGBRUSH lb1 = {BS_SOLID, style->fill_colour, 0};
if (style->fill_type == PLOT_OP_TYPE_NONE)
lb1.lbStyle = BS_HOLLOW;
-
+
HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL);
if (pen == NULL) {
-// DeleteObject(clipregion);
-
ReleaseDC(current_hwnd, hdc);
return false;
}
HGDIOBJ penbak = SelectObject(hdc, (HGDIOBJ) pen);
if (penbak == NULL) {
-// DeleteObject(clipregion);
DeleteObject(pen);
ReleaseDC(current_hwnd, hdc);
@@ -198,7 +185,6 @@
}
HBRUSH brush = CreateBrushIndirect(&lb1);
if (brush == NULL) {
-// DeleteObject(clipregion);
SelectObject(hdc, penbak);
DeleteObject(pen);
@@ -207,7 +193,6 @@
}
HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush);
if (brushbak == NULL) {
-// DeleteObject(clipregion);
SelectObject(hdc, penbak);
DeleteObject(pen);
DeleteObject(brush);
@@ -215,22 +200,11 @@
ReleaseDC(current_hwnd, hdc);
return false;
}
- RECT r;
- r.left = x0;
- r.top = y0;
- r.right = x1;
- r.bottom = y1;
-
- //SelectClipRgn(hdc, clipregion);
-
+
Rectangle(hdc, x0, y0, x1, y1);
- //SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
pen = SelectObject(hdc, penbak);
brush = SelectObject(hdc, brushbak);
-// DeleteObject(clipregion);
DeleteObject(pen);
DeleteObject(brush);
@@ -303,9 +277,9 @@
printf ("%ld,%ld ", points[i].x, points[i].y);
#endif
}
-
+
SelectClipRgn(hdc, clipregion);
-
+
if (n >= 2)
Polygon(hdc, points, n);
@@ -325,7 +299,7 @@
}
-static bool text(int x, int y, const char *text, size_t length,
+static bool text(int x, int y, const char *text, size_t length,
const plot_font_style_t *style)
{
#if NSWS_PLOT_DEBUG
@@ -343,7 +317,7 @@
ReleaseDC(current_hwnd, hdc);
return false;
}
-
+
HFONT fontbak, font = get_font(style);
if (font == NULL) {
DeleteObject(clipregion);
@@ -364,9 +338,9 @@
r.bottom = y + s.cy / 4;
SelectClipRgn(hdc, clipregion);
-
+
SetTextAlign(hdc, TA_BASELINE | TA_LEFT);
- if ((style->background & 0xFF000000) != 0x01000000)
+ if ((style->background & 0xFF000000) != 0x01000000)
/* 100% alpha */
SetBkColor(hdc, (DWORD) (style->background & 0x00FFFFFF));
SetBkMode(hdc, TRANSPARENT);
@@ -410,7 +384,7 @@
ReleaseDC(current_hwnd, hdc);
return false;
}
-
+
COLORREF col = (DWORD)((style->fill_colour | style->stroke_colour)
& 0x00FFFFFF);
HPEN pen = CreatePen(PS_GEOMETRIC | PS_SOLID, 1, col);
@@ -454,7 +428,7 @@
r.bottom = y + radius;
SelectClipRgn(hdc, clipregion);
-
+
if (style->fill_type == PLOT_OP_TYPE_NONE)
Arc(hdc, x - radius, y - radius, x + radius, y + radius,
x - radius, y - radius,
@@ -526,7 +500,7 @@
q2 += 4;
angle1 = ((angle1 + 45) % 90) - 45;
angle2 = ((angle2 + 45) % 90) - 45;
-
+
switch(q1) {
case 1:
a1 = 1.0;
@@ -545,7 +519,7 @@
a1 = tan((M_PI / 180) * angle1);
break;
}
-
+
switch(q2) {
case 1:
a2 = 1.0;
@@ -564,18 +538,18 @@
a2 = tan((M_PI / 180) * angle2);
break;
}
-
+
r.left = x - radius;
r.top = y - radius;
r.right = x + radius;
r.bottom = y + radius;
SelectClipRgn(hdc, clipregion);
-
+
Arc(hdc, x - radius, y - radius, x + radius, y + radius,
x + (int)(a1 * radius), y + (int)(b1 * radius),
x + (int)(a2 * radius), y + (int)(b2 * radius));
-
+
SelectClipRgn(hdc, NULL);
/* ValidateRect(current_hwnd, &r);
*/
@@ -587,90 +561,109 @@
return true;
}
-
-static bool bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bitmap_flags_t flags)
-{
-#if NSWS_PLOT_DEBUG
- LOG(("%p bitmap %d,%d width %d height %d", current_hwnd, x, y, width,
- height));
-#endif
- if (bitmap == NULL)
- return false;
- HDC hdc = GetDC(current_hwnd);
+static bool
+plot_block(COLORREF col, int x, int y, int width, int height)
+{
+ HDC hdc;
+ HRGN clipregion;
+ HGDIOBJ original = NULL;
+
+ /* Bail early if we can */
+ if ((x >= plot_clip.right) ||
+ ((x + width) < plot_clip.left) ||
+ (y >= plot_clip.bottom) ||
+ ((y + height) < plot_clip.top)) {
+ /* Image completely outside clip region */
+ return true;
+ }
+
+ clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
+ return false;
+ }
+
+ hdc = GetDC(current_hwnd);
if (hdc == NULL) {
- return false;
- }
- RECT *cliprect = gui_window_clip_rect(current_gui);
- if (cliprect == NULL)
- cliprect = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(cliprect);
- if (clipregion == NULL) {
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HDC Memhdc = CreateCompatibleDC(hdc);
- if (Memhdc == NULL) {
- DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
+ DeleteObject(clipregion);
+ return false;
+ }
+
+ SelectClipRgn(hdc, clipregion);
+
+ /* Saving the original pen object */
+ original = SelectObject(hdc,GetStockObject(DC_PEN));
+
+ SelectObject(hdc, GetStockObject(DC_PEN));
+ SelectObject(hdc, GetStockObject(DC_BRUSH));
+ SetDCPenColor(hdc, col);
+ SetDCBrushColor(hdc, col);
+ Rectangle(hdc,x,y,width,height);
+
+ SelectObject(hdc,original); /* Restoring the original pen object */
+
+ DeleteObject(clipregion);
+ ReleaseDC(current_hwnd, hdc);
+ return true;
+
+}
+
+/* blunt force truma way of achiving alpha blended plotting */
+static bool
+plot_alpha_bitmap(HDC hdc,
+ struct bitmap *bitmap,
+ int x, int y,
+ int width, int height)
+{
+ HDC Memhdc;
BITMAPINFOHEADER bmih;
- RECT r;
int v, vv, vi, h, hh, width4, transparency;
unsigned char alpha;
- bool modifying = false;
-
- SelectClipRgn(hdc, clipregion);
- if ((bitmap->width != width) || (bitmap->height != height)) {
+ bool isscaled = false; /* set if the scaled bitmap requires freeing */
+ BITMAP MemBM;
+ 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
+
+ assert(bitmap != NULL);
+
+ Memhdc = CreateCompatibleDC(hdc);
+ if (Memhdc == NULL) {
+ return false;
+ }
+
+ if ((bitmap->width != width) ||
+ (bitmap->height != height)) {
+ LOG(("scaling from %d,%d to %d,%d",
+ bitmap->width, bitmap->height, width, height));
bitmap = bitmap_scale(bitmap, width, height);
if (bitmap == NULL)
return false;
- modifying = true;
- }
-
- if ((flags & BITMAPF_REPEAT_X) || (flags & BITMAPF_REPEAT_Y)) {
- struct bitmap *prebitmap = bitmap_pretile(bitmap,
- cliprect->right - x,
- cliprect->bottom - y, flags);
- if (prebitmap == NULL)
- return false;
- if (modifying) {
- free(bitmap->pixdata);
- free(bitmap);
- }
- modifying = true;
- bitmap = prebitmap;
- }
- BITMAP MemBM;
- BITMAPINFO *bmi = (BITMAPINFO *) malloc(sizeof(BITMAPINFOHEADER) +
- (bitmap->width * bitmap->height * 4));
+ isscaled = true;
+ }
+
+ bmi = (BITMAPINFO *) malloc(sizeof(BITMAPINFOHEADER) +
+ (bitmap->width * bitmap->height * 4));
if (bmi == NULL) {
- DeleteObject(clipregion);
DeleteDC(Memhdc);
-
- ReleaseDC(current_hwnd, hdc);
- return false;
- }
- HBITMAP MemBMh = CreateCompatibleBitmap(
- hdc, bitmap->width, bitmap->height);
+ return false;
+ }
+
+ MemBMh = CreateCompatibleBitmap(hdc, bitmap->width, bitmap->height);
if (MemBMh == NULL){
- DeleteObject(clipregion);
free(bmi);
DeleteDC(Memhdc);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
/* save 'background' data for alpha channel work */
SelectObject(Memhdc, MemBMh);
- BitBlt(Memhdc, 0, 0, bitmap->width, bitmap->height, hdc, x, y,
- SRCCOPY);
+ BitBlt(Memhdc, 0, 0, bitmap->width, bitmap->height, hdc, x, y, SRCCOPY);
GetObject(MemBMh, sizeof(BITMAP), &MemBM);
-
+
bmih.biSize = sizeof(bmih);
bmih.biWidth = bitmap->width;
bmih.biHeight = bitmap->height;
@@ -683,15 +676,15 @@
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
bmi->bmiHeader = bmih;
-
+
GetDIBits(hdc, MemBMh, 0, bitmap->height, bmi->bmiColors, bmi,
DIB_RGB_COLORS);
-
+
/* then load 'foreground' bits from bitmap->pixdata */
-
+
width4 = bitmap->width * 4;
- for (v = 0, vv = 0, vi = (bitmap->height - 1) * width4;
- v < bitmap->height;
+ for (v = 0, vv = 0, vi = (bitmap->height - 1) * width4;
+ v < bitmap->height;
v++, vv += bitmap->width, vi -= width4) {
for (h = 0, hh = 0; h < bitmap->width; h++, hh += 4) {
alpha = bitmap->pixdata[vi + hh + 3];
@@ -701,13 +694,13 @@
bitmap->pixdata[vi + hh + 2];
bmi->bmiColors[vv + h].rgbGreen =
bitmap->pixdata[vi + hh + 1];
- bmi->bmiColors[vv + h].rgbRed =
+ bmi->bmiColors[vv + h].rgbRed =
bitmap->pixdata[vi + hh];
} else if (alpha > 0) {
transparency = 0x100 - alpha;
bmi->bmiColors[vv + h].rgbBlue =
(bmi->bmiColors[vv + h].rgbBlue
- * transparency +
+ * transparency +
(bitmap->pixdata[vi + hh + 2]) *
alpha) >> 8;
bmi->bmiColors[vv + h].rgbGreen =
@@ -722,60 +715,203 @@
bitmap->pixdata[vi + hh]
* alpha) >> 8;
}
-/* alternative simple 2/3 stage alpha value handling */
-/* if (bitmap->pixdata[vi + hh + 3] > 0xAA) {
- bmi->bmiColors[vv + h].rgbBlue =
- bitmap->pixdata[vi + hh + 2];
- bmi->bmiColors[vv + h].rgbGreen =
- bitmap->pixdata[vi + hh + 1];
- bmi->bmiColors[vv + h].rgbRed =
- bitmap->pixdata[vi + hh];
- } else if (bitmap->pixdata[vi + hh + 3] > 0x70){
- bmi->bmiColors[vv + h].rgbBlue =
- (bmi->bmiColors[vv + h].rgbBlue +
- bitmap->pixdata[vi + hh + 2]) / 2;
- bmi->bmiColors[vv + h].rgbRed =
- (bmi->bmiColors[vv + h].rgbRed +
- bitmap->pixdata[vi + hh]) / 2;
- bmi->bmiColors[vv + h].rgbGreen =
- (bmi->bmiColors[vv + h].rgbGreen +
- bitmap->pixdata[vi + hh + 1]) / 2;
- } else if (bitmap->pixdata[vi + hh + 3] > 0x30){
- bmi->bmiColors[vv + h].rgbBlue =
- (bmi->bmiColors[vv + h].rgbBlue * 3 +
- bitmap->pixdata[vi + hh + 2]) / 4;
- bmi->bmiColors[vv + h].rgbRed =
- (bmi->bmiColors[vv + h].rgbRed * 3 +
- bitmap->pixdata[vi + hh]) / 4;
- bmi->bmiColors[vv + h].rgbGreen =
- (bmi->bmiColors[vv + h].rgbGreen * 3 +
- bitmap->pixdata[vi + hh + 1]) / 4;
- }
-*/ }
+ }
}
SetDIBitsToDevice(hdc, x, y, bitmap->width, bitmap->height,
- 0, 0, 0, bitmap->height, (const void *) bmi->bmiColors,
+ 0, 0, 0, bitmap->height,
+ (const void *) bmi->bmiColors,
bmi, DIB_RGB_COLORS);
-
- r.left = x;
- r.top = y;
- r.right = x + bitmap->width;
- r.bottom = y + bitmap->height;
- if (modifying && bitmap && bitmap->pixdata) {
+
+ if (isscaled && bitmap && bitmap->pixdata) {
free(bitmap->pixdata);
free(bitmap);
}
-
-/* ValidateRect(current_hwnd, &r);
- */ free(bmi);
-/* SelectClipRgn(hdc, NULL);
- */ DeleteObject(clipregion);
+
+ free(bmi);
DeleteObject(MemBMh);
DeleteDC(Memhdc);
-
+ return true;
+}
+
+
+static bool
+plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height)
+{
+ int bltres;
+ HDC hdc;
+ HRGN clipregion;
+
+ /* Bail early if we can */
+ if ((x >= plot_clip.right) ||
+ ((x + width) < plot_clip.left) ||
+ (y >= plot_clip.bottom) ||
+ ((y + height) < plot_clip.top)) {
+ /* Image completely outside clip region */
+ return true;
+ }
+
+ clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
+ return false;
+ }
+
+ hdc = GetDC(current_hwnd);
+ if (hdc == NULL) {
+ DeleteObject(clipregion);
+ return false;
+ }
+
+ SelectClipRgn(hdc, clipregion);
+
+ if (bitmap->opaque) {
+ /* opaque bitmap */
+ if ((bitmap->width == width) &&
+ (bitmap->height == height)) {
+ /* unscaled */
+ bltres = SetDIBitsToDevice(hdc,
+ x, y,
+ width, height,
+ 0, 0,
+ 0,
+ height,
+ bitmap->pixdata,
+ (BITMAPINFO *)bitmap->pbmi,
+ DIB_RGB_COLORS);
+ } else {
+ /* scaled */
+ SetStretchBltMode(hdc, COLORONCOLOR);
+ bltres = StretchDIBits(hdc,
+ x, y,
+ width, height,
+ 0, 0,
+ bitmap->width, bitmap->height,
+ bitmap->pixdata,
+ (BITMAPINFO *)bitmap->pbmi,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+
+
+ }
+ } else {
+ /* Bitmap with alpha.*/
+#ifdef WINDOWS_GDI_ALPHA_WORKED
+ BLENDFUNCTION blnd = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA };
+ HDC bmihdc;
+ bmihdc = CreateCompatibleDC(hdc);
+ SelectObject(bmihdc, bitmap->windib);
+ bltres = AlphaBlend(hdc,
+ x, y,
+ width, height,
+ bmihdc,
+ 0, 0,
+ bitmap->width, bitmap->height,
+ blnd);
+ DeleteDC(bmihdc);
+#else
+ bltres = plot_alpha_bitmap(hdc, bitmap, x, y, width, height);
+ LOG(("bltres = %d", bltres));
+#endif
+
+ }
+
+ DeleteObject(clipregion);
ReleaseDC(current_hwnd, hdc);
return true;
-}
+
+}
+
+static bool
+windows_plot_bitmap(int x, int y,
+ int width, int height,
+ struct bitmap *bitmap, colour bg,
+ bitmap_flags_t flags)
+{
+ int xf,yf;
+ bool repeat_x = (flags & BITMAPF_REPEAT_X);
+ bool repeat_y = (flags & BITMAPF_REPEAT_Y);
+
+ /* Bail early if we can */
+
+ /* check if nothing to plot */
+ if (width == 0 || height == 0)
+ return true;
+
+ /* x and y define coordinate of top left of of the initial explicitly
+ * placed tile. The width and height are the image scaling and the
+ * bounding box defines the extent of the repeat (which may go in all
+ * four directions from the initial tile).
+ */
+
+ if (!(repeat_x || repeat_y)) {
+ /* Not repeating at all, so just plot it */
+ if ((bitmap->width == 1) && (bitmap->height == 1)) {
+ if ((*(bitmap->pixdata + 3) & 0xff) == 0) {
+ return true;
+ }
+ return plot_block(*(COLORREF *)bitmap->pixdata, x, y, x + width, y + height);
+
+ } else {
+ return plot_bitmap(bitmap, x, y, width, height);
+ }
+ }
+
+ /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill
+ * of the area. Can only be done when image is fully opaque. */
+ if ((bitmap->width == 1) && (bitmap->height == 1)) {
+ if ((*(COLORREF *)bitmap->pixdata & 0xff000000) != 0) {
+ return plot_block(*(COLORREF *)bitmap->pixdata,
+ plot_clip.left,
+ plot_clip.top,
+ plot_clip.right,
+ plot_clip.bottom);
+ }
+ }
+
+ /* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with
+ * a flat fill of the area. Can only be done when image is fully
+ * opaque. */
+ if ((width == 1) && (height == 1)) {
+ if (bitmap->opaque) {
+ /** TODO: Currently using top left pixel. Maybe centre
+ * pixel or average value would be better. */
+ return plot_block(*(COLORREF *)bitmap->pixdata,
+ plot_clip.left,
+ plot_clip.top,
+ plot_clip.right,
+ 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));
+*/
+
+ /* get left most tile position */
+ if (repeat_x)
+ for (; x > plot_clip.left; x -= width);
+
+ /* get top most tile position */
+ 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));
+*/
+
+ /* tile down and across to extents */
+ for (xf = x; xf < plot_clip.right; xf += width) {
+ for (yf = y; yf < plot_clip.bottom; yf += height) {
+
+ plot_bitmap(bitmap, xf, yf, width, height);
+ if (!repeat_y)
+ break;
+ }
+ if (!repeat_x)
+ break;
+ }
+ return true;
+}
+
static bool flush(void)
{
@@ -812,7 +948,7 @@
.text = text,
.disc = disc,
.arc = arc,
- .bitmap = bitmap,
+ .bitmap = windows_plot_bitmap,
.flush = flush,
.path = path,
.option_knockout = true,
Modified: trunk/netsurf/windows/thumbnail.c
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/thumbnail.c?rev=1...
==============================================================================
--- trunk/netsurf/windows/thumbnail.c (original)
+++ trunk/netsurf/windows/thumbnail.c Wed Oct 13 15:29:30 2010
@@ -15,6 +15,8 @@
* 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 <windows.h>
#include "content/urldb.h"
#include "desktop/browser.h"
12 years, 7 months