summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--windows/font.c4
-rw-r--r--windows/gui.c28
-rw-r--r--windows/gui.h3
-rw-r--r--windows/localhistory.c94
-rw-r--r--windows/plot.c376
-rw-r--r--windows/plot.h4
-rw-r--r--windows/thumbnail.c136
7 files changed, 252 insertions, 393 deletions
diff --git a/windows/font.c b/windows/font.c
index 246c3b713..ada54eef0 100644
--- a/windows/font.c
+++ b/windows/font.c
@@ -76,9 +76,9 @@ HFONT get_font(const plot_font_style_t *style)
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 */
diff --git a/windows/gui.c b/windows/gui.c
index 0c29cfdad..85833fecf 100644
--- a/windows/gui.c
+++ b/windows/gui.c
@@ -70,6 +70,7 @@ char *options_file_location;
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 @@ struct gui_window {
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 @@ void gui_poll(bool active)
{
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 @@ static LRESULT
nsws_drawable_paint(struct gui_window *gw, HWND hwnd)
{
PAINTSTRUCT ps;
+ HDC hdc, tmp_hdc;
- BeginPaint(hwnd, &ps);
+ 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 @@ nsws_drawable_paint(struct gui_window *gw, HWND hwnd)
gw->bw->scale,
0xFFFFFF);
+ plot_hdc = tmp_hdc;
}
EndPaint(hwnd, &ps);
@@ -1422,8 +1425,6 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return DefWindowProc(hwnd, msg, wparam, lparam);
}
- current_gui = gw;
-
switch(msg) {
/*
@@ -1640,7 +1641,7 @@ gui_create_browser_window(struct browser_window *bw,
/* 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 @@ RECT *gui_window_redraw_rect(struct gui_window *w)
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)
diff --git a/windows/gui.h b/windows/gui.h
index e91da3946..f4eca062c 100644
--- a/windows/gui.h
+++ b/windows/gui.h
@@ -63,6 +63,8 @@ struct browser_mouse {
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 @@ void gui_window_set_localhistory(struct gui_window *,
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 *);
diff --git a/windows/localhistory.c b/windows/localhistory.c
index 4a07d5f24..258d72df4 100644
--- a/windows/localhistory.c
+++ b/windows/localhistory.c
@@ -71,8 +71,7 @@ void nsws_localhistory_init(struct gui_window *w)
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 @@ void nsws_localhistory_init(struct gui_window *w)
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 @@ LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg,
}
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 @@ LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg,
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 @@ LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg,
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 @@ LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg,
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 @@ LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg,
nsws_localhistory_clear(w);
DestroyWindow(hwnd);
break;
+
case WM_DESTROY:
nsws_localhistory_clear(w);
PostQuitMessage(0);
break;
+
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
diff --git a/windows/plot.c b/windows/plot.c
index 93789b776..517dd4c7c 100644
--- a/windows/plot.c
+++ b/windows/plot.c
@@ -44,37 +44,20 @@
#endif
/* set NSWS_PLOT_DEBUG to 0 for no debugging, 1 for debugging */
-#define NSWS_PLOT_DEBUG 0
+#define NSWS_PLOT_DEBUG 1
-HWND current_hwnd;
-struct gui_window *current_gui;
-bool thumbnail = false;
-static float nsws_plot_scale = 1.0;
-static RECT localhistory_clip;
+HDC plot_hdc;
+static float nsws_plot_scale = 1.0;
-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));
+ LOG(("clip %d,%d to %d,%d", x0, y0, x1, y1));
#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;
-
plot_clip.left = x0;
plot_clip.top = y0;
@@ -87,22 +70,20 @@ static bool clip(int x0, int y0, int x1, int y1)
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));
+ LOG(("from %d,%d to %d,%d", x0, y0, x1, y1));
#endif
- RECT *clipr = gui_window_clip_rect(current_gui);
- if (clipr == NULL)
- clipr = &localhistory_clip;
- HRGN clipregion = CreateRectRgnIndirect(clipr);
- if (clipregion == NULL) {
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
return false;
}
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
return false;
}
+
COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF);
/* windows 0x00bbggrr */
DWORD penstyle = PS_GEOMETRIC | ((style->stroke_type ==
@@ -113,16 +94,12 @@ static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style)
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);
+ 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 @@ static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style)
r.right = x1;
r.bottom = y1;
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
- MoveToEx(hdc, x0, y0, (LPPOINT) NULL);
+ MoveToEx(plot_hdc, x0, y0, (LPPOINT) NULL);
- LineTo(hdc, x1, y1);
+ LineTo(plot_hdc, x1, y1);
+
+ SelectClipRgn(plot_hdc, NULL);
+ pen = SelectObject(plot_hdc, bak);
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
- pen = SelectObject(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)
{
- x1++;
- y1++;
#if NSWS_PLOT_DEBUG
- LOG(("rectangle from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1,
- thumbnail));
+ LOG(("rectangle from %d,%d to %d,%d", x0, y0, x1, y1));
#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
+
+ /* 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++;
+
COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF);
DWORD penstyle = PS_GEOMETRIC |
(style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT :
@@ -173,42 +156,38 @@ static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
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);
+ 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);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
- HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush);
+ 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);
+ SelectClipRgn(plot_hdc, clipregion);
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ 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);
+ DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
return true;
}
@@ -216,59 +195,51 @@ static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
static bool polygon(const int *p, unsigned int n, const plot_style_t *style)
{
#if NSWS_PLOT_DEBUG
- LOG(("polygon %d points thumbnail %d", n, thumbnail));
+ LOG(("polygon %d points", n));
#endif
- POINT points[n];
- unsigned int i;
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
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);
+ POINT points[n];
+ unsigned int i;
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
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);
+ 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);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
- HBRUSH brushbak = SelectObject(hdc, brush);
+ 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);
+ 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 @@ static bool polygon(const int *p, unsigned int n, const plot_style_t *style)
#endif
}
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
if (n >= 2)
- Polygon(hdc, points, n);
+ Polygon(plot_hdc, points, n);
- SelectClipRgn(hdc, NULL);
+ SelectClipRgn(plot_hdc, NULL);
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ 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 @@ static bool text(int x, int y, const char *text, size_t length,
const plot_font_style_t *style)
{
#if NSWS_PLOT_DEBUG
- LOG(("words %s at %d,%d thumbnail %d", text, x, y, thumbnail));
+ LOG(("words %s at %d,%d", text, x, y));
#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
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;
}
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);
+ SelectClipRgn(plot_hdc, clipregion);
- SetTextAlign(hdc, TA_BASELINE | TA_LEFT);
+ 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 @@ static bool text(int x, int y, const char *text, size_t length,
return false;
}
MultiByteToWideChar(CP_UTF8, 0, text, length, wstring, wlen);
- TextOutW(hdc, x, y, wstring, wlen);
+ TextOutW(plot_hdc, x, y, wstring, wlen);
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
+ 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));
+ LOG(("disc at %d,%d radius %d", x, y, radius));
#endif
- HDC hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
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);
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
return false;
}
@@ -390,35 +352,27 @@ static bool disc(int x, int y, int radius, const plot_style_t *style)
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);
+ 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);
+ SelectObject(plot_hdc, penbak);
DeleteObject(pen);
-
- ReleaseDC(current_hwnd, hdc);
return false;
}
- HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush);
+ 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 @@ static bool disc(int x, int y, int radius, const plot_style_t *style)
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);
+ Ellipse(plot_hdc, x - radius, y - radius, x + radius, y + radius);
- SelectClipRgn(hdc, NULL);
-/* ValidateRect(current_hwnd, &r);
- */
- pen = SelectObject(hdc, penbak);
- brush = SelectObject(hdc, brushbak);
+ 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 @@ static bool arc(int x, int y, int radius, int angle1, int angle2,
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) {
+
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
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);
+ HRGN clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
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);
+ 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 @@ static bool arc(int x, int y, int radius, int angle1, int angle2,
r.right = x + radius;
r.bottom = y + radius;
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
- Arc(hdc, x - radius, y - radius, x + radius, y + radius,
+ 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 @@ plot_block(COLORREF col, int x, int y, int width, int height)
return true;
}
- clipregion = CreateRectRgnIndirect(&plot_clip);
- if (clipregion == NULL) {
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
return false;
}
- hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
+ clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
return false;
}
- SelectClipRgn(hdc, clipregion);
+ SelectClipRgn(plot_hdc, clipregion);
/* Saving the original pen object */
- original = SelectObject(hdc,GetStockObject(DC_PEN));
+ original = SelectObject(plot_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(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(hdc,original); /* Restoring the original pen object */
+ SelectObject(plot_hdc,original); /* Restoring the original pen object */
DeleteObject(clipregion);
- ReleaseDC(current_hwnd, hdc);
+
return true;
}
@@ -614,6 +556,22 @@ plot_alpha_bitmap(HDC hdc,
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;
@@ -628,8 +586,6 @@ plot_alpha_bitmap(HDC hdc,
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;
@@ -731,6 +687,7 @@ plot_alpha_bitmap(HDC hdc,
DeleteObject(MemBMh);
DeleteDC(Memhdc);
return true;
+#endif
}
@@ -738,7 +695,6 @@ 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 */
@@ -750,25 +706,25 @@ plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height)
return true;
}
- clipregion = CreateRectRgnIndirect(&plot_clip);
- if (clipregion == NULL) {
+ /* ensure the plot HDC is set */
+ if (plot_hdc == NULL) {
+ LOG(("HDC not set on call to plotters"));
return false;
}
- hdc = GetDC(current_hwnd);
- if (hdc == NULL) {
- DeleteObject(clipregion);
+ clipregion = CreateRectRgnIndirect(&plot_clip);
+ if (clipregion == NULL) {
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 @@ plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height)
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 @@ plot_bitmap(struct bitmap *bitmap, int x, int y, int width, int height)
}
} 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;
}
@@ -832,6 +773,13 @@ windows_plot_bitmap(int x, int y,
/* Bail early if we can */
+ LOG(("Plotting %p at %d,%d by %d,%d",bitmap, x,y,width,height));
+
+ if (bitmap == NULL) {
+ LOG(("Passed null bitmap!"));
+ return true;
+ }
+
/* check if nothing to plot */
if (width == 0 || height == 0)
return true;
diff --git a/windows/plot.h b/windows/plot.h
index 157ce82df..5e6eac16c 100644
--- a/windows/plot.h
+++ b/windows/plot.h
@@ -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);
diff --git a/windows/thumbnail.c b/windows/thumbnail.c
index 6b372a828..dece47253 100644
--- a/windows/thumbnail.c
+++ b/windows/thumbnail.c
@@ -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 @@ thumbnail_create(hlcache_handle *content,
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;
-
- 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) {
+ int width;
+ int height;
+ HDC hdc, bufferdc, minidc;
+
+ 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);
-
- SelectObject(minidc, minibm);
+ /* 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);
- 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);
-
- 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(bufferdc);
DeleteDC(minidc);
- free(bmi);
+ bitmap_destroy(fsbitmap);
+
if (url)
urldb_set_thumbnail(url, bitmap);
- doublebuffering = false;
return true;
-*/
}