From 449e41e306624bd89f84976435d16291ca0405a8 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 29 Nov 2011 14:16:26 +0000 Subject: New function for applying a change in offset to a scrollbar. svn path=/trunk/netsurf/; revision=13196 --- desktop/scrollbar.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'desktop/scrollbar.c') diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index e6fe83c90..1ec89437a 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -448,6 +448,53 @@ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos) } +/* + * Exported function. Documented in scrollbar.h + */ +bool scrollbar_scroll(struct scrollbar *s, int change) +{ + int well_length; + int old_offset = s->offset; + struct scrollbar_msg_data msg; + + if (change == 0 || s->full_size <= s->visible_size) + /* zero scroll step, or unscrollable */ + return false; + + if (s->offset + change > s->full_size - s->visible_size) + s->offset = s->full_size - s->visible_size; + else if (s->offset + change < 0) + s->offset = 0; + else + s->offset += change; + + if (s->offset == old_offset) + /* Nothing happened */ + return false; + + well_length = s->length - 2 * SCROLLBAR_WIDTH; + s->bar_pos = (s->full_size < 1) ? 0 : + ((well_length * s->offset) / s->full_size); + + msg.scrollbar = s; + msg.msg = SCROLLBAR_MSG_MOVED; + msg.scroll_offset = s->offset; + s->client_callback(s->client_data, &msg); + + msg.msg = SCROLLBAR_MSG_REDRAW; + msg.x0 = s->horizontal ? SCROLLBAR_WIDTH - 1 : 0; + msg.y0 = s->horizontal ? 0 : SCROLLBAR_WIDTH - 1; + msg.x1 = (s->horizontal ? s->length - SCROLLBAR_WIDTH + 1 : + SCROLLBAR_WIDTH); + msg.y1 = (s->horizontal ? SCROLLBAR_WIDTH : + s->length - SCROLLBAR_WIDTH + 1); + + s->client_callback(s->client_data, &msg); + + return true; +} + + /* * Exported function. Documented in scrollbar.h */ -- cgit v1.2.3