From 3938d5340b4d44dfe9c7839d1dc2bd790607f8ff Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 3 Aug 2019 15:52:42 +0100 Subject: Corewindow: Sanitise scrolling API. Now the core has a helper so that all the front ends don't need to implement the scroll to show area API. Now they simply have get and set scroll APIs. --- frontends/amiga/corewindow.c | 36 ++++++++++------- frontends/atari/treeview.c | 32 ++++++++++----- frontends/framebuffer/corewindow.c | 29 +++++++++++--- frontends/gtk/corewindow.c | 80 +++++++++++++++++++------------------- frontends/riscos/corewindow.c | 57 ++++++++++++++++++++------- frontends/windows/corewindow.c | 25 +++++++++--- 6 files changed, 168 insertions(+), 91 deletions(-) (limited to 'frontends') diff --git a/frontends/amiga/corewindow.c b/frontends/amiga/corewindow.c index 7ab6e8e14..2f155ba40 100644 --- a/frontends/amiga/corewindow.c +++ b/frontends/amiga/corewindow.c @@ -825,16 +825,17 @@ ami_cw_invalidate_area(struct core_window *cw, const struct rect *r) } -static void +static nserror ami_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) { struct ami_corewindow *ami_cw = (struct ami_corewindow *)cw; ami_cw_window_size(ami_cw, width, height); + return NSERROR_OK; } -static void +static nserror ami_cw_update_size(struct core_window *cw, int width, int height) { struct ami_corewindow *ami_cw = (struct ami_corewindow *)cw; @@ -861,11 +862,12 @@ ami_cw_update_size(struct core_window *cw, int width, int height) SCROLLER_Visible, win_h, TAG_DONE); } + return NSERROR_OK; } -static void -ami_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +ami_cw_get_scroll(struct core_window *cw, int *x, int *y) { struct ami_corewindow *ami_cw = (struct ami_corewindow *)cw; @@ -879,43 +881,49 @@ ami_cw_scroll_visible(struct core_window *cw, const struct rect *r) ami_cw_scroller_top(ami_cw, &win_x0, &win_y0); - win_x1 = win_x0 + win_w; - win_y1 = win_y0 + win_h; + *x = win_x0; + *y = win_y0; + return NSERROR_OK +} - if(r->y1 > win_y1) scrollsety = r->y1 - win_h; - if(r->y0 < (LONG)win_y0) scrollsety = r->y0; - if(r->x1 > win_x1) scrollsetx = r->x1 - win_w; - if(r->x0 < (LONG)win_x0) scrollsetx = r->x0; + +static nserror +ami_cw_set_scroll(struct core_window *cw, int x, int y) +{ + struct ami_corewindow *ami_cw = (struct ami_corewindow *)cw; if(ami_cw->scroll_y_visible == true) { RefreshSetGadgetAttrs((APTR)ami_cw->objects[GID_CW_VSCROLL], ami_cw->win, NULL, - SCROLLER_Top, scrollsety, + SCROLLER_Top, y, TAG_DONE); } if(ami_cw->scroll_x_visible == true) { RefreshSetGadgetAttrs((APTR)ami_cw->objects[GID_CW_HSCROLL], ami_cw->win, NULL, - SCROLLER_Top, scrollsetx, + SCROLLER_Top, x, TAG_DONE); } /* probably need to redraw here */ ami_cw_redraw(ami_cw, NULL); + return NSERROR_OK; } -static void +static nserror ami_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct ami_corewindow *ami_cw = (struct ami_corewindow *)cw; ami_cw->drag_status = ds; + return NSERROR_OK; } struct core_window_callback_table ami_cw_cb_table = { .invalidate = ami_cw_invalidate_area, .update_size = ami_cw_update_size, - .scroll_visible = ami_cw_scroll_visible, + .set_scroll = ami_cw_set_scroll, + .get_scroll = ami_cw_get_scroll, .get_window_dimensions = ami_cw_get_window_dimensions, .drag_status = ami_cw_drag_status }; diff --git a/frontends/atari/treeview.c b/frontends/atari/treeview.c index 23db41309..49d26ef5b 100644 --- a/frontends/atari/treeview.c +++ b/frontends/atari/treeview.c @@ -426,7 +426,7 @@ atari_treeview_invalidate_area(struct core_window *cw, * \param width the width in px, or negative if don't care * \param height the height in px, or negative if don't care */ -static void +static nserror atari_treeview_update_size(struct core_window *cw, int width, int height) { GRECT area; @@ -436,7 +436,7 @@ atari_treeview_update_size(struct core_window *cw, int width, int height) if (tv != NULL) { if (tv->disposing) - return; + return NSERROR_INVALID; /* Get acces to the gemtk window slider settings: */ slid = gemtk_wm_get_scroll_info(tv->window); @@ -465,6 +465,8 @@ atari_treeview_update_size(struct core_window *cw, int width, int height) */ gemtk_wm_update_slider(tv->window, GEMTK_WM_VH_SLIDER); } + + return NSERROR_OK; } @@ -474,11 +476,18 @@ atari_treeview_update_size(struct core_window *cw, int width, int height) * \param cw the core window object * \param r rectangle to make visible */ -static void -atari_treeview_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +atari_treeview_set_scroll(struct core_window *cw, int x, int y) { - /* atari frontend doesn't support dragging outside the treeview */ - /* so there is no need to implement this? */ + /* TODO */ + return NSERROR_OK; +} + +static nserror +atari_treeview_get_scroll(struct core_window *cw, int *x, int *y) +{ + /* TODO */ + return NSERROR_NOT_IMPLEMENTED; } @@ -489,7 +498,7 @@ atari_treeview_scroll_visible(struct core_window *cw, const struct rect *r) * \param width to be set to viewport width in px, if non NULL * \param height to be set to viewport height in px, if non NULL */ -static void +static nserror atari_treeview_get_window_dimensions(struct core_window *cw, int *width, int *height) @@ -501,6 +510,8 @@ atari_treeview_get_window_dimensions(struct core_window *cw, *width = work.g_w; *height = work.g_h; } + + return NSERROR_OK; } @@ -510,10 +521,10 @@ atari_treeview_get_window_dimensions(struct core_window *cw, * \param cw the core window object * \param ds the current drag status */ -static void +static nserror atari_treeview_drag_status(struct core_window *cw, core_window_drag_status ds) { - + return NSERROR_NOT_IMPLEMENTED; } @@ -523,7 +534,8 @@ atari_treeview_drag_status(struct core_window *cw, core_window_drag_status ds) static struct core_window_callback_table cw_t = { .invalidate = atari_treeview_invalidate_area, .update_size = atari_treeview_update_size, - .scroll_visible = atari_treeview_scroll_visible, + .set_scroll = atari_treeview_set_scroll, + .get_scroll = atari_treeview_get_scroll, .get_window_dimensions = atari_treeview_get_window_dimensions, .drag_status = atari_treeview_drag_status }; diff --git a/frontends/framebuffer/corewindow.c b/frontends/framebuffer/corewindow.c index 93f88ff61..a27d666f2 100644 --- a/frontends/framebuffer/corewindow.c +++ b/frontends/framebuffer/corewindow.c @@ -136,7 +136,7 @@ fb_cw_invalidate(struct core_window *cw, const struct rect *r) } -static void +static nserror fb_cw_update_size(struct core_window *cw, int width, int height) { /* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw; @@ -144,41 +144,58 @@ fb_cw_update_size(struct core_window *cw, int width, int height) toolkit_widget_set_size_request(FB_WIDGET(fb_cw->drawing_area), width, height); */ + return NSERROR_OK; +} + + +static nserror +fb_cw_set_scroll(struct core_window *cw, int x, int y) +{ +/* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw; + + toolkit_scroll_widget(fb_cw->widget, r); +*/ + return NSERROR_OK; } -static void -fb_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +fb_cw_get_scroll(struct core_window *cw, int *x, int *y) { /* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw; toolkit_scroll_widget(fb_cw->widget, r); */ + return NSERROR_NOT_IMPLEMENTED; } -static void +static nserror fb_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) { struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw; *width = fbtk_get_width(fb_cw->drawable); *height = fbtk_get_height(fb_cw->drawable); + return NSERROR_OK; } -static void +static nserror fb_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw; fb_cw->drag_status = ds; + + return NSERROR_OK; } struct core_window_callback_table fb_cw_cb_table = { .invalidate = fb_cw_invalidate, .update_size = fb_cw_update_size, - .scroll_visible = fb_cw_scroll_visible, + .set_scroll = fb_cw_set_scroll, + .get_scroll = fb_cw_get_scroll, .get_window_dimensions = fb_cw_get_window_dimensions, .drag_status = fb_cw_drag_status }; diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c index 9dc388c4f..cb78212dd 100644 --- a/frontends/gtk/corewindow.c +++ b/frontends/gtk/corewindow.c @@ -588,13 +588,15 @@ nsgtk_cw_invalidate_area(struct core_window *cw, const struct rect *rect) * \param width New widget width. * \param height New widget height. */ -static void +static nserror nsgtk_cw_update_size(struct core_window *cw, int width, int height) { struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; gtk_widget_set_size_request(GTK_WIDGET(nsgtk_cw->drawing_area), width, height); + + return NSERROR_OK; } @@ -604,12 +606,10 @@ nsgtk_cw_update_size(struct core_window *cw, int width, int height) * \param cw core window handle. * \param r rectangle that needs scrolling. */ -static void -nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +nsgtk_cw_set_scroll(struct core_window *cw, int x, int y) { struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; - int x0, y0, x1, y1; - gdouble vpage, hpage; GtkAdjustment *vadj; GtkAdjustment *hadj; @@ -619,41 +619,36 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r) assert(vadj != NULL); assert(hadj != NULL); - g_object_get(vadj, "page-size", &vpage, NULL); - g_object_get(hadj, "page-size", &hpage, NULL); + gtk_adjustment_set_value(vadj, y); + gtk_adjustment_set_value(hadj, x); - y0 = (int)(gtk_adjustment_get_value(vadj)); - y1 = y0 + vpage; - x0 = (int)(gtk_adjustment_get_value(hadj)); - x1 = x0 + hpage; + return NSERROR_OK; +} - 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); +/** + * scroll window core window callback + * + * \param cw core window handle. + * \param r rectangle that needs scrolling. + */ +static nserror +nsgtk_cw_get_scroll(struct core_window *cw, int *x, int *y) +{ + struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; + GtkAdjustment *vadj; + GtkAdjustment *hadj; + + vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled); + hadj = gtk_scrolled_window_get_hadjustment(nsgtk_cw->scrolled); + + assert(vadj != NULL); + assert(hadj != NULL); + + *y = (int)(gtk_adjustment_get_value(vadj)); + *x = (int)(gtk_adjustment_get_value(hadj)); + + return NSERROR_OK; } @@ -664,7 +659,7 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r) * \param[out] width to be set to viewport width in px * \param[out] height to be set to viewport height in px */ -static void +static nserror nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) { struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; @@ -679,6 +674,8 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled); g_object_get(vadj, "page-size", &page, NULL); *height = page; + + return NSERROR_OK; } @@ -688,11 +685,13 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) * \param cw core window handle. * \param ds The new drag status. */ -static void +static nserror nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)cw; nsgtk_cw->drag_status = ds; + + return NSERROR_OK; } @@ -702,7 +701,8 @@ nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds) static struct core_window_callback_table nsgtk_cw_cb_table = { .invalidate = nsgtk_cw_invalidate_area, .update_size = nsgtk_cw_update_size, - .scroll_visible = nsgtk_cw_scroll_visible, + .set_scroll = nsgtk_cw_set_scroll, + .get_scroll = nsgtk_cw_get_scroll, .get_window_dimensions = nsgtk_cw_get_window_dimensions, .drag_status = nsgtk_cw_drag_status }; diff --git a/frontends/riscos/corewindow.c b/frontends/riscos/corewindow.c index 6adfb03e7..fd0e50a2d 100644 --- a/frontends/riscos/corewindow.c +++ b/frontends/riscos/corewindow.c @@ -792,7 +792,7 @@ ro_cw_invalidate(struct core_window *cw, const struct rect *r) /** * Callback from the core to update the content area size. */ -static void +static nserror ro_cw_update_size(struct core_window *cw, int width, int height) { struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw; @@ -811,7 +811,7 @@ ro_cw_update_size(struct core_window *cw, int width, int height) if (error) { NSLOG(netsurf, INFO, "xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INVALID; } /* only update the window if it is open */ @@ -824,14 +824,15 @@ ro_cw_update_size(struct core_window *cw, int width, int height) update_scrollbars(ro_cw, &open); } + return NSERROR_OK; } /** * Callback from the core to scroll the visible content. */ -static void -ro_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +ro_cw_get_scroll(struct core_window *cw, int *x, int *y) { struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw; wimp_window_state state = { @@ -843,17 +844,39 @@ ro_cw_scroll_visible(struct core_window *cw, const struct rect *r) if (error) { NSLOG(netsurf, ERROR, "xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INVALID; } - /* TODO: - * Scroll so the area is brought into view, not just the top left of - * the rectangle. See `nsgtk_cw_scroll_visible`. - */ - state.xscroll = -r->x0 * 2; - state.yscroll = -r->y0 * 2; + *x = state.xscroll / 2; + *y = state.yscroll / 2; + return NSERROR_OK; +} + + +/** + * Callback from the core to scroll the visible content. + */ +static nserror +ro_cw_set_scroll(struct core_window *cw, int x, int y) +{ + struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw; + wimp_window_state state = { + .w = ro_cw->wh, + }; + os_error *error; + + error = xwimp_get_window_state(&state); + if (error) { + NSLOG(netsurf, ERROR, "xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess); + return NSERROR_INVALID; + } + + state.xscroll = -x * 2; + state.yscroll = -y * 2; ro_cw_open(PTR_WIMP_OPEN(&state)); + return NSERROR_OK; } @@ -864,7 +887,7 @@ ro_cw_scroll_visible(struct core_window *cw, const struct rect *r) * \param[out] width to be set to viewport width in px * \param[out] height to be set to viewport height in px */ -static void +static nserror ro_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) { struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw; @@ -876,29 +899,33 @@ ro_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) if (error) { NSLOG(netsurf, INFO, "xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INVALID; } *width = (state.visible.x1 - state.visible.x0) / 2; *height = (state.visible.y1 - state.visible.y0) / 2; + return NSERROR_OK; } /** * Callback from the core to update the drag status. */ -static void +static nserror ro_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw; ro_cw->drag_status = ds; + + return NSERROR_OK; } struct core_window_callback_table ro_cw_cb_table = { .invalidate = ro_cw_invalidate, .update_size = ro_cw_update_size, - .scroll_visible = ro_cw_scroll_visible, + .set_scroll = ro_cw_set_scroll, + .get_scroll = ro_cw_get_scroll, .get_window_dimensions = ro_cw_get_window_dimensions, .drag_status = ro_cw_drag_status }; diff --git a/frontends/windows/corewindow.c b/frontends/windows/corewindow.c index 7d88ce7c4..be2891fcd 100644 --- a/frontends/windows/corewindow.c +++ b/frontends/windows/corewindow.c @@ -443,7 +443,7 @@ nsw32_cw_invalidate_area(struct core_window *cw, const struct rect *rect) /** * Callback from the core to update the content area size */ -static void +static nserror nsw32_cw_update_size(struct core_window *cw, int width, int height) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; @@ -453,13 +453,23 @@ nsw32_cw_update_size(struct core_window *cw, int width, int height) NSLOG(netsurf, INFO, "new content size w:%d h:%d", width, height); update_scrollbars(nsw32_cw); + return NSERROR_OK; } -static void -nsw32_cw_scroll_visible(struct core_window *cw, const struct rect *r) +static nserror +nsw32_cw_set_scroll(struct core_window *cw, int x, int y) { /** /todo call setscroll apropriately */ + return NSERROR_OK; +} + + +static nserror +nsw32_cw_get_scroll(struct core_window *cw, int *x, int *y) +{ + /** /todo call getscroll apropriately */ + return NSERROR_NOT_IMPLEMENTED; } @@ -470,7 +480,7 @@ nsw32_cw_scroll_visible(struct core_window *cw, const struct rect *r) * \param[out] width to be set to viewport width in px * \param[out] height to be set to viewport height in px */ -static void +static nserror nsw32_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; @@ -479,21 +489,24 @@ nsw32_cw_get_window_dimensions(struct core_window *cw, int *width, int *height) GetClientRect(nsw32_cw->hWnd, &rc); *width = rc.right; *height = rc.bottom; + return NSERROR_OK; } -static void +static nserror nsw32_cw_drag_status(struct core_window *cw, core_window_drag_status ds) { struct nsw32_corewindow *nsw32_cw = (struct nsw32_corewindow *)cw; nsw32_cw->drag_status = ds; + return NSERROR_OK; } struct core_window_callback_table nsw32_cw_cb_table = { .invalidate = nsw32_cw_invalidate_area, .update_size = nsw32_cw_update_size, - .scroll_visible = nsw32_cw_scroll_visible, + .set_scroll = nsw32_cw_set_scroll, + .get_scroll = nsw32_cw_get_scroll, .get_window_dimensions = nsw32_cw_get_window_dimensions, .drag_status = nsw32_cw_drag_status }; -- cgit v1.2.3