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
151 (struct core_window *)ncwin);
152 if (res != NSERROR_OK) {
153 free(ncwin);
154 return res;
155 }
156
157 /* memoise window so it can be represented when necessary
158 * instead of recreating every time.
159 */
160 hotlist_window = ncwin;
161
162 return NSERROR_OK;
163}
164
165
166/* exported interface documented in windows/hotlist.h */
167nserror nsw32_hotlist_present(HINSTANCE hInstance)
168{
169 nserror res;
170
171 res = nsw32_hotlist_init(hInstance);
172 if (res == NSERROR_OK) {
173 ShowWindow(hotlist_window->core.hWnd, SW_SHOWNORMAL);
174 }
175 return res;
176}
177
178/* exported interface documented in windows/hotlist.h */
180{
181 nserror res;
182
183 if (hotlist_window == NULL) {
184 return NSERROR_OK;
185 }
186
187 res = hotlist_fini();
188 if (res == NSERROR_OK) {
190 DestroyWindow(hotlist_window->core.hWnd);
191 free(hotlist_window);
192 hotlist_window = NULL;
193 }
194
195 return res;
196}
bool hotlist_keypress(uint32_t key)
Key press handling.
Definition: hotlist.c:1698
void hotlist_mouse_action(browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: hotlist.c:1691
nserror hotlist_fini(void)
Finalise the hotlist.
Definition: hotlist.c:1388
void hotlist_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx)
Redraw the hotlist.
Definition: hotlist.c:1683
nserror hotlist_manager_init(struct core_window_callback_table *cw_t, void *core_window_handle)
Initialise the hotlist manager.
Definition: hotlist.c:1354
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:179
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:167
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: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
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: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