NetSurf
system_colour.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * System colour handling implementation.
22 */
23
24#include <string.h>
25
26#include "utils/config.h"
27#include "utils/utils.h"
28#include "utils/log.h"
29#include "utils/nsoption.h"
30#include "netsurf/css.h"
31
33
34#define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1)
35
36static lwc_string *colour_list[colour_list_len];
37
38static lwc_string **ns_system_colour_pw = NULL;
39
40
41/* exported interface documented in desktop/system_colour.h */
43{
44 unsigned int ccount;
45
46 if (ns_system_colour_pw != NULL)
48
49 /* Intern colour strings */
50 for (ccount = 0; ccount < colour_list_len; ccount++) {
51 struct nsoption_s *opt;
52 opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START];
53 if (lwc_intern_string(opt->key + SLEN("sys_colour_"),
54 opt->key_len - SLEN("sys_colour_"),
55 &(colour_list[ccount])) != lwc_error_ok) {
56 return NSERROR_NOMEM;
57 }
58 }
59
61
62 return NSERROR_OK;
63}
64
65
66/* exported interface documented in desktop/system_colour.h */
68{
69 unsigned int ccount;
70
71 for (ccount = 0; ccount < colour_list_len; ccount++) {
72 lwc_string_unref(colour_list[ccount]);
73 }
74}
75
76
77/* exported interface documented in desktop/system_colour.h */
78nserror ns_system_colour_char(const char *name, colour *colour_out)
79{
80 unsigned int ccount;
81
82 for (ccount = 0; ccount < colour_list_len; ccount++) {
83 if (strcmp(name,
84 nsoptions[ccount + NSOPTION_SYS_COLOUR_START].key + SLEN("sys_colour_")) == 0) {
85 *colour_out = nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c;
86 return NSERROR_OK;
87 }
88 }
89
90 return NSERROR_INVALID;
91}
92
93
94/* exported interface documented in desktop/system_colour.h */
95css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
96{
97 unsigned int ccount;
98 bool match;
99
100 for (ccount = 0; ccount < colour_list_len; ccount++) {
101 if (lwc_string_caseless_isequal(name,
102 colour_list[ccount],
103 &match) == lwc_error_ok && match) {
105 return CSS_OK;
106 }
107 }
108
109 return CSS_INVALID;
110}
#define NSOPTION_SYS_COLOUR_START
Definition: options.h:37
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_INIT_FAILED
Initialisation failed.
Definition: errors.h:38
@ NSERROR_INVALID
Invalid data.
Definition: errors.h:49
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
Netsurf core css API.
#define ns_color_to_nscss(c)
Convert a NetSurf color to a CSS colour primitive.
Definition: css.h:50
Interface to utility string handling.
const char * key
Definition: nsoption.h:111
union nsoption_s::@149 value
colour c
Definition: nsoption.h:120
int key_len
Definition: nsoption.h:112
nserror ns_system_colour_char(const char *name, colour *colour_out)
Obtain a system colour from a name.
Definition: system_colour.c:78
#define colour_list_len
Definition: system_colour.c:34
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
css callback to obtain named system colour.
Definition: system_colour.c:95
static lwc_string ** ns_system_colour_pw
Definition: system_colour.c:38
static lwc_string * colour_list[colour_list_len]
Definition: system_colour.c:36
nserror ns_system_colour_init(void)
Initialise the system colours.
Definition: system_colour.c:42
void ns_system_colour_finalize(void)
release any resources associated with the system colours.
Definition: system_colour.c:67
Interface to system colour values.
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
struct nsoption_s * nsoptions
global active option table.
Definition: nsoption.c:45
Option reading and saving interface.
Interface to a number of general purpose functionality.
#define SLEN(x)
Calculate length of constant C string.
Definition: utils.h:84