From 277bcec7c6234823390903087dd553c9838c013c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 10 Jan 2014 14:32:29 +0000 Subject: stop system colours being anything to do with frontends --- desktop/gui.h | 9 --------- desktop/netsurf.c | 7 +++++-- desktop/netsurf.h | 8 +++++++- desktop/scrollbar.c | 7 ++++--- desktop/system_colour.c | 36 +++++++++++++++++++----------------- desktop/system_colour.h | 40 ++++++++++++++++++++++++++++++++++++++++ desktop/treeview.c | 14 +++++++------- 7 files changed, 82 insertions(+), 39 deletions(-) create mode 100644 desktop/system_colour.h (limited to 'desktop') diff --git a/desktop/gui.h b/desktop/gui.h index 26a9f4b43..9317e8576 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -169,13 +169,4 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, */ nsurl* gui_get_resource_url(const char *path); -/** css callback to obtain named system colours from a frontend. */ -css_error gui_system_colour(void *pw, lwc_string *name, css_color *color); - -/** Obtain a named system colour from a frontend. */ -colour gui_system_colour_char(const char *name); - -bool gui_system_colour_init(void); -void gui_system_colour_finalize(void); - #endif diff --git a/desktop/netsurf.c b/desktop/netsurf.c index fa026dc6a..36b0b589a 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -39,6 +39,7 @@ #include "desktop/netsurf.h" #include "desktop/401login.h" #include "desktop/browser.h" +#include "desktop/system_colour.h" #include "desktop/gui.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" @@ -211,7 +212,9 @@ nserror netsurf_init(const char *messages) hlcache_initialise(&hlcache_parameters); /* Initialize system colours */ - gui_system_colour_init(); + error = ns_system_colour_init(); + if (error != NSERROR_OK) + return error; js_initialise(); @@ -270,7 +273,7 @@ void netsurf_exit(void) urldb_destroy(); LOG(("Destroying System colours")); - gui_system_colour_finalize(); + ns_system_colour_finalize(); corestrings_fini(); LOG(("Remaining lwc strings:")); diff --git a/desktop/netsurf.h b/desktop/netsurf.h index bfdb647ff..aa1796f7c 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -28,8 +28,14 @@ extern const char * const netsurf_version; extern const int netsurf_version_major; extern const int netsurf_version_minor; +/** Initialise netsurf core */ nserror netsurf_init(const char *messages); -extern void netsurf_exit(void); + +/** Run primary event loop */ extern int netsurf_main_loop(void); +/** finalise NetSurf core */ +extern void netsurf_exit(void); + + #endif diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index d24ea727a..dadb82801 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -25,6 +25,7 @@ #include #include +#include "desktop/system_colour.h" #include "desktop/mouse.h" #include "desktop/scrollbar.h" #include "utils/nsoption.h" @@ -190,9 +191,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y, int v[6]; /* array of triangle vertices */ int x0, y0, x1, y1; - colour bg_fill_colour = gui_system_colour_char("Scrollbar"); - colour fg_fill_colour = gui_system_colour_char("ButtonFace"); - colour arrow_fill_colour = gui_system_colour_char("ButtonText"); + colour bg_fill_colour = ns_system_colour_char("Scrollbar"); + colour fg_fill_colour = ns_system_colour_char("ButtonFace"); + colour arrow_fill_colour = ns_system_colour_char("ButtonText"); plot_style_t bg_fill_style = { .fill_type = PLOT_OP_TYPE_SOLID, diff --git a/desktop/system_colour.c b/desktop/system_colour.c index 4ef170981..178c03536 100644 --- a/desktop/system_colour.c +++ b/desktop/system_colour.c @@ -21,45 +21,47 @@ * */ +#include + +#include "utils/config.h" #include "utils/utils.h" #include "utils/log.h" #include "css/utils.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "utils/nsoption.h" - #define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1) static lwc_string *colour_list[colour_list_len]; -static lwc_string **gui_system_colour_pw = NULL; +static lwc_string **ns_system_colour_pw = NULL; -bool gui_system_colour_init(void) +nserror ns_system_colour_init(void) { unsigned int ccount; - if (gui_system_colour_pw != NULL) - return false; + if (ns_system_colour_pw != NULL) + return NSERROR_INIT_FAILED; /* Intern colour strings */ for (ccount = 0; ccount < colour_list_len; ccount++) { struct nsoption_s *opt; opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START]; - if (lwc_intern_string(opt->key + SLEN("sys_colour_"), - opt->key_len - SLEN("sys_colour_"), + if (lwc_intern_string(opt->key + SLEN("sys_colour_"), + opt->key_len - SLEN("sys_colour_"), &(colour_list[ccount])) != lwc_error_ok) { - return false; + return NSERROR_NOMEM; } } - gui_system_colour_pw = colour_list; - - return true; + ns_system_colour_pw = colour_list; + + return NSERROR_OK; } -void gui_system_colour_finalize(void) +void ns_system_colour_finalize(void) { unsigned int ccount; @@ -68,7 +70,7 @@ void gui_system_colour_finalize(void) } } -colour gui_system_colour_char(const char *name) +colour ns_system_colour_char(const char *name) { colour ret = 0; unsigned int ccount; @@ -83,19 +85,19 @@ colour gui_system_colour_char(const char *name) return ret; } -css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour) +css_error ns_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, + if (lwc_string_caseless_isequal(name, colour_list[ccount], &match) == lwc_error_ok && match) { *colour = ns_color_to_nscss(nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c); return CSS_OK; } - } + } return CSS_INVALID; } diff --git a/desktop/system_colour.h b/desktop/system_colour.h new file mode 100644 index 000000000..b5d4baad4 --- /dev/null +++ b/desktop/system_colour.h @@ -0,0 +1,40 @@ +/* + * Copyright 2014 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 + * Interface to system colour values. + */ + +#ifndef _NETSURF_DESKTOP_SYSTEM_COLOUR_H_ +#define _NETSURF_DESKTOP_SYSTEM_COLOUR_H_ + +#include + +#include "utils/errors.h" +#include "desktop/plot_style.h" + +/** css callback to obtain named system colours. */ +css_error ns_system_colour(void *pw, lwc_string *name, css_color *color); + +/** Obtain a named system colour from a frontend. */ +colour ns_system_colour_char(const char *name); + +nserror ns_system_colour_init(void); +void ns_system_colour_finalize(void); + +#endif diff --git a/desktop/treeview.c b/desktop/treeview.c index a137c46c5..d380882b1 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -21,7 +21,7 @@ */ #include "css/utils.h" -#include "desktop/gui.h" +#include "desktop/system_colour.h" #include "desktop/knockout.h" #include "desktop/plotters.h" #include "desktop/textarea.h" @@ -3466,15 +3466,15 @@ static void treeview_init_plot_styles(int font_pt_size) plot_style_even.bg.stroke_width = 0; plot_style_even.bg.stroke_colour = 0; plot_style_even.bg.fill_type = PLOT_OP_TYPE_SOLID; - plot_style_even.bg.fill_colour = gui_system_colour_char("Window"); + plot_style_even.bg.fill_colour = ns_system_colour_char("Window"); /* Text colour */ plot_style_even.text.family = PLOT_FONT_FAMILY_SANS_SERIF; plot_style_even.text.size = font_pt_size * FONT_SIZE_SCALE; plot_style_even.text.weight = 400; plot_style_even.text.flags = FONTF_NONE; - plot_style_even.text.foreground = gui_system_colour_char("WindowText"); - plot_style_even.text.background = gui_system_colour_char("Window"); + plot_style_even.text.foreground = ns_system_colour_char("WindowText"); + plot_style_even.text.background = ns_system_colour_char("Window"); /* Entry field text colour */ plot_style_even.itext = plot_style_even.text; @@ -3484,13 +3484,13 @@ static void treeview_init_plot_styles(int font_pt_size) /* Selected background colour */ plot_style_even.sbg = plot_style_even.bg; - plot_style_even.sbg.fill_colour = gui_system_colour_char("Highlight"); + plot_style_even.sbg.fill_colour = ns_system_colour_char("Highlight"); /* Selected text colour */ plot_style_even.stext = plot_style_even.text; plot_style_even.stext.foreground = - gui_system_colour_char("HighlightText"); - plot_style_even.stext.background = gui_system_colour_char("Highlight"); + ns_system_colour_char("HighlightText"); + plot_style_even.stext.background = ns_system_colour_char("Highlight"); /* Selected entry field text colour */ plot_style_even.sitext = plot_style_even.stext; -- cgit v1.2.3