NetSurf
pageinfo.c
Go to the documentation of this file.
1/*
2 * Copyright 2020 Chris Young <chris@unsatisfactorysoftware.co.uk>
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 * Amiga implementation of page info using core windows.
22 */
23
24#include <stdint.h>
25#include <stdlib.h>
26
27#include <proto/intuition.h>
28
29#include <classes/window.h>
30#include <gadgets/layout.h>
31#include <gadgets/scroller.h>
32#include <gadgets/space.h>
33#include <images/label.h>
34
35#include <intuition/icclass.h>
36#include <reaction/reaction_macros.h>
37
38#include "utils/log.h"
39#include "netsurf/keypress.h"
40#include "netsurf/plotters.h"
41#include "desktop/page-info.h"
42#include "utils/messages.h"
43#include "utils/nsoption.h"
44
45#include "amiga/corewindow.h"
46#include "amiga/libs.h"
47#include "amiga/pageinfo.h"
48#include "amiga/schedule.h"
49#include "amiga/utf8.h"
50
51
52/**
53 * Amiga page info window context
54 */
56 /** Amiga core window context */
58 /** core pageinfo */
59 struct page_info *pi;
60};
61
62/**
63 * destroy a previously created pageinfo window
64 */
65static void
67{
68 nserror res;
69 struct ami_pageinfo_window *pageinfo_win = (struct ami_pageinfo_window *)ami_cw;
70 if(pageinfo_win->pi != NULL) {
71 res = page_info_destroy(pageinfo_win->pi);
72
73 if (res == NSERROR_OK) {
74 pageinfo_win->pi = NULL;
75 ami_corewindow_fini(&pageinfo_win->core); /* closes the window for us */
76 }
77 }
78}
79
80/**
81 * close pageinfo window (callback)
82 */
83static void
85{
87}
88
89/**
90 * callback for unknown events on Amiga core window
91 * (result & WMHI_CLASSMASK) gives the class of event (eg. WMHI_GADGETUP)
92 * (result & WMHI_GADGETMASK) gives the gadget ID (eg. GID_SSLCERT_ACCEPT)
93 *
94 * \param ami_cw The Amiga core window structure.
95 * \param result event as returned by RA_HandleInput()
96 * \return TRUE if window closed during event processing
97 */
98static BOOL
100{
101 if((result & WMHI_CLASSMASK) == WMHI_INACTIVE) {
102 /* Window went inactive, so schedule to close it */
104 /* NB: do not return TRUE here as we're still open for now */
105 }
106 return FALSE;
107}
108
109/**
110 * callback for mouse action for pageinfo on core window
111 *
112 * \param ami_cw The Amiga core window structure.
113 * \param mouse_state netsurf mouse state on event
114 * \param x location of event
115 * \param y location of event
116 * \return NSERROR_OK on success otherwise apropriate error code
117 */
118static nserror
120 browser_mouse_state mouse_state,
121 int x, int y)
122{
123 bool did_something = false;
124 struct ami_pageinfo_window *pageinfo_win = (struct ami_pageinfo_window *)ami_cw;
125
126 if(page_info_mouse_action(pageinfo_win->pi, mouse_state, x, y, &did_something) == NSERROR_OK)
127 if (did_something == true) {
128 /* Something happened so we need to close ourselves */
129 ami_schedule(0, ami_pageinfo_close_cb, pageinfo_win);
130 }
131
132 return NSERROR_OK;
133}
134
135/**
136 * callback for keypress for pageinfo on core window
137 *
138 * \param ami_cw The Amiga core window structure.
139 * \param nskey The netsurf key code
140 * \return NSERROR_OK on success otherwise apropriate error code
141 */
142static nserror
143ami_pageinfo_key(struct ami_corewindow *ami_cw, uint32_t nskey)
144{
145 struct ami_pageinfo_window *pageinfo_win = (struct ami_pageinfo_window *)ami_cw;
146
147 if (page_info_keypress(pageinfo_win->pi, nskey)) {
148 return NSERROR_OK;
149 }
151}
152
153/**
154 * callback on draw event for pageinfo on core window
155 *
156 * \param ami_cw The Amiga core window structure.
157 * \param x the x coordinate to draw
158 * \param y the y coordinate to draw
159 * \param r The rectangle of the window that needs updating.
160 * \param ctx The drawing context
161 * \return NSERROR_OK on success otherwise apropriate error code
162 */
163static nserror
164ami_pageinfo_draw(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx)
165{
166 struct ami_pageinfo_window *pageinfo_win = (struct ami_pageinfo_window *)ami_cw;
167
168 page_info_redraw(pageinfo_win->pi, x, y, r, ctx);
169
170 return NSERROR_OK;
171}
172
173static nserror
174ami_pageinfo_create_window(struct ami_pageinfo_window *pageinfo_win, ULONG left, ULONG top)
175{
176 struct ami_corewindow *ami_cw = (struct ami_corewindow *)&pageinfo_win->core;
177 ULONG refresh_mode = WA_SmartRefresh;
178 struct Screen *scrn = ami_gui_get_screen();
179
180 if(nsoption_bool(window_simple_refresh) == true) {
181 refresh_mode = WA_SimpleRefresh;
182 }
183
184 ami_cw->objects[GID_CW_WIN] = WindowObj,
185 WA_ScreenTitle, ami_gui_get_screen_title(),
186 WA_Activate, TRUE,
187 WA_DepthGadget, FALSE,
188 WA_DragBar, FALSE,
189 WA_CloseGadget, FALSE,
190 WA_SizeGadget, FALSE,
191 WA_Borderless, TRUE,
192 WA_Left, left,
193 WA_Top, top,
194 WA_PubScreen, scrn,
195 WA_ReportMouse, TRUE,
196 refresh_mode, TRUE,
197 WA_IDCMP, IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE |
198 IDCMP_RAWKEY | IDCMP_IDCMPUPDATE | IDCMP_INACTIVEWINDOW |
199 IDCMP_EXTENDEDMOUSE | IDCMP_SIZEVERIFY | IDCMP_REFRESHWINDOW,
200 WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
201 WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE |
202 IDCMP_SIZEVERIFY | IDCMP_REFRESHWINDOW,
203 WINDOW_SharedPort, ami_gui_get_shared_msgport(),
204 WINDOW_UserData, pageinfo_win,
205 WINDOW_IconifyGadget, FALSE,
206 WINDOW_ParentGroup, ami_cw->objects[GID_CW_MAIN] = LayoutVObj,
207 LAYOUT_AddChild, ami_cw->objects[GID_CW_DRAW] = SpaceObj,
208 GA_ID, GID_CW_DRAW,
209 SPACE_Transparent, TRUE,
210 SPACE_BevelStyle, BVS_BOX,
211 GA_RelVerify, TRUE,
212 SpaceEnd,
213 EndGroup,
214 EndWindow;
215
216 if(ami_cw->objects[GID_CW_WIN] == NULL) {
217 return NSERROR_NOMEM;
218 }
219
220 return NSERROR_OK;
221}
222
223/* exported interface documented in amiga/pageinfo.h */
224nserror ami_pageinfo_open(struct browser_window *bw, ULONG left, ULONG top)
225{
226 struct ami_pageinfo_window *ncwin;
227 nserror res;
228 int width, height;
229
230 ncwin = calloc(1, sizeof(struct ami_pageinfo_window));
231 if (ncwin == NULL) {
232 return NSERROR_NOMEM;
233 }
234
235 ncwin->core.wintitle = ami_utf8_easy((char *)messages_get("PageInfo"));
236
237 res = ami_pageinfo_create_window(ncwin, left, top);
238 if (res != NSERROR_OK) {
239 NSLOG(netsurf, INFO, "Page info init failed");
241 free(ncwin);
242 return res;
243 }
244
245 /* initialise Amiga core window */
246 ncwin->core.draw = ami_pageinfo_draw;
247 ncwin->core.key = ami_pageinfo_key;
251
252 res = ami_corewindow_init(&ncwin->core);
253 if (res != NSERROR_OK) {
255 DisposeObject(ncwin->core.objects[GID_CW_WIN]);
256 free(ncwin);
257 return res;
258 }
259
260 res = page_info_create(ncwin->core.cb_table,
261 (struct core_window *)ncwin,
262 bw,
263 &ncwin->pi);
264
265 if (res != NSERROR_OK) {
267 DisposeObject(ncwin->core.objects[GID_CW_WIN]);
268 free(ncwin);
269 return res;
270 }
271
272 if(page_info_get_size(ncwin->pi, &width, &height) == NSERROR_OK) {
273 /* Set window to the correct size.
274 * TODO: this should really set the size of ncwin->core.objects[GID_CW_DRAW]
275 * and let the window adjust, here we've hardcoded to add 6x4px as that's
276 * what window.class does before v45.
277 */
278 SetAttrs(ncwin->core.objects[GID_CW_WIN], WA_InnerWidth, width + 6, WA_InnerHeight, height + 4, TAG_DONE);
279 }
280
281 return NSERROR_OK;
282}
283
nserror ami_corewindow_fini(struct ami_corewindow *ami_cw)
finalise elements of Amiga core window.
Definition: corewindow.c:986
nserror ami_corewindow_init(struct ami_corewindow *ami_cw)
initialise elements of Amiga core window.
Definition: corewindow.c:926
@ GID_CW_MAIN
Definition: corewindow.h:33
@ GID_CW_WIN
Definition: corewindow.h:32
@ GID_CW_DRAW
Definition: corewindow.h:34
struct Screen * ami_gui_get_screen(void)
Get a pointer to the screen NetSurf is running on.
Definition: gui.c:403
static struct Screen * scrn
Definition: gui.c:326
STRPTR ami_gui_get_screen_title(void)
Get the string for NetSurf's screen titlebar.
Definition: gui.c:974
struct MsgPort * ami_gui_get_shared_msgport(void)
Get shared message port.
static void ami_pageinfo_destroy(struct ami_corewindow *ami_cw)
destroy a previously created pageinfo window
Definition: pageinfo.c:66
static nserror ami_pageinfo_key(struct ami_corewindow *ami_cw, uint32_t nskey)
callback for keypress for pageinfo on core window
Definition: pageinfo.c:143
static nserror ami_pageinfo_create_window(struct ami_pageinfo_window *pageinfo_win, ULONG left, ULONG top)
Definition: pageinfo.c:174
static nserror ami_pageinfo_draw(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx)
callback on draw event for pageinfo on core window
Definition: pageinfo.c:164
nserror ami_pageinfo_open(struct browser_window *bw, ULONG left, ULONG top)
Open the page info window.
Definition: pageinfo.c:224
static nserror ami_pageinfo_mouse(struct ami_corewindow *ami_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action for pageinfo on core window
Definition: pageinfo.c:119
static void ami_pageinfo_close_cb(void *p)
close pageinfo window (callback)
Definition: pageinfo.c:84
static BOOL ami_pageinfo_event(struct ami_corewindow *ami_cw, ULONG result)
callback for unknown events on Amiga core window (result & WMHI_CLASSMASK) gives the class of event (...
Definition: pageinfo.c:99
nserror ami_schedule(int t, void(*callback)(void *p), void *p)
Schedule a callback.
Definition: schedule.c:331
STATIC char result[100]
Definition: arexx.c:77
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
void ami_utf8_free(char *ptr)
Definition: utf8.c:104
char * ami_utf8_easy(const char *string)
Definition: utf8.c:109
browser_mouse_state
Mouse state.
Definition: mouse.h:43
Target independent plotting interface.
Interface to key press operations.
#define WindowObj
Definition: libs.h:77
#define LayoutVObj
Definition: libs.h:65
#define SpaceObj
Definition: libs.h:74
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
#define IDCMP_EXTENDEDMOUSE
Definition: os3support.h:121
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_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.
int width
Definition: gui.c:159
int height
Definition: gui.c:160
Amiga core window state.
Definition: corewindow.h:45
void(* close)(struct ami_corewindow *ami_cw)
callback to close an Amiga core window
Definition: corewindow.h:165
Object * objects[GID_CW_LAST]
Definition: corewindow.h:52
struct core_window_callback_table * cb_table
table of callbacks for core window operations
Definition: corewindow.h:86
nserror(* mouse)(struct ami_corewindow *ami_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on Amiga core window
Definition: corewindow.h:121
nserror(* draw)(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx)
callback to draw on drawable area of Amiga core window
Definition: corewindow.h:98
nserror(* key)(struct ami_corewindow *ami_cw, uint32_t nskey)
callback for keypress on Amiga core window
Definition: corewindow.h:110
BOOL(* event)(struct ami_corewindow *ami_cw, ULONG result)
callback for unknown events on Amiga core window eg.
Definition: corewindow.h:133
struct Hook idcmp_hook
Definition: corewindow.h:54
char * wintitle
window title, must be allocated wth ami_utf8 function
Definition: corewindow.h:76
Amiga page info window context.
Definition: pageinfo.c:55
struct page_info * pi
core pageinfo
Definition: pageinfo.c:59
struct ami_corewindow core
Amiga core window context.
Definition: pageinfo.c:57
Browser window data.
The page info window structure.
Definition: page-info.c:238
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
Option reading and saving interface.
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:270