NetSurf
iconbar.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Stephen Fryatt <stevef@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 * Iconbar icon and menus implementation.
22 */
23
24#include <assert.h>
25#include <errno.h>
26#include <stdbool.h>
27#include <stddef.h>
28#include <stdlib.h>
29#include <string.h>
30#include <time.h>
31#include <features.h>
32#include <oslib/os.h>
33#include <oslib/osbyte.h>
34#include <oslib/wimp.h>
35
36#include "utils/nsoption.h"
37#include "utils/log.h"
38#include "utils/messages.h"
39#include "utils/nsurl.h"
41
42#include "riscos/gui.h"
43#include "riscos/configure.h"
44#include "riscos/cookies.h"
45#include "riscos/dialog.h"
47#include "riscos/hotlist.h"
48#include "riscos/iconbar.h"
49#include "riscos/wimp_event.h"
50
51static bool ro_gui_iconbar_click(wimp_pointer *pointer);
52
53static bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
54 wimp_selection *selection, menu_action action);
55static void ro_gui_iconbar_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
56 wimp_selection *selection, menu_action action);
57
58
59static wimp_menu *ro_gui_iconbar_menu = NULL; /**< Iconbar menu handle */
60
61/**
62 * Initialise the iconbar menus, create an icon and register the necessary
63 * handlers to look after them all.
64 */
65
67{
68 os_error *error;
69
70 /* Build the iconbar menu */
71
72 static const struct ns_menu iconbar_definition = {
73 "NetSurf", {
74 { "Info", NO_ACTION, &dialog_info },
75 { "AppHelpNoShortcut", HELP_OPEN_CONTENTS, 0 },
76 { "Open", BROWSER_NAVIGATE_URL, 0 },
77 { "Open.OpenURL", BROWSER_NAVIGATE_URL, &dialog_openurl },
78 { "Open.HotlistShowNoShortcut", HOTLIST_SHOW, 0 },
79 { "Open.HistGlobalNoShortcut", HISTORY_SHOW_GLOBAL, 0 },
80 { "Open.ShowCookies", COOKIES_SHOW, 0 },
81 { "Choices", CHOICES_SHOW, 0 },
82 { "Quit", APPLICATION_QUIT, 0 },
83 {NULL, 0, 0}
84 }
85 };
86 ro_gui_iconbar_menu = ro_gui_menu_define_menu(&iconbar_definition);
87
88 /* Create an iconbar icon. */
89
90 wimp_icon_create icon = {
91 wimp_ICON_BAR_RIGHT,
92 { { 0, 0, 68, 68 },
93 wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED |
94 (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT),
95 { "!netsurf" } } };
96 error = xwimp_create_icon(&icon, 0);
97 if (error) {
98 NSLOG(netsurf, INFO, "xwimp_create_icon: 0x%x: %s",
99 error->errnum, error->errmess);
100 die(error->errmess);
101 }
102
103 /* Register handlers to look after clicks and menu actions. */
104
107
109 true, true);
114}
115
116
117/**
118 * Handle Mouse_Click events on the iconbar icon.
119 *
120 * \param *pointer The wimp event block to be processed.
121 * \return true if the event was handled; else false.
122 */
123
124bool ro_gui_iconbar_click(wimp_pointer *pointer)
125{
126 int key_down = 0;
127 nsurl *url;
128 nserror error;
129
130 switch (pointer->buttons) {
131 case wimp_CLICK_SELECT:
132 if (nsoption_charp(homepage_url) != NULL) {
133 error = nsurl_create(nsoption_charp(homepage_url), &url);
134 } else {
135 error = nsurl_create(NETSURF_HOMEPAGE, &url);
136 }
137
138 /* create an initial browser window */
139 if (error == NSERROR_OK) {
141 url,
142 NULL,
143 NULL,
144 NULL);
145 nsurl_unref(url);
146 }
147 if (error != NSERROR_OK) {
149 }
150 break;
151
152 case wimp_CLICK_ADJUST:
153 xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &key_down);
154 if (key_down == 0) {
156 }
157 break;
158 }
159
160 return true;
161}
162
163/**
164 * Handle submenu warnings for the iconbar menu
165 *
166 * \param w The window owning the menu.
167 * \param i The icon owning the menu.
168 * \param *menu The menu to which the warning applies.
169 * \param *selection The wimp menu selection data.
170 * \param action The selected menu action.
171 */
172
173void ro_gui_iconbar_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
174 wimp_selection *selection, menu_action action)
175{
176 if (w != wimp_ICON_BAR || i != wimp_ICON_WINDOW)
177 return;
178
179 switch (action) {
182 break;
183 default:
184 break;
185 }
186}
187
188/**
189 * Handle selections from the iconbar menu
190 *
191 * \param w The window owning the menu.
192 * \param i The icon owning the menu.
193 * \param menu The wimp menu
194 * \param selection The wimp menu selection data.
195 * \param action The selected menu action.
196 * \return true if action accepted; else false.
197 */
198
199bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
200 wimp_selection *selection, menu_action action)
201{
202 nsurl *url;
203 nserror error;
204
205 if (w != wimp_ICON_BAR || i != wimp_ICON_WINDOW)
206 return false;
207
208 switch (action) {
210 error = nsurl_create("https://www.netsurf-browser.org/documentation/", &url);
211 if (error == NSERROR_OK) {
213 url,
214 NULL,
215 NULL,
216 NULL);
217 nsurl_unref(url);
218 }
219 if (error != NSERROR_OK) {
221 }
222 return true;
223
227 return true;
228 case HOTLIST_SHOW:
230 return true;
233 return true;
234 case COOKIES_SHOW:
236 return true;
237 case CHOICES_SHOW:
239 return true;
240 case APPLICATION_QUIT:
241 if (ro_gui_prequit()) {
242 NSLOG(netsurf, INFO,
243 "QUIT in response to user request");
244 riscos_done = true;
245 }
246 return true;
247 default:
248 return false;
249 }
250
251 return false;
252}
253
254/**
255 * Check if a particular menu handle is the iconbar menu
256 *
257 * \param *menu The menu in question.
258 * \return true if this menu is the iconbar menu
259 */
260
261bool ro_gui_iconbar_check_menu(wimp_menu *menu)
262{
263 return (ro_gui_iconbar_menu == menu) ? true : false;
264}
265
void die(const char *error)
Cause an abnormal program termination.
Definition: misc.c:69
menu_action
Definition: scaffolding.h:77
@ CHOICES_SHOW
Definition: scaffolding.h:176
@ COOKIES_SHOW
Definition: scaffolding.h:99
@ BROWSER_NAVIGATE_URL
Definition: scaffolding.h:138
@ HOTLIST_SHOW
Definition: scaffolding.h:96
@ APPLICATION_QUIT
Definition: scaffolding.h:177
@ HISTORY_SHOW_GLOBAL
Definition: scaffolding.h:92
@ HELP_OPEN_CONTENTS
Definition: scaffolding.h:83
Browser window creation and manipulation interface.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
void ro_gui_configure_show(void)
Definition: configure.c:126
RISC OS option setting (interface).
void ro_gui_dialog_prepare_open_url(void)
Prepares the Open URL dialog.
Definition: dialog.c:807
void ro_gui_dialog_open_persistent(wimp_w parent, wimp_w w, bool pointer)
Open a persistent dialog box relative to the pointer.
Definition: dialog.c:591
wimp_w dialog_info
Definition: dialog.c:75
wimp_w dialog_openurl
Definition: dialog.c:79
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
nserror ro_gui_global_history_present(void)
make the global history window visible.
RISc OS global history interface.
nserror ro_gui_hotlist_present(void)
make the cookie window visible.
Definition: hotlist.c:539
Hotlist (interface).
bool ro_gui_iconbar_check_menu(wimp_menu *menu)
Check if a particular menu handle is the iconbar menu.
Definition: iconbar.c:261
void ro_gui_iconbar_initialise(void)
Initialise the iconbar menus, create an icon and register the necessary handlers to look after them a...
Definition: iconbar.c:66
static bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, wimp_selection *selection, menu_action action)
Handle selections from the iconbar menu.
Definition: iconbar.c:199
static bool ro_gui_iconbar_click(wimp_pointer *pointer)
Handle Mouse_Click events on the iconbar icon.
Definition: iconbar.c:124
static void ro_gui_iconbar_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu, wimp_selection *selection, menu_action action)
Handle submenu warnings for the iconbar menu.
Definition: iconbar.c:173
static wimp_menu * ro_gui_iconbar_menu
Iconbar menu handle.
Definition: iconbar.c:59
Iconbar icon and menus (interface).
#define NO_ACTION
Definition: idna.c:695
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
wimp_menu * ro_gui_menu_define_menu(const struct ns_menu *menu)
Creates a wimp_menu and adds it to the list to handle actions for.
Definition: menus.c:510
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
Localised message support (interface).
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
nserror ro_gui_cookies_present(const char *search_term)
make the cookie window visible.
Definition: cookies.c:449
Interface to riscos cookie viewing using riscos core window.
bool ro_gui_prequit(void)
Test whether it's okay to shutdown, prompting the user if not.
Definition: gui.c:2145
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2077
bool riscos_done
Definition: gui.c:93
Interface to utility string handling.
Definition: menus.h:159
Interface to time operations.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
bool ro_gui_wimp_event_register_menu_selection(wimp_w w, bool(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a))
Register a function to be called following a menu selection.
Definition: wimp_event.c:1581
bool ro_gui_wimp_event_register_mouse_click(wimp_w w, bool(*callback)(wimp_pointer *pointer))
Register a function to be called for all mouse-clicks to icons in a window that don't have registered...
Definition: wimp_event.c:1439
bool ro_gui_wimp_event_register_menu_warning(wimp_w w, void(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a))
Register a function to be called when a sub-menu warning is received.
Definition: wimp_event.c:1603
bool ro_gui_wimp_event_register_menu(wimp_w w, wimp_menu *m, bool menu_auto, bool position_ibar)
Register a window menu to be (semi-)automatically handled.
Definition: wimp_event.c:1270
Automated RISC OS WIMP event handling (interface).