Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #716 from jcbertin/develop
Browse files Browse the repository at this point in the history
Fixed NSColor compatibility for deployment targets inferior to 10.8.
  • Loading branch information
odrobnik committed Feb 5, 2014
2 parents 638b218 + 993bda6 commit 49c4f3a
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Core/Source/DTColor+Compatibility.m
Expand Up @@ -22,9 +22,50 @@ - (CGFloat)alphaComponent


#else #else


#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_7
#import <objc/runtime.h>

@interface NSColor (DTCoreText)
+ (NSColor *)DTCoreText_colorWithCGColor:(CGColorRef)cgColor;
- (CGColorRef)DTCoreText_CGColor;
@end

static void DTCoreTextAddMissingSelector(Class aClass, SEL aSelector, SEL implementationSelector)
{
Method method = class_getInstanceMethod(aClass, aSelector);
if (method == NULL) {
method = class_getInstanceMethod(aClass, implementationSelector);
NSCAssert(method != NULL, @"missing implementation method");

IMP methodImplementation = method_getImplementation(method);
const char *methodTypeEncoding = method_getTypeEncoding(method);

#if !defined(NS_BLOCK_ASSERTIONS)
BOOL rc = class_addMethod(aClass, aSelector, methodImplementation, methodTypeEncoding);
NSCAssert(rc, @"failed to add missing method");
#else
(void) class_addMethod(aClass, aSelector, methodImplementation, methodTypeEncoding);
#endif
}
}

__attribute__((constructor))
static void DTCoreTextNSColorInitialization(void)
{
Class NSColorClass = objc_getClass("NSColor");
Class NSColorMetaClass = object_getClass(NSColorClass);
DTCoreTextAddMissingSelector(NSColorMetaClass, @selector(colorWithCGColor:), @selector(DTCoreText_colorWithCGColor:));
DTCoreTextAddMissingSelector(NSColorClass, @selector(CGColor), @selector(DTCoreText_CGColor));
}

#define colorWithCGColor DTCoreText_colorWithCGColor
#define CGColor DTCoreText_CGColor
#define HTML DTCoreText
#endif

@implementation NSColor (HTML) @implementation NSColor (HTML)


#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_7 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_7 || MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_7
+ (NSColor *)colorWithCGColor:(CGColorRef)cgColor + (NSColor *)colorWithCGColor:(CGColorRef)cgColor
{ {
size_t count = CGColorGetNumberOfComponents(cgColor); size_t count = CGColorGetNumberOfComponents(cgColor);
Expand Down

0 comments on commit 49c4f3a

Please sign in to comment.