NetSurf
Data Structures | Macros | Functions | Variables
menus.c File Reference

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"
Include dependency graph for menus.c:

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_definitionro_gui_menu_find_menu (wimp_menu *menu)
 Finds the menu_definition corresponding to a wimp_menu. More...
 
static struct menu_definition_entryro_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_definitionro_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
 

Detailed Description

Menu creation and handling implementation.

Definition in file menus.c.

Macro Definition Documentation

◆ DEFAULT_FLAGS

#define DEFAULT_FLAGS
Value:
(wimp_ICON_TEXT | wimp_ICON_FILLED | \
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | \
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))

Definition at line 89 of file menus.c.

◆ IS_MENU

#define IS_MENU (   menu)    !((int)(menu) & 1)

Definition at line 110 of file menus.c.

Function Documentation

◆ ro_gui_menu_closed()

static void ro_gui_menu_closed ( void  )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_create()

void ro_gui_menu_create ( wimp_menu *  menu,
int  x,
int  y,
wimp_w  w 
)

Display a menu.

Parameters
*menuPointer to the menu to be displayed.
xThe x position.
yThe y position.
wThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_define_menu()

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.

Parameters
menuThe data to create the menu with
Returns
The menu created, or NULL on failure

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_define_menu_add()

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 
)
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()

Parameters
definitionTop level menu definition
menuMenu declaration data
depthDepth of menu we're currently building
parent_entryEntry in parent menu, or NULL if root menu
firstFirst index in declaration data that is used by this menu
lastLast index in declaration data that is used by this menu
prefixPrefix pf menu declaration string already seen
prefix_lengthLength 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_destroy()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_find_action()

menu_action ro_gui_menu_find_action ( wimp_menu *  menu,
wimp_menu_entry *  menu_entry 
)
static

Finds the action corresponding to a wimp_menu_entry for a wimp_menu.

Parameters
menuthe menu to search for an action within
menu_entrythe menu_entry to find
Returns
the associated action, or 0 if one could not be found

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_find_entry()

struct menu_definition_entry * ro_gui_menu_find_entry ( wimp_menu *  menu,
menu_action  action 
)
static

Finds the menu_definition_entry corresponding to an action for a wimp_menu.

Parameters
menuthe menu to search for an action within
actionthe action to find
Returns
the associated menu entry, or NULL if one could not be found

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_find_menu()

struct menu_definition * ro_gui_menu_find_menu ( wimp_menu *  menu)
static

Finds the menu_definition corresponding to a wimp_menu.

Parameters
menuthe menu to find the definition for
Returns
the associated definition, or NULL if one could not be found

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().

Here is the caller graph for this function:

◆ ro_gui_menu_find_menu_entry_key()

const char * ro_gui_menu_find_menu_entry_key ( wimp_menu *  menu,
const char *  translated 
)

Finds the key associated with a menu entry translation.

Parameters
menuthe menu to search
translatedthe translated text
Returns
the original message key, or NULL if one could not be found

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_get_checksum()

int ro_gui_menu_get_checksum ( void  )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_init()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_init_structure()

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().

Here is the caller graph for this function:

◆ ro_gui_menu_message_deleted()

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.

Parameters
*deletedThe message block.

Definition at line 442 of file menus.c.

References current_menu, and ro_gui_menu_closed().

Referenced by ro_gui_user_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_refresh()

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.

Parameters
*menuThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_selection()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_set_entry_shaded()

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.

Parameters
menuthe menu containing the action
actionthe action to tick/untick
shadedwhether 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_set_entry_ticked()

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.

Parameters
menuthe menu containing the action
actionthe action to tick/untick
tickedwhether 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_translate()

bool ro_gui_menu_translate ( struct menu_definition menu)
static

Translate a menu's textual content into the system local encoding.

Parameters
menuThe menu to translate
Returns
false if out of memory, true otherwise

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_warning()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_menu_window_changed()

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.

Parameters
fromThe original window handle.
toThe 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().

Here is the caller graph for this function:

◆ ro_gui_popup_menu()

void ro_gui_popup_menu ( wimp_menu *  menu,
wimp_w  w,
wimp_i  i 
)

Display a pop-up menu next to the specified icon.

Parameters
menumenu to open
wwindow handle
iicon 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().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ current_menu

wimp_menu* current_menu

◆ current_menu_icon

wimp_i current_menu_icon
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().

◆ current_menu_open

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().

◆ current_menu_window

wimp_w current_menu_window

◆ image_quality_menu

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().

◆ languages_menu

wimp_menu * languages_menu

◆ proxy_type_menu

wimp_menu * proxy_type_menu

◆ ro_gui_menu_definitions

struct menu_definition* ro_gui_menu_definitions
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().