diff options
Diffstat (limited to 'desktop/scrollbar.c')
-rw-r--r-- | desktop/scrollbar.c | 777 |
1 files changed, 467 insertions, 310 deletions
diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index 9a4d70fe4..af5536ba4 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -18,8 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** \file - * Scrollbar widget (implementation). +/** + * \file + * implementation of scrollbar widget. */ #include <stdbool.h> @@ -36,44 +37,65 @@ #include "desktop/system_colour.h" #include "desktop/scrollbar.h" +/** + * Scrollbar context + */ struct scrollbar { - bool horizontal; /* Horizontal scrollbar if true, else vertical - */ - int length; /* Length of the scrollbar widget */ - - int full_size; /* Length of the full scrollable area */ - int visible_size; /* Length visible part of the scrollable area */ - - int offset; /* Current scroll offset to visible area */ - - int bar_pos; /* Position of the scrollbar */ - int bar_len; /* Length of the scrollbar */ - - scrollbar_client_callback client_callback; /* Callback receiving - * scrollbar events */ - void *client_data; /* User data passed to the callback */ - - bool dragging; /* Flag indicating drag at progess */ - int drag_start_coord; /* Coordinate value at drag start */ - int drag_start_pos; /* Scrollbar offset or bar_pos at drag start */ - bool drag_content; /* Flag indicating that the drag corresponds to - * a dragged content area, rather than a dragged - * scrollbar. */ + /** Horizontal scrollbar if true, else vertical */ + bool horizontal; + /** Length of the scrollbar widget */ + int length; + + /** Length of the full scrollable area */ + int full_size; + /** Length visible part of the scrollable area */ + int visible_size; + + /** Current scroll offset to visible area */ + int offset; + + /** Position of the scrollbar */ + int bar_pos; + /** Length of the scrollbar */ + int bar_len; + + /** Callback receiving scrollbar events */ + scrollbar_client_callback client_callback; + /** User data passed to the callback */ + void *client_data; + + /** Flag indicating drag at progess */ + bool dragging; + /** Coordinate value at drag start */ + int drag_start_coord; + /** Scrollbar offset or bar_pos at drag start */ + int drag_start_pos; + /** Flag indicating that the drag corresponds to a dragged + * content area, rather than a dragged scrollbar. + */ + bool drag_content; - struct scrollbar *pair; /* Parpendicular scrollbar, or NULL */ - bool pair_drag; /* Flag indicating that the current drag affects - the perpendicular scrollbar too */ + /** Parpendicular scrollbar, or NULL */ + struct scrollbar *pair; + /** Flag indicating that the current drag affects the + * perpendicular scrollbar too + */ + bool pair_drag; }; /* - * Exported function. Documented in desktop/scrollbar.h + * Exported interface. Documented in desktop/scrollbar.h */ -nserror scrollbar_create(bool horizontal, int length, int full_size, - int visible_size, void *client_data, - scrollbar_client_callback client_callback, - struct scrollbar **s) +nserror +scrollbar_create(bool horizontal, + int length, + int full_size, + int visible_size, + void *client_data, + scrollbar_client_callback client_callback, + struct scrollbar **s) { struct scrollbar *scrollbar; int well_length; @@ -95,7 +117,7 @@ nserror scrollbar_create(bool horizontal, int length, int full_size, well_length = length - 2 * SCROLLBAR_WIDTH; scrollbar->bar_len = (full_size == 0) ? 0 : - ((well_length * visible_size) / full_size); + ((well_length * visible_size) / full_size); scrollbar->client_callback = client_callback; scrollbar->client_data = client_data; @@ -110,49 +132,49 @@ nserror scrollbar_create(bool horizontal, int length, int full_size, /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_destroy(struct scrollbar *s) { - if (s->pair != NULL) + if (s->pair != NULL) { s->pair->pair = NULL; + } free(s); } /** - * Draw an outline rectangle common to a several scrollbar elements. + * Draw an outline rectangle common to several scrollbar elements. * - * \param x0 left border of the outline - * \param y0 top border of the outline - * \param x1 right border of the outline - * \param y1 bottom border of the outline - * \param c base colour of the outline, the other colours are created by - * lightening or darkening this one - * \param ctx current redraw context + * \param ctx current redraw context + * \param area the area of the scrollbar + * \param c base colour of the outline, the other colours are created by + * lightening or darkening this one * \param inset true for inset outline, false for an outset one - * \return + * \return NSERROR_OK on success else error code */ - -static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, - int x1, int y1, colour c, bool inset, - const struct redraw_context *ctx) +static inline nserror +scrollbar_rectangle(const struct redraw_context *ctx, + struct rect *area, + colour c, + bool inset) { - const struct plotter_table *plot = ctx->plot; + struct rect line; + nserror res; static plot_style_t c0 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; static plot_style_t c1 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; static plot_style_t c2 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; if (inset) { @@ -165,225 +187,338 @@ static inline bool scrollbar_redraw_scrollbar_rectangle(int x0, int y0, c2.stroke_colour = blend_colour(c0.stroke_colour, c1.stroke_colour); /* Plot the outline */ - if (!plot->line(x0, y0, x1, y0, &c0)) return false; - if (!plot->line(x1, y0, x1, y1 + 1, &c1)) return false; - if (!plot->line(x1, y0, x1, y0 + 1, &c2)) return false; - if (!plot->line(x1, y1, x0, y1, &c1)) return false; - if (!plot->line(x0, y1, x0, y0, &c0)) return false; - if (!plot->line(x0, y1, x0, y1 + 1, &c2)) return false; - return true; + line.x0 = area->x0; line.y0 = area->y0; + line.x1 = area->x1; line.y1 = area->y0; + res = ctx->plot->line(ctx, &c0, &line); + if (res != NSERROR_OK) { + return res; + } + + line.x0 = area->x1; line.y0 = area->y0; + line.x1 = area->x1; line.y1 = area->y1 + 1; + res = ctx->plot->line(ctx, &c1, &line); + if (res != NSERROR_OK) { + return res; + } + + line.x0 = area->x1; line.y0 = area->y0; + line.x1 = area->x1; line.y1 = area->y0 + 1; + res = ctx->plot->line(ctx, &c2, &line); + if (res != NSERROR_OK) { + return res; + } + + line.x0 = area->x1; line.y0 = area->y1; + line.x1 = area->x0; line.y1 = area->y1; + res = ctx->plot->line(ctx, &c1, &line); + if (res != NSERROR_OK) { + return res; + } + + line.x0 = area->x0; line.y0 = area->y1; + line.x1 = area->x0; line.y1 = area->y0; + res = ctx->plot->line(ctx, &c0, &line); + if (res != NSERROR_OK) { + return res; + } + + line.x0 = area->x0; line.y0 = area->y1; + line.x1 = area->x0; line.y1 = area->y1 + 1; + res = ctx->plot->line(ctx, &c2, &line); + + return res; } /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ -bool scrollbar_redraw(struct scrollbar *s, int x, int y, - const struct rect *clip, float scale, - const struct redraw_context *ctx) +nserror +scrollbar_redraw(struct scrollbar *s, + int x, int y, + const struct rect *clip, + float scale, + const struct redraw_context *ctx) { - const struct plotter_table *plot = ctx->plot; int w = SCROLLBAR_WIDTH; int bar_pos, bar_c0, bar_c1; int v[6]; /* array of triangle vertices */ - int x0, y0, x1, y1; - - colour bg_fill_colour = ns_system_colour_char("Scrollbar"); - colour fg_fill_colour = ns_system_colour_char("ButtonFace"); - colour arrow_fill_colour = ns_system_colour_char("ButtonText"); + struct rect area; + struct rect rect; + nserror res; plot_style_t bg_fill_style = { .fill_type = PLOT_OP_TYPE_SOLID, - .fill_colour = bg_fill_colour }; plot_style_t fg_fill_style = { .fill_type = PLOT_OP_TYPE_SOLID, - .fill_colour = fg_fill_colour }; plot_style_t arrow_fill_style = { .fill_type = PLOT_OP_TYPE_SOLID, - .fill_colour = arrow_fill_colour }; - x0 = x; - y0 = y; - x1 = x + (s->horizontal ? s->length : SCROLLBAR_WIDTH) - 1; - y1 = y + (s->horizontal ? SCROLLBAR_WIDTH : s->length) - 1; + res = ns_system_colour_char("Scrollbar", &bg_fill_style.fill_colour); + if (res != NSERROR_OK) { + return res; + } + + res = ns_system_colour_char("ButtonFace", &fg_fill_style.fill_colour); + if (res != NSERROR_OK) { + return res; + } + + res = ns_system_colour_char("ButtonText", &arrow_fill_style.fill_colour); + if (res != NSERROR_OK) { + return res; + } + + area.x0 = x; + area.y0 = y; + area.x1 = x + (s->horizontal ? s->length : SCROLLBAR_WIDTH) - 1; + area.y1 = y + (s->horizontal ? SCROLLBAR_WIDTH : s->length) - 1; bar_pos = s->bar_pos; - bar_c1 = (s->horizontal ? x0 : y0) + SCROLLBAR_WIDTH + - s->bar_pos + s->bar_len - 1; + bar_c1 = (s->horizontal ? area.x0 : area.y0) + SCROLLBAR_WIDTH + + s->bar_pos + s->bar_len - 1; if (scale != 1.0) { w *= scale; - x0 *= scale; - y0 *= scale; - x1 *= scale; - y1 *= scale; + area.x0 *= scale; + area.y0 *= scale; + area.x1 *= scale; + area.y1 *= scale; bar_pos *= scale; bar_c1 *= scale; } - bar_c0 = (s->horizontal ? x0 : y0) + w + bar_pos; + bar_c0 = (s->horizontal ? area.x0 : area.y0) + w + bar_pos; - if (x1 < clip->x0 || y1 < clip->y0 || clip->x1 < x0 || clip->y1 < y0) - /* scrollbar is outside the clipping rectangle, nothing to - * render */ - return true; + /* if scrollbar is outside the clipping rectangle, nothing to render */ + if ((area.x1 < clip->x0) || + (area.y1 < clip->y0) || + (clip->x1 < area.x0) || + (clip->y1 < area.y0)) { + return NSERROR_OK; + } - if (s->horizontal) { /* scrollbar is horizontal */ - + /* scrollbar outline */ - if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, - bg_fill_colour, true, ctx)) - return false; + res = scrollbar_rectangle(ctx, &area, + bg_fill_style.fill_colour, true); + if (res != NSERROR_OK) { + return res; + } + /* left arrow icon border */ - if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, - y0 + 1, - x0 + w - 2, - y1 - 1, - fg_fill_colour, false, ctx)) - return false; + rect.x0 = area.x0 + 1; + rect.y0 = area.y0 + 1; + rect.x1 = area.x0 + w - 2; + rect.y1 = area.y1 - 1; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + /* left arrow icon background */ - if (!plot->rectangle(x0 + 2, - y0 + 2, - x0 + w - 2, - y1 - 1, - &fg_fill_style)) - return false; + rect.x0 = area.x0 + 2; + rect.y0 = area.y0 + 2; + rect.x1 = area.x0 + w - 2; + rect.y1 = area.y1 - 1; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* left arrow */ - v[0] = x0 + w / 4; - v[1] = y0 + w / 2; - v[2] = x0 + w * 3 / 4; - v[3] = y0 + w / 4; - v[4] = x0 + w * 3 / 4; - v[5] = y0 + w * 3 / 4; - if (!plot->polygon(v, 3, &arrow_fill_style)) - return false; + v[0] = area.x0 + w / 4; + v[1] = area.y0 + w / 2; + v[2] = area.x0 + w * 3 / 4; + v[3] = area.y0 + w / 4; + v[4] = area.x0 + w * 3 / 4; + v[5] = area.y0 + w * 3 / 4; + res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3); + if (res != NSERROR_OK) { + return res; + } + /* scrollbar well background */ - if (!plot->rectangle(x0 + w - 1, - y0 + 1, - x1 - w + 2, - y1, - &bg_fill_style)) - return false; + rect.x0 = area.x0 + w - 1; + rect.y0 = area.y0 + 1; + rect.x1 = area.x1 - w + 2; + rect.y1 = area.y1; + res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* scrollbar position indicator bar */ - if (!scrollbar_redraw_scrollbar_rectangle(bar_c0, - y0 + 1, - bar_c1, - y1 - 1, - fg_fill_colour, false, ctx)) - return false; - if (!plot->rectangle(bar_c0 + 1, - y0 + 2, - bar_c1, - y1 - 1, - &fg_fill_style)) - return false; + rect.x0 = bar_c0; + rect.y0 = area.y0 + 1; + rect.x1 = bar_c1; + rect.y1 = area.y1 - 1; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + + rect.x0 = bar_c0 + 1; + rect.y0 = area.y0 + 2; + rect.x1 = bar_c1; + rect.y1 = area.y1 - 1; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* right arrow icon border */ - if (!scrollbar_redraw_scrollbar_rectangle(x1 - w + 2, - y0 + 1, - x1 - 1, - y1 - 1, - fg_fill_colour, false, ctx)) - return false; + rect.x0 = area.x1 - w + 2; + rect.y0 = area.y0 + 1; + rect.x1 = area.x1 - 1; + rect.y1 = area.y1 - 1; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + /* right arrow icon background */ - if (!plot->rectangle(x1 - w + 3, - y0 + 2, - x1 - 1, - y1 - 1, - &fg_fill_style)) - return false; + rect.x0 = area.x1 - w + 3; + rect.y0 = area.y0 + 2; + rect.x1 = area.x1 - 1; + rect.y1 = area.y1 - 1; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* right arrow */ - v[0] = x1 - w / 4 + 1; - v[1] = y0 + w / 2; - v[2] = x1 - w * 3 / 4 + 1; - v[3] = y0 + w / 4; - v[4] = x1 - w * 3 / 4 + 1; - v[5] = y0 + w * 3 / 4; - if (!plot->polygon(v, 3, &arrow_fill_style)) - return false; + v[0] = rect.x1 - w / 4 + 1; + v[1] = rect.y0 + w / 2; + v[2] = rect.x1 - w * 3 / 4 + 1; + v[3] = rect.y0 + w / 4; + v[4] = rect.x1 - w * 3 / 4 + 1; + v[5] = rect.y0 + w * 3 / 4; + res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3); + if (res != NSERROR_OK) { + return res; + } } else { /* scrollbar is vertical */ - + /* outline */ - if (!scrollbar_redraw_scrollbar_rectangle(x0, y0, x1, y1, - bg_fill_colour, true, ctx)) - return false; - /* top arrow background */ - if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, - y0 + 1, - x1 - 1, - y0 + w - 2, - fg_fill_colour, false, ctx)) - return false; - if (!plot->rectangle(x0 + 2, - y0 + 2, - x1 - 1, - y0 + w - 2, - &fg_fill_style)) - return false; + res = scrollbar_rectangle(ctx, &area, + bg_fill_style.fill_colour, true); + if (res != NSERROR_OK) { + return res; + } + + /* top arrow border */ + rect.x0 = area.x0 + 1; + rect.y0 = area.y0 + 1; + rect.x1 = area.x1 - 1; + rect.y1 = area.y0 + w - 2; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + + /* top arrow background */ + rect.x0 = area.x0 + 2; + rect.y0 = area.y0 + 2; + rect.x1 = area.x1 - 1; + rect.y1 = area.y0 + w - 2; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* up arrow */ - v[0] = x0 + w / 2; - v[1] = y0 + w / 4; - v[2] = x0 + w / 4; - v[3] = y0 + w * 3 / 4; - v[4] = x0 + w * 3 / 4; - v[5] = y0 + w * 3 / 4; - if (!plot->polygon(v, 3, &arrow_fill_style)) - return false; + v[0] = area.x0 + w / 2; + v[1] = area.y0 + w / 4; + v[2] = area.x0 + w / 4; + v[3] = area.y0 + w * 3 / 4; + v[4] = area.x0 + w * 3 / 4; + v[5] = area.y0 + w * 3 / 4; + res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3); + if (res != NSERROR_OK) { + return res; + } + /* scrollbar well background */ - if (!plot->rectangle(x0 + 1, - y0 + w - 1, - x1, - y1 - w + 2, - &bg_fill_style)) - return false; + rect.x0 = area.x0 + 1; + rect.y0 = area.y0 + w - 1; + rect.x1 = area.x1; + rect.y1 = area.y1 - w + 2; + res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* scrollbar position indicator bar */ - if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, - bar_c0, - x1 - 1, - bar_c1, - fg_fill_colour, false, ctx)) - return false; - if (!plot->rectangle(x0 + 2, - bar_c0 + 1, - x1 - 1, - bar_c1, - &fg_fill_style)) - return false; - /* bottom arrow background */ - if (!scrollbar_redraw_scrollbar_rectangle(x0 + 1, - y1 - w + 2, - x1 - 1, - y1 - 1, - fg_fill_colour, false, ctx)) - return false; - if (!plot->rectangle(x0 + 2, - y1 - w + 3, - x1 - 1, - y1 - 1, - &fg_fill_style)) - return false; + rect.x0 = area.x0 + 1; + rect.y0 = bar_c0; + rect.x1 = area.x1 - 1; + rect.y1 = bar_c1; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + + rect.x0 = area.x0 + 2; + rect.y0 = bar_c0 + 1; + rect.x1 = area.x1 - 1; + rect.y1 = bar_c1; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + + /* down arrow icon border */ + rect.x0 = area.x0 + 1; + rect.y0 = area.y1 - w + 2; + rect.x1 = area.x1 - 1; + rect.y1 = area.y1 - 1; + res = scrollbar_rectangle(ctx, &rect, + fg_fill_style.fill_colour, false); + if (res != NSERROR_OK) { + return res; + } + + /* down arrow icon background */ + rect.x0 = area.x0 + 2; + rect.y0 = area.y1 - w + 3; + rect.x1 = area.x1 - 1; + rect.y1 = area.y1 - 1; + res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect); + if (res != NSERROR_OK) { + return res; + } + /* down arrow */ - v[0] = x0 + w / 2; - v[1] = y1 - w / 4 + 1; - v[2] = x0 + w / 4; - v[3] = y1 - w * 3 / 4 + 1; - v[4] = x0 + w * 3 / 4; - v[5] = y1 - w * 3 / 4 + 1; - if (!plot->polygon(v, 3, &arrow_fill_style)) - return false; + v[0] = area.x0 + w / 2; + v[1] = area.y1 - w / 4 + 1; + v[2] = area.x0 + w / 4; + v[3] = area.y1 - w * 3 / 4 + 1; + v[4] = area.x0 + w * 3 / 4; + v[5] = area.y1 - w * 3 / 4 + 1; + res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3); + if (res != NSERROR_OK) { + return res; + } } - return true; + return NSERROR_OK; } /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos) { @@ -391,46 +526,49 @@ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos) int old_offset = s->offset; struct scrollbar_msg_data msg; - if (value < 0) + if (value < 0) { value = 0; + } - if (s->full_size == s->visible_size) + if (s->full_size == s->visible_size) { return; + } well_length = s->length - 2 * SCROLLBAR_WIDTH; if (bar_pos) { - if (value > well_length - s->bar_len) + if (value > well_length - s->bar_len) { s->bar_pos = well_length - s->bar_len; - else + } else { s->bar_pos = value; + } s->offset = ((well_length - s->bar_len) < 1) ? 0 : - (((s->full_size - s->visible_size) * - s->bar_pos) / (well_length - s->bar_len)); + (((s->full_size - s->visible_size) * + s->bar_pos) / (well_length - s->bar_len)); } else { - if (value > s->full_size - s->visible_size) + if (value > s->full_size - s->visible_size) { s->offset = s->full_size - s->visible_size; - else + } else { s->offset = value; + } s->bar_pos = (s->full_size < 1) ? 0 : - ((well_length * s->offset) / s->full_size); + ((well_length * s->offset) / s->full_size); } - if (s->offset == old_offset) - /* Nothing happened */ - return; - - msg.scrollbar = s; - msg.msg = SCROLLBAR_MSG_MOVED; - msg.scroll_offset = s->offset; - s->client_callback(s->client_data, &msg); + if (s->offset != old_offset) { + /* client callback if there was a chnage */ + msg.scrollbar = s; + msg.msg = SCROLLBAR_MSG_MOVED; + msg.scroll_offset = s->offset; + s->client_callback(s->client_data, &msg); + } } /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ bool scrollbar_scroll(struct scrollbar *s, int change) { @@ -438,9 +576,10 @@ bool scrollbar_scroll(struct scrollbar *s, int change) int old_offset = s->offset; struct scrollbar_msg_data msg; - if (change == 0 || s->full_size <= s->visible_size) + if (change == 0 || s->full_size <= s->visible_size) { /* zero scroll step, or unscrollable */ return false; + } /* Convert named change values to appropriate pixel offset value */ switch (change) { @@ -466,21 +605,23 @@ bool scrollbar_scroll(struct scrollbar *s, int change) } /* Get new offset */ - if (s->offset + change > s->full_size - s->visible_size) + if (s->offset + change > s->full_size - s->visible_size) { s->offset = s->full_size - s->visible_size; - else if (s->offset + change < 0) + } else if (s->offset + change < 0) { s->offset = 0; - else + } else { s->offset += change; + } - if (s->offset == old_offset) + if (s->offset == old_offset) { /* Nothing happened */ return false; + } /* Update scrollbar */ well_length = s->length - 2 * SCROLLBAR_WIDTH; s->bar_pos = (s->full_size < 1) ? 0 : - ((well_length * s->offset) / s->full_size); + ((well_length * s->offset) / s->full_size); msg.scrollbar = s; msg.msg = SCROLLBAR_MSG_MOVED; @@ -492,41 +633,47 @@ bool scrollbar_scroll(struct scrollbar *s, int change) /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ int scrollbar_get_offset(struct scrollbar *s) { - if (s == NULL) + if (s == NULL) { return 0; + } return s->offset; } /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_set_extents(struct scrollbar *s, int length, - int visible_size, int full_size) + int visible_size, int full_size) { int cur_excess = s->full_size - s->visible_size; int well_length; struct scrollbar_msg_data msg; - if (length == s->length && visible_size == s->visible_size && - full_size == s->full_size) { + if (length == s->length && + visible_size == s->visible_size && + full_size == s->full_size) { /* Nothing's changed. */ return; } - if (length != -1) + if (length != -1) { s->length = length; - if (visible_size != -1) + } + if (visible_size != -1) { s->visible_size = visible_size; - if (full_size != -1) + } + if (full_size != -1) { s->full_size = full_size; + } - if (s->full_size < s->visible_size) + if (s->full_size < s->visible_size) { s->full_size = s->visible_size; + } /* Update scroll offset (scaled in proportion with change in excess) */ if (cur_excess <= 0) { @@ -553,7 +700,7 @@ void scrollbar_set_extents(struct scrollbar *s, int length, /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ bool scrollbar_is_horizontal(struct scrollbar *s) { @@ -568,12 +715,14 @@ bool scrollbar_is_horizontal(struct scrollbar *s) * \param x the X coordinate of the drag start * \param y the Y coordinate of the drag start * \param content_drag whether this should be a reverse drag (used when the - * user drags the content area, rather than the scrollbar) + * user drags the content area, rather than the scrollbar) * \param pair whether the drag is a '2D' scroll */ - -static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y, - bool content_drag, bool pair) +static void +scrollbar_drag_start_internal(struct scrollbar *s, + int x, int y, + bool content_drag, + bool pair) { struct scrollbar_msg_data msg; @@ -585,7 +734,7 @@ static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y, msg.scrollbar = s; - /* \todo - some proper numbers please! */ + /** \todo some proper numbers please! */ if (s->horizontal) { msg.x0 = -2048; msg.x1 = 2048; @@ -602,10 +751,10 @@ static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y, s->pair_drag = true; s->pair->drag_start_coord = - s->pair->horizontal ? x : y; + s->pair->horizontal ? x : y; s->pair->drag_start_pos = (content_drag) ? s->pair->offset : - s->pair->bar_pos; + s->pair->bar_pos; s->pair->dragging = true; s->pair->drag_content = content_drag; @@ -624,10 +773,12 @@ static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y, /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ -scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s, - browser_mouse_state mouse, int x, int y) +scrollbar_mouse_status +scrollbar_mouse_action(struct scrollbar *s, + browser_mouse_state mouse, + int x, int y) { int x0, y0, x1, y1; int val; @@ -638,13 +789,13 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s, * scrollbar indication bar to be launching actions on the scroll area */ bool but1 = ((mouse & BROWSER_MOUSE_PRESS_1) || - ((mouse & BROWSER_MOUSE_HOLDING_1) && - (mouse & BROWSER_MOUSE_DRAG_ON) && - !s->dragging)); + ((mouse & BROWSER_MOUSE_HOLDING_1) && + (mouse & BROWSER_MOUSE_DRAG_ON) && + !s->dragging)); bool but2 = ((mouse & BROWSER_MOUSE_PRESS_2) || - ((mouse & BROWSER_MOUSE_HOLDING_2) && - (mouse & BROWSER_MOUSE_DRAG_ON) && - !s->dragging)); + ((mouse & BROWSER_MOUSE_HOLDING_2) && + (mouse & BROWSER_MOUSE_DRAG_ON) && + !s->dragging)); h = s->horizontal; @@ -659,88 +810,91 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s, } - if (h) + if (h) { val = x; - else + } else { val = y; + } if (s->dragging) { val -= s->drag_start_coord; - if (s->drag_content) + if (s->drag_content) { val = -val; - if (val != 0) + } + if (val != 0) { scrollbar_set(s, s->drag_start_pos + val, - !(s->drag_content)); + !(s->drag_content)); + } if (s->pair_drag) { scrollbar_mouse_action(s->pair, mouse, x, y); status = SCROLLBAR_MOUSE_BOTH; - } else + } else { status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT; - + } return status; } if (val < SCROLLBAR_WIDTH) { /* left/up arrow */ - + status = h ? SCROLLBAR_MOUSE_LFT : SCROLLBAR_MOUSE_UP; - if (but1) + if (but1) { scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false); - else if (but2) + } else if (but2) { scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false); - + } } else if (val < SCROLLBAR_WIDTH + s->bar_pos) { /* well between left/up arrow and bar */ status = h ? SCROLLBAR_MOUSE_PLFT : SCROLLBAR_MOUSE_PUP; - if (but1) + if (but1) { scrollbar_set(s, s->offset - s->length, false); - else if (but2) + } else if (but2) { scrollbar_set(s, s->offset + s->length, false); - + } } else if (val > s->length - SCROLLBAR_WIDTH) { /* right/down arrow */ status = h ? SCROLLBAR_MOUSE_RGT : SCROLLBAR_MOUSE_DWN; - if (but1) + if (but1) { scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false); - else if (but2) + } else if (but2) { scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false); - - } else if (val > SCROLLBAR_WIDTH + s->bar_pos + - s->bar_len) { + } + } else if (val > SCROLLBAR_WIDTH + s->bar_pos + s->bar_len) { /* well between right/down arrow and bar */ status = h ? SCROLLBAR_MOUSE_PRGT : SCROLLBAR_MOUSE_PDWN; - if (but1) + if (but1) { scrollbar_set(s, s->offset + s->length, false); - else if (but2) + } else if (but2) { scrollbar_set(s, s->offset - s->length, false); - } - else { + } + } else { /* scrollbar position indication bar */ - + status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT; } - + if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2) && - (val >= SCROLLBAR_WIDTH + s->bar_pos - && val < SCROLLBAR_WIDTH + s->bar_pos + - s->bar_len)) + (val >= SCROLLBAR_WIDTH + s->bar_pos + && val < SCROLLBAR_WIDTH + s->bar_pos + + s->bar_len)) { /* The mouse event is a drag start on the scrollbar position * indication bar. */ scrollbar_drag_start_internal(s, x, y, false, - (mouse & BROWSER_MOUSE_DRAG_2) ? true : false); + (mouse & BROWSER_MOUSE_DRAG_2) ? true : false); + } return status; } /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status) { @@ -784,10 +938,10 @@ const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status) /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_mouse_drag_end(struct scrollbar *s, - browser_mouse_state mouse, int x, int y) + browser_mouse_state mouse, int x, int y) { struct scrollbar_msg_data msg; int val, drag_start_pos; @@ -797,10 +951,12 @@ void scrollbar_mouse_drag_end(struct scrollbar *s, drag_start_pos = s->drag_start_pos; val = (s->horizontal ? x : y) - s->drag_start_coord; - if (s->drag_content) + if (s->drag_content) { val = -val; - if (val != 0) + } + if (val != 0) { scrollbar_set(s, drag_start_pos + val, !(s->drag_content)); + } s->dragging = false; s->drag_content = false; @@ -811,11 +967,13 @@ void scrollbar_mouse_drag_end(struct scrollbar *s, drag_start_pos = s->pair->drag_start_pos; val = (s->pair->horizontal ? x : y) - s->pair->drag_start_coord; - if (s->pair->drag_content) + if (s->pair->drag_content) { val = -val; - if (val != 0) + } + if (val != 0) { scrollbar_set(s->pair, drag_start_pos + val, - !(s->pair->drag_content)); + !(s->pair->drag_content)); + } s->pair->dragging = false; s->pair->drag_content = false; @@ -828,7 +986,7 @@ void scrollbar_mouse_drag_end(struct scrollbar *s, /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_start_content_drag(struct scrollbar *s, int x, int y) { @@ -837,13 +995,13 @@ void scrollbar_start_content_drag(struct scrollbar *s, int x, int y) /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void scrollbar_make_pair(struct scrollbar *horizontal, - struct scrollbar *vertical) + struct scrollbar *vertical) { assert(horizontal->horizontal && - !vertical->horizontal); + !vertical->horizontal); horizontal->pair = vertical; vertical->pair = horizontal; @@ -851,10 +1009,9 @@ void scrollbar_make_pair(struct scrollbar *horizontal, /* - * Exported function. Documented in scrollbar.h + * Exported interface. Documented in scrollbar.h */ void *scrollbar_get_data(struct scrollbar *s) { return s->client_data; } - |