NetSurf
pageinfo.c
Go to the documentation of this file.
1/*
2 * Copyright 2020 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 * Implementation of RISC OS page info core window.
22 */
23
24#include <stdint.h>
25#include <stdlib.h>
26#include <oslib/wimp.h>
27
28#include "utils/log.h"
29#include "netsurf/mouse.h"
30#include "netsurf/plotters.h"
31#include "desktop/page-info.h"
32
33#include "riscos/gui.h"
34#include "riscos/dialog.h"
35#include "riscos/toolbar.h"
36#include "riscos/wimputils.h"
37#include "riscos/corewindow.h"
38#include "riscos/pageinfo.h"
39
40
41/**
42 * Page info window container for RISC OS.
43 */
46 /** Core page-info window */
47 struct page_info *pgi;
48};
49
50/** page info window is a singleton */
51static struct ro_pageinfo_window *pageinfo_window = NULL;
52
53/** riscos template for pageinfo window */
54static wimp_window *dialog_pageinfo_template;
55
56/**
57 * callback to draw on drawable area of ro page info window
58 *
59 * \param ro_cw The riscos core window structure.
60 * \param r The rectangle of the window that needs updating.
61 * \param originx The risc os plotter x origin.
62 * \param originy The risc os plotter y origin.
63 * \return NSERROR_OK on success otherwise apropriate error code
64 */
65static nserror
67 int originx,
68 int originy,
69 struct rect *r)
70{
71 struct redraw_context ctx = {
72 .interactive = true,
73 .background_images = true,
74 .plot = &ro_plotters
75 };
76 struct ro_pageinfo_window *lhw;
77
78 lhw = (struct ro_pageinfo_window *)ro_cw;
79
80 ro_plot_origin_x = originx;
81 ro_plot_origin_y = originy;
82 no_font_blending = true;
83 page_info_redraw(lhw->pgi, 0, 0, r, &ctx);
84 no_font_blending = false;
85
86 return NSERROR_OK;
87}
88
89
90/**
91 * callback for keypress on ro coookie window
92 *
93 * \param ro_cw The ro core window structure.
94 * \param nskey The netsurf key code.
95 * \return NSERROR_OK if key processed,
96 * NSERROR_NOT_IMPLEMENTED if key not processed
97 * otherwise apropriate error code
98 */
99static nserror
100ro_pageinfo_key(struct ro_corewindow *ro_cw, uint32_t nskey)
101{
102 struct ro_pageinfo_window *lhw;
103
104 lhw = (struct ro_pageinfo_window *)ro_cw;
105
106 if (page_info_keypress(lhw->pgi, nskey)) {
107 return NSERROR_OK;
108 }
110}
111
112
113/**
114 * callback for mouse event on ro page info window
115 *
116 * \param ro_cw The ro core window structure.
117 * \param mouse_state mouse state
118 * \param x location of event
119 * \param y location of event
120 * \return NSERROR_OK on sucess otherwise apropriate error code.
121 */
122static nserror
124 browser_mouse_state mouse_state,
125 int x, int y)
126{
127 struct ro_pageinfo_window *pgiw;
128
129 pgiw = (struct ro_pageinfo_window *)ro_cw;
130 bool did_something = false;
131
132 if (page_info_mouse_action(pgiw->pgi, mouse_state, x, y, &did_something) == NSERROR_OK) {
133 if (did_something == true) {
134 /* Something happened so we need to close ourselves */
135 ro_gui_dialog_close(ro_cw->wh);
136 }
137 }
138
139 if ((mouse_state & BROWSER_MOUSE_LEAVE) != 0) {
140 ro_gui_dialog_close(ro_cw->wh);
141 }
142
143 return NSERROR_OK;
144}
145
146
147/**
148 * Creates the window for the page info tree.
149 *
150 * \return NSERROR_OK on success else appropriate error code on faliure.
151 */
152static nserror
154 struct ro_pageinfo_window **win_out)
155{
156 os_error *error;
157 struct ro_pageinfo_window *ncwin;
158 nserror res;
159
160 /* memoise window so it can be represented when necessary
161 * instead of recreating every time.
162 */
163 if ((*win_out) != NULL) {
164 res = page_info_set((*win_out)->pgi, bw);
165 return res;
166 }
167
168 ncwin = calloc(1, sizeof(*ncwin));
169 if (ncwin == NULL) {
170 return NSERROR_NOMEM;
171 }
172
173 /* create window from template */
174 error = xwimp_create_window(dialog_pageinfo_template,
175 &ncwin->core.wh);
176 if (error) {
177 NSLOG(netsurf, INFO, "xwimp_create_window: 0x%x: %s",
178 error->errnum, error->errmess);
179 ro_warn_user("WimpError", error->errmess);
180 free(ncwin);
181 return NSERROR_NOMEM;
182 }
183
184 /* initialise callbacks */
185 ncwin->core.draw = ro_pageinfo_draw;
186 ncwin->core.key = ro_pageinfo_key;
188
189 /* initialise core window */
190 res = ro_corewindow_init(&ncwin->core,
191 NULL,
192 NULL,
193 0,
194 NULL);
195 if (res != NSERROR_OK) {
196 free(ncwin);
197 return res;
198 }
199
200 res = page_info_create((struct core_window *)ncwin,
201 bw,
202 &ncwin->pgi);
203 if (res != NSERROR_OK) {
204 free(ncwin);
205 return res;
206 }
207
208 *win_out = ncwin;
209
210 return NSERROR_OK;
211}
212
213
214/**
215 * open RISC OS page info window at the correct size
216 */
217static nserror
219{
220 nserror res;
221 int width, height;
222 os_box box = {0, 0, 0, 0};
223 wimp_window_state state;
224 os_error *error;
225
226 res = page_info_get_size(lhw->pgi, &width, &height);
227 if (res != NSERROR_OK) {
228 return res;
229 }
230
231 width *= 2;
232 height *= 2;
233
234 /* set extent */
235 box.x1 = width;
236 box.y0 = -height;
237 error = xwimp_set_extent(lhw->core.wh, &box);
238 if (error) {
239 NSLOG(netsurf, INFO, "xwimp_set_extent: 0x%x: %s",
240 error->errnum, error->errmess);
241 ro_warn_user("WimpError", error->errmess);
242 return NSERROR_NOMEM;
243 }
244
245 /* open full size */
246 state.w = lhw->core.wh;
247 error = xwimp_get_window_state(&state);
248 if (error) {
249 NSLOG(netsurf, INFO, "xwimp_get_window_state: 0x%x: %s",
250 error->errnum, error->errmess);
251 ro_warn_user("WimpError", error->errmess);
252 return NSERROR_NOMEM;
253 }
254 state.visible.x0 = 0;
255 state.visible.y0 = 0;
256 state.visible.x1 = width;
257 state.visible.y1 = height;
258 state.next = wimp_HIDDEN;
259 error = xwimp_open_window(PTR_WIMP_OPEN(&state));
260 if (error) {
261 NSLOG(netsurf, INFO, "xwimp_open_window: 0x%x: %s",
262 error->errnum, error->errmess);
263 ro_warn_user("WimpError", error->errmess);
264 return NSERROR_NOMEM;
265 }
266
268
269 /* Give the window focus. */
270 error = xwimp_set_caret_position(lhw->core.wh, -1, 0, 0, -1, 0);
271 if (error) {
272 NSLOG(netsurf, INFO,
273 "xwimp_set_caret_position: 0x%x : %s",
274 error->errnum,
275 error->errmess);
276 }
277
278 return NSERROR_OK;
279}
280
281
282/* exported interface documented in riscos/pageinfo.h */
284{
286
287 return NSERROR_OK;
288}
289
290/* exported interface documented in riscos/pageinfo.h */
292{
293 nserror res;
294
296 if (res == NSERROR_OK) {
297 NSLOG(netsurf, INFO, "Presenting");
299 } else {
300 NSLOG(netsurf, INFO, "Failed presenting error code %d", res);
301 }
302
303 return res;
304}
305
306/* exported interface documented in riscos/pageinfo.h */
308{
309 nserror res;
310
311 if (pageinfo_window == NULL) {
312 return NSERROR_OK;
313 }
314
316 if (res == NSERROR_OK) {
318
319 free(pageinfo_window);
320 pageinfo_window = NULL;
321 }
322
323 return res;
324}
wimp_w parent
Definition: dialog.c:88
void ro_gui_dialog_open_persistent(wimp_w parent, wimp_w w, bool pointer)
Open a persistent dialog box relative to the pointer.
Definition: dialog.c:591
wimp_window * ro_gui_dialog_load_template(const char *template_name)
Load a template without creating a window.
Definition: dialog.c:242
void ro_gui_dialog_close(wimp_w close)
Close a dialog box.
Definition: dialog.c:335
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_IMPLEMENTED
Functionality is not implemented.
Definition: errors.h:61
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
bool no_font_blending
Definition: font.c:48
Core mouse and pointer states.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
@ BROWSER_MOUSE_LEAVE
pointer leaving window
Definition: mouse.h:85
Target independent plotting interface.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
nserror page_info_get_size(struct page_info *pi, int *width, int *height)
Get size of page info content area.
Definition: page-info.c:822
nserror page_info_destroy(struct page_info *pi)
Destroy a page info corewindow.
Definition: page-info.c:570
nserror page_info_redraw(const struct page_info *pi, int x, int y, const struct rect *clip, const struct redraw_context *ctx)
Redraw the page info window.
Definition: page-info.c:620
nserror page_info_create(struct core_window *cw_h, struct browser_window *bw, struct page_info **pi_out)
Create a page info corewindow.
Definition: page-info.c:537
bool page_info_keypress(struct page_info *pi, int32_t key)
Key press handling.
Definition: page-info.c:814
nserror page_info_set(struct page_info *pgi, struct browser_window *bw)
change the browser window the page information refers to
Definition: page-info.c:580
nserror page_info_mouse_action(struct page_info *pi, enum browser_mouse_state mouse, int x, int y, bool *did_something)
Mouse action handling.
Definition: page-info.c:753
Pave info viewer window interface.
nserror ro_corewindow_fini(struct ro_corewindow *ro_cw)
finalise elements of ro core window.
Definition: corewindow.c:1078
nserror ro_corewindow_init(struct ro_corewindow *ro_cw, const struct button_bar_buttons *tb_buttons, char *tb_order, theme_style tb_style, const char *tb_help)
initialise elements of riscos core window.
Definition: corewindow.c:1003
RISC OS core window interface.
int width
Definition: gui.c:160
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2077
int height
Definition: gui.c:161
int ro_plot_origin_x
Definition: plotters.c:40
int ro_plot_origin_y
Definition: plotters.c:41
const struct plotter_table ro_plotters
RISC OS plotter operation table.
Definition: plotters.c:727
static struct ro_pageinfo_window * pageinfo_window
page info window is a singleton
Definition: pageinfo.c:51
nserror ro_gui_pageinfo_present(struct gui_window *gw)
make the pageinfo window visible.
Definition: pageinfo.c:291
static nserror ro_pageinfo_draw(struct ro_corewindow *ro_cw, int originx, int originy, struct rect *r)
callback to draw on drawable area of ro page info window
Definition: pageinfo.c:66
nserror ro_gui_pageinfo_initialise(void)
initialise the pageinfo window template ready for subsequent use.
Definition: pageinfo.c:283
nserror ro_gui_pageinfo_finalise(void)
Free any resources allocated for the page info window.
Definition: pageinfo.c:307
static wimp_window * dialog_pageinfo_template
riscos template for pageinfo window
Definition: pageinfo.c:54
static nserror ro_pageinfo_open(struct ro_pageinfo_window *lhw, wimp_w parent)
open RISC OS page info window at the correct size
Definition: pageinfo.c:218
static nserror ro_pageinfo_init(struct browser_window *bw, struct ro_pageinfo_window **win_out)
Creates the window for the page info tree.
Definition: pageinfo.c:153
static nserror ro_pageinfo_mouse(struct ro_corewindow *ro_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on ro page info window
Definition: pageinfo.c:123
static nserror ro_pageinfo_key(struct ro_corewindow *ro_cw, uint32_t nskey)
callback for keypress on ro coookie window
Definition: pageinfo.c:100
Interface to page info core window for RISC OS.
Window toolbars (interface).
Node in box tree.
Definition: box.h:177
Browser window data.
first entry in window list
Definition: gui.c:297
struct fbtk_widget_s * window
Definition: gui.h:33
struct browser_window * bw
The 'content' window that is rendered in the gui_window.
Definition: gui.c:315
The page info window structure.
Definition: page-info.c:238
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
ro core window state
Definition: corewindow.h:39
nserror(* mouse)(struct ro_corewindow *ro_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on ro core window
Definition: corewindow.h:89
wimp_w wh
window handle
Definition: corewindow.h:41
nserror(* key)(struct ro_corewindow *ro_cw, uint32_t nskey)
callback for keypress on ro core window
Definition: corewindow.h:78
nserror(* draw)(struct ro_corewindow *ro_cw, int originx, int originy, struct rect *r)
callback to draw on drawable area of ro core window
Definition: corewindow.h:67
Page info window container for RISC OS.
Definition: pageinfo.c:44
struct ro_corewindow core
Definition: pageinfo.c:45
struct page_info * pgi
Core page-info window.
Definition: pageinfo.c:47
A collection of grubby utilities for working with OSLib's wimp API.
#define PTR_WIMP_OPEN(pstate)
Definition: wimputils.h:39