summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <jan.nijtmans@noemail.net>2012-02-10 23:55:24 (GMT)
committerjan.nijtmans <jan.nijtmans@noemail.net>2012-02-10 23:55:24 (GMT)
commitcca9ed326599756620a7712dfb6be83e1724a6f4 (patch)
tree50bfed10a7859a141c470f598ee83cd31ca8ebfd /generic
parentf67cc2dfbb28c39d35ed3efe4c325792a7f68e92 (diff)
downloadtk-cca9ed326599756620a7712dfb6be83e1724a6f4.zip
tk-cca9ed326599756620a7712dfb6be83e1724a6f4.tar.gz
tk-cca9ed326599756620a7712dfb6be83e1724a6f4.tar.bz2
proposed fix for bug-3486474
FossilOrigin-Name: 6f74cf37d47277636825553974d4f586dccb35ca
Diffstat (limited to 'generic')
-rw-r--r--generic/tkColor.c55
-rw-r--r--generic/tkCursor.c4
-rw-r--r--generic/tkImgBmap.c4
-rw-r--r--generic/tkImgPhoto.c2
-rw-r--r--generic/tkInt.h7
5 files changed, 67 insertions, 5 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__ */
diff --git a/generic/tkCursor.c b/generic/tkCursor.c
index 466d0ef..f599083 100644
--- a/generic/tkCursor.c
+++ b/generic/tkCursor.c
@@ -357,12 +357,12 @@ Tk_GetCursorFromData(interp, tkwin, source, mask, width, height,
* available and add it to the database.
*/
- if (XParseColor(dataKey.display, Tk_Colormap(tkwin), fg, &fgColor) == 0) {
+ if (TkParseColor(dataKey.display, Tk_Colormap(tkwin), fg, &fgColor) == 0) {
Tcl_AppendResult(interp, "invalid color name \"", fg, "\"",
(char *) NULL);
goto error;
}
- if (XParseColor(dataKey.display, Tk_Colormap(tkwin), bg, &bgColor) == 0) {
+ if (TkParseColor(dataKey.display, Tk_Colormap(tkwin), bg, &bgColor) == 0) {
Tcl_AppendResult(interp, "invalid color name \"", bg, "\"",
(char *) NULL);
goto error;
diff --git a/generic/tkImgBmap.c b/generic/tkImgBmap.c
index 99ae050..e1ccecb 100644
--- a/generic/tkImgBmap.c
+++ b/generic/tkImgBmap.c
@@ -1266,7 +1266,7 @@ ImgBmapPostscript(clientData, interp, tkwin, psinfo, x, y, width, height,
*/
if ((masterPtr->bgUid != NULL) && (masterPtr->bgUid[0] != '\000')) {
XColor color;
- XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->bgUid,
+ TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->bgUid,
&color);
if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) {
return TCL_ERROR;
@@ -1286,7 +1286,7 @@ ImgBmapPostscript(clientData, interp, tkwin, psinfo, x, y, width, height,
*/
if ( (masterPtr->fgUid != NULL) && (masterPtr->data != NULL) ) {
XColor color;
- XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->fgUid,
+ TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->fgUid,
&color);
if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) {
return TCL_ERROR;
diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c
index 80b44d7..ffbb47c 100644
--- a/generic/tkImgPhoto.c
+++ b/generic/tkImgPhoto.c
@@ -1150,7 +1150,7 @@ ImgPhotoCmd(clientData, interp, objc, objv)
break;
}
for (x = 0; x < dataWidth; ++x) {
- if (!XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin),
+ if (!TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin),
listArgv[x], &color)) {
Tcl_AppendResult(interp, "can't parse color \"",
listArgv[x], "\"", (char *) NULL);
diff --git a/generic/tkInt.h b/generic/tkInt.h
index 777201e..c274236 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1213,6 +1213,13 @@ EXTERN int TkParsePadAmount _ANSI_ARGS_((Tcl_Interp *interp,
Tk_Window tkwin, Tcl_Obj *objPtr,
int *pad1Ptr, int *pad2Ptr));
EXTERN int TkpAlwaysShowSelection _ANSI_ARGS_((Tk_Window tkwin));
+#ifdef __WIN32__
+#define TkParseColor XParseColor
+#else
+EXTERN Status TkParseColor _ANSI_ARGS_((Display * display,
+ Colormap map, _Xconst char* spec,
+ XColor * colorPtr));
+#endif
/*
* Unsupported commands.