2013-05-28 12:56:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* System colour handling
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "utils/config.h"
|
2013-05-28 12:56:55 +04:00
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/log.h"
|
2013-05-29 15:10:40 +04:00
|
|
|
#include "css/utils.h"
|
2014-01-10 18:32:29 +04:00
|
|
|
#include "desktop/system_colour.h"
|
2013-05-28 12:56:55 +04:00
|
|
|
#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];
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
static lwc_string **ns_system_colour_pw = NULL;
|
2013-05-28 12:56:55 +04:00
|
|
|
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
nserror ns_system_colour_init(void)
|
2013-05-28 12:56:55 +04:00
|
|
|
{
|
|
|
|
unsigned int ccount;
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
if (ns_system_colour_pw != NULL)
|
|
|
|
return NSERROR_INIT_FAILED;
|
2013-05-28 12:56:55 +04:00
|
|
|
|
|
|
|
/* Intern colour strings */
|
|
|
|
for (ccount = 0; ccount < colour_list_len; ccount++) {
|
|
|
|
struct nsoption_s *opt;
|
|
|
|
opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START];
|
2014-01-10 18:32:29 +04:00
|
|
|
if (lwc_intern_string(opt->key + SLEN("sys_colour_"),
|
|
|
|
opt->key_len - SLEN("sys_colour_"),
|
2013-05-28 12:56:55 +04:00
|
|
|
&(colour_list[ccount])) != lwc_error_ok) {
|
2014-01-10 18:32:29 +04:00
|
|
|
return NSERROR_NOMEM;
|
2013-05-28 12:56:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
ns_system_colour_pw = colour_list;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2013-05-28 12:56:55 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
void ns_system_colour_finalize(void)
|
2013-05-28 12:56:55 +04:00
|
|
|
{
|
|
|
|
unsigned int ccount;
|
|
|
|
|
|
|
|
for (ccount = 0; ccount < colour_list_len; ccount++) {
|
|
|
|
lwc_string_unref(colour_list[ccount]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
colour ns_system_colour_char(const char *name)
|
2013-05-28 12:56:55 +04:00
|
|
|
{
|
2013-05-29 14:33:17 +04:00
|
|
|
colour ret = 0;
|
2013-05-28 12:56:55 +04:00
|
|
|
unsigned int ccount;
|
|
|
|
|
|
|
|
for (ccount = 0; ccount < colour_list_len; ccount++) {
|
|
|
|
if (strcmp(name,
|
|
|
|
nsoptions[ccount + NSOPTION_SYS_COLOUR_START].key + SLEN("sys_colour_")) == 0) {
|
|
|
|
ret = nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:32:29 +04:00
|
|
|
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
|
2013-05-28 12:56:55 +04:00
|
|
|
{
|
|
|
|
unsigned int ccount;
|
|
|
|
bool match;
|
|
|
|
|
|
|
|
for (ccount = 0; ccount < colour_list_len; ccount++) {
|
2014-01-10 18:32:29 +04:00
|
|
|
if (lwc_string_caseless_isequal(name,
|
2013-05-28 12:56:55 +04:00
|
|
|
colour_list[ccount],
|
|
|
|
&match) == lwc_error_ok && match) {
|
|
|
|
*colour = ns_color_to_nscss(nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c);
|
|
|
|
return CSS_OK;
|
|
|
|
}
|
2014-01-10 18:32:29 +04:00
|
|
|
}
|
2013-05-28 12:56:55 +04:00
|
|
|
|
|
|
|
return CSS_INVALID;
|
|
|
|
}
|