1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
/*
* Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Iconbar icon and menus (implementation).
*/
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <features.h>
#include "oslib/os.h"
#include "oslib/osbyte.h"
#include "oslib/wimp.h"
#include "riscos/configure.h"
#include "riscos/cookies.h"
#include "riscos/dialog.h"
#include "riscos/global_history.h"
#include "riscos/hotlist.h"
#include "riscos/iconbar.h"
#include "riscos/options.h"
#include "riscos/wimp_event.h"
#include "utils/log.h"
#include "utils/utils.h"
static bool ro_gui_iconbar_click(wimp_pointer *pointer);
static bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
wimp_selection *selection, menu_action action);
static void ro_gui_iconbar_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
wimp_selection *selection, menu_action action);
static wimp_menu *ro_gui_iconbar_menu = NULL; /**< Iconbar menu handle */
/**
* Initialise the iconbar menus, create an icon and register the necessary
* handlers to look after them all.
*/
void ro_gui_iconbar_initialise(void)
{
os_error *error;
/* Build the iconbar menu */
static const struct ns_menu iconbar_definition = {
"NetSurf", {
{ "Info", NO_ACTION, &dialog_info },
{ "AppHelp", HELP_OPEN_CONTENTS, 0 },
{ "Open", BROWSER_NAVIGATE_URL, 0 },
{ "Open.OpenURL", BROWSER_NAVIGATE_URL, &dialog_openurl },
{ "Open.HotlistShow", HOTLIST_SHOW, 0 },
{ "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 },
{ "Open.ShowCookies", COOKIES_SHOW, 0 },
{ "Choices", CHOICES_SHOW, 0 },
{ "Quit", APPLICATION_QUIT, 0 },
{NULL, 0, 0}
}
};
ro_gui_iconbar_menu = ro_gui_menu_define_menu(&iconbar_definition);
/* Create an iconbar icon. */
wimp_icon_create icon = {
wimp_ICON_BAR_RIGHT,
{ { 0, 0, 68, 68 },
wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED |
(wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT),
{ "!netsurf" } } };
error = xwimp_create_icon(&icon, 0);
if (error) {
LOG(("xwimp_create_icon: 0x%x: %s",
error->errnum, error->errmess));
die(error->errmess);
}
/* Register handlers to look after clicks and menu actions. */
ro_gui_wimp_event_register_mouse_click(wimp_ICON_BAR,
ro_gui_iconbar_click);
ro_gui_wimp_event_register_menu(wimp_ICON_BAR, ro_gui_iconbar_menu,
true, true);
ro_gui_wimp_event_register_menu_selection(wimp_ICON_BAR,
ro_gui_iconbar_menu_select);
ro_gui_wimp_event_register_menu_warning(wimp_ICON_BAR,
ro_gui_iconbar_menu_warning);
}
/**
* Handle Mouse_Click events on the iconbar icon.
*
* \param *pointer The wimp event block to be processed.
* \return true if the event was handled; else false.
*/
bool ro_gui_iconbar_click(wimp_pointer *pointer)
{
char url[80];
int key_down = 0;
switch (pointer->buttons) {
case wimp_CLICK_SELECT:
if (option_homepage_url && option_homepage_url[0]) {
browser_window_create(option_homepage_url, NULL, 0,
true, false);
} else {
snprintf(url, sizeof url,
"file:///<NetSurf$Dir>/Docs/welcome/index_%s",
option_language);
browser_window_create(url, NULL, 0, true, false);
}
break;
case wimp_CLICK_ADJUST:
xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &key_down);
if (key_down == 0)
ro_gui_hotlist_open();
break;
}
return true;
}
/**
* Handle submenu warnings for the iconbar menu
*
* \param w The window owning the menu.
* \param i The icon owning the menu.
* \param *menu The menu to which the warning applies.
* \param *selection The wimp menu selection data.
* \param action The selected menu action.
*/
void ro_gui_iconbar_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
wimp_selection *selection, menu_action action)
{
if (w != wimp_ICON_BAR || i != wimp_ICON_WINDOW)
return;
switch (action) {
case BROWSER_NAVIGATE_URL:
ro_gui_dialog_prepare_open_url();
break;
default:
break;
}
}
/**
* Handle selections from the iconbar menu
*
* \param w The window owning the menu.
* \param i The icon owning the menu.
* \param *selection The wimp menu selection data.
* \param action The selected menu action.
* \return true if action accepted; else false.
*/
bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
wimp_selection *selection, menu_action action)
{
if (w != wimp_ICON_BAR || i != wimp_ICON_WINDOW)
return false;
switch (action) {
case HELP_OPEN_CONTENTS:
ro_gui_open_help_page("documentation/index");
return true;
case BROWSER_NAVIGATE_URL:
ro_gui_dialog_prepare_open_url();
ro_gui_dialog_open_persistent(NULL, dialog_openurl, true);
return true;
case HOTLIST_SHOW:
ro_gui_hotlist_open();
return true;
case HISTORY_SHOW_GLOBAL:
ro_gui_global_history_open();
return true;
case COOKIES_SHOW:
ro_gui_cookies_open();
return true;
case CHOICES_SHOW:
ro_gui_configure_show();
return true;
case APPLICATION_QUIT:
if (ro_gui_prequit()) {
LOG(("QUIT in response to user request"));
netsurf_quit = true;
}
return true;
default:
return false;
}
return false;
}
/**
* Check if a particular menu handle is the iconbar menu
*
* \param *menu The menu in question.
* \return true if this menu is the iconbar menu
*/
bool ro_gui_iconbar_check_menu(wimp_menu *menu)
{
return (ro_gui_iconbar_menu == menu) ? true : false;
}
|