2003-08-22 01:39:07 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2005-02-25 01:00:41 +03:00
|
|
|
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
2003-08-22 01:39:07 +04:00
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2005-02-07 17:28:43 +03:00
|
|
|
* Copyright 2005 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2003-08-22 01:39:07 +04:00
|
|
|
*/
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/** \file
|
|
|
|
* Menu creation and handling (implementation).
|
|
|
|
*/
|
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
#include <ctype.h>
|
2003-08-22 01:39:07 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-05-14 23:59:09 +04:00
|
|
|
#include "oslib/os.h"
|
2005-07-16 18:35:25 +04:00
|
|
|
#include "oslib/osbyte.h"
|
2004-07-28 00:44:46 +04:00
|
|
|
#include "oslib/osgbpb.h"
|
2005-07-16 18:35:25 +04:00
|
|
|
#include "oslib/territory.h"
|
2003-08-22 01:39:07 +04:00
|
|
|
#include "oslib/wimp.h"
|
2010-04-07 16:45:18 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/cookies.h"
|
2010-06-04 13:35:08 +04:00
|
|
|
#include "desktop/browser.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/gui.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/history_global_core.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/history_core.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/netsurf.h"
|
2009-01-30 08:08:54 +03:00
|
|
|
#include "desktop/selection.h"
|
2009-02-01 05:19:01 +03:00
|
|
|
#include "desktop/textinput.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#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"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/menus.h"
|
2012-03-22 13:34:34 +04:00
|
|
|
#include "desktop/options.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/save.h"
|
|
|
|
#include "riscos/tinct.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "riscos/toolbar.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/treeview.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/url_suggest.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/utf8.h"
|
2003-08-22 01:39:07 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry {
|
|
|
|
menu_action action; /**< menu action */
|
|
|
|
wimp_menu_entry *menu_entry; /**< corresponding menu entry */
|
2005-07-16 18:35:25 +04:00
|
|
|
const char *entry_key; /**< Messages key for entry text */
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry *next; /**< next menu entry */
|
2004-07-04 22:44:51 +04:00
|
|
|
};
|
2004-11-03 02:23:07 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition {
|
|
|
|
wimp_menu *menu; /**< corresponding menu */
|
2005-07-16 18:35:25 +04:00
|
|
|
const char *title_key; /**< Messages key for title text */
|
|
|
|
int current_encoding; /**< Identifier for current text encoding of menu text (as per OS_Byte,71,127) */
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry *entries; /**< menu entries */
|
|
|
|
struct menu_definition *next; /**< next menu */
|
2004-10-05 03:54:42 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
static void ro_gui_menu_define_menu_add(struct menu_definition *definition,
|
2009-03-29 04:14:28 +04:00
|
|
|
const struct ns_menu *menu, int depth,
|
2005-07-16 18:35:25 +04:00
|
|
|
wimp_menu_entry *parent_entry,
|
2005-04-08 00:46:22 +04:00
|
|
|
int first, int last, const char *prefix, int prefix_length);
|
|
|
|
static struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu);
|
|
|
|
static struct menu_definition_entry *ro_gui_menu_find_entry(wimp_menu *menu,
|
|
|
|
menu_action action);
|
|
|
|
static menu_action ro_gui_menu_find_action(wimp_menu *menu,
|
|
|
|
wimp_menu_entry *menu_entry);
|
|
|
|
static int ro_gui_menu_get_checksum(void);
|
2005-07-16 18:35:25 +04:00
|
|
|
static bool ro_gui_menu_translate(struct menu_definition *menu);
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* default menu item flags */
|
|
|
|
#define DEFAULT_FLAGS (wimp_ICON_TEXT | wimp_ICON_FILLED | \
|
|
|
|
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | \
|
|
|
|
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))
|
2004-07-04 22:44:51 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/** The currently defined menus to perform actions for */
|
|
|
|
static struct menu_definition *ro_gui_menu_definitions;
|
|
|
|
/** The current menu being worked with (may not be open) */
|
|
|
|
wimp_menu *current_menu;
|
|
|
|
/** Whether a menu is currently open */
|
2005-12-31 07:40:49 +03:00
|
|
|
bool current_menu_open = false;
|
2005-04-08 00:46:22 +04:00
|
|
|
/** Window that owns the current menu */
|
2005-12-31 07:40:49 +03:00
|
|
|
wimp_w current_menu_window;
|
|
|
|
/** Icon that owns the current menu (only valid for popup menus) */
|
|
|
|
static wimp_i current_menu_icon;
|
2005-04-08 00:46:22 +04:00
|
|
|
/** The available menus */
|
2011-02-21 02:16:33 +03:00
|
|
|
wimp_menu *image_quality_menu, *proxy_type_menu, *languages_menu;
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* the values given in PRM 3-157 for how to check menus/windows are
|
2005-11-28 03:20:15 +03:00
|
|
|
* incorrect so we use a hack of checking if the sub-menu has bit 0
|
|
|
|
* set which is undocumented but true of window handles on
|
|
|
|
* all target OS versions */
|
2005-12-31 07:40:49 +03:00
|
|
|
#define IS_MENU(menu) !((int)(menu) & 1)
|
2005-11-28 03:20:15 +03:00
|
|
|
|
2003-08-22 01:39:07 +04:00
|
|
|
/**
|
|
|
|
* Create menu structures.
|
|
|
|
*/
|
2005-07-16 18:35:25 +04:00
|
|
|
void ro_gui_menu_init(void)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
/* image quality menu */
|
2009-03-29 04:14:28 +04:00
|
|
|
static const struct ns_menu images_definition = {
|
2005-04-08 00:46:22 +04:00
|
|
|
"Display", {
|
|
|
|
{ "ImgStyle0", NO_ACTION, 0 },
|
|
|
|
{ "ImgStyle1", NO_ACTION, 0 },
|
|
|
|
{ "ImgStyle2", NO_ACTION, 0 },
|
|
|
|
{ "ImgStyle3", NO_ACTION, 0 },
|
|
|
|
{NULL, 0, 0}
|
|
|
|
}
|
|
|
|
};
|
2009-03-29 04:14:28 +04:00
|
|
|
image_quality_menu = ro_gui_menu_define_menu(&images_definition);
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
/* proxy menu */
|
2009-03-29 04:14:28 +04:00
|
|
|
static const struct ns_menu proxy_type_definition = {
|
2006-04-07 02:42:22 +04:00
|
|
|
"ProxyType", {
|
2005-04-08 00:46:22 +04:00
|
|
|
{ "ProxyNone", NO_ACTION, 0 },
|
2006-04-07 02:42:22 +04:00
|
|
|
{ "ProxyNoAuth", NO_ACTION, 0 },
|
2005-04-08 00:46:22 +04:00
|
|
|
{ "ProxyBasic", NO_ACTION, 0 },
|
|
|
|
{ "ProxyNTLM", NO_ACTION, 0 },
|
|
|
|
{NULL, 0, 0}
|
|
|
|
}
|
|
|
|
};
|
2009-03-29 04:14:28 +04:00
|
|
|
proxy_type_menu = ro_gui_menu_define_menu(&proxy_type_definition);
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
/* special case menus */
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_url_suggest_init();
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* Note: This table *must* be kept in sync with the LangNames file */
|
2009-03-29 04:14:28 +04:00
|
|
|
static const struct ns_menu lang_definition = {
|
2005-07-16 18:35:25 +04:00
|
|
|
"Languages", {
|
|
|
|
{ "lang_af", NO_ACTION, 0 },
|
|
|
|
{ "lang_bm", NO_ACTION, 0 },
|
|
|
|
{ "lang_ca", NO_ACTION, 0 },
|
|
|
|
{ "lang_cs", NO_ACTION, 0 },
|
|
|
|
{ "lang_cy", NO_ACTION, 0 },
|
|
|
|
{ "lang_da", NO_ACTION, 0 },
|
|
|
|
{ "lang_de", NO_ACTION, 0 },
|
|
|
|
{ "lang_en", NO_ACTION, 0 },
|
|
|
|
{ "lang_es", NO_ACTION, 0 },
|
|
|
|
{ "lang_et", NO_ACTION, 0 },
|
|
|
|
{ "lang_eu", NO_ACTION, 0 },
|
|
|
|
{ "lang_ff", NO_ACTION, 0 },
|
|
|
|
{ "lang_fi", NO_ACTION, 0 },
|
|
|
|
{ "lang_fr", NO_ACTION, 0 },
|
|
|
|
{ "lang_ga", NO_ACTION, 0 },
|
|
|
|
{ "lang_gl", NO_ACTION, 0 },
|
|
|
|
{ "lang_ha", NO_ACTION, 0 },
|
|
|
|
{ "lang_hr", NO_ACTION, 0 },
|
|
|
|
{ "lang_hu", NO_ACTION, 0 },
|
|
|
|
{ "lang_id", NO_ACTION, 0 },
|
|
|
|
{ "lang_is", NO_ACTION, 0 },
|
|
|
|
{ "lang_it", NO_ACTION, 0 },
|
|
|
|
{ "lang_lt", NO_ACTION, 0 },
|
|
|
|
{ "lang_lv", NO_ACTION, 0 },
|
|
|
|
{ "lang_ms", NO_ACTION, 0 },
|
|
|
|
{ "lang_mt", NO_ACTION, 0 },
|
|
|
|
{ "lang_nl", NO_ACTION, 0 },
|
|
|
|
{ "lang_no", NO_ACTION, 0 },
|
|
|
|
{ "lang_pl", NO_ACTION, 0 },
|
|
|
|
{ "lang_pt", NO_ACTION, 0 },
|
|
|
|
{ "lang_rn", NO_ACTION, 0 },
|
|
|
|
{ "lang_ro", NO_ACTION, 0 },
|
|
|
|
{ "lang_rw", NO_ACTION, 0 },
|
|
|
|
{ "lang_sk", NO_ACTION, 0 },
|
|
|
|
{ "lang_sl", NO_ACTION, 0 },
|
|
|
|
{ "lang_so", NO_ACTION, 0 },
|
|
|
|
{ "lang_sq", NO_ACTION, 0 },
|
|
|
|
{ "lang_sr", NO_ACTION, 0 },
|
|
|
|
{ "lang_sv", NO_ACTION, 0 },
|
|
|
|
{ "lang_sw", NO_ACTION, 0 },
|
|
|
|
{ "lang_tr", NO_ACTION, 0 },
|
|
|
|
{ "lang_uz", NO_ACTION, 0 },
|
|
|
|
{ "lang_vi", NO_ACTION, 0 },
|
|
|
|
{ "lang_wo", NO_ACTION, 0 },
|
|
|
|
{ "lang_xs", NO_ACTION, 0 },
|
|
|
|
{ "lang_yo", NO_ACTION, 0 },
|
|
|
|
{ "lang_zu", NO_ACTION, 0 },
|
|
|
|
{ NULL, 0, 0 }
|
|
|
|
}
|
|
|
|
};
|
2009-03-29 04:14:28 +04:00
|
|
|
languages_menu = ro_gui_menu_define_menu(&lang_definition);
|
2004-07-28 00:44:46 +04:00
|
|
|
}
|
2003-08-22 01:39:07 +04:00
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a menu.
|
2010-10-25 03:17:21 +04:00
|
|
|
*
|
|
|
|
* \param *menu Pointer to the menu to be displayed.
|
|
|
|
* \param x The x position.
|
|
|
|
* \param y The y position.
|
|
|
|
* \param w The window that the menu belongs to.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2011-02-21 02:16:33 +03:00
|
|
|
void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2004-07-18 21:38:01 +04:00
|
|
|
os_error *error;
|
2005-07-16 18:35:25 +04:00
|
|
|
struct menu_definition *definition;
|
|
|
|
|
|
|
|
/* translate menu, if necessary (this returns quickly
|
|
|
|
* if there's nothing to be done) */
|
|
|
|
definition = ro_gui_menu_find_menu(menu);
|
|
|
|
if (definition) {
|
|
|
|
if (!ro_gui_menu_translate(definition)) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 21:38:01 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/* store the menu characteristics */
|
|
|
|
current_menu = menu;
|
|
|
|
current_menu_window = w;
|
2011-02-21 02:16:33 +03:00
|
|
|
current_menu_icon = wimp_ICON_WINDOW;
|
2004-07-18 21:38:01 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/* create the menu */
|
|
|
|
current_menu_open = true;
|
2004-07-18 21:38:01 +04:00
|
|
|
error = xwimp_create_menu(menu, x - 64, y);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_menu_closed();
|
2004-07-18 21:38:01 +04:00
|
|
|
}
|
2003-08-22 01:39:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-19 03:40:28 +03:00
|
|
|
/**
|
|
|
|
* Display a pop-up menu next to the specified icon.
|
2005-02-25 01:00:41 +03:00
|
|
|
*
|
|
|
|
* \param menu menu to open
|
2005-04-08 00:46:22 +04:00
|
|
|
* \param w window handle
|
|
|
|
* \param i icon handle
|
2003-12-19 03:40:28 +03:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i)
|
|
|
|
{
|
2003-12-27 03:11:57 +03:00
|
|
|
wimp_window_state state;
|
|
|
|
wimp_icon_state icon_state;
|
2005-02-25 01:00:41 +03:00
|
|
|
os_error *error;
|
|
|
|
|
2003-12-27 03:11:57 +03:00
|
|
|
state.w = w;
|
|
|
|
icon_state.w = w;
|
|
|
|
icon_state.i = i;
|
2005-02-25 01:00:41 +03:00
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_window_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xwimp_get_icon_state(&icon_state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_icon_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2006-01-08 04:51:33 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
ro_gui_menu_create(menu,
|
2004-07-18 21:38:01 +04:00
|
|
|
state.visible.x0 + icon_state.icon.extent.x1 + 64,
|
2005-02-25 01:00:41 +03:00
|
|
|
state.visible.y1 + icon_state.icon.extent.y1 -
|
2011-02-21 02:16:33 +03:00
|
|
|
state.yscroll, w);
|
2005-12-31 07:40:49 +03:00
|
|
|
current_menu_icon = i;
|
2003-12-19 03:40:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-22 01:39:07 +04:00
|
|
|
/**
|
2005-04-08 00:46:22 +04:00
|
|
|
* Clean up after a menu has been closed, or forcible close an open menu.
|
2011-02-21 02:16:33 +03:00
|
|
|
*/
|
|
|
|
void ro_gui_menu_closed(void)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2004-06-27 19:34:46 +04:00
|
|
|
os_error *error;
|
2003-08-22 01:39:07 +04:00
|
|
|
|
2005-04-28 21:15:29 +04:00
|
|
|
if (current_menu) {
|
|
|
|
error = xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
ro_gui_wimp_event_menus_closed(current_menu_window,
|
|
|
|
current_menu_icon, current_menu);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
current_menu = NULL;
|
2003-08-22 01:39:07 +04:00
|
|
|
}
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
current_menu_window = NULL;
|
2009-03-27 05:14:23 +03:00
|
|
|
current_menu_icon = 0;
|
2005-04-08 00:46:22 +04:00
|
|
|
current_menu_open = false;
|
2005-03-19 15:50:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
/**
|
2011-02-21 02:16:33 +03:00
|
|
|
* Allow the current menu window to change, if the window is deleted and
|
|
|
|
* recreated while a menu is active on an Adjust-click.
|
|
|
|
*
|
|
|
|
* \param from The original window handle.
|
|
|
|
* \param to The new replacement window handle.
|
2004-02-26 03:44:42 +03:00
|
|
|
*/
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
void ro_gui_menu_window_changed(wimp_w from, wimp_w to)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2005-06-08 01:29:26 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (from == current_menu_window)
|
|
|
|
current_menu_window = to;
|
2004-07-11 17:05:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-04-08 00:46:22 +04:00
|
|
|
* Handle menu selection.
|
2004-07-11 17:05:38 +04:00
|
|
|
*/
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_menu_selection(wimp_selection *selection)
|
|
|
|
{
|
2011-02-21 02:16:33 +03:00
|
|
|
int i; //, j;
|
2010-10-05 23:14:46 +04:00
|
|
|
wimp_menu_entry *menu_entry;
|
|
|
|
menu_action action;
|
|
|
|
wimp_pointer pointer;
|
|
|
|
os_error *error;
|
|
|
|
int previous_menu_icon = current_menu_icon;
|
2005-12-31 07:40:49 +03:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* if we are using gui_multitask then menu selection events
|
|
|
|
* may be delivered after the menu has been closed. As such,
|
|
|
|
* we simply ignore these events. */
|
2005-05-14 20:13:36 +04:00
|
|
|
if (!current_menu)
|
2011-02-21 02:16:33 +03:00
|
|
|
return;
|
2009-05-30 03:43:53 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
assert(current_menu_window);
|
2006-01-08 04:51:33 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* get the menu entry and associated action and definition */
|
2005-04-08 00:46:22 +04:00
|
|
|
menu_entry = ¤t_menu->entries[selection->items[0]];
|
|
|
|
for (i = 1; selection->items[i] != -1; i++)
|
|
|
|
menu_entry = &menu_entry->sub_menu->
|
|
|
|
entries[selection->items[i]];
|
|
|
|
action = ro_gui_menu_find_action(current_menu, menu_entry);
|
2004-07-11 17:05:38 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* Deal with the menu action. If this manages to re-prepare the
|
|
|
|
* menu for re-opening, we test for and act on Adjust clicks.
|
2010-10-05 23:14:46 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!ro_gui_wimp_event_menu_selection(current_menu_window,
|
2011-02-21 02:16:33 +03:00
|
|
|
current_menu_icon, current_menu, selection, action))
|
|
|
|
return;
|
2005-12-31 07:40:49 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/* re-open the menu for Adjust clicks */
|
|
|
|
error = xwimp_get_pointer_info(&pointer);
|
2004-07-06 02:17:59 +04:00
|
|
|
if (error) {
|
2005-04-08 00:46:22 +04:00
|
|
|
LOG(("xwimp_get_pointer_info: 0x%x: %s",
|
2004-07-11 17:05:38 +04:00
|
|
|
error->errnum, error->errmess));
|
2005-04-08 00:46:22 +04:00
|
|
|
warn_user("WimpError", error->errmess);
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_menu_closed();
|
2005-04-08 00:46:22 +04:00
|
|
|
return;
|
2004-07-06 02:17:59 +04:00
|
|
|
}
|
2004-03-27 21:46:08 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
if (pointer.buttons != wimp_CLICK_ADJUST) {
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_menu_closed();
|
2005-04-08 00:46:22 +04:00
|
|
|
return;
|
2004-06-27 02:31:34 +04:00
|
|
|
}
|
2004-03-27 21:46:08 +03:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_menu_create(current_menu, 0, 0, current_menu_window);
|
2005-12-31 07:40:49 +03:00
|
|
|
current_menu_icon = previous_menu_icon;
|
2004-03-27 21:46:08 +03:00
|
|
|
}
|
2004-04-03 06:59:35 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
/**
|
2005-04-08 00:46:22 +04:00
|
|
|
* Handle Message_MenuWarning.
|
2005-02-07 17:28:43 +03:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_menu_warning(wimp_message_menu_warning *warning)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
int i;
|
|
|
|
menu_action action;
|
|
|
|
wimp_menu_entry *menu_entry;
|
|
|
|
os_error *error;
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
assert(current_menu);
|
|
|
|
assert(current_menu_window);
|
|
|
|
|
|
|
|
/* get the sub-menu of the warning */
|
|
|
|
if (warning->selection.items[0] == -1)
|
|
|
|
return;
|
|
|
|
menu_entry = ¤t_menu->entries[warning->selection.items[0]];
|
|
|
|
for (i = 1; warning->selection.items[i] != -1; i++)
|
|
|
|
menu_entry = &menu_entry->sub_menu->
|
|
|
|
entries[warning->selection.items[i]];
|
2010-10-05 23:14:46 +04:00
|
|
|
action = ro_gui_menu_find_action(current_menu, menu_entry);
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* Process the warning via Wimp_Event, then register the resulting
|
|
|
|
* submenu with the module.
|
2010-10-05 23:14:46 +04:00
|
|
|
*/
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_wimp_event_submenu_warning(current_menu_window,
|
2010-10-05 23:14:46 +04:00
|
|
|
current_menu_icon, current_menu, &(warning->selection),
|
2011-02-21 02:16:33 +03:00
|
|
|
action);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (IS_MENU(menu_entry->sub_menu)) {
|
|
|
|
ro_gui_wimp_event_register_submenu((wimp_w) 0);
|
|
|
|
} else {
|
|
|
|
ro_gui_wimp_event_register_submenu((wimp_w)
|
|
|
|
menu_entry->sub_menu);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* If this is a dialogue box, remove the close and back icons.
|
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_wimp_update_window_furniture((wimp_w)
|
|
|
|
menu_entry->sub_menu,
|
|
|
|
wimp_WINDOW_CLOSE_ICON | wimp_WINDOW_BACK_ICON,
|
|
|
|
0);
|
|
|
|
}
|
2005-02-07 17:28:43 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/* open the sub-menu */
|
2011-02-21 02:16:33 +03:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
error = xwimp_create_sub_menu(menu_entry->sub_menu,
|
|
|
|
warning->pos.x, warning->pos.y);
|
2005-02-07 17:28:43 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_sub_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-14 23:59:09 +04:00
|
|
|
/**
|
2011-02-21 02:16:33 +03:00
|
|
|
* Update the current menu by sending it a Menu Prepare event through wimp_event
|
|
|
|
* and then reopening it if the contents has changed.
|
2004-05-14 23:59:09 +04:00
|
|
|
*
|
2011-02-21 02:16:33 +03:00
|
|
|
* \param *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.
|
2004-05-14 23:59:09 +04:00
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
void ro_gui_menu_refresh(wimp_menu *menu)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2011-02-21 02:16:33 +03:00
|
|
|
int checksum = 0;
|
2004-07-18 03:32:09 +04:00
|
|
|
os_error *error;
|
2005-04-28 21:15:29 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (!current_menu_open)
|
2004-07-18 03:32:09 +04:00
|
|
|
return;
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
checksum = ro_gui_menu_get_checksum();
|
2004-07-18 03:32:09 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (!ro_gui_wimp_event_prepare_menu(current_menu_window,
|
|
|
|
current_menu_icon, current_menu))
|
|
|
|
return;
|
2004-07-18 03:32:09 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* \TODO -- Call the menu's event handler here. */
|
|
|
|
|
|
|
|
if (checksum != ro_gui_menu_get_checksum()) {
|
|
|
|
error = xwimp_create_menu(current_menu, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
2005-04-28 21:15:29 +04:00
|
|
|
}
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
2004-07-18 03:32:09 +04:00
|
|
|
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a wimp_menu and adds it to the list to handle actions for.
|
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param *menu The data to create the menu with
|
|
|
|
* \param *callbacks A callback table for the menu (NULL if to be
|
|
|
|
* handled in the 'old-fashined way' by menus.c).
|
|
|
|
* \return The menu created, or NULL on failure
|
2005-04-08 00:46:22 +04:00
|
|
|
*/
|
2009-03-29 04:14:28 +04:00
|
|
|
wimp_menu *ro_gui_menu_define_menu(const struct ns_menu *menu)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition *definition;
|
|
|
|
int entry;
|
|
|
|
|
|
|
|
definition = calloc(sizeof(struct menu_definition), 1);
|
2009-05-30 03:43:53 +04:00
|
|
|
if (!definition) {
|
2005-04-08 00:46:22 +04:00
|
|
|
die("No memory to create menu definition.");
|
2009-05-30 03:43:53 +04:00
|
|
|
return NULL; /* For the benefit of scan-build */
|
|
|
|
}
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
/* link in the menu to our list */
|
|
|
|
definition->next = ro_gui_menu_definitions;
|
|
|
|
ro_gui_menu_definitions = definition;
|
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* count number of menu entries */
|
|
|
|
for (entry = 0; menu->entries[entry].text; entry++)
|
|
|
|
/* do nothing */;
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/* create our definitions */
|
|
|
|
ro_gui_menu_define_menu_add(definition, menu, 0, NULL,
|
|
|
|
0, entry, NULL, 0);
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* and translate menu into current encoding */
|
|
|
|
if (!ro_gui_menu_translate(definition))
|
|
|
|
die("No memory to translate menu.");
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
return definition->menu;
|
|
|
|
}
|
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
*
|
|
|
|
* \param definition Top level menu definition
|
|
|
|
* \param menu Menu declaration data
|
|
|
|
* \param depth Depth of menu we're currently building
|
|
|
|
* \param parent_entry Entry in parent menu, or NULL if root menu
|
|
|
|
* \param first First index in declaration data that is used by this menu
|
2005-11-27 15:53:59 +03:00
|
|
|
* \param last Last index in declaration data that is used by this menu
|
2005-07-16 18:35:25 +04:00
|
|
|
* \param prefix Prefix pf menu declaration string already seen
|
|
|
|
* \param prefix_length Length of prefix
|
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
void ro_gui_menu_define_menu_add(struct menu_definition *definition,
|
2009-03-29 04:14:28 +04:00
|
|
|
const struct ns_menu *menu, int depth,
|
2005-07-16 18:35:25 +04:00
|
|
|
wimp_menu_entry *parent_entry, int first, int last,
|
2008-07-27 02:29:15 +04:00
|
|
|
const char *prefix, int prefix_length)
|
|
|
|
{
|
2005-07-16 18:35:25 +04:00
|
|
|
int entry, id, cur_depth;
|
2005-04-08 00:46:22 +04:00
|
|
|
int entries = 0;
|
|
|
|
int matches[last - first + 1];
|
|
|
|
const char *match;
|
2005-07-16 18:35:25 +04:00
|
|
|
const char *text, *menu_text;
|
2005-04-08 00:46:22 +04:00
|
|
|
wimp_menu *new_menu;
|
|
|
|
struct menu_definition_entry *definition_entry;
|
|
|
|
|
|
|
|
/* step 1: store the matches for depth and subset string */
|
|
|
|
for (entry = first; entry < last; entry++) {
|
|
|
|
cur_depth = 0;
|
|
|
|
match = menu->entries[entry].text;
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* skip specials at start of string */
|
|
|
|
while (!isalnum(*match))
|
|
|
|
match++;
|
|
|
|
|
|
|
|
/* attempt prefix match */
|
2005-04-08 00:46:22 +04:00
|
|
|
if ((prefix) && (strncmp(match, prefix, prefix_length)))
|
|
|
|
continue;
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* Find depth of this entry */
|
2005-04-08 00:46:22 +04:00
|
|
|
while (*match)
|
|
|
|
if (*match++ == '.')
|
|
|
|
cur_depth++;
|
2005-07-16 18:35:25 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
if (depth == cur_depth)
|
|
|
|
matches[entries++] = entry;
|
|
|
|
}
|
|
|
|
matches[entries] = last;
|
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* no entries, so exit */
|
2005-04-08 00:46:22 +04:00
|
|
|
if (entries == 0)
|
|
|
|
return;
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* step 2: build and link the menu. we must use realloc to stop
|
|
|
|
* our memory fragmenting so we can test for sub-menus easily */
|
2005-04-08 00:46:22 +04:00
|
|
|
new_menu = (wimp_menu *)malloc(wimp_SIZEOF_MENU(entries));
|
|
|
|
if (!new_menu)
|
|
|
|
die("No memory to create menu.");
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
if (parent_entry) {
|
|
|
|
/* Fix up sub menu pointer */
|
|
|
|
parent_entry->sub_menu = new_menu;
|
2005-04-08 00:46:22 +04:00
|
|
|
} else {
|
2005-07-16 18:35:25 +04:00
|
|
|
/* Root menu => fill in definition struct */
|
|
|
|
definition->title_key = menu->title;
|
|
|
|
definition->current_encoding = 0;
|
2005-04-08 00:46:22 +04:00
|
|
|
definition->menu = new_menu;
|
|
|
|
}
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* this is fixed up in ro_gui_menu_translate() */
|
|
|
|
new_menu->title_data.indirected_text.text = NULL;
|
|
|
|
|
|
|
|
/* fill in menu flags */
|
2005-12-31 07:40:49 +03:00
|
|
|
ro_gui_menu_init_structure(new_menu, entries);
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/* and then create the entries */
|
2005-04-08 00:46:22 +04:00
|
|
|
for (entry = 0; entry < entries; entry++) {
|
|
|
|
/* add the entry */
|
|
|
|
id = matches[entry];
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
text = menu->entries[id].text;
|
|
|
|
|
|
|
|
/* fill in menu flags from specials at start of string */
|
2005-04-08 00:46:22 +04:00
|
|
|
new_menu->entries[entry].menu_flags = 0;
|
2005-07-16 18:35:25 +04:00
|
|
|
while (!isalnum(*text)) {
|
|
|
|
if (*text == '_')
|
2005-04-08 00:46:22 +04:00
|
|
|
new_menu->entries[entry].menu_flags |=
|
2005-07-16 18:35:25 +04:00
|
|
|
wimp_MENU_SEPARATE;
|
|
|
|
text++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get messages key for menu entry */
|
|
|
|
menu_text = strrchr(text, '.');
|
|
|
|
if (!menu_text)
|
|
|
|
/* no '.' => top-level entry */
|
|
|
|
menu_text = text;
|
|
|
|
else
|
|
|
|
menu_text++; /* and move past the '.' */
|
|
|
|
|
|
|
|
/* fill in submenu data */
|
2005-04-08 00:46:22 +04:00
|
|
|
if (menu->entries[id].sub_window)
|
2005-07-16 18:35:25 +04:00
|
|
|
new_menu->entries[entry].sub_menu =
|
2009-03-29 04:14:28 +04:00
|
|
|
(wimp_menu *) (*menu->entries[id].sub_window);
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* this is fixed up in ro_gui_menu_translate() */
|
|
|
|
new_menu->entries[entry].data.indirected_text.text = NULL;
|
|
|
|
|
|
|
|
/* create definition entry */
|
|
|
|
definition_entry =
|
|
|
|
malloc(sizeof(struct menu_definition_entry));
|
|
|
|
if (!definition_entry)
|
|
|
|
die("Unable to create menu definition entry");
|
|
|
|
definition_entry->action = menu->entries[id].action;
|
|
|
|
definition_entry->menu_entry = &new_menu->entries[entry];
|
|
|
|
definition_entry->entry_key = menu_text;
|
|
|
|
definition_entry->next = definition->entries;
|
|
|
|
definition->entries = definition_entry;
|
2005-04-08 00:46:22 +04:00
|
|
|
|
|
|
|
/* recurse */
|
|
|
|
if (new_menu->entries[entry].sub_menu == wimp_NO_SUB_MENU) {
|
2005-07-16 18:35:25 +04:00
|
|
|
ro_gui_menu_define_menu_add(definition, menu,
|
|
|
|
depth + 1, &new_menu->entries[entry],
|
2005-04-08 00:46:22 +04:00
|
|
|
matches[entry], matches[entry + 1],
|
2005-07-16 18:35:25 +04:00
|
|
|
text, strlen(text));
|
2005-04-08 00:46:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* give menu warnings */
|
|
|
|
if (new_menu->entries[entry].sub_menu != wimp_NO_SUB_MENU)
|
|
|
|
new_menu->entries[entry].menu_flags |=
|
2005-07-16 18:35:25 +04:00
|
|
|
wimp_MENU_GIVE_WARNING;
|
2005-04-08 00:46:22 +04:00
|
|
|
}
|
|
|
|
new_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;
|
|
|
|
new_menu->entries[entries - 1].menu_flags |= wimp_MENU_LAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
/**
|
|
|
|
* Initialise the basic state of a menu structure so all entries are
|
|
|
|
* indirected text with no flags, no submenu.
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_menu_init_structure(wimp_menu *menu, int entries)
|
|
|
|
{
|
2005-12-31 07:40:49 +03:00
|
|
|
int i;
|
2006-01-08 04:51:33 +03:00
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
menu->title_fg = wimp_COLOUR_BLACK;
|
|
|
|
menu->title_bg = wimp_COLOUR_LIGHT_GREY;
|
|
|
|
menu->work_fg = wimp_COLOUR_BLACK;
|
|
|
|
menu->work_bg = wimp_COLOUR_WHITE;
|
|
|
|
menu->width = 200;
|
|
|
|
menu->height = wimp_MENU_ITEM_HEIGHT;
|
|
|
|
menu->gap = wimp_MENU_ITEM_GAP;
|
|
|
|
|
|
|
|
for (i = 0; i < entries; i++) {
|
|
|
|
menu->entries[i].menu_flags = 0;
|
|
|
|
menu->entries[i].sub_menu = wimp_NO_SUB_MENU;
|
|
|
|
menu->entries[i].icon_flags =
|
|
|
|
DEFAULT_FLAGS | wimp_ICON_INDIRECTED;
|
|
|
|
menu->entries[i].data.indirected_text.validation =
|
|
|
|
(char *)-1;
|
|
|
|
}
|
|
|
|
menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;
|
2006-01-03 01:09:23 +03:00
|
|
|
menu->entries[i - 1].menu_flags |= wimp_MENU_LAST;
|
2005-12-31 07:40:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/**
|
|
|
|
* Finds the menu_definition corresponding to a wimp_menu.
|
|
|
|
*
|
|
|
|
* \param menu the menu to find the definition for
|
|
|
|
* \return the associated definition, or NULL if one could not be found
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition *definition;
|
|
|
|
|
|
|
|
if (!menu)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (definition = ro_gui_menu_definitions; definition;
|
|
|
|
definition = definition->next)
|
|
|
|
if (definition->menu == menu)
|
|
|
|
return definition;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-25 05:43:07 +03:00
|
|
|
/**
|
|
|
|
* Finds the key associated with a menu entry translation.
|
|
|
|
*
|
|
|
|
* \param menu the menu to search
|
|
|
|
* \param translated the translated text
|
|
|
|
* \return the original message key, or NULL if one could not be found
|
|
|
|
*/
|
|
|
|
const char *ro_gui_menu_find_menu_entry_key(wimp_menu *menu,
|
2008-07-27 02:29:15 +04:00
|
|
|
const char *translated)
|
|
|
|
{
|
2006-01-25 05:43:07 +03:00
|
|
|
struct menu_definition_entry *entry;
|
|
|
|
struct menu_definition *definition = ro_gui_menu_find_menu(menu);
|
|
|
|
|
|
|
|
if (!definition)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (entry = definition->entries; entry; entry = entry->next)
|
|
|
|
if (!strcmp(entry->menu_entry->data.indirected_text.text, translated))
|
|
|
|
return entry->entry_key;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
/**
|
|
|
|
* Finds the menu_definition_entry corresponding to an action for a wimp_menu.
|
|
|
|
*
|
|
|
|
* \param menu the menu to search for an action within
|
|
|
|
* \param action the action to find
|
|
|
|
* \return the associated menu entry, or NULL if one could not be found
|
|
|
|
*/
|
|
|
|
struct menu_definition_entry *ro_gui_menu_find_entry(wimp_menu *menu,
|
2008-07-27 02:29:15 +04:00
|
|
|
menu_action action)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry *entry;
|
|
|
|
struct menu_definition *definition = ro_gui_menu_find_menu(menu);
|
|
|
|
|
|
|
|
if (!definition)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (entry = definition->entries; entry; entry = entry->next)
|
|
|
|
if (entry->action == action)
|
|
|
|
return entry;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the action corresponding to a wimp_menu_entry for a wimp_menu.
|
|
|
|
*
|
|
|
|
* \param menu the menu to search for an action within
|
|
|
|
* \param menu_entry the menu_entry to find
|
|
|
|
* \return the associated action, or 0 if one could not be found
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
menu_action ro_gui_menu_find_action(wimp_menu *menu, wimp_menu_entry *menu_entry)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry *entry;
|
|
|
|
struct menu_definition *definition = ro_gui_menu_find_menu(menu);
|
|
|
|
|
|
|
|
if (!definition)
|
|
|
|
return NO_ACTION;
|
|
|
|
|
|
|
|
for (entry = definition->entries; entry; entry = entry->next) {
|
|
|
|
if (entry->menu_entry == menu_entry)
|
|
|
|
return entry->action;
|
|
|
|
}
|
|
|
|
return NO_ACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an action within a menu as having a specific ticked status.
|
|
|
|
*
|
|
|
|
* \param menu the menu containing the action
|
|
|
|
* \param action the action to tick/untick
|
|
|
|
* \param ticked whether to set the item as ticked
|
|
|
|
*/
|
|
|
|
void ro_gui_menu_set_entry_shaded(wimp_menu *menu, menu_action action,
|
2008-07-27 02:29:15 +04:00
|
|
|
bool shaded)
|
|
|
|
{
|
2006-07-13 16:46:02 +04:00
|
|
|
struct menu_definition_entry *entry;
|
|
|
|
struct menu_definition *definition = ro_gui_menu_find_menu(menu);
|
|
|
|
|
|
|
|
if (!definition)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* we can't use find_entry as multiple actions may appear in one menu */
|
|
|
|
for (entry = definition->entries; entry; entry = entry->next)
|
|
|
|
if (entry->action == action) {
|
|
|
|
if (shaded)
|
|
|
|
entry->menu_entry->icon_flags |= wimp_ICON_SHADED;
|
|
|
|
else
|
|
|
|
entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED;
|
|
|
|
}
|
2005-04-08 00:46:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an action within a menu as having a specific ticked status.
|
|
|
|
*
|
|
|
|
* \param menu the menu containing the action
|
|
|
|
* \param action the action to tick/untick
|
|
|
|
* \param ticked whether to set the item as ticked
|
|
|
|
*/
|
|
|
|
void ro_gui_menu_set_entry_ticked(wimp_menu *menu, menu_action action,
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ticked)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
struct menu_definition_entry *entry =
|
|
|
|
ro_gui_menu_find_entry(menu, action);
|
|
|
|
if (entry) {
|
|
|
|
if (ticked)
|
|
|
|
entry->menu_entry->menu_flags |= wimp_MENU_TICKED;
|
|
|
|
else
|
|
|
|
entry->menu_entry->menu_flags &= ~wimp_MENU_TICKED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates a simple checksum for the current menu state
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
int ro_gui_menu_get_checksum(void)
|
|
|
|
{
|
2005-04-08 00:46:22 +04:00
|
|
|
wimp_selection menu_tree;
|
|
|
|
int i = 0, j, checksum = 0;
|
|
|
|
os_error *error;
|
|
|
|
wimp_menu *menu;
|
2005-06-08 01:29:26 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
if (!current_menu_open)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error = xwimp_get_menu_state((wimp_menu_state_flags)0,
|
|
|
|
&menu_tree, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_menu_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
menu = current_menu;
|
2005-12-31 07:40:49 +03:00
|
|
|
do {
|
2005-04-08 00:46:22 +04:00
|
|
|
j = 0;
|
|
|
|
do {
|
|
|
|
if (menu->entries[j].icon_flags & wimp_ICON_SHADED)
|
|
|
|
checksum ^= (1 << (i + j * 2));
|
|
|
|
if (menu->entries[j].menu_flags & wimp_MENU_TICKED)
|
|
|
|
checksum ^= (2 << (i + j * 2));
|
|
|
|
} while (!(menu->entries[j++].menu_flags & wimp_MENU_LAST));
|
2005-06-09 22:37:27 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
j = menu_tree.items[i++];
|
2005-12-31 07:40:49 +03:00
|
|
|
if (j != -1) {
|
|
|
|
menu = menu->entries[j].sub_menu;
|
|
|
|
if ((!menu) || (menu == wimp_NO_SUB_MENU) || (!IS_MENU(menu)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (j != -1);
|
2005-06-09 22:37:27 +04:00
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
return checksum;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
2005-07-16 18:35:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate a menu's textual content into the system local encoding
|
|
|
|
*
|
|
|
|
* \param menu The menu to translate
|
|
|
|
* \return false if out of memory, true otherwise
|
|
|
|
*/
|
|
|
|
bool ro_gui_menu_translate(struct menu_definition *menu)
|
|
|
|
{
|
|
|
|
os_error *error;
|
|
|
|
int alphabet;
|
|
|
|
struct menu_definition_entry *entry;
|
|
|
|
char *translated;
|
|
|
|
utf8_convert_ret err;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2005-07-16 18:35:25 +04:00
|
|
|
/* read current alphabet */
|
|
|
|
error = xosbyte1(osbyte_ALPHABET_NUMBER, 127, 0, &alphabet);
|
|
|
|
if (error) {
|
|
|
|
LOG(("failed reading alphabet: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
/* assume Latin1 */
|
|
|
|
alphabet = territory_ALPHABET_LATIN1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu->current_encoding == alphabet)
|
|
|
|
/* menu text is already in the correct encoding */
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* translate root menu title text */
|
|
|
|
free(menu->menu->title_data.indirected_text.text);
|
|
|
|
err = utf8_to_local_encoding(messages_get(menu->title_key),
|
|
|
|
0, &translated);
|
|
|
|
if (err != UTF8_CONVERT_OK) {
|
|
|
|
assert(err != UTF8_CONVERT_BADENC);
|
|
|
|
LOG(("utf8_to_enc failed"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and fill in WIMP menu field */
|
|
|
|
menu->menu->title_data.indirected_text.text = translated;
|
|
|
|
|
|
|
|
/* now the menu entries */
|
|
|
|
for (entry = menu->entries; entry; entry = entry->next) {
|
|
|
|
wimp_menu *submenu = entry->menu_entry->sub_menu;
|
|
|
|
|
|
|
|
/* tranlate menu entry text */
|
|
|
|
free(entry->menu_entry->data.indirected_text.text);
|
|
|
|
err = utf8_to_local_encoding(messages_get(entry->entry_key),
|
|
|
|
0, &translated);
|
|
|
|
if (err != UTF8_CONVERT_OK) {
|
|
|
|
assert(err != UTF8_CONVERT_BADENC);
|
|
|
|
LOG(("utf8_to_enc failed"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in WIMP menu fields */
|
|
|
|
entry->menu_entry->data.indirected_text.text = translated;
|
|
|
|
entry->menu_entry->data.indirected_text.validation =
|
|
|
|
(char *) -1;
|
|
|
|
entry->menu_entry->data.indirected_text.size =
|
|
|
|
strlen(translated);
|
|
|
|
|
|
|
|
/* child menu title - this is the same as the text of
|
|
|
|
* the parent menu entry, so just copy the pointer */
|
2005-12-31 07:40:49 +03:00
|
|
|
if (submenu != wimp_NO_SUB_MENU && IS_MENU(submenu)) {
|
2005-07-16 18:35:25 +04:00
|
|
|
submenu->title_data.indirected_text.text =
|
|
|
|
translated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finally, set the current encoding of the menu */
|
|
|
|
menu->current_encoding = alphabet;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
|