summaryrefslogtreecommitdiffstats
path: root/generic/tkColor.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-10 23:55:24 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-10 23:55:24 (GMT)
commitc910863e19f9c9cc3db56924634315a37ecfe2bb (patch)
tree50bfed10a7859a141c470f598ee83cd31ca8ebfd /generic/tkColor.c
parentd0aa23eb9005cbc9b4e706ab70b5082be80bad35 (diff)
downloadtk-c910863e19f9c9cc3db56924634315a37ecfe2bb.zip
tk-c910863e19f9c9cc3db56924634315a37ecfe2bb.tar.gz
tk-c910863e19f9c9cc3db56924634315a37ecfe2bb.tar.bz2
proposed fix for bug-3486474
Diffstat (limited to 'generic/tkColor.c')
-rw-r--r--generic/tkColor.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/generic/tkColor.c b/generic/tkColor.c
index f06c43f..87f3209 100644
--- a/generic/tkColor.c
+++ b/generic/tkColor.c
@@ -809,3 +809,58 @@ TkDebugColor(tkwin, name)
}
return resultPtr;
}
+
+#ifndef __WIN32__
+/* This function is not necessary for Win32,
+ * since XParseColor already does the right thing */
+Status
+TkParseColor(display, map, spec, colorPtr)
+ Display * display; /* The display */
+ Colormap map; /* Color map */
+ _Xconst char* spec; /* String to be parsed */
+ XColor * colorPtr;
+{
+ if (*spec == '#') {
+ char buf[14];
+ buf[0] = '#'; buf[13] = '\0';
+ if (!spec[1] || !spec[2] || !spec[3]) {
+ /* Not at least 3 hex digits, so invalid */
+ return 0;
+ } else if (!spec[4]) {
+ /* Exactly 3 hex digits */
+ buf[1] = buf[2] = buf[3] = buf[4] = spec[1];
+ buf[5] = buf[6] = buf[7] = buf[8] = spec[2];
+ buf[9] = buf[10] = buf[11] = buf[12] = spec[3];
+ return XParseColor(display, map, buf, colorPtr);
+ } else if (!spec[5] || !spec[6]) {
+ /* Not at least 6 hex digits, so invalid */
+ return 0;
+ } else if (!spec[7]) {
+ /* Exactly 6 hex digits */
+ buf[1] = buf[3] = spec[1];
+ buf[2] = buf[4] = spec[2];
+ buf[5] = buf[7] = spec[3];
+ buf[6] = buf[8] = spec[4];
+ buf[9] = buf[11] = spec[5];
+ buf[10] = buf[12] = spec[6];
+ return XParseColor(display, map, buf, colorPtr);
+ } else if (!spec[8] || !spec[9]) {
+ /* Not at least 9 hex digits, so invalid */
+ return 0;
+ } else if (!spec[10]) {
+ /* Exactly 9 hex digits */
+ buf[1] = buf[4] = spec[1];
+ buf[2] = spec[2];
+ buf[3] = spec[3];
+ buf[5] = buf[8] = spec[4];
+ buf[6] = spec[5];
+ buf[7] = spec[6];
+ buf[9] = buf[12] = spec[7];
+ buf[10] = spec[8];
+ buf[11] = spec[9];
+ return XParseColor(display, map, buf, colorPtr);
+ }
+ }
+ return XParseColor(display, map, spec, colorPtr);
+}
+#endif /* __WIN32__ */