Revision: 25398 http://sourceforge.net/p/bibdesk/svn/25398 Author: hofman Date: 2021-01-14 14:55:26 +0000 (Thu, 14 Jan 2021) Log Message: ----------- Move lock badge class to separate files
Modified Paths: -------------- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj Added Paths: ----------- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.h trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m Added: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.h =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.h (rev 0) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.h 2021-01-14 14:55:26 UTC (rev 25398) @@ -0,0 +1,47 @@ +// +// FVLockBadge.h +// FileView +// +// Created by Christiaan Hofman on 01/14/21. +/* + This software is Copyright (c) 2021 + Christiaa Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + + +@interface FVLockBadge : NSObject + +// returns a cached layer for overlay on an icon ++ (CGLayerRef)lockBadgeWithSize:(NSSize)size; + +@end Added: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m (rev 0) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m 2021-01-14 14:55:26 UTC (rev 25398) @@ -0,0 +1,99 @@ +// +// FVLockBadge.m +// FileView +// +// Created by Christiaan Hofman on 01/14/21. +/* + This software is Copyright (c) 2021 + Christiaan hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "FVLockBadge.h" +#import "FVUtilities.h" + +@implementation FVLockBadge + +static CFMutableDictionaryRef _badges = NULL; +static const NSUInteger _sizes[] = { 32, 64, 128, 256, 512 }; + ++ (void)initialize +{ + FVINITIALIZE(FVLockBadge); + + _badges = CFDictionaryCreateMutable(NULL, 0, &FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks); + NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger); + + // kLockedBadgeIcon looks much better than kLockedIcon, which gets jagged quickly + NSImage *lockBadge = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)]; + + for (i = 0; i < iMax; i++) { + + CGRect dstRect = CGRectMake(0, 0, _sizes[i], _sizes[i]); + + NSGraphicsContext *windowContext = FVWindowGraphicsContextWithSize(NSRectFromCGRect(dstRect).size); + NSParameterAssert(nil != windowContext); + + CGLayerRef layer = CGLayerCreateWithContext([windowContext graphicsPort], dstRect.size, NULL); + CGContextRef context = CGLayerGetContext(layer); + + // don't use CGContextClearRect with non-window/bitmap contexts + CGContextSetRGBFillColor(context, 0, 0, 0, 0); + CGContextFillRect(context, dstRect); + + // rect needs to be a square, or else the aspect ratio of the arrow is wrong + // rect needs to be the same size as the full icon, or the scale of the arrow is wrong + + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]]; + + // We don't know the size of the actual link arrow (and it changes with the size of dstRect), so fine-tuning the drawing isn't really possible as far as I can see. + [lockBadge drawInRect:NSRectFromCGRect(dstRect)]; + + [NSGraphicsContext restoreGraphicsState]; + + CFDictionarySetValue(_badges, (void *)_sizes[i], layer); + CGLayerRelease(layer); + } +} + ++ (CGLayerRef)lockBadgeWithSize:(NSSize)size; +{ + NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger); + for (i = 0; i < iMax; i++) { + + NSUInteger height = _sizes[i]; + if (height > size.height) + return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)height); + } + return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)_sizes[iMax - 1]); +} + +@end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-14 10:26:24 UTC (rev 25397) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m 2021-01-14 14:55:26 UTC (rev 25398) @@ -38,6 +38,7 @@ #import "FVPDFIcon.h" #import <pthread.h> +#import "FVLockBadge.h" #import "_FVMappedDataProvider.h" #import "_FVSplitSet.h" @@ -47,13 +48,6 @@ static _FVSplitSet *_releaseableIcons = nil; static CGLayerRef _pageLayer = NULL; -@interface FVLockBadge : NSObject - -// returns a cached layer for overlay on an icon -+ (CGLayerRef)lockBadgeWithSize:(NSSize)size; - -@end - @implementation FVPDFIcon + (void)initialize @@ -714,63 +708,3 @@ @end - -@implementation FVLockBadge - -static CFMutableDictionaryRef _badges = NULL; -static const NSUInteger _sizes[] = { 32, 64, 128, 256, 512 }; - -+ (void)initialize -{ - FVINITIALIZE(FVLockBadge); - - _badges = CFDictionaryCreateMutable(NULL, 0, &FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks); - NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger); - - // kLockedBadgeIcon looks much better than kLockedIcon, which gets jagged quickly - NSImage *lockBadge = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)]; - - for (i = 0; i < iMax; i++) { - - CGRect dstRect = CGRectMake(0, 0, _sizes[i], _sizes[i]); - - NSGraphicsContext *windowContext = FVWindowGraphicsContextWithSize(NSRectFromCGRect(dstRect).size); - NSParameterAssert(nil != windowContext); - - CGLayerRef layer = CGLayerCreateWithContext([windowContext graphicsPort], dstRect.size, NULL); - CGContextRef context = CGLayerGetContext(layer); - - // don't use CGContextClearRect with non-window/bitmap contexts - CGContextSetRGBFillColor(context, 0, 0, 0, 0); - CGContextFillRect(context, dstRect); - - // rect needs to be a square, or else the aspect ratio of the arrow is wrong - // rect needs to be the same size as the full icon, or the scale of the arrow is wrong - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]]; - - // We don't know the size of the actual link arrow (and it changes with the size of dstRect), so fine-tuning the drawing isn't really possible as far as I can see. - [lockBadge drawInRect:NSRectFromCGRect(dstRect)]; - - [NSGraphicsContext restoreGraphicsState]; - - CFDictionarySetValue(_badges, (void *)_sizes[i], layer); - CGLayerRelease(layer); - } -} - - -+ (CGLayerRef)lockBadgeWithSize:(NSSize)size; -{ - NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger); - for (i = 0; i < iMax; i++) { - - NSUInteger height = _sizes[i]; - if (height > size.height) - return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)height); - } - return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)_sizes[iMax - 1]); -} - -@end Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj =================================================================== --- trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj 2021-01-14 10:26:24 UTC (rev 25397) +++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj 2021-01-14 14:55:26 UTC (rev 25398) @@ -53,6 +53,8 @@ CE89233F0D7CBB1A006D514C /* FVOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CE05D5E90D7C22550034C2A8 /* FVOperation.m */; }; CEA831140DC1FAB500B551D1 /* FVAccessibilityIconElement.h in Headers */ = {isa = PBXBuildFile; fileRef = CEA831120DC1FAB500B551D1 /* FVAccessibilityIconElement.h */; }; CEA831150DC1FAB500B551D1 /* FVAccessibilityIconElement.m in Sources */ = {isa = PBXBuildFile; fileRef = CEA831130DC1FAB500B551D1 /* FVAccessibilityIconElement.m */; }; + CEC48F2325B090ED00A2B40A /* FVLockBadge.m in Sources */ = {isa = PBXBuildFile; fileRef = CEC48F2125B090ED00A2B40A /* FVLockBadge.m */; }; + CEC48F2425B090ED00A2B40A /* FVLockBadge.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC48F2225B090ED00A2B40A /* FVLockBadge.h */; }; CEC9932D1072B6C50089F20D /* FVPreviewer.xib in Resources */ = {isa = PBXBuildFile; fileRef = CEC9932C1072B6C50089F20D /* FVPreviewer.xib */; }; CEFC19B10F693E8B00B2AEE6 /* FileView.h in Headers */ = {isa = PBXBuildFile; fileRef = CEFC19B00F693E8B00B2AEE6 /* FileView.h */; settings = {ATTRIBUTES = (Public, ); }; }; CEFC1CF60F6AB84000B2AEE6 /* _FVDocumentDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = CEFC1CE90F6AB84000B2AEE6 /* _FVDocumentDescription.h */; }; @@ -207,6 +209,8 @@ CE65FC5B0F72578D0089F9DC /* _FVSplitSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _FVSplitSet.m; sourceTree = "<group>"; }; CEA831120DC1FAB500B551D1 /* FVAccessibilityIconElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FVAccessibilityIconElement.h; sourceTree = "<group>"; }; CEA831130DC1FAB500B551D1 /* FVAccessibilityIconElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FVAccessibilityIconElement.m; sourceTree = "<group>"; }; + CEC48F2125B090ED00A2B40A /* FVLockBadge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FVLockBadge.m; sourceTree = "<group>"; }; + CEC48F2225B090ED00A2B40A /* FVLockBadge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FVLockBadge.h; sourceTree = "<group>"; }; CEC9932C1072B6C50089F20D /* FVPreviewer.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FVPreviewer.xib; sourceTree = "<group>"; }; CEFC19B00F693E8B00B2AEE6 /* FileView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileView.h; sourceTree = "<group>"; }; CEFC1CE90F6AB84000B2AEE6 /* _FVDocumentDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _FVDocumentDescription.h; sourceTree = "<group>"; }; @@ -411,8 +415,8 @@ CE05D4840D7B37A80034C2A8 /* Icons */ = { isa = PBXGroup; children = ( + CEFC1D260F6ABA2300B2AEE6 /* FVAliasBadge.h */, CEFC1D250F6ABA2300B2AEE6 /* FVAliasBadge.m */, - CEFC1D260F6ABA2300B2AEE6 /* FVAliasBadge.h */, CEFC1D270F6ABA2300B2AEE6 /* FVBaseIcon.h */, CEFC1D280F6ABA2300B2AEE6 /* FVBaseIcon.m */, F9A2D3EA0CCBE13F002F517B /* FVFinderIcon.h */, @@ -423,6 +427,8 @@ CE05D4690D7B36DD0034C2A8 /* FVIcon_Private.m */, F9A2D3E60CCBE12B002F517B /* FVImageIcon.h */, F9A2D3E70CCBE12B002F517B /* FVImageIcon.m */, + CEC48F2225B090ED00A2B40A /* FVLockBadge.h */, + CEC48F2125B090ED00A2B40A /* FVLockBadge.m */, CE05D46A0D7B36DD0034C2A8 /* FVMIMEIcon.h */, CE05D46B0D7B36DD0034C2A8 /* FVMIMEIcon.m */, CE05D46C0D7B36DD0034C2A8 /* FVMovieIcon.h */, @@ -431,8 +437,8 @@ F9A2D3EF0CCBE14E002F517B /* FVPDFIcon.m */, CE05D46E0D7B36DD0034C2A8 /* FVPlaceholderImage.h */, CE05D46F0D7B36DD0034C2A8 /* FVPlaceholderImage.m */, + F9A2D4270CCBE6BA002F517B /* FVQuickLookIcon.h */, F946921C0CA5700800AC2772 /* FVQuickLookIcon.m */, - F9A2D4270CCBE6BA002F517B /* FVQuickLookIcon.h */, F9A2D3F20CCBE15C002F517B /* FVTextIcon.h */, F9A2D3F30CCBE15C002F517B /* FVTextIcon.m */, F92C7BAA0D280626004409D8 /* FVWebViewIcon.h */, @@ -642,6 +648,7 @@ CEFC1CFE0F6AB84000B2AEE6 /* FVCGColorSpaceDescription.h in Headers */, CEFC1D000F6AB84000B2AEE6 /* FVCGImageDescription.h in Headers */, CEFC1D090F6AB8AD00B2AEE6 /* FVBitmapContext.h in Headers */, + CEC48F2425B090ED00A2B40A /* FVLockBadge.h in Headers */, CEFC1D0B0F6AB8AD00B2AEE6 /* FVCGImageUtilities.h in Headers */, CEFC1D0D0F6AB8AD00B2AEE6 /* FVImageBuffer.h in Headers */, CEFC1D170F6AB94F00B2AEE6 /* FVObject.h in Headers */, @@ -815,6 +822,7 @@ CEFC1D290F6ABA2300B2AEE6 /* FVAliasBadge.m in Sources */, CEFC1D2C0F6ABA2300B2AEE6 /* FVBaseIcon.m in Sources */, CEFC1F6E0F6AD4B300B2AEE6 /* FVQuickLookIcon.m in Sources */, + CEC48F2325B090ED00A2B40A /* FVLockBadge.m in Sources */, CE65FC5D0F72578D0089F9DC /* _FVMappedDataProvider.m in Sources */, CE65FC5F0F72578D0089F9DC /* _FVSplitSet.m in Sources */, CE07BD4310E789FE00686ACC /* _FVFullScreenContentView.m in Sources */, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit