First steps towards rationalising fbtk, split teh scrollbar widgets out

svn path=/trunk/netsurf/; revision=10466
This commit is contained in:
Vincent Sanders 2010-04-22 23:50:58 +00:00
parent 695af237a9
commit fe151c135d
6 changed files with 553 additions and 341 deletions

View File

@ -102,7 +102,7 @@ S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# S_FRAMEBUFFER are sources purely for the framebuffer build
S_FRAMEBUFFER := gui.c framebuffer.c tree.c history.c hotlist.c \
save.c schedule.c thumbnail.c misc.c bitmap.c filetype.c \
login.c findfile.c fbtk.c
login.c findfile.c fbtk.c fbtk_widget_scroll.c
S_FRAMEBUFFER += font_$(NETSURF_FB_FONTLIB).c

View File

@ -37,6 +37,7 @@
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/fbtk_widget.h"
#include "framebuffer/bitmap.h"
#include "framebuffer/image_data.h"
@ -47,90 +48,6 @@ static plot_font_style_t root_style = {
.flags = FONTF_NONE,
};
enum fbtk_widgettype_e {
FB_WIDGET_TYPE_ROOT = 0,
FB_WIDGET_TYPE_WINDOW,
FB_WIDGET_TYPE_BITMAP,
FB_WIDGET_TYPE_FILL,
FB_WIDGET_TYPE_TEXT,
FB_WIDGET_TYPE_HSCROLL,
FB_WIDGET_TYPE_VSCROLL,
FB_WIDGET_TYPE_USER,
};
typedef struct fbtk_widget_list_s fbtk_widget_list_t;
/* wrapper struct for all widget types */
struct fbtk_widget_s {
/* Generic properties */
int x;
int y;
int width;
int height;
colour bg;
colour fg;
/* handlers */
fbtk_mouseclick_t click;
void *clickpw; /* private data for callback */
fbtk_input_t input;
void *inputpw; /* private data for callback */
fbtk_move_t move;
void *movepw; /* private data for callback */
fbtk_redraw_t redraw;
void *redrawpw; /* private data for callback */
bool redraw_required;
fbtk_widget_t *parent; /* parent widget */
/* Widget specific */
enum fbtk_widgettype_e type;
union {
/* toolkit base handle */
struct {
nsfb_t *fb;
fbtk_widget_t *rootw;
fbtk_widget_t *input;
} root;
/* window */
struct {
/* widgets associated with this window */
fbtk_widget_list_t *widgets; /* begining of list */
fbtk_widget_list_t *widgets_end; /* end of list */
} window;
/* bitmap */
struct {
struct bitmap *bitmap;
} bitmap;
/* text */
struct {
char* text;
bool outline;
fbtk_enter_t enter;
void *pw;
int idx;
} text;
/* application driven widget */
struct {
void *pw; /* private data for user widget */
} user;
struct {
int pos;
int pct;
} scroll;
} u;
};
/* widget list */
struct fbtk_widget_list_s {
@ -206,7 +123,7 @@ bool fbtk_clip_to_widget(fbtk_widget_t *widget, bbox_t * restrict box)
/* creates a new widget of a given type */
static fbtk_widget_t *
fbtk_widget_t *
new_widget(enum fbtk_widgettype_e type)
{
fbtk_widget_t *neww;
@ -254,7 +171,7 @@ fbtk_request_redraw(fbtk_widget_t *widget)
}
}
static fbtk_widget_t *
fbtk_widget_t *
add_widget_to_window(fbtk_widget_t *window, fbtk_widget_t *widget)
{
fbtk_widget_list_t *newent;
@ -372,94 +289,7 @@ fb_redraw_fill(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
return 0;
}
static int
fb_redraw_hscroll(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
{
int hscroll;
int hpos;
nsfb_bbox_t bbox;
nsfb_bbox_t rect;
fbtk_get_bbox(widget, &bbox);
nsfb_claim(root->u.root.fb, &bbox);
rect = bbox;
/* background */
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
/* scroll well */
rect.x0 = bbox.x0 + 1;
rect.y0 = bbox.y0 + 2;
rect.x1 = bbox.x1 - 2;
rect.y1 = bbox.y1 - 3;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
/* scroll well outline */
nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
hscroll = ((widget->width - 4) * widget->u.scroll.pct) / 100 ;
hpos = ((widget->width - 4) * widget->u.scroll.pos) / 100 ;
LOG(("hscroll %d",hscroll));
rect.x0 = bbox.x0 + 3 + hpos;
rect.y0 = bbox.y0 + 5;
rect.x1 = bbox.x0 + hscroll + hpos;
rect.y1 = bbox.y0 + widget->height - 5;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
nsfb_update(root->u.root.fb, &bbox);
return 0;
}
static int
fb_redraw_vscroll(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
{
int vscroll;
int vpos;
nsfb_bbox_t bbox;
nsfb_bbox_t rect;
fbtk_get_bbox(widget, &bbox);
nsfb_claim(root->u.root.fb, &bbox);
rect = bbox;
/* background */
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
rect.x0 = bbox.x0 + 2;
rect.y0 = bbox.y0 + 1;
rect.x1 = bbox.x1 - 3;
rect.y1 = bbox.y1 - 2;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
/* scroll well */
nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
/* scroll well outline */
vscroll = ((widget->height - 4) * widget->u.scroll.pct) / 100 ;
vpos = ((widget->height - 4) * widget->u.scroll.pos) / 100 ;
LOG(("scroll %d",vscroll));
rect.x0 = bbox.x0 + 5;
rect.y0 = bbox.y0 + 3 + vpos;
rect.x1 = bbox.x0 + widget->width - 5;
rect.y1 = bbox.y0 + vscroll + vpos;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
nsfb_update(root->u.root.fb, &bbox);
return 0;
}
static int
fb_redraw_bitmap(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
@ -808,34 +638,6 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
fbtk_request_redraw(widget);
}
void
fbtk_set_scroll(fbtk_widget_t *widget, int pct)
{
if (widget == NULL)
return;
if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
(widget->type == FB_WIDGET_TYPE_VSCROLL)) {
widget->u.scroll.pct = pct;
fbtk_request_redraw(widget);
}
}
void
fbtk_set_scroll_pos(fbtk_widget_t *widget, int pos)
{
if (widget == NULL)
return;
if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
(widget->type == FB_WIDGET_TYPE_VSCROLL)) {
widget->u.scroll.pos = pos;
fbtk_request_redraw(widget);
}
}
void
fbtk_set_bitmap(fbtk_widget_t *widget, struct bitmap *image)
@ -1072,39 +874,7 @@ fbtk_create_fill(fbtk_widget_t *window, int x, int y, int width, int height, col
return add_widget_to_window(window, neww);
}
fbtk_widget_t *
fbtk_create_hscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg)
{
fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_HSCROLL);
neww->x = x;
neww->y = y;
neww->width = width;
neww->height = height;
neww->fg = fg;
neww->bg = bg;
neww->redraw = fb_redraw_hscroll;
return add_widget_to_window(window, neww);
}
fbtk_widget_t *
fbtk_create_vscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg)
{
fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_VSCROLL);
neww->x = x;
neww->y = y;
neww->width = width;
neww->height = height;
neww->fg = fg;
neww->bg = bg;
neww->redraw = fb_redraw_vscroll;
return add_widget_to_window(window, neww);
}
fbtk_widget_t *
fbtk_create_button(fbtk_widget_t *window,

View File

@ -1,3 +1,24 @@
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
*
* 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/>.
*/
#ifndef NETSURF_FB_FBTK_H
#define NETSURF_FB_FBTK_H
#define FB_SCROLL_COLOUR 0xFFAAAAAA
#define FB_FRAME_COLOUR 0xFFDDDDDD
@ -6,6 +27,24 @@
typedef struct fbtk_widget_s fbtk_widget_t;
enum fbtk_callback_info_type {
FBTK_CBIT_NONE,
FBTK_CBIT_SCROLLX,
FBTK_CBIT_SCROLLY,
};
typedef struct fbtk_callback_info {
enum fbtk_callback_info_type type;
void *context;
nsfb_event_t *event;
int x;
int y;
char *text;
} fbtk_callback_info;
typedef int (*fbtk_callback)(fbtk_widget_t *widget, fbtk_callback_info *cbi);
/* user widget callback */
typedef int (*fbtk_user_t)(fbtk_widget_t *widget, void *pw);
@ -86,7 +125,7 @@ fbtk_create_fill(fbtk_widget_t *window, int x, int y, int width, int height, col
* @return new widget handle or NULL on error.
*/
fbtk_widget_t *
fbtk_create_hscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg);
fbtk_create_hscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg, fbtk_callback callback, void *context);
/** Create a vertical scroll widget
*
@ -96,7 +135,7 @@ fbtk_create_hscroll(fbtk_widget_t *window, int x, int y, int width, int height,
* @return new widget handle or NULL on error.
*/
fbtk_widget_t *
fbtk_create_vscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg);
fbtk_create_vscroll(fbtk_widget_t *window, int x, int y, int width, int height, colour fg, colour bg, fbtk_callback callback, void *context);
/** Create a user widget.
*
@ -210,7 +249,7 @@ int fbtk_keycode_to_ucs4(int code, uint8_t mods);
/* clip a box to a widgets area */
bool fbtk_clip_to_widget(fbtk_widget_t *widget, bbox_t * restrict box);
#endif

119
framebuffer/fbtk_widget.h Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
*
* 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/>.
*/
#ifndef NETSURF_FB_FBTK_WIDGET_H
#define NETSURF_FB_FBTK_WIDGET_H
enum fbtk_widgettype_e {
FB_WIDGET_TYPE_ROOT = 0,
FB_WIDGET_TYPE_WINDOW,
FB_WIDGET_TYPE_BITMAP,
FB_WIDGET_TYPE_FILL,
FB_WIDGET_TYPE_TEXT,
FB_WIDGET_TYPE_HSCROLL,
FB_WIDGET_TYPE_VSCROLL,
FB_WIDGET_TYPE_USER,
};
typedef struct fbtk_widget_list_s fbtk_widget_list_t;
/* wrapper struct for all widget types */
struct fbtk_widget_s {
/* Generic properties */
int x;
int y;
int width;
int height;
colour bg;
colour fg;
/* handlers */
fbtk_mouseclick_t click;
void *clickpw; /* private data for callback */
fbtk_input_t input;
void *inputpw; /* private data for callback */
fbtk_move_t move;
void *movepw; /* private data for callback */
fbtk_redraw_t redraw;
void *redrawpw; /* private data for callback */
bool redraw_required;
fbtk_widget_t *parent; /* parent widget */
fbtk_callback callback; /* event callback */
void *callback_context;
/* Widget specific */
enum fbtk_widgettype_e type;
union {
/* toolkit base handle */
struct {
nsfb_t *fb;
fbtk_widget_t *rootw;
fbtk_widget_t *input;
} root;
/* window */
struct {
/* widgets associated with this window */
fbtk_widget_list_t *widgets; /* begining of list */
fbtk_widget_list_t *widgets_end; /* end of list */
} window;
/* bitmap */
struct {
struct bitmap *bitmap;
} bitmap;
/* text */
struct {
char* text;
bool outline;
fbtk_enter_t enter;
void *pw;
int idx;
} text;
/* application driven widget */
struct {
void *pw; /* private data for user widget */
} user;
struct {
int pos;
int pct;
struct fbtk_widget_s *btnul; /* scroll button up/left */
struct fbtk_widget_s *btndr; /* scroll button down/right*/
} scroll;
} u;
};
/* widget manipulation functions */
fbtk_widget_t *new_widget(enum fbtk_widgettype_e type);
fbtk_widget_t *add_widget_to_window(fbtk_widget_t *window, fbtk_widget_t *widget);
#endif

View File

@ -0,0 +1,356 @@
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
*
* Framebuffer windowing toolkit scrollbar widgets
*
* 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/>.
*/
#include <stdbool.h>
#include <libnsfb.h>
#include <libnsfb_plot.h>
#include <libnsfb_event.h>
#include "utils/log.h"
#include "desktop/browser.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/fbtk_widget.h"
#include "framebuffer/bitmap.h"
#include "framebuffer/image_data.h"
/** Vertical scroll widget */
static int
vscroll_redraw(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
{
int vscroll;
int vpos;
nsfb_bbox_t bbox;
nsfb_bbox_t rect;
fbtk_get_bbox(widget, &bbox);
nsfb_claim(root->u.root.fb, &bbox);
rect = bbox;
/* background */
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
rect.x0 = bbox.x0 + 2;
rect.y0 = bbox.y0 + 1;
rect.x1 = bbox.x1 - 3;
rect.y1 = bbox.y1 - 2;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
/* scroll well */
nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
/* scroll well outline */
vscroll = ((widget->height - 4) * widget->u.scroll.pct) / 100 ;
vpos = ((widget->height - 4) * widget->u.scroll.pos) / 100 ;
LOG(("scroll %d",vscroll));
rect.x0 = bbox.x0 + 5;
rect.y0 = bbox.y0 + 3 + vpos;
rect.x1 = bbox.x0 + widget->width - 5;
rect.y1 = bbox.y0 + vscroll + vpos;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
nsfb_update(root->u.root.fb, &bbox);
return 0;
}
static int
vscrollu_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
cbi.type = FBTK_CBIT_SCROLLY;
cbi.context = scrollw->callback_context;
cbi.y = -1;
return (scrollw->callback)(scrollw, &cbi);
}
static int
vscrolld_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
cbi.type = FBTK_CBIT_SCROLLY;
cbi.context = scrollw->callback_context;
cbi.y = 1;
return (scrollw->callback)(scrollw, &cbi);
}
static int
vscrollarea_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
int vscroll;
int vpos;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
vscroll = ((widget->height - 4) * widget->u.scroll.pct) / 100 ;
vpos = ((widget->height - 4) * widget->u.scroll.pos) / 100 ;
cbi.type = FBTK_CBIT_SCROLLY;
cbi.context = scrollw->callback_context;
if (y < vpos) {
/* above bar */
cbi.y = -1;
return (scrollw->callback)(scrollw, &cbi);
} else if (y > (vpos+vscroll)) {
/* below bar */
cbi.y = 1;
return (scrollw->callback)(scrollw, &cbi);
}
return 0;
}
fbtk_widget_t *
fbtk_create_vscroll(fbtk_widget_t *window,
int x, int y,
int width, int height,
colour fg,
colour bg,
fbtk_callback callback,
void *context)
{
fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_VSCROLL);
neww->x = x;
neww->y = y + scrollu.height;
neww->width = width;
neww->height = height - scrollu.height - scrolld.height;
neww->fg = fg;
neww->bg = bg;
neww->redraw = vscroll_redraw;
neww->click = vscrollarea_click;
neww->clickpw = neww;
neww->callback = callback;
neww->callback_context = context;
neww->u.scroll.btnul = fbtk_create_button(window, x + (width - scrollu.width) / 2, y, fg, &scrollu, vscrollu_click, neww);
neww->u.scroll.btndr = fbtk_create_button(window, x + (width - scrolld.width) / 2, y + height - scrolld.height, fg, &scrolld, vscrolld_click, neww);
return add_widget_to_window(window, neww);
}
/* Horizontal scroll widget */
static int
hscroll_redraw(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
{
int hscroll;
int hpos;
nsfb_bbox_t bbox;
nsfb_bbox_t rect;
fbtk_get_bbox(widget, &bbox);
nsfb_claim(root->u.root.fb, &bbox);
rect = bbox;
/* background */
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
/* scroll well */
rect.x0 = bbox.x0 + 1;
rect.y0 = bbox.y0 + 2;
rect.x1 = bbox.x1 - 2;
rect.y1 = bbox.y1 - 3;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
/* scroll well outline */
nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
hscroll = ((widget->width - 4) * widget->u.scroll.pct) / 100 ;
hpos = ((widget->width - 4) * widget->u.scroll.pos) / 100 ;
LOG(("hscroll %d",hscroll));
rect.x0 = bbox.x0 + 3 + hpos;
rect.y0 = bbox.y0 + 5;
rect.x1 = bbox.x0 + hscroll + hpos;
rect.y1 = bbox.y0 + widget->height - 5;
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
nsfb_update(root->u.root.fb, &bbox);
return 0;
}
static int
hscrolll_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
cbi.type = FBTK_CBIT_SCROLLX;
cbi.context = scrollw->callback_context;
cbi.x = -1;
return (scrollw->callback)(scrollw, &cbi);
}
static int
hscrollr_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
cbi.type = FBTK_CBIT_SCROLLX;
cbi.context = scrollw->callback_context;
cbi.x = 1;
return (scrollw->callback)(scrollw, &cbi);
}
static int
hscrollarea_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
fbtk_widget_t *scrollw = pw;
fbtk_callback_info cbi;
int hscroll;
int hpos;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
hscroll = ((widget->width - 4) * widget->u.scroll.pct) / 100 ;
hpos = ((widget->width - 4) * widget->u.scroll.pos) / 100 ;
cbi.type = FBTK_CBIT_SCROLLX;
cbi.context = scrollw->callback_context;
if (x < hpos) {
/* above bar */
cbi.x = -1;
return (scrollw->callback)(scrollw, &cbi);
} else if (x > (hpos + hscroll)) {
/* below bar */
cbi.x = 1;
return (scrollw->callback)(scrollw, &cbi);
}
return 0;
}
fbtk_widget_t *
fbtk_create_hscroll(fbtk_widget_t *window,
int x, int y,
int width, int height,
colour fg,
colour bg,
fbtk_callback callback,
void *context)
{
fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_HSCROLL);
neww->x = x + scrolll.width;
neww->y = y;
neww->width = width - scrolll.width - scrollr.width;
neww->height = height;
neww->fg = fg;
neww->bg = bg;
neww->redraw = hscroll_redraw;
neww->click = hscrollarea_click;
neww->clickpw = neww;
neww->callback = callback;
neww->callback_context = context;
neww->u.scroll.btnul = fbtk_create_button(window, x, y + ((height - scrolll.height) / 2), fg, &scrolll, hscrolll_click, neww);
neww->u.scroll.btndr = fbtk_create_button(window, x + width - scrollr.width, y + ((height - scrolll.height) / 2), fg, &scrollr, hscrollr_click, neww);
return add_widget_to_window(window, neww);
}
void
fbtk_set_scroll(fbtk_widget_t *widget, int pct)
{
if (widget == NULL)
return;
if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
(widget->type == FB_WIDGET_TYPE_VSCROLL)) {
widget->u.scroll.pct = pct;
fbtk_request_redraw(widget);
}
}
void
fbtk_set_scroll_pos(fbtk_widget_t *widget, int pos)
{
if (widget == NULL)
return;
if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
(widget->type == FB_WIDGET_TYPE_VSCROLL)) {
widget->u.scroll.pos = pos;
fbtk_request_redraw(widget);
}
}

View File

@ -768,63 +768,24 @@ fb_stop_click(fbtk_widget_t *widget,
return 0;
}
/* left scroll icon click routine */
static int
fb_scrolll_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
struct gui_window *gw = pw;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
fb_window_scroll(gw->browser, -100, 0);
return 0;
}
static int
fb_scrollr_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
fb_scroll_callback(fbtk_widget_t *widget, fbtk_callback_info *cbi)
{
struct gui_window *gw = pw;
struct gui_window *gw = cbi->context;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
switch (cbi->type) {
case FBTK_CBIT_SCROLLY:
fb_window_scroll(gw->browser, 0, 100 * cbi->y);
break;
fb_window_scroll(gw->browser, 100, 0);
return 0;
}
static int
fb_scrollu_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
struct gui_window *gw = pw;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
fb_window_scroll(gw->browser, 0, -100);
return 0;
}
static int
fb_scrolld_click(fbtk_widget_t *widget,
nsfb_event_t *event,
int x, int y, void *pw)
{
struct gui_window *gw = pw;
if (event->type != NSFB_EVENT_KEY_DOWN)
return 0;
fb_window_scroll(gw->browser, 0, 100);
case FBTK_CBIT_SCROLLX:
fb_window_scroll(gw->browser, 100 * cbi->x, 0);
break;
default:
break;
}
return 0;
}
@ -974,62 +935,29 @@ gui_create_browser_window(struct browser_window *bw,
FB_FRAME_COLOUR, FB_COLOUR_BLACK,
false);
fbtk_set_handler_move(gw->status, set_ptr_default_move, bw);
xpos = statusbar_width;
/* horizontal scrollbar */
fbtk_create_button(gw->window,
xpos,
fbtk_get_height(gw->window) - furniture_width +
(furniture_width -
scrolll.height) / 2,
FB_FRAME_COLOUR, &scrolll,
fb_scrolll_click, gw);
xpos += scrolll.width;
/* create horizontal scrollbar */
gw->hscroll = fbtk_create_hscroll(gw->window,
xpos,
statusbar_width,
fbtk_get_height(gw->window) - furniture_width,
fbtk_get_width(gw->window) - xpos -
scrollr.width,
fbtk_get_width(gw->window) - statusbar_width - furniture_width,
furniture_width,
FB_SCROLL_COLOUR,
FB_FRAME_COLOUR);
fbtk_create_button(gw->window,
fbtk_get_width(gw->window) - scrollr.width,
fbtk_get_height(gw->window) - furniture_width +
(furniture_width -
scrollr.height) / 2,
FB_FRAME_COLOUR, &scrollr,
fb_scrollr_click, gw);
/* create vertical */
fbtk_create_button(gw->window,
fbtk_get_width(gw->window) - furniture_width +
(furniture_width -
scrollu.width) / 2,
toolbar_height,
FB_FRAME_COLOUR, &scrollu,
fb_scrollu_click, gw);
FB_FRAME_COLOUR,
fb_scroll_callback,
gw);
/* create vertical scrollbar */
gw->vscroll = fbtk_create_vscroll(gw->window,
fbtk_get_width(gw->window) - furniture_width,
toolbar_height + scrollu.height,
toolbar_height,
furniture_width,
fbtk_get_height(gw->window) - toolbar_height -
furniture_width -
scrollu.height - scrolld.height,
fbtk_get_height(gw->window) - toolbar_height - furniture_width,
FB_SCROLL_COLOUR,
FB_FRAME_COLOUR);
FB_FRAME_COLOUR,
fb_scroll_callback,
gw);
fbtk_create_button(gw->window,
fbtk_get_width(gw->window) - furniture_width +
(furniture_width -
scrolld.width) / 2,
fbtk_get_height(gw->window) - furniture_width -
scrolld.height,
FB_FRAME_COLOUR, &scrolld,
fb_scrolld_click, gw);
break;