NetSurf
history_local.c
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 * Implementation of Amiga local history 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/button.h>
31#include <gadgets/layout.h>
32#include <gadgets/scroller.h>
33#include <gadgets/space.h>
34#include <images/label.h>
35
36#include <intuition/icclass.h>
37#include <reaction/reaction_macros.h>
38
39#include "utils/log.h"
40#include "netsurf/keypress.h"
41#include "netsurf/plotters.h"
43#include "utils/messages.h"
44#include "utils/nsoption.h"
45#include "utils/nsurl.h"
46
47#include "amiga/corewindow.h"
48#include "amiga/gui.h"
49#include "amiga/libs.h"
50#include "amiga/history_local.h"
51#include "amiga/utf8.h"
52
53
54/**
55 * Amiga local history viewing window context
56 */
58 /** Amiga core window context */
60
61 /** Amiga GUI stuff */
62 struct gui_window *gw;
63
64 /** local history viewer context data */
66};
67
69
70/**
71 * destroy a previously created local history view
72 */
75{
76 nserror res;
77
78 if (history_local_win == NULL) {
79 return NSERROR_OK;
80 }
81
82 res = local_history_fini(history_local_win->session);
83 if (res == NSERROR_OK) {
84 ami_gui_set_history_window(history_local_win->gw, NULL);
85 res = ami_corewindow_fini(&history_local_win->core); /* closes the window for us */
87 }
88 return res;
89}
90
92{
93 struct ami_history_local_window *history_local_win;
94 /* technically degenerate container of */
95 history_local_win = (struct ami_history_local_window *)ami_cw;
96
97 ami_history_local_destroy(history_local_win);
98}
99
100/**
101 * callback for mouse action for local history on core window
102 *
103 * \param ami_cw The Amiga core window structure.
104 * \param mouse_state netsurf mouse state on event
105 * \param x location of event
106 * \param y location of event
107 * \return NSERROR_OK on success otherwise apropriate error code
108 */
109static nserror
111 browser_mouse_state mouse_state,
112 int x, int y)
113{
114 struct ami_history_local_window *history_local_win;
115 /* technically degenerate container of */
116 history_local_win = (struct ami_history_local_window *)ami_cw;
117
118 nsurl *url;
119
120 if(local_history_get_url(history_local_win->session, x, y, &url) == NSERROR_OK) {
121 if (url == NULL) {
122 SetGadgetAttrs(
123 (struct Gadget *)ami_cw->objects[GID_CW_DRAW],
124 ami_cw->win,
125 NULL,
127 NULL,
128 TAG_DONE);
129 } else {
130 SetGadgetAttrs(
131 (struct Gadget *)ami_cw->objects[GID_CW_DRAW],
132 ami_cw->win,
133 NULL,
135 nsurl_access(url),
136 TAG_DONE);
137 nsurl_unref(url);
138 }
139 }
140
141 local_history_mouse_action(history_local_win->session, mouse_state, x, y);
142
143 return NSERROR_OK;
144}
145
146/**
147 * callback for keypress for local history on core window
148 *
149 * \param ami_cw The Amiga core window structure.
150 * \param nskey The netsurf key code
151 * \return NSERROR_OK on success otherwise apropriate error code
152 */
153static nserror
154ami_history_local_key(struct ami_corewindow *ami_cw, uint32_t nskey)
155{
156 struct ami_history_local_window *history_local_win;
157
158 /* technically degenerate container of */
159 history_local_win = (struct ami_history_local_window *)ami_cw;
160
161 if (local_history_keypress(history_local_win->session, nskey)) {
162 return NSERROR_OK;
163 }
165}
166
167/**
168 * callback on draw event for certificate verify on core window
169 *
170 * \param ami_cw The Amiga core window structure.
171 * \param x the x coordinate to draw
172 * \param y the y coordinate to draw
173 * \param r The rectangle of the window that needs updating.
174 * \param ctx The drawing context
175 * \return NSERROR_OK on success otherwise apropriate error code
176 */
177static nserror
178ami_history_local_draw(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx)
179{
180 struct ami_history_local_window *history_local_win;
181
182 /* technically degenerate container of */
183 history_local_win = (struct ami_history_local_window *)ami_cw;
184
185 //ctx->plot->clip(ctx, r); //??
186 local_history_redraw(history_local_win->session, x, y, r, ctx);
187
188 return NSERROR_OK;
189}
190
191static nserror
193{
194 struct ami_corewindow *ami_cw = (struct ami_corewindow *)&history_local_win->core;
195 ULONG refresh_mode = WA_SmartRefresh;
196
197 if(nsoption_bool(window_simple_refresh) == true) {
198 refresh_mode = WA_SimpleRefresh;
199 }
200
201 ami_cw->objects[GID_CW_WIN] = WindowObj,
202 WA_ScreenTitle, ami_gui_get_screen_title(),
203 WA_Title, ami_cw->wintitle,
204 WA_Activate, TRUE,
205 WA_DepthGadget, TRUE,
206 WA_DragBar, TRUE,
207 WA_CloseGadget, TRUE,
208 WA_SizeGadget, TRUE,
209 WA_SizeBRight, TRUE,
210 WA_Width, 100,
211 WA_Height, 100,
212 WA_PubScreen, ami_gui_get_screen(),
213 WA_ReportMouse, TRUE,
214 refresh_mode, TRUE,
215 WA_IDCMP, IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE |
216 IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE |
217 IDCMP_EXTENDEDMOUSE | IDCMP_SIZEVERIFY | IDCMP_REFRESHWINDOW,
218 WINDOW_IDCMPHook, &ami_cw->idcmp_hook,
219 WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE | IDCMP_EXTENDEDMOUSE |
220 IDCMP_SIZEVERIFY | IDCMP_REFRESHWINDOW,
221 WINDOW_SharedPort, ami_gui_get_shared_msgport(),
222 WINDOW_HorizProp, 1,
223 WINDOW_VertProp, 1,
224 WINDOW_UserData, history_local_win,
225// WINDOW_MenuStrip, NULL,
226 WINDOW_MenuUserData, WGUD_HOOK,
227 WINDOW_IconifyGadget, FALSE,
228 WINDOW_Position, WPOS_CENTERSCREEN,
229 WINDOW_ParentGroup, ami_cw->objects[GID_CW_MAIN] = LayoutVObj,
230 LAYOUT_AddChild, ami_cw->objects[GID_CW_DRAW] = SpaceObj,
231 GA_ID, GID_CW_DRAW,
232 SPACE_Transparent, TRUE,
233 SPACE_BevelStyle, BVS_DISPLAY,
234 GA_RelVerify, TRUE,
235 SpaceEnd,
236 EndGroup,
237 EndWindow;
238
239 if(ami_cw->objects[GID_CW_WIN] == NULL) {
240 return NSERROR_NOMEM;
241 }
242
243 return NSERROR_OK;
244}
245
246/* exported interface documented in amiga/history_local.h */
248{
249 struct ami_history_local_window *ncwin;
250 nserror res;
251 int width, height;
252
253 if(history_local_window != NULL) {
254 //windowtofront()
255
256 if (ami_gui_get_history_window(gw) != NULL) {
258 return res;
259 }
260
261 return NSERROR_OK;
262 }
263
264 ncwin = calloc(1, sizeof(struct ami_history_local_window));
265 if (ncwin == NULL) {
266 return NSERROR_NOMEM;
267 }
268
269 ncwin->core.wintitle = ami_utf8_easy((char *)messages_get("History"));
270
272 if (res != NSERROR_OK) {
273 NSLOG(netsurf, INFO, "SSL UI builder init failed");
275 free(ncwin);
276 return res;
277 }
278
279 /* initialise Amiga core window */
284 ncwin->core.event = NULL;
285 ncwin->core.drag_end = NULL;
286 ncwin->core.icon_drop = NULL;
287
288 res = ami_corewindow_init(&ncwin->core);
289 if (res != NSERROR_OK) {
291 DisposeObject(ncwin->core.objects[GID_CW_WIN]);
292 free(ncwin);
293 return res;
294 }
295
296 res = local_history_init(ncwin->core.cb_table,
297 (struct core_window *)ncwin,
299 &ncwin->session);
300 if (res != NSERROR_OK) {
302 DisposeObject(ncwin->core.objects[GID_CW_WIN]);
303 free(ncwin);
304 return res;
305 }
306
307 res = local_history_get_size(ncwin->session,
308 &width,
309 &height);
310
311 /*TODO: Adjust these to account for window borders */
312
313 SetAttrs(ncwin->core.objects[GID_CW_WIN],
314 WA_Width, width,
315 WA_Height, height,
316 TAG_DONE);
317
318 ncwin->gw = gw;
319 history_local_window = ncwin;
321
323
324 return NSERROR_OK;
325}
326
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 ami_history_local_window * ami_gui_get_history_window(struct gui_window *gw)
Get local history window from gui_window.
Definition: gui.c:486
struct Screen * ami_gui_get_screen(void)
Get a pointer to the screen NetSurf is running on.
Definition: gui.c:403
STRPTR ami_gui_get_screen_title(void)
Get the string for NetSurf's screen titlebar.
Definition: gui.c:974
void ami_gui_set_history_window(struct gui_window *gw, struct ami_history_local_window *hw)
Set local history window in gui_window.
Definition: gui.c:492
struct browser_window * ami_gui_get_browser_window(struct gui_window *gw)
Get browser window from gui_window.
Definition: gui.c:419
struct MsgPort * ami_gui_get_shared_msgport(void)
Get shared message port.
nserror local_history_init(struct core_window_callback_table *cw_t, void *core_window_handle, struct browser_window *bw, struct local_history_session **session)
Initialise the local history.
nserror local_history_redraw(struct local_history_session *session, int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the local history.
nserror local_history_scroll_to_cursor(struct local_history_session *session)
Scroll the local history window to ensure the current cursor is shown.
nserror local_history_get_size(struct local_history_session *session, int *width, int *height)
get size of local history content area.
nserror local_history_set(struct local_history_session *session, struct browser_window *bw)
Change the browser window to draw local history for.
nserror local_history_fini(struct local_history_session *session)
Finalise the local history.
bool local_history_keypress(struct local_history_session *session, uint32_t key)
Key press handling.
nserror local_history_get_url(struct local_history_session *session, int x, int y, nsurl **url_out)
get url of entry at position in local history content area.
nserror local_history_mouse_action(struct local_history_session *session, enum browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
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
nserror ami_history_local_destroy(struct ami_history_local_window *history_local_win)
destroy a previously created local history view
Definition: history_local.c:74
static nserror ami_history_local_mouse(struct ami_corewindow *ami_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action for local history on core window
static void ami_history_local_destroy_cw(struct ami_corewindow *ami_cw)
Definition: history_local.c:91
static nserror ami_history_local_draw(struct ami_corewindow *ami_cw, int x, int y, struct rect *r, struct redraw_context *ctx)
callback on draw event for certificate verify on core window
static nserror ami_history_local_key(struct ami_corewindow *ami_cw, uint32_t nskey)
callback for keypress for local history on core window
nserror ami_history_local_present(struct gui_window *gw)
Open the global history viewer.
static struct ami_history_local_window * history_local_window
Definition: history_local.c:68
static nserror ami_history_local_create_window(struct ami_history_local_window *history_local_win)
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).
NetSurf URL handling (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
#define IDCMP_EXTENDEDMOUSE
Definition: os3support.h:121
#define GA_HintInfo
Definition: os3support.h:78
#define BVS_DISPLAY
Definition: os3support.h:120
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
nserror(* icon_drop)(struct ami_corewindow *ami_cw, struct nsurl *url, const char *title, int x, int y)
callback for icon drop on Amiga core window ie.
Definition: corewindow.h:158
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
struct Window * win
Definition: corewindow.h:51
BOOL(* event)(struct ami_corewindow *ami_cw, ULONG result)
callback for unknown events on Amiga core window eg.
Definition: corewindow.h:133
nserror(* drag_end)(struct ami_corewindow *ami_cw, int x, int y)
callback for drag end on Amiga core window ie.
Definition: corewindow.h:144
struct Hook idcmp_hook
Definition: corewindow.h:54
char * wintitle
window title, must be allocated wth ami_utf8 function
Definition: corewindow.h:76
Amiga local history viewing window context.
Definition: history_local.c:57
struct gui_window * gw
Amiga GUI stuff.
Definition: history_local.c:62
struct ami_corewindow core
Amiga core window context.
Definition: history_local.c:59
struct local_history_session * session
local history viewer context data
Definition: history_local.c:65
first entry in window list
Definition: gui.c:296
local history viewer context
Definition: local_history.c:50
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