summaryrefslogtreecommitdiffstats
path: root/win/tkWinColor.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinColor.c')
-rw-r--r--win/tkWinColor.c64
1 files changed, 17 insertions, 47 deletions
diff --git a/win/tkWinColor.c b/win/tkWinColor.c
index 20ab2e0..5eaeeb3 100644
--- a/win/tkWinColor.c
+++ b/win/tkWinColor.c
@@ -31,11 +31,11 @@ typedef struct WinColor {
*/
typedef struct {
- char *name;
+ const char *name;
int index;
} SystemColorEntry;
-static SystemColorEntry sysColors[] = {
+static const SystemColorEntry sysColors[] = {
{"3dDarkShadow", COLOR_3DDKSHADOW},
{"3dLight", COLOR_3DLIGHT},
{"ActiveBorder", COLOR_ACTIVEBORDER},
@@ -61,15 +61,9 @@ static SystemColorEntry sysColors[] = {
{"Scrollbar", COLOR_SCROLLBAR},
{"Window", COLOR_WINDOW},
{"WindowFrame", COLOR_WINDOWFRAME},
- {"WindowText", COLOR_WINDOWTEXT},
- {NULL, 0}
+ {"WindowText", COLOR_WINDOWTEXT}
};
-typedef struct ThreadSpecificData {
- int ncolors;
-} ThreadSpecificData;
-static Tcl_ThreadDataKey dataKey;
-
/*
* Forward declarations for functions defined later in this file.
*/
@@ -102,37 +96,14 @@ FindSystemColor(
int *indexPtr) /* Out parameter to store color index. */
{
int l, u, r, i;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
-
- /*
- * Count the number of elements in the color array if we haven't done so
- * yet.
- */
-
- if (tsdPtr->ncolors == 0) {
- SystemColorEntry *ePtr;
- int version;
-
- version = LOBYTE(LOWORD(GetVersion()));
- for (ePtr = sysColors; ePtr->name != NULL; ePtr++) {
- if (version < 4) {
- if (ePtr->index == COLOR_3DDKSHADOW) {
- ePtr->index = COLOR_BTNSHADOW;
- } else if (ePtr->index == COLOR_3DLIGHT) {
- ePtr->index = COLOR_BTNHIGHLIGHT;
- }
- }
- tsdPtr->ncolors++;
- }
- }
+ int index;
/*
* Perform a binary search on the sorted array of colors.
*/
l = 0;
- u = tsdPtr->ncolors - 1;
+ u = (sizeof(sysColors) / sizeof(sysColors[0])) - 1;
while (l <= u) {
i = (l + u) / 2;
r = strcasecmp(name, sysColors[i].name);
@@ -148,8 +119,8 @@ FindSystemColor(
return 0;
}
- *indexPtr = sysColors[i].index;
- colorPtr->pixel = GetSysColor(sysColors[i].index);
+ *indexPtr = index = sysColors[i].index;
+ colorPtr->pixel = GetSysColor(index);
/*
* x257 is (value<<8 + value) to get the properly bit shifted and padded
@@ -202,7 +173,7 @@ TkpGetColor(
&& FindSystemColor(name+6, &color, &index))
|| TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), name,
&color)) {
- winColPtr = (WinColor *) ckalloc(sizeof(WinColor));
+ winColPtr = ckalloc(sizeof(WinColor));
winColPtr->info.color = color;
winColPtr->index = index;
@@ -240,7 +211,7 @@ TkpGetColorByValue(
XColor *colorPtr) /* Red, green, and blue fields indicate
* desired color. */
{
- WinColor *tkColPtr = (WinColor *) ckalloc(sizeof(WinColor));
+ WinColor *tkColPtr = ckalloc(sizeof(WinColor));
tkColPtr->info.color.red = colorPtr->red;
tkColPtr->info.color.green = colorPtr->green;
@@ -375,7 +346,7 @@ XAllocColor(
color->blue = closeEntry.peBlue * 257;
entry = closeEntry;
if (index >= cmap->size) {
- OutputDebugString("XAllocColor: Colormap is bigger than we thought");
+ OutputDebugStringA("XAllocColor: Colormap is bigger than we thought");
}
} else {
cmap->size++;
@@ -454,7 +425,7 @@ XFreeColors(
for (i = 0; i < npixels; i++) {
entryPtr = Tcl_FindHashEntry(&cmap->refCounts, INT2PTR(pixels[i]));
if (!entryPtr) {
- Tcl_Panic("Tried to free a color that isn't allocated.");
+ Tcl_Panic("Tried to free a color that isn't allocated");
}
refCount = PTR2INT(Tcl_GetHashValue(entryPtr)) - 1;
if (refCount == 0) {
@@ -463,14 +434,13 @@ XFreeColors(
GetPaletteEntries(cmap->palette, index, 1, &entry);
if (cref == RGB(entry.peRed, entry.peGreen, entry.peBlue)) {
count = cmap->size - index;
- entries = (PALETTEENTRY *)
- ckalloc(sizeof(PALETTEENTRY) * count);
+ entries = ckalloc(sizeof(PALETTEENTRY) * count);
GetPaletteEntries(cmap->palette, index+1, count, entries);
SetPaletteEntries(cmap->palette, index, count, entries);
- ckfree((char *) entries);
+ ckfree(entries);
cmap->size--;
} else {
- Tcl_Panic("Tried to free a color that isn't allocated.");
+ Tcl_Panic("Tried to free a color that isn't allocated");
}
Tcl_DeleteHashEntry(entryPtr);
} else {
@@ -524,7 +494,7 @@ XCreateColormap(
logPalettePtr->palNumEntries = GetPaletteEntries(sysPal, 0, 256,
logPalettePtr->palPalEntry);
- cmap = (TkWinColormap *) ckalloc(sizeof(TkWinColormap));
+ cmap = ckalloc(sizeof(TkWinColormap));
cmap->size = logPalettePtr->palNumEntries;
cmap->stale = 0;
cmap->palette = CreatePalette(logPalettePtr);
@@ -569,10 +539,10 @@ XFreeColormap(
TkWinColormap *cmap = (TkWinColormap *) colormap;
if (!DeleteObject(cmap->palette)) {
- Tcl_Panic("Unable to free colormap, palette is still selected.");
+ Tcl_Panic("Unable to free colormap, palette is still selected");
}
Tcl_DeleteHashTable(&cmap->refCounts);
- ckfree((char *) cmap);
+ ckfree(cmap);
return Success;
}