Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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. /** \file
  20.  * System colour handling
  21.  *
  22.  */
  23.  
  24. #include "utils/utils.h"
  25. #include "utils/log.h"
  26. #include "desktop/gui.h"
  27. #include "desktop/options.h"
  28.  
  29. struct gui_system_colour_ctx {
  30.         const char *name;
  31.         int length;
  32.         css_color colour;
  33.         colour *option_colour;
  34.         lwc_string *lwcstr;
  35. };
  36.  
  37. static struct gui_system_colour_ctx colour_list[] = {
  38.         {
  39.                 "ActiveBorder",
  40.                 SLEN("ActiveBorder"),
  41.                 0xff000000,
  42.                 &nsoption_colour(sys_colour_ActiveBorder),
  43.                 NULL
  44.         }, {
  45.                 "ActiveCaption",
  46.                 SLEN("ActiveCaption"),
  47.                 0xffdddddd,
  48.                 &nsoption_colour(sys_colour_ActiveCaption),
  49.                 NULL
  50.         }, {
  51.                 "AppWorkspace",
  52.                 SLEN("AppWorkspace"),
  53.                 0xffeeeeee,
  54.                 &nsoption_colour(sys_colour_AppWorkspace),
  55.                 NULL
  56.         }, {
  57.                 "Background",
  58.                 SLEN("Background"),
  59.                 0xff0000aa,
  60.                 &nsoption_colour(sys_colour_Background),
  61.                 NULL
  62.         }, {
  63.                 "ButtonFace",
  64.                 SLEN("ButtonFace"),
  65.                 0xffaaaaaa,
  66.                 &nsoption_colour(sys_colour_ButtonFace),
  67.                 NULL
  68.         }, {
  69.                 "ButtonHighlight",
  70.                 SLEN("ButtonHighlight"),
  71.                 0xffdddddd,
  72.                 &nsoption_colour(sys_colour_ButtonHighlight),
  73.                 NULL
  74.         }, {
  75.                 "ButtonShadow",
  76.                 SLEN("ButtonShadow"),
  77.                 0xffbbbbbb,
  78.                 &nsoption_colour(sys_colour_ButtonShadow),
  79.                 NULL
  80.         }, {
  81.                 "ButtonText",
  82.                 SLEN("ButtonText"),
  83.                 0xff000000,
  84.                 &nsoption_colour(sys_colour_ButtonText),
  85.                 NULL
  86.         }, {
  87.                 "CaptionText",
  88.                 SLEN("CaptionText"),
  89.                 0xff000000,
  90.                 &nsoption_colour(sys_colour_CaptionText),
  91.                 NULL
  92.         }, {
  93.                 "GrayText",
  94.                 SLEN("GrayText"),
  95.                 0xffcccccc,
  96.                 &nsoption_colour(sys_colour_GrayText),
  97.                 NULL
  98.         }, {
  99.                 "Highlight",
  100.                 SLEN("Highlight"),
  101.                 0xff0000ee,
  102.                 &nsoption_colour(sys_colour_Highlight),
  103.                 NULL
  104.         }, {
  105.                 "HighlightText",
  106.                 SLEN("HighlightText"),
  107.                 0xff000000,
  108.                 &nsoption_colour(sys_colour_HighlightText),
  109.                 NULL
  110.         }, {
  111.                 "InactiveBorder",
  112.                 SLEN("InactiveBorder"),
  113.                 0xffffffff,
  114.                 &nsoption_colour(sys_colour_InactiveBorder),
  115.                 NULL
  116.         }, {
  117.                 "InactiveCaption",
  118.                 SLEN("InactiveCaption"),
  119.                 0xffffffff,
  120.                 &nsoption_colour(sys_colour_InactiveCaption),
  121.                 NULL
  122.         }, {
  123.                 "InactiveCaptionText",
  124.                 SLEN("InactiveCaptionText"),
  125.                 0xffcccccc,
  126.                 &nsoption_colour(sys_colour_InactiveCaptionText),
  127.                 NULL
  128.         }, {
  129.                 "InfoBackground",
  130.                 SLEN("InfoBackground"),
  131.                 0xffaaaaaa,
  132.                 &nsoption_colour(sys_colour_InfoBackground),
  133.                 NULL
  134.         }, {
  135.                 "InfoText",
  136.                 SLEN("InfoText"),
  137.                 0xff000000,
  138.                 &nsoption_colour(sys_colour_InfoText),
  139.                 NULL
  140.         }, {
  141.                 "Menu",
  142.                 SLEN("Menu"),
  143.                 0xffaaaaaa,
  144.                 &nsoption_colour(sys_colour_Menu),
  145.                 NULL
  146.         }, {
  147.                 "MenuText",
  148.                 SLEN("MenuText"),
  149.                 0xff000000,
  150.                 &nsoption_colour(sys_colour_MenuText),
  151.                 NULL
  152.         }, {
  153.                 "Scrollbar",
  154.                 SLEN("Scrollbar"),
  155.                 0xffaaaaaa,
  156.                 &nsoption_colour(sys_colour_Scrollbar),
  157.                 NULL
  158.         }, {
  159.                 "ThreeDDarkShadow",
  160.                 SLEN("ThreeDDarkShadow"),
  161.                 0xff555555,
  162.                 &nsoption_colour(sys_colour_ThreeDDarkShadow),
  163.                 NULL
  164.         }, {
  165.                 "ThreeDFace",
  166.                 SLEN("ThreeDFace"),
  167.                 0xffdddddd,
  168.                 &nsoption_colour(sys_colour_ThreeDFace),
  169.                 NULL
  170.         }, {
  171.                 "ThreeDHighlight",
  172.                 SLEN("ThreeDHighlight"),
  173.                 0xffaaaaaa,
  174.                 &nsoption_colour(sys_colour_ThreeDHighlight),
  175.                 NULL
  176.         }, {
  177.                 "ThreeDLightShadow",
  178.                 SLEN("ThreeDLightShadow"),
  179.                 0xff999999,
  180.                 &nsoption_colour(sys_colour_ThreeDLightShadow),
  181.                 NULL
  182.         }, {
  183.                 "ThreeDShadow",
  184.                 SLEN("ThreeDShadow"),
  185.                 0xff777777,
  186.                 &nsoption_colour(sys_colour_ThreeDShadow),
  187.                 NULL
  188.         }, {
  189.                 "Window",
  190.                 SLEN("Window"),
  191.                 0xffaaaaaa,
  192.                 &nsoption_colour(sys_colour_Window),
  193.                 NULL
  194.         }, {
  195.                 "WindowFrame",
  196.                 SLEN("WindowFrame"),
  197.                 0xff000000,
  198.                 &nsoption_colour(sys_colour_WindowFrame),
  199.                 NULL
  200.         }, {
  201.  
  202.                 "WindowText",
  203.                 SLEN("WindowText"),
  204.                 0xff000000,
  205.                 &nsoption_colour(sys_colour_WindowText),
  206.                 NULL
  207.         },
  208.  
  209. };
  210.  
  211. #define colour_list_len (sizeof(colour_list) / sizeof(struct gui_system_colour_ctx))
  212.  
  213. static struct gui_system_colour_ctx *gui_system_colour_pw = NULL;
  214.  
  215.  
  216. bool gui_system_colour_init(void)
  217. {
  218.         unsigned int ccount;
  219.  
  220.         if (gui_system_colour_pw != NULL)
  221.                 return false;
  222.  
  223.         /* Intern colour strings */
  224.         for (ccount = 0; ccount < colour_list_len; ccount++) {
  225.                 if (lwc_intern_string(colour_list[ccount].name,
  226.                                       colour_list[ccount].length,
  227.                                       &(colour_list[ccount].lwcstr)) != lwc_error_ok) {
  228.                         return false;
  229.                 }
  230.         }
  231.  
  232.         /* pull in options if set (ie not transparent) */
  233.         for (ccount = 0; ccount < colour_list_len; ccount++) {
  234.                 if (*(colour_list[ccount].option_colour) != 0) {
  235.                         colour_list[ccount].colour = *(colour_list[ccount].option_colour);
  236.                 }
  237.         }
  238.  
  239.         gui_system_colour_pw = colour_list;
  240.  
  241.         return true;
  242. }
  243.  
  244. void gui_system_colour_finalize(void)
  245. {
  246.         unsigned int ccount;
  247.  
  248.         for (ccount = 0; ccount < colour_list_len; ccount++) {
  249.                 lwc_string_unref(colour_list[ccount].lwcstr);
  250.         }
  251. }
  252.  
  253. colour gui_system_colour_char(const char *name)
  254. {
  255.         colour ret = 0xff00000;
  256.         unsigned int ccount;
  257.  
  258.         for (ccount = 0; ccount < colour_list_len; ccount++) {
  259.                 if (strcmp(name, colour_list[ccount].name) == 0) {
  260.                         ret = colour_list[ccount].colour;
  261.                         break;
  262.                 }
  263.         }
  264.         return ret;
  265. }
  266.  
  267. css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour)
  268. {
  269.         unsigned int ccount;
  270.         bool match;
  271.  
  272.         for (ccount = 0; ccount < colour_list_len; ccount++) {
  273.                 if (lwc_string_caseless_isequal(name,
  274.                                 colour_list[ccount].lwcstr,
  275.                                 &match) == lwc_error_ok && match) {
  276.                         *colour = colour_list[ccount].colour;
  277.                         return CSS_OK;
  278.                 }
  279.         }
  280.  
  281.         return CSS_INVALID;
  282. }
  283.