Fix bounding on windows frontend window scrolling

This commit is contained in:
Vincent Sanders 2015-04-18 23:59:01 +01:00
parent 2465fc4e6b
commit 10f621441f

View File

@ -797,8 +797,27 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
return; return;
} }
/*LOG(("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height));*/
/* The resulting gui window scroll must remain withn the
* windows bounding box.
*/
if (sx < 0) {
w->requestscrollx = -w->scrollx;
} else if (sx > (width - w->width)) {
w->requestscrollx = (width - w->width) - w->scrollx;
} else {
w->requestscrollx = sx - w->scrollx; w->requestscrollx = sx - w->scrollx;
}
if (sy < 0) {
w->requestscrolly = -w->scrolly;
} else if (sy > (height - w->height)) {
w->requestscrolly = (height - w->height) - w->scrolly;
} else {
w->requestscrolly = sy - w->scrolly; w->requestscrolly = sy - w->scrolly;
}
/*LOG(("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly));*/
/* set the vertical scroll offset */ /* set the vertical scroll offset */
si.cbSize = sizeof(si); si.cbSize = sizeof(si);
@ -809,7 +828,7 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
si.nPos = max(w->scrolly + w->requestscrolly, 0); si.nPos = max(w->scrolly + w->requestscrolly, 0);
si.nPos = min(si.nPos, height - w->height); si.nPos = min(si.nPos, height - w->height);
SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE); SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE);
LOG(("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos)); /*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 */
si.cbSize = sizeof(si); si.cbSize = sizeof(si);
@ -820,7 +839,7 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
si.nPos = max(w->scrollx + w->requestscrollx, 0); si.nPos = max(w->scrollx + w->requestscrollx, 0);
si.nPos = min(si.nPos, width - w->width); si.nPos = min(si.nPos, width - w->width);
SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE); SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE);
LOG(("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos)); /*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);
@ -834,6 +853,7 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
r.left = 0; r.left = 0;
r.right = w->width + 1; r.right = w->width + 1;
ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE); ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
/*LOG(("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly));*/
w->scrolly += w->requestscrolly; w->scrolly += w->requestscrolly;
w->scrollx += w->requestscrollx; w->scrollx += w->requestscrollx;
w->requestscrollx = 0; w->requestscrollx = 0;