From 388e8a8a9010d772cfc0f59592cdaca7869691df Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Tue, 11 May 2004 23:40:07 +0000 Subject: [project @ 2004-05-11 23:40:07 by rjw] Interactive help support. svn path=/import/netsurf/; revision=853 --- riscos/gui.c | 9 +++- riscos/gui.h | 1 + riscos/help.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ riscos/help.h | 19 ++++++++ riscos/menus.c | 2 +- 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 riscos/help.c create mode 100644 riscos/help.h diff --git a/riscos/gui.c b/riscos/gui.c index 436ee8de8..5aa32cf2a 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -17,6 +17,7 @@ #include #include #include "oslib/font.h" +#include "oslib/help.h" #include "oslib/hourglass.h" #include "oslib/inetsuite.h" #include "oslib/os.h" @@ -37,6 +38,7 @@ #include "netsurf/render/html.h" #include "netsurf/riscos/constdata.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/help.h" #include "netsurf/riscos/options.h" #ifdef WITH_PLUGIN #include "netsurf/riscos/plugin.h" @@ -70,7 +72,8 @@ static clock_t gui_last_poll; /**< Time of last wimp_poll. */ osspriteop_area *gui_pointers; /**< Sprite area containing pointer data */ /** Accepted wimp user messages. */ -static wimp_MESSAGE_LIST(27) task_messages = { { +static wimp_MESSAGE_LIST(28) task_messages = { { + message_HELP_REQUEST, message_DATA_SAVE, message_DATA_SAVE_ACK, message_DATA_LOAD, @@ -776,6 +779,10 @@ void ro_gui_keypress(wimp_key *key) void ro_gui_user_message(wimp_event_no event, wimp_message *message) { switch (message->action) { + case message_HELP_REQUEST: + ro_gui_interactive_help_request(message); + break; + case message_DATA_SAVE: ro_msg_datasave(message); break; diff --git a/riscos/gui.h b/riscos/gui.h index e6656b3c1..73ba83eac 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -31,6 +31,7 @@ extern struct form_control *current_gadget; extern gui_window *window_list; extern bool gui_reformat_pending; extern bool gui_redraw_debug; +extern wimp_menu *current_menu; extern gui_window *current_gui; extern gui_window *ro_gui_current_redraw_gui; extern osspriteop_area *gui_pointers; diff --git a/riscos/help.c b/riscos/help.c new file mode 100644 index 000000000..b82455877 --- /dev/null +++ b/riscos/help.c @@ -0,0 +1,152 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 Richard Wilson + */ + +/** \file + * Interactive help (implementation). + */ + +#include +#include +#include +#include "oslib/help.h" +#include "oslib/wimp.h" +#include "netsurf/riscos/gui.h" +#include "netsurf/riscos/help.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/log.h" + + +/* Current prefixes: + + HelpB Browser window + HelpI Iconbar menu + HelpM Browser window menu + HelpT Toolbar window + HelpS Status window + + The prefixes are followed by either the icon number (eg 'HelpT7'), or a series + of numbers representing the menu structure (eg 'HelpM3-1-2'). +*/ + +static void ro_gui_interactive_help_broadcast(wimp_message *message, char *token); + + +/** + * Attempts to process an interactive help message request + * + * \param message the request message + */ +void ro_gui_interactive_help_request(wimp_message *message) { + char message_token[32]; + char menu_buffer[4]; + wimp_selection menu_tree; + help_full_message_request *message_data; + wimp_w window; + wimp_i icon; + gui_window *g; + unsigned int index; + + /* Ensure we have a help request + */ + if ((!message) || (message->action != message_HELP_REQUEST)) return; + + /* Initialise the basic token to a null byte + */ + message_token[0] = 0x00; + + /* Get the message data + */ + message_data = (help_full_message_request *)message; + window = message_data->w; + icon = message_data->i; + + /* Check if we have a browser window, toolbar window or status window + */ + g = ro_gui_window_lookup(window); + if (g) { + if (g->window == window) { + sprintf(message_token, "HelpB%i", (int)icon); + } else if ((g->data.browser.toolbar) && + (g->data.browser.toolbar->toolbar_handle == window)) { + sprintf(message_token, "HelpT%i", (int)icon); + } else if ((g->data.browser.toolbar) && + (g->data.browser.toolbar->status_handle == window)) { + sprintf(message_token, "HelpS%i", (int)icon); + } + } + + /* If we've managed to find something so far then we broadcast it + */ + if (message_token[0] != 0x00) { + ro_gui_interactive_help_broadcast(message, &message_token[0]); + return; + } + + /* As a last resort, check for menu help. + */ + if (xwimp_get_menu_state((wimp_menu_state_flags)1, + &menu_tree, + window, icon)) return; + if (menu_tree.items[0] == -1) return; + + /* Set the prefix + */ + if (current_menu == iconbar_menu) { + sprintf(message_token, "HelpI"); + } else if (current_menu == browser_menu) { + sprintf(message_token, "HelpM"); + } else { + return; + } + + /* Decode the menu + */ + index = 0; + while (menu_tree.items[index] != -1) { + if (index == 0) { + sprintf(menu_buffer, "%i", menu_tree.items[index]); + } else { + sprintf(menu_buffer, "-%i", menu_tree.items[index]); + } + strcat(message_token, menu_buffer); + index++; + } + + /* Finally, broadcast the menu help + */ + ro_gui_interactive_help_broadcast(message, &message_token[0]); +} + + +/** + * Broadcasts a help reply + * + * \param message the original request message + * \param token the token to look up + */ +static void ro_gui_interactive_help_broadcast(wimp_message *message, char *token) { + char *translated_token; + help_full_message_reply *reply; + + /* Check if the message exists + */ + translated_token = (char *)messages_get(token); + if (translated_token == token) return; + + /* Copy our message string + */ + reply = (help_full_message_reply *)message; + reply->reply[235] = 0; + strncpy(reply->reply, translated_token, 235); + + /* Broadcast the help reply + */ + reply->size = 256; + reply->action = message_HELP_REPLY; + reply->your_ref = reply->my_ref; + wimp_send_message(wimp_USER_MESSAGE, reply, reply->sender); +} diff --git a/riscos/help.h b/riscos/help.h new file mode 100644 index 000000000..bdf9847ab --- /dev/null +++ b/riscos/help.h @@ -0,0 +1,19 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 Richard Wilson + */ + +/** \file + * Interactive help (interface). + */ + +#ifndef _NETSURF_RISCOS_HELP_H_ +#define _NETSURF_RISCOS_HELP_H_ + +#include "oslib/wimp.h" + +void ro_gui_interactive_help_request(wimp_message *message); + +#endif diff --git a/riscos/menus.c b/riscos/menus.c index 41f08007b..5ad303cb4 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -45,7 +45,7 @@ static void ro_gui_menu_pageinfo(wimp_message_menu_warning *warning); static void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning); static struct box *ro_gui_menu_find_object_box(void); -static wimp_menu *current_menu; +wimp_menu *current_menu; static int current_menu_x, current_menu_y; gui_window *current_gui; struct content *save_content = 0; -- cgit v1.2.3