From c078c3f50932f9fc0bcb20ed8ddaaf648f6acda2 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 2 Aug 2019 21:00:06 +0100 Subject: gtk/corewindow.c: Correctly handle scroll_visible Signed-off-by: Daniel Silverstone --- frontends/gtk/corewindow.c | 50 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'frontends/gtk') diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c index 4f05648ba..9dc388c4f 100644 --- a/frontends/gtk/corewindow.c +++ b/frontends/gtk/corewindow.c @@ -608,26 +608,52 @@ static void nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r) { struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; - int y = 0, height = 0, y0, y1; - gdouble page; + int x0, y0, x1, y1; + gdouble vpage, hpage; GtkAdjustment *vadj; + GtkAdjustment *hadj; vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled); + hadj = gtk_scrolled_window_get_hadjustment(nsgtk_cw->scrolled); - assert(vadj); + assert(vadj != NULL); + assert(hadj != NULL); - g_object_get(vadj, "page-size", &page, NULL); + g_object_get(vadj, "page-size", &vpage, NULL); + g_object_get(hadj, "page-size", &hpage, NULL); y0 = (int)(gtk_adjustment_get_value(vadj)); - y1 = y0 + page; - - if ((y >= y0) && (y + height <= y1)) - return; - if (y + height > y1) - y0 = y0 + (y + height - y1); - if (y < y0) - y0 = y; + y1 = y0 + vpage; + x0 = (int)(gtk_adjustment_get_value(hadj)); + x1 = x0 + hpage; + + if (r->y1 > y1) { + /* The bottom of the rectangle is off the bottom of the + * window, so scroll down to fit it + */ + y0 = r->y1 - vpage; + } + if (r->y0 < y0) { + /* The top of the rectangle is off the top of the window, + * so scroll up to fit it + */ + y0 = r->y0; + } + if (r->x1 > x1) { + /* The right of the rectangle is off the right of the window + * so scroll right to fit it + */ + x0 = r->x1 - hpage; + } + if (r->x0 < x0) { + /* The left of the rectangle is off the left of the window + * so scroll left to fit it + */ + x0 = r->x0; + } + gtk_adjustment_set_value(vadj, y0); + gtk_adjustment_set_value(hadj, x0); } -- cgit v1.2.3