HelenOS sources
This source file includes following definitions.
- ui_scrollbar_create
- ui_scrollbar_destroy
- ui_scrollbar_ctl
- ui_scrollbar_set_cb
- ui_scrollbar_set_rect
- ui_scrollbar_paint_thumb_frame
- ui_scrollbar_paint_outset
- ui_scrollbar_trough_length
- ui_scrollbar_move_length
- ui_scrollbar_set_thumb_length
- ui_scrollbar_get_pos
- ui_scrollbar_set_pos
- ui_scrollbar_paint_gfx
- ui_scrollbar_paint_text
- ui_scrollbar_paint
- ui_scrollbar_get_geom
- ui_scrollbar_thumb_press
- ui_scrollbar_upper_trough_press
- ui_scrollbar_lower_trough_press
- ui_scrollbar_release
- ui_scrollbar_troughs_update
- ui_scrollbar_update
- ui_scrollbar_up
- ui_scrollbar_down
- ui_scrollbar_page_up
- ui_scrollbar_page_down
- ui_scrollbar_moved
- ui_scrollbar_pos_event
- ui_scrollbar_up_btn_down
- ui_scrollbar_up_btn_up
- ui_scrollbar_up_btn_decor_paint
- ui_scrollbar_down_btn_decor_paint
- ui_scrollbar_down_btn_down
- ui_scrollbar_down_btn_up
- ui_scrollbar_ctl_destroy
- ui_scrollbar_ctl_paint
- ui_scrollbar_ctl_pos_event
- ui_scrollbar_cm_up
- ui_scrollbar_cm_down
- ui_scrollbar_cm_page_up
- ui_scrollbar_cm_page_down
#include <errno.h>
#include <gfx/color.h>
#include <gfx/context.h>
#include <gfx/render.h>
#include <gfx/text.h>
#include <io/pos_event.h>
#include <stdlib.h>
#include <str.h>
#include <ui/clickmatic.h>
#include <ui/control.h>
#include <ui/paint.h>
#include <ui/pbutton.h>
#include <ui/scrollbar.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/pbutton.h"
#include "../private/resource.h"
#include "../private/scrollbar.h"
enum {
ui_scrollbar_btn_len = 21,
ui_scrollbar_btn_len_text = 1,
ui_scrollbar_thumb_frame_thickness = 1,
ui_scrollbar_thumb_bevel_width = 2,
ui_scrollbar_def_thumb_len = 21,
ui_scrollbar_def_thumb_len_text = 1,
ui_scrollbar_min_thumb_len = 10,
ui_scrollbar_min_thumb_len_text = 1,
};
static void ui_scrollbar_up_btn_down(ui_pbutton_t *, void *);
static void ui_scrollbar_up_btn_up(ui_pbutton_t *, void *);
static errno_t ui_scrollbar_up_btn_decor_paint(ui_pbutton_t *, void *,
gfx_coord2_t *);
static errno_t ui_scrollbar_down_btn_decor_paint(ui_pbutton_t *, void *,
gfx_coord2_t *);
static void ui_scrollbar_down_btn_down(ui_pbutton_t *, void *);
static void ui_scrollbar_down_btn_up(ui_pbutton_t *, void *);
static void ui_scrollbar_ctl_destroy(void *);
static errno_t ui_scrollbar_ctl_paint(void *);
static ui_evclaim_t ui_scrollbar_ctl_pos_event(void *, pos_event_t *);
static ui_pbutton_cb_t ui_scrollbar_up_btn_cb = {
.down = ui_scrollbar_up_btn_down,
.up = ui_scrollbar_up_btn_up
};
static ui_pbutton_decor_ops_t ui_scrollbar_up_btn_decor_ops = {
.paint = ui_scrollbar_up_btn_decor_paint
};
static ui_pbutton_cb_t ui_scrollbar_down_btn_cb = {
.down = ui_scrollbar_down_btn_down,
.up = ui_scrollbar_down_btn_up
};
static ui_pbutton_decor_ops_t ui_scrollbar_down_btn_decor_ops = {
.paint = ui_scrollbar_down_btn_decor_paint
};
static ui_control_ops_t ui_scrollbar_ops = {
.destroy = ui_scrollbar_ctl_destroy,
.paint = ui_scrollbar_ctl_paint,
.pos_event = ui_scrollbar_ctl_pos_event
};
static void ui_scrollbar_cm_up(ui_clickmatic_t *, void *);
static void ui_scrollbar_cm_down(ui_clickmatic_t *, void *);
static void ui_scrollbar_cm_page_up(ui_clickmatic_t *, void *);
static void ui_scrollbar_cm_page_down(ui_clickmatic_t *, void *);
ui_clickmatic_cb_t ui_scrollbar_clickmatic_up_cb = {
.clicked = ui_scrollbar_cm_up
};
ui_clickmatic_cb_t ui_scrollbar_clickmatic_down_cb = {
.clicked = ui_scrollbar_cm_down
};
ui_clickmatic_cb_t ui_scrollbar_clickmatic_page_up_cb = {
.clicked = ui_scrollbar_cm_page_up
};
ui_clickmatic_cb_t ui_scrollbar_clickmatic_page_down_cb = {
.clicked = ui_scrollbar_cm_page_down
};
errno_t ui_scrollbar_create(ui_t *ui, ui_window_t *window,
ui_scrollbar_dir_t dir, ui_scrollbar_t **rscrollbar)
{
ui_scrollbar_t *scrollbar;
ui_resource_t *resource;
const char *up_text;
const char *down_text;
errno_t rc;
resource = ui_window_get_res(window);
scrollbar = calloc(1, sizeof(ui_scrollbar_t));
if (scrollbar == NULL)
return ENOMEM;
rc = ui_control_new(&ui_scrollbar_ops, (void *) scrollbar,
&scrollbar->control);
if (rc != EOK) {
free(scrollbar);
return rc;
}
if (dir == ui_sbd_horiz) {
up_text = resource->textmode ? "\u25c4" : "<";
down_text = resource->textmode ? "\u25ba" : ">";
} else {
up_text = resource->textmode ? "\u25b2" : "^";
down_text = resource->textmode ? "\u25bc" : "v";
}
rc = ui_pbutton_create(resource, up_text, &scrollbar->up_btn);
if (rc != EOK)
goto error;
ui_pbutton_set_cb(scrollbar->up_btn, &ui_scrollbar_up_btn_cb,
scrollbar);
ui_pbutton_set_decor_ops(scrollbar->up_btn,
&ui_scrollbar_up_btn_decor_ops, (void *) scrollbar);
ui_pbutton_set_flags(scrollbar->up_btn, ui_pbf_no_text_depress);
rc = ui_pbutton_create(resource, down_text, &scrollbar->down_btn);
if (rc != EOK)
goto error;
ui_pbutton_set_cb(scrollbar->down_btn, &ui_scrollbar_down_btn_cb,
(void *) scrollbar);
ui_pbutton_set_decor_ops(scrollbar->down_btn,
&ui_scrollbar_down_btn_decor_ops, (void *) scrollbar);
ui_pbutton_set_flags(scrollbar->down_btn, ui_pbf_no_text_depress);
scrollbar->thumb_len = resource->textmode ?
ui_scrollbar_def_thumb_len_text :
ui_scrollbar_def_thumb_len;
scrollbar->ui = ui;
scrollbar->window = window;
scrollbar->dir = dir;
*rscrollbar = scrollbar;
return EOK;
error:
ui_scrollbar_destroy(scrollbar);
return rc;
}
void ui_scrollbar_destroy(ui_scrollbar_t *scrollbar)
{
if (scrollbar == NULL)
return;
ui_pbutton_destroy(scrollbar->up_btn);
ui_pbutton_destroy(scrollbar->down_btn);
ui_control_delete(scrollbar->control);
free(scrollbar);
}
ui_control_t *ui_scrollbar_ctl(ui_scrollbar_t *scrollbar)
{
return scrollbar->control;
}
void ui_scrollbar_set_cb(ui_scrollbar_t *scrollbar, ui_scrollbar_cb_t *cb, void *arg)
{
scrollbar->cb = cb;
scrollbar->arg = arg;
}
void ui_scrollbar_set_rect(ui_scrollbar_t *scrollbar, gfx_rect_t *rect)
{
ui_scrollbar_geom_t geom;
scrollbar->rect = *rect;
ui_scrollbar_get_geom(scrollbar, &geom);
ui_pbutton_set_rect(scrollbar->up_btn, &geom.up_btn_rect);
ui_pbutton_set_rect(scrollbar->down_btn, &geom.down_btn_rect);
}
static errno_t ui_scrollbar_paint_thumb_frame(ui_resource_t *res, gfx_rect_t *rect,
gfx_coord_t thickness, gfx_rect_t *inside)
{
gfx_rect_t drect;
errno_t rc;
rc = gfx_set_color(res->gc, res->btn_frame_color);
if (rc != EOK)
goto error;
drect.p0.x = rect->p0.x + 1;
drect.p0.y = rect->p0.y;
drect.p1.x = rect->p1.x - 1;
drect.p1.y = rect->p0.y + thickness;
rc = gfx_fill_rect(res->gc, &drect);
if (rc != EOK)
goto error;
drect.p0.x = rect->p0.x + 1;
drect.p0.y = rect->p1.y - thickness;
drect.p1.x = rect->p1.x - 1;
drect.p1.y = rect->p1.y;
rc = gfx_fill_rect(res->gc, &drect);
if (rc != EOK)
goto error;
drect.p0.x = rect->p0.x;
drect.p0.y = rect->p0.y + 1;
drect.p1.x = rect->p0.x + thickness;
drect.p1.y = rect->p1.y - 1;
rc = gfx_fill_rect(res->gc, &drect);
if (rc != EOK)
goto error;
drect.p0.x = rect->p1.x - thickness;
drect.p0.y = rect->p0.y + 1;
drect.p1.x = rect->p1.x;
drect.p1.y = rect->p1.y - 1;
rc = gfx_fill_rect(res->gc, &drect);
if (rc != EOK)
goto error;
if (inside != NULL) {
inside->p0.x = rect->p0.x + thickness;
inside->p0.y = rect->p0.y + thickness;
inside->p1.x = rect->p1.x - thickness;
inside->p1.y = rect->p1.y - thickness;
}
return EOK;
error:
return rc;
}
static errno_t ui_scrollbar_paint_outset(ui_scrollbar_t *scrollbar,
gfx_rect_t *rect, gfx_rect_t *inside)
{
ui_resource_t *resource = ui_window_get_res(scrollbar->window);
return ui_paint_bevel(resource->gc, rect,
resource->btn_highlight_color,
resource->btn_shadow_color, ui_scrollbar_thumb_bevel_width, inside);
}
gfx_coord_t ui_scrollbar_trough_length(ui_scrollbar_t *scrollbar)
{
ui_resource_t *resource;
gfx_coord2_t dims;
gfx_coord_t len;
gfx_coord_t sblen;
resource = ui_window_get_res(scrollbar->window);
gfx_rect_dims(&scrollbar->rect, &dims);
sblen = scrollbar->dir == ui_sbd_horiz ?
dims.x : dims.y;
len = resource->textmode ? ui_scrollbar_btn_len_text :
ui_scrollbar_btn_len;
return sblen - 2 * len;
}
gfx_coord_t ui_scrollbar_move_length(ui_scrollbar_t *scrollbar)
{
return ui_scrollbar_trough_length(scrollbar) -
scrollbar->thumb_len;
}
void ui_scrollbar_set_thumb_length(ui_scrollbar_t *scrollbar, gfx_coord_t len)
{
ui_resource_t *resource;
gfx_coord_t min_len;
gfx_coord_t max_len;
resource = ui_window_get_res(scrollbar->window);
min_len = resource->textmode ?
ui_scrollbar_min_thumb_len_text :
ui_scrollbar_min_thumb_len;
max_len = ui_scrollbar_trough_length(scrollbar);
if (len < min_len)
len = min_len;
if (len > max_len)
len = max_len;
if (len != scrollbar->thumb_len) {
scrollbar->thumb_len = len;
(void) ui_scrollbar_paint(scrollbar);
}
}
gfx_coord_t ui_scrollbar_get_pos(ui_scrollbar_t *scrollbar)
{
return scrollbar->pos;
}
void ui_scrollbar_set_pos(ui_scrollbar_t *scrollbar, gfx_coord_t pos)
{
gfx_coord_t length;
length = ui_scrollbar_move_length(scrollbar);
if (pos < 0)
pos = 0;
if (pos > length)
pos = length;
if (pos != scrollbar->pos) {
scrollbar->pos = pos;
(void) ui_scrollbar_paint(scrollbar);
ui_scrollbar_troughs_update(scrollbar,
&scrollbar->last_curs_pos);
}
}
errno_t ui_scrollbar_paint_gfx(ui_scrollbar_t *scrollbar)
{
ui_resource_t *resource;
ui_scrollbar_geom_t geom;
gfx_rect_t brect;
gfx_rect_t irect;
errno_t rc;
resource = ui_window_get_res(scrollbar->window);
ui_scrollbar_get_geom(scrollbar, &geom);
rc = ui_paint_inset_frame(resource, &scrollbar->rect, NULL);
if (rc != EOK)
goto error;
rc = gfx_set_color(resource->gc,
scrollbar->upper_trough_held && scrollbar->upper_trough_inside ?
resource->sbar_act_trough_color :
resource->sbar_trough_color);
if (rc != EOK)
goto error;
rc = gfx_fill_rect(resource->gc, &geom.upper_trough_rect);
if (rc != EOK)
goto error;
rc = gfx_set_color(resource->gc,
scrollbar->lower_trough_held && scrollbar->lower_trough_inside ?
resource->sbar_act_trough_color :
resource->sbar_trough_color);
if (rc != EOK)
goto error;
rc = gfx_fill_rect(resource->gc, &geom.lower_trough_rect);
if (rc != EOK)
goto error;
rc = ui_scrollbar_paint_thumb_frame(resource, &geom.thumb_rect,
ui_scrollbar_thumb_frame_thickness, &brect);
if (rc != EOK)
goto error;
rc = ui_scrollbar_paint_outset(scrollbar, &brect, &irect);
if (rc != EOK)
goto error;
rc = gfx_set_color(resource->gc, resource->btn_face_color);
if (rc != EOK)
goto error;
rc = gfx_fill_rect(resource->gc, &irect);
if (rc != EOK)
goto error;
rc = ui_pbutton_paint(scrollbar->up_btn);
if (rc != EOK)
goto error;
rc = ui_pbutton_paint(scrollbar->down_btn);
if (rc != EOK)
goto error;
rc = gfx_update(resource->gc);
if (rc != EOK)
goto error;
return EOK;
error:
return rc;
}
errno_t ui_scrollbar_paint_text(ui_scrollbar_t *scrollbar)
{
ui_resource_t *resource;
ui_scrollbar_geom_t geom;
errno_t rc;
resource = ui_window_get_res(scrollbar->window);
ui_scrollbar_get_geom(scrollbar, &geom);
rc = ui_paint_text_rect(resource, &geom.trough_rect,
resource->sbar_trough_color, "\u2592");
if (rc != EOK)
goto error;
rc = ui_paint_text_rect(resource, &geom.thumb_rect,
resource->sbar_trough_color, "\u25a0");
if (rc != EOK)
goto error;
rc = ui_pbutton_paint(scrollbar->up_btn);
if (rc != EOK)
goto error;
rc = ui_pbutton_paint(scrollbar->down_btn);
if (rc != EOK)
goto error;
rc = gfx_update(resource->gc);
if (rc != EOK)
goto error;
return EOK;
error:
return rc;
}
errno_t ui_scrollbar_paint(ui_scrollbar_t *scrollbar)
{
ui_resource_t *resource = ui_window_get_res(scrollbar->window);
if (resource->textmode) {
return ui_scrollbar_paint_text(scrollbar);
} else {
return ui_scrollbar_paint_gfx(scrollbar);
}
}
void ui_scrollbar_get_geom(ui_scrollbar_t *scrollbar, ui_scrollbar_geom_t *geom)
{
ui_resource_t *resource;
gfx_coord_t btn_len;
gfx_rect_t orect;
gfx_rect_t irect;
resource = ui_window_get_res(scrollbar->window);
if (resource->textmode) {
btn_len = ui_scrollbar_btn_len_text;
} else {
btn_len = ui_scrollbar_btn_len;
}
if (resource->textmode) {
irect = scrollbar->rect;
orect = scrollbar->rect;
} else {
ui_paint_get_inset_frame_inside(resource,
&scrollbar->rect, &irect);
ui_paint_get_bevel_inside(resource->gc,
&scrollbar->rect, 1, &orect);
}
if (scrollbar->dir == ui_sbd_horiz) {
geom->up_btn_rect.p0.x = orect.p0.x;
geom->up_btn_rect.p0.y = orect.p0.y;
geom->up_btn_rect.p1.x = orect.p0.x + btn_len;
geom->up_btn_rect.p1.y = orect.p1.y;
geom->trough_rect.p0.x = geom->up_btn_rect.p1.x;
geom->trough_rect.p0.y = irect.p0.y;
geom->trough_rect.p1.x = orect.p1.x - btn_len;
geom->trough_rect.p1.y = irect.p1.y;
geom->thumb_rect.p0.x = geom->up_btn_rect.p1.x +
scrollbar->pos;
geom->thumb_rect.p0.y = orect.p0.y;
geom->thumb_rect.p1.x = geom->thumb_rect.p0.x +
scrollbar->thumb_len;
geom->thumb_rect.p1.y = orect.p1.y;
geom->upper_trough_rect.p0 = geom->trough_rect.p0;
geom->upper_trough_rect.p1.x = geom->thumb_rect.p0.x;
geom->upper_trough_rect.p1.y = geom->trough_rect.p1.y;
geom->lower_trough_rect.p0.x = geom->thumb_rect.p1.x;
geom->lower_trough_rect.p0.y = geom->trough_rect.p0.y;
geom->lower_trough_rect.p1 = geom->trough_rect.p1;
geom->down_btn_rect.p0.x = geom->trough_rect.p1.x;
geom->down_btn_rect.p0.y = orect.p0.y;
geom->down_btn_rect.p1.x = orect.p1.x;
geom->down_btn_rect.p1.y = orect.p1.y;
} else {
geom->up_btn_rect.p0.x = orect.p0.x;
geom->up_btn_rect.p0.y = orect.p0.y;
geom->up_btn_rect.p1.x = orect.p1.x;
geom->up_btn_rect.p1.y = orect.p0.y + btn_len;
geom->trough_rect.p0.x = irect.p0.x;
geom->trough_rect.p0.y = geom->up_btn_rect.p1.y;
geom->trough_rect.p1.x = irect.p1.x;
geom->trough_rect.p1.y = orect.p1.y - btn_len;
geom->thumb_rect.p0.x = orect.p0.x;
geom->thumb_rect.p0.y = geom->up_btn_rect.p1.y +
scrollbar->pos;
geom->thumb_rect.p1.x = orect.p1.x;
geom->thumb_rect.p1.y = geom->thumb_rect.p0.y +
scrollbar->thumb_len;
geom->upper_trough_rect.p0 = geom->trough_rect.p0;
geom->upper_trough_rect.p1.x = geom->trough_rect.p1.x;
geom->upper_trough_rect.p1.y = geom->thumb_rect.p0.y;
geom->lower_trough_rect.p0.x = geom->trough_rect.p0.x;
geom->lower_trough_rect.p0.y = geom->thumb_rect.p1.y;
geom->lower_trough_rect.p1 = geom->trough_rect.p1;
geom->down_btn_rect.p0.x = orect.p0.x;
geom->down_btn_rect.p0.y = geom->trough_rect.p1.y;
geom->down_btn_rect.p1.x = orect.p1.x;
geom->down_btn_rect.p1.y = orect.p1.y;
}
}
void ui_scrollbar_thumb_press(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
{
if (scrollbar->thumb_held)
return;
scrollbar->thumb_held = true;
scrollbar->press_pos = *pos;
scrollbar->last_pos = scrollbar->pos;
(void) ui_scrollbar_paint(scrollbar);
}
void ui_scrollbar_upper_trough_press(ui_scrollbar_t *scrollbar)
{
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
scrollbar->upper_trough_held = true;
scrollbar->upper_trough_inside = true;
ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_up_cb,
(void *) scrollbar);
ui_clickmatic_press(clickmatic);
}
void ui_scrollbar_lower_trough_press(ui_scrollbar_t *scrollbar)
{
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
scrollbar->lower_trough_held = true;
scrollbar->lower_trough_inside = true;
ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_down_cb,
(void *) scrollbar);
ui_clickmatic_press(clickmatic);
}
void ui_scrollbar_release(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
{
ui_clickmatic_t *clickmatic;
if (scrollbar->thumb_held) {
ui_scrollbar_update(scrollbar, pos);
scrollbar->thumb_held = false;
}
if (scrollbar->upper_trough_held || scrollbar->lower_trough_held) {
clickmatic = ui_get_clickmatic(scrollbar->ui);
ui_clickmatic_release(clickmatic);
ui_clickmatic_set_cb(clickmatic, NULL, NULL);
scrollbar->upper_trough_held = false;
scrollbar->lower_trough_held = false;
(void) ui_scrollbar_paint(scrollbar);
}
}
void ui_scrollbar_troughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
{
ui_scrollbar_geom_t geom;
bool inside_up;
bool inside_down;
ui_scrollbar_get_geom(scrollbar, &geom);
inside_up = gfx_pix_inside_rect(pos, &geom.upper_trough_rect);
inside_down = gfx_pix_inside_rect(pos, &geom.lower_trough_rect);
if (inside_up && !scrollbar->upper_trough_inside) {
scrollbar->upper_trough_inside = true;
(void) ui_scrollbar_paint(scrollbar);
} else if (!inside_up && scrollbar->upper_trough_inside) {
scrollbar->upper_trough_inside = false;
(void) ui_scrollbar_paint(scrollbar);
}
if (inside_down && !scrollbar->lower_trough_inside) {
scrollbar->lower_trough_inside = true;
(void) ui_scrollbar_paint(scrollbar);
} else if (!inside_down && scrollbar->lower_trough_inside) {
scrollbar->lower_trough_inside = false;
(void) ui_scrollbar_paint(scrollbar);
}
}
void ui_scrollbar_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
{
gfx_coord_t spos;
if (scrollbar->thumb_held) {
if (scrollbar->dir == ui_sbd_horiz)
spos = scrollbar->last_pos + pos->x - scrollbar->press_pos.x;
else
spos = scrollbar->last_pos + pos->y - scrollbar->press_pos.y;
ui_scrollbar_set_pos(scrollbar, spos);
ui_scrollbar_moved(scrollbar, scrollbar->pos);
}
ui_scrollbar_troughs_update(scrollbar, pos);
}
void ui_scrollbar_up(ui_scrollbar_t *scrollbar)
{
if (scrollbar->cb != NULL && scrollbar->cb->up != NULL)
scrollbar->cb->up(scrollbar, scrollbar->arg);
}
void ui_scrollbar_down(ui_scrollbar_t *scrollbar)
{
if (scrollbar->cb != NULL && scrollbar->cb->down != NULL)
scrollbar->cb->down(scrollbar, scrollbar->arg);
}
void ui_scrollbar_page_up(ui_scrollbar_t *scrollbar)
{
if (scrollbar->cb != NULL && scrollbar->cb->page_up != NULL)
scrollbar->cb->page_up(scrollbar, scrollbar->arg);
}
void ui_scrollbar_page_down(ui_scrollbar_t *scrollbar)
{
if (scrollbar->cb != NULL && scrollbar->cb->page_down != NULL)
scrollbar->cb->page_down(scrollbar, scrollbar->arg);
}
void ui_scrollbar_moved(ui_scrollbar_t *scrollbar, gfx_coord_t pos)
{
if (scrollbar->cb != NULL && scrollbar->cb->moved != NULL)
scrollbar->cb->moved(scrollbar, scrollbar->arg, pos);
}
ui_evclaim_t ui_scrollbar_pos_event(ui_scrollbar_t *scrollbar, pos_event_t *event)
{
gfx_coord2_t pos;
ui_evclaim_t claimed;
ui_scrollbar_geom_t geom;
ui_scrollbar_get_geom(scrollbar, &geom);
pos.x = event->hpos;
pos.y = event->vpos;
claimed = ui_pbutton_pos_event(scrollbar->up_btn, event);
if (claimed == ui_claimed)
return ui_claimed;
claimed = ui_pbutton_pos_event(scrollbar->down_btn, event);
if (claimed == ui_claimed)
return ui_claimed;
switch (event->type) {
case POS_PRESS:
if (gfx_pix_inside_rect(&pos, &geom.thumb_rect)) {
ui_scrollbar_thumb_press(scrollbar, &pos);
return ui_claimed;
}
if (gfx_pix_inside_rect(&pos, &geom.upper_trough_rect)) {
ui_scrollbar_upper_trough_press(scrollbar);
return ui_claimed;
}
if (gfx_pix_inside_rect(&pos, &geom.lower_trough_rect)) {
ui_scrollbar_lower_trough_press(scrollbar);
return ui_claimed;
}
break;
case POS_RELEASE:
if (scrollbar->thumb_held || scrollbar->upper_trough_held ||
scrollbar->lower_trough_held) {
ui_scrollbar_release(scrollbar, &pos);
return ui_claimed;
}
break;
case POS_UPDATE:
ui_scrollbar_update(scrollbar, &pos);
scrollbar->last_curs_pos = pos;
break;
case POS_DCLICK:
break;
}
return ui_unclaimed;
}
static void ui_scrollbar_up_btn_down(ui_pbutton_t *pbutton, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_up_cb,
(void *) scrollbar);
ui_clickmatic_press(clickmatic);
}
static void ui_scrollbar_up_btn_up(ui_pbutton_t *pbutton, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
ui_clickmatic_release(clickmatic);
ui_clickmatic_set_cb(clickmatic, NULL, NULL);
}
static errno_t ui_scrollbar_up_btn_decor_paint(ui_pbutton_t *pbutton,
void *arg, gfx_coord2_t *pos)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
errno_t rc;
rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color);
if (rc != EOK)
return rc;
if (scrollbar->dir == ui_sbd_horiz)
return ui_paint_left_triangle(pbutton->res->gc, pos, 5);
else
return ui_paint_up_triangle(pbutton->res->gc, pos, 5);
}
static errno_t ui_scrollbar_down_btn_decor_paint(ui_pbutton_t *pbutton,
void *arg, gfx_coord2_t *pos)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
errno_t rc;
rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color);
if (rc != EOK)
return rc;
if (scrollbar->dir == ui_sbd_horiz)
return ui_paint_right_triangle(pbutton->res->gc, pos, 5);
else
return ui_paint_down_triangle(pbutton->res->gc, pos, 5);
}
static void ui_scrollbar_down_btn_down(ui_pbutton_t *pbutton, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_down_cb,
(void *) scrollbar);
ui_clickmatic_press(clickmatic);
}
static void ui_scrollbar_down_btn_up(ui_pbutton_t *pbutton, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
ui_clickmatic_release(clickmatic);
ui_clickmatic_set_cb(clickmatic, NULL, NULL);
}
void ui_scrollbar_ctl_destroy(void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *) arg;
ui_scrollbar_destroy(scrollbar);
}
errno_t ui_scrollbar_ctl_paint(void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *) arg;
return ui_scrollbar_paint(scrollbar);
}
ui_evclaim_t ui_scrollbar_ctl_pos_event(void *arg, pos_event_t *event)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
return ui_scrollbar_pos_event(scrollbar, event);
}
static void ui_scrollbar_cm_up(ui_clickmatic_t *clickmatic, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
if (scrollbar->up_btn->inside)
ui_scrollbar_up(scrollbar);
}
static void ui_scrollbar_cm_down(ui_clickmatic_t *clickmatic, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
if (scrollbar->down_btn->inside)
ui_scrollbar_down(scrollbar);
}
static void ui_scrollbar_cm_page_up(ui_clickmatic_t *clickmatic, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
if (scrollbar->upper_trough_inside)
ui_scrollbar_page_up(scrollbar);
}
static void ui_scrollbar_cm_page_down(ui_clickmatic_t *clickmatic, void *arg)
{
ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
if (scrollbar->lower_trough_inside)
ui_scrollbar_page_down(scrollbar);
}
HelenOS homepage, sources at GitHub