summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
Diffstat (limited to 'riscos')
-rw-r--r--riscos/configure.c3
-rw-r--r--riscos/configure/con_language.c124
-rw-r--r--riscos/configure/configure.h1
-rw-r--r--riscos/gui.c31
-rw-r--r--riscos/gui.h1
-rw-r--r--riscos/menus.c75
-rw-r--r--riscos/menus.h5
7 files changed, 175 insertions, 65 deletions
diff --git a/riscos/configure.c b/riscos/configure.c
index c9a504a7f..1217e3800 100644
--- a/riscos/configure.c
+++ b/riscos/configure.c
@@ -80,6 +80,9 @@ void ro_gui_configure_initialise(void) {
ro_gui_configure_register("con_home",
ro_gui_options_home_initialise,
ro_gui_wimp_event_finalise);
+ ro_gui_configure_register("con_language",
+ ro_gui_options_language_initialise,
+ ro_gui_wimp_event_finalise);
}
void ro_gui_configure_show(void) {
diff --git a/riscos/configure/con_language.c b/riscos/configure/con_language.c
new file mode 100644
index 000000000..8725452a4
--- /dev/null
+++ b/riscos/configure/con_language.c
@@ -0,0 +1,124 @@
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
+ * Copyright 2006 Richard Wilson <info@tinct.net>
+ */
+
+#include "netsurf/desktop/options.h"
+#include "netsurf/riscos/dialog.h"
+#include "netsurf/riscos/gui.h"
+#include "netsurf/riscos/menus.h"
+#include "netsurf/riscos/options.h"
+#include "netsurf/riscos/wimp.h"
+#include "netsurf/riscos/wimp_event.h"
+#include "netsurf/riscos/configure.h"
+#include "netsurf/riscos/configure/configure.h"
+#include "netsurf/utils/log.h"
+#include "netsurf/utils/messages.h"
+#include "netsurf/utils/utils.h"
+
+
+#define LANGUAGE_INTERFACE_FIELD 3
+#define LANGUAGE_INTERFACE_GRIGHT 4
+#define LANGUAGE_WEB_PAGES_FIELD 6
+#define LANGUAGE_WEB_PAGES_GRIGHT 7
+#define LANGUAGE_DEFAULT_BUTTON 8
+#define LANGUAGE_CANCEL_BUTTON 9
+#define LANGUAGE_OK_BUTTON 10
+
+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) {
+
+ /* set the current values */
+ ro_gui_set_icon_string(w, LANGUAGE_INTERFACE_FIELD,
+ ro_gui_options_language_name(option_language ?
+ option_language : "en"));
+ ro_gui_set_icon_string(w, LANGUAGE_WEB_PAGES_FIELD,
+ ro_gui_options_language_name(option_accept_language ?
+ option_accept_language : "en"));
+
+ /* initialise all functions for a newly created window */
+ ro_gui_wimp_event_register_menu_gright(w, LANGUAGE_INTERFACE_FIELD,
+ LANGUAGE_INTERFACE_GRIGHT, languages_menu);
+ ro_gui_wimp_event_register_menu_gright(w, LANGUAGE_WEB_PAGES_FIELD,
+ LANGUAGE_WEB_PAGES_GRIGHT, languages_menu);
+ ro_gui_wimp_event_register_button(w, LANGUAGE_DEFAULT_BUTTON,
+ ro_gui_options_language_default);
+ ro_gui_wimp_event_register_cancel(w, LANGUAGE_CANCEL_BUTTON);
+ ro_gui_wimp_event_register_ok(w, LANGUAGE_OK_BUTTON,
+ ro_gui_options_language_ok);
+ ro_gui_wimp_event_set_help_prefix(w, "HelpLanguageConfig");
+ ro_gui_wimp_event_memorise(w);
+ return true;
+
+}
+
+void ro_gui_options_language_default(wimp_pointer *pointer) {
+ const char *code;
+
+ code = ro_gui_default_language();
+ ro_gui_set_icon_string(pointer->w, LANGUAGE_INTERFACE_FIELD,
+ ro_gui_options_language_name(code ?
+ code : "en"));
+ ro_gui_set_icon_string(pointer->w, LANGUAGE_WEB_PAGES_FIELD,
+ ro_gui_options_language_name(code ?
+ code : "en"));
+}
+
+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_' */
+ if ((!option_language) || (strcmp(option_language, code))) {
+ temp = strdup(code);
+ if (temp) {
+ free(option_language);
+ option_language = temp;
+ } else {
+ LOG(("No memory to duplicate language code"));
+ warn_user("NoMemory", 0);
+ }
+ }
+ }
+ 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_' */
+ if ((!option_accept_language) ||
+ (strcmp(option_accept_language, code))) {
+ temp = strdup(code);
+ if (temp) {
+ free(option_accept_language);
+ option_accept_language = temp;
+ } else {
+ LOG(("No memory to duplicate language code"));
+ warn_user("NoMemory", 0);
+ }
+ }
+ }
+ ro_gui_save_options();
+ return true;
+}
+
+
+/**
+ * Convert a 2-letter ISO language code to the language name.
+ *
+ * \param code 2-letter ISO language code
+ * \return language name, or code if unknown
+ */
+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);
+}
diff --git a/riscos/configure/configure.h b/riscos/configure/configure.h
index acc28491e..9ec796c84 100644
--- a/riscos/configure/configure.h
+++ b/riscos/configure/configure.h
@@ -20,6 +20,7 @@ bool ro_gui_options_fonts_initialise(wimp_w w);
bool ro_gui_options_home_initialise(wimp_w w);
bool ro_gui_options_image_initialise(wimp_w w);
void ro_gui_options_image_finalise(wimp_w w);
+bool ro_gui_options_language_initialise(wimp_w w);
bool ro_gui_options_memory_initialise(wimp_w w);
bool ro_gui_options_theme_initialise(wimp_w w);
void ro_gui_options_theme_finalise(wimp_w w);
diff --git a/riscos/gui.c b/riscos/gui.c
index 86301099d..7a7be6515 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -487,18 +487,12 @@ void ro_gui_create_dirs(void)
}
/**
- * Determine the language to use.
- *
- * RISC OS has no standard way of determining which language the user prefers.
- * We have to guess from the 'Country' setting.
+ * Choose the language to use.
*/
void ro_gui_choose_language(void)
{
char path[40];
- const char *lang;
- int country;
- os_error *error;
/* if option_language exists and is valid, use that */
if (option_language) {
@@ -513,6 +507,25 @@ void ro_gui_choose_language(void)
free(option_language);
option_language = 0;
}
+
+ option_language = strdup(ro_gui_default_language());
+ assert(option_language);
+ option_accept_language = strdup(option_language);
+ assert(option_accept_language);
+}
+
+
+/**
+ * Determine the default language to use.
+ *
+ * RISC OS has no standard way of determining which language the user prefers.
+ * We have to guess from the 'Country' setting.
+ */
+const char *ro_gui_default_language(void) {
+ char path[40];
+ const char *lang;
+ int country;
+ os_error *error;
/* choose a language from the configured country number */
error = xosbyte_read(osbyte_VAR_COUNTRY_NUMBER, &country);
@@ -540,8 +553,8 @@ void ro_gui_choose_language(void)
}
sprintf(path, "NetSurf:Resources.%s", lang);
if (is_dir(path))
- option_language = strdup(lang);
- else
+ return lang;
+ return "en";
option_language = strdup("en");
assert(option_language);
if (!option_accept_language)
diff --git a/riscos/gui.h b/riscos/gui.h
index 59becd3ad..9a60379fd 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -103,6 +103,7 @@ void ro_gui_screen_size(int *width, int *height);
void ro_gui_view_source(struct content *content);
void ro_gui_drag_box_start(wimp_pointer *pointer);
bool ro_gui_prequit(void);
+const char *ro_gui_default_language(void);
/* in download.c */
void ro_gui_download_init(void);
diff --git a/riscos/menus.c b/riscos/menus.c
index 59e41e230..de4866d85 100644
--- a/riscos/menus.c
+++ b/riscos/menus.c
@@ -818,25 +818,6 @@ void ro_gui_prepare_navigate(struct gui_window *gui) {
/**
- * Prepare the image quality menu for use
- *
- * \param tinct_options the options to set the menu status for
- */
-void ro_gui_menu_prepare_image_quality(unsigned int tinct_options) {
- for (int i = 0; i < 4; i++)
- image_quality_menu->entries[i].menu_flags &= ~wimp_MENU_TICKED;
- if (tinct_options & tinct_USE_OS_SPRITE_OP)
- image_quality_menu->entries[0].menu_flags |= wimp_MENU_TICKED;
- else if (tinct_options & tinct_ERROR_DIFFUSE)
- image_quality_menu->entries[3].menu_flags |= wimp_MENU_TICKED;
- else if (tinct_options & tinct_DITHER)
- image_quality_menu->entries[2].menu_flags |= wimp_MENU_TICKED;
- else
- image_quality_menu->entries[1].menu_flags |= wimp_MENU_TICKED;
-}
-
-
-/**
* Prepare the page info window for use
*
* \param g the gui_window to set the display icons for
@@ -916,40 +897,6 @@ void ro_gui_menu_prepare_objectinfo(struct box *box) {
/**
- * Prepare languages menu for use
- *
- * \param accept For Accept-Languages selection
- * \param lang Currently selected language
- */
-void ro_gui_menu_prepare_languages(bool accept, const char *lang)
-{
- struct menu_definition *menu;
- struct menu_definition_entry *entry;
- char path_buf[40];
- int offset = strlen("lang_");
-
- menu = ro_gui_menu_find_menu(languages_menu);
- for (entry = menu->entries; entry; entry = entry->next) {
- if (!accept) {
- snprintf(path_buf, sizeof path_buf,
- "NetSurf:Resources.%.2s",
- entry->entry_key + offset);
-
- entry->menu_entry->icon_flags |= is_dir(path_buf) ?
- 0 : wimp_ICON_SHADED;
- }
- else
- entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED;
-
- /* set ticked status */
- if (strncmp(lang, entry->entry_key + offset, 2) == 0)
- entry->menu_entry->menu_flags |= wimp_MENU_TICKED;
- else
- entry->menu_entry->menu_flags &= ~wimp_MENU_TICKED;
- }
-}
-
-/**
* Display a menu of options for a form select control.
*
* \param bw browser window containing form control
@@ -1292,6 +1239,28 @@ struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu) {
/**
+ * 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,
+ const char *translated) {
+ 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;
+}
+
+
+/**
* Finds the menu_definition_entry corresponding to an action for a wimp_menu.
*
* \param menu the menu to search for an action within
diff --git a/riscos/menus.h b/riscos/menus.h
index e42849206..ea6df7a24 100644
--- a/riscos/menus.h
+++ b/riscos/menus.h
@@ -132,8 +132,7 @@ void ro_gui_menu_selection(wimp_selection* selection);
void ro_gui_menu_warning(wimp_message_menu_warning *warning);
void ro_gui_menu_init_structure(wimp_menu *menu, int entries);
void ro_gui_prepare_navigate(struct gui_window *gui);
-void ro_gui_menu_prepare_image_quality(unsigned int tinct_options);
-void ro_gui_menu_prepare_languages(bool accept, const char *lang);
-void ro_gui_display_font_menu(const char *tick, wimp_w w, wimp_i i);
+const char *ro_gui_menu_find_menu_entry_key(wimp_menu *menu,
+ const char *translated);
#endif