Update windows frontend for set_scroll API change

This commit is contained in:
Vincent Sanders 2017-04-26 22:27:49 +01:00
parent c100a33285
commit 5fba1fb94d
3 changed files with 62 additions and 54 deletions

View File

@ -137,8 +137,10 @@ nsws_drawable_vscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam)
SetScrollInfo(hwnd, SB_VERT, &si, TRUE); SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
GetScrollInfo(hwnd, SB_VERT, &si); GetScrollInfo(hwnd, SB_VERT, &si);
if (si.nPos != mem) { if (si.nPos != mem) {
win32_window_set_scroll(gw, gw->scrollx, gw->scrolly + struct rect rect;
gw->requestscrolly + si.nPos - mem); rect.x0 = rect.x1 = gw->scrollx;
rect.y0 = rect.y1 = gw->scrolly + gw->requestscrolly + si.nPos - mem;
win32_window_set_scroll(gw, &rect);
} }
return 0; return 0;
@ -201,9 +203,10 @@ nsws_drawable_hscroll(struct gui_window *gw, HWND hwnd, WPARAM wparam)
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
GetScrollInfo(hwnd, SB_HORZ, &si); GetScrollInfo(hwnd, SB_HORZ, &si);
if (si.nPos != mem) { if (si.nPos != mem) {
win32_window_set_scroll(gw, struct rect rect;
gw->scrollx + gw->requestscrollx + si.nPos - mem, rect.x0 = rect.x1 = gw->scrollx + gw->requestscrollx + si.nPos - mem;
gw->scrolly); rect.y0 = rect.y1 = gw->scrolly;
win32_window_set_scroll(gw, &rect);
} }
return 0; return 0;

View File

@ -923,7 +923,7 @@ win32_window_invalidate_area(struct gui_window *gw, const struct rect *rect)
*/ */
static void nsws_set_scale(struct gui_window *gw, float scale) static void nsws_set_scale(struct gui_window *gw, float scale)
{ {
int x, y; struct rect rect;
assert(gw != NULL); assert(gw != NULL);
@ -931,8 +931,8 @@ static void nsws_set_scale(struct gui_window *gw, float scale)
return; return;
} }
x = gw->scrollx; rect.x0 = rect.x1 = gw->scrollx;
y = gw->scrolly; rect.y0 = rect.y1 = gw->scrolly;
gw->scale = scale; gw->scale = scale;
@ -941,7 +941,7 @@ static void nsws_set_scale(struct gui_window *gw, float scale)
} }
win32_window_invalidate_area(gw, NULL); win32_window_invalidate_area(gw, NULL);
win32_window_set_scroll(gw, x, y); win32_window_set_scroll(gw, &rect);
} }
@ -1338,7 +1338,7 @@ nsws_window_resize(struct gui_window *gw,
WPARAM wparam, WPARAM wparam,
LPARAM lparam) LPARAM lparam)
{ {
int x, y; struct rect rect;
RECT rstatus, rtool; RECT rstatus, rtool;
if ((gw->toolbar == NULL) || if ((gw->toolbar == NULL) ||
@ -1351,7 +1351,7 @@ nsws_window_resize(struct gui_window *gw,
GetClientRect(gw->toolbar, &rtool); GetClientRect(gw->toolbar, &rtool);
GetWindowRect(gw->statusbar, &rstatus); GetWindowRect(gw->statusbar, &rstatus);
win32_window_get_scroll(gw, &x, &y); win32_window_get_scroll(gw, &rect.x0, &rect.y0);
gw->width = LOWORD(lparam); gw->width = LOWORD(lparam);
gw->height = HIWORD(lparam) - (rtool.bottom - rtool.top) - (rstatus.bottom - rstatus.top); gw->height = HIWORD(lparam) - (rtool.bottom - rtool.top) - (rstatus.bottom - rstatus.top);
@ -1365,7 +1365,7 @@ nsws_window_resize(struct gui_window *gw,
} }
nsws_window_update_forward_back(gw); nsws_window_update_forward_back(gw);
win32_window_set_scroll(gw, x, y); win32_window_set_scroll(gw, &rect);
if (gw->toolbar != NULL) { if (gw->toolbar != NULL) {
SendMessage(gw->toolbar, TB_SETSTATE, SendMessage(gw->toolbar, TB_SETSTATE,
@ -1830,40 +1830,39 @@ bool nsws_window_go(HWND hwnd, const char *urltxt)
/* exported interface documented in windows/window.h */ /* exported interface documented in windows/window.h */
void win32_window_set_scroll(struct gui_window *w, int sx, int sy) nserror win32_window_set_scroll(struct gui_window *gw, const struct rect *rect)
{ {
SCROLLINFO si; SCROLLINFO si;
nserror err; nserror res;
int height; int height;
int width; int width;
POINT p; POINT p;
if ((w == NULL) || (w->bw == NULL)) if ((gw == NULL) || (gw->bw == NULL)) {
return; return NSERROR_BAD_PARAMETER;
err = browser_window_get_extents(w->bw, true, &width, &height);
if (err != NSERROR_OK) {
return;
} }
/*LOG("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height);*/ res = browser_window_get_extents(gw->bw, true, &width, &height);
if (res != NSERROR_OK) {
return res;
}
/* The resulting gui window scroll must remain within the /* The resulting gui window scroll must remain within the
* windows bounding box. * windows bounding box.
*/ */
if (sx < 0) { if (rect->x0 < 0) {
w->requestscrollx = -w->scrollx; gw->requestscrollx = -gw->scrollx;
} else if (sx > (width - w->width)) { } else if (rect->x0 > (width - gw->width)) {
w->requestscrollx = (width - w->width) - w->scrollx; gw->requestscrollx = (width - gw->width) - gw->scrollx;
} else { } else {
w->requestscrollx = sx - w->scrollx; gw->requestscrollx = rect->x0 - gw->scrollx;
} }
if (sy < 0) { if (rect->y0 < 0) {
w->requestscrolly = -w->scrolly; gw->requestscrolly = -gw->scrolly;
} else if (sy > (height - w->height)) { } else if (rect->y0 > (height - gw->height)) {
w->requestscrolly = (height - w->height) - w->scrolly; gw->requestscrolly = (height - gw->height) - gw->scrolly;
} else { } else {
w->requestscrolly = sy - w->scrolly; gw->requestscrolly = rect->y0 - gw->scrolly;
} }
/*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/ /*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/
@ -1873,10 +1872,10 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
si.fMask = SIF_ALL; si.fMask = SIF_ALL;
si.nMin = 0; si.nMin = 0;
si.nMax = height - 1; si.nMax = height - 1;
si.nPage = w->height; si.nPage = gw->height;
si.nPos = max(w->scrolly + w->requestscrolly, 0); si.nPos = max(gw->scrolly + gw->requestscrolly, 0);
si.nPos = min(si.nPos, height - w->height); si.nPos = min(si.nPos, height - gw->height);
SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE); SetScrollInfo(gw->drawingarea, SB_VERT, &si, TRUE);
/*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/ /*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
/* set the horizontal scroll offset */ /* set the horizontal scroll offset */
@ -1884,30 +1883,31 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
si.fMask = SIF_ALL; si.fMask = SIF_ALL;
si.nMin = 0; si.nMin = 0;
si.nMax = width -1; si.nMax = width -1;
si.nPage = w->width; si.nPage = gw->width;
si.nPos = max(w->scrollx + w->requestscrollx, 0); si.nPos = max(gw->scrollx + gw->requestscrollx, 0);
si.nPos = min(si.nPos, width - w->width); si.nPos = min(si.nPos, width - gw->width);
SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE); SetScrollInfo(gw->drawingarea, SB_HORZ, &si, TRUE);
/*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/ /*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
/* Set caret position */ /* Set caret position */
GetCaretPos(&p); GetCaretPos(&p);
HideCaret(w->drawingarea); HideCaret(gw->drawingarea);
SetCaretPos(p.x - w->requestscrollx, p.y - w->requestscrolly); SetCaretPos(p.x - gw->requestscrollx, p.y - gw->requestscrolly);
ShowCaret(w->drawingarea); ShowCaret(gw->drawingarea);
RECT r, redraw; RECT r, redraw;
r.top = 0; r.top = 0;
r.bottom = w->height + 1; r.bottom = gw->height + 1;
r.left = 0; r.left = 0;
r.right = w->width + 1; r.right = gw->width + 1;
ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE); ScrollWindowEx(gw->drawingarea, - gw->requestscrollx, - gw->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
/*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/ /*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/
w->scrolly += w->requestscrolly; gw->scrolly += gw->requestscrolly;
w->scrollx += w->requestscrollx; gw->scrollx += gw->requestscrollx;
w->requestscrollx = 0; gw->requestscrollx = 0;
w->requestscrolly = 0; gw->requestscrolly = 0;
return NSERROR_OK;
} }

View File

@ -73,6 +73,7 @@ struct gui_window {
struct gui_window *next, *prev; /**< global linked list */ struct gui_window *next, *prev; /**< global linked list */
}; };
struct rect;
/** /**
* Obtain gui window structure from window handle. * Obtain gui window structure from window handle.
@ -91,13 +92,17 @@ struct gui_window *nsws_get_gui_window(HWND hwnd);
bool nsws_window_go(HWND hwnd, const char *urltxt); bool nsws_window_go(HWND hwnd, const char *urltxt);
/** /**
* scroll the window * Set the scroll position of a win32 browser window.
* *
* \param w The win32 gui window to scroll. * Scrolls the viewport to ensure the specified rectangle of the
* \param sx the new 'absolute' horizontal scroll location * content is shown. The win32 implementation scrolls the contents so
* \param sy the new 'absolute' vertical scroll location * the specified point in the content is at the top of the viewport.
*
* \param gw The win32 gui window to scroll.
* \param rect The rectangle to ensure is shown.
* \return NSERROR_OK on success or apropriate error code.
*/ */
void win32_window_set_scroll(struct gui_window *w, int sx, int sy); nserror win32_window_set_scroll(struct gui_window *gw, const struct rect *rect);
/** /**
* Create the main browser window class. * Create the main browser window class.