Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NS Scroll View Magnification #37

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bb0c134
Add missing methods and stubs for TextEdit
CKegel Apr 8, 2023
81d2422
add NSDocumentController type discovery
CKegel Apr 12, 2023
fd68ee2
Implement NSUserInterfaceItemIdentifcation protocol
CKegel Apr 21, 2023
5300f80
Fix handling of NSTextContainer and NSTextStorage in NSTextView.subproj
CKegel Apr 21, 2023
e086fe9
Add document format inference in NSAttributedString
CKegel Apr 21, 2023
2f6272f
Align `documentClassForType:` implementation with Apple's developer d…
CKegel Apr 21, 2023
7fcfc33
Implement `readFromURL:` in NSMutableAttributedString
CKegel Apr 21, 2023
a4bc3fe
Add framework for size and magnification methods
CKegel Apr 25, 2023
b3c2e2d
Implement NSParagraph TabStops properly
CKegel Apr 28, 2023
a72e581
Remove redundant declaration of `translatesAutoResizingMaskIntoConstr…
CKegel Oct 14, 2023
d6c5c1c
Convert hexadecimal color values to CGFloat literals.
CKegel Dec 5, 2023
bce2767
Correct leak in internal NSTextView method.
CKegel Feb 9, 2024
317e077
Align implementation of `documentClassForType:` with Apple's develope…
CKegel Feb 9, 2024
1507165
initial implementation of scaleUnitSquareToSize
jvmespark Feb 6, 2024
a1e509e
implemented boolean allowsMagnification
jvmespark Feb 9, 2024
44a6574
implemented cgfloat magnification
jvmespark Feb 9, 2024
1ab8aac
implemented CGFloats min/max magnification and set up method magnifyT…
jvmespark Feb 9, 2024
0ae4f4c
added exceptions to setting magnification, first implementation of se…
jvmespark Feb 13, 2024
c190383
Remove duplicate definition of magnification properties.
CKegel Feb 16, 2024
14cf4f5
fixed minor bugs
jvmespark Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 175 additions & 104 deletions AppKit/NSAttributedString.m

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions AppKit/NSDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ - (void) updateChangeCount: (NSDocumentChangeType) changeType {
case NSChangeAutosaved:
NSUnimplementedMethod();
break;

case NSChangeRedone:
_changeCount++; //Opposite of Undo - this may be wrong
break;
}

BOOL edited = [self isDocumentEdited];
Expand Down Expand Up @@ -467,6 +471,7 @@ - (BOOL) readFromURL: (NSURL *) url
if ([self _isSelectorOverridden: @selector(readFromFile:ofType:)]) {
return [self readFromFile: [url path] ofType: type];
} else {

NSFileWrapper *fileWrapper = [[[NSFileWrapper alloc]
initWithPath: [url path]] autorelease];

Expand Down Expand Up @@ -695,8 +700,8 @@ - (void) runModalSavePanelForSaveOperation: (NSSaveOperationType) operation

#if 0
// setAllowedFileTypes: is unimplemented - so don't call it.
NSArray* writableTypes = [self writableTypesForSaveOperation: operation];
[savePanel setAllowedFileTypes: writableTypes];
NSArray* writableTypes = [self writableTypesForSaveOperation: operation];
[savePanel setAllowedFileTypes: writableTypes];
#endif

if ([self prepareSavePanel: savePanel] == NO) {
Expand Down Expand Up @@ -1197,9 +1202,8 @@ - (NSFileWrapper *) fileWrapperRepresentationOfType: (NSString *) type {
return self;
}

- initWithContentsOfURL: (NSURL *) url ofType: (NSString *) type {
- (id) initWithContentsOfURL: (NSURL *) url ofType: (NSString *) type {
NSError *error;

[self init];

error = nil;
Expand All @@ -1223,6 +1227,7 @@ - (NSFileWrapper *) fileWrapperRepresentationOfType: (NSString *) type {
return self;
}


- (BOOL) loadDataRepresentation: (NSData *) data ofType: (NSString *) type {
[NSException raise: NSInternalInconsistencyException
format: @"-[%@ %s]", [self class], sel_getName(_cmd)];
Expand Down Expand Up @@ -1507,4 +1512,18 @@ - (void) performSynchronousFileAccessUsingBlock: (void (^)(void)) block {
block();
}

- (void) saveToURL: (NSURL *) url
ofType: (NSString *) typeName
forSaveOperation: (NSSaveOperationType) saveOperation
completionHandler: (void (^)(NSError *errorOrNil)) completionHandler
{
NSUnimplementedMethod();
}

- (void) autosaveWithImplicitCancellability: (BOOL) autosavingIsImplicitlyCancellable
completionHandler: (void (^)(NSError *errorOrNil)) completionHandler
{
NSUnimplementedMethod();
}

@end
88 changes: 74 additions & 14 deletions AppKit/NSDocumentController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,50 @@ this software and associated documentation files (the "Software"), to deal in

@interface _NSUnsupportedDocument : NSObject

- initWithType: (NSString *) type error: (NSError **) error;
- (instancetype) initWithType: (NSString *) type error: (NSError **) error;
- (instancetype) initWithContentsOfURL: (NSURL *) url
ofType: (NSString *) typeName
error: (NSError *_Nullable *) outError;
- (id) initWithContentsOfURL: (NSURL *) url ofType: (NSString *) typeName;
- (id) initWithContentsOfFile: (NSString *) absolutePath
ofType: (NSString *) typeName;

@end

@implementation _NSUnsupportedDocument

- initWithType: (NSString *) type error: (NSError **) error {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code: NSFeatureUnsupportedError userInfo: nil];
- (instancetype) initWithType: (NSString *) type error: (NSError **) error {
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFeatureUnsupportedError
userInfo: nil];
[self release];
return nil;
}

- (instancetype) initWithContentsOfURL: (NSURL *) url
ofType: (NSString *) typeName
error: (NSError *_Nullable *) outError
{

if (outError) {
*outError = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFeatureUnsupportedError
userInfo: nil];
}

[self release];
return nil;
}

- (id) initWithContentsOfURL: (NSURL *) url ofType: (NSString *) typeName {
[self release];
return nil;
}

- (id) initWithContentsOfFile: (NSString *) absolutePath
ofType: (NSString *) typeName
{
[self release];
return nil;
}

Expand Down Expand Up @@ -141,10 +177,15 @@ - (NSString *) displayNameForType: (NSString *) type {
}

- (Class) documentClassForType: (NSString *) type {
NSDictionary *info = [self _infoForType: type];
NSString *result = [info objectForKey: @"NSDocumentClass"];
NSString *result = nil;
for (NSDictionary *fileType in _fileTypes) {
if ([type isEqualToString: [fileType objectForKey: @"CFBundleTypeName"]]) {
result = [fileType objectForKey: @"NSDocumentClass"];
break;
}
}

return (result == nil) ? [_NSUnsupportedDocument class] : NSClassFromString(result);
return (result == nil) ? nil : NSClassFromString(result);
}

- (NSArray *) fileExtensionsFromType: (NSString *) type {
Expand All @@ -168,13 +209,13 @@ - (NSArray *) _allFileExtensions {

- (NSString *) typeFromFileExtension: (NSString *) extension {
extension = [extension lowercaseString];

for (NSDictionary *fileType in _fileTypes)
for (NSString *name in
[fileType objectForKey: @"CFBundleTypeExtensions"])
[fileType objectForKey: @"CFBundleTypeExtensions"]) {
if ([[name lowercaseString] isEqual: extension] ||
[name isEqual: @"*"])
return [fileType objectForKey: @"CFBundleTypeName"];
}

return nil;
}
Expand Down Expand Up @@ -259,7 +300,21 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error {
if (extension == nil)
return nil;

return [self typeFromFileExtension: extension];
NSString *UTI;

BOOL success = [url getResourceValue: &UTI
forKey: NSURLTypeIdentifierKey
error: error];
if (!success) {
return nil;
}

for(NSDictionary *fileType in _fileTypes) {
if ([[fileType objectForKey: @"LSItemContentTypes"] containsObject: UTI]) {
return [fileType objectForKey: @"CFBundleTypeName"];
}
}
return nil;
}

- makeDocumentWithContentsOfFile: (NSString *) path ofType: (NSString *) type {
Expand All @@ -281,7 +336,6 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error {

result = [[[class alloc] initWithContentsOfURL: url
ofType: type] autorelease];

return result;
}

Expand Down Expand Up @@ -367,7 +421,6 @@ - (id) makeUntitledDocumentOfType: (NSString *) type

- openUntitledDocumentAndDisplay: (BOOL) display error: (NSError **) error {
NSString *type = [self defaultType];

/* Cocoa documentation says:
"For backward binary compatibility with Mac OS X v10.3 and earlier,
the default implementation of this method instead invokes
Expand Down Expand Up @@ -430,13 +483,20 @@ - (id) makeUntitledDocumentOfType: (NSString *) type
NSDocument *result = [self documentForURL: url];

if (result == nil) {
NSString *extension = [[url path] pathExtension];
NSString *type = [self typeFromFileExtension: extension];
NSError *type_error = nil;
NSString *type = [self typeForContentsOfURL: url
error: &type_error];

if (type_error) {
if (error) {
*error = type_error;
}
return result;
}

result = [self makeDocumentWithContentsOfURL: url
ofType: type
error: error];

if (result != nil) {
[self addDocument: result];
[result makeWindowControllers];
Expand Down
18 changes: 18 additions & 0 deletions AppKit/NSMutableAttributedString.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,22 @@ - (void) applyFontTraits: (NSFontTraitMask) traits range: (NSRange) range {
[self endEditing];
}

- (BOOL) readFromURL: (NSURL *) url
options: (NSDictionary<NSAttributedStringDocumentReadingOptionKey, id> *) opts
documentAttributes: (NSDictionary<NSAttributedStringDocumentAttributeKey, id> *_Nullable *) dict
error: (NSError *_Nullable *) error
{
NSAttributedString *str = [NSAttributedString alloc];
str = [str initWithURL: url
options: opts
documentAttributes: dict
error: error];
if (str == nil) {
return NO;
}
[self setAttributedString: str];
[str release];
return YES;
}

@end
26 changes: 23 additions & 3 deletions AppKit/NSMutableParagraphStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,29 @@ - (void) setDefaultTabInterval: (CGFloat) interval {
}

- (void) setTabStops: (NSArray *) tabStops {
tabStops = [tabStops copy];
[_tabStops release];
_tabStops = tabStops;
if (tabStops != _tabStops) {
[_tabStops removeAllObjects];
[_tabStops addObjectsFromArray: tabStops];
[_tabStops sortUsingSelector: @selector(compare:)];
}
}

- (void) addTabStop: (NSTextTab *) tabStop {
NSUInteger index = [_tabStops
indexOfObjectPassingTest: ^BOOL(NSTextTab *other, NSUInteger id,
BOOL *stop) {
return [other compare: tabStop] == NSOrderedAscending;
}];

if (index == NSNotFound) {
[_tabStops insertObject: tabStop atIndex: 0];
} else {
[_tabStops insertObject: tabStop atIndex: index];
}
}

- (void) removeTabStop: (NSTextTab *) tabStop {
[_tabStops removeObject: tabStop];
}

- (void) setHyphenationFactor: (float) factor {
Expand Down
7 changes: 6 additions & 1 deletion AppKit/NSParagraphStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ + (NSParagraphStyle *) defaultParagraphStyle {
return shared;
}

+ (NSWritingDirection) defaultWritingDirectionForLanguage: (NSString *) languageName {
NSUnimplementedMethod();
return NSWritingDirectionNatural;
}

+ (NSArray *) _defaultTabStops {
static NSArray *shared = nil;

Expand Down Expand Up @@ -69,7 +74,7 @@ - (void) _initWithDefaults {
_lineHeightMultiple = 0;
_lineSpacing = 0;
_defaultTabInterval = 0;
_tabStops = [[[self class] _defaultTabStops] retain];
_tabStops = [[[self class] _defaultTabStops] mutableCopy];
_hyphenationFactor = 0;
_tighteningFactorForTruncation = 0;
}
Expand Down
Loading