NetSurf
|
Menu creation and handling implementation. More...
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "oslib/os.h"
#include "oslib/osbyte.h"
#include "oslib/osgbpb.h"
#include "oslib/territory.h"
#include "oslib/wimp.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utf8.h"
#include "desktop/cookie_manager.h"
#include "riscos/dialog.h"
#include "riscos/configure.h"
#include "riscos/cookies.h"
#include "riscos/gui.h"
#include "riscos/global_history.h"
#include "riscos/help.h"
#include "riscos/hotlist.h"
#include "riscos/menus.h"
#include "utils/nsoption.h"
#include "riscos/save.h"
#include "riscos/tinct.h"
#include "riscos/toolbar.h"
#include "riscos/url_suggest.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/ucstables.h"
Go to the source code of this file.
Data Structures | |
struct | menu_definition_entry |
struct | menu_definition |
Macros | |
#define | DEFAULT_FLAGS |
#define | IS_MENU(menu) !((int)(menu) & 1) |
Functions | |
static void | ro_gui_menu_closed (void) |
Clean up after a menu has been closed, or forcibly close an open menu. More... | |
static void | ro_gui_menu_define_menu_add (struct menu_definition *definition, const struct ns_menu *menu, int depth, wimp_menu_entry *parent_entry, int first, int last, const char *prefix, int prefix_length) |
Create a wimp menu tree from ns_menu data. More... | |
static struct menu_definition * | ro_gui_menu_find_menu (wimp_menu *menu) |
Finds the menu_definition corresponding to a wimp_menu. More... | |
static struct menu_definition_entry * | ro_gui_menu_find_entry (wimp_menu *menu, menu_action action) |
Finds the menu_definition_entry corresponding to an action for a wimp_menu. More... | |
static menu_action | ro_gui_menu_find_action (wimp_menu *menu, wimp_menu_entry *menu_entry) |
Finds the action corresponding to a wimp_menu_entry for a wimp_menu. More... | |
static int | ro_gui_menu_get_checksum (void) |
Calculates a simple checksum for the current menu state. More... | |
static bool | ro_gui_menu_translate (struct menu_definition *menu) |
Translate a menu's textual content into the system local encoding. More... | |
void | ro_gui_menu_init (void) |
Create menu structures. More... | |
void | ro_gui_menu_create (wimp_menu *menu, int x, int y, wimp_w w) |
Display a menu. More... | |
void | ro_gui_popup_menu (wimp_menu *menu, wimp_w w, wimp_i i) |
Display a pop-up menu next to the specified icon. More... | |
void | ro_gui_menu_destroy (void) |
Forcibly close any menu or transient dialogue box that is currently open. More... | |
void | ro_gui_menu_window_changed (wimp_w from, wimp_w to) |
Allow the current menu window to change, if the window is deleted and recreated while a menu is active on an Adjust-click. More... | |
void | ro_gui_menu_selection (wimp_selection *selection) |
Handle menu selection. More... | |
void | ro_gui_menu_warning (wimp_message_menu_warning *warning) |
Handle Message_MenuWarning. More... | |
void | ro_gui_menu_message_deleted (wimp_message_menus_deleted *deleted) |
Handle Message_MenusDeleted, removing our current record of an open menu if it matches the deleted menu handle. More... | |
void | ro_gui_menu_refresh (wimp_menu *menu) |
Update the current menu by sending it a Menu Prepare event through wimp_event and then reopening it if the contents has changed. More... | |
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. More... | |
void | ro_gui_menu_init_structure (wimp_menu *menu, int entries) |
Initialise the basic state of a menu structure so all entries are indirected text with no flags, no submenu. More... | |
const char * | ro_gui_menu_find_menu_entry_key (wimp_menu *menu, const char *translated) |
Finds the key associated with a menu entry translation. More... | |
void | ro_gui_menu_set_entry_shaded (wimp_menu *menu, menu_action action, bool shaded) |
Sets an action within a menu as having a specific ticked status. More... | |
void | ro_gui_menu_set_entry_ticked (wimp_menu *menu, menu_action action, bool ticked) |
Sets an action within a menu as having a specific ticked status. More... | |
Variables | |
static struct menu_definition * | ro_gui_menu_definitions |
The currently defined menus to perform actions for. More... | |
wimp_menu * | current_menu |
The current menu being worked with (may not be open) More... | |
bool | current_menu_open = false |
Whether a menu is currently open. More... | |
wimp_w | current_menu_window |
Window that owns the current menu. More... | |
static wimp_i | current_menu_icon |
Icon that owns the current menu (only valid for popup menus) More... | |
wimp_menu * | image_quality_menu |
The available menus. More... | |
wimp_menu * | proxy_type_menu |
wimp_menu * | languages_menu |
Menu creation and handling implementation.
Definition in file menus.c.
#define DEFAULT_FLAGS |
|
static |
Clean up after a menu has been closed, or forcibly close an open menu.
Definition at line 453 of file menus.c.
References current_menu, current_menu_icon, current_menu_open, current_menu_window, and ro_gui_wimp_event_menus_closed().
Referenced by ro_gui_menu_create(), ro_gui_menu_destroy(), ro_gui_menu_message_deleted(), and ro_gui_menu_selection().
void ro_gui_menu_create | ( | wimp_menu * | menu, |
int | x, | ||
int | y, | ||
wimp_w | w | ||
) |
Display a menu.
*menu | Pointer to the menu to be displayed. |
x | The x position. |
y | The y position. |
w | The window that the menu belongs to. |
Definition at line 211 of file menus.c.
References current_menu, current_menu_icon, current_menu_open, current_menu_window, menu_definition::menu, NSLOG, ro_gui_menu_closed(), ro_gui_menu_find_menu(), ro_gui_menu_translate(), and ro_warn_user().
Referenced by gui_window_create_form_select_menu(), ro_gui_menu_selection(), ro_gui_popup_menu(), and ro_gui_wimp_event_process_window_menu_click().
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.
menu | The data to create the menu with |
Definition at line 510 of file menus.c.
References die(), menu_definition::menu, menu_definition::next, ro_gui_menu_define_menu_add(), ro_gui_menu_definitions, and ro_gui_menu_translate().
Referenced by ro_cookie_init(), ro_global_history_init(), ro_gui_iconbar_initialise(), ro_gui_menu_init(), ro_gui_window_initialise(), ro_hotlist_init(), and ro_toolbar_init().
|
static |
Create a wimp menu tree from ns_menu data.
This function does not deal with the menu textual content - it simply creates and populates the appropriate structures. Textual content is generated by ro_gui_menu_translate_menu()
definition | Top level menu definition |
menu | Menu declaration data |
depth | Depth of menu we're currently building |
parent_entry | Entry in parent menu, or NULL if root menu |
first | First index in declaration data that is used by this menu |
last | Last index in declaration data that is used by this menu |
prefix | Prefix pf menu declaration string already seen |
prefix_length | Length of prefix |
Definition at line 555 of file menus.c.
References menu_definition_entry::action, ns_menu_entry::action, menu_definition::current_encoding, die(), menu_definition::entries, ns_menu::entries, menu_definition_entry::entry_key, menu_definition::menu, menu_definition_entry::menu_entry, menu_definition_entry::next, ro_gui_menu_define_menu_add(), ro_gui_menu_init_structure(), ns_menu_entry::sub_window, ns_menu_entry::text, text(), ns_menu::title, and menu_definition::title_key.
Referenced by ro_gui_menu_define_menu(), and ro_gui_menu_define_menu_add().
void ro_gui_menu_destroy | ( | void | ) |
Forcibly close any menu or transient dialogue box that is currently open.
Definition at line 288 of file menus.c.
References current_menu, NSLOG, ro_gui_menu_closed(), and ro_warn_user().
Referenced by gui_window_create_form_select_menu(), gui_window_destroy(), ro_gui_wimp_event_keypress(), ro_gui_wimp_event_mouse_click(), ro_gui_wimp_event_ok_click(), ro_gui_window_prepare_form_select_menu(), and ro_print_cleanup().
|
static |
Finds the action corresponding to a wimp_menu_entry for a wimp_menu.
menu | the menu to search for an action within |
menu_entry | the menu_entry to find |
Definition at line 781 of file menus.c.
References menu_definition_entry::action, menu_definition::entries, menu_definition::menu, menu_definition_entry::menu_entry, menu_definition_entry::next, NO_ACTION, and ro_gui_menu_find_menu().
Referenced by ro_gui_menu_selection(), and ro_gui_menu_warning().
|
static |
Finds the menu_definition_entry corresponding to an action for a wimp_menu.
menu | the menu to search for an action within |
action | the action to find |
Definition at line 758 of file menus.c.
References menu_definition_entry::action, menu_definition::entries, menu_definition::menu, menu_definition_entry::next, and ro_gui_menu_find_menu().
Referenced by ro_gui_menu_set_entry_ticked().
|
static |
Finds the menu_definition corresponding to a wimp_menu.
menu | the menu to find the definition for |
Definition at line 713 of file menus.c.
References menu_definition::menu, menu_definition::next, and ro_gui_menu_definitions.
Referenced by ro_gui_menu_create(), ro_gui_menu_find_action(), ro_gui_menu_find_entry(), ro_gui_menu_find_menu_entry_key(), and ro_gui_menu_set_entry_shaded().
const char * ro_gui_menu_find_menu_entry_key | ( | wimp_menu * | menu, |
const char * | translated | ||
) |
Finds the key associated with a menu entry translation.
menu | the menu to search |
translated | the translated text |
Definition at line 735 of file menus.c.
References menu_definition::entries, menu_definition_entry::entry_key, menu_definition::menu, menu_definition_entry::menu_entry, menu_definition_entry::next, and ro_gui_menu_find_menu().
Referenced by ro_gui_options_language_ok().
|
static |
Calculates a simple checksum for the current menu state.
Definition at line 848 of file menus.c.
References current_menu, current_menu_open, IS_MENU, NSLOG, and ro_warn_user().
Referenced by ro_gui_menu_refresh().
void ro_gui_menu_init | ( | void | ) |
Create menu structures.
Definition at line 116 of file menus.c.
References image_quality_menu, languages_menu, NO_ACTION, proxy_type_menu, ro_gui_menu_define_menu(), and ro_gui_url_suggest_init().
Referenced by gui_init().
void ro_gui_menu_init_structure | ( | wimp_menu * | menu, |
int | entries | ||
) |
Initialise the basic state of a menu structure so all entries are indirected text with no flags, no submenu.
Definition at line 682 of file menus.c.
References DEFAULT_FLAGS.
Referenced by ro_gui_menu_define_menu_add(), ro_gui_options_fonts_init_menu(), ro_gui_search_init(), ro_gui_window_prepare_form_select_menu(), and wimp_MENU().
void ro_gui_menu_message_deleted | ( | wimp_message_menus_deleted * | deleted | ) |
Handle Message_MenusDeleted, removing our current record of an open menu if it matches the deleted menu handle.
*deleted | The message block. |
Definition at line 442 of file menus.c.
References current_menu, and ro_gui_menu_closed().
Referenced by ro_gui_user_message().
void ro_gui_menu_refresh | ( | wimp_menu * | menu | ) |
Update the current menu by sending it a Menu Prepare event through wimp_event and then reopening it if the contents has changed.
*menu | The menu to refresh: if 0, the current menu will be refreshed regardless, otherwise it will be refreshed only if it matches the supplied handle. |
Definition at line 475 of file menus.c.
References current_menu, current_menu_icon, current_menu_open, current_menu_window, NSLOG, ro_gui_menu_get_checksum(), ro_gui_wimp_event_prepare_menu(), and ro_warn_user().
Referenced by gui_window_new_content(), gui_window_start_throbber(), and gui_window_stop_throbber().
void ro_gui_menu_selection | ( | wimp_selection * | selection | ) |
Handle menu selection.
Definition at line 326 of file menus.c.
References current_menu, current_menu_icon, current_menu_window, menu_definition::entries, NSLOG, ro_gui_menu_closed(), ro_gui_menu_create(), ro_gui_menu_find_action(), ro_gui_wimp_event_menu_selection(), and ro_warn_user().
Referenced by ro_gui_handle_event().
void ro_gui_menu_set_entry_shaded | ( | wimp_menu * | menu, |
menu_action | action, | ||
bool | shaded | ||
) |
Sets an action within a menu as having a specific ticked status.
menu | the menu containing the action |
action | the action to tick/untick |
shaded | whether to set the item as shaded |
Definition at line 804 of file menus.c.
References menu_definition_entry::action, menu_definition::entries, menu_definition::menu, menu_definition_entry::menu_entry, menu_definition_entry::next, and ro_gui_menu_find_menu().
Referenced by cookie_menu_prepare(), global_history_menu_prepare(), hotlist_menu_prepare(), ro_gui_window_menu_prepare(), and ro_toolbar_menu_prepare().
void ro_gui_menu_set_entry_ticked | ( | wimp_menu * | menu, |
menu_action | action, | ||
bool | ticked | ||
) |
Sets an action within a menu as having a specific ticked status.
menu | the menu containing the action |
action | the action to tick/untick |
ticked | whether to set the item as ticked |
Definition at line 831 of file menus.c.
References menu_definition_entry::action, menu_definition_entry::menu_entry, and ro_gui_menu_find_entry().
Referenced by cookie_menu_prepare(), global_history_menu_prepare(), hotlist_menu_prepare(), ro_gui_window_menu_prepare(), and ro_toolbar_menu_prepare().
|
static |
Translate a menu's textual content into the system local encoding.
menu | The menu to translate |
Definition at line 894 of file menus.c.
References menu_definition::current_encoding, menu_definition::entries, menu_definition_entry::entry_key, IS_MENU, menu_definition::menu, menu_definition_entry::menu_entry, messages_get(), menu_definition_entry::next, NSERROR_BAD_ENCODING, NSERROR_OK, NSLOG, menu_definition::title_key, and utf8_to_local_encoding().
Referenced by ro_gui_menu_create(), and ro_gui_menu_define_menu().
void ro_gui_menu_warning | ( | wimp_message_menu_warning * | warning | ) |
Handle Message_MenuWarning.
Definition at line 381 of file menus.c.
References current_menu, current_menu_icon, current_menu_window, menu_definition::entries, IS_MENU, NSLOG, ro_gui_menu_find_action(), ro_gui_wimp_event_register_submenu(), ro_gui_wimp_event_submenu_warning(), ro_gui_wimp_update_window_furniture(), and ro_warn_user().
Referenced by ro_gui_user_message().
void ro_gui_menu_window_changed | ( | wimp_w | from, |
wimp_w | to | ||
) |
Allow the current menu window to change, if the window is deleted and recreated while a menu is active on an Adjust-click.
from | The original window handle. |
to | The new replacement window handle. |
Definition at line 314 of file menus.c.
References current_menu_window, from, and to.
Referenced by ro_gui_wimp_event_transfer().
void ro_gui_popup_menu | ( | wimp_menu * | menu, |
wimp_w | w, | ||
wimp_i | i | ||
) |
Display a pop-up menu next to the specified icon.
menu | menu to open |
w | window handle |
i | icon handle |
Definition at line 251 of file menus.c.
References current_menu_icon, menu_definition::menu, NSLOG, ro_gui_menu_create(), and ro_warn_user().
Referenced by ro_gui_wimp_event_mouse_click().
wimp_menu* current_menu |
The current menu being worked with (may not be open)
Definition at line 96 of file menus.c.
Referenced by ro_gui_interactive_help_request(), ro_gui_menu_closed(), ro_gui_menu_create(), ro_gui_menu_destroy(), ro_gui_menu_get_checksum(), ro_gui_menu_message_deleted(), ro_gui_menu_refresh(), ro_gui_menu_selection(), ro_gui_menu_warning(), and ro_gui_wimp_event_mouse_click().
|
static |
Icon that owns the current menu (only valid for popup menus)
Definition at line 102 of file menus.c.
Referenced by ro_gui_menu_closed(), ro_gui_menu_create(), ro_gui_menu_refresh(), ro_gui_menu_selection(), ro_gui_menu_warning(), and ro_gui_popup_menu().
bool current_menu_open = false |
Whether a menu is currently open.
Definition at line 98 of file menus.c.
Referenced by ro_gui_menu_closed(), ro_gui_menu_create(), ro_gui_menu_get_checksum(), and ro_gui_menu_refresh().
wimp_w current_menu_window |
Window that owns the current menu.
Definition at line 100 of file menus.c.
Referenced by gui_window_destroy(), ro_gui_menu_closed(), ro_gui_menu_create(), ro_gui_menu_refresh(), ro_gui_menu_selection(), ro_gui_menu_warning(), ro_gui_menu_window_changed(), and ro_gui_wimp_event_mouse_click().
wimp_menu* image_quality_menu |
The available menus.
Definition at line 104 of file menus.c.
Referenced by ro_gui_menu_init(), ro_gui_options_image_click(), ro_gui_options_image_initialise(), and ro_gui_options_image_read().
wimp_menu * languages_menu |
Definition at line 104 of file menus.c.
Referenced by ro_gui_menu_init(), ro_gui_options_language_initialise(), and ro_gui_options_language_ok().
wimp_menu * proxy_type_menu |
Definition at line 104 of file menus.c.
Referenced by ro_gui_menu_init(), ro_gui_options_connection_default(), ro_gui_options_connection_initialise(), and ro_gui_options_connection_proxy_type().
|
static |
The currently defined menus to perform actions for.
Definition at line 94 of file menus.c.
Referenced by ro_gui_menu_define_menu(), and ro_gui_menu_find_menu().