Localise configure icon strings when appropriate.

Fix gright menu handling - now writes into display field without 
attempting to localise the selection string - it's already localised.
Update German Messages file appropriately.

svn path=/trunk/netsurf/; revision=2638
This commit is contained in:
John Mark Bell 2006-06-20 21:35:33 +00:00
parent 5f10c6277a
commit 5adef63ac5
7 changed files with 494 additions and 341 deletions

View File

@ -871,7 +871,7 @@ con_content:Inhalte
con_fonts:Schriftarten
con_home:Homepage
con_image:Bilder
con_inter:Nützliches
con_inter:Nützliches
con_lang:Sprachen
con_memory:Speicher
con_secure:Sicherheit

View File

@ -6,7 +6,7 @@
*/
/** \file
* RISC OS option setting (implemenation).
* RISC OS option setting (implementation).
*/
#include <assert.h>
@ -15,9 +15,12 @@
#include <stdio.h>
#include <string.h>
#include "oslib/os.h"
#include "oslib/osbyte.h"
#include "oslib/territory.h"
#include "oslib/wimp.h"
#include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/configure.h"
#include "netsurf/riscos/wimp.h"
#include "netsurf/riscos/wimp_event.h"
#include "netsurf/riscos/configure/configure.h"
#include "netsurf/utils/log.h"
@ -26,10 +29,13 @@
#define CONFIGURE_ICON_PADDING_H 32
#define CONFIGURE_ICON_PADDING_V 32
#define CONFIGURE_DEFAULT_ICON_WIDTH (68 + CONFIGURE_ICON_PADDING_H)
#define CONFIGURE_DEFAULT_ICON_HEIGHT (128 + CONFIGURE_ICON_PADDING_V)
struct configure_tool {
const char *name;
const char *translated;
#define CONFIGURE_TOOL_TRANSLATED_SIZE 64
char translated[CONFIGURE_TOOL_TRANSLATED_SIZE];
char *validation;
bool (*initialise)(wimp_w w);
void (*finalise)(wimp_w w);
@ -40,10 +46,11 @@ struct configure_tool {
};
static wimp_w configure_window;
static int configure_current_encoding;
static int configure_icons = 0;
static struct configure_tool *configure_tools = NULL;
static int configure_icon_width = 68 + CONFIGURE_ICON_PADDING_H;
static int configure_icon_height = 128 + CONFIGURE_ICON_PADDING_V;
static int configure_icon_width = CONFIGURE_DEFAULT_ICON_WIDTH;
static int configure_icon_height = CONFIGURE_DEFAULT_ICON_HEIGHT;
static int configure_icons_per_line = 0;
static int configure_width;
static int configure_height;
@ -51,8 +58,10 @@ static int configure_height;
static bool ro_gui_configure_click(wimp_pointer *pointer);
static void ro_gui_configure_open_window(wimp_open *open);
static void ro_gui_configure_close(wimp_w w);
static bool ro_gui_configure_translate(void);
void ro_gui_configure_initialise(void) {
void ro_gui_configure_initialise(void)
{
/* create our window */
configure_window = ro_gui_dialog_create("configure");
ro_gui_wimp_event_register_open_window(configure_window,
@ -95,58 +104,66 @@ void ro_gui_configure_initialise(void) {
ro_gui_configure_register("con_secure",
ro_gui_options_security_initialise,
ro_gui_wimp_event_finalise);
/* translate the icons */
if (!ro_gui_configure_translate())
die("ro_gui_configure_translate failed");
}
void ro_gui_configure_show(void) {
int width, height;
void ro_gui_configure_show(void)
{
int width, height;
width = configure_icon_width << 2;
height = ((configure_icons + 3) >> 2) * configure_icon_height;
ro_gui_dialog_open_top(configure_window, NULL, width, height);
}
bool ro_gui_configure_click(wimp_pointer *pointer) {
struct configure_tool *tool;
bool ro_gui_configure_click(wimp_pointer *pointer)
{
struct configure_tool *tool;
if (pointer->buttons == wimp_CLICK_MENU)
return true;
if (pointer->buttons == wimp_CLICK_MENU)
return true;
for (tool = configure_tools; tool; tool = tool->next) {
if (tool->i == pointer->i) {
if (!tool->open) {
tool->open = true;
if (!tool->initialise(tool->w))
return false;
ro_gui_dialog_open_persistent(
configure_window,
tool->w, true);
ro_gui_wimp_event_register_close_window(
tool->w,
ro_gui_configure_close);
for (tool = configure_tools; tool; tool = tool->next) {
if (tool->i == pointer->i) {
if (!tool->open) {
tool->open = true;
if (!tool->initialise(tool->w))
return false;
ro_gui_dialog_open_persistent(
configure_window,
tool->w, true);
ro_gui_wimp_event_register_close_window(
tool->w,
ro_gui_configure_close);
} else {
} else {
ro_gui_dialog_open_top(tool->w, NULL, 0, 0);
}
break;
}
}
break;
}
}
return true;
}
void ro_gui_configure_close(wimp_w w) {
struct configure_tool *tool;
void ro_gui_configure_close(wimp_w w)
{
struct configure_tool *tool;
for (tool = configure_tools; tool; tool = tool->next) {
if (tool->w == w) {
tool->open = false;
if (tool->finalise)
tool->finalise(w);
break;
}
}
for (tool = configure_tools; tool; tool = tool->next) {
if (tool->w == w) {
tool->open = false;
if (tool->finalise)
tool->finalise(w);
break;
}
}
}
void ro_gui_configure_open_window(wimp_open *open) {
void ro_gui_configure_open_window(wimp_open *open)
{
os_error *error;
int screen_width, screen_height;
int height, width;
@ -156,6 +173,11 @@ void ro_gui_configure_open_window(wimp_open *open) {
int x, y, l;
struct configure_tool *tool;
if (!ro_gui_configure_translate()) {
warn_user("ro_gui_configure_translate failed", 0);
return;
}
width = open->visible.x1 - open->visible.x0;
height = open->visible.y1 - open->visible.y0;
icons_per_line = width / configure_icon_width;
@ -235,24 +257,24 @@ void ro_gui_configure_open_window(wimp_open *open) {
}
void ro_gui_configure_register(const char *window,
bool (*initialise)(wimp_w w), void (*finalise)(wimp_w w)) {
bool (*initialise)(wimp_w w), void (*finalise)(wimp_w w))
{
wimp_icon_create new_icon;
struct configure_tool *tool;
struct configure_tool *link;
int icon_width;
os_error *error;
/* create our tool */
tool = calloc(sizeof(struct configure_tool), 1);
if (!tool) {
LOG(("Insufficient memory for calloc()"));
LOG(("Insufficient memory for calloc()"));
die("Insufficient memory");
}
tool->name = window;
tool->translated = messages_get(window);
tool->translated[0] = '\0';
tool->validation = malloc(strlen(window) + 2);
if (!tool->validation) {
LOG(("Insufficient memory for malloc()"));
LOG(("Insufficient memory for malloc()"));
die("Insufficient memory");
}
sprintf(tool->validation, "S%s", window);
@ -260,18 +282,6 @@ void ro_gui_configure_register(const char *window,
tool->finalise = finalise;
tool->w = ro_gui_dialog_create(tool->name);
/* update the width */
error = xwimptextop_string_width(tool->translated,
strlen(tool->translated), &icon_width);
if (error) {
LOG(("xwimptextop_string_width: 0x%x: %s",
error->errnum, error->errmess));
die(error->errmess);
}
icon_width += CONFIGURE_ICON_PADDING_H;
if (icon_width > configure_icon_width)
configure_icon_width = icon_width;
/* create the icon */
new_icon.w = configure_window;
new_icon.icon.extent.x0 = 0;
@ -288,7 +298,7 @@ void ro_gui_configure_register(const char *window,
new_icon.icon.data.indirected_text_and_sprite.validation =
tool->validation;
new_icon.icon.data.indirected_text_and_sprite.size =
strlen(tool->translated);
CONFIGURE_TOOL_TRANSLATED_SIZE;
error = xwimp_create_icon(&new_icon, &tool->i);
if (error) {
LOG(("xwimp_create_icon: 0x%x: %s",
@ -296,6 +306,10 @@ void ro_gui_configure_register(const char *window,
die(error->errmess);
}
/* Set the icon's text in current local encoding */
ro_gui_set_icon_string(configure_window, tool->i,
messages_get(tool->name));
/* link into our list alphabetically */
if ((!configure_tools) ||
(strcmp(configure_tools->translated,
@ -319,3 +333,72 @@ void ro_gui_configure_register(const char *window,
}
configure_icons++;
}
/**
* Translate tool icons into the system local encoding.
* This will also recalculate the minimum required icon width.
*
* \return true on success, false on memory exhaustion
*/
bool ro_gui_configure_translate(void)
{
int alphabet;
struct configure_tool *tool;
int icon_width;
os_error *error;
/* 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 (alphabet == configure_current_encoding)
/* text is already in the correct encoding */
return true;
/* reset icon width */
configure_icon_width = CONFIGURE_DEFAULT_ICON_WIDTH;
for (tool = configure_tools; tool; tool = tool->next) {
/* re-translate the text */
ro_gui_set_icon_string(configure_window, tool->i,
messages_get(tool->name));
/* update the width */
error = xwimptextop_string_width(tool->translated,
strlen(tool->translated), &icon_width);
if (error) {
LOG(("xwimptextop_string_width: 0x%x: %s",
error->errnum, error->errmess));
return false;
}
icon_width += CONFIGURE_ICON_PADDING_H;
if (icon_width > configure_icon_width)
configure_icon_width = icon_width;
error = xwimp_resize_icon(configure_window,
tool->i,
0,
-configure_icon_height,
configure_icon_width,
0);
if (error) {
LOG(("xwimp_resize_icon: 0x%x: %s",
error->errnum, error->errmess));
}
}
/* invalidate our global icons_per_line setting
* so the icons get reflowed */
configure_icons_per_line = 0;
/* finally, set the current encoding */
configure_current_encoding = alphabet;
return true;
}

View File

@ -148,7 +148,7 @@ bool ro_gui_options_fonts_ok(wimp_w w)
option_font_default = i + 1;
ro_gui_save_options();
return true;
return true;
}
bool ro_gui_options_fonts_init_menu(void)

View File

@ -32,8 +32,8 @@ static void ro_gui_options_language_default(wimp_pointer *pointer);
static bool ro_gui_options_language_ok(wimp_w w);
static const char *ro_gui_options_language_name(const char *code);
bool ro_gui_options_language_initialise(wimp_w w) {
bool ro_gui_options_language_initialise(wimp_w w)
{
/* set the current values */
ro_gui_set_icon_string(w, LANGUAGE_INTERFACE_FIELD,
ro_gui_options_language_name(option_language ?
@ -58,7 +58,8 @@ bool ro_gui_options_language_initialise(wimp_w w) {
}
void ro_gui_options_language_default(wimp_pointer *pointer) {
void ro_gui_options_language_default(wimp_pointer *pointer)
{
const char *code;
code = ro_gui_default_language();
@ -70,21 +71,22 @@ void ro_gui_options_language_default(wimp_pointer *pointer) {
code : "en"));
}
bool ro_gui_options_language_ok(wimp_w w) {
bool ro_gui_options_language_ok(wimp_w w)
{
const char *code;
char *temp;
code = ro_gui_menu_find_menu_entry_key(languages_menu,
ro_gui_get_icon_string(w, LANGUAGE_INTERFACE_FIELD));
if (code) {
code += 5; /* skip 'lang_' */
code += 5; /* skip 'lang_' */
if ((!option_language) || (strcmp(option_language, code))) {
temp = strdup(code);
if (temp) {
free(option_language);
option_language = temp;
free(option_language);
option_language = temp;
} else {
LOG(("No memory to duplicate language code"));
LOG(("No memory to duplicate language code"));
warn_user("NoMemory", 0);
}
}
@ -92,21 +94,21 @@ bool ro_gui_options_language_ok(wimp_w w) {
code = ro_gui_menu_find_menu_entry_key(languages_menu,
ro_gui_get_icon_string(w, LANGUAGE_WEB_PAGES_FIELD));
if (code) {
code += 5; /* skip 'lang_' */
code += 5; /* skip 'lang_' */
if ((!option_accept_language) ||
(strcmp(option_accept_language, code))) {
temp = strdup(code);
if (temp) {
free(option_accept_language);
option_accept_language = temp;
free(option_accept_language);
option_accept_language = temp;
} else {
LOG(("No memory to duplicate language code"));
LOG(("No memory to duplicate language code"));
warn_user("NoMemory", 0);
}
}
}
ro_gui_save_options();
return true;
return true;
}
@ -116,9 +118,11 @@ bool ro_gui_options_language_ok(wimp_w w) {
* \param code 2-letter ISO language code
* \return language name, or code if unknown
*/
const char *ro_gui_options_language_name(const char *code) {
const char *ro_gui_options_language_name(const char *code)
{
char key[] = "lang_xx";
key[5] = code[0];
key[6] = code[1];
return messages_get(key);
}

View File

@ -283,6 +283,71 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) {
}
/**
* Set the contents of an icon to a string.
*
* \param w window handle
* \param i icon handle
* \param text string (in local encoding) (copied)
*/
void ro_gui_set_icon_string_le(wimp_w w, wimp_i i, const char *text) {
wimp_caret caret;
wimp_icon_state ic;
os_error *error;
int old_len, len;
/* get the icon data */
ic.w = w;
ic.i = i;
error = xwimp_get_icon_state(&ic);
if (error) {
LOG(("xwimp_get_icon_state: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
/* check that the existing text is not the same as the updated text
* to stop flicker */
if (ic.icon.data.indirected_text.size &&
!strncmp(ic.icon.data.indirected_text.text,
text,
(unsigned int)ic.icon.data.indirected_text.size - 1))
return;
/* copy the text across */
old_len = strlen(ic.icon.data.indirected_text.text);
if (ic.icon.data.indirected_text.size) {
strncpy(ic.icon.data.indirected_text.text, text,
(unsigned int)ic.icon.data.indirected_text.size - 1);
ic.icon.data.indirected_text.text[
ic.icon.data.indirected_text.size - 1] = '\0';
}
/* handle the caret being in the icon */
error = xwimp_get_caret_position(&caret);
if (error) {
LOG(("xwimp_get_caret_position: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
if ((caret.w == w) && (caret.i == i)) {
len = strlen(text);
if ((caret.index > len) || (caret.index == old_len))
caret.index = len;
error = xwimp_set_caret_position(w, i, caret.pos.x, caret.pos.y,
-1, caret.index);
if (error) {
LOG(("xwimp_set_caret_position: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}
ro_gui_redraw_icon(w, i);
}
/**
* Set the contents of an icon to a number.
*

View File

@ -30,6 +30,7 @@ void ro_convert_pixels_to_os_units(os_coord *pixels, os_mode mode);
void ro_gui_force_redraw_icon(wimp_w w, wimp_i i);
char *ro_gui_get_icon_string(wimp_w w, wimp_i i);
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text);
void ro_gui_set_icon_string_le(wimp_w w, wimp_i i, const char *text);
void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value);
void ro_gui_set_icon_decimal(wimp_w w, wimp_i i, int value, int decimal_places);

View File

@ -354,7 +354,7 @@ bool ro_gui_wimp_event_menu_selection(wimp_w w, wimp_i i, wimp_menu *menu,
if (menu_entry->menu_flags & wimp_MENU_TICKED)
return true;
ro_gui_set_icon_string(window->w, event->data.menu_gright.field,
ro_gui_set_icon_string_le(window->w, event->data.menu_gright.field,
menu_entry->data.indirected_text.text);
ro_gui_wimp_event_prepare_menu(window->w, event);
if (window->menu_selection)