mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-01 00:34:31 +03:00
make scrollbar redraw signal errors correctly
allow scrollbar redraw to return error codes and update documentation commenst appropriately.
This commit is contained in:
parent
2f5e5620e2
commit
44c5aef1c8
@ -154,8 +154,11 @@ browser_window_set_name(struct browser_window *bw, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* exported interface, documented in browser.h */
|
/* exported interface, documented in browser.h */
|
||||||
bool browser_window_redraw(struct browser_window *bw, int x, int y,
|
bool
|
||||||
const struct rect *clip, const struct redraw_context *ctx)
|
browser_window_redraw(struct browser_window *bw,
|
||||||
|
int x, int y,
|
||||||
|
const struct rect *clip,
|
||||||
|
const struct redraw_context *ctx)
|
||||||
{
|
{
|
||||||
struct redraw_context new_ctx = *ctx;
|
struct redraw_context new_ctx = *ctx;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
@ -164,6 +167,7 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y,
|
|||||||
content_type content_type;
|
content_type content_type;
|
||||||
struct content_redraw_data data;
|
struct content_redraw_data data;
|
||||||
struct rect content_clip;
|
struct rect content_clip;
|
||||||
|
nserror res;
|
||||||
|
|
||||||
if (bw == NULL) {
|
if (bw == NULL) {
|
||||||
LOG("NULL browser window");
|
LOG("NULL browser window");
|
||||||
@ -299,16 +303,22 @@ bool browser_window_redraw(struct browser_window *bw, int x, int y,
|
|||||||
if (bw->scroll_x != NULL) {
|
if (bw->scroll_x != NULL) {
|
||||||
browser_window_get_scrollbar_pos(bw, true,
|
browser_window_get_scrollbar_pos(bw, true,
|
||||||
&off_x, &off_y);
|
&off_x, &off_y);
|
||||||
plot_ok &= scrollbar_redraw(bw->scroll_x,
|
res = scrollbar_redraw(bw->scroll_x,
|
||||||
x + off_x, y + off_y, clip,
|
x + off_x, y + off_y, clip,
|
||||||
bw->scale, &new_ctx);
|
bw->scale, &new_ctx);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
plot_ok = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (bw->scroll_y != NULL) {
|
if (bw->scroll_y != NULL) {
|
||||||
browser_window_get_scrollbar_pos(bw, false,
|
browser_window_get_scrollbar_pos(bw, false,
|
||||||
&off_x, &off_y);
|
&off_x, &off_y);
|
||||||
plot_ok &= scrollbar_redraw(bw->scroll_y,
|
res = scrollbar_redraw(bw->scroll_y,
|
||||||
x + off_x, y + off_y, clip,
|
x + off_x, y + off_y, clip,
|
||||||
bw->scale, &new_ctx);
|
bw->scale, &new_ctx);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
plot_ok = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,39 +46,56 @@ struct scrollbar {
|
|||||||
/** Length of the scrollbar widget */
|
/** Length of the scrollbar widget */
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
int full_size; /* Length of the full scrollable area */
|
/** Length of the full scrollable area */
|
||||||
int visible_size; /* Length visible part of the scrollable area */
|
int full_size;
|
||||||
|
/** Length visible part of the scrollable area */
|
||||||
|
int visible_size;
|
||||||
|
|
||||||
int offset; /* Current scroll offset to visible area */
|
/** Current scroll offset to visible area */
|
||||||
|
int offset;
|
||||||
|
|
||||||
int bar_pos; /* Position of the scrollbar */
|
/** Position of the scrollbar */
|
||||||
int bar_len; /* Length of the scrollbar */
|
int bar_pos;
|
||||||
|
/** Length of the scrollbar */
|
||||||
|
int bar_len;
|
||||||
|
|
||||||
scrollbar_client_callback client_callback; /* Callback receiving
|
/** Callback receiving scrollbar events */
|
||||||
* scrollbar events */
|
scrollbar_client_callback client_callback;
|
||||||
void *client_data; /* User data passed to the callback */
|
/** User data passed to the callback */
|
||||||
|
void *client_data;
|
||||||
|
|
||||||
bool dragging; /* Flag indicating drag at progess */
|
/** Flag indicating drag at progess */
|
||||||
int drag_start_coord; /* Coordinate value at drag start */
|
bool dragging;
|
||||||
int drag_start_pos; /* Scrollbar offset or bar_pos at drag start */
|
/** Coordinate value at drag start */
|
||||||
bool drag_content; /* Flag indicating that the drag corresponds to
|
int drag_start_coord;
|
||||||
* a dragged content area, rather than a dragged
|
/** Scrollbar offset or bar_pos at drag start */
|
||||||
* scrollbar. */
|
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 */
|
/** Parpendicular scrollbar, or NULL */
|
||||||
bool pair_drag; /* Flag indicating that the current drag affects
|
struct scrollbar *pair;
|
||||||
the perpendicular scrollbar too */
|
/** 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,
|
nserror
|
||||||
int visible_size, void *client_data,
|
scrollbar_create(bool horizontal,
|
||||||
scrollbar_client_callback client_callback,
|
int length,
|
||||||
struct scrollbar **s)
|
int full_size,
|
||||||
|
int visible_size,
|
||||||
|
void *client_data,
|
||||||
|
scrollbar_client_callback client_callback,
|
||||||
|
struct scrollbar **s)
|
||||||
{
|
{
|
||||||
struct scrollbar *scrollbar;
|
struct scrollbar *scrollbar;
|
||||||
int well_length;
|
int well_length;
|
||||||
@ -100,7 +117,7 @@ nserror scrollbar_create(bool horizontal, int length, int full_size,
|
|||||||
|
|
||||||
well_length = length - 2 * SCROLLBAR_WIDTH;
|
well_length = length - 2 * SCROLLBAR_WIDTH;
|
||||||
scrollbar->bar_len = (full_size == 0) ? 0 :
|
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_callback = client_callback;
|
||||||
scrollbar->client_data = client_data;
|
scrollbar->client_data = client_data;
|
||||||
@ -115,12 +132,13 @@ 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)
|
void scrollbar_destroy(struct scrollbar *s)
|
||||||
{
|
{
|
||||||
if (s->pair != NULL)
|
if (s->pair != NULL) {
|
||||||
s->pair->pair = NULL;
|
s->pair->pair = NULL;
|
||||||
|
}
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +153,6 @@ void scrollbar_destroy(struct scrollbar *s)
|
|||||||
* \param inset true for inset outline, false for an outset one
|
* \param inset true for inset outline, false for an outset one
|
||||||
* \return NSERROR_OK on success else error code
|
* \return NSERROR_OK on success else error code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline nserror
|
static inline nserror
|
||||||
scrollbar_rectangle(const struct redraw_context *ctx,
|
scrollbar_rectangle(const struct redraw_context *ctx,
|
||||||
struct rect *area,
|
struct rect *area,
|
||||||
@ -215,11 +232,14 @@ scrollbar_rectangle(const struct redraw_context *ctx,
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exported function. Documented in scrollbar.h
|
* Exported interface. Documented in scrollbar.h
|
||||||
*/
|
*/
|
||||||
bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
nserror
|
||||||
const struct rect *clip, float scale,
|
scrollbar_redraw(struct scrollbar *s,
|
||||||
const struct redraw_context *ctx)
|
int x, int y,
|
||||||
|
const struct rect *clip,
|
||||||
|
float scale,
|
||||||
|
const struct redraw_context *ctx)
|
||||||
{
|
{
|
||||||
int w = SCROLLBAR_WIDTH;
|
int w = SCROLLBAR_WIDTH;
|
||||||
int bar_pos, bar_c0, bar_c1;
|
int bar_pos, bar_c0, bar_c1;
|
||||||
@ -259,7 +279,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
area.y1 = y + (s->horizontal ? SCROLLBAR_WIDTH : s->length) - 1;
|
area.y1 = y + (s->horizontal ? SCROLLBAR_WIDTH : s->length) - 1;
|
||||||
bar_pos = s->bar_pos;
|
bar_pos = s->bar_pos;
|
||||||
bar_c1 = (s->horizontal ? area.x0 : area.y0) + SCROLLBAR_WIDTH +
|
bar_c1 = (s->horizontal ? area.x0 : area.y0) + SCROLLBAR_WIDTH +
|
||||||
s->bar_pos + s->bar_len - 1;
|
s->bar_pos + s->bar_len - 1;
|
||||||
|
|
||||||
if (scale != 1.0) {
|
if (scale != 1.0) {
|
||||||
w *= scale;
|
w *= scale;
|
||||||
@ -278,7 +298,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
(area.y1 < clip->y0) ||
|
(area.y1 < clip->y0) ||
|
||||||
(clip->x1 < area.x0) ||
|
(clip->x1 < area.x0) ||
|
||||||
(clip->y1 < area.y0)) {
|
(clip->y1 < area.y0)) {
|
||||||
return true;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->horizontal) {
|
if (s->horizontal) {
|
||||||
@ -288,7 +308,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
res = scrollbar_rectangle(ctx, &area,
|
res = scrollbar_rectangle(ctx, &area,
|
||||||
bg_fill_style.fill_colour, true);
|
bg_fill_style.fill_colour, true);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* left arrow icon border */
|
/* left arrow icon border */
|
||||||
@ -299,7 +319,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
res = scrollbar_rectangle(ctx, &rect,
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
fg_fill_style.fill_colour, false);
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* left arrow icon background */
|
/* left arrow icon background */
|
||||||
@ -309,7 +329,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* left arrow */
|
/* left arrow */
|
||||||
@ -321,7 +341,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
v[5] = area.y0 + w * 3 / 4;
|
v[5] = area.y0 + w * 3 / 4;
|
||||||
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scrollbar well background */
|
/* scrollbar well background */
|
||||||
@ -331,7 +351,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1;
|
rect.y1 = area.y1;
|
||||||
res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scrollbar position indicator bar */
|
/* scrollbar position indicator bar */
|
||||||
@ -339,9 +359,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y0 = area.y0 + 1;
|
rect.y0 = area.y0 + 1;
|
||||||
rect.x1 = bar_c1;
|
rect.x1 = bar_c1;
|
||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = scrollbar_rectangle(ctx, &rect, fg_fill_style.fill_colour, false);
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.x0 = bar_c0 + 1;
|
rect.x0 = bar_c0 + 1;
|
||||||
@ -350,7 +371,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* right arrow icon border */
|
/* right arrow icon border */
|
||||||
@ -358,9 +379,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y0 = area.y0 + 1;
|
rect.y0 = area.y0 + 1;
|
||||||
rect.x1 = area.x1 - 1;
|
rect.x1 = area.x1 - 1;
|
||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = scrollbar_rectangle(ctx, &rect, fg_fill_style.fill_colour, false);
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* right arrow icon background */
|
/* right arrow icon background */
|
||||||
@ -370,7 +392,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* right arrow */
|
/* right arrow */
|
||||||
@ -382,15 +404,16 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
v[5] = rect.y0 + w * 3 / 4;
|
v[5] = rect.y0 + w * 3 / 4;
|
||||||
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* scrollbar is vertical */
|
/* scrollbar is vertical */
|
||||||
|
|
||||||
/* outline */
|
/* outline */
|
||||||
res = scrollbar_rectangle(ctx, &area, bg_fill_style.fill_colour, true);
|
res = scrollbar_rectangle(ctx, &area,
|
||||||
|
bg_fill_style.fill_colour, true);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* top arrow border */
|
/* top arrow border */
|
||||||
@ -398,9 +421,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y0 = area.y0 + 1;
|
rect.y0 = area.y0 + 1;
|
||||||
rect.x1 = area.x1 - 1;
|
rect.x1 = area.x1 - 1;
|
||||||
rect.y1 = area.y0 + w - 2;
|
rect.y1 = area.y0 + w - 2;
|
||||||
res = scrollbar_rectangle(ctx, &rect, fg_fill_style.fill_colour, false);
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* top arrow background */
|
/* top arrow background */
|
||||||
@ -410,7 +434,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y0 + w - 2;
|
rect.y1 = area.y0 + w - 2;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* up arrow */
|
/* up arrow */
|
||||||
@ -422,7 +446,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
v[5] = area.y0 + w * 3 / 4;
|
v[5] = area.y0 + w * 3 / 4;
|
||||||
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scrollbar well background */
|
/* scrollbar well background */
|
||||||
@ -432,7 +456,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1 - w + 2;
|
rect.y1 = area.y1 - w + 2;
|
||||||
res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &bg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scrollbar position indicator bar */
|
/* scrollbar position indicator bar */
|
||||||
@ -440,9 +464,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y0 = bar_c0;
|
rect.y0 = bar_c0;
|
||||||
rect.x1 = area.x1 - 1;
|
rect.x1 = area.x1 - 1;
|
||||||
rect.y1 = bar_c1;
|
rect.y1 = bar_c1;
|
||||||
res = scrollbar_rectangle(ctx, &rect, fg_fill_style.fill_colour, false);
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.x0 = area.x0 + 2;
|
rect.x0 = area.x0 + 2;
|
||||||
@ -451,7 +476,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = bar_c1;
|
rect.y1 = bar_c1;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* down arrow icon border */
|
/* down arrow icon border */
|
||||||
@ -459,9 +484,10 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y0 = area.y1 - w + 2;
|
rect.y0 = area.y1 - w + 2;
|
||||||
rect.x1 = area.x1 - 1;
|
rect.x1 = area.x1 - 1;
|
||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = scrollbar_rectangle(ctx, &rect, fg_fill_style.fill_colour, false);
|
res = scrollbar_rectangle(ctx, &rect,
|
||||||
|
fg_fill_style.fill_colour, false);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* down arrow icon background */
|
/* down arrow icon background */
|
||||||
@ -471,7 +497,7 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
rect.y1 = area.y1 - 1;
|
rect.y1 = area.y1 - 1;
|
||||||
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
res = ctx->plot->rectangle(ctx, &fg_fill_style, &rect);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* down arrow */
|
/* down arrow */
|
||||||
@ -483,16 +509,16 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
|||||||
v[5] = area.y1 - w * 3 / 4 + 1;
|
v[5] = area.y1 - w * 3 / 4 + 1;
|
||||||
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
res = ctx->plot->polygon(ctx, &arrow_fill_style, v, 3);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
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)
|
void scrollbar_set(struct scrollbar *s, int value, bool bar_pos)
|
||||||
{
|
{
|
||||||
@ -500,46 +526,49 @@ void scrollbar_set(struct scrollbar *s, int value, bool bar_pos)
|
|||||||
int old_offset = s->offset;
|
int old_offset = s->offset;
|
||||||
struct scrollbar_msg_data msg;
|
struct scrollbar_msg_data msg;
|
||||||
|
|
||||||
if (value < 0)
|
if (value < 0) {
|
||||||
value = 0;
|
value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->full_size == s->visible_size)
|
if (s->full_size == s->visible_size) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
||||||
if (bar_pos) {
|
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;
|
s->bar_pos = well_length - s->bar_len;
|
||||||
else
|
} else {
|
||||||
s->bar_pos = value;
|
s->bar_pos = value;
|
||||||
|
}
|
||||||
|
|
||||||
s->offset = ((well_length - s->bar_len) < 1) ? 0 :
|
s->offset = ((well_length - s->bar_len) < 1) ? 0 :
|
||||||
(((s->full_size - s->visible_size) *
|
(((s->full_size - s->visible_size) *
|
||||||
s->bar_pos) / (well_length - s->bar_len));
|
s->bar_pos) / (well_length - s->bar_len));
|
||||||
|
|
||||||
} else {
|
} 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;
|
s->offset = s->full_size - s->visible_size;
|
||||||
else
|
} else {
|
||||||
s->offset = value;
|
s->offset = value;
|
||||||
|
}
|
||||||
|
|
||||||
s->bar_pos = (s->full_size < 1) ? 0 :
|
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)
|
if (s->offset != old_offset) {
|
||||||
/* Nothing happened */
|
/* client callback if there was a chnage */
|
||||||
return;
|
msg.scrollbar = s;
|
||||||
|
msg.msg = SCROLLBAR_MSG_MOVED;
|
||||||
msg.scrollbar = s;
|
msg.scroll_offset = s->offset;
|
||||||
msg.msg = SCROLLBAR_MSG_MOVED;
|
s->client_callback(s->client_data, &msg);
|
||||||
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)
|
bool scrollbar_scroll(struct scrollbar *s, int change)
|
||||||
{
|
{
|
||||||
@ -547,9 +576,10 @@ bool scrollbar_scroll(struct scrollbar *s, int change)
|
|||||||
int old_offset = s->offset;
|
int old_offset = s->offset;
|
||||||
struct scrollbar_msg_data msg;
|
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 */
|
/* zero scroll step, or unscrollable */
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert named change values to appropriate pixel offset value */
|
/* Convert named change values to appropriate pixel offset value */
|
||||||
switch (change) {
|
switch (change) {
|
||||||
@ -575,21 +605,23 @@ bool scrollbar_scroll(struct scrollbar *s, int change)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get new offset */
|
/* 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;
|
s->offset = s->full_size - s->visible_size;
|
||||||
else if (s->offset + change < 0)
|
} else if (s->offset + change < 0) {
|
||||||
s->offset = 0;
|
s->offset = 0;
|
||||||
else
|
} else {
|
||||||
s->offset += change;
|
s->offset += change;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->offset == old_offset)
|
if (s->offset == old_offset) {
|
||||||
/* Nothing happened */
|
/* Nothing happened */
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Update scrollbar */
|
/* Update scrollbar */
|
||||||
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
||||||
s->bar_pos = (s->full_size < 1) ? 0 :
|
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.scrollbar = s;
|
||||||
msg.msg = SCROLLBAR_MSG_MOVED;
|
msg.msg = SCROLLBAR_MSG_MOVED;
|
||||||
@ -601,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)
|
int scrollbar_get_offset(struct scrollbar *s)
|
||||||
{
|
{
|
||||||
if (s == NULL)
|
if (s == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return s->offset;
|
return s->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exported function. Documented in scrollbar.h
|
* Exported interface. Documented in scrollbar.h
|
||||||
*/
|
*/
|
||||||
void scrollbar_set_extents(struct scrollbar *s, int length,
|
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 cur_excess = s->full_size - s->visible_size;
|
||||||
int well_length;
|
int well_length;
|
||||||
struct scrollbar_msg_data msg;
|
struct scrollbar_msg_data msg;
|
||||||
|
|
||||||
if (length == s->length && visible_size == s->visible_size &&
|
if (length == s->length &&
|
||||||
full_size == s->full_size) {
|
visible_size == s->visible_size &&
|
||||||
|
full_size == s->full_size) {
|
||||||
/* Nothing's changed. */
|
/* Nothing's changed. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length != -1)
|
if (length != -1) {
|
||||||
s->length = length;
|
s->length = length;
|
||||||
if (visible_size != -1)
|
}
|
||||||
|
if (visible_size != -1) {
|
||||||
s->visible_size = visible_size;
|
s->visible_size = visible_size;
|
||||||
if (full_size != -1)
|
}
|
||||||
|
if (full_size != -1) {
|
||||||
s->full_size = full_size;
|
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;
|
s->full_size = s->visible_size;
|
||||||
|
}
|
||||||
|
|
||||||
/* Update scroll offset (scaled in proportion with change in excess) */
|
/* Update scroll offset (scaled in proportion with change in excess) */
|
||||||
if (cur_excess <= 0) {
|
if (cur_excess <= 0) {
|
||||||
@ -662,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)
|
bool scrollbar_is_horizontal(struct scrollbar *s)
|
||||||
{
|
{
|
||||||
@ -680,9 +718,11 @@ bool scrollbar_is_horizontal(struct scrollbar *s)
|
|||||||
* 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
|
* \param pair whether the drag is a '2D' scroll
|
||||||
*/
|
*/
|
||||||
|
static void
|
||||||
static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y,
|
scrollbar_drag_start_internal(struct scrollbar *s,
|
||||||
bool content_drag, bool pair)
|
int x, int y,
|
||||||
|
bool content_drag,
|
||||||
|
bool pair)
|
||||||
{
|
{
|
||||||
struct scrollbar_msg_data msg;
|
struct scrollbar_msg_data msg;
|
||||||
|
|
||||||
@ -694,7 +734,7 @@ static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y,
|
|||||||
|
|
||||||
msg.scrollbar = s;
|
msg.scrollbar = s;
|
||||||
|
|
||||||
/* \todo - some proper numbers please! */
|
/** \todo some proper numbers please! */
|
||||||
if (s->horizontal) {
|
if (s->horizontal) {
|
||||||
msg.x0 = -2048;
|
msg.x0 = -2048;
|
||||||
msg.x1 = 2048;
|
msg.x1 = 2048;
|
||||||
@ -711,10 +751,10 @@ static void scrollbar_drag_start_internal(struct scrollbar *s, int x, int y,
|
|||||||
s->pair_drag = true;
|
s->pair_drag = true;
|
||||||
|
|
||||||
s->pair->drag_start_coord =
|
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->drag_start_pos = (content_drag) ? s->pair->offset :
|
||||||
s->pair->bar_pos;
|
s->pair->bar_pos;
|
||||||
|
|
||||||
s->pair->dragging = true;
|
s->pair->dragging = true;
|
||||||
s->pair->drag_content = content_drag;
|
s->pair->drag_content = content_drag;
|
||||||
@ -733,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,
|
scrollbar_mouse_status
|
||||||
browser_mouse_state mouse, int x, int y)
|
scrollbar_mouse_action(struct scrollbar *s,
|
||||||
|
browser_mouse_state mouse,
|
||||||
|
int x, int y)
|
||||||
{
|
{
|
||||||
int x0, y0, x1, y1;
|
int x0, y0, x1, y1;
|
||||||
int val;
|
int val;
|
||||||
@ -747,13 +789,13 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
|||||||
* scrollbar indication bar to be launching actions on the scroll area
|
* scrollbar indication bar to be launching actions on the scroll area
|
||||||
*/
|
*/
|
||||||
bool but1 = ((mouse & BROWSER_MOUSE_PRESS_1) ||
|
bool but1 = ((mouse & BROWSER_MOUSE_PRESS_1) ||
|
||||||
((mouse & BROWSER_MOUSE_HOLDING_1) &&
|
((mouse & BROWSER_MOUSE_HOLDING_1) &&
|
||||||
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
||||||
!s->dragging));
|
!s->dragging));
|
||||||
bool but2 = ((mouse & BROWSER_MOUSE_PRESS_2) ||
|
bool but2 = ((mouse & BROWSER_MOUSE_PRESS_2) ||
|
||||||
((mouse & BROWSER_MOUSE_HOLDING_2) &&
|
((mouse & BROWSER_MOUSE_HOLDING_2) &&
|
||||||
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
||||||
!s->dragging));
|
!s->dragging));
|
||||||
|
|
||||||
h = s->horizontal;
|
h = s->horizontal;
|
||||||
|
|
||||||
@ -768,24 +810,27 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (h)
|
if (h) {
|
||||||
val = x;
|
val = x;
|
||||||
else
|
} else {
|
||||||
val = y;
|
val = y;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->dragging) {
|
if (s->dragging) {
|
||||||
val -= s->drag_start_coord;
|
val -= s->drag_start_coord;
|
||||||
if (s->drag_content)
|
if (s->drag_content) {
|
||||||
val = -val;
|
val = -val;
|
||||||
if (val != 0)
|
}
|
||||||
|
if (val != 0) {
|
||||||
scrollbar_set(s, s->drag_start_pos + val,
|
scrollbar_set(s, s->drag_start_pos + val,
|
||||||
!(s->drag_content));
|
!(s->drag_content));
|
||||||
|
}
|
||||||
if (s->pair_drag) {
|
if (s->pair_drag) {
|
||||||
scrollbar_mouse_action(s->pair, mouse, x, y);
|
scrollbar_mouse_action(s->pair, mouse, x, y);
|
||||||
status = SCROLLBAR_MOUSE_BOTH;
|
status = SCROLLBAR_MOUSE_BOTH;
|
||||||
} else
|
} else {
|
||||||
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,42 +838,41 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
|||||||
/* left/up arrow */
|
/* left/up arrow */
|
||||||
|
|
||||||
status = h ? SCROLLBAR_MOUSE_LFT : SCROLLBAR_MOUSE_UP;
|
status = h ? SCROLLBAR_MOUSE_LFT : SCROLLBAR_MOUSE_UP;
|
||||||
if (but1)
|
if (but1) {
|
||||||
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
||||||
else if (but2)
|
} else if (but2) {
|
||||||
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
||||||
|
}
|
||||||
} else if (val < SCROLLBAR_WIDTH + s->bar_pos) {
|
} else if (val < SCROLLBAR_WIDTH + s->bar_pos) {
|
||||||
/* well between left/up arrow and bar */
|
/* well between left/up arrow and bar */
|
||||||
|
|
||||||
status = h ? SCROLLBAR_MOUSE_PLFT : SCROLLBAR_MOUSE_PUP;
|
status = h ? SCROLLBAR_MOUSE_PLFT : SCROLLBAR_MOUSE_PUP;
|
||||||
|
|
||||||
if (but1)
|
if (but1) {
|
||||||
scrollbar_set(s, s->offset - s->length, false);
|
scrollbar_set(s, s->offset - s->length, false);
|
||||||
else if (but2)
|
} else if (but2) {
|
||||||
scrollbar_set(s, s->offset + s->length, false);
|
scrollbar_set(s, s->offset + s->length, false);
|
||||||
|
}
|
||||||
} else if (val > s->length - SCROLLBAR_WIDTH) {
|
} else if (val > s->length - SCROLLBAR_WIDTH) {
|
||||||
/* right/down arrow */
|
/* right/down arrow */
|
||||||
|
|
||||||
status = h ? SCROLLBAR_MOUSE_RGT : SCROLLBAR_MOUSE_DWN;
|
status = h ? SCROLLBAR_MOUSE_RGT : SCROLLBAR_MOUSE_DWN;
|
||||||
|
|
||||||
if (but1)
|
if (but1) {
|
||||||
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
||||||
else if (but2)
|
} else if (but2) {
|
||||||
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
||||||
|
}
|
||||||
} else if (val > SCROLLBAR_WIDTH + s->bar_pos +
|
} else if (val > SCROLLBAR_WIDTH + s->bar_pos + s->bar_len) {
|
||||||
s->bar_len) {
|
|
||||||
/* well between right/down arrow and bar */
|
/* well between right/down arrow and bar */
|
||||||
|
|
||||||
status = h ? SCROLLBAR_MOUSE_PRGT : SCROLLBAR_MOUSE_PDWN;
|
status = h ? SCROLLBAR_MOUSE_PRGT : SCROLLBAR_MOUSE_PDWN;
|
||||||
if (but1)
|
if (but1) {
|
||||||
scrollbar_set(s, s->offset + s->length, false);
|
scrollbar_set(s, s->offset + s->length, false);
|
||||||
else if (but2)
|
} else if (but2) {
|
||||||
scrollbar_set(s, s->offset - s->length, false);
|
scrollbar_set(s, s->offset - s->length, false);
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
/* scrollbar position indication bar */
|
/* scrollbar position indication bar */
|
||||||
|
|
||||||
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
||||||
@ -836,20 +880,21 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
|||||||
|
|
||||||
|
|
||||||
if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2) &&
|
if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2) &&
|
||||||
(val >= SCROLLBAR_WIDTH + s->bar_pos
|
(val >= SCROLLBAR_WIDTH + s->bar_pos
|
||||||
&& val < SCROLLBAR_WIDTH + s->bar_pos +
|
&& val < SCROLLBAR_WIDTH + s->bar_pos +
|
||||||
s->bar_len))
|
s->bar_len)) {
|
||||||
/* The mouse event is a drag start on the scrollbar position
|
/* The mouse event is a drag start on the scrollbar position
|
||||||
* indication bar. */
|
* indication bar. */
|
||||||
scrollbar_drag_start_internal(s, x, y, false,
|
scrollbar_drag_start_internal(s, x, y, false,
|
||||||
(mouse & BROWSER_MOUSE_DRAG_2) ? true : false);
|
(mouse & BROWSER_MOUSE_DRAG_2) ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
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)
|
const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status)
|
||||||
{
|
{
|
||||||
@ -893,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,
|
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;
|
struct scrollbar_msg_data msg;
|
||||||
int val, drag_start_pos;
|
int val, drag_start_pos;
|
||||||
@ -906,10 +951,12 @@ void scrollbar_mouse_drag_end(struct scrollbar *s,
|
|||||||
drag_start_pos = s->drag_start_pos;
|
drag_start_pos = s->drag_start_pos;
|
||||||
val = (s->horizontal ? x : y) - s->drag_start_coord;
|
val = (s->horizontal ? x : y) - s->drag_start_coord;
|
||||||
|
|
||||||
if (s->drag_content)
|
if (s->drag_content) {
|
||||||
val = -val;
|
val = -val;
|
||||||
if (val != 0)
|
}
|
||||||
|
if (val != 0) {
|
||||||
scrollbar_set(s, drag_start_pos + val, !(s->drag_content));
|
scrollbar_set(s, drag_start_pos + val, !(s->drag_content));
|
||||||
|
}
|
||||||
|
|
||||||
s->dragging = false;
|
s->dragging = false;
|
||||||
s->drag_content = false;
|
s->drag_content = false;
|
||||||
@ -920,11 +967,13 @@ void scrollbar_mouse_drag_end(struct scrollbar *s,
|
|||||||
drag_start_pos = s->pair->drag_start_pos;
|
drag_start_pos = s->pair->drag_start_pos;
|
||||||
val = (s->pair->horizontal ? x : y) - s->pair->drag_start_coord;
|
val = (s->pair->horizontal ? x : y) - s->pair->drag_start_coord;
|
||||||
|
|
||||||
if (s->pair->drag_content)
|
if (s->pair->drag_content) {
|
||||||
val = -val;
|
val = -val;
|
||||||
if (val != 0)
|
}
|
||||||
|
if (val != 0) {
|
||||||
scrollbar_set(s->pair, drag_start_pos + val,
|
scrollbar_set(s->pair, drag_start_pos + val,
|
||||||
!(s->pair->drag_content));
|
!(s->pair->drag_content));
|
||||||
|
}
|
||||||
|
|
||||||
s->pair->dragging = false;
|
s->pair->dragging = false;
|
||||||
s->pair->drag_content = false;
|
s->pair->drag_content = false;
|
||||||
@ -937,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)
|
void scrollbar_start_content_drag(struct scrollbar *s, int x, int y)
|
||||||
{
|
{
|
||||||
@ -946,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,
|
void scrollbar_make_pair(struct scrollbar *horizontal,
|
||||||
struct scrollbar *vertical)
|
struct scrollbar *vertical)
|
||||||
{
|
{
|
||||||
assert(horizontal->horizontal &&
|
assert(horizontal->horizontal &&
|
||||||
!vertical->horizontal);
|
!vertical->horizontal);
|
||||||
|
|
||||||
horizontal->pair = vertical;
|
horizontal->pair = vertical;
|
||||||
vertical->pair = horizontal;
|
vertical->pair = horizontal;
|
||||||
@ -960,7 +1009,7 @@ 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)
|
void *scrollbar_get_data(struct scrollbar *s)
|
||||||
{
|
{
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/**
|
||||||
* Scrollbar widget (interface).
|
* \file
|
||||||
|
* Scrollbar widget interface.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NETSURF_DESKTOP_SCROLLBAR_H_
|
#ifndef NETSURF_DESKTOP_SCROLLBAR_H
|
||||||
#define _NETSURF_DESKTOP_SCROLLBAR_H_
|
#define NETSURF_DESKTOP_SCROLLBAR_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -36,16 +37,22 @@
|
|||||||
|
|
||||||
struct scrollbar;
|
struct scrollbar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scrollbar message types
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SCROLLBAR_MSG_MOVED, /* the scroll value has changed */
|
SCROLLBAR_MSG_MOVED, /**< the scroll value has changed */
|
||||||
SCROLLBAR_MSG_SCROLL_START, /* a scrollbar drag has started, all
|
SCROLLBAR_MSG_SCROLL_START, /**< a scrollbar drag has started, all
|
||||||
* mouse events should be passed to
|
* mouse events should be passed to
|
||||||
* the scrollbar regardless of the
|
* the scrollbar regardless of the
|
||||||
* coordinates
|
* coordinates
|
||||||
*/
|
*/
|
||||||
SCROLLBAR_MSG_SCROLL_FINISHED, /* cancel the above */
|
SCROLLBAR_MSG_SCROLL_FINISHED, /**< cancel a scrollbar drag */
|
||||||
} scrollbar_msg;
|
} scrollbar_msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scrollbar message context data
|
||||||
|
*/
|
||||||
struct scrollbar_msg_data {
|
struct scrollbar_msg_data {
|
||||||
struct scrollbar *scrollbar;
|
struct scrollbar *scrollbar;
|
||||||
scrollbar_msg msg;
|
scrollbar_msg msg;
|
||||||
@ -53,6 +60,27 @@ struct scrollbar_msg_data {
|
|||||||
int x0, y0, x1, y1;
|
int x0, y0, x1, y1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scrollbar mouse input status flags
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
SCROLLBAR_MOUSE_NONE = 0, /**< Not relevant */
|
||||||
|
SCROLLBAR_MOUSE_USED = (1 << 0), /**< Took action with input */
|
||||||
|
SCROLLBAR_MOUSE_BOTH = (1 << 1), /**< Scrolling both bars */
|
||||||
|
SCROLLBAR_MOUSE_UP = (1 << 2), /**< Hover: scroll up */
|
||||||
|
SCROLLBAR_MOUSE_PUP = (1 << 3), /**< Hover: scroll page up */
|
||||||
|
SCROLLBAR_MOUSE_VRT = (1 << 4), /**< Hover: vert. drag bar */
|
||||||
|
SCROLLBAR_MOUSE_PDWN = (1 << 5), /**< Hover: scroll page down */
|
||||||
|
SCROLLBAR_MOUSE_DWN = (1 << 6), /**< Hover: scroll down */
|
||||||
|
SCROLLBAR_MOUSE_LFT = (1 << 7), /**< Hover: scroll left */
|
||||||
|
SCROLLBAR_MOUSE_PLFT = (1 << 8), /**< Hover: scroll page left */
|
||||||
|
SCROLLBAR_MOUSE_HRZ = (1 << 9), /**< Hover: horiz. drag bar */
|
||||||
|
SCROLLBAR_MOUSE_PRGT = (1 << 10), /**< Hover: scroll page right */
|
||||||
|
SCROLLBAR_MOUSE_RGT = (1 << 11) /**< Hover: scroll right */
|
||||||
|
} scrollbar_mouse_status;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client callback for the scrollbar.
|
* Client callback for the scrollbar.
|
||||||
*
|
*
|
||||||
@ -84,7 +112,7 @@ nserror scrollbar_create(bool horizontal, int length, int full_size,
|
|||||||
/**
|
/**
|
||||||
* Destroy a scrollbar.
|
* Destroy a scrollbar.
|
||||||
*
|
*
|
||||||
* \param s the scrollbar to be destroyed
|
* \param s the scrollbar to be destroyed
|
||||||
*/
|
*/
|
||||||
void scrollbar_destroy(struct scrollbar *s);
|
void scrollbar_destroy(struct scrollbar *s);
|
||||||
|
|
||||||
@ -97,9 +125,9 @@ void scrollbar_destroy(struct scrollbar *s);
|
|||||||
* \param clip the clipping rectangle
|
* \param clip the clipping rectangle
|
||||||
* \param scale scale for the redraw
|
* \param scale scale for the redraw
|
||||||
* \param ctx current redraw context
|
* \param ctx current redraw context
|
||||||
* \return true on succes false otherwise
|
* \return NSERROR_OK on success otherwise error code
|
||||||
*/
|
*/
|
||||||
bool scrollbar_redraw(struct scrollbar *s, int x, int y,
|
nserror scrollbar_redraw(struct scrollbar *s, int x, int y,
|
||||||
const struct rect *clip, float scale,
|
const struct rect *clip, float scale,
|
||||||
const struct redraw_context *ctx);
|
const struct redraw_context *ctx);
|
||||||
|
|
||||||
@ -125,8 +153,8 @@ bool scrollbar_scroll(struct scrollbar *s, int change);
|
|||||||
/**
|
/**
|
||||||
* Get the current scroll offset to the visible part of the full area.
|
* Get the current scroll offset to the visible part of the full area.
|
||||||
*
|
*
|
||||||
* \param s the scrollbar to get the scroll offset value from
|
* \param s the scrollbar to get the scroll offset value from
|
||||||
* \return current scroll offset
|
* \return current scroll offset
|
||||||
*/
|
*/
|
||||||
int scrollbar_get_offset(struct scrollbar *s);
|
int scrollbar_get_offset(struct scrollbar *s);
|
||||||
|
|
||||||
@ -150,22 +178,6 @@ void scrollbar_set_extents(struct scrollbar *s, int length,
|
|||||||
*/
|
*/
|
||||||
bool scrollbar_is_horizontal(struct scrollbar *s);
|
bool scrollbar_is_horizontal(struct scrollbar *s);
|
||||||
|
|
||||||
/* Scrollbar mouse input status flags */
|
|
||||||
typedef enum {
|
|
||||||
SCROLLBAR_MOUSE_NONE = 0, /**< Not relevant */
|
|
||||||
SCROLLBAR_MOUSE_USED = (1 << 0), /**< Took action with input */
|
|
||||||
SCROLLBAR_MOUSE_BOTH = (1 << 1), /**< Scrolling both bars */
|
|
||||||
SCROLLBAR_MOUSE_UP = (1 << 2), /**< Hover: scroll up */
|
|
||||||
SCROLLBAR_MOUSE_PUP = (1 << 3), /**< Hover: scroll page up */
|
|
||||||
SCROLLBAR_MOUSE_VRT = (1 << 4), /**< Hover: vert. drag bar */
|
|
||||||
SCROLLBAR_MOUSE_PDWN = (1 << 5), /**< Hover: scroll page down */
|
|
||||||
SCROLLBAR_MOUSE_DWN = (1 << 6), /**< Hover: scroll down */
|
|
||||||
SCROLLBAR_MOUSE_LFT = (1 << 7), /**< Hover: scroll left */
|
|
||||||
SCROLLBAR_MOUSE_PLFT = (1 << 8), /**< Hover: scroll page left */
|
|
||||||
SCROLLBAR_MOUSE_HRZ = (1 << 9), /**< Hover: horiz. drag bar */
|
|
||||||
SCROLLBAR_MOUSE_PRGT = (1 << 10), /**< Hover: scroll page right */
|
|
||||||
SCROLLBAR_MOUSE_RGT = (1 << 11) /**< Hover: scroll right */
|
|
||||||
} scrollbar_mouse_status;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle mouse actions other then drag ends.
|
* Handle mouse actions other then drag ends.
|
||||||
@ -179,6 +191,7 @@ typedef enum {
|
|||||||
scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
||||||
browser_mouse_state mouse, int x, int y);
|
browser_mouse_state mouse, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a status bar message from a scrollbar mouse input status.
|
* Get a status bar message from a scrollbar mouse input status.
|
||||||
*
|
*
|
||||||
@ -187,6 +200,7 @@ scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s,
|
|||||||
*/
|
*/
|
||||||
const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status);
|
const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle end of mouse drags.
|
* Handle end of mouse drags.
|
||||||
*
|
*
|
||||||
@ -198,18 +212,21 @@ const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status);
|
|||||||
void scrollbar_mouse_drag_end(struct scrollbar *s,
|
void scrollbar_mouse_drag_end(struct scrollbar *s,
|
||||||
browser_mouse_state mouse, int x, int y);
|
browser_mouse_state mouse, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the content is being dragged to the scrollbars have to adjust.
|
* Called when the content is being dragged to the scrollbars have to adjust.
|
||||||
|
*
|
||||||
* If the content has both scrollbars, and scrollbar_make_pair has beed called
|
* If the content has both scrollbars, and scrollbar_make_pair has beed called
|
||||||
* before, only the one scroll which will receive further mouse events has to be
|
* before, only the one scroll which will receive further mouse events has to be
|
||||||
* passed.
|
* passed.
|
||||||
*
|
*
|
||||||
* \param s one of the the scrollbars owned by the dragged content
|
* \param s one of the the scrollbars owned by the dragged content
|
||||||
* \param x X coordinate of mouse during drag start
|
* \param x X coordinate of mouse during drag start
|
||||||
* \param y Y coordinate of mouse during drag start
|
* \param y Y coordinate of mouse during drag start
|
||||||
*/
|
*/
|
||||||
void scrollbar_start_content_drag(struct scrollbar *s, int x, int y);
|
void scrollbar_start_content_drag(struct scrollbar *s, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect a horizontal and a vertical scrollbar into a pair so that they
|
* Connect a horizontal and a vertical scrollbar into a pair so that they
|
||||||
* co-operate during 2D drags.
|
* co-operate during 2D drags.
|
||||||
@ -220,11 +237,12 @@ void scrollbar_start_content_drag(struct scrollbar *s, int x, int y);
|
|||||||
void scrollbar_make_pair(struct scrollbar *horizontal,
|
void scrollbar_make_pair(struct scrollbar *horizontal,
|
||||||
struct scrollbar *vertical);
|
struct scrollbar *vertical);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scrollbar's client data
|
* Get the scrollbar's client data
|
||||||
*
|
*
|
||||||
* \param s the scrollbar to get the client data from
|
* \param s the scrollbar to get the client data from
|
||||||
* \return client data
|
* \return client data
|
||||||
*/
|
*/
|
||||||
void *scrollbar_get_data(struct scrollbar *s);
|
void *scrollbar_get_data(struct scrollbar *s);
|
||||||
|
|
||||||
|
@ -2392,19 +2392,21 @@ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale,
|
|||||||
|
|
||||||
ctx->plot->clip(ctx, clip);
|
ctx->plot->clip(ctx, clip);
|
||||||
|
|
||||||
if (ta->bar_x != NULL)
|
if (ta->bar_x != NULL) {
|
||||||
scrollbar_redraw(ta->bar_x,
|
scrollbar_redraw(ta->bar_x,
|
||||||
x / scale + ta->border_width,
|
x / scale + ta->border_width,
|
||||||
y / scale + ta->vis_height - ta->border_width -
|
y / scale + ta->vis_height - ta->border_width -
|
||||||
SCROLLBAR_WIDTH,
|
SCROLLBAR_WIDTH,
|
||||||
clip, scale, ctx);
|
clip, scale, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
if (ta->bar_y != NULL)
|
if (ta->bar_y != NULL) {
|
||||||
scrollbar_redraw(ta->bar_y,
|
scrollbar_redraw(ta->bar_y,
|
||||||
x / scale + ta->vis_width - ta->border_width -
|
x / scale + ta->vis_width - ta->border_width -
|
||||||
SCROLLBAR_WIDTH,
|
SCROLLBAR_WIDTH,
|
||||||
y / scale + ta->border_width,
|
y / scale + ta->border_width,
|
||||||
clip, scale, ctx);
|
clip, scale, ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1298,11 +1298,13 @@ bool form_redraw_select_menu(struct form_control *control, int x, int y,
|
|||||||
option = option->next;
|
option = option->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scrollbar_redraw(menu->scrollbar,
|
res = scrollbar_redraw(menu->scrollbar,
|
||||||
x_cp + menu->width - SCROLLBAR_WIDTH,
|
x_cp + menu->width - SCROLLBAR_WIDTH,
|
||||||
y_cp,
|
y_cp,
|
||||||
clip, scale, ctx))
|
clip, scale, ctx);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user