Merge more code with gui main branch revision 39484

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@39507 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2016-03-09 16:28:35 +00:00
parent 2088ec1ab5
commit 2c8aba77c6
9 changed files with 460 additions and 263 deletions

View file

@ -24,6 +24,9 @@
/* Define to 1 if you have the `getmntinfo' function. */
#undef HAVE_GETMNTINFO
/* Define to 1 if you have the `GifQuantizeBuffer' function. */
#undef HAVE_GIFQUANTIZEBUFFER
/* Have ImageMagick */
#undef HAVE_IMAGEMAGICK
@ -96,12 +99,18 @@
/* Define to 1 if you have the <sys/mntent.h> header file. */
#undef HAVE_SYS_MNTENT_H
/* Define to 1 if you have the <sys/statvfs.h> header file. */
#undef HAVE_SYS_STATVFS_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/vfs.h> header file. */
#undef HAVE_SYS_VFS_H
/* Define to 1 if you have the <unicode/uchar.h> header file. */
#undef HAVE_UNICODE_UCHAR_H

View file

@ -3,7 +3,7 @@
Main include file for GNUstep GUI Library
Copyright (C) 1996 Free Software Foundation, Inc.
Copyright (C) 1996-2015 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -45,6 +45,7 @@
#import <AppKit/NSGraphics.h>
#import <AppKit/NSActionCell.h>
#import <AppKit/NSAnimationContext.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSAttributedString.h>
#import <AppKit/NSBitmapImageRep.h>

View file

@ -3,7 +3,7 @@
The one and only application class
Copyright (C) 1996,1999 Free Software Foundation, Inc.
Copyright (C) 1996-2105 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -149,6 +149,27 @@ enum _NSApplicationPrintReply
typedef NSUInteger NSApplicationPrintReply;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
typedef enum _NSApplicationPresentationOptions
{
NSApplicationPresentationDefault = 0,
NSApplicationPresentationAutoHideDock = (1 << 0),
NSApplicationPresentationHideDock = (1 << 1),
NSApplicationPresentationAutoHideMenuBar = (1 << 2),
NSApplicationPresentationHideMenuBar = (1 << 3),
NSApplicationPresentationDisableAppleMenu = (1 << 4),
NSApplicationPresentationDisableProcessSwitching = (1 << 5),
NSApplicationPresentationDisableForceQuit = (1 << 6),
NSApplicationPresentationDisableSessionTermination = (1 << 7),
NSApplicationPresentationDisableHideApplication = (1 << 8),
NSApplicationPresentationDisableMenuBarTransparency = (1 << 9),
NSApplicationPresentationFullScreen = (1 << 10),
NSApplicationPresentationAutoHideToolbar = (1 << 11)
} NSApplicationPresentationOptions;
#endif
APPKIT_EXPORT NSString *NSModalPanelRunLoopMode;
APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode;
@ -177,6 +198,7 @@ APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode;
NSWindow *_hidden_key;
NSWindow *_hidden_main;
GSInfoPanel *_infoPanel;
NSApplicationPresentationOptions _presentationOptions;
/* This autorelease pool should only be created and used by -run, with
a single exception (which is why it is stored here as an ivar): the
@ -398,6 +420,12 @@ APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode;
- (NSInteger) requestUserAttention: (NSRequestUserAttentionType)requestType;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (NSApplicationPresentationOptions) currentPresentationOptions;
- (NSApplicationPresentationOptions) presentationOptions;
- (void)setPresentationOptions: (NSApplicationPresentationOptions)options;
#endif
@end
/**

View file

@ -3,7 +3,7 @@
Load, manipulate and display images
Copyright (C) 1996, 2005 Free Software Foundation, Inc.
Copyright (C) 1996-2016 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@colorado.edu>
Date: Feb 1996
@ -45,6 +45,13 @@
@class NSColor;
@class NSView;
/* Named images */
APPKIT_EXPORT NSString *NSImageNameMultipleDocuments;
APPKIT_EXPORT NSString *NSImageNameTrashEmpty;
APPKIT_EXPORT NSString *NSImageNameTrashFull;
APPKIT_EXPORT NSString *NSImageNameColorPanel;
/** Defines how an NSImage is to be cached. Possible values are:
* <list>
* <item>NSImageCacheDefault</item>
@ -403,6 +410,16 @@ APPKIT_EXTERN NSString *const NSImageNameFolder;
#endif
/**
* <p>Draws the entire image in <code>rect</code> scaling if needed.<br>
* Drawing is done using <code>NSCompositeSourceOver</code>.
* </p>
*/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (void) drawInRect: (NSRect)rect;
#endif
//
// Determining How the Image is Drawn
//

View file

@ -75,15 +75,18 @@
@interface NSTableView (Private)
- (float *)_columnOrigins;
- (void) _willDisplayCell: (NSCell*)cell forTableColumn: (NSTableColumn *)tb row: (int)index;
// TESTPLANT-MAL-2016: Keeping for tableview grouped row support AKA Cocoa...
- (NSCell *) _dataCellForTableColumn: (NSTableColumn *)tb row: (int) rowIndex;
- (BOOL)_isGroupRow: (NSInteger)rowIndex;
@end
// TESTPLANT-MAL-2016: Keeping for tableview grouped row support AKA Cocoa...
@interface NSTableView (PrivateAccess)
- (NSIndexSet*)_selectedRowIndexes;
- (NSIndexSet*)_selectedColumnIndexes;
@end
// TESTPLANT-MAL-2016: Keeping for tableview grouped row support AKA Cocoa...
@implementation NSTableView (PrivateAccess)
- (NSIndexSet *)_selectedRowIndexes
{
@ -98,6 +101,11 @@
@interface NSCell (Private)
- (void) _setInEditing: (BOOL)flag;
- (BOOL) _inEditing;
- (void) _drawEditorWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView;
- (void) _drawAttributedText: (NSAttributedString*)aString
inFrame: (NSRect)aRect;
@end
@implementation GSTheme (Drawing)
@ -271,6 +279,7 @@
tiles = [self tilesNamed: @"NSButton" state: state];
}
// TESTPLANT-MAL-2016: KEEPING ALL Testplant changes here...
if (tiles == nil)
{
switch (style)
@ -381,7 +390,8 @@
}
else
{
[self fillRect: frame withTiles: tiles];
[self fillRect: frame
withTiles: tiles];
}
}
@ -524,7 +534,8 @@
}
else
{
NSInterfaceStyle interfaceStyle = NSInterfaceStyleForKey(@"NSScrollerInterfaceStyle", aScroller);
NSInterfaceStyle interfaceStyle =
NSInterfaceStyleForKey(@"NSScrollerInterfaceStyle", aScroller);
if ((interfaceStyle == NSNextStepInterfaceStyle
|| interfaceStyle == NSMacintoshInterfaceStyle
@ -1503,7 +1514,8 @@ static NSImage *spinningImages[MaxCount];
}
else
{
[self fillRect: bounds withTiles: tiles];
[self fillRect: bounds
withTiles: tiles];
return [tiles contentRectForRect: bounds
isFlipped: [[NSView focusView] isFlipped]];
@ -1534,7 +1546,8 @@ static NSImage *spinningImages[MaxCount];
{
NSColor *color;
color = [self colorNamed: @"tableHeaderTextColor" state: state];
color = [self colorNamed: @"tableHeaderTextColor"
state: state];
if (color == nil)
{
if (state == GSThemeHighlightedState)
@ -1621,6 +1634,10 @@ static NSImage *spinningImages[MaxCount];
/* These include the black border. */
#define TITLE_HEIGHT 23.0
#define RESIZE_HEIGHT 9.0
#define TITLEBAR_BUTTON_SIZE 15.0
#define TITLEBAR_PADDING_TOP 4.0
#define TITLEBAR_PADDING_RIGHT 4.0
#define TITLEBAR_PADDING_LEFT 4.0
- (float) titlebarHeight
{
@ -1632,6 +1649,26 @@ static NSImage *spinningImages[MaxCount];
return RESIZE_HEIGHT;
}
- (float) titlebarButtonSize
{
return TITLEBAR_BUTTON_SIZE;
}
- (float) titlebarPaddingRight
{
return TITLEBAR_PADDING_RIGHT;
}
- (float) titlebarPaddingTop
{
return TITLEBAR_PADDING_TOP;
}
- (float) titlebarPaddingLeft
{
return TITLEBAR_PADDING_LEFT;
}
static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
- (void) drawTitleBarRect: (NSRect)titleBarRect
@ -2572,7 +2609,8 @@ typedef enum {
{
NSPoint p1,p2;
int i, visibleColumns;
float hScrollerWidth = [browser hasHorizontalScroller] ? [NSScroller scrollerWidth] : 0;
float hScrollerWidth = [browser hasHorizontalScroller] ?
[NSScroller scrollerWidth] : 0;
// Columns borders
[self drawGrayBezel: bounds withClip: rect];
@ -2605,7 +2643,8 @@ typedef enum {
NSRect colFrame = [browser frameOfColumn: [browser firstVisibleColumn]];
NSRect scrollViewRect = NSUnionRect(baseRect, colFrame);
GSDrawTiles *tiles = [self tilesNamed: @"NSScrollView" state: GSThemeNormalState];
GSDrawTiles *tiles = [self tilesNamed: @"NSScrollView"
state: GSThemeNormalState];
[self fillRect: scrollViewRect
withTiles: tiles];
@ -3059,6 +3098,7 @@ typedef enum {
}
}
// Draw vertical lines
if (numberOfColumns > 0)
{
NSInteger i;
@ -3492,7 +3532,8 @@ typedef enum {
}
[[GSTheme theme] fillRect: [box borderRect] withTiles: tiles];
[[GSTheme theme] fillRect: [box borderRect]
withTiles: tiles];
// Restore clipping path
[NSGraphicsContext restoreGraphicsState];

View file

@ -409,16 +409,16 @@
- (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
{
NSBezierPath *p = [NSBezierPath bezierPath];
NSBezierPath *p;
NSPoint point;
CGFloat radius;
// make smaller than enclosing frame
cellFrame = NSInsetRect(cellFrame, 4, floor(cellFrame.size.height * 0.1875));
cellFrame = NSInsetRect(cellFrame, 4, 4);
radius = cellFrame.size.height / 2.0;
point = cellFrame.origin;
point.x += radius;
point.y += radius;
point.y += radius - 0.5;
// Draw initial path to enclose the button...
// left half-circle
@ -446,13 +446,13 @@
// Add highlights...
point = cellFrame.origin;
point.x += radius;
point.y += radius;
point.x += radius - 0.5;
point.y += radius - 0.5;
p = [NSBezierPath bezierPath];
[p setLineWidth: 2.0];
[p setLineWidth: 1.0];
[p appendBezierPathWithArcWithCenter: point
radius: radius
startAngle: 120.0
startAngle: 135.0
endAngle: 270.0];
// line to first point and right halfcircle
@ -460,7 +460,7 @@
[p appendBezierPathWithArcWithCenter: point
radius: radius
startAngle: 270.0
endAngle: 270.0];
endAngle: 315.0];
[[NSColor controlLightHighlightColor] set];
[p stroke];
}

View file

@ -268,6 +268,26 @@ static Class controlClass;
}
}
- (void) setAttributedStringValue: (NSAttributedString*)attribStr
{
[super setAttributedStringValue: attribStr];
if (_control_view)
{
if ([_control_view isKindOfClass: controlClass])
{
if (_cell.in_editing)
{
[self _updateFieldEditor:
[(NSControl *)_control_view currentEditor]];
}
else
{
[(NSControl *)_control_view updateCell: self];
}
}
}
}
/*
* Target and Action
*/

View file

@ -2,7 +2,7 @@
<abstract>The one and only application class.</abstract>
Copyright (C) 1996,1999 Free Software Foundation, Inc.
Copyright (C) 1996-2015 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -2022,6 +2022,9 @@ See -runModalForWindow:
[sheet setParentWindow: docWindow];
[docWindow setAttachedSheet: sheet];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSWindowWillBeginSheetNotification
object: docWindow];
ret = [self runModalForWindow: sheet
relativeToWindow: docWindow];
@ -2036,6 +2039,9 @@ See -runModalForWindow:
[docWindow setAttachedSheet: nil];
[sheet setParentWindow: nil];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSWindowDidEndSheetNotification
object: docWindow];
}
/**
@ -3697,6 +3703,25 @@ struct _DelegateWrapper
return 0;
}
- (NSApplicationPresentationOptions) currentPresentationOptions
{
return _presentationOptions;
}
- (NSApplicationPresentationOptions) presentationOptions
{
return _presentationOptions;
}
/**
* Currently unimplemented and unused in GNUstep, it could be extended to handle
* special GNUstep needs too
*/
- (void)setPresentationOptions: (NSApplicationPresentationOptions)options
{
_presentationOptions = options;
}
/*
* NSCoding protocol
*/
@ -3815,6 +3840,7 @@ struct _DelegateWrapper
// TESTPLANT-MAL-2016: Keeping local version...
{
NSRect iconContentRect = GSGetIconFrame(_app_icon_window);
NSRect iconFrame = [_app_icon_window frameRectForContentRect: iconContentRect];

View file

@ -2,7 +2,7 @@
<abstract>Load, manipulate and display images</abstract>
Copyright (C) 1996, 2005 Free Software Foundation, Inc.
Copyright (C) 1996-2016 Free Software Foundation, Inc.
Author: Adam Fedor <fedor@colorado.edu>
Date: Feb 1996
@ -58,6 +58,8 @@
BOOL NSImageForceCaching = NO; /* use on missmatch */
static NSDictionary *nsmapping = nil;
// OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
NSString *const NSImageNameQuickLookTemplate = @"NSQuickLookTemplate";
NSString *const NSImageNameBluetooth = @"NSBluetoothTemplate";
@ -93,36 +95,256 @@ NSString *const NSImageNameFolderBurnable = @"NSFolderBurnable";
NSString *const NSImageNameFolderSmart = @"NSFolderSmart";
NSString *const NSImageNameNetwork = @"NSNetwork";
// OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
NSString *const NSImageNameFolder = @"NSFolder";
@interface NSView (Private)
- (void) _lockFocusInContext: (NSGraphicsContext *)ctxt inRect: (NSRect)rect;
@end
@implementation NSBundle (NSImageAdditions)
- (NSString*) pathForImageResource: (NSString*)name
static NSArray*
imageTypes()
{
NSString *ext = [name pathExtension];
NSString *path = nil;
NSArray *types;
if ((ext == nil) || [ext isEqualToString:@""])
/* If the extension is one of the image types,
* remove it from the name and place it in the
* type argument.
*/
types = [[[GSTheme theme] imageClass] imageUnfilteredFileTypes];
if (nil == types)
{
NSArray *types = [NSImage imageUnfilteredFileTypes];
NSUInteger c = [types count];
NSUInteger i;
types = [NSImage imageUnfilteredFileTypes];
}
return types;
}
for (i = 0; path == nil && i < c; i++)
static void
fixupImageNameAndType(NSString **name, NSString **type)
{
NSString *ext = [*name pathExtension];
if ([ext length] > 0)
{
/* If the extension is one of the image types,
* remove it from the name and place it in the
* type argument.
*/
if ([imageTypes() indexOfObject: ext] != NSNotFound)
{
ext = [types objectAtIndex: i];
path = [self pathForResource: name ofType: ext];
*type = ext;
*name = [*name stringByDeletingPathExtension];
}
}
else
}
- (NSString *) _pathForImageNamed: (NSString *)aName
ofType: (NSString *)ext
subdirectory: (NSString *)aDir
inBundle: (NSBundle *)aBundle
{
NSEnumerator *e;
id o;
if (ext != nil)
{
name = [name stringByDeletingPathExtension];
path = [self pathForResource: name ofType: ext];
return [aBundle pathForResource: aName ofType: ext inDirectory: aDir];
}
e = [imageTypes() objectEnumerator];
while ((o = [e nextObject]) != nil)
{
NSString *path;
path = [aBundle pathForResource: aName ofType: o inDirectory: aDir];
if ([path length] > 0)
{
return path;
}
}
return nil;
}
- (NSString *) _pathForLibraryImageNamed: (NSString *)aName
ofType: (NSString *)ext
inDirectory: (NSString *)aDir
{
NSEnumerator *e;
id o;
if (ext != nil)
{
return [NSBundle pathForLibraryResource: aName
ofType: ext
inDirectory: aDir];
}
e = [imageTypes() objectEnumerator];
while ((o = [e nextObject]) != nil)
{
NSString *path;
path = [NSBundle pathForLibraryResource: aName
ofType: o
inDirectory: aDir];
if ([path length] > 0)
{
return path;
}
}
return nil;
}
- (NSString *) _pathForSystemImageNamed: (NSString *)realName
ofType: (NSString *)ext
{
NSString *path;
path = [self _pathForLibraryImageNamed: realName
ofType: ext
inDirectory: @"Images"];
/* If not found then search in system using the reverse NSImage nsmapping */
if (nil == path)
{
NSEnumerator *e;
NSString *aliasName;
e = [[nsmapping allKeysForObject: realName] objectEnumerator];
while ((aliasName = [e nextObject]) != nil)
{
path = [self _pathForLibraryImageNamed: aliasName
ofType: ext
inDirectory: @"Images"];
if (path != nil)
{
break;
}
}
}
return path;
}
/*
* nsmapping.strings maps alternative image naming schemes to the GSTheme
* standard image naming scheme. For example, NSSwitch (from OpenStep) and
* common_SwitchOff (from GNUstep) are mapped to GSSwitch. In nameDict that
* tracks image instances, the keys are image names from GSTheme such as
* GSSwitch or additional icon names such NSApplicationIcon or
* NSToolbarShowColors. In the long run, it would be cleaner to move built-in
* theme images into a GNUstep.theme bundle.
*
* If you pass NSSwitch to +imageNamed:, nsmapping is used to get GSSwitch as
* the real name, then _pathForImageNamed: will look up the image first in the
* theme and fall back on the Library images. For the library images, we do a
* reverse lookup in nsmapping (using allKeysForObject:) to get the image file
* name (e.g. from GSSwitch to common_SwitchOff). This reverse lookup is
* similar to the one supported for getting image file names from the
* bundle, this reverse lookup could be handled by GSTheme rather than being
*
* The type received in argument is meaningfull for searching image files
* using the proposed image name, but useless otherwise.
*/
- (NSString *) _pathForThemeImageNamed: (NSString *)name
ofType: (NSString *)ext
{
GSTheme *theme;
NSDictionary *themeMapping;
NSString *mappedName;
NSString *path = nil;
theme = [GSTheme theme];
themeMapping = [[theme infoDictionary] objectForKey: @"GSThemeImages"];
mappedName = [themeMapping objectForKey: name];
/* First search among the theme images using the GSTheme mapping */
if (mappedName != nil)
{
NSString *extension = nil;
NSString *proposedName = mappedName;
fixupImageNameAndType(&proposedName, &extension);
/* If the image file name from the theme mapping uses an extension,
* this extension is used to look up the path. If the image file
* cannot be found, _pathForImageNamed:ofType:subdirectory:inBundle:
* searches an image file for the file extensions from -imageFileTypes.
*/
path = [self _pathForImageNamed: proposedName
ofType: extension
subdirectory: @"ThemeImages"
inBundle: [theme bundle]];
}
/* If not found, search among the theme images using the reverse NSImage
* mapping (for GNUstep and OpenStep image names such as common_SwitchOff
* or NSSwitch)
*/
if (nil == path)
{
NSEnumerator *e;
NSString *aliasName;
e = [[nsmapping allKeysForObject: name] objectEnumerator];
while (nil == path && (aliasName = [e nextObject]) != nil)
{
NSAssert([[aliasName pathExtension] length] == 0,
@"nsmapping.strings "
"must include no extensions in image file names");
path = [self _pathForImageNamed: aliasName
ofType: nil
subdirectory: @"ThemeImages"
inBundle: [theme bundle]];
}
}
/* If not found, search among the theme images using the image name directly
*/
if (path == nil)
{
path = [self _pathForImageNamed: name
ofType: ext
subdirectory: @"ThemeImages"
inBundle: [theme bundle]];
}
return path;
}
- (NSString*) pathForImageResource: (NSString*)name
{
NSString *ext = nil;
NSString *path = nil;
NSString *ident;
fixupImageNameAndType(&name, &ext);
if (nil != (ident = [self bundleIdentifier]))
{
NSString *subdir;
subdir = [@"ThemeImages" stringByAppendingPathComponent: ident];
path = [self _pathForImageNamed: name
ofType: ext
subdirectory: subdir
inBundle: [[GSTheme theme] bundle]];
}
if (nil == path)
{
path = [self _pathForImageNamed: name
ofType: ext
subdirectory: nil
inBundle: self];
if (nil == path)
{
path = [self _pathForThemeImageNamed: name ofType: ext];
if (nil == path)
{
path = [self _pathForSystemImageNamed: name ofType: ext];
}
}
}
return path;
}
@ -161,7 +383,6 @@ NSString *const NSImageNameFolder = @"NSFolder";
/* Class variables and functions for class methods */
static NSRecursiveLock *imageLock = nil;
static NSMutableDictionary *nameDict = nil;
static NSDictionary *nsmapping = nil;
static NSColor *clearColor = nil;
static Class cachedClass = 0;
static Class bitmapClass = 0;
@ -196,7 +417,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
@interface NSImage (Private)
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
+ (NSString *) _pathForImageNamed: (NSString *)aName;
+ (void) _reloadCachedImages;
- (BOOL) _useFromFile: (NSString *)fileName;
- (BOOL) _loadFromData: (NSData *)data;
@ -256,7 +476,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
if (image == nil && realName != nil)
{
NSString *path = [self _pathForImageNamed: realName];
NSString *path = [[NSBundle mainBundle] pathForImageResource: realName];
if ([path length] != 0)
{
@ -435,9 +655,9 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
NSArray *array = [pasteboard propertyListForType: NSFilenamesPboardType];
NSString* file;
if ((array == nil) || ([array count] == 0) ||
(file = [array objectAtIndex: 0]) == nil ||
![self _loadFromFile: file])
if ((array == nil) || ([array count] == 0)
|| (file = [array objectAtIndex: 0]) == nil
|| ![self _loadFromFile: file])
{
RELEASE(self);
return nil;
@ -883,6 +1103,14 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
hints: nil];
}
- (void) drawInRect: (NSRect)rect
{
[self drawInRect: rect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
}
- (void) drawInRect: (NSRect)dstRect
fromRect: (NSRect)srcRect
operation: (NSCompositingOperation)op
@ -1248,12 +1476,16 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
const NSSize repRes = GSResolutionOfImageRep(rep);
if (GSSizeIsIntegerMultipleOfSize(repRes, dres))
{
const NSSize repResDifference = NSMakeSize(fabs(repRes.width - dres.width),
const NSSize repResDifference
= NSMakeSize(fabs(repRes.width - dres.width),
fabs(repRes.height - dres.height));
const NSSize closestResolutionDifference = NSMakeSize(fabs(closestRes.width - dres.width),
const NSSize closestResolutionDifference
= NSMakeSize(fabs(closestRes.width - dres.width),
fabs(closestRes.height - dres.height));
if (repResDifference.width < closestResolutionDifference.width &&
repResDifference.height < closestResolutionDifference.height)
if (repResDifference.width
< closestResolutionDifference.width
&& repResDifference.height
< closestResolutionDifference.height)
{
closestRes = repRes;
}
@ -1516,10 +1748,10 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
while ((rep = [enumerator nextObject]) != nil)
{
const NSSize repSize = [rep size];
if ((repSize.width >= desiredSize.width) &&
(repSize.height >= desiredSize.height) &&
(repSize.width < bestSize.width) &&
(repSize.height < bestSize.height))
if ((repSize.width >= desiredSize.width)
&& (repSize.height >= desiredSize.height)
&& (repSize.width < bestSize.width)
&& (repSize.height < bestSize.height))
{
bestSize = repSize;
bestRep = rep;
@ -1553,10 +1785,14 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
// Producing TIFF Data for the Image
- (NSData *) TIFFRepresentation
{
NSArray *reps;
NSData *data;
// As a result of using bitmap representations, new drawing wont show on the tiff data.
data = [bitmapClass TIFFRepresentationOfImageRepsInArray: [self representations]];
/* As a result of using bitmap representations,
* new drawing wont show on the tiff data.
*/
reps = [self _representationsWithCachedImages: NO];
data = [bitmapClass TIFFRepresentationOfImageRepsInArray: reps];
if (!data)
{
@ -1582,10 +1818,14 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
- (NSData *) TIFFRepresentationUsingCompression: (NSTIFFCompression)comp
factor: (float)aFloat
{
NSArray *reps;
NSData *data;
// As a result of using bitmap representations, new drawing wont show on the tiff data.
data = [bitmapClass TIFFRepresentationOfImageRepsInArray: [self representations]
/* As a result of using bitmap representations,
* new drawing wont show on the tiff data.
*/
reps = [self _representationsWithCachedImages: NO];
data = [bitmapClass TIFFRepresentationOfImageRepsInArray: reps
usingCompression: comp
factor: aFloat];
@ -1594,7 +1834,9 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
NSBitmapImageRep *rep;
NSSize size = [self size];
// If there isn't a bitmap representation to output, create one and store it.
/* If there isn't a bitmap representation to output,
* create one and store it.
*/
[self lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSMakeRect(0.0, 0.0, size.width, size.height)];
@ -1732,7 +1974,8 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
if ([coder containsValueForKey: @"NSName"])
{
RELEASE(self);
return RETAIN([NSImage imageNamed: [coder decodeObjectForKey: @"NSName"]]);
return RETAIN([NSImage imageNamed:
[coder decodeObjectForKey: @"NSName"]]);
}
if ([coder containsValueForKey: @"NSColor"])
{
@ -1756,8 +1999,10 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
NSArray *reps;
NSUInteger i;
// FIXME: NSReps is in a strange format. It is a mutable array with one
// element which is an array with a first element 0 and than the image rep.
/* FIXME: NSReps is in a strange format. It is a mutable array
* with one element which is an array with a first element 0
* and than the image rep.
*/
reps = [coder decodeObjectForKey: @"NSReps"];
reps = [reps objectAtIndex: 0];
for (i = 1; i < [reps count]; i++)
@ -1774,8 +2019,9 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
NSURL *tmp = (NSURL*)rep;
rep = [NSImageRep imageRepWithContentsOfURL: rep];
// If we are unable to resolved the URL, try to get it from the
// resources folder.
/* If we are unable to resolved the URL,
* try to get it from the resources folder.
*/
if (rep == nil)
{
NSString *fileName = [[tmp absoluteString] lastPathComponent];
@ -1984,7 +2230,7 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
while ((name = [e nextObject]) != nil)
{
NSImage *image = [nameDict objectForKey: name];
NSString *path = [self _pathForImageNamed: name];
NSString *path = [[NSBundle mainBundle] pathForImageResource: name];
//NSLog(@"Loaded image %@ from %@", name, path);
@ -1999,60 +2245,6 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
[imageLock unlock];
}
+ (NSString *) _pathForLibraryImageNamed: (NSString *)aName
ofType: (NSString *)ext
inDirectory: (NSString *)aDir
{
if (ext != nil)
{
return [NSBundle pathForLibraryResource: aName
ofType: ext
inDirectory: aDir];
}
NSEnumerator *e = [[self imageFileTypes] objectEnumerator];
id o = nil;
while ((o = [e nextObject]) != nil)
{
NSString *path = [NSBundle pathForLibraryResource: aName
ofType: o
inDirectory: aDir];
if (path != nil && [path length] != 0)
return path;
}
return nil;
}
+ (NSString *) _pathForSystemImageNamed: (NSString *)realName
ofType: (NSString *)ext
{
NSString *path = [self _pathForLibraryImageNamed: realName
ofType: ext
inDirectory: @"Images"];
/* If not found then search in system using the reverse NSImage nsmapping */
if (path == nil)
{
NSEnumerator *e =
[[nsmapping allKeysForObject: realName] objectEnumerator];
NSString *aliasName = nil;
while ((aliasName = [e nextObject]) != nil)
{
path = [self _pathForLibraryImageNamed: aliasName
ofType: ext
inDirectory: @"Images"];
if (path != nil)
break;
}
}
return path;
}
+ (NSString *) _resourceNameForImageNamed: (NSString *)aName
type: (NSString **)aType
@ -2081,148 +2273,6 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
return name;
}
+ (NSString *) _pathForImageNamed: (NSString *)aName
ofType: (NSString *)ext
subdirectory: (NSString *)aDir
inBundle: (NSBundle *)aBundle
{
if (ext != nil)
{
return [aBundle pathForResource: aName
ofType: ext
inDirectory: aDir];
}
NSEnumerator *e = [[self imageFileTypes] objectEnumerator];
id o = nil;
while ((o = [e nextObject]) != nil)
{
NSString * path = [aBundle pathForResource: aName
ofType: o
inDirectory: aDir];
if (path != nil && [path length] != 0)
return path;
}
return nil;
}
/*
* The type received in argument is meaningfull for searching image files
* using the proposed image name, but useless otherwise.
*/
+ (NSString *) _pathForThemeImageNamed: (NSString *)aName
ofType: (NSString *)ext
{
NSDictionary *themeMapping =
[[[GSTheme theme] infoDictionary] objectForKey: @"GSThemeImages"];
NSString *mappedName = [themeMapping objectForKey: aName];
NSString *path = nil;
/* First search among the theme images using the GSTheme mapping */
if (mappedName != nil)
{
NSString *extension = nil;
NSString *proposedName = [self _resourceNameForImageNamed: mappedName
type: &extension];
/* If the image file name from the theme mapping uses an extension, this
extension is used to look up the path. If the image file cannot found,
_pathForImageNamed:ofType:subdirectory:inBundle: searches an image
file for the file extensions from -imageFileTypes. */
path = [self _pathForImageNamed: proposedName
ofType: extension
subdirectory: @"ThemeImages"
inBundle: [[GSTheme theme] bundle]];
}
/* If not found, search among the theme images using the reverse NSImage
mapping (for GNUstep and OpenStep image names such as common_SwitchOff
or NSSwitch) */
if (path == nil)
{
NSEnumerator *e =
[[nsmapping allKeysForObject: aName] objectEnumerator];
NSString *aliasName = nil;
while ((aliasName = [e nextObject]) != nil)
{
NSAssert([[aliasName pathExtension] length] == 0, @"nsmapping.strings "
"must include no extensions in image file names");
path = [self _pathForImageNamed: aliasName
ofType: nil
subdirectory: @"ThemeImages"
inBundle: [[GSTheme theme] bundle]];
if (path != nil)
break;
}
}
/* If not found, search among the theme images using the image name directly */
if (path == nil)
{
path = [self _pathForImageNamed: aName
ofType: ext
subdirectory: @"ThemeImages"
inBundle: [[GSTheme theme] bundle]];
}
return path;
}
/*
* nsmapping.strings maps alternative image naming schemes to the GSTheme
* standard image naming scheme. For example, NSSwitch (from OpenStep) and
* common_SwitchOff (from GNUstep) are mapped to GSSwitch. In nameDict that
* tracks image instances, the keys are image names from GSTheme such as
* GSSwitch or additional icon names such NSApplicationIcon or
* NSToolbarShowColors. In the long run, it would be cleaner to move built-in
* theme images into a GNUstep.theme bundle.
*
* If you pass NSSwitch to +imageNamed:, nsmapping is used to get GSSwitch as
* the real name, then _pathForImageNamed: will look up the image first in the
* theme and fall back on the Library images. For the library images, we do a
* reverse lookup in nsmapping (using allKeysForObject:) to get the image file
* name (e.g. from GSSwitch to common_SwitchOff). This reverse lookup is
* similar to the one supported for getting image file names from the
* GSThemeImages section of a theme Info.plist. By creating a GNUstep.theme
* bundle, this reverse lookup could be handled by GSTheme rather than being
* treated as a special case in -_pathForImageNamed:.
*/
+ (NSString *) _pathForImageNamed: (NSString *)aName
{
NSString *ext = nil;
NSString *proposedName = [self _resourceNameForImageNamed: aName type: &ext];
NSString *path = nil;
// FIXME: This should use [NSBundle pathForImageResource] if possible, but
// this will only allow imageUnfilteredFileTypes.
/* First search locally */
path = [self _pathForImageNamed: proposedName
ofType: ext
subdirectory: nil
inBundle: [NSBundle mainBundle]];
/* If not found then search in theme */
if (path == nil)
{
path = [self _pathForThemeImageNamed: proposedName ofType: ext];
}
/* If not found then search in system */
if (path == nil)
{
path = [self _pathForSystemImageNamed: proposedName ofType: ext];
}
return path;
}
- (BOOL)_loadFromData: (NSData *)data
{
BOOL ok;
@ -2438,9 +2488,11 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
if (pixelsWide == NSImageRepMatchesDevice ||
pixelsHigh == NSImageRepMatchesDevice)
{
// FIXME: Since the cached rep must be a bitmap,
// we must rasterize vector reps at a particular DPI.
// Here we hardcode 72, but we should choose the DPI more intelligently.
/* FIXME: Since the cached rep must be a bitmap,
* we must rasterize vector reps at a particular DPI.
* Here we hardcode 72, but we should choose the DPI
* more intelligently.
*/
pixelsWide = repSize.width;
pixelsHigh = repSize.height;
}
@ -2448,7 +2500,9 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
else // e.g. when there are no representations at all
{
repSize = imageSize;
// FIXME: assumes 72 DPI. Also truncates, not sure if that is a problem.
/* FIXME: assumes 72 DPI. Also truncates,
* not sure if that is a problem.
*/
pixelsWide = imageSize.width;
pixelsHigh = imageSize.height;
}
@ -2458,7 +2512,8 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
return nil;
// Create a new cached image rep without any contents.
cacheRep = [[cachedClass alloc] initWithSize: repSize
cacheRep = [[cachedClass alloc]
initWithSize: repSize
pixelsWide: pixelsWide
pixelsHigh: pixelsHigh
depth: [[NSScreen mainScreen] depth]