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(ncwin->core.cb_table,
201 (struct core_window *)ncwin,
202 bw,
203 &ncwin->pgi);
204 if (res != NSERROR_OK) {
205 free(ncwin);
206 return res;
207 }
208
209 *win_out = ncwin;
210
211 return NSERROR_OK;
212}
213
214
215/**
216 * open RISC OS page info window at the correct size
217 */
218static nserror
220{
221 nserror res;
222 int width, height;
223 os_box box = {0, 0, 0, 0};
224 wimp_window_state state;
225 os_error *error;
226
227 res = page_info_get_size(lhw->pgi, &width, &height);
228 if (res != NSERROR_OK) {
229 return res;
230 }
231
232 width *= 2;
233 height *= 2;
234
235 /* set extent */
236 box.x1 = width;
237 box.y0 = -height;
238 error = xwimp_set_extent(lhw->core.wh, &box);
239 if (error) {
240 NSLOG(netsurf, INFO, "xwimp_set_extent: 0x%x: %s",
241 error->errnum, error->errmess);
242 ro_warn_user("WimpError", error->errmess);
243 return NSERROR_NOMEM;
244 }
245
246 /* open full size */
247 state.w = lhw->core.wh;
248 error = xwimp_get_window_state(&state);
249 if (error) {
250 NSLOG(netsurf, INFO, "xwimp_get_window_state: 0x%x: %s",
251 error->errnum, error->errmess);
252 ro_warn_user("WimpError", error->errmess);
253 return NSERROR_NOMEM;
254 }
255 state.visible.x0 = 0;
256 state.visible.y0 = 0;
257 state.visible.x1 = width;
258 state.visible.y1 = height;
259 state.next = wimp_HIDDEN;
260 error = xwimp_open_window(PTR_WIMP_OPEN(&state));
261 if (error) {
262 NSLOG(netsurf, INFO, "xwimp_open_window: 0x%x: %s",
263 error->errnum, error->errmess);
264 ro_warn_user("WimpError", error->errmess);
265 return NSERROR_NOMEM;
266 }
267
269
270 /* Give the window focus. */
271 error = xwimp_set_caret_position(lhw->core.wh, -1, 0, 0, -1, 0);
272 if (error) {
273 NSLOG(netsurf, INFO,
274 "xwimp_set_caret_position: 0x%x : %s",
275 error->errnum,
276 error->errmess);
277 }
278
279 return NSERROR_OK;
280}
281
282
283/* exported interface documented in riscos/pageinfo.h */
285{
287
288 return NSERROR_OK;
289}
290
291/* exported interface documented in riscos/pageinfo.h */
293{
294 nserror res;
295
297 if (res == NSERROR_OK) {
298 NSLOG(netsurf, INFO, "Presenting");
300 } else {
301 NSLOG(netsurf, INFO, "Failed presenting error code %d", res);
302 }
303
304 return res;
305}
306
307/* exported interface documented in riscos/pageinfo.h */
309{
310 nserror res;
311
312 if (pageinfo_window == NULL) {
313 return NSERROR_OK;
314 }
315
317 if (res == NSERROR_OK) {
319
320 free(pageinfo_window);
321 pageinfo_window = NULL;
322 }
323
324 return res;
325}
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:827
nserror page_info_destroy(struct page_info *pi)
Destroy a page info corewindow.
Definition: page-info.c:574
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:624
bool page_info_keypress(struct page_info *pi, int32_t key)
Key press handling.
Definition: page-info.c:819
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:584
nserror page_info_create(const struct core_window_callback_table *cw_t, struct core_window *cw_h, struct browser_window *bw, struct page_info **pi_out)
Create a page info corewindow.
Definition: page-info.c:538
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:757
Pave info viewer window interface.
nserror ro_corewindow_fini(struct ro_corewindow *ro_cw)
finalise elements of ro core window.
Definition: corewindow.c:1079
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:1001
RISC OS core window interface.
int width
Definition: gui.c:159
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2076
int height
Definition: gui.c:160
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:292
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:284
nserror ro_gui_pageinfo_finalise(void)
Free any resources allocated for the page info window.
Definition: pageinfo.c:308
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:219
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:296
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:314
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:37
struct core_window_callback_table * cb_table
table of callbacks for core window operations
Definition: corewindow.h:57
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:90
wimp_w wh
window handle
Definition: corewindow.h:39
nserror(* key)(struct ro_corewindow *ro_cw, uint32_t nskey)
callback for keypress on ro core window
Definition: corewindow.h:79
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:68
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