2011-05-10 02:49:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2004-2008 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
* Copyright 2008 Michael Drake <tlsa@netsurf-browser.org>
|
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* implementation of scrollbar widget.
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-10-17 15:21:06 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2020-04-07 23:10:30 +03:00
|
|
|
#include "utils/nscolour.h"
|
2014-10-17 15:21:06 +04:00
|
|
|
#include "utils/nsoption.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-01-13 13:01:25 +03:00
|
|
|
#include "desktop/system_colour.h"
|
|
|
|
#include "desktop/scrollbar.h"
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
/**
|
|
|
|
* Scrollbar context
|
|
|
|
*/
|
2011-05-10 02:49:17 +04:00
|
|
|
struct scrollbar {
|
2017-02-11 16:54:08 +03:00
|
|
|
/** Horizontal scrollbar if true, else vertical */
|
|
|
|
bool horizontal;
|
|
|
|
/** Length of the scrollbar widget */
|
|
|
|
int length;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
/** 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;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
/** Parpendicular scrollbar, or NULL */
|
|
|
|
struct scrollbar *pair;
|
|
|
|
/** Flag indicating that the current drag affects the
|
|
|
|
* perpendicular scrollbar too
|
|
|
|
*/
|
|
|
|
bool pair_drag;
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in desktop/scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2017-03-02 02:30:29 +03:00
|
|
|
nserror
|
|
|
|
scrollbar_create(bool horizontal,
|
|
|
|
int length,
|
|
|
|
int full_size,
|
|
|
|
int visible_size,
|
|
|
|
void *client_data,
|
|
|
|
scrollbar_client_callback client_callback,
|
|
|
|
struct scrollbar **s)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
struct scrollbar *scrollbar;
|
|
|
|
int well_length;
|
|
|
|
|
|
|
|
scrollbar = malloc(sizeof(struct scrollbar));
|
|
|
|
if (scrollbar == NULL) {
|
2011-05-10 21:17:03 +04:00
|
|
|
*s = NULL;
|
2016-04-26 14:14:56 +03:00
|
|
|
return NSERROR_NOMEM;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
scrollbar->horizontal = horizontal;
|
|
|
|
scrollbar->length = length;
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar->full_size = full_size;
|
|
|
|
scrollbar->visible_size = visible_size;
|
2011-05-10 18:29:10 +04:00
|
|
|
scrollbar->offset = 0;
|
|
|
|
scrollbar->bar_pos = 0;
|
2011-05-10 02:49:17 +04:00
|
|
|
scrollbar->pair = NULL;
|
|
|
|
scrollbar->pair_drag = false;
|
|
|
|
|
|
|
|
well_length = length - 2 * SCROLLBAR_WIDTH;
|
2011-08-27 13:13:23 +04:00
|
|
|
scrollbar->bar_len = (full_size == 0) ? 0 :
|
2017-03-02 02:30:29 +03:00
|
|
|
((well_length * visible_size) / full_size);
|
2011-05-10 02:49:17 +04:00
|
|
|
|
|
|
|
scrollbar->client_callback = client_callback;
|
|
|
|
scrollbar->client_data = client_data;
|
|
|
|
|
|
|
|
scrollbar->dragging = false;
|
2011-05-11 12:34:33 +04:00
|
|
|
scrollbar->drag_content = false;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
*s = scrollbar;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2016-04-26 14:14:56 +03:00
|
|
|
return NSERROR_OK;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_destroy(struct scrollbar *s)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->pair != NULL) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->pair->pair = NULL;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
free(s);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-02-11 16:54:08 +03:00
|
|
|
* Draw an outline rectangle common to several scrollbar elements.
|
2011-05-10 02:49:17 +04:00
|
|
|
*
|
2017-02-19 14:32:17 +03:00
|
|
|
* \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
|
2017-02-11 16:54:08 +03:00
|
|
|
* lightening or darkening this one
|
2011-05-10 02:49:17 +04:00
|
|
|
* \param inset true for inset outline, false for an outset one
|
2017-02-19 14:32:17 +03:00
|
|
|
* \return NSERROR_OK on success else error code
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2017-02-11 16:54:08 +03:00
|
|
|
static inline nserror
|
|
|
|
scrollbar_rectangle(const struct redraw_context *ctx,
|
|
|
|
struct rect *area,
|
|
|
|
colour c,
|
|
|
|
bool inset)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2017-02-11 16:54:08 +03:00
|
|
|
struct rect line;
|
|
|
|
nserror res;
|
2011-06-30 19:48:07 +04:00
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
static plot_style_t c0 = {
|
|
|
|
.stroke_type = PLOT_OP_TYPE_SOLID,
|
2018-05-23 15:04:19 +03:00
|
|
|
.stroke_width = plot_style_int_to_fixed(1),
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static plot_style_t c1 = {
|
|
|
|
.stroke_type = PLOT_OP_TYPE_SOLID,
|
2018-05-23 15:04:19 +03:00
|
|
|
.stroke_width = plot_style_int_to_fixed(1),
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static plot_style_t c2 = {
|
|
|
|
.stroke_type = PLOT_OP_TYPE_SOLID,
|
2018-05-23 15:04:19 +03:00
|
|
|
.stroke_width = plot_style_int_to_fixed(1),
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (inset) {
|
|
|
|
c0.stroke_colour = darken_colour(c);
|
|
|
|
c1.stroke_colour = lighten_colour(c);
|
|
|
|
} else {
|
|
|
|
c0.stroke_colour = lighten_colour(c);
|
|
|
|
c1.stroke_colour = darken_colour(c);
|
|
|
|
}
|
|
|
|
c2.stroke_colour = blend_colour(c0.stroke_colour, c1.stroke_colour);
|
|
|
|
|
|
|
|
/* Plot the outline */
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
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;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2017-03-02 02:30:29 +03:00
|
|
|
nserror
|
|
|
|
scrollbar_redraw(struct scrollbar *s,
|
|
|
|
int x, int y,
|
|
|
|
const struct rect *clip,
|
|
|
|
float scale,
|
|
|
|
const struct redraw_context *ctx)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
int w = SCROLLBAR_WIDTH;
|
2011-05-17 13:05:49 +04:00
|
|
|
int bar_pos, bar_c0, bar_c1;
|
2011-05-10 02:49:17 +04:00
|
|
|
int v[6]; /* array of triangle vertices */
|
2017-02-11 16:54:08 +03:00
|
|
|
struct rect area;
|
|
|
|
struct rect rect;
|
|
|
|
nserror res;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2012-03-25 22:53:34 +04:00
|
|
|
plot_style_t bg_fill_style = {
|
2011-05-10 02:49:17 +04:00
|
|
|
.fill_type = PLOT_OP_TYPE_SOLID,
|
2020-04-07 23:10:30 +03:00
|
|
|
.fill_colour = nscolours[NSCOLOUR_SCROLL_WELL],
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
2012-03-25 22:53:34 +04:00
|
|
|
plot_style_t fg_fill_style = {
|
2011-05-10 02:49:17 +04:00
|
|
|
.fill_type = PLOT_OP_TYPE_SOLID,
|
2020-04-07 23:10:30 +03:00
|
|
|
.fill_colour = nscolours[NSCOLOUR_BUTTON_BG],
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
2012-03-25 22:53:34 +04:00
|
|
|
plot_style_t arrow_fill_style = {
|
2011-05-10 02:49:17 +04:00
|
|
|
.fill_type = PLOT_OP_TYPE_SOLID,
|
2020-04-07 23:10:30 +03:00
|
|
|
.fill_colour = nscolours[NSCOLOUR_BUTTON_FG],
|
2011-05-10 02:49:17 +04:00
|
|
|
};
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
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;
|
2011-05-10 21:17:03 +04:00
|
|
|
bar_pos = s->bar_pos;
|
2017-02-11 16:54:08 +03:00
|
|
|
bar_c1 = (s->horizontal ? area.x0 : area.y0) + SCROLLBAR_WIDTH +
|
2017-03-02 02:30:29 +03:00
|
|
|
s->bar_pos + s->bar_len - 1;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
|
|
|
if (scale != 1.0) {
|
|
|
|
w *= scale;
|
2017-02-11 16:54:08 +03:00
|
|
|
area.x0 *= scale;
|
|
|
|
area.y0 *= scale;
|
|
|
|
area.x1 *= scale;
|
|
|
|
area.y1 *= scale;
|
2011-05-10 18:29:10 +04:00
|
|
|
bar_pos *= scale;
|
2011-05-10 02:49:17 +04:00
|
|
|
bar_c1 *= scale;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
bar_c0 = (s->horizontal ? area.x0 : area.y0) + w + bar_pos;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
/* 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)) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return NSERROR_OK;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
if (s->horizontal) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar is horizontal */
|
2017-02-11 16:54:08 +03:00
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar outline */
|
2017-03-01 15:50:30 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &area,
|
|
|
|
bg_fill_style.fill_colour, true);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* left arrow icon border */
|
2017-02-11 16:54:08 +03:00
|
|
|
rect.x0 = area.x0 + 1;
|
|
|
|
rect.y0 = area.y0 + 1;
|
|
|
|
rect.x1 = area.x0 + w - 2;
|
|
|
|
rect.y1 = area.y1 - 1;
|
2017-03-01 15:50:30 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* left arrow icon background */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* left arrow */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar well background */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar position indicator bar */
|
2017-02-11 16:54:08 +03:00
|
|
|
rect.x0 = bar_c0;
|
|
|
|
rect.y0 = area.y0 + 1;
|
|
|
|
rect.x1 = bar_c1;
|
|
|
|
rect.y1 = area.y1 - 1;
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* right arrow icon border */
|
2017-02-11 16:54:08 +03:00
|
|
|
rect.x0 = area.x1 - w + 2;
|
|
|
|
rect.y0 = area.y0 + 1;
|
|
|
|
rect.x1 = area.x1 - 1;
|
|
|
|
rect.y1 = area.y1 - 1;
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* right arrow icon background */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* right arrow */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
} else {
|
|
|
|
/* scrollbar is vertical */
|
2017-02-11 16:54:08 +03:00
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* outline */
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &area,
|
|
|
|
bg_fill_style.fill_colour, true);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* top arrow border */
|
|
|
|
rect.x0 = area.x0 + 1;
|
|
|
|
rect.y0 = area.y0 + 1;
|
|
|
|
rect.x1 = area.x1 - 1;
|
|
|
|
rect.y1 = area.y0 + w - 2;
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* up arrow */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar well background */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar position indicator bar */
|
2017-02-11 16:54:08 +03:00
|
|
|
rect.x0 = area.x0 + 1;
|
|
|
|
rect.y0 = bar_c0;
|
|
|
|
rect.x1 = area.x1 - 1;
|
|
|
|
rect.y1 = bar_c1;
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
2017-03-02 02:30:29 +03:00
|
|
|
res = scrollbar_rectangle(ctx, &rect,
|
|
|
|
fg_fill_style.fill_colour, false);
|
2017-02-11 16:54:08 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
/* down arrow */
|
2017-02-11 16:54:08 +03:00
|
|
|
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) {
|
2017-03-02 02:30:29 +03:00
|
|
|
return res;
|
2017-02-11 16:54:08 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
return NSERROR_OK;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_set(struct scrollbar *s, int value, bool bar_pos)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
int well_length;
|
2011-08-31 17:04:50 +04:00
|
|
|
int old_offset = s->offset;
|
2011-05-10 02:49:17 +04:00
|
|
|
struct scrollbar_msg_data msg;
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (value < 0) {
|
2011-05-10 21:17:03 +04:00
|
|
|
value = 0;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->full_size == s->visible_size) {
|
2011-05-10 02:49:17 +04:00
|
|
|
return;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
2011-05-10 02:49:17 +04:00
|
|
|
if (bar_pos) {
|
2017-03-02 02:30:29 +03:00
|
|
|
if (value > well_length - s->bar_len) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->bar_pos = well_length - s->bar_len;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->bar_pos = value;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-08-30 22:13:23 +04:00
|
|
|
s->offset = ((well_length - s->bar_len) < 1) ? 0 :
|
2017-03-02 02:30:29 +03:00
|
|
|
(((s->full_size - s->visible_size) *
|
|
|
|
s->bar_pos) / (well_length - s->bar_len));
|
2011-05-10 02:49:17 +04:00
|
|
|
|
|
|
|
} else {
|
2017-03-02 02:30:29 +03:00
|
|
|
if (value > s->full_size - s->visible_size) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->offset = s->full_size - s->visible_size;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->offset = value;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-08-30 22:13:23 +04:00
|
|
|
s->bar_pos = (s->full_size < 1) ? 0 :
|
2017-03-02 02:30:29 +03:00
|
|
|
((well_length * s->offset) / s->full_size);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
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);
|
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-29 18:16:26 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-11-29 18:16:26 +04:00
|
|
|
*/
|
|
|
|
bool scrollbar_scroll(struct scrollbar *s, int change)
|
|
|
|
{
|
|
|
|
int well_length;
|
|
|
|
int old_offset = s->offset;
|
|
|
|
struct scrollbar_msg_data msg;
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (change == 0 || s->full_size <= s->visible_size) {
|
2011-11-29 18:16:26 +04:00
|
|
|
/* zero scroll step, or unscrollable */
|
|
|
|
return false;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-11-29 18:16:26 +04:00
|
|
|
|
2011-12-18 19:36:38 +04:00
|
|
|
/* Convert named change values to appropriate pixel offset value */
|
|
|
|
switch (change) {
|
|
|
|
case SCROLL_TOP:
|
|
|
|
change = -s->full_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCROLL_PAGE_UP:
|
|
|
|
change = -s->visible_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCROLL_PAGE_DOWN:
|
|
|
|
change = s->visible_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCROLL_BOTTOM:
|
|
|
|
change = s->full_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Change value is already a pixel offset */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get new offset */
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->offset + change > s->full_size - s->visible_size) {
|
2011-11-29 18:16:26 +04:00
|
|
|
s->offset = s->full_size - s->visible_size;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else if (s->offset + change < 0) {
|
2011-11-29 18:16:26 +04:00
|
|
|
s->offset = 0;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else {
|
2011-11-29 18:16:26 +04:00
|
|
|
s->offset += change;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-11-29 18:16:26 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->offset == old_offset) {
|
2011-11-29 18:16:26 +04:00
|
|
|
/* Nothing happened */
|
|
|
|
return false;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-11-29 18:16:26 +04:00
|
|
|
|
2011-12-18 19:36:38 +04:00
|
|
|
/* Update scrollbar */
|
2011-11-29 18:16:26 +04:00
|
|
|
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
|
|
|
s->bar_pos = (s->full_size < 1) ? 0 :
|
2017-03-02 02:30:29 +03:00
|
|
|
((well_length * s->offset) / s->full_size);
|
2011-11-29 18:16:26 +04:00
|
|
|
|
|
|
|
msg.scrollbar = s;
|
|
|
|
msg.msg = SCROLLBAR_MSG_MOVED;
|
|
|
|
msg.scroll_offset = s->offset;
|
|
|
|
s->client_callback(s->client_data, &msg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
int scrollbar_get_offset(struct scrollbar *s)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s == NULL) {
|
2011-05-10 02:49:17 +04:00
|
|
|
return 0;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
return s->offset;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_set_extents(struct scrollbar *s, int length,
|
2017-03-02 02:30:29 +03:00
|
|
|
int visible_size, int full_size)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2011-08-25 13:21:41 +04:00
|
|
|
int cur_excess = s->full_size - s->visible_size;
|
2014-09-19 15:33:34 +04:00
|
|
|
int well_length;
|
|
|
|
struct scrollbar_msg_data msg;
|
2011-05-10 18:29:10 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (length == s->length &&
|
|
|
|
visible_size == s->visible_size &&
|
|
|
|
full_size == s->full_size) {
|
2014-09-19 15:39:02 +04:00
|
|
|
/* Nothing's changed. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (length != -1) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->length = length;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
if (visible_size != -1) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->visible_size = visible_size;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
if (full_size != -1) {
|
2011-05-10 21:17:03 +04:00
|
|
|
s->full_size = full_size;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->full_size < s->visible_size) {
|
2011-08-27 13:13:23 +04:00
|
|
|
s->full_size = s->visible_size;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-08-27 13:13:23 +04:00
|
|
|
|
2011-08-25 13:21:41 +04:00
|
|
|
/* Update scroll offset (scaled in proportion with change in excess) */
|
2014-09-19 15:32:52 +04:00
|
|
|
if (cur_excess <= 0) {
|
|
|
|
s->offset = 0;
|
|
|
|
} else {
|
|
|
|
s->offset = (full_size - visible_size) * s->offset / cur_excess;
|
|
|
|
}
|
2011-08-25 13:21:41 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
well_length = s->length - 2 * SCROLLBAR_WIDTH;
|
|
|
|
|
2011-08-30 22:13:23 +04:00
|
|
|
if (s->full_size < 1) {
|
|
|
|
s->bar_len = well_length;
|
|
|
|
s->bar_pos = 0;
|
|
|
|
} else {
|
|
|
|
s->bar_len = (well_length * s->visible_size) / s->full_size;
|
|
|
|
s->bar_pos = (well_length * s->offset) / s->full_size;
|
|
|
|
}
|
2014-09-19 15:33:34 +04:00
|
|
|
|
|
|
|
msg.scrollbar = s;
|
|
|
|
msg.msg = SCROLLBAR_MSG_MOVED;
|
|
|
|
msg.scroll_offset = s->offset;
|
|
|
|
s->client_callback(s->client_data, &msg);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
bool scrollbar_is_horizontal(struct scrollbar *s)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2011-05-10 21:17:03 +04:00
|
|
|
return s->horizontal;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal procedure used for starting a drag scroll for a scrollbar.
|
|
|
|
*
|
2011-05-10 21:17:03 +04:00
|
|
|
* \param s the scrollbar to start the drag for
|
2011-05-10 02:49:17 +04:00
|
|
|
* \param x the X coordinate of the drag start
|
|
|
|
* \param y the Y coordinate of the drag start
|
2011-05-11 12:34:33 +04:00
|
|
|
* \param content_drag whether this should be a reverse drag (used when the
|
2017-02-11 16:54:08 +03:00
|
|
|
* user drags the content area, rather than the scrollbar)
|
2011-05-10 02:49:17 +04:00
|
|
|
* \param pair whether the drag is a '2D' scroll
|
|
|
|
*/
|
2017-03-02 02:30:29 +03:00
|
|
|
static void
|
|
|
|
scrollbar_drag_start_internal(struct scrollbar *s,
|
|
|
|
int x, int y,
|
|
|
|
bool content_drag,
|
|
|
|
bool pair)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
struct scrollbar_msg_data msg;
|
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->drag_start_coord = s->horizontal ? x : y;
|
2011-05-11 12:34:33 +04:00
|
|
|
s->drag_start_pos = (content_drag) ? s->offset : s->bar_pos;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->dragging = true;
|
2011-05-11 12:34:33 +04:00
|
|
|
s->drag_content = content_drag;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
msg.scrollbar = s;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
/** \todo some proper numbers please! */
|
2011-05-10 21:17:03 +04:00
|
|
|
if (s->horizontal) {
|
2011-05-11 14:36:15 +04:00
|
|
|
msg.x0 = -2048;
|
|
|
|
msg.x1 = 2048;
|
2011-05-10 02:49:17 +04:00
|
|
|
msg.y0 = 0;
|
|
|
|
msg.y1 = 0;
|
|
|
|
} else {
|
|
|
|
msg.x0 = 0;
|
|
|
|
msg.x1 = 0;
|
2011-05-11 14:36:15 +04:00
|
|
|
msg.y0 = -2048;
|
|
|
|
msg.y1 = 2048;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
if (pair && s->pair != NULL) {
|
|
|
|
s->pair_drag = true;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->pair->drag_start_coord =
|
2017-03-02 02:30:29 +03:00
|
|
|
s->pair->horizontal ? x : y;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-11 12:34:33 +04:00
|
|
|
s->pair->drag_start_pos = (content_drag) ? s->pair->offset :
|
2017-03-02 02:30:29 +03:00
|
|
|
s->pair->bar_pos;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->pair->dragging = true;
|
2011-05-11 12:34:33 +04:00
|
|
|
s->pair->drag_content = content_drag;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
if (s->pair->horizontal) {
|
2011-05-11 14:36:15 +04:00
|
|
|
msg.x0 = -2048;
|
|
|
|
msg.x1 = 2048;
|
2011-05-10 02:49:17 +04:00
|
|
|
} else {
|
2011-05-11 14:36:15 +04:00
|
|
|
msg.y0 = -2048;
|
|
|
|
msg.y1 = 2048;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
msg.msg = SCROLLBAR_MSG_SCROLL_START;
|
2011-05-10 21:17:03 +04:00
|
|
|
s->client_callback(s->client_data, &msg);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2017-03-02 02:30:29 +03:00
|
|
|
scrollbar_mouse_status
|
|
|
|
scrollbar_mouse_action(struct scrollbar *s,
|
|
|
|
browser_mouse_state mouse,
|
|
|
|
int x, int y)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
int x0, y0, x1, y1;
|
|
|
|
int val;
|
2013-03-11 16:57:33 +04:00
|
|
|
scrollbar_mouse_status status = SCROLLBAR_MOUSE_NONE;
|
2011-05-10 02:49:17 +04:00
|
|
|
bool h;
|
|
|
|
|
|
|
|
/* we want mouse presses and mouse drags that were not started at the
|
|
|
|
* scrollbar indication bar to be launching actions on the scroll area
|
|
|
|
*/
|
|
|
|
bool but1 = ((mouse & BROWSER_MOUSE_PRESS_1) ||
|
2017-03-02 02:30:29 +03:00
|
|
|
((mouse & BROWSER_MOUSE_HOLDING_1) &&
|
|
|
|
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
|
|
|
!s->dragging));
|
2011-05-10 02:49:17 +04:00
|
|
|
bool but2 = ((mouse & BROWSER_MOUSE_PRESS_2) ||
|
2017-03-02 02:30:29 +03:00
|
|
|
((mouse & BROWSER_MOUSE_HOLDING_2) &&
|
|
|
|
(mouse & BROWSER_MOUSE_DRAG_ON) &&
|
|
|
|
!s->dragging));
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
h = s->horizontal;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
|
|
|
x0 = 0;
|
|
|
|
y0 = 0;
|
2011-05-10 21:17:03 +04:00
|
|
|
x1 = h ? s->length : SCROLLBAR_WIDTH;
|
|
|
|
y1 = h ? SCROLLBAR_WIDTH : s->length;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
if (!s->dragging && !(x >= x0 && x <= x1 && y >= y0 && y <= y1)) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* Not a drag and mouse outside scrollbar widget */
|
2013-03-11 16:57:33 +04:00
|
|
|
return SCROLLBAR_MOUSE_NONE;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (h) {
|
2011-05-10 02:49:17 +04:00
|
|
|
val = x;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else {
|
2011-05-10 02:49:17 +04:00
|
|
|
val = y;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
if (s->dragging) {
|
|
|
|
val -= s->drag_start_coord;
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->drag_content) {
|
2011-05-10 02:49:17 +04:00
|
|
|
val = -val;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
if (val != 0) {
|
2011-05-11 12:34:33 +04:00
|
|
|
scrollbar_set(s, s->drag_start_pos + val,
|
2017-03-02 02:30:29 +03:00
|
|
|
!(s->drag_content));
|
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
if (s->pair_drag) {
|
|
|
|
scrollbar_mouse_action(s->pair, mouse, x, y);
|
2013-03-11 16:57:33 +04:00
|
|
|
status = SCROLLBAR_MOUSE_BOTH;
|
2017-03-02 02:30:29 +03:00
|
|
|
} else {
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val < SCROLLBAR_WIDTH) {
|
|
|
|
/* left/up arrow */
|
2017-02-11 16:54:08 +03:00
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_LFT : SCROLLBAR_MOUSE_UP;
|
2017-03-02 02:30:29 +03:00
|
|
|
if (but1) {
|
2011-08-25 22:29:21 +04:00
|
|
|
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
} else if (but2) {
|
2011-08-25 22:29:21 +04:00
|
|
|
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
} else if (val < SCROLLBAR_WIDTH + s->bar_pos) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* well between left/up arrow and bar */
|
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_PLFT : SCROLLBAR_MOUSE_PUP;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (but1) {
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_set(s, s->offset - s->length, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
} else if (but2) {
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_set(s, s->offset + s->length, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
} else if (val > s->length - SCROLLBAR_WIDTH) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* right/down arrow */
|
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_RGT : SCROLLBAR_MOUSE_DWN;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (but1) {
|
2011-08-25 22:29:21 +04:00
|
|
|
scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
} else if (but2) {
|
2011-08-25 22:29:21 +04:00
|
|
|
scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
} else if (val > SCROLLBAR_WIDTH + s->bar_pos + s->bar_len) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* well between right/down arrow and bar */
|
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_PRGT : SCROLLBAR_MOUSE_PDWN;
|
2017-03-02 02:30:29 +03:00
|
|
|
if (but1) {
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_set(s, s->offset + s->length, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
} else if (but2) {
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_set(s, s->offset - s->length, false);
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
} else {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* scrollbar position indication bar */
|
2017-02-11 16:54:08 +03:00
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
status = h ? SCROLLBAR_MOUSE_HRZ : SCROLLBAR_MOUSE_VRT;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
|
2011-05-10 02:49:17 +04:00
|
|
|
if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2) &&
|
2017-03-02 02:30:29 +03:00
|
|
|
(val >= SCROLLBAR_WIDTH + s->bar_pos
|
|
|
|
&& val < SCROLLBAR_WIDTH + s->bar_pos +
|
|
|
|
s->bar_len)) {
|
2011-05-10 02:49:17 +04:00
|
|
|
/* The mouse event is a drag start on the scrollbar position
|
|
|
|
* indication bar. */
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_drag_start_internal(s, x, y, false,
|
2017-03-02 02:30:29 +03:00
|
|
|
(mouse & BROWSER_MOUSE_DRAG_2) ? true : false);
|
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 16:57:33 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2013-03-11 16:57:33 +04:00
|
|
|
*/
|
|
|
|
const char *scrollbar_mouse_status_to_message(scrollbar_mouse_status status)
|
|
|
|
{
|
|
|
|
switch ((unsigned int) status) {
|
|
|
|
case SCROLLBAR_MOUSE_UP:
|
|
|
|
case SCROLLBAR_MOUSE_UP | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollUp");
|
|
|
|
case SCROLLBAR_MOUSE_PUP:
|
|
|
|
case SCROLLBAR_MOUSE_PUP | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollPUp");
|
|
|
|
case SCROLLBAR_MOUSE_VRT:
|
|
|
|
case SCROLLBAR_MOUSE_VRT | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollV");
|
|
|
|
case SCROLLBAR_MOUSE_PDWN:
|
|
|
|
case SCROLLBAR_MOUSE_PDWN | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollPDown");
|
|
|
|
case SCROLLBAR_MOUSE_DWN:
|
|
|
|
case SCROLLBAR_MOUSE_DWN | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollDown");
|
|
|
|
case SCROLLBAR_MOUSE_LFT:
|
|
|
|
case SCROLLBAR_MOUSE_LFT | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollLeft");
|
|
|
|
case SCROLLBAR_MOUSE_PLFT:
|
|
|
|
case SCROLLBAR_MOUSE_PLFT | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollPLeft");
|
|
|
|
case SCROLLBAR_MOUSE_HRZ:
|
|
|
|
case SCROLLBAR_MOUSE_HRZ | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollH");
|
|
|
|
case SCROLLBAR_MOUSE_PRGT:
|
|
|
|
case SCROLLBAR_MOUSE_PRGT | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollPRight");
|
|
|
|
case SCROLLBAR_MOUSE_RGT:
|
|
|
|
case SCROLLBAR_MOUSE_RGT | SCROLLBAR_MOUSE_USED:
|
|
|
|
return messages_get("ScrollRight");
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_mouse_drag_end(struct scrollbar *s,
|
2017-03-02 02:30:29 +03:00
|
|
|
browser_mouse_state mouse, int x, int y)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
|
|
|
struct scrollbar_msg_data msg;
|
2011-05-10 21:17:03 +04:00
|
|
|
int val, drag_start_pos;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
assert(s->dragging);
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-11 12:34:33 +04:00
|
|
|
drag_start_pos = s->drag_start_pos;
|
2011-05-10 21:17:03 +04:00
|
|
|
val = (s->horizontal ? x : y) - s->drag_start_coord;
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->drag_content) {
|
2011-05-10 02:49:17 +04:00
|
|
|
val = -val;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
if (val != 0) {
|
2011-05-11 12:34:33 +04:00
|
|
|
scrollbar_set(s, drag_start_pos + val, !(s->drag_content));
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->dragging = false;
|
2011-05-11 12:34:33 +04:00
|
|
|
s->drag_content = false;
|
2011-05-10 21:17:03 +04:00
|
|
|
|
|
|
|
if (s->pair_drag) {
|
|
|
|
s->pair_drag = false;
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-11 12:34:33 +04:00
|
|
|
drag_start_pos = s->pair->drag_start_pos;
|
2011-05-10 21:17:03 +04:00
|
|
|
val = (s->pair->horizontal ? x : y) - s->pair->drag_start_coord;
|
|
|
|
|
2017-03-02 02:30:29 +03:00
|
|
|
if (s->pair->drag_content) {
|
2011-05-10 02:49:17 +04:00
|
|
|
val = -val;
|
2017-03-02 02:30:29 +03:00
|
|
|
}
|
|
|
|
if (val != 0) {
|
2011-05-11 12:34:33 +04:00
|
|
|
scrollbar_set(s->pair, drag_start_pos + val,
|
2017-03-02 02:30:29 +03:00
|
|
|
!(s->pair->drag_content));
|
|
|
|
}
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
s->pair->dragging = false;
|
2011-05-11 12:34:33 +04:00
|
|
|
s->pair->drag_content = false;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
2011-05-10 21:17:03 +04:00
|
|
|
|
|
|
|
msg.scrollbar = s;
|
2011-05-10 02:49:17 +04:00
|
|
|
msg.msg = SCROLLBAR_MSG_SCROLL_FINISHED;
|
2011-05-10 21:17:03 +04:00
|
|
|
s->client_callback(s->client_data, &msg);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_start_content_drag(struct scrollbar *s, int x, int y)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2011-05-10 21:17:03 +04:00
|
|
|
scrollbar_drag_start_internal(s, x, y, true, true);
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 02:49:17 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void scrollbar_make_pair(struct scrollbar *horizontal,
|
2017-03-02 02:30:29 +03:00
|
|
|
struct scrollbar *vertical)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2011-05-10 21:17:03 +04:00
|
|
|
assert(horizontal->horizontal &&
|
2017-03-02 02:30:29 +03:00
|
|
|
!vertical->horizontal);
|
2011-05-10 02:49:17 +04:00
|
|
|
|
2011-05-10 21:17:03 +04:00
|
|
|
horizontal->pair = vertical;
|
|
|
|
vertical->pair = horizontal;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 21:30:46 +04:00
|
|
|
/*
|
2017-03-02 02:30:29 +03:00
|
|
|
* Exported interface. Documented in scrollbar.h
|
2011-05-10 21:30:46 +04:00
|
|
|
*/
|
2011-05-10 21:17:03 +04:00
|
|
|
void *scrollbar_get_data(struct scrollbar *s)
|
2011-05-10 02:49:17 +04:00
|
|
|
{
|
2011-05-10 21:17:03 +04:00
|
|
|
return s->client_data;
|
2011-05-10 02:49:17 +04:00
|
|
|
}
|