NetSurf
hotlist.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 bookmark (hotlist) manager.
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"
32#include "desktop/hotlist.h"
33
34#include "windows/plot.h"
35#include "windows/corewindow.h"
36#include "windows/hotlist.h"
37
38
39/**
40 * Hotlist window container for win32.
41 */
44};
45
46/** hotlist window singleton */
48
49/**
50 * callback for keypress on hotlist window
51 *
52 * \param nsw32_cw The nsw32 core window structure.
53 * \param nskey The netsurf key code
54 * \return NSERROR_OK on success otherwise apropriate error code
55 */
56static nserror
57nsw32_hotlist_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
58{
59 if (hotlist_keypress(nskey)) {
60 return NSERROR_OK;
61 }
63}
64
65/**
66 * callback for mouse action on hotlist window
67 *
68 * \param nsw32_cw The nsw32 core window structure.
69 * \param mouse_state netsurf mouse state on event
70 * \param x location of event
71 * \param y location of event
72 * \return NSERROR_OK on success otherwise apropriate error code
73 */
74static nserror
76 browser_mouse_state mouse_state,
77 int x, int y)
78{
79 hotlist_mouse_action(mouse_state, x, y);
80
81 return NSERROR_OK;
82}
83
84/**
85 * callback on draw event for hotlist window
86 *
87 * \param nsw32_cw The nsw32 core window structure.
88 * \param scrollx The horizontal scroll offset.
89 * \param scrolly The vertical scroll offset.
90 * \param r The rectangle of the window that needs updating.
91 * \return NSERROR_OK on success otherwise apropriate error code
92 */
93static nserror
95 int scrollx,
96 int scrolly,
97 struct rect *r)
98{
99 struct redraw_context ctx = {
100 .interactive = true,
101 .background_images = true,
102 .plot = &win_plotters
103 };
104
105 hotlist_redraw(-scrollx, -scrolly, r, &ctx);
106
107 return NSERROR_OK;
108}
109
110
111static nserror
113{
114 ShowWindow(nsw32_cw->hWnd, SW_HIDE);
115
116 return NSERROR_OK;
117}
118
119/**
120 * Creates the window for the hotlist tree.
121 *
122 * \return NSERROR_OK on success else appropriate error code on faliure.
123 */
124static nserror nsw32_hotlist_init(HINSTANCE hInstance)
125{
126 struct nsw32_hotlist_window *ncwin;
127 nserror res;
128
129 if (hotlist_window != NULL) {
130 return NSERROR_OK;
131 }
132
133 ncwin = calloc(1, sizeof(*ncwin));
134 if (ncwin == NULL) {
135 return NSERROR_NOMEM;
136 }
137
138 ncwin->core.title = "NetSurf Bookmarks";
140 ncwin->core.key = nsw32_hotlist_key;
143
144 res = nsw32_corewindow_init(hInstance, NULL, &ncwin->core);
145 if (res != NSERROR_OK) {
146 free(ncwin);
147 return res;
148 }
149
150 res = hotlist_manager_init((struct core_window *)ncwin);
151 if (res != NSERROR_OK) {
152 free(ncwin);
153 return res;
154 }
155
156 /* memoise window so it can be represented when necessary
157 * instead of recreating every time.
158 */
159 hotlist_window = ncwin;
160
161 return NSERROR_OK;
162}
163
164
165/* exported interface documented in windows/hotlist.h */
166nserror nsw32_hotlist_present(HINSTANCE hInstance)
167{
168 nserror res;
169
170 res = nsw32_hotlist_init(hInstance);
171 if (res == NSERROR_OK) {
172 ShowWindow(hotlist_window->core.hWnd, SW_SHOWNORMAL);
173 }
174 return res;
175}
176
177/* exported interface documented in windows/hotlist.h */
179{
180 nserror res;
181
182 if (hotlist_window == NULL) {
183 return NSERROR_OK;
184 }
185
186 res = hotlist_fini();
187 if (res == NSERROR_OK) {
189 DestroyWindow(hotlist_window->core.hWnd);
190 free(hotlist_window);
191 hotlist_window = NULL;
192 }
193
194 return res;
195}
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1697
void hotlist_mouse_action(browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1690
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1387
nserror hotlist_manager_init(void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1682
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_hotlist_init(HINSTANCE hInstance)
Creates the window for the hotlist tree.
Definition: hotlist.c:124
nserror nsw32_hotlist_finalise(void)
Free any resources allocated for the hotlist window.
Definition: hotlist.c:178
static struct nsw32_hotlist_window * hotlist_window
hotlist window singleton
Definition: hotlist.c:47
static nserror nsw32_hotlist_close(struct nsw32_corewindow *nsw32_cw)
Definition: hotlist.c:112
static nserror nsw32_hotlist_key(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on hotlist window
Definition: hotlist.c:57
static nserror nsw32_hotlist_mouse(struct nsw32_corewindow *nsw32_cw, browser_mouse_state mouse_state, int x, int y)
callback for mouse action on hotlist window
Definition: hotlist.c:75
static nserror nsw32_hotlist_draw(struct nsw32_corewindow *nsw32_cw, int scrollx, int scrolly, struct rect *r)
callback on draw event for hotlist window
Definition: hotlist.c:94
nserror nsw32_hotlist_present(HINSTANCE hInstance)
make the hotlist window visible.
Definition: hotlist.c:166
Interface to win32 bookmark manager (hotlist).
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:29
nserror(* close)(struct nsw32_corewindow *nsw32_cw)
callback for window close event
Definition: corewindow.h:82
const char * title
window title
Definition: corewindow.h:40
nserror(* key)(struct nsw32_corewindow *nsw32_cw, uint32_t nskey)
callback for keypress on nsw32 core window
Definition: corewindow.h:63
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:74
HWND hWnd
window handle
Definition: corewindow.h:31
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:52
Hotlist window container for win32.
Definition: hotlist.c:42
struct nsw32_corewindow core
Definition: hotlist.c:43
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:519
nserror nsw32_corewindow_fini(struct nsw32_corewindow *nsw32_cw)
finalise elements of nsw32 core window.
Definition: corewindow.c:577
const struct plotter_table win_plotters
win32 API plot operation table
Definition: plot.c:1040