Cleanup NSCursor/NSImage subtitution code for hardcoded Xcode images in XIBs

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@40278 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2016-12-22 20:56:31 +00:00
parent e59e74cb90
commit 25897d63e8
2 changed files with 84 additions and 36 deletions

View file

@ -41,6 +41,11 @@
#import "GNUstepGUI/GSDisplayServer.h"
@interface NSImage (Private)
+ (NSDictionary *)_XcodeImageMappings;
+ (NSArray *)_XcodeImagePaths;
@end
// Class variables
static NSMutableArray *gnustep_gui_cursor_stack;
static NSCursor *gnustep_gui_current_cursor;
@ -608,7 +613,7 @@ backgroundColorHint:(NSColor *)bg
DESTROY(self);
if ([aDecoder containsValueForKey: @"NSCursorType"])
{
int type = [aDecoder decodeIntForKey: @"NSCursorType"];
int type = [aDecoder decodeIntForKey: @"NSCursorType"];
switch (type)
{
@ -666,7 +671,7 @@ backgroundColorHint:(NSColor *)bg
break;
}
RETAIN(self);
}
}
else
{
NSPoint hotSpot = NSMakePoint(0, 0);
@ -682,20 +687,31 @@ backgroundColorHint:(NSColor *)bg
}
// Testplant-MAL-2015-06-26: Keeping testplant fixes...
if ([[image name] isEqualToString:@"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff"])
{
NSDebugLog(@"An NSCursor object was encoded with the image "
@"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff. "
@"This cursor was automatically substituted with [NSCursor IBeamCursor].");
[image setName:nil];
self = RETAIN([NSCursor IBeamCursor]);
}
else
{
self = [[NSCursor alloc] initWithImage: image
hotSpot: hotSpot];
}
if ([[NSImage _XcodeImagePaths] containsObject:[image name]])
{
NSString *selectorName = [[NSImage _XcodeImageMappings] objectForKey:[image name]];
SEL selector = NSSelectorFromString(selectorName);
if (selector == NULL)
{
NSDebugLog(@"An NSCursor object was encoded with the image %@ which was not automatically substituted with NSCursor substitute due to missing selector: %@.", [image name], selectorName);
}
else
{
NSDebugLog(@"An NSCursor object was encoded with the image %@. This cursor was automatically substituted with NSCursor substitute (%@).", [image name], selectorName);
self = RETAIN([NSCursor performSelector:selector]);
[image setName:nil];
}
}
else if (image == nil)
{
NSLog(@"%s:NSCursor object was encoded with image which was not found", __PRETTY_FUNCTION__);
}
else
{
self = [[NSCursor alloc] initWithImage: image hotSpot: hotSpot];
}
}
}
else

View file

@ -394,6 +394,8 @@ static NSArray *imagePasteboardTypes = nil;
static NSArray *iterate_reps_for_types(NSArray *imageReps, SEL method);
static NSDictionary *_XcodeImageMappings = nil;
/* Find the GSRepData object holding a representation */
static GSRepData*
repd_for_rep(NSArray *_reps, NSImageRep *rep)
@ -418,6 +420,8 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
@interface NSImage (Private)
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
+ (void) _reloadCachedImages;
+ (NSArray*) _XcodeImagePaths;
+ (NSDictionary*) _XcodeImageMappings;
- (BOOL) _useFromFile: (NSString *)fileName;
- (BOOL) _loadFromData: (NSData *)data;
- (BOOL) _loadFromFile: (NSString *)fileName;
@ -439,7 +443,18 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
// Initial version
[self setVersion: 1];
{
if (_XcodeImageMappings == nil)
{
@synchronized([self class])
{
_XcodeImageMappings = @{ @"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff" : @"IBeamCursor" };
RETAIN(_XcodeImageMappings);
}
}
}
// initialize the class variables
nameDict = [[NSMutableDictionary alloc] initWithCapacity: 10];
path = [NSBundle pathForLibraryResource: @"nsmapping"
@ -2025,26 +2040,33 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
if (rep == nil)
{
// Testplant-MAL-10042016: keeping branch code...
NSString *fileName = [[tmp absoluteString] lastPathComponent];
NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName];
rep = [NSImageRep imageRepWithContentsOfFile: path];
// This hack is a workaround on the issue where Xcode is including its cursor image
// on NSTextView's scroll view: We set the name of the image so we can catch it
// in the NSCursor's initWithCoder:
NSString *filePath = [tmp absoluteString];
NSString *fileName = [filePath lastPathComponent];
NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName];
// This hack is a workaround on the issue where Xcode is including its cursor image
// on NSTextView's scroll view: We set the name of the image so we can catch it
// in the NSCursor's initWithCoder:
if ([[tmp absoluteString] isEqualToString:@"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff"])
{
[self setName:[tmp absoluteString]];
}
else if ([[tmp absoluteString] rangeOfString:@"/Xcode.app/"].length > 0
|| [[tmp absoluteString] rangeOfString:@"/DVTKit.framework/"].length > 0)
{
NSDebugLog (@"WARNING: Decoding image with absolute path %@."
@" Xcode may have inserted this in your XIB and the"
@" image may not be available in the app's resources"
, [tmp absoluteString]);
}
// Check Xcode known hard-encoded image references...
if (path == nil)
{
if ([[[self class] _XcodeImagePaths] containsObject:filePath])
{
[self setName:[tmp absoluteString]];
}
else if (([filePath rangeOfString:@"/Xcode.app/"].length > 0) ||
([filePath rangeOfString:@"/DVTKit.framework/"].length > 0))
{
NSDebugLog (@"WARNING: Decoding image with absolute path %@."
@" Xcode may have inserted this in your XIB and the"
@" image may not be available in the app's resources"
, [tmp absoluteString]);
}
}
else
{
rep = [NSImageRep imageRepWithContentsOfFile: path];
}
}
// If the representation was found, add it...
@ -2302,6 +2324,16 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
return ok;
}
+ (NSArray *)_XcodeImagePaths
{
return [_XcodeImageMappings allKeys];
}
+ (NSDictionary *)_XcodeImageMappings
{
return _XcodeImageMappings;
}
- (BOOL) _loadFromFile: (NSString *)fileName
{
NSArray *array;