NetSurf
|
#include <stdlib.h>
#include <sys/types.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include <libnsfb.h>
#include <libnsfb_plot.h>
#include <libnsfb_plot_util.h>
#include <libnsfb_event.h>
#include <libnsfb_cursor.h>
#include "utils/utils.h"
#include "utils/log.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/image_data.h"
#include "widget.h"
Go to the source code of this file.
Macros | |
#define | REGION(x, y, cx1, cx2, cy1, cy2) |
#define | SWAP(a, b) do { int t; t=(a); (a)=(b); (b)=t; } while(0) |
Enumerations | |
enum | { POINT_LEFTOF_REGION = 1 , POINT_RIGHTOF_REGION = 2 , POINT_ABOVE_REGION = 4 , POINT_BELOW_REGION = 8 } |
Functions | |
void | fbtk_request_redraw (fbtk_widget_t *widget) |
Indicate a widget should be redrawn. More... | |
int | fbtk_set_mapping (fbtk_widget_t *widget, bool map) |
Map a widget and request it is redrawn. More... | |
static void | swap_siblings (fbtk_widget_t *lw) |
Swap a sibling widget with the next deepest in the hierachy. More... | |
int | fbtk_set_zorder (fbtk_widget_t *widget, int z) |
Set the z order of a widget. More... | |
bool | fbtk_set_pos_and_size (fbtk_widget_t *widget, int x, int y, int width, int height) |
Change the widget's position and size. More... | |
void | fbtk_set_caret (fbtk_widget_t *widget, bool set, int x, int y, int height, void(*remove_caret)(fbtk_widget_t *widget)) |
Set caret owner and position. More... | |
int | fbtk_destroy_widget (fbtk_widget_t *widget) |
Destroy a widget and all its descendants. More... | |
bool | fbtk_clip_rect (const bbox_t *restrict clip, bbox_t *restrict box) |
clip one bounding box to another. More... | |
bool | fbtk_clip_to_widget (fbtk_widget_t *widget, bbox_t *restrict box) |
clip a bounding box to a widgets area. More... | |
int | fbtk_set_ptr (fbtk_widget_t *widget, fbtk_callback_info *cbi) |
set pointer to bitmap in context. More... | |
fbtk_widget_t * | fbtk_get_root_widget (fbtk_widget_t *widget) |
find the root widget from any widget in the toolkit hierarchy. More... | |
int | fbtk_get_absx (fbtk_widget_t *widget) |
Get a widget's absolute horizontal screen co-ordinate. More... | |
int | fbtk_get_absy (fbtk_widget_t *widget) |
Get a widget's absolute vertical screen co-ordinate. More... | |
int | fbtk_get_height (fbtk_widget_t *widget) |
Get a widget's height. More... | |
int | fbtk_get_width (fbtk_widget_t *widget) |
Get a widget's width. More... | |
bool | fbtk_get_bbox (fbtk_widget_t *widget, nsfb_bbox_t *bbox) |
bool | fbtk_get_caret (fbtk_widget_t *widget, int *x, int *y, int *height) |
Get a widget caret pos, if it owns caret. More... | |
fbtk_widget_t * | fbtk_get_widget_at (fbtk_widget_t *nwid, int x, int y) |
Obtain the widget at a point on screen. More... | |
fbtk_widget_t * | fbtk_widget_new (fbtk_widget_t *parent, enum fbtk_widgettype_e type, int x, int y, int width, int height) |
creates a new widget and insert it into to hierachy. More... | |
bool | fbtk_get_redraw_pending (fbtk_widget_t *widget) |
Determine if there are any redraws pending for a widget. More... | |
static int | do_redraw (nsfb_t *nsfb, fbtk_widget_t *widget) |
Perform a depth-first tree-walk, calling the redraw callback of the widgets in turn. More... | |
int | fbtk_redraw (fbtk_widget_t *widget) |
Perform any pending widget redraws. More... | |
fbtk_callback | fbtk_get_handler (fbtk_widget_t *widget, fbtk_callback_type cbt) |
Get a callback handler. More... | |
fbtk_callback | fbtk_set_handler (fbtk_widget_t *widget, fbtk_callback_type cbt, fbtk_callback cb, void *context) |
Set a callback handler. More... | |
int | fbtk_post_callback (fbtk_widget_t *widget, fbtk_callback_type cbt,...) |
Helper function to allow simple calling of callbacks with parameters. More... | |
void | fbtk_set_focus (fbtk_widget_t *widget) |
Give widget input focus. More... | |
nsfb_t * | fbtk_get_nsfb (fbtk_widget_t *widget) |
Retrieve the framebuffer library handle from toolkit widget. More... | |
fbtk_widget_t * | fbtk_init (nsfb_t *fb) |
Initialise widget toolkit. More... | |
#define REGION | ( | x, | |
y, | |||
cx1, | |||
cx2, | |||
cy1, | |||
cy2 | |||
) |
#define SWAP | ( | a, | |
b | |||
) | do { int t; t=(a); (a)=(b); (b)=t; } while(0) |
anonymous enum |
|
static |
Perform a depth-first tree-walk, calling the redraw callback of the widgets in turn.
This function makes no decisions of its own and simply walks the widget tree depth first calling widgets redraw callbacks if flagged to do so. The tree search is optimised with a flag to indicate wether the children of a node should be considered.
Definition at line 630 of file fbtk.c.
References fbtk_widget_s::child, do_redraw(), fbtk, FBTK_CBT_REDRAW, fbtk_get_absx(), fbtk_get_absy(), fbtk_post_callback(), fbtk_widget_s::height, fbtk_widget_s::last_child, fbtk_widget_s::needed, nsfb, NSLOG, fbtk_widget_s::prev, fbtk_widget_s::redraw, fbtk_widget_s::width, fbtk_widget_s::x, and fbtk_widget_s::y.
Referenced by do_redraw(), and fbtk_redraw().
bool fbtk_clip_to_widget | ( | fbtk_widget_t * | widget, |
bbox_t *restrict | box | ||
) |
clip a bounding box to a widgets area.
Definition at line 379 of file fbtk.c.
References fbtk_clip_rect(), fbtk_widget_s::height, and fbtk_widget_s::width.
Referenced by fb_queue_redraw().
int fbtk_destroy_widget | ( | fbtk_widget_t * | widget | ) |
Destroy a widget and all its descendants.
Removes a widget from the hierachy and frees it and all its children.
widget | The widget to destroy. |
Definition at line 282 of file fbtk.c.
References FBTK_CBT_DESTROY, fbtk_destroy_widget(), fbtk_post_callback(), fbtk_widget_s::first_child, fbtk_widget_s::next, fbtk_widget_s::parent, parent, and fbtk_widget_s::prev.
Referenced by fbtk_destroy_widget(), and gui_window_destroy().
int fbtk_get_absx | ( | fbtk_widget_t * | widget | ) |
Get a widget's absolute horizontal screen co-ordinate.
widget | The widget to inspect. |
Definition at line 430 of file fbtk.c.
References fbtk_widget_s::parent, and fbtk_widget_s::x.
Referenced by create_normal_browser_window(), do_redraw(), fb_cw_draw_event(), fb_pan(), fb_redraw(), fbtk_click(), and fbtk_warp_pointer().
int fbtk_get_absy | ( | fbtk_widget_t * | widget | ) |
Get a widget's absolute vertical screen co-ordinate.
widget | The widget to inspect. |
Definition at line 445 of file fbtk.c.
References fbtk_widget_s::parent, and fbtk_widget_s::y.
Referenced by create_normal_browser_window(), do_redraw(), fb_cw_draw_event(), fb_pan(), fb_redraw(), fbtk_click(), and fbtk_warp_pointer().
bool fbtk_get_bbox | ( | fbtk_widget_t * | widget, |
nsfb_bbox_t * | bbox | ||
) |
Definition at line 474 of file fbtk.c.
References fbtk_widget_s::height, fbtk_widget_s::parent, fbtk_widget_s::width, fbtk_widget_s::x, and fbtk_widget_s::y.
bool fbtk_get_caret | ( | fbtk_widget_t * | widget, |
int * | x, | ||
int * | y, | ||
int * | height | ||
) |
Get a widget caret pos, if it owns caret.
widget | The widget to inspect. |
x | If widget has caret, returns x-coord of caret within widget |
y | If widget has caret, returns y-coord of caret within widget |
height | If widget has caret, returns caret height |
Definition at line 494 of file fbtk.c.
References fbtk_get_root_widget(), height, and root.
Referenced by fb_redraw(), fb_redraw_text(), fb_text_input_remove_caret_cb(), fbtk_set_text(), gui_window_remove_caret(), and gui_window_remove_caret_cb().
fbtk_callback fbtk_get_handler | ( | fbtk_widget_t * | widget, |
fbtk_callback_type | cbt | ||
) |
Get a callback handler.
Definition at line 681 of file fbtk.c.
References fbtk_widget_s::callback, FBTK_CBT_END, and FBTK_CBT_START.
Referenced by fbtk_click().
int fbtk_get_height | ( | fbtk_widget_t * | widget | ) |
Get a widget's height.
widget | The widget to inspect. |
Definition at line 460 of file fbtk.c.
References fbtk_widget_s::height.
Referenced by create_normal_browser_window(), fb_browser_window_input(), fb_browser_window_redraw(), fb_corewindow_init(), fb_cw_draw_event(), fb_cw_get_window_dimensions(), fb_local_history_present(), fb_pan(), fb_window_invalidate_area(), fbtk_enable_oskb(), gui_window_get_dimensions(), gui_window_update_extent(), resize_normal_browser_window(), and widget_scroll_y().
nsfb_t * fbtk_get_nsfb | ( | fbtk_widget_t * | widget | ) |
Retrieve the framebuffer library handle from toolkit widget.
widget | A fbtk widget. |
Definition at line 802 of file fbtk.c.
References fbtk_get_root_widget(), and root.
Referenced by fb_cw_draw_event(), fb_pan(), fb_redraw(), fb_redraw_bitmap(), fb_redraw_fill(), fb_redraw_text(), fb_redraw_window(), and gui_resize().
bool fbtk_get_redraw_pending | ( | fbtk_widget_t * | widget | ) |
Determine if there are any redraws pending for a widget.
Mainly used by clients on the root widget to determine if they need to call fbtk_redraw
widget | to check. |
Definition at line 611 of file fbtk.c.
References fbtk_get_root_widget(), and root.
Referenced by framebuffer_run().
fbtk_widget_t * fbtk_get_root_widget | ( | fbtk_widget_t * | widget | ) |
find the root widget from any widget in the toolkit hierarchy.
widget | Any widget. |
Definition at line 412 of file fbtk.c.
References FB_WIDGET_TYPE_ROOT, NSLOG, fbtk_widget_s::parent, and fbtk_widget_s::type.
Referenced by fb_redraw_text(), fb_redraw_text_button(), fbtk_click(), fbtk_enable_oskb(), fbtk_event(), fbtk_get_caret(), fbtk_get_nsfb(), fbtk_get_redraw_pending(), fbtk_get_widget_at(), fbtk_input(), fbtk_redraw(), fbtk_set_caret(), fbtk_set_focus(), fbtk_set_ptr(), fbtk_tgrab_pointer(), fbtk_warp_pointer(), hscroll_redraw(), and vscroll_redraw().
fbtk_widget_t * fbtk_get_widget_at | ( | fbtk_widget_t * | widget, |
int | x, | ||
int | y | ||
) |
Obtain the widget at a point on screen.
widget | any tookit widget. |
x | location in horizontal plane. |
y | location in vertical plane. |
Definition at line 516 of file fbtk.c.
References fbtk_get_root_widget(), fbtk_widget_s::first_child, fbtk_widget_s::height, fbtk_widget_s::mapped, fbtk_widget_s::next, fbtk_widget_s::width, fbtk_widget_s::x, and fbtk_widget_s::y.
Referenced by fbtk_click(), and fbtk_warp_pointer().
int fbtk_get_width | ( | fbtk_widget_t * | widget | ) |
Get a widget's width.
widget | The widget to inspect. |
Definition at line 467 of file fbtk.c.
References fbtk_widget_s::width.
Referenced by create_normal_browser_window(), create_toolbar(), fb_browser_window_input(), fb_browser_window_redraw(), fb_corewindow_init(), fb_cw_draw_event(), fb_cw_get_window_dimensions(), fb_local_history_present(), fb_pan(), fb_window_invalidate_area(), fbtk_enable_oskb(), gui_window_get_dimensions(), gui_window_update_extent(), resize_normal_browser_window(), resize_toolbar(), and widget_scroll_x().
fbtk_widget_t * fbtk_init | ( | nsfb_t * | fb | ) |
Initialise widget toolkit.
Initialises widget toolkit against a framebuffer.
fb | The underlying framebuffer. |
Definition at line 814 of file fbtk.c.
References FB_WIDGET_TYPE_ROOT, and root.
Referenced by main().
int fbtk_post_callback | ( | fbtk_widget_t * | widget, |
fbtk_callback_type | cbt, | ||
... | |||
) |
Helper function to allow simple calling of callbacks with parameters.
widget | The fbtk widget to post the callback to. |
cbt | The type of callback to post |
... | Parameters appropriate for the callback type. |
Definition at line 715 of file fbtk.c.
References fbtk_widget_s::callback, fbtk_widget_s::callback_context, fbtk_callback_info::context, fbtk_callback_info::event, FBTK_CBT_CLICK, FBTK_CBT_INPUT, FBTK_CBT_POINTERMOVE, FBTK_CBT_REDRAW, FBTK_CBT_SCROLLX, FBTK_CBT_SCROLLY, FBTK_CBT_STRIP_FOCUS, FBTK_CBT_USER, fbtk_widget_s::mapped, fbtk_callback_info::type, fbtk_callback_info::x, and fbtk_callback_info::y.
Referenced by do_redraw(), fbtk_click(), fbtk_destroy_widget(), fbtk_input(), fbtk_set_focus(), fbtk_warp_pointer(), hscroll_drag(), hscrollarea_click(), hscrolll_click(), hscrollr_click(), vscroll_drag(), vscrollarea_click(), vscrolld_click(), and vscrollu_click().
int fbtk_redraw | ( | fbtk_widget_t * | widget | ) |
Perform any pending widget redraws.
widget | A fbtk widget. |
Definition at line 669 of file fbtk.c.
References do_redraw(), fbtk_get_root_widget(), and root.
Referenced by framebuffer_run().
void fbtk_request_redraw | ( | fbtk_widget_t * | widget | ) |
Indicate a widget should be redrawn.
Definition at line 82 of file fbtk.c.
References fbtk_widget_s::child, fbtk, fbtk_request_redraw(), fbtk_widget_s::height, fbtk_widget_s::last_child, fbtk_widget_s::mapped, fbtk_widget_s::needed, NSLOG, fbtk_widget_s::parent, fbtk_widget_s::prev, fbtk_widget_s::redraw, fbtk_widget_s::width, fbtk_widget_s::x, and fbtk_widget_s::y.
Referenced by fb_queue_redraw(), fb_text_input_remove_caret_cb(), fbtk_request_redraw(), fbtk_set_bitmap(), fbtk_set_mapping(), fbtk_set_scroll_parameters(), fbtk_set_scroll_position(), fbtk_set_text(), gui_resize(), text_input(), text_input_click(), widget_scroll_x(), and widget_scroll_y().
void fbtk_set_caret | ( | fbtk_widget_t * | widget, |
bool | set, | ||
int | x, | ||
int | y, | ||
int | height, | ||
void(*)(fbtk_widget_t *widget) | remove_caret | ||
) |
Set caret owner and position.
widget | widget to give caret to, or ensure caret is released from |
set | true: caret to be set for widget, false: caret to be released |
x | x-coordinate of caret top |
y | y-coordinate of caret top |
height | height of caret |
remove_caret | callback when caret is removed. |
Definition at line 252 of file fbtk.c.
References fbtk_get_root_widget(), height, and root.
Referenced by fb_browser_window_strip_focus(), fbtk_set_text(), gui_window_place_caret(), gui_window_remove_caret(), text_input(), text_input_click(), and text_input_strip_focus().
void fbtk_set_focus | ( | fbtk_widget_t * | widget | ) |
Give widget input focus.
widget | Widget to be given input focus. |
Definition at line 781 of file fbtk.c.
References FBTK_CBT_STRIP_FOCUS, fbtk_get_root_widget(), fbtk_post_callback(), and root.
Referenced by create_normal_browser_window(), and fbtk_click().
fbtk_callback fbtk_set_handler | ( | fbtk_widget_t * | widget, |
fbtk_callback_type | cbt, | ||
fbtk_callback | cb, | ||
void * | pw | ||
) |
Set a callback handler.
Set a callback handler and the pointer to pass for a widget.
widget | The widget to set the handler for. |
cbt | The type of callback to set. |
cb | The callback. |
pw | The private pointer to pass when calling the callback. |
Definition at line 693 of file fbtk.c.
References fbtk_widget_s::callback, fbtk_widget_s::callback_context, FBTK_CBT_END, and FBTK_CBT_START.
Referenced by create_browser_widget(), create_normal_browser_window(), create_toolbar(), fb_corewindow_init(), fbtk_create_bitmap(), fbtk_create_button(), fbtk_create_fill(), fbtk_create_hscroll(), fbtk_create_text(), fbtk_create_text_button(), fbtk_create_vscroll(), fbtk_create_window(), fbtk_create_writable_text(), fbtk_writable_text(), hscrollarea_click(), and vscrollarea_click().
int fbtk_set_mapping | ( | fbtk_widget_t * | widget, |
bool | map | ||
) |
Map a widget and request it is redrawn.
Definition at line 127 of file fbtk.c.
References fbtk_request_redraw(), fbtk_widget_s::mapped, NSLOG, and fbtk_widget_s::parent.
Referenced by create_toolbar(), fb_local_history_hide(), fb_local_history_mouse(), fb_local_history_present(), gui_window_create(), map_osk(), and osk_close().
bool fbtk_set_pos_and_size | ( | fbtk_widget_t * | widget, |
int | x, | ||
int | y, | ||
int | width, | ||
int | height | ||
) |
Change the widget's position and size.
(Doesn't redraw)
Definition at line 209 of file fbtk.c.
References fbtk_widget_s::height, height, fbtk_widget_s::parent, parent, fbtk_widget_s::width, width, fbtk_widget_s::x, and fbtk_widget_s::y.
Referenced by fbtk_reposition_hscroll(), fbtk_reposition_vscroll(), gui_resize(), resize_browser_widget(), resize_normal_browser_window(), and resize_toolbar().
int fbtk_set_ptr | ( | fbtk_widget_t * | widget, |
fbtk_callback_info * | cbi | ||
) |
set pointer to bitmap in context.
widget helper callback to set cursor image to the bitmap passed in the callbacks private data.
Definition at line 393 of file fbtk.c.
References fbtk_callback_info::context, fbtk_get_root_widget(), fbtk_bitmap::height, fbtk_bitmap::hot_x, fbtk_bitmap::hot_y, fbtk_bitmap::pixdata, root, and fbtk_bitmap::width.
Referenced by fbtk_create_button(), and fbtk_create_text_button().
int fbtk_set_zorder | ( | fbtk_widget_t * | widget, |
int | z | ||
) |
Set the z order of a widget.
Definition at line 181 of file fbtk.c.
References fbtk_widget_s::next, fbtk_widget_s::prev, and swap_siblings().
Referenced by fb_local_history_present(), and map_osk().
fbtk_widget_t * fbtk_widget_new | ( | fbtk_widget_t * | parent, |
enum fbtk_widgettype_e | type, | ||
int | x, | ||
int | y, | ||
int | width, | ||
int | height | ||
) |
creates a new widget and insert it into to hierachy.
The widget is set to defaults of false, 0 or NULL.
parent | The parent widget. The new widget will be added with the shallowest z order relative to its siblings. |
type | The type of the widget. |
x | The x co-ordinate relative to the parent widget. |
y | The y co-ordinate relative to the parent widget. |
width | the widgets width. This will be clipped to the parent, if the value is 0 the largest extent which can fit within the parent is used, if the value is negative the largest value that will fit within the parent less the value given will be used. |
height | the widgets width. This will be clipped to the parent, if the value is 0 the largest extent which can fit within the parent is used, if the value is negative the largest value that will fit within the parent less the value given will be used. |
Definition at line 546 of file fbtk.c.
References fbtk, fbtk_widget_s::height, height, fbtk_widget_s::next, NSLOG, fbtk_widget_s::parent, parent, fbtk_widget_s::prev, type, fbtk_widget_s::type, fbtk_widget_s::width, width, fbtk_widget_s::x, and fbtk_widget_s::y.
Referenced by fbtk_create_bitmap(), fbtk_create_button(), fbtk_create_fill(), fbtk_create_hscroll(), fbtk_create_text(), fbtk_create_text_button(), fbtk_create_user(), fbtk_create_vscroll(), fbtk_create_window(), and fbtk_create_writable_text().
|
static |
Swap a sibling widget with the next deepest in the hierachy.
lw | The widget to swap |
Definition at line 146 of file fbtk.c.
References fbtk_widget_s::first_child, fbtk_widget_s::last_child, fbtk_widget_s::next, NSLOG, fbtk_widget_s::parent, and fbtk_widget_s::prev.
Referenced by fbtk_set_zorder().