diff options
-rw-r--r-- | desktop/scrollbar.c | 47 | ||||
-rw-r--r-- | desktop/scrollbar.h | 9 |
2 files changed, 56 insertions, 0 deletions
diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index e6fe83c90..1ec89437a 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -451,6 +451,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 + */ int scrollbar_get_offset(struct scrollbar *s) { if (s == NULL) diff --git a/desktop/scrollbar.h b/desktop/scrollbar.h index 7c5307fff..3f415e8d9 100644 --- a/desktop/scrollbar.h +++ b/desktop/scrollbar.h @@ -111,6 +111,15 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, void scrollbar_set(struct scrollbar *s, int value, bool bar_pos); /** + * Scroll the scrollbar by given amount. + * + * \param s the scrollbar to be scrolled + * \param change the change in scroll offset required (in px) + * \return true iff the scrollbar was moved. + */ +bool scrollbar_scroll(struct scrollbar *s, int change); + +/** * Get the current scroll offset to the visible part of the full area. * * \param s the scrollbar to get the scroll offset value from |