NetSurf
global_history.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 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 win32 global history interface.
22 */
23
24#include <stdint.h>
25#include <stdlib.h>
26#include <windows.h>
27
28#include "utils/log.h"
29#include "utils/nsoption.h"
30#include "netsurf/keypress.h"
31#include "netsurf/plotters.h"
33
34#include "windows/plot.h"
35#include "windows/corewindow.h"
37
38
41};
42
44
45/**
46 * callback for keypress on global_history window
47 *
48 * \param nsw32_cw The nsw32 core window structure.
49 * \param nskey The netsurf key code
50 * \return NSERROR_OK on success otherwise apropriate error code
51 */
52static nserror
53nsw32_global_history_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
54{
55 if (global_history_keypress(nskey)) {
56 return NSERROR_OK;
57 }
59}
60
61/**
62 * callback for mouse action on global_history window
63 *
64 * \param nsw32_cw The nsw32 core window structure.
65 * \param mouse_state netsurf mouse state on event
66 * \param x location of event
67 * \param y location of event
68 * \return NSERROR_OK on success otherwise apropriate error code
69 */
70static nserror
72 browser_mouse_state mouse_state,
73 int x, int y)
74{
75 global_history_mouse_action(mouse_state, x, y);
76
77 return NSERROR_OK;
78}
79
80/**
81 * callback on draw event for global_history window
82 *
83 * \param nsw32_cw The nsw32 core window structure.
84 * \param scrollx The horizontal scroll offset.
85 * \param scrolly The vertical scroll offset.
86 * \param r The rectangle of the window that needs updating.
87 * \return NSERROR_OK on success otherwise apropriate error code
88 */
89static nserror
91 int scrollx,
92 int scrolly,
93 struct rect *r)
94{
95 struct redraw_context ctx = {
96 .interactive = true,
97 .background_images = true,
98 .plot = &win_plotters
99 };
100
101 global_history_redraw(-scrollx, -scrolly, r, &ctx);
102
103 return NSERROR_OK;
104}
105
106
107static nserror
109{
110 ShowWindow(nsw32_cw->hWnd, SW_HIDE);
111
112 return NSERROR_OK;
113}
114
115/**
116 * Creates the window for the global_history tree.
117 *
118 * \return NSERROR_OK on success else appropriate error code on faliure.
119 */
120static nserror nsw32_global_history_init(HINSTANCE hInstance)
121{
122 struct nsw32_global_history_window *ncwin;
123 nserror res;
124
125 if (global_history_window != NULL) {
126 return NSERROR_OK;
127 }
128
129 ncwin = calloc(1, sizeof(*ncwin));
130 if (ncwin == NULL) {
131 return NSERROR_NOMEM;
132 }
133
134 ncwin->core.title = "NetSurf Global History";
139
140 res = nsw32_corewindow_init(hInstance, NULL, &ncwin->core);
141 if (res != NSERROR_OK) {
142 free(ncwin);
143 return res;
144 }
145
146 res = global_history_init(ncwin->core.cb_table,
147 (struct core_window *)ncwin);
148 if (res != NSERROR_OK) {
149 free(ncwin);
150 return res;
151 }
152
153 /* memoise window so it can be represented when necessary
154 * instead of recreating every time.
155 */
156 global_history_window = ncwin;
157
158 return NSERROR_OK;
159}
160
161
162/* exported interface documented in windows/global_history.h */
164{
165 nserror res;
166
167 res = nsw32_global_history_init(hInstance);
168 if (res == NSERROR_OK) {
169 ShowWindow(global_history_window->core.hWnd, SW_SHOWNORMAL);
170 }
171 return res;
172}
173
174/* exported interface documented in windows/global_history.h */
176{
177 nserror res;
178
179 if (global_history_window == NULL) {
180 return NSERROR_OK;
181 }
182
183 res = global_history_fini();
184 if (res == NSERROR_OK) {
186 DestroyWindow(global_history_window->core.hWnd);
189 }
190
191 return res;
192}
nserror global_history_fini(void)
Finalise the global history.
nserror global_history_init(struct core_window_callback_table *cw_t, void *core_window_handle)
Initialise the global history.
void global_history_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the global history.
bool global_history_keypress(uint32_t key)
Key press handling.
void global_history_mouse_action(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
static nserror nsw32_global_history_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on global_history window
static nserror nsw32_global_history_close(struct nsw32_corewindow *nsw32_cw)
static nserror nsw32_global_history_mouse(struct nsw32_corewindow *nsw32_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action on global_history window
static struct nsw32_global_history_window * global_history_window
static nserror nsw32_global_history_draw(struct nsw32_corewindow *nsw32_cw, int scrollx, int scrolly, struct rect *r)
callback on draw event for global_history window
nserror nsw32_global_history_finalise(void)
Destroys the global history window and performs any other necessary cleanup actions.
static nserror nsw32_global_history_init(HINSTANCE hInstance)
Creates the window for the global_history tree.
nserror nsw32_global_history_present(HINSTANCE hInstance)
make the global history window visible.
Interface to win32 global history manager using nsw32 core window.
browser_mouse_state
Mouse state.
Definition: mouse.h:43
Target independent plotting interface.
Interface to key press operations.
#define ShowWindow(...)
Definition: os3support.h:172
nsw32 core window state
Definition: corewindow.h:27
nserror(* close)(struct nsw32_corewindow *nsw32_cw)
callback for window close event
Definition: corewindow.h:83
const char * title
window title
Definition: corewindow.h:38
struct core_window_callback_table * cb_table
table of callbacks for core window operations
Definition: corewindow.h:44
nserror(* key)(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on nsw32 core window
Definition: corewindow.h:64
nserror(* mouse)(struct nsw32_corewindow *nsw32_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse event on nsw32 core window
Definition: corewindow.h:75
HWND hWnd
window handle
Definition: corewindow.h:29
nserror(* draw)(struct nsw32_corewindow *nsw32_cw, int scrollx, int scrolly, struct rect *r)
callback to draw on drawable area of nsw32 core window
Definition: corewindow.h:53
struct nsw32_corewindow core
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
Option reading and saving interface.
nserror nsw32_corewindow_init(HINSTANCE hInstance, HWND hWndParent, struct nsw32_corewindow *nsw32_cw)
initialise elements of nsw32 core window.
Definition: corewindow.c:517
nserror nsw32_corewindow_fini(struct nsw32_corewindow *nsw32_cw)
finalise elements of nsw32 core window.
Definition: corewindow.c:576
const struct plotter_table win_plotters
win32 API plot operation table
Definition: plot.c:1040