Ticket #2171: colors for popup menu:
[pantumic.git] / lib / skin / colors-old.c
blobb9bc1fcdcf44715e3db29fa7049bebdbe429ec34
1 /*
2 Skins engine.
3 Work with colors - backward compability
5 Copyright (C) 2009 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 MA 02110-1301, USA.
28 #include <config.h>
29 #include <stdlib.h>
30 #include <sys/types.h> /* size_t */
32 #include "internal.h"
34 #include "lib/tty/color.h"
36 #include "src/setup.h"
38 /*** global variables ****************************************************************************/
40 /*** file scope macro definitions ****************************************************************/
42 /*** file scope type declarations ****************************************************************/
44 typedef struct mc_skin_colors_old_struct
46 const char *old_color;
47 const char *group;
48 const char *key;
49 } mc_skin_colors_old_t;
51 /*** file scope variables ************************************************************************/
53 static const mc_skin_colors_old_t old_colors[] = {
54 {"normal", "core", "_default_"},
55 {"marked", "core", "marked"},
56 {"selected", "core", "selected"},
57 {"markselect", "core", "markselect"},
58 {"disabled", "core", "disabled"},
59 {"reverse", "core", "reverse"},
60 {"dnormal", "dialog", "_default_"},
61 {"dfocus", "dialog", "dfocus"},
62 {"dhotnormal", "dialog", "dhotnormal"},
63 {"dhotfocus", "dialog", "dhotfocus"},
64 {"errors", "error", "_default_"},
65 {"errdhotnormal", "error", "errdhotnormal"},
66 {"errdhotfocus", "error", "errdhotfocus"},
67 {"menunormal", "menu", "_default_"},
68 {"menuhot", "menu", "menuhot"},
69 {"menusel", "menu", "menusel"},
70 {"menuhotsel", "menu", "menuhotsel"},
71 {"menuinactive", "menu", "menuinactive"},
72 {"pmenunormal", "popupmenu", "_default_"},
73 {"pmenusel", "popupmenu", "menusel"},
74 {"pmenutitle", "popupmenu", "menutitle"},
75 {"bbarhotkey", "buttonbar", "hotkey"},
76 {"bbarbutton", "buttonbar", "button"},
77 {"statusbar", "statusbar", "_default_"},
78 {"gauge", "core", "gauge"},
79 {"input", "core", "input"},
80 {"inputmark", "core", "inputmark"},
81 {"inputunchanged", "core", "inputunchanged"},
82 {"commandlinemark", "core", "commandlinemark"},
83 {"helpnormal", "help", "_default_"},
84 {"helpitalic", "help", "helpitalic"},
85 {"helpbold", "help", "helpbold"},
86 {"helplink", "help", "helplink"},
87 {"helpslink", "help", "helpslink"},
88 {"viewunderline", "viewer", "viewunderline"},
89 {"editnormal", "editor", "_default_"},
90 {"editbold", "editor", "editbold"},
91 {"editmarked", "editor", "editmarked"},
92 {"editwhitespace", "editor", "editwhitespace"},
93 {"editlinestate", "editor", "editlinestate"},
94 {NULL, NULL, NULL}
98 /*** file scope functions ************************************************************************/
99 /* --------------------------------------------------------------------------------------------- */
101 static gboolean
102 mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
104 int lc_index;
106 if (old_color != NULL)
107 for (lc_index = 0; old_colors[lc_index].old_color; lc_index++)
108 if (strcasecmp (old_color, old_colors[lc_index].old_color) == 0)
110 if (group != NULL)
111 *group = old_colors[lc_index].group;
112 if (key != NULL)
113 *key = old_colors[lc_index].key;
114 return TRUE;
116 return FALSE;
119 /* --------------------------------------------------------------------------------------------- */
121 static void
122 mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
124 gchar **colors, **orig_colors;
125 gchar **key_val;
126 const gchar *skin_group, *skin_key;
127 gchar *skin_val;
129 if (the_color_string == NULL)
130 return;
132 orig_colors = colors = g_strsplit (the_color_string, ":", -1);
133 if (colors == NULL)
134 return;
136 for (; *colors; colors++)
138 key_val = g_strsplit_set (*colors, "=,", 3);
140 if (!key_val)
141 continue;
143 if (key_val[1] == NULL
144 || !mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
146 g_strfreev (key_val);
147 continue;
150 if (key_val[2] != NULL)
151 skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
152 else
153 skin_val = g_strdup_printf ("%s;", key_val[1]);
154 mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
156 g_free (skin_val);
158 g_strfreev (key_val);
160 g_strfreev (orig_colors);
163 /* --------------------------------------------------------------------------------------------- */
164 /*** public functions ****************************************************************************/
165 /* --------------------------------------------------------------------------------------------- */
167 void
168 mc_skin_colors_old_configure (mc_skin_t * mc_skin)
170 mc_skin_colors_old_configure_one (mc_skin, setup_color_string);
171 mc_skin_colors_old_configure_one (mc_skin, term_color_string);
172 mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
173 mc_skin_colors_old_configure_one (mc_skin, command_line_colors);
176 /* --------------------------------------------------------------------------------------------- */