NetSurf
corewindow.c
Go to the documentation of this file.
1/*
2 * Copyright 2017 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * framebuffer generic core window interface.
22 *
23 * Provides interface for core renderers to the framebufefr toolkit
24 * drawable area.
25 *
26 * This module is an object that must be encapsulated. Client users
27 * should embed a struct fb_corewindow at the beginning of their
28 * context for this display surface, fill in relevant data and then
29 * call fb_corewindow_init()
30 *
31 * The fb core window structure requires the callback for draw, key and
32 * mouse operations.
33 */
34
35#include <assert.h>
36#include <stdbool.h>
37#include <stdlib.h>
38#include <limits.h>
39
40#include <libnsfb.h>
41#include <libnsfb_plot.h>
42#include <libnsfb_event.h>
43
44#include "utils/log.h"
45#include "utils/utils.h"
46#include "utils/messages.h"
47#include "utils/utf8.h"
48#include "utils/nsoption.h"
49#include "netsurf/keypress.h"
50#include "netsurf/mouse.h"
51#include "netsurf/plot_style.h"
52
53#include "framebuffer/gui.h"
54#include "framebuffer/fbtk.h"
56
57
58/* toolkit event handlers that do generic things and call internal callbacks */
59
60
61static int
63{
64 struct fb_corewindow *fb_cw = (struct fb_corewindow *)cbi->context;
66
67 /** \todo frambuffer corewindow mouse event handling needs improving */
68 if (cbi->event->type != NSFB_EVENT_KEY_UP) {
69 state = BROWSER_MOUSE_HOVER;
70 } else {
72 }
73
74 fb_cw->mouse(fb_cw, state, cbi->x, cbi->y);
75
76 return 1;
77}
78
79/*
80static bool
81fb_cw_input_event(toolkit_widget *widget, void *ctx)
82{
83 struct fb_corewindow *fb_cw = (struct fb_corewindow *)ctx;
84
85 fb_cw->key(fb_cw, keycode);
86
87 return true;
88}
89*/
90
91/**
92 * handler for toolkit window redraw event
93 */
95{
96 struct fb_corewindow *fb_cw;
97 nsfb_bbox_t rbox;
98 struct rect clip;
99
100 fb_cw = (struct fb_corewindow *)cbi->context;
101
102 rbox.x0 = fbtk_get_absx(widget);
103 rbox.y0 = fbtk_get_absy(widget);
104
105 rbox.x1 = rbox.x0 + fbtk_get_width(widget);
106 rbox.y1 = rbox.y0 + fbtk_get_height(widget);
107
108 nsfb_claim(fbtk_get_nsfb(widget), &rbox);
109
110 clip.x0 = fb_cw->scrollx;
111 clip.y0 = fb_cw->scrolly;
112 clip.x1 = fbtk_get_width(widget) + fb_cw->scrollx;
113 clip.y1 = fbtk_get_height(widget) + fb_cw->scrolly;
114
115 fb_cw->draw(fb_cw, &clip);
116
117 nsfb_update(fbtk_get_nsfb(widget), &rbox);
118
119 return 0;
120}
121
122
123/**
124 * callback from core to request a redraw
125 */
126static nserror
127fb_cw_invalidate(struct core_window *cw, const struct rect *r)
128{
129/* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
130
131 toolkit_widget_queue_draw_area(fb_cw->widget,
132 r->x0, r->y0,
133 r->x1 - r->x0, r->y1 - r->y0);
134*/
135 return NSERROR_OK;
136}
137
138
139static nserror
140fb_cw_update_size(struct core_window *cw, int width, int height)
141{
142/* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
143
144 toolkit_widget_set_size_request(FB_WIDGET(fb_cw->drawing_area),
145 width, height);
146*/
147 return NSERROR_OK;
148}
149
150
151static nserror
152fb_cw_set_scroll(struct core_window *cw, int x, int y)
153{
154/* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
155
156 toolkit_scroll_widget(fb_cw->widget, r);
157*/
158 return NSERROR_OK;
159}
160
161
162static nserror
163fb_cw_get_scroll(const struct core_window *cw, int *x, int *y)
164{
165/* struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
166
167 toolkit_scroll_widget(fb_cw->widget, r);
168*/
170}
171
172
173static nserror
174fb_cw_get_window_dimensions(const struct core_window *cw,
175 int *width, int *height)
176{
177 struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
178
179 *width = fbtk_get_width(fb_cw->drawable);
181 return NSERROR_OK;
182}
183
184
185static nserror
187{
188 struct fb_corewindow *fb_cw = (struct fb_corewindow *)cw;
189 fb_cw->drag_status = ds;
190
191 return NSERROR_OK;
192}
193
194
197 .set_extent = fb_cw_update_size,
198 .set_scroll = fb_cw_set_scroll,
199 .get_scroll = fb_cw_get_scroll,
200 .get_dimensions = fb_cw_get_window_dimensions,
201 .drag_status = fb_cw_drag_status
202};
203
205
206/* exported function documented fb/corewindow.h */
208{
209 int furniture_width;
210
211 furniture_width = nsoption_int(fb_furniture_size);
212
213 /* setup the core window callback table */
215
216 /* container window */
217 fb_cw->wnd = fbtk_create_window(parent, 0, 0, 0, 0, 0);
218
219 fb_cw->drawable = fbtk_create_user(fb_cw->wnd,
220 0, 0,
221 -furniture_width, -furniture_width,
222 fb_cw);
223
227 fb_cw);
228
232 fb_cw);
233/*
234 fbtk_set_handler(fb_cw->drawable,
235 FBTK_CBT_INPUT,
236 fb_cw_input_event,
237 fb_cw);
238
239 fbtk_set_handler(fb_cw->drawable,
240 FBTK_CBT_POINTERMOVE,
241 fb_cw_move_event,
242 fb_cw);
243*/
244
245 /* create horizontal scrollbar */
246 fb_cw->hscroll = fbtk_create_hscroll(fb_cw->wnd,
247 0,
248 fbtk_get_height(fb_cw->wnd) - furniture_width,
249 fbtk_get_width(fb_cw->wnd) - furniture_width,
250 furniture_width,
253 NULL,
254 NULL);
255
256 fb_cw->vscroll = fbtk_create_vscroll(fb_cw->wnd,
257 fbtk_get_width(fb_cw->wnd) - furniture_width,
258 0,
259 furniture_width,
260 fbtk_get_height(fb_cw->wnd) - furniture_width,
263 NULL,
264 NULL);
265
266 fbtk_create_fill(fb_cw->wnd,
267 fbtk_get_width(fb_cw->wnd) - furniture_width,
268 fbtk_get_height(fb_cw->wnd) - furniture_width,
269 furniture_width,
270 furniture_width,
272
273
274 return NSERROR_OK;
275}
276
277/* exported interface documented in fb/corewindow.h */
279{
280 return NSERROR_OK;
281}
core_window_drag_status
drag status passed to drag_status callback
Definition: core_window.h:41
@ CORE_WINDOW_DRAG_NONE
Definition: core_window.h:42
wimp_w parent
Definition: dialog.c:88
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_IMPLEMENTED
Functionality is not implemented.
Definition: errors.h:61
@ NSERROR_OK
No error.
Definition: errors.h:30
fbtk_callback fbtk_set_handler(fbtk_widget_t *widget, fbtk_callback_type cbt, fbtk_callback cb, void *pw)
Set a callback handler.
Definition: fbtk.c:693
@ FBTK_CBT_REDRAW
Definition: fbtk.h:44
@ FBTK_CBT_CLICK
Definition: fbtk.h:39
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)
Create a vertical scroll widget.
Definition: scroll.c:224
int fbtk_get_absx(fbtk_widget_t *widget)
Get a widget's absolute horizontal screen co-ordinate.
Definition: fbtk.c:430
#define FB_SCROLL_COLOUR
Definition: fbtk.h:24
int fbtk_get_width(fbtk_widget_t *widget)
Get a widget's width.
Definition: fbtk.c:467
fbtk_widget_t * fbtk_create_fill(fbtk_widget_t *window, int x, int y, int width, int height, colour c)
Create a filled rectangle.
Definition: fill.c:59
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)
Create a horizontal scroll widget.
Definition: scroll.c:463
#define FB_FRAME_COLOUR
Definition: fbtk.h:25
fbtk_widget_t * fbtk_create_user(fbtk_widget_t *window, int x, int y, int width, int height, void *pw)
Create a user widget.
Definition: user.c:43
fbtk_widget_t * fbtk_create_window(fbtk_widget_t *parent, int x, int y, int width, int height, colour bg)
Create a window widget.
Definition: window.c:66
int fbtk_get_absy(fbtk_widget_t *widget)
Get a widget's absolute vertical screen co-ordinate.
Definition: fbtk.c:445
nsfb_t * fbtk_get_nsfb(fbtk_widget_t *widget)
Retrieve the framebuffer library handle from toolkit widget.
Definition: fbtk.c:802
int fbtk_get_height(fbtk_widget_t *widget)
Get a widget's height.
Definition: fbtk.c:460
struct core_window_table * framebuffer_core_window_table
Definition: corewindow.c:204
nserror fb_corewindow_init(fbtk_widget_t *parent, struct fb_corewindow *fb_cw)
initialise elements of fb core window.
Definition: corewindow.c:207
static nserror fb_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
Definition: corewindow.c:186
nserror fb_corewindow_fini(struct fb_corewindow *fb_cw)
finalise elements of fb core window.
Definition: corewindow.c:278
static nserror fb_cw_set_scroll(struct core_window *cw, int x, int y)
Definition: corewindow.c:152
static nserror fb_cw_invalidate(struct core_window *cw, const struct rect *r)
callback from core to request a redraw
Definition: corewindow.c:127
static nserror fb_cw_get_window_dimensions(const struct core_window *cw, int *width, int *height)
Definition: corewindow.c:174
static int fb_cw_draw_event(fbtk_widget_t *widget, fbtk_callback_info *cbi)
handler for toolkit window redraw event
Definition: corewindow.c:94
static nserror fb_cw_update_size(struct core_window *cw, int width, int height)
Definition: corewindow.c:140
static nserror fb_cw_get_scroll(const struct core_window *cw, int *x, int *y)
Definition: corewindow.c:163
struct core_window_table fb_cw_cb_table
Definition: corewindow.c:195
static int fb_cw_mouse_press_event(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: corewindow.c:62
Core mouse and pointer states.
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
@ BROWSER_MOUSE_PRESS_1
primary button pressed
Definition: mouse.h:59
@ BROWSER_MOUSE_HOVER
No mouse buttons pressed, May be used to indicate hover or end of drag.
Definition: mouse.h:56
Interface to key press operations.
Localised message support (interface).
plotter style interfaces, generic styles and style colour helpers.
int width
Definition: gui.c:160
int height
Definition: gui.c:161
Core user interface window function table.
Definition: core_window.h:53
nserror(* invalidate)(struct core_window *cw, const struct rect *rect)
Invalidate an area of a window.
Definition: core_window.h:71
fb core window state
Definition: corewindow.h:29
struct fbtk_widget_s * wnd
framebuffer toolkit window.
Definition: corewindow.h:34
core_window_drag_status drag_status
drag status set by core
Definition: corewindow.h:52
struct fbtk_widget_s * drawable
framebuffer toolkit user drawable widget.
Definition: corewindow.h:46
struct fbtk_widget_s * vscroll
framebuffer toolkit vertical scrollbar.
Definition: corewindow.h:42
struct fbtk_widget_s * hscroll
framebuffer toolkit horizontal scrollbar.
Definition: corewindow.h:38
nserror(* draw)(struct fb_corewindow *fb_cw, struct rect *r)
callback to draw on drawable area of fb core window
Definition: corewindow.h:61
int scrolly
scroll offsets.
Definition: corewindow.h:48
nserror(* mouse)(struct fb_corewindow *fb_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on fb core window
Definition: corewindow.h:83
widget callback information
Definition: fbtk.h:52
nsfb_event_t * event
Definition: fbtk.h:55
void * context
Definition: fbtk.h:54
Widget description.
Definition: widget.h:120
Rectangle coordinates.
Definition: types.h:40
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357