From 15598b57901bc6abcd6b49337445a4c8fe31e15a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 28 May 2013 15:01:15 +0100 Subject: move riscos to new option API --- riscos/Makefile.target | 2 +- riscos/gui.c | 153 ++++++++++++++------- riscos/system_colour.c | 354 ------------------------------------------------- riscos/system_colour.h | 34 ----- 4 files changed, 103 insertions(+), 440 deletions(-) delete mode 100644 riscos/system_colour.c delete mode 100644 riscos/system_colour.h (limited to 'riscos') diff --git a/riscos/Makefile.target b/riscos/Makefile.target index faefa417f..e73a5a3a1 100644 --- a/riscos/Makefile.target +++ b/riscos/Makefile.target @@ -73,7 +73,7 @@ S_RISCOS := 401login.c assert.c bitmap.c buffer.c cookies.c configure.c \ global_history.c gui.c help.c history.c hotlist.c iconbar.c \ image.c menus.c message.c palettes.c plotters.c \ print.c query.c save.c save_draw.c save_pdf.c schedule.c \ - search.c searchweb.c sslcert.c system_colour.c textarea.c \ + search.c searchweb.c sslcert.c textarea.c \ textselection.c theme.c theme_install.c thumbnail.c toolbar.c \ treeview.c ucstables.c uri.c url_complete.c url_protocol.c \ url_suggest.c wimp.c wimp_event.c window.c \ diff --git a/riscos/gui.c b/riscos/gui.c index 50ccceff9..f82ce742d 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -84,7 +84,6 @@ #include "riscos/save.h" #include "riscos/sslcert.h" #include "riscos/content-handlers/sprite.h" -#include "riscos/system_colour.h" #include "riscos/textselection.h" #include "riscos/theme.h" #include "riscos/toolbar.h" @@ -328,45 +327,86 @@ nsurl *gui_get_resource_url(const char *path) return url; } -/* Documented in utils/nsoption.h */ -void gui_options_init_defaults(void) +/** + * set option from wimp + */ +static nserror +set_colour_from_wimp(struct nsoption_s *opts, + wimp_colour wimp, + enum nsoption_e option, + colour def_colour) +{ + os_error *error; + os_PALETTE(20) palette; + + error = xwimp_read_palette((os_palette *) &palette); + if (error != NULL) { + LOG(("xwimp_read_palette: 0x%x: %s", + error->errnum, error->errmess)); + } else { + def_colour = palette.entries[wimp]; + } + + return def_colour; +} + +/** + * Set option defaults for riscos frontend + * + * @param defaults The option table to update. + * @return error status. + * + * @TODO -- The wimp_COLOUR_... values here map the colour definitions + * to parts of the RISC OS desktop palette. In places this + * is fairly arbitrary, and could probably do with + * re-checking. + * + */ +static nserror set_defaults(struct nsoption_s *defaults) { /* Set defaults for absent option strings */ - nsoption_setnull_charp(theme, strdup("Aletheia")); - nsoption_setnull_charp(toolbar_browser, strdup("0123|58|9")); - nsoption_setnull_charp(toolbar_hotlist, strdup("40|12|3")); - nsoption_setnull_charp(toolbar_history, strdup("0|12|3")); - nsoption_setnull_charp(toolbar_cookies, strdup("0|12")); nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle")); nsoption_setnull_charp(cookie_file, strdup("NetSurf:Cookies")); nsoption_setnull_charp(cookie_jar, strdup(CHOICES_PREFIX "Cookies")); - nsoption_setnull_charp(url_path, strdup("NetSurf:URL")); - nsoption_setnull_charp(url_save, strdup(CHOICES_PREFIX "URL")); - nsoption_setnull_charp(hotlist_path, strdup("NetSurf:Hotlist")); - nsoption_setnull_charp(hotlist_save, strdup(CHOICES_PREFIX "Hotlist")); - nsoption_setnull_charp(recent_path, strdup("NetSurf:Recent")); - nsoption_setnull_charp(recent_save, strdup(CHOICES_PREFIX "Recent")); - nsoption_setnull_charp(theme_path, strdup("NetSurf:Themes")); - nsoption_setnull_charp(theme_save, strdup(CHOICES_PREFIX "Themes")); - - if (nsoption_charp(theme) == NULL || - nsoption_charp(toolbar_browser) == NULL || - nsoption_charp(toolbar_hotlist) == NULL || - nsoption_charp(toolbar_history) == NULL || - nsoption_charp(toolbar_cookies) == NULL || - nsoption_charp(ca_bundle) == NULL || - nsoption_charp(cookie_file) == NULL || - nsoption_charp(cookie_jar) == NULL || - nsoption_charp(url_path) == NULL || - nsoption_charp(url_save) == NULL || - nsoption_charp(hotlist_path) == NULL || - nsoption_charp(hotlist_save) == NULL || - nsoption_charp(recent_path) == NULL || - nsoption_charp(recent_save) == NULL || - nsoption_charp(theme_path) == NULL || - nsoption_charp(theme_save) == NULL) { - die("Failed initialising string options"); - } + + if (nsoption_charp(ca_bundle) == NULL || + nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar) == NULL) { + LOG(("Failed initialising string options")); + return NSERROR_BAD_PARAMETER; + } + + /* set default system colours for riscos ui */ + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_ActiveBorder, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_CREAM, NSOPTION_sys_colour_ActiveCaption, 0x00dddddd); + set_colour_from_wimp(defaults, wimp_COLOUR_VERY_LIGHT_GREY, NSOPTION_sys_colour_AppWorkspace, 0x00eeeeee); + set_colour_from_wimp(defaults, wimp_COLOUR_VERY_LIGHT_GREY, NSOPTION_sys_colour_Background, 0x00aa0000);/* \TODO -- Check */ + set_colour_from_wimp(defaults, wimp_COLOUR_VERY_LIGHT_GREY, NSOPTION_sys_colour_ButtonFace, 0x00aaaaaa); + set_colour_from_wimp(defaults, wimp_COLOUR_DARK_GREY, NSOPTION_sys_colour_ButtonHighlight, 0x00cccccc);/* \TODO -- Check */ + set_colour_from_wimp(defaults, wimp_COLOUR_MID_DARK_GREY, NSOPTION_sys_colour_ButtonShadow, 0x00bbbbbb); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_ButtonText, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_CaptionText, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_MID_LIGHT_GREY, NSOPTION_sys_colour_GrayText, 0x00777777);/* \TODO -- Check */ + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_Highlight, 0x00ee0000); + set_colour_from_wimp(defaults, wimp_COLOUR_WHITE, NSOPTION_sys_colour_HighlightText, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_InactiveBorder, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_LIGHT_GREY, NSOPTION_sys_colour_InactiveCaption, 0x00ffffff); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_InactiveCaptionText, 0x00cccccc); + set_colour_from_wimp(defaults, wimp_COLOUR_CREAM, NSOPTION_sys_colour_InfoBackground, 0x00aaaaaa); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_InfoText, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_WHITE, NSOPTION_sys_colour_Menu, 0x00aaaaaa); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_MenuText, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_LIGHT_GREY, NSOPTION_sys_colour_Scrollbar, 0x00aaaaaa);/* \TODO -- Check */ + set_colour_from_wimp(defaults, wimp_COLOUR_MID_DARK_GREY, NSOPTION_sys_colour_ThreeDDarkShadow, 0x00555555); + set_colour_from_wimp(defaults, wimp_COLOUR_VERY_LIGHT_GREY, NSOPTION_sys_colour_ThreeDFace, 0x00dddddd); + set_colour_from_wimp(defaults, wimp_COLOUR_WHITE, NSOPTION_sys_colour_ThreeDHighlight, 0x00aaaaaa); + set_colour_from_wimp(defaults, wimp_COLOUR_WHITE, NSOPTION_sys_colour_ThreeDLightShadow, 0x00999999); + set_colour_from_wimp(defaults, wimp_COLOUR_MID_DARK_GREY, NSOPTION_sys_colour_ThreeDShadow, 0x00777777); + set_colour_from_wimp(defaults, wimp_COLOUR_VERY_LIGHT_GREY, NSOPTION_sys_colour_Window, 0x00aaaaaa); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_WindowFrame, 0x00000000); + set_colour_from_wimp(defaults, wimp_COLOUR_BLACK, NSOPTION_sys_colour_WindowText, 0x00000000); + + return NSERROR_OK; } /** @@ -819,6 +859,7 @@ int main(int argc, char** argv) os_var_type type; int used = -1; /* slightly better with older OSLib versions */ os_error *error; + nserror ret; /* Consult NetSurf$Logging environment variable to decide if logging * is required. */ @@ -842,25 +883,37 @@ int main(int argc, char** argv) */ nslog_init(nslog_stream_configure, &argc, argv); - /* Pass a NULL pointer for Messages path, because until the Choices - * are loaded in netsurf_init, we don't know the Messages path. */ - netsurf_init(&argc, &argv, "NetSurf:Choices", NULL); - - artworks_init(); - draw_init(); - sprite_init(); + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read("NetSurf:Choices", NULL); + nsoption_commandline(&argc, argv, NULL); /* Choose the interface language to use */ ro_gui_choose_language(); - /* Load in our language-specific Messages */ - if ((length = snprintf(path, sizeof(path), - "NetSurf:Resources.%s.Messages", - nsoption_charp(language))) < 0 || length >= (int)sizeof(path)) + /* select language-specific Messages */ + if (((length = snprintf(path, + sizeof(path), + "NetSurf:Resources.%s.Messages", + nsoption_charp(language))) < 0) || + (length >= (int)sizeof(path))) { die("Failed to locate Messages resource."); - /* We disabled core Messages load, so have to load them here */ - messages_load(path); - /* Also load some extra RISC OS specific Messages */ + } + + /* common initialisation */ + ret = netsurf_init(path); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise"); + } + + artworks_init(); + draw_init(); + sprite_init(); + + /* Load some extra RISC OS specific Messages */ messages_load("NetSurf:Resources.LangNames"); gui_init(argc, argv); @@ -1406,11 +1459,9 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) case message_MODE_CHANGE: ro_gui_get_screen_properties(); rufl_invalidate_cache(); - ro_gui_system_colour_update(); break; case message_PALETTE_CHANGE: - ro_gui_system_colour_update(); break; case message_FONT_CHANGED: diff --git a/riscos/system_colour.c b/riscos/system_colour.c deleted file mode 100644 index 39a86ac30..000000000 --- a/riscos/system_colour.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright 2011 Vincent Sanders - * - * 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 . - */ - -/** \file - * System colour handling - * - */ - -#include "oslib/os.h" -#include "oslib/wimp.h" -#include "utils/utils.h" -#include "utils/log.h" -#include "desktop/gui.h" -#include "utils/nsoption.h" -#include "riscos/system_colour.h" - -struct gui_system_colour_ctx { - const char *name; - int length; - css_color colour; - wimp_colour system_colour; - colour *option_colour; - lwc_string *lwcstr; -}; - -/* \TODO -- The wimp_COLOUR_... values in the table below map the colour - * definitions to parts of the RISC OS desktop palette. In places - * this is fairly arbitrary, and could probably do with re-checking. - */ - -static struct gui_system_colour_ctx colour_list[] = { - { - "ActiveBorder", - SLEN("ActiveBorder"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_ActiveBorder), - NULL - }, { - "ActiveCaption", - SLEN("ActiveCaption"), - 0xffdddddd, - wimp_COLOUR_CREAM, - &nsoption_colour(sys_colour_ActiveCaption), - NULL - }, { - "AppWorkspace", - SLEN("AppWorkspace"), - 0xffeeeeee, - wimp_COLOUR_VERY_LIGHT_GREY, - &nsoption_colour(sys_colour_AppWorkspace), - NULL - }, { - "Background", - SLEN("Background"), - 0xff0000aa, - wimp_COLOUR_VERY_LIGHT_GREY, /* \TODO -- Check */ - &nsoption_colour(sys_colour_Background), - NULL - }, { - "ButtonFace", - SLEN("ButtonFace"), - 0xffaaaaaa, - wimp_COLOUR_VERY_LIGHT_GREY, - &nsoption_colour(sys_colour_ButtonFace), - NULL - }, { - "ButtonHighlight", - SLEN("ButtonHighlight"), - 0xffdddddd, - wimp_COLOUR_DARK_GREY, /* \TODO -- Check */ - &nsoption_colour(sys_colour_ButtonHighlight), - NULL - }, { - "ButtonShadow", - SLEN("ButtonShadow"), - 0xffbbbbbb, - wimp_COLOUR_MID_DARK_GREY, - &nsoption_colour(sys_colour_ButtonShadow), - NULL - }, { - "ButtonText", - SLEN("ButtonText"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_ButtonText), - NULL - }, { - "CaptionText", - SLEN("CaptionText"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_CaptionText), - NULL - }, { - "GrayText", - SLEN("GrayText"), - 0xffcccccc, - wimp_COLOUR_MID_LIGHT_GREY, /* \TODO -- Check */ - &nsoption_colour(sys_colour_GrayText), - NULL - }, { - "Highlight", - SLEN("Highlight"), - 0xff0000ee, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_Highlight), - NULL - }, { - "HighlightText", - SLEN("HighlightText"), - 0xff000000, - wimp_COLOUR_WHITE, - &nsoption_colour(sys_colour_HighlightText), - NULL - }, { - "InactiveBorder", - SLEN("InactiveBorder"), - 0xffffffff, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_InactiveBorder), - NULL - }, { - "InactiveCaption", - SLEN("InactiveCaption"), - 0xffffffff, - wimp_COLOUR_LIGHT_GREY, - &nsoption_colour(sys_colour_InactiveCaption), - NULL - }, { - "InactiveCaptionText", - SLEN("InactiveCaptionText"), - 0xffcccccc, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_InactiveCaptionText), - NULL - }, { - "InfoBackground", - SLEN("InfoBackground"), - 0xffaaaaaa, - wimp_COLOUR_CREAM, - &nsoption_colour(sys_colour_InfoBackground), - NULL - }, { - "InfoText", - SLEN("InfoText"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_InfoText), - NULL - }, { - "Menu", - SLEN("Menu"), - 0xffaaaaaa, - wimp_COLOUR_WHITE, - &nsoption_colour(sys_colour_Menu), - NULL - }, { - "MenuText", - SLEN("MenuText"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_MenuText), - NULL - }, { - "Scrollbar", - SLEN("Scrollbar"), - 0xffaaaaaa, - wimp_COLOUR_LIGHT_GREY, /* \TODO -- Check */ - &nsoption_colour(sys_colour_Scrollbar), - NULL - }, { - "ThreeDDarkShadow", - SLEN("ThreeDDarkShadow"), - 0xff555555, - wimp_COLOUR_MID_DARK_GREY, - &nsoption_colour(sys_colour_ThreeDDarkShadow), - NULL - }, { - "ThreeDFace", - SLEN("ThreeDFace"), - 0xffdddddd, - wimp_COLOUR_VERY_LIGHT_GREY, - &nsoption_colour(sys_colour_ThreeDFace), - NULL - }, { - "ThreeDHighlight", - SLEN("ThreeDHighlight"), - 0xffaaaaaa, - wimp_COLOUR_WHITE, - &nsoption_colour(sys_colour_ThreeDHighlight), - NULL - }, { - "ThreeDLightShadow", - SLEN("ThreeDLightShadow"), - 0xff999999, - wimp_COLOUR_WHITE, - &nsoption_colour(sys_colour_ThreeDLightShadow), - NULL - }, { - "ThreeDShadow", - SLEN("ThreeDShadow"), - 0xff777777, - wimp_COLOUR_MID_DARK_GREY, - &nsoption_colour(sys_colour_ThreeDShadow), - NULL - }, { - "Window", - SLEN("Window"), - 0xffaaaaaa, - wimp_COLOUR_VERY_LIGHT_GREY, - &nsoption_colour(sys_colour_Window), - NULL - }, { - "WindowFrame", - SLEN("WindowFrame"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_WindowFrame), - NULL - }, { - "WindowText", - SLEN("WindowText"), - 0xff000000, - wimp_COLOUR_BLACK, - &nsoption_colour(sys_colour_WindowText), - NULL - }, - -}; - -#define colour_list_len (sizeof(colour_list) / sizeof(struct gui_system_colour_ctx)) - -static struct gui_system_colour_ctx *gui_system_colour_pw = NULL; - -bool gui_system_colour_init(void) -{ - unsigned int ccount; - - if (gui_system_colour_pw != NULL) - return false; - - /* Intern colour strings */ - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (lwc_intern_string(colour_list[ccount].name, - colour_list[ccount].length, - &(colour_list[ccount].lwcstr)) != lwc_error_ok) { - return false; - } - } - - /* pull in options if set (ie not transparent) */ - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (*(colour_list[ccount].option_colour) != 0) { - colour_list[ccount].colour = - *(colour_list[ccount].option_colour); - } - } - - ro_gui_system_colour_update(); - - gui_system_colour_pw = colour_list; - - return true; -} - -void gui_system_colour_finalize(void) -{ - unsigned int ccount; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - lwc_string_unref(colour_list[ccount].lwcstr); - } -} - -colour gui_system_colour_char(const char *name) -{ - colour ret = 0xff00000; - unsigned int ccount; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (strcmp(name, colour_list[ccount].name) == 0) { - ret = colour_list[ccount].colour; - break; - } - } - return ret; -} - -css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour) -{ - unsigned int ccount; - bool match; - - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (lwc_string_caseless_isequal(name, - colour_list[ccount].lwcstr, - &match) == lwc_error_ok && match) { - *colour = colour_list[ccount].colour; - return CSS_OK; - } - } - - return CSS_INVALID; -} - - -#define ro_gui_system_colour_convert_os_to_css(os) (0xff000000 | \ - (((os) & 0x0000ff00) << 8) | \ - (((os) & 0x00ff0000) >> 8) | \ - (((os) & 0xff000000) >> 24)) - - -/* This is a exported interface for the RISC OS frontend, - * documented in riscos/system_colour.h - */ - -void ro_gui_system_colour_update(void) -{ - os_error *error; - os_PALETTE(20) palette; - unsigned int ccount; - - error = xwimp_read_palette((os_palette *) &palette); - if (error != NULL) { - LOG(("xwimp_read_palette: 0x%x: %s", - error->errnum, error->errmess)); - return; - } - - for (ccount = 0; ccount < colour_list_len; ccount++) { - if (*(colour_list[ccount].option_colour) == 0) { - colour_list[ccount].colour = - ro_gui_system_colour_convert_os_to_css( - palette.entries[colour_list[ccount]. - system_colour]); - } - } -} diff --git a/riscos/system_colour.h b/riscos/system_colour.h deleted file mode 100644 index a6672e305..000000000 --- a/riscos/system_colour.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2011 Stephen Fryatt - * - * 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 . - */ - -/** \file - * System colour handling (frontend internal interface) - */ - -#ifndef _NETSURF_RISCOS_SYSTEM_COLOUR_H_ -#define _NETSURF_RISCOS_SYSTEM_COLOUR_H_ - -/** - * Scan the CSS system colour definitions, and update any that haven't been - * overridden in NetSurf's options to reflect the current Desktop palette. - */ - -void ro_gui_system_colour_update(void); - -#endif - -- cgit v1.2.3