summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXColor.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-11-12 10:16:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-11-12 10:16:00 (GMT)
commit011db3181f22da410d14abd5df6dc1da7d0fed6f (patch)
tree4d01ddf684235961ad07ecd0e91e4b3136de618d /macosx/tkMacOSXColor.c
parent950726731dd2068e363d294fedc3d3a68da2698b (diff)
parenta57e550fe40ed58660f2b7e50f64f56bbc0e9518 (diff)
downloadtk-011db3181f22da410d14abd5df6dc1da7d0fed6f.zip
tk-011db3181f22da410d14abd5df6dc1da7d0fed6f.tar.gz
tk-011db3181f22da410d14abd5df6dc1da7d0fed6f.tar.bz2
Merge trunk. Clean-up win32 systray code (not completed yet, still some ANSI functions are used which cannot handle full Unicode)
Diffstat (limited to 'macosx/tkMacOSXColor.c')
-rw-r--r--macosx/tkMacOSXColor.c146
1 files changed, 13 insertions, 133 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index 2bcbd4e..4fe3ce4 100644
--- a/macosx/tkMacOSXColor.c
+++ b/macosx/tkMacOSXColor.c
@@ -282,6 +282,7 @@ GetRGBA(
if (!sRGB) {
sRGB = [NSColorSpace sRGBColorSpace];
}
+
switch (entry->type) {
case rgbColor:
rgba[0] = ((pixel >> 16) & 0xff) / 255.0;
@@ -430,22 +431,21 @@ TkMacOSXInDarkMode(Tk_Window tkwin)
* Sets the components of a CGColorRef from an XColor pixel value. The
* pixel value is used to look up the color in the system color table, and
* then SetCGColorComponents is called with the table entry and the pixel
- * value.
+ * value. The parameter macColor should be a pointer to a CGColorRef.
*
* Results:
* Returns false if the color is not found, true otherwise.
*
* Side effects:
- * The variable macColor is set to a new CGColorRef, the caller is
- * responsible for releasing it!
+ * The CGColorRef referenced by the variable macColor may be modified.
*
*----------------------------------------------------------------------
*/
int
TkSetMacColor(
- unsigned long pixel, /* Pixel value to convert. */
- void *macColor) /* CGColorRef to modify. */
+ unsigned long pixel, /* Pixel value to convert. */
+ void *macColor) /* CGColorRef to modify. */
{
CGColorRef *color = (CGColorRef*)macColor;
SystemColorDatum *entry = GetEntryFromPixel(pixel);
@@ -460,118 +460,6 @@ TkSetMacColor(
/*
*----------------------------------------------------------------------
*
- * TkpInitGCCache, TkpFreeGCCache, CopyCachedColor, SetCachedColor --
- *
- * Maintain a per-GC cache of previously converted CGColorRefs
- *
- * Results:
- * None resp. retained CGColorRef for CopyCachedColor()
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkpInitGCCache(
- GC gc)
-{
- bzero(TkpGetGCCache(gc), sizeof(TkpGCCache));
-}
-
-void
-TkpFreeGCCache(
- GC gc)
-{
- TkpGCCache *gcCache = TkpGetGCCache(gc);
-
- if (gcCache->cachedForegroundColor) {
- CFRelease(gcCache->cachedForegroundColor);
- }
- if (gcCache->cachedBackgroundColor) {
- CFRelease(gcCache->cachedBackgroundColor);
- }
-}
-
-static CGColorRef
-CopyCachedColor(
- GC gc,
- unsigned long pixel)
-{
- TkpGCCache *gcCache = TkpGetGCCache(gc);
- CGColorRef cgColor = NULL;
-
- if (gcCache) {
- if (gcCache->cachedForeground == pixel) {
- cgColor = gcCache->cachedForegroundColor;
- } else if (gcCache->cachedBackground == pixel) {
- cgColor = gcCache->cachedBackgroundColor;
- }
- if (cgColor) {
- CFRetain(cgColor);
- }
- }
- return cgColor;
-}
-
-static void
-SetCachedColor(
- GC gc,
- unsigned long pixel,
- CGColorRef cgColor)
-{
- TkpGCCache *gcCache = TkpGetGCCache(gc);
-
- if (gcCache && cgColor) {
- if (gc->foreground == pixel) {
- if (gcCache->cachedForegroundColor) {
- CFRelease(gcCache->cachedForegroundColor);
- }
- gcCache->cachedForegroundColor = (CGColorRef) CFRetain(cgColor);
- gcCache->cachedForeground = pixel;
- } else if (gc->background == pixel) {
- if (gcCache->cachedBackgroundColor) {
- CFRelease(gcCache->cachedBackgroundColor);
- }
- gcCache->cachedBackgroundColor = (CGColorRef) CFRetain(cgColor);
- gcCache->cachedBackground = pixel;
- }
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkMacOSXCreateCGColor --
- *
- * Creates a CGColorRef from a X style pixel value.
- *
- * Results:
- * Returns NULL if not a real pixel, CGColorRef otherwise.
- *
- * Side effects:
- * None
- *
- *----------------------------------------------------------------------
- */
-
-CGColorRef
-TkMacOSXCreateCGColor(
- GC gc,
- unsigned long pixel) /* Pixel value to convert. */
-{
- CGColorRef cgColor = CopyCachedColor(gc, pixel);
-
- if (!cgColor && TkSetMacColor(pixel, &cgColor)) {
- SetCachedColor(gc, pixel, cgColor);
- }
- return cgColor;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* TkMacOSXGetNSColor --
*
* Creates an autoreleased NSColor from a X style pixel value.
@@ -588,22 +476,16 @@ TkMacOSXCreateCGColor(
NSColor*
TkMacOSXGetNSColor(
- GC gc,
+ TCL_UNUSED(GC),
unsigned long pixel) /* Pixel value to convert. */
{
- CGColorRef cgColor = TkMacOSXCreateCGColor(gc, pixel);
+ CGColorRef cgColor;
NSColor *nsColor = nil;
- if (cgColor) {
- NSColorSpace *colorSpace = [[NSColorSpace alloc]
- initWithCGColorSpace:CGColorGetColorSpace(cgColor)];
-
- nsColor = [NSColor colorWithColorSpace:colorSpace
- components:CGColorGetComponents(cgColor)
- count:CGColorGetNumberOfComponents(cgColor)];
- [colorSpace release];
- CFRelease(cgColor);
- }
+ TkSetMacColor(pixel, &cgColor);
+ nsColor = [NSColor colorWithColorSpace:sRGB
+ components:CGColorGetComponents(cgColor)
+ count:CGColorGetNumberOfComponents(cgColor)];
return nsColor;
}
@@ -627,7 +509,7 @@ TkMacOSXGetNSColor(
void
TkMacOSXSetColorInContext(
- GC gc,
+ TCL_UNUSED(GC),
unsigned long pixel,
CGContextRef context)
{
@@ -646,9 +528,7 @@ TkMacOSXSetColorInContext(
}
break;
default:
- if (SetCGColorComponents(entry, pixel, &cgColor)){
- SetCachedColor(gc, pixel, cgColor);
- }
+ SetCGColorComponents(entry, pixel, &cgColor);
break;
}
}