From bb0c134428e6a7f9c64d4b7ec0b69d9f124f3fa2 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 7 Apr 2023 20:24:42 -0400 Subject: [PATCH 01/20] Add missing methods and stubs for TextEdit --- AppKit/NSAttributedString.m | 53 +++++++++++- AppKit/NSDocument.m | 27 +++++- AppKit/NSDocumentController.m | 86 ++++++++++++++++--- AppKit/NSMutableAttributedString.m | 11 +++ AppKit/NSMutableParagraphStyle.m | 8 ++ AppKit/NSParagraphStyle.m | 5 ++ AppKit/NSScrollView.m | 56 ++++++++++++ AppKit/NSScroller.m | 12 +++ AppKit/NSTextView.subproj/NSLayoutManager.m | 12 +++ AppKit/NSTextView.subproj/NSTextView.m | 45 ++++++++++ AppKit/NSView.m | 9 ++ AppKit/include/AppKit/NSAttributedString.h | 14 +++ AppKit/include/AppKit/NSDocument.h | 17 +++- AppKit/include/AppKit/NSLayoutManager.h | 12 +++ .../AppKit/NSMutableAttributedString.h | 10 +++ .../include/AppKit/NSMutableParagraphStyle.h | 4 + AppKit/include/AppKit/NSParagraphStyle.h | 2 + AppKit/include/AppKit/NSScrollView.h | 26 ++++++ AppKit/include/AppKit/NSScroller.h | 11 +++ AppKit/include/AppKit/NSTextView.h | 23 ++++- AppKit/include/AppKit/NSView.h | 3 + 21 files changed, 425 insertions(+), 21 deletions(-) diff --git a/AppKit/NSAttributedString.m b/AppKit/NSAttributedString.m index c6deb4d857..5080d8a3b8 100644 --- a/AppKit/NSAttributedString.m +++ b/AppKit/NSAttributedString.m @@ -129,6 +129,8 @@ this software and associated documentation files (the "Software"), to deal in NSString *const NSUsesScreenFontsDocumentAttribute = @"UsesScreenFonts"; NSString *const NSTextEffectAttributeName = @"NSTextEffect"; +NSAttributedStringKey NSWritingDirectionAttributeName = @"NSWritingDirectionAttribute"; +NSString *const NSCocoaVersionDocumentAttribute = @"NSCocoaVersionDocumentAttribute"; NSUInteger NSUnderlineStrikethroughMask = 0x4000; NSUInteger NSUnderlineByWordMask = 0x8000; @@ -157,6 +159,53 @@ + (NSAttributedString *) attributedStringWithAttachment: error: (NSError **) error { NSUnimplementedMethod(); + NSString *docType = [options objectForKey:NSDocumentTypeDocumentAttribute]; + + if(docType == nil){ + NSLog(@"NSAttributedString initFromData - inferring document type"); + //TODO: infer document type (assume RTF for now) + docType = NSRTFTextDocumentType; + } + + //Read the document based on its type + if([docType isEqual: NSDocFormatTextDocumentType]){ + return nil; + } + else if([docType isEqual: NSHTMLTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSMacSimpleTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSOfficeOpenXMLTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSOpenDocumentTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSPlainTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSRTFTextDocumentType]){ + return [self initWithRTF:data documentAttributes:attributes]; + } + else if([docType isEqual: NSRTFDTextDocumentType]){ + return [self initWithRTFD:data documentAttributes:attributes]; + } + else if([docType isEqual: NSWebArchiveTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else if([docType isEqual: NSWordMLTextDocumentType]){ + NSLog(@"NSAttributedString initFromData - dont know how to parse %@", docType); + return nil; + } + else { return nil; } @@ -237,7 +286,9 @@ + (NSAttributedString *) attributedStringWithAttachment: error: (NSError **) error { NSUnimplementedMethod(); - return nil; + NSLog(@"NSAttributedString - initializing from URL"); + NSData *data = [NSData dataWithContentsOfURL: url]; + return [self initWithData:data options:options documentAttributes:attributes error:error]; } #pragma mark - diff --git a/AppKit/NSDocument.m b/AppKit/NSDocument.m index aa228c298d..49205a67ce 100644 --- a/AppKit/NSDocument.m +++ b/AppKit/NSDocument.m @@ -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]; @@ -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]; @@ -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) { @@ -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; @@ -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)]; @@ -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 diff --git a/AppKit/NSDocumentController.m b/AppKit/NSDocumentController.m index 209d738ab5..9970de58c1 100644 --- a/AppKit/NSDocumentController.m +++ b/AppKit/NSDocumentController.m @@ -30,14 +30,47 @@ 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{ + + *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; } @@ -141,9 +174,13 @@ - (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 ([[fileType objectForKey: @"LSItemContentTypes"] containsObject: type]) + result = [fileType objectForKey: @"NSDocumentClass"]; + } + NSLog(@"NSDocController - docClassForType found class %@ for type %@", result, type); return (result == nil) ? [_NSUnsupportedDocument class] : NSClassFromString(result); } @@ -168,13 +205,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; } @@ -259,7 +296,23 @@ - (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){ + NSLog(@"NSDocumentController - found type: %@", UTI); + return UTI; + //TODO: move below code to documentClassForType + for(NSDictionary *type in _fileTypes){ + for(NSString *contentType in [type objectForKey:@"LSItemContentTypes"]){ + return [type objectForKey:@"CFBundleTypeName"]; + } + } + } + else{ + //TODO:Handle Error Here + } + return nil; } - makeDocumentWithContentsOfFile: (NSString *) path ofType: (NSString *) type { @@ -277,11 +330,13 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error { error: (NSError **) error { id result; + NSLog(@"DocController - making %@ from URL", type); Class class = [self documentClassForType: type]; + NSLog(@"DocController - initializing Document"); result = [[[class alloc] initWithContentsOfURL: url - ofType: type] autorelease]; - + ofType: type ] autorelease]; + NSLog(@"NSDocController - made from URL"); return result; } @@ -430,13 +485,18 @@ - (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; + NSString *type = [self typeForContentsOfURL:url error:&type_error]; + + if(type_error != nil){ + *error = type_error; + return result; + } result = [self makeDocumentWithContentsOfURL: url ofType: type error: error]; - + NSLog(@"NSDocCtrl openDocWithContsURL - made Document"); if (result != nil) { [self addDocument: result]; [result makeWindowControllers]; diff --git a/AppKit/NSMutableAttributedString.m b/AppKit/NSMutableAttributedString.m index 46483026b2..d23f0ff73c 100644 --- a/AppKit/NSMutableAttributedString.m +++ b/AppKit/NSMutableAttributedString.m @@ -203,4 +203,15 @@ - (void) applyFontTraits: (NSFontTraitMask) traits range: (NSRange) range { [self endEditing]; } +- (BOOL) readFromURL:(NSURL *)url + options:(NSDictionary *)opts + documentAttributes:(NSDictionary * _Nullable *)dict + error:(NSError * _Nullable *)error { + NSAttributedString *str = [NSAttributedString alloc]; + [str initWithURL:url options:opts documentAttributes:dict error:error]; + //[self setAttributedString:str]; + NSLog(@"NSMutableAttributedString readFromURL: - hopefully finished reading!"); + return true; +} + @end diff --git a/AppKit/NSMutableParagraphStyle.m b/AppKit/NSMutableParagraphStyle.m index 3aff6ac561..3fbe4b6560 100644 --- a/AppKit/NSMutableParagraphStyle.m +++ b/AppKit/NSMutableParagraphStyle.m @@ -133,6 +133,14 @@ - (void) setTabStops: (NSArray *) tabStops { _tabStops = tabStops; } +- (void) addTabStop:(NSTextTab *) tabStop { + //NSUnimplementedMethod(); +} + +- (void) removeTabStop:(NSTextTab *) tabStop { + //NSUnimplementedMethod(); +} + - (void) setHyphenationFactor: (float) factor { _hyphenationFactor = factor; } diff --git a/AppKit/NSParagraphStyle.m b/AppKit/NSParagraphStyle.m index 61d8ccda4c..0a10fadd6f 100644 --- a/AppKit/NSParagraphStyle.m +++ b/AppKit/NSParagraphStyle.m @@ -34,6 +34,11 @@ + (NSParagraphStyle *) defaultParagraphStyle { return shared; } ++ (NSWritingDirection)defaultWritingDirectionForLanguage:(NSString *)languageName { + NSUnimplementedMethod(); + return NSWritingDirectionNatural; +} + + (NSArray *) _defaultTabStops { static NSArray *shared = nil; diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index 2afdd224c2..3b8c62b79b 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -86,6 +86,16 @@ + (NSSize) frameSizeForContentSize: (NSSize) contentSize return contentSize; } ++ (NSSize)frameSizeForContentSize:(NSSize)cSize + horizontalScrollerClass:(Class)horizontalScrollerClass + verticalScrollerClass:(Class)verticalScrollerClass + borderType:(NSBorderType)type + controlSize:(NSControlSize)controlSize + scrollerStyle:(NSScrollerStyle)scrollerStyle +{ + NSUnimplementedMethod(); +} + + (NSSize) contentSizeForFrameSize: (NSSize) frameSize hasHorizontalScroller: (BOOL) hasHorizontalScroller hasVerticalScroller: (BOOL) hasVerticalScroller @@ -120,6 +130,16 @@ + (NSSize) contentSizeForFrameSize: (NSSize) frameSize return frameSize; } ++ (NSSize)contentSizeForFrameSize:(NSSize)fSize + horizontalScrollerClass:(Class)horizontalScrollerClass + verticalScrollerClass:(Class)verticalScrollerClass + borderType:(NSBorderType)type + controlSize:(NSControlSize)controlSize + scrollerStyle:(NSScrollerStyle)scrollerStyle +{ + NSUnimplementedMethod(); +} + + (void) setRulerViewClass: (Class) class { _rulerViewClass = class; } @@ -614,6 +634,22 @@ - (NSCursor *) documentCursor { return _documentCursor; } +- (CGFloat) magnification { + return _magnification; +} + +- (CGFloat) minMagnification { + return _minMagnification; +} + +- (CGFloat) maxMagnification { + return _maxMagnification; +} + +- (BOOL) allowsMagnification { + return _allowsMagnification; +} + - (void) setDocumentView: (NSView *) view { [_clipView setDocumentView: view]; [self reflectScrolledClipView: _clipView]; @@ -779,6 +815,26 @@ - (void) setAutohidesScrollers: (BOOL) value { // FIXME: tile or hide/show scrollers? } +- (void) setMagnification: (CGFloat) value { + _magnification = value; + NSUnimplementedMethod(); +} + +- (void) setMinMagnification: (CGFloat) value { + _minMagnification = value; + NSUnimplementedMethod(); +} + +- (void) setMaxMagnification: (CGFloat) value { + _maxMagnification = value; + NSUnimplementedMethod(); +} + +- (void) setAllowsMagnification: (BOOL) value { + _allowsMagnification = value; + NSUnimplementedMethod(); +} + - (void) tile { NSRect frame; diff --git a/AppKit/NSScroller.m b/AppKit/NSScroller.m index 754afef2a7..6c361fa313 100644 --- a/AppKit/NSScroller.m +++ b/AppKit/NSScroller.m @@ -34,6 +34,9 @@ + (CGFloat) scrollerWidth { return [[NSDisplay currentDisplay] scrollerWidth]; } ++ (NSScrollerStyle) preferredScrollerStyle { + NSUnimplementedMethod(); +} /* OS X has a global default "AppleScrollBarVariant" with the values: Single, DoubleMin, DoubleMax, and DoubleBoth This controls the default position of the scroller. This should be controlling the positioning. @@ -141,6 +144,11 @@ - (NSControlSize) controlSize { return _controlSize; } +- (NSScrollerStyle) scrollerStyle { + return _scrollerStyle; +} + + - (void) setFloatValue: (float) zeroToOneValue knobProportion: (CGFloat) zeroToOneKnob { @@ -185,6 +193,10 @@ - (void) setControlSize: (NSControlSize) value { [self setNeedsDisplay: YES]; } +- (void) setScrollerStyle: (NSScrollerStyle) style { + _scrollerStyle = style; +} + - (NSRect) frameOfDecrementPage { NSRect knobSlot = [self rectForPart: NSScrollerKnobSlot]; NSRect knob = [self rectForPart: NSScrollerKnob]; diff --git a/AppKit/NSTextView.subproj/NSLayoutManager.m b/AppKit/NSTextView.subproj/NSLayoutManager.m index a7cd585970..a38f557eb0 100644 --- a/AppKit/NSTextView.subproj/NSLayoutManager.m +++ b/AppKit/NSTextView.subproj/NSLayoutManager.m @@ -177,6 +177,8 @@ - (NSArray *) textContainers { } - (NSTextView *) firstTextView { + if([_textContainers count] < 1) + return nil; return [[_textContainers objectAtIndex: 0] textView]; } @@ -726,6 +728,11 @@ - (NSTextContainer *) extraLineFragmentTextContainer { return _extraLineFragmentTextContainer; } +- (BOOL) allowsNonContiguousLayout { + NSUnimplementedMethod(); + return _allowsNonContiguousLayout; +} + - (void) setTextContainer: (NSTextContainer *) container forGlyphRange: (NSRange) glyphRange { @@ -2909,4 +2916,9 @@ - (NSView *) rulerAccessoryViewForTextView: (NSTextView *) view { return nil; } + +- (void) setAllowsNonContiguousLayout: (BOOL) value { + _allowsNonContiguousLayout = value; + NSUnimplementedMethod(); +} @end diff --git a/AppKit/NSTextView.subproj/NSTextView.m b/AppKit/NSTextView.subproj/NSTextView.m index 1858357dac..275c77f6f9 100644 --- a/AppKit/NSTextView.subproj/NSTextView.m +++ b/AppKit/NSTextView.subproj/NSTextView.m @@ -3630,6 +3630,22 @@ - (void) setEnabledTextCheckingTypes: (NSTextCheckingTypes) checkingTypes { NSUnimplementedMethod(); } +- (BOOL) smartInsertDeleteEnabled { + return _smartInsertDeleteEnabled; +} + +- (void) setSmartInsertDeleteEnabled: (BOOL) boolForKey { + _smartInsertDeleteEnabled = boolForKey; +} + +- (BOOL) allowsDocumentBackgroundColorChange { + return _allowsDocumentBackgroundColorChange; +} + +- (void) setAllowsDocumentBackgroundColorChange: (BOOL) value { + _allowsDocumentBackgroundColorChange = value; +} + - (void) setSpellingState: (NSInteger) value range: (NSRange) characterRange { [[self layoutManager] addTemporaryAttribute: NSSpellingStateAttributeName @@ -3956,6 +3972,35 @@ - (void) rulerView: (NSRulerView *) rulerView - (id) replacementObjectForKeyedArchiver { NSUnimplementedMethod(); return self; + +- (NSTextLayoutOrientation) layoutOrientation { + NSUnimplementedMethod(); + return _layoutOrientation; +} + +- (void)setLayoutOrientation:(NSTextLayoutOrientation)orientation { + _layoutOrientation = orientation; + NSUnimplementedMethod(); +} + +- (BOOL) usesFindBar { + NSUnimplementedMethod(); + return _usesFindBar; +} + +- (void) setUsesFindBar: (BOOL) value { + NSUnimplementedMethod(); + _usesFindBar = value; +} + +- (BOOL) isIncrementalSearchingEnabled { + NSUnimplementedMethod(); + return _incrementalSearchingEnabled; +} + +- (void) setIncrementalSearchingEnabled: (BOOL) value { + NSUnimplementedMethod(); + _incrementalSearchingEnabled = value; } @end diff --git a/AppKit/NSView.m b/AppKit/NSView.m index b945e72514..de8b19679c 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -887,6 +887,10 @@ - (NSString *) toolTip { return toolTip; } +- (BOOL) translatesAutoresizingMaskIntoConstraints { + return _translatesAutoresizingMaskIntoConstraints; +} + - viewWithTag: (NSInteger) tag { int i, count = [_subviews count]; @@ -1126,6 +1130,11 @@ - (void) setBoundsRotation: (CGFloat) angle { NSUnimplementedMethod(); } +- (void) settranslatesAutoresizingMaskIntoConstraints: (BOOL) value { + _translatesAutoresizingMaskIntoConstraints = value; + NSUnimplementedMethod(); +} + - (void) setPostsFrameChangedNotifications: (BOOL) flag { _postsNotificationOnFrameChange = flag; } diff --git a/AppKit/include/AppKit/NSAttributedString.h b/AppKit/include/AppKit/NSAttributedString.h index 03a7bd3890..dd61c6094a 100644 --- a/AppKit/include/AppKit/NSAttributedString.h +++ b/AppKit/include/AppKit/NSAttributedString.h @@ -24,6 +24,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @class NSFont, NSColor, NSParagraphStyle, NSTextAttachment, NSFileWrapper, NSTextList, NSTextBlock, NSTextTable; +typedef NSString *NSAttributedStringDocumentReadingOptionKey; +typedef NSString *NSAttributedStringDocumentAttributeKey; +typedef NSString *NSAttributedStringKey; + APPKIT_EXPORT NSString *const NSFontAttributeName; APPKIT_EXPORT NSString *const NSParagraphStyleAttributeName; APPKIT_EXPORT NSString *const NSForegroundColorAttributeName; @@ -112,10 +116,13 @@ APPKIT_EXPORT NSString *const NSCharacterShapeAttributeName; APPKIT_EXPORT NSString *const NSUsesScreenFontsDocumentAttribute; APPKIT_EXPORT NSString *const NSTextEffectAttributeName; +APPKIT_EXPORT NSAttributedStringKey NSWritingDirectionAttributeName; +APPKIT_EXPORT NSString *const NSCocoaVersionDocumentAttribute; APPKIT_EXPORT NSUInteger NSUnderlineStrikethroughMask; APPKIT_EXPORT NSUInteger NSUnderlineByWordMask; + enum { NSSpellingStateSpellingFlag = 0x01, NSSpellingStateGrammarFlag = 0x02, @@ -239,6 +246,13 @@ enum { - (NSRect) boundingRectWithSize: (NSSize) size options: (NSStringDrawingOptions) options; +#pragma mark - +#pragma mark Getting Attribute Data +- (void)enumerateAttribute:(NSAttributedStringKey)attrName + inRange:(NSRange)enumerationRange + options:(NSAttributedStringEnumerationOptions)opts + usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block; + #pragma mark - #pragma mark Testing String Data Sources diff --git a/AppKit/include/AppKit/NSDocument.h b/AppKit/include/AppKit/NSDocument.h index 62d760d725..440e176b0c 100644 --- a/AppKit/include/AppKit/NSDocument.h +++ b/AppKit/include/AppKit/NSDocument.h @@ -23,18 +23,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @class NSWindow, NSWindowController, NSSavePanel, NSMenuItem, NSFileWrapper, NSPrintOperation, NSPrintInfo, NSPageLayout, NSView; -typedef enum { +typedef enum NSDocumentChangeType : NSUInteger { NSChangeDone, NSChangeUndone, NSChangeCleared, NSChangeReadOtherContents, NSChangeAutosaved, + NSChangeRedone, + NSChangeDiscardable = 256, } NSDocumentChangeType; typedef enum { NSSaveOperation, NSSaveAsOperation, NSSaveToOperation, + NSAutosaveElsewhereOperation, + NSAutosaveInPlaceOperation, + NSAutosaveAsOperation, NSAutosaveOperation, } NSSaveOperationType; @@ -230,7 +235,7 @@ typedef enum { (NSSaveOperationType) operation; - (NSFileWrapper *) fileWrapperRepresentationOfType: (NSString *) type; - initWithContentsOfFile: (NSString *) path ofType: (NSString *) type; -- initWithContentsOfURL: (NSURL *) url ofType: (NSString *) type; +- (id) initWithContentsOfURL: (NSURL *) url ofType: (NSString *) type; - (BOOL) loadDataRepresentation: (NSData *) data ofType: (NSString *) type; - (BOOL) loadFileWrapperRepresentation: (NSFileWrapper *) wrapper ofType: (NSString *) type; @@ -259,4 +264,12 @@ typedef enum { ofType: (NSString *) type saveOperation: (NSSaveOperationType) operation; +- (void)saveToURL: (NSURL *) url + ofType: (NSString *) typeName + forSaveOperation: (NSSaveOperationType) saveOperation +completionHandler: (void (^)(NSError *errorOrNil)) completionHandler; + +- (void)autosaveWithImplicitCancellability: (BOOL) autosavingIsImplicitlyCancellable + completionHandler: (void (^)(NSError *errorOrNil)) completionHandler; + @end diff --git a/AppKit/include/AppKit/NSLayoutManager.h b/AppKit/include/AppKit/NSLayoutManager.h index 03de587a4c..9463dbbf5a 100644 --- a/AppKit/include/AppKit/NSLayoutManager.h +++ b/AppKit/include/AppKit/NSLayoutManager.h @@ -32,6 +32,11 @@ typedef enum { NSGlyphInscribeOverBelow, } NSGlyphInscription; +typedef NS_ENUM(NSInteger, NSTextLayoutOrientation) { + NSTextLayoutOrientationHorizontal, + NSTextLayoutOrientationVertical, +}; + @interface NSLayoutManager : NSObject { NSTextStorage *_textStorage; NSGlyphGenerator *_glyphGenerator; @@ -47,6 +52,7 @@ typedef enum { struct NSRangeEntries *_rangeToTemporaryAttributes; BOOL _layoutInvalid; + BOOL _allowsNonContiguousLayout; NSRect _extraLineFragmentRect; NSRect _extraLineFragmentUsedRect; @@ -126,6 +132,8 @@ typedef enum { - (NSRect) extraLineFragmentUsedRect; - (NSTextContainer *) extraLineFragmentTextContainer; +- (BOOL) allowsNonContiguousLayout; + - (void) setTextContainer: (NSTextContainer *) container forGlyphRange: (NSRange) glyphRange; - (void) setLineFragmentRect: (NSRect) fragmentRect @@ -268,6 +276,8 @@ typedef enum { paragraphStyle: (NSParagraphStyle *) style ruler: (NSRulerView *) ruler enabled: (BOOL) isEnabled; + +- (void) setAllowsNonContiguousLayout: (BOOL) value; @end @protocol NSLayoutManagerDelegate @@ -284,4 +294,6 @@ typedef enum { @protocol NSTextLayoutOrientationProvider +- (NSTextLayoutOrientation) layoutOrientation; + @end diff --git a/AppKit/include/AppKit/NSMutableAttributedString.h b/AppKit/include/AppKit/NSMutableAttributedString.h index 0c2cbacfa7..dd4e85384f 100644 --- a/AppKit/include/AppKit/NSMutableAttributedString.h +++ b/AppKit/include/AppKit/NSMutableAttributedString.h @@ -25,4 +25,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - (void) fixParagraphStyleAttributeInRange: (NSRange) range; - (void) fixAttributesInRange: (NSRange) range; - (void) applyFontTraits: (NSFontTraitMask) traits range: (NSRange) range; + +- (BOOL) readFromURL:(NSURL *)url + options:(NSDictionary *)opts + documentAttributes:(NSDictionary * _Nullable *)dict + error:(NSError * _Nullable *)error; + +- (void)addAttribute:(NSAttributedStringKey)name + value:(id)value + range:(NSRange)range; + @end diff --git a/AppKit/include/AppKit/NSMutableParagraphStyle.h b/AppKit/include/AppKit/NSMutableParagraphStyle.h index 365044aa74..253d1e273a 100644 --- a/AppKit/include/AppKit/NSMutableParagraphStyle.h +++ b/AppKit/include/AppKit/NSMutableParagraphStyle.h @@ -18,6 +18,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import +#import @interface NSMutableParagraphStyle : NSParagraphStyle @@ -47,6 +48,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - (void) setDefaultTabInterval: (CGFloat) interval; - (void) setTabStops: (NSArray *) tabStops; +- (void) addTabStop:(NSTextTab *) tabStop; +- (void) removeTabStop:(NSTextTab *) tabStop; + - (void) setHyphenationFactor: (float) factor; - (void) setTighteningFactorForTruncation: (float) factor; diff --git a/AppKit/include/AppKit/NSParagraphStyle.h b/AppKit/include/AppKit/NSParagraphStyle.h index f942545bd5..c3cec80486 100644 --- a/AppKit/include/AppKit/NSParagraphStyle.h +++ b/AppKit/include/AppKit/NSParagraphStyle.h @@ -52,6 +52,8 @@ typedef enum { + (NSParagraphStyle *) defaultParagraphStyle; ++ (NSWritingDirection)defaultWritingDirectionForLanguage:(NSString *)languageName; + - (NSWritingDirection) baseWritingDirection; - (CGFloat) paragraphSpacing; diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index 946731c5f0..32f8f73150 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -19,6 +19,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import +#import +#import #import @class NSClipView, NSScroller, NSColor, NSRulerView; @@ -50,16 +52,32 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; BOOL _scrollsDynamically; BOOL _autohidesScrollers; NSCursor *_documentCursor; + BOOL _allowsMagnification; + CGFloat _magnification; + CGFloat _minMagnification; + CGFloat _maxMagnification; } + (NSSize) frameSizeForContentSize: (NSSize) contentSize hasHorizontalScroller: (BOOL) hasHorizontalScroller hasVerticalScroller: (BOOL) hasVerticalScroller borderType: (NSBorderType) borderType; ++ (NSSize)frameSizeForContentSize:(NSSize)cSize + horizontalScrollerClass:(Class)horizontalScrollerClass + verticalScrollerClass:(Class)verticalScrollerClass + borderType:(NSBorderType)type + controlSize:(NSControlSize)controlSize + scrollerStyle:(NSScrollerStyle)scrollerStyle; + (NSSize) contentSizeForFrameSize: (NSSize) fSize hasHorizontalScroller: (BOOL) hasHorizontalScroller hasVerticalScroller: (BOOL) hasVerticalScroller borderType: (NSBorderType) borderType; ++ (NSSize)contentSizeForFrameSize:(NSSize)fSize + horizontalScrollerClass:(Class)horizontalScrollerClass + verticalScrollerClass:(Class)verticalScrollerClass + borderType:(NSBorderType)type + controlSize:(NSControlSize)controlSize + scrollerStyle:(NSScrollerStyle)scrollerStyle; + (void) setRulerViewClass: (Class) aClass; + (Class) rulerViewClass; @@ -94,6 +112,10 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (BOOL) autohidesScrollers; - (NSCursor *) documentCursor; +- (CGFloat) magnification; +- (CGFloat) minMagnification; +- (CGFloat) maxMagnification; +- (BOOL) allowsMagnification; - (void) setDocumentView: (NSView *) view; - (void) setContentView: (NSClipView *) clipView; @@ -116,6 +138,10 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (void) setScrollsDynamically: (BOOL) flag; - (void) setDocumentCursor: (NSCursor *) cursor; - (void) setAutohidesScrollers: (BOOL) value; +- (void) setMagnification: (CGFloat) value; +- (void) setMinMagnification: (CGFloat) value; +- (void) setMaxMagnification: (CGFloat) value; +- (BOOL) setAllowsMagnification: (BOOL) value; - (void) tile; - (void) reflectScrolledClipView: (NSClipView *) clipView; diff --git a/AppKit/include/AppKit/NSScroller.h b/AppKit/include/AppKit/NSScroller.h index a255e8f807..b27d1f5423 100644 --- a/AppKit/include/AppKit/NSScroller.h +++ b/AppKit/include/AppKit/NSScroller.h @@ -46,6 +46,12 @@ enum { NSOnlyScrollerArrows = 1, NSAllScrollerParts = 2, }; + +typedef NS_ENUM(NSInteger, NSScrollerStyle) { + NSScrollerStyleLegacy, + NSScrollerStyleOverlay, +}; + typedef NSUInteger NSUsableScrollerParts; @interface NSScroller : NSControl { @@ -64,6 +70,8 @@ typedef NSUInteger NSUsableScrollerParts; NSScrollerPart _hitPart; BOOL _isEnabled; BOOL _isHighlighted; + + NSScrollerStyle _scrollerStyle; } + (CGFloat) scrollerWidth; @@ -71,11 +79,14 @@ typedef NSUInteger NSUsableScrollerParts; - (CGFloat) knobProportion; - (NSScrollArrowPosition) arrowsPosition; - (NSControlSize) controlSize; +- (NSScrollerStyle) scrollerStyle; ++ (NSScrollerStyle) preferredScrollerStyle; - (void) setFloatValue: (float) zeroToOneValue knobProportion: (CGFloat) zeroToOneKnob; - (void) setArrowsPosition: (NSScrollArrowPosition) position; - (void) setControlSize: (NSControlSize) value; +- (void) setScrollerStyle : (NSScrollerStyle) style; - (NSRect) rectForPart: (NSScrollerPart) part; - (void) checkSpaceForParts; diff --git a/AppKit/include/AppKit/NSTextView.h b/AppKit/include/AppKit/NSTextView.h index 54455036be..3743b3b843 100644 --- a/AppKit/include/AppKit/NSTextView.h +++ b/AppKit/include/AppKit/NSTextView.h @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import #import @@ -68,7 +69,7 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; @class NSUndoTyping; -@interface NSTextView : NSText { +@interface NSTextView : NSText { NSTextStorage *_textStorage; NSTextContainer *_textContainer; NSSize _textContainerInset; @@ -98,6 +99,7 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; BOOL _usesRuler; BOOL _rulerVisible; BOOL _usesFontPanel; + BOOL _usesFindBar; BOOL _allowsUndo; NSMutableArray *_selectedRanges; @@ -129,8 +131,14 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; BOOL _isContinuousSpellCheckingEnabled; BOOL _isAutomaticSpellingCorrectionEnabled; NSTextCheckingTypes _enabledTextCheckingTypes; + BOOL _smartInsertDeleteEnabled; + + BOOL _allowsDocumentBackgroundColorChange; NSUndoTyping *_undoTyping; + NSTextLayoutOrientation _layoutOrientation; + + BOOL _incrementalSearchingEnabled; } - initWithFrame: (NSRect) frame textContainer: (NSTextContainer *) container; @@ -250,8 +258,21 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; - (NSTextCheckingTypes) enabledTextCheckingTypes; - (void) setEnabledTextCheckingTypes: (NSTextCheckingTypes) checkingTypes; +- (BOOL) smartInsertDeleteEnabled; +- (void) setSmartInsertDeleteEnabled: (BOOL) boolForKey; + +- (BOOL) allowsDocumentBackgroundColorChange; +- (void) setAllowsDocumentBackgroundColorChange: (BOOL) value; + - (void) setSpellingState: (NSInteger) value range: (NSRange) characterRange; +- (BOOL) usesFindBar; +- (void) setUsesFindBar: (BOOL) value; +- (BOOL) isIncrementalSearchingEnabled; +- (void) setIncrementalSearchingEnabled: (BOOL) value; + +- (void) setLayoutOrientation:(NSTextLayoutOrientation)orientation; + @end @interface NSObject (NSTextView_undoManager) diff --git a/AppKit/include/AppKit/NSView.h b/AppKit/include/AppKit/NSView.h index 7f65ac772b..1cac743cc5 100644 --- a/AppKit/include/AppKit/NSView.h +++ b/AppKit/include/AppKit/NSView.h @@ -109,6 +109,7 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre NSInteger _rectsBeingRedrawnCount; CGFloat _frameRotation; CGFloat _boundsRotation; + BOOL _translatesAutoresizingMaskIntoConstraints; BOOL _validTrackingAreas; BOOL _validTransforms; @@ -203,6 +204,7 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre - (NSMenu *) menuForEvent: (NSEvent *) event; - (NSMenuItem *) enclosingMenuItem; - (NSString *) toolTip; +- (BOOL) translatesAutoresizingMaskIntoConstraints; - viewWithTag: (NSInteger) tag; - (NSView *) hitTest: (NSPoint) point; @@ -225,6 +227,7 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre - (void) setBoundsSize: (NSSize) size; - (void) setBoundsOrigin: (NSPoint) origin; - (void) setBoundsRotation: (CGFloat) angle; +- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL) value; - (CGFloat) frameRotation; - (CGFloat) boundsRotation; From 81d2422c6737efb08e39e19ff96cc821008965e1 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Wed, 12 Apr 2023 19:02:09 -0400 Subject: [PATCH 02/20] add NSDocumentController type discovery --- AppKit/NSAttributedString.m | 5 +++-- AppKit/NSDocumentController.m | 13 ++++--------- AppKit/NSMutableAttributedString.m | 1 - 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/AppKit/NSAttributedString.m b/AppKit/NSAttributedString.m index 5080d8a3b8..15052f2b83 100644 --- a/AppKit/NSAttributedString.m +++ b/AppKit/NSAttributedString.m @@ -159,7 +159,7 @@ + (NSAttributedString *) attributedStringWithAttachment: error: (NSError **) error { NSUnimplementedMethod(); - NSString *docType = [options objectForKey:NSDocumentTypeDocumentAttribute]; + NSString *docType = [options objectForKey:@"NSDocumentTypeDocumentAttribute"]; if(docType == nil){ NSLog(@"NSAttributedString initFromData - inferring document type"); @@ -207,6 +207,7 @@ + (NSAttributedString *) attributedStringWithAttachment: } else { return nil; + } } - initWithDocFormat: (NSData *) werd @@ -252,6 +253,7 @@ + (NSAttributedString *) attributedStringWithAttachment: } - initWithRTF: (NSData *) rtf documentAttributes: (NSDictionary **) attributes { + NSLog(@"NSAttributedString - initializing from RTF"); NSAttributedString *string = [NSRichTextReader attributedStringWithData: rtf]; if (string == nil) { @@ -285,7 +287,6 @@ + (NSAttributedString *) attributedStringWithAttachment: documentAttributes: (NSDictionary **) attributes error: (NSError **) error { - NSUnimplementedMethod(); NSLog(@"NSAttributedString - initializing from URL"); NSData *data = [NSData dataWithContentsOfURL: url]; return [self initWithData:data options:options documentAttributes:attributes error:error]; diff --git a/AppKit/NSDocumentController.m b/AppKit/NSDocumentController.m index 9970de58c1..90532bbfe5 100644 --- a/AppKit/NSDocumentController.m +++ b/AppKit/NSDocumentController.m @@ -305,13 +305,11 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error { //TODO: move below code to documentClassForType for(NSDictionary *type in _fileTypes){ for(NSString *contentType in [type objectForKey:@"LSItemContentTypes"]){ - return [type objectForKey:@"CFBundleTypeName"]; + if([contentType isEqual: UTI]) + return [type objectForKey:@"CFBundleTypeName"]; } } } - else{ - //TODO:Handle Error Here - } return nil; } @@ -330,13 +328,11 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error { error: (NSError **) error { id result; - NSLog(@"DocController - making %@ from URL", type); Class class = [self documentClassForType: type]; - NSLog(@"DocController - initializing Document"); result = [[[class alloc] initWithContentsOfURL: url - ofType: type ] autorelease]; - NSLog(@"NSDocController - made from URL"); + ofType: type] autorelease]; + return result; } @@ -422,7 +418,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 diff --git a/AppKit/NSMutableAttributedString.m b/AppKit/NSMutableAttributedString.m index d23f0ff73c..e680cfdfc1 100644 --- a/AppKit/NSMutableAttributedString.m +++ b/AppKit/NSMutableAttributedString.m @@ -213,5 +213,4 @@ - (BOOL) readFromURL:(NSURL *)url NSLog(@"NSMutableAttributedString readFromURL: - hopefully finished reading!"); return true; } - @end From fd68ee23c752911bafe56f137ea51640d36cff83 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:18:12 -0400 Subject: [PATCH 03/20] Implement NSUserInterfaceItemIdentifcation protocol --- AppKit/NSView.m | 6 +++--- AppKit/include/AppKit/NSView.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AppKit/NSView.m b/AppKit/NSView.m index de8b19679c..9d2d3bc28a 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -888,7 +888,7 @@ - (NSString *) toolTip { } - (BOOL) translatesAutoresizingMaskIntoConstraints { - return _translatesAutoresizingMaskIntoConstraints; + return _translatesAutoresizingMaskIntoConstraints; } - viewWithTag: (NSInteger) tag { @@ -1131,8 +1131,8 @@ - (void) setBoundsRotation: (CGFloat) angle { } - (void) settranslatesAutoresizingMaskIntoConstraints: (BOOL) value { - _translatesAutoresizingMaskIntoConstraints = value; - NSUnimplementedMethod(); + _translatesAutoresizingMaskIntoConstraints = value; + NSUnimplementedMethod(); } - (void) setPostsFrameChangedNotifications: (BOOL) flag { diff --git a/AppKit/include/AppKit/NSView.h b/AppKit/include/AppKit/NSView.h index 1cac743cc5..1dba742b5e 100644 --- a/AppKit/include/AppKit/NSView.h +++ b/AppKit/include/AppKit/NSView.h @@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import #import #import #import From 5300f80f186dc615462c0c0541d506c9d66f1331 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:41:22 -0400 Subject: [PATCH 04/20] Fix handling of NSTextContainer and NSTextStorage in NSTextView.subproj Fix issue where a layout manager's NSTextStorage could be `nil` at initialization but later set by introducing the `_setTextStorage:` method to NSTextView. Add stubs a for missing properties in NSTextView. Refactor `firstTextView` to properly find and return the first text view, or `nil` if there are no text views. Use 64-bit ready types where applicable. Relocate unrelated code from _setTextStorage --- AppKit/NSTextView.subproj/NSLayoutManager.m | 20 +-- AppKit/NSTextView.subproj/NSTextContainer.m | 1 + AppKit/NSTextView.subproj/NSTextView.m | 148 +++++++++++++++----- AppKit/include/AppKit/NSTextView.h | 29 +++- 4 files changed, 155 insertions(+), 43 deletions(-) diff --git a/AppKit/NSTextView.subproj/NSLayoutManager.m b/AppKit/NSTextView.subproj/NSLayoutManager.m index a38f557eb0..d4cc265519 100644 --- a/AppKit/NSTextView.subproj/NSLayoutManager.m +++ b/AppKit/NSTextView.subproj/NSLayoutManager.m @@ -30,7 +30,6 @@ this software and associated documentation files (the "Software"), to deal in #import #import -#import #import #import #import @@ -39,6 +38,7 @@ this software and associated documentation files (the "Software"), to deal in #import #import #import +#import #import "NSBidiHelper.h" #import "NSRulerMarker+NSTextExtensions.h" @@ -177,13 +177,17 @@ - (NSArray *) textContainers { } - (NSTextView *) firstTextView { - if([_textContainers count] < 1) - return nil; - return [[_textContainers objectAtIndex: 0] textView]; + for (NSTextContainer *container in _textContainers) { + NSTextView *textView = [container textView]; + if (textView) { + return textView; + } + } + return nil; } - (NSTextView *) textViewForBeginningOfSelection { - return [[_textContainers objectAtIndex: 0] textView]; + return [self firstTextView]; } - (BOOL) layoutManagerOwnsFirstResponderInWindow: (NSWindow *) window { @@ -729,7 +733,6 @@ - (NSTextContainer *) extraLineFragmentTextContainer { } - (BOOL) allowsNonContiguousLayout { - NSUnimplementedMethod(); return _allowsNonContiguousLayout; } @@ -1372,7 +1375,7 @@ - (NSRect *) rectArrayForGlyphRange: (NSRange) glyphRange #if DEBUG_rectArrayForGlyphRange_withinSelectedGlyphRange_inTextContainer_rectCount NSLog(@"This existing range is %@\n", NSStringFromRange(range)); #endif - + // The part of the that we are interested in - start with the full // rect, we'll change it if we don't want the full fragment NSRect fill = fragment->rect; @@ -1381,7 +1384,8 @@ - (NSRect *) rectArrayForGlyphRange: (NSRange) glyphRange NSRange intersect; if (remainder.length > 0) intersect = NSIntersectionRange(remainder, range); - else // NSIntersectionRange's returned location is undefined for 0-length ranges + else // NSIntersectionRange's returned location is undefined for + // 0-length ranges intersect = NSMakeRange(remainder.location, 0); #if DEBUG_rectArrayForGlyphRange_withinSelectedGlyphRange_inTextContainer_rectCount diff --git a/AppKit/NSTextView.subproj/NSTextContainer.m b/AppKit/NSTextView.subproj/NSTextContainer.m index 1a06322151..40b8682639 100644 --- a/AppKit/NSTextView.subproj/NSTextContainer.m +++ b/AppKit/NSTextView.subproj/NSTextContainer.m @@ -189,6 +189,7 @@ - (void) setHeightTracksTextView: (BOOL) flag { - (void) setLayoutManager: (NSLayoutManager *) layoutManager { _layoutManager = layoutManager; + [_textView _setTextStorage: [_layoutManager textStorage]]; } - (void) replaceLayoutManager: (NSLayoutManager *) layoutManager { diff --git a/AppKit/NSTextView.subproj/NSTextView.m b/AppKit/NSTextView.subproj/NSTextView.m index 275c77f6f9..2ad8d1d8d7 100644 --- a/AppKit/NSTextView.subproj/NSTextView.m +++ b/AppKit/NSTextView.subproj/NSTextView.m @@ -143,6 +143,36 @@ - (void) encodeWithCoder: (NSCoder *) coder { NSUnimplementedMethod(); } +- (void) _setTextStorage: (NSTextStorage *) storage { + if (_ownsTextStorage) + [_textStorage release]; + + _textStorage = storage; + _ownsTextStorage = NO; + + NSMutableDictionary *typingAttributes = + [[_textStorage attributesAtIndex: 0 + effectiveRange: NULL] mutableCopy]; + if (![typingAttributes objectForKey: NSFontAttributeName]) { + [typingAttributes setObject: _font forKey: NSFontAttributeName]; + } + if (![typingAttributes objectForKey: NSForegroundColorAttributeName]) { + [typingAttributes setObject: _textColor + forKey: NSForegroundColorAttributeName]; + } + + [_typingAttributes release]; + _typingAttributes = typingAttributes; + + if ([typingAttributes objectForKey: NSParagraphStyleAttributeName]) { + _defaultParagraphStyle = [[typingAttributes + objectForKey: NSParagraphStyleAttributeName] copy]; + } else { + _defaultParagraphStyle = + [[NSParagraphStyle defaultParagraphStyle] copy]; + } +} + - initWithCoder: (NSCoder *) coder { [super initWithCoder: coder]; @@ -240,8 +270,6 @@ - (void) encodeWithCoder: (NSCoder *) coder { - initWithFrame: (NSRect) frame textContainer: (NSTextContainer *) container { [super initWithFrame: frame]; - _textStorage = [[container layoutManager] textStorage]; - _ownsTextStorage = NO; _textContainer = [container retain]; [_textContainer setTextView: self]; _textContainerInset = NSMakeSize(0, 0); @@ -263,26 +291,6 @@ - (void) encodeWithCoder: (NSCoder *) coder { _selectedRanges = [[NSMutableArray alloc] init]; [_selectedRanges addObject: [NSValue valueWithRange: NSMakeRange(0, 0)]]; - NSMutableDictionary *typingAttributes = - [[_textStorage attributesAtIndex: 0 - effectiveRange: NULL] mutableCopy]; - if (![typingAttributes objectForKey: NSFontAttributeName]) { - [typingAttributes setObject: _font forKey: NSFontAttributeName]; - } - if (![typingAttributes objectForKey: NSForegroundColorAttributeName]) { - [typingAttributes setObject: _textColor - forKey: NSForegroundColorAttributeName]; - } - _typingAttributes = typingAttributes; - - if ([typingAttributes objectForKey: NSParagraphStyleAttributeName]) { - _defaultParagraphStyle = [[typingAttributes - objectForKey: NSParagraphStyleAttributeName] copy]; - } else { - _defaultParagraphStyle = - [[NSParagraphStyle defaultParagraphStyle] copy]; - } - _rangeForUserCompletion = NSMakeRange(NSNotFound, 0); _selectedTextAttributes = [[NSDictionary dictionaryWithObjectsAndKeys: [NSColor selectedTextColor], @@ -291,9 +299,12 @@ - (void) encodeWithCoder: (NSCoder *) coder { NSBackgroundColorAttributeName, nil] retain]; + [self _setTextStorage: [[container layoutManager] textStorage]]; + [self setBoundsOrigin: NSMakePoint(-_textContainerInset.width, -_textContainerInset.height)]; [self configureMenu]; + [self registerForDraggedTypes: [NSArray arrayWithObjects: NSRTFPboardType, NSStringPboardType, @@ -3389,9 +3400,7 @@ - (void) showGuessPanel: sender { - (void) _continuousSpellCheckWithInvalidatedRange: (NSRange) invalidatedRange { NSString *string = [self string]; NSUInteger start, end; - // TODO, truncate invalidated range to string size if needed - // round range to nearest paragraphs [string getParagraphStart: &start @@ -3433,10 +3442,8 @@ - (void) _continuousSpellCheckWithInvalidatedRange: (NSRange) invalidatedRange { } - (void) _continuousSpellCheck { - [self _continuousSpellCheckWithInvalidatedRange: NSMakeRange( - 0, - [[self string] - length])]; + NSRange invalidatedRange = NSMakeRange(0, [[self string] length]); + [self _continuousSpellCheckWithInvalidatedRange: invalidatedRange]; } - (void) checkSpelling: sender { @@ -3978,29 +3985,104 @@ - (NSTextLayoutOrientation) layoutOrientation { return _layoutOrientation; } -- (void)setLayoutOrientation:(NSTextLayoutOrientation)orientation { +- (void) setLayoutOrientation: (NSTextLayoutOrientation) orientation { _layoutOrientation = orientation; NSUnimplementedMethod(); } +- (BOOL) isIncrementalSearchingEnabled { + NSUnimplementedMethod(); + return _incrementalSearchingEnabled; +} + - (BOOL) usesFindBar { NSUnimplementedMethod(); return _usesFindBar; } +- (BOOL) usesInspectorBar { + NSUnimplementedMethod(); + return _usesInspectorBar; +} + +- (void) setIncrementalSearchingEnabled: (BOOL) value { + NSUnimplementedMethod(); + _incrementalSearchingEnabled = value; +} + - (void) setUsesFindBar: (BOOL) value { NSUnimplementedMethod(); _usesFindBar = value; } -- (BOOL) isIncrementalSearchingEnabled { +- (void) setUsesInspectorBar: (BOOL) value { NSUnimplementedMethod(); - return _incrementalSearchingEnabled; + _usesInspectorBar = value; } -- (void) setIncrementalSearchingEnabled: (BOOL) value { +- (BOOL) isGrammarCheckingEnabled { + NSUnimplementedMethod(); + return _grammarCheckingEnabled; +} + +- (BOOL) isAutomaticQuoteSubstitutionEnabled { + NSUnimplementedMethod(); + return _automaticQuoteSubstitutionEnabled; +} + +- (BOOL) isAutomaticDashSubstitutionEnabled { + NSUnimplementedMethod(); + return _automaticDashSubstitutionEnabled; +} + +- (BOOL) isAutomaticLinkDetectionEnabled { + NSUnimplementedMethod(); + return _automaticLinkDetectionEnabled; +} + +- (BOOL) isAutomaticDataDetectionEnabled { + NSUnimplementedMethod(); + return _automaticDataDetectionEnabled; +} + +- (BOOL) isAutomaticTextReplacementEnabled { + NSUnimplementedMethod(); + return _automaticTextReplacementEnabled; +} + +- (void) setGrammarCheckingEnabled: (BOOL) value { + NSUnimplementedMethod(); + _grammarCheckingEnabled = value; +} + +- (void) setAutomaticQuoteSubstitutionEnabled: (BOOL) value { + NSUnimplementedMethod(); + _automaticQuoteSubstitutionEnabled = value; +} + +- (void) setAutomaticDashSubstitutionEnabled: (BOOL) value { + NSUnimplementedMethod(); + _automaticDashSubstitutionEnabled = value; +} + +- (void) setAutomaticLinkDetectionEnabled: (BOOL) value { + NSUnimplementedMethod(); + _automaticLinkDetectionEnabled = value; +} + +- (void) setAutomaticDataDetectionEnabled: (BOOL) value { + NSUnimplementedMethod(); + _automaticDataDetectionEnabled = value; +} + +- (void) setAutomaticTextReplacementEnabled: (BOOL) value { + NSUnimplementedMethod(); + _automaticTextReplacementEnabled = value; +} + +// Is defined in NSText but throws an NSInvalidAbstractInvocation Exception +- (void) setImportsGraphics: (BOOL) value { NSUnimplementedMethod(); - _incrementalSearchingEnabled = value; } @end diff --git a/AppKit/include/AppKit/NSTextView.h b/AppKit/include/AppKit/NSTextView.h index 3743b3b843..58e92d34ac 100644 --- a/AppKit/include/AppKit/NSTextView.h +++ b/AppKit/include/AppKit/NSTextView.h @@ -139,12 +139,22 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; NSTextLayoutOrientation _layoutOrientation; BOOL _incrementalSearchingEnabled; + BOOL _grammarCheckingEnabled; + BOOL _automaticQuoteSubstitutionEnabled; + BOOL _automaticDashSubstitutionEnabled; + BOOL _automaticLinkDetectionEnabled; + BOOL _automaticDataDetectionEnabled; + BOOL _automaticTextReplacementEnabled; + + BOOL _usesInspectorBar; } - initWithFrame: (NSRect) frame textContainer: (NSTextContainer *) container; - initWithFrame: (NSRect) frame; +- (void) _setTextStorage: (NSTextStorage *) storage; + - (NSTextContainer *) textContainer; - (NSSize) textContainerInset; @@ -266,13 +276,28 @@ APPKIT_EXPORT NSString *const NSAllRomanInputSourcesLocaleIdentifier; - (void) setSpellingState: (NSInteger) value range: (NSRange) characterRange; -- (BOOL) usesFindBar; -- (void) setUsesFindBar: (BOOL) value; - (BOOL) isIncrementalSearchingEnabled; +- (BOOL) usesFindBar; +- (BOOL) usesInspectorBar; - (void) setIncrementalSearchingEnabled: (BOOL) value; +- (void) setUsesFindBar: (BOOL) value; +- (void) setUsesInspectorBar: (BOOL) value; - (void) setLayoutOrientation:(NSTextLayoutOrientation)orientation; +- (BOOL) isGrammarCheckingEnabled; +- (BOOL) isAutomaticQuoteSubstitutionEnabled; +- (BOOL) isAutomaticDashSubstitutionEnabled; +- (BOOL) isAutomaticLinkDetectionEnabled; +- (BOOL) isAutomaticDataDetectionEnabled; +- (BOOL) isAutomaticTextReplacementEnabled; +- (void) setGrammarCheckingEnabled: (BOOL) value; +- (void) setAutomaticQuoteSubstitutionEnabled: (BOOL) value; +- (void) setAutomaticDashSubstitutionEnabled: (BOOL) value; +- (void) setAutomaticLinkDetectionEnabled: (BOOL) value; +- (void) setAutomaticDataDetectionEnabled: (BOOL) value; +- (void) setAutomaticTextReplacementEnabled: (BOOL) value; + @end @interface NSObject (NSTextView_undoManager) From e086fe9f333583306822ef41999b071dca165733 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:47:30 -0400 Subject: [PATCH 05/20] Add document format inference in NSAttributedString Adds code in `initWithData` to infer document format for RTF, HTML, and plaintext documents. Additionally refactors NSAttributedString to use the correct attribute types as described in Apple's documentation. --- AppKit/NSAttributedString.m | 245 +++++++++++---------- AppKit/include/AppKit/NSAttributedString.h | 199 +++++++++-------- 2 files changed, 237 insertions(+), 207 deletions(-) diff --git a/AppKit/NSAttributedString.m b/AppKit/NSAttributedString.m index 15052f2b83..68bffa5735 100644 --- a/AppKit/NSAttributedString.m +++ b/AppKit/NSAttributedString.m @@ -27,110 +27,95 @@ this software and associated documentation files (the "Software"), to deal in #import #import -NSString *const NSFontAttributeName = @"NSFontAttributeName"; -NSString *const NSParagraphStyleAttributeName = - @"NSParagraphStyleAttributeName"; -NSString *const NSForegroundColorAttributeName = - @"NSForegroundColorAttributeName"; -NSString *const NSBackgroundColorAttributeName = - @"NSBackgroundColorAttributeName"; -NSString *const NSUnderlineStyleAttributeName = - @"NSUnderlineStyleAttributeName"; -NSString *const NSUnderlineColorAttributeName = - @"NSUnderlineColorAttributeName"; -NSString *const NSAttachmentAttributeName = @"NSAttachmentAttributeName"; -NSString *const NSKernAttributeName = @"NSKernAttributeName"; -NSString *const NSLigatureAttributeName = @"NSLigatureAttributeName"; -NSString *const NSStrikethroughStyleAttributeName = - @"NSStrikethroughStyleAttributeName"; -NSString *const NSStrikethroughColorAttributeName = - @"NSStrikethroughColorAttributeName"; -NSString *const NSObliquenessAttributeName = @"NSObliquenessAttributeName"; -NSString *const NSStrokeWidthAttributeName = @"NSStrokeWidthAttributeName"; -NSString *const NSStrokeColorAttributeName = @"NSStrokeColorAttributeName"; -NSString *const NSBaselineOffsetAttributeName = - @"NSBaselineOffsetAttributeName"; -NSString *const NSSuperscriptAttributeName = @"NSSuperscriptAttributeName"; -NSString *const NSLinkAttributeName = @"NSLinkAttributeName"; -NSString *const NSShadowAttributeName = @"NSShadowAttributeName"; -NSString *const NSExpansionAttributeName = @"NSExpansionAttributeName"; -NSString *const NSCursorAttributeName = @"NSCursorAttributeName"; -NSString *const NSToolTipAttributeName = @"NSToolTipAttributeName"; -NSString *const NSSpellingStateAttributeName = - @"NSSpellingStateAttributeName"; // temporary attribute - -NSString *const NSDocumentTypeDocumentAttribute = @"DocumentType"; -NSString *const NSConvertedDocumentAttribute = @"Converted"; -NSString *const NSFileTypeDocumentAttribute = @"UTI"; -NSString *const NSTitleDocumentAttribute = @"NSTitleDocumentAttribute"; -NSString *const NSCompanyDocumentAttribute = @"NSCompanyDocumentAttribute"; -NSString *const NSCopyrightDocumentAttribute = @"NSCopyrightDocumentAttribute"; -NSString *const NSSubjectDocumentAttribute = @"NSSubjectDocumentAttribute"; -NSString *const NSAuthorDocumentAttribute = @"NSAuthorDocumentAttribute"; -NSString *const NSKeywordsDocumentAttribute = @"NSKeywordsDocumentAttribute"; -NSString *const NSCommentDocumentAttribute = @"NSCommentDocumentAttribute"; -NSString *const NSEditorDocumentAttribute = @"NSEditorDocumentAttribute"; -NSString *const NSCreationTimeDocumentAttribute = - @"NSCreationTimeDocumentAttribute"; -NSString *const NSModificationTimeDocumentAttribute = - @"NSModificationTimeDocumentAttribute"; -NSString *const NSManagerDocumentAttribute = @"NSManagerDocumentAttribute"; -NSString *const NSCategoryDocumentAttribute = @"NSCategoryDocumentAttribute"; -NSString *const NSAppearanceDocumentAttribute = - @"NSAppearanceDocumentAttribute"; -NSString *const NSCharacterEncodingDocumentAttribute = @"CharacterEncoding"; -NSString *const NSDefaultAttributesDocumentAttribute = @"DefaultAttributes"; -NSString *const NSPaperSizeDocumentAttribute = @"PaperSize"; -NSString *const NSLeftMarginDocumentAttribute = @"LeftMargin"; -NSString *const NSRightMarginDocumentAttribute = @"RightMargin"; -NSString *const NSTopMarginDocumentAttribute = @"TopMargin"; -NSString *const NSBottomMarginDocumentAttribute = @"BottomMargin"; -NSString *const NSViewSizeDocumentAttribute = @"ViewSize"; -NSString *const NSViewZoomDocumentAttribute = @"ViewZoom"; -NSString *const NSViewModeDocumentAttribute = @"ViewMode"; -NSString *const NSReadOnlyDocumentAttribute = @"ReadOnly"; -NSString *const NSBackgroundColorDocumentAttribute = @"BackgroundColor"; -NSString *const NSHyphenationFactorDocumentAttribute = @"HyphenationFactor"; -NSString *const NSDefaultTabIntervalDocumentAttribute = @"DefaultTabInterval"; -NSString *const NSTextLayoutSectionsAttribute = - @"NSTextLayoutSectionsAttribute"; -NSString *const NSExcludedElementsDocumentAttribute = @"ExcludedElements"; -NSString *const NSTextEncodingNameDocumentAttribute = @"TextEncodingName"; -NSString *const NSPrefixSpacesDocumentAttribute = @"PrefixSpaces"; - -NSString *const NSDocumentTypeDocumentOption = @"DocumentType"; -NSString *const NSDefaultAttributesDocumentOption = @"DefaultAttributes"; -NSString *const NSCharacterEncodingDocumentOption = @"CharacterEncoding"; -NSString *const NSTextEncodingNameDocumentOption = @"TextEncodingName"; -NSString *const NSBaseURLDocumentOption = @"BaseURL"; -NSString *const NSTimeoutDocumentOption = @"Timeout"; -NSString *const NSWebPreferencesDocumentOption = @"WebPreferences"; -NSString *const NSWebResourceLoadDelegateDocumentOption = - @"WebResourceLoadDelegate"; -NSString *const NSTextSizeMultiplierDocumentOption = @"TextSizeMultiplier"; -NSString *const NSFileTypeDocumentOption = @"UTI"; - -NSString *const NSPlainTextDocumentType = @"NSPlainText"; -NSString *const NSRTFTextDocumentType = @"NSRTF"; -NSString *const NSRTFDTextDocumentType = @"NSRTFD"; -NSString *const NSHTMLTextDocumentType = @"NSHTML"; -NSString *const NSMacSimpleTextDocumentType = @"NSMacSimpleText"; -NSString *const NSDocFormatTextDocumentType = @"NSDocFormat"; -NSString *const NSWordMLTextDocumentType = @"NSWordML"; -NSString *const NSWebArchiveTextDocumentType = @"NSWebArchive"; -NSString *const NSOfficeOpenXMLTextDocumentType = @"NSOfficeOpenXML"; -NSString *const NSOpenDocumentTextDocumentType = @"NSOpenDocument"; - -NSString *const NSTextLayoutSectionOrientation = - @"NSTextLayoutSectionOrientation"; -NSString *const NSTextLayoutSectionRange = @"NSTextLayoutSectionRange"; - -NSString *const NSCharacterShapeAttributeName = @"NSCharacterShape"; -NSString *const NSUsesScreenFontsDocumentAttribute = @"UsesScreenFonts"; - -NSString *const NSTextEffectAttributeName = @"NSTextEffect"; +NSAttributedStringKey NSFontAttributeName = @"NSFontAttributeName"; +NSAttributedStringKey NSParagraphStyleAttributeName = @"NSParagraphStyleAttributeName"; +NSAttributedStringKey NSForegroundColorAttributeName = @"NSForegroundColorAttributeName"; +NSAttributedStringKey NSBackgroundColorAttributeName = @"NSBackgroundColorAttributeName"; +NSAttributedStringKey NSUnderlineStyleAttributeName = @"NSUnderlineStyleAttributeName"; +NSAttributedStringKey NSUnderlineColorAttributeName = @"NSUnderlineColorAttributeName"; +NSAttributedStringKey NSAttachmentAttributeName = @"NSAttachmentAttributeName"; +NSAttributedStringKey NSKernAttributeName = @"NSKernAttributeName"; +NSAttributedStringKey NSLigatureAttributeName = @"NSLigatureAttributeName"; +NSAttributedStringKey NSStrikethroughStyleAttributeName = @"NSStrikethroughStyleAttributeName"; +NSAttributedStringKey NSStrikethroughColorAttributeName = @"NSStrikethroughColorAttributeName"; +NSAttributedStringKey NSObliquenessAttributeName = @"NSObliquenessAttributeName"; +NSAttributedStringKey NSStrokeWidthAttributeName = @"NSStrokeWidthAttributeName"; +NSAttributedStringKey NSStrokeColorAttributeName = @"NSStrokeColorAttributeName"; +NSAttributedStringKey NSBaselineOffsetAttributeName = @"NSBaselineOffsetAttributeName"; +NSAttributedStringKey NSSuperscriptAttributeName = @"NSSuperscriptAttributeName"; +NSAttributedStringKey NSLinkAttributeName = @"NSLinkAttributeName"; +NSAttributedStringKey NSShadowAttributeName = @"NSShadowAttributeName"; +NSAttributedStringKey NSExpansionAttributeName = @"NSExpansionAttributeName"; +NSAttributedStringKey NSCursorAttributeName = @"NSCursorAttributeName"; +NSAttributedStringKey NSToolTipAttributeName = @"NSToolTipAttributeName"; +NSAttributedStringKey NSSpellingStateAttributeName = @"NSSpellingStateAttributeName"; // temporary attribute + +NSAttributedStringDocumentAttributeKey NSDocumentTypeDocumentAttribute = @"DocumentType"; +NSAttributedStringDocumentAttributeKey NSConvertedDocumentAttribute = @"Converted"; +NSAttributedStringDocumentAttributeKey NSFileTypeDocumentAttribute = @"UTI"; +NSAttributedStringDocumentAttributeKey NSTitleDocumentAttribute = @"NSTitleDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCompanyDocumentAttribute = @"NSCompanyDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCopyrightDocumentAttribute = @"NSCopyrightDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSSubjectDocumentAttribute = @"NSSubjectDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSAuthorDocumentAttribute = @"NSAuthorDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSKeywordsDocumentAttribute = @"NSKeywordsDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCommentDocumentAttribute = @"NSCommentDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSEditorDocumentAttribute = @"NSEditorDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCreationTimeDocumentAttribute = @"NSCreationTimeDocumentAttribute"; +NSAttributedStringKey NSModificationTimeDocumentAttribute = @"NSModificationTimeDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSManagerDocumentAttribute = @"NSManagerDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCategoryDocumentAttribute = @"NSCategoryDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSAppearanceDocumentAttribute = @"NSAppearanceDocumentAttribute"; +NSAttributedStringDocumentAttributeKey NSCharacterEncodingDocumentAttribute = @"CharacterEncoding"; +NSAttributedStringDocumentAttributeKey NSDefaultAttributesDocumentAttribute = @"DefaultAttributes"; +NSAttributedStringDocumentAttributeKey NSPaperSizeDocumentAttribute = @"PaperSize"; +NSAttributedStringDocumentAttributeKey NSLeftMarginDocumentAttribute = @"LeftMargin"; +NSAttributedStringDocumentAttributeKey NSRightMarginDocumentAttribute = @"RightMargin"; +NSAttributedStringDocumentAttributeKey NSTopMarginDocumentAttribute = @"TopMargin"; +NSAttributedStringDocumentAttributeKey NSBottomMarginDocumentAttribute = @"BottomMargin"; +NSAttributedStringDocumentAttributeKey NSViewSizeDocumentAttribute = @"ViewSize"; +NSAttributedStringDocumentAttributeKey NSViewZoomDocumentAttribute = @"ViewZoom"; +NSAttributedStringDocumentAttributeKey NSViewModeDocumentAttribute = @"ViewMode"; +NSAttributedStringDocumentAttributeKey NSReadOnlyDocumentAttribute = @"ReadOnly"; +NSAttributedStringDocumentAttributeKey NSBackgroundColorDocumentAttribute = @"BackgroundColor"; +NSAttributedStringDocumentAttributeKey NSHyphenationFactorDocumentAttribute = @"HyphenationFactor"; +NSAttributedStringDocumentAttributeKey NSDefaultTabIntervalDocumentAttribute = @"DefaultTabInterval"; +NSAttributedStringDocumentAttributeKey NSTextLayoutSectionsAttribute = @"NSTextLayoutSectionsAttribute"; +NSAttributedStringDocumentAttributeKey NSExcludedElementsDocumentAttribute = @"ExcludedElements"; +NSAttributedStringDocumentAttributeKey NSTextEncodingNameDocumentAttribute = @"TextEncodingName"; +NSAttributedStringDocumentAttributeKey NSPrefixSpacesDocumentAttribute = @"PrefixSpaces"; +NSAttributedStringDocumentAttributeKey NSCocoaVersionDocumentAttribute = @"NSCocoaVersionDocumentAttribute"; + +NSAttributedStringDocumentReadingOptionKey NSDocumentTypeDocumentOption = @"DocumentType"; +NSAttributedStringDocumentReadingOptionKey NSDefaultAttributesDocumentOption = @"DefaultAttributes"; +NSAttributedStringDocumentReadingOptionKey NSCharacterEncodingDocumentOption = @"CharacterEncoding"; +NSAttributedStringDocumentReadingOptionKey NSTextEncodingNameDocumentOption = @"TextEncodingName"; +NSAttributedStringDocumentReadingOptionKey NSBaseURLDocumentOption = @"BaseURL"; +NSAttributedStringDocumentReadingOptionKey NSTimeoutDocumentOption = @"Timeout"; +NSAttributedStringDocumentReadingOptionKey NSWebPreferencesDocumentOption = @"WebPreferences"; +NSAttributedStringDocumentReadingOptionKey NSWebResourceLoadDelegateDocumentOption = @"WebResourceLoadDelegate"; +NSAttributedStringDocumentReadingOptionKey NSTextSizeMultiplierDocumentOption = @"TextSizeMultiplier"; +NSAttributedStringDocumentReadingOptionKey NSFileTypeDocumentOption = @"UTI"; + +NSAttributedStringDocumentType NSPlainTextDocumentType = @"NSPlainText"; +NSAttributedStringDocumentType NSRTFTextDocumentType = @"NSRTF"; +NSAttributedStringDocumentType NSRTFDTextDocumentType = @"NSRTFD"; +NSAttributedStringDocumentType NSHTMLTextDocumentType = @"NSHTML"; +NSAttributedStringDocumentType NSMacSimpleTextDocumentType = @"NSMacSimpleText"; +NSAttributedStringDocumentType NSDocFormatTextDocumentType = @"NSDocFormat"; +NSAttributedStringDocumentType NSWordMLTextDocumentType = @"NSWordML"; +NSAttributedStringDocumentType NSWebArchiveTextDocumentType = @"NSWebArchive"; +NSAttributedStringDocumentType NSOfficeOpenXMLTextDocumentType = @"NSOfficeOpenXML"; +NSAttributedStringDocumentType NSOpenDocumentTextDocumentType = @"NSOpenDocument"; + +NSTextLayoutSectionKey NSTextLayoutSectionOrientation = @"NSTextLayoutSectionOrientation"; +NSTextLayoutSectionKey NSTextLayoutSectionRange = @"NSTextLayoutSectionRange"; + +NSAttributedStringKey NSCharacterShapeAttributeName = @"NSCharacterShape"; +NSAttributedStringKey NSUsesScreenFontsDocumentAttribute = @"UsesScreenFonts"; + +const NSAttributedStringKey NSTextEffectAttributeName = @"NSTextEffect"; NSAttributedStringKey NSWritingDirectionAttributeName = @"NSWritingDirectionAttribute"; -NSString *const NSCocoaVersionDocumentAttribute = @"NSCocoaVersionDocumentAttribute"; NSUInteger NSUnderlineStrikethroughMask = 0x4000; NSUInteger NSUnderlineByWordMask = 0x8000; @@ -159,15 +144,48 @@ + (NSAttributedString *) attributedStringWithAttachment: error: (NSError **) error { NSUnimplementedMethod(); - NSString *docType = [options objectForKey:@"NSDocumentTypeDocumentAttribute"]; - + NSString *docType = [options objectForKey:NSDocumentTypeDocumentAttribute]; + + //Infer the document format if not provided if(docType == nil){ - NSLog(@"NSAttributedString initFromData - inferring document type"); - //TODO: infer document type (assume RTF for now) - docType = NSRTFTextDocumentType; + //Extract a prefix from the document to identify the type + //FIXME: use 64 bit ready types and check encoding + char prefix[14]; + NSUInteger dataLength = [data length]; + + if(dataLength < sizeof(prefix)) + { + [data getBytes: prefix length: dataLength]; + prefix[dataLength] = 0; + } + else + { + [data getBytes: prefix length: sizeof(prefix)]; + } + + //Use the prefix to determine the document format + // FIXME extend the list + if (strncmp(prefix, "{\\rtf", 5) == 0) + { + docType = NSRTFTextDocumentType; + } + else if (strncasecmp(prefix, " Date: Fri, 21 Apr 2023 11:58:46 -0400 Subject: [PATCH 06/20] Align `documentClassForType:` implementation with Apple's developer documentation --- AppKit/NSDocumentController.m | 90 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/AppKit/NSDocumentController.m b/AppKit/NSDocumentController.m index 90532bbfe5..297e9279e9 100644 --- a/AppKit/NSDocumentController.m +++ b/AppKit/NSDocumentController.m @@ -31,45 +31,48 @@ this software and associated documentation files (the "Software"), to deal in @interface _NSUnsupportedDocument : NSObject - (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; +- (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 - (instancetype) initWithType: (NSString *) type error: (NSError **) error { - *error = [NSError errorWithDomain:NSCocoaErrorDomain - code: NSFeatureUnsupportedError + *error = [NSError errorWithDomain: NSCocoaErrorDomain + code: NSFeatureUnsupportedError userInfo: nil]; [self release]; return nil; } -- (instancetype) initWithContentsOfURL:(NSURL *)url - ofType:(NSString *)typeName - error:(NSError * _Nullable *)outError{ - - *outError = [NSError errorWithDomain:NSCocoaErrorDomain - code: NSFeatureUnsupportedError - userInfo: 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{ +- (id) initWithContentsOfURL: (NSURL *) url ofType: (NSString *) typeName { [self release]; return nil; } -- (id) initWithContentsOfFile:(NSString *)absolutePath - ofType:(NSString *)typeName{ +- (id) initWithContentsOfFile: (NSString *) absolutePath + ofType: (NSString *) typeName +{ [self release]; return nil; } @@ -175,13 +178,15 @@ - (NSString *) displayNameForType: (NSString *) type { - (Class) documentClassForType: (NSString *) type { NSString *result = nil; - for(NSDictionary *fileType in _fileTypes){ - if ([[fileType objectForKey: @"LSItemContentTypes"] containsObject: type]) + for (NSDictionary *fileType in _fileTypes) { + if ([type isEqualToString: [fileType objectForKey: @"CFBundleTypeName"]]) { result = [fileType objectForKey: @"NSDocumentClass"]; + break; + } } - NSLog(@"NSDocController - docClassForType found class %@ for type %@", result, type); - return (result == nil) ? [_NSUnsupportedDocument class] : NSClassFromString(result); + return (result == nil) ? [_NSUnsupportedDocument class] + : NSClassFromString(result); } - (NSArray *) fileExtensionsFromType: (NSString *) type { @@ -207,7 +212,7 @@ - (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"]; @@ -298,16 +303,16 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error { NSString *UTI; - BOOL success = [url getResourceValue:&UTI forKey:NSURLTypeIdentifierKey error:error]; - if(success){ - NSLog(@"NSDocumentController - found type: %@", UTI); - return UTI; - //TODO: move below code to documentClassForType - for(NSDictionary *type in _fileTypes){ - for(NSString *contentType in [type objectForKey:@"LSItemContentTypes"]){ - if([contentType isEqual: UTI]) - return [type objectForKey:@"CFBundleTypeName"]; - } + 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; @@ -332,7 +337,6 @@ - (NSString *) typeForContentsOfURL: (NSURL *) url error: (NSError **) error { result = [[[class alloc] initWithContentsOfURL: url ofType: type] autorelease]; - return result; } @@ -480,18 +484,20 @@ - (id) makeUntitledDocumentOfType: (NSString *) type NSDocument *result = [self documentForURL: url]; if (result == nil) { - NSError *type_error; - NSString *type = [self typeForContentsOfURL:url error:&type_error]; - - if(type_error != nil){ - *error = type_error; + 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]; - NSLog(@"NSDocCtrl openDocWithContsURL - made Document"); if (result != nil) { [self addDocument: result]; [result makeWindowControllers]; From 7fcfc33365754e60ea82aac2a9a66e201146ebed Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:59:13 -0400 Subject: [PATCH 07/20] Implement `readFromURL:` in NSMutableAttributedString --- AppKit/NSMutableAttributedString.m | 26 ++++++++++++------- AppKit/include/AppKit/NSAttributedString.h | 9 +++---- .../AppKit/NSMutableAttributedString.h | 16 ++++++------ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/AppKit/NSMutableAttributedString.m b/AppKit/NSMutableAttributedString.m index e680cfdfc1..4d4ae25cd1 100644 --- a/AppKit/NSMutableAttributedString.m +++ b/AppKit/NSMutableAttributedString.m @@ -203,14 +203,22 @@ - (void) applyFontTraits: (NSFontTraitMask) traits range: (NSRange) range { [self endEditing]; } -- (BOOL) readFromURL:(NSURL *)url - options:(NSDictionary *)opts - documentAttributes:(NSDictionary * _Nullable *)dict - error:(NSError * _Nullable *)error { - NSAttributedString *str = [NSAttributedString alloc]; - [str initWithURL:url options:opts documentAttributes:dict error:error]; - //[self setAttributedString:str]; - NSLog(@"NSMutableAttributedString readFromURL: - hopefully finished reading!"); - return true; +- (BOOL) readFromURL: (NSURL *) url + options: (NSDictionary *) opts + documentAttributes: (NSDictionary *_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 diff --git a/AppKit/include/AppKit/NSAttributedString.h b/AppKit/include/AppKit/NSAttributedString.h index 5876f205f2..bad341c486 100644 --- a/AppKit/include/AppKit/NSAttributedString.h +++ b/AppKit/include/AppKit/NSAttributedString.h @@ -258,11 +258,10 @@ enum { #pragma mark - #pragma mark Getting Attribute Data -- (void) enumerateAttribute: (NSAttributedStringKey) attrName - inRange: (NSRange) enumerationRange - options: (NSAttributedStringEnumerationOptions) opts - usingBlock: - (void (^)(id value, NSRange range, BOOL *stop)) block; +- (void)enumerateAttribute: (NSAttributedStringKey) attrName + inRange: (NSRange) enumerationRange + options: (NSAttributedStringEnumerationOptions) opts + usingBlock: (void (^)(id value, NSRange range, BOOL *stop)) block; #pragma mark - #pragma mark Testing String Data Sources diff --git a/AppKit/include/AppKit/NSMutableAttributedString.h b/AppKit/include/AppKit/NSMutableAttributedString.h index dd4e85384f..cab1673ed0 100644 --- a/AppKit/include/AppKit/NSMutableAttributedString.h +++ b/AppKit/include/AppKit/NSMutableAttributedString.h @@ -26,13 +26,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - (void) fixAttributesInRange: (NSRange) range; - (void) applyFontTraits: (NSFontTraitMask) traits range: (NSRange) range; -- (BOOL) readFromURL:(NSURL *)url - options:(NSDictionary *)opts - documentAttributes:(NSDictionary * _Nullable *)dict - error:(NSError * _Nullable *)error; - -- (void)addAttribute:(NSAttributedStringKey)name - value:(id)value - range:(NSRange)range; +- (BOOL) readFromURL: (NSURL *) url + options: (NSDictionary *) opts + documentAttributes: (NSDictionary * _Nullable *) dict + error: (NSError * _Nullable *)error; + +- (void)addAttribute: (NSAttributedStringKey) name + value: (id) value + range: (NSRange) range; @end From a4bc3feb1164479d8d05c9139fdf076fe3b90d58 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:00:59 -0400 Subject: [PATCH 08/20] Add framework for size and magnification methods Add stubs for content size, frame size, and magnification size, and add basic implementations where feasible. --- AppKit/NSScrollView.m | 48 ++++++++++++++++++---------- AppKit/include/AppKit/NSScrollView.h | 26 +++++++-------- AppKit/include/AppKit/NSScroller.h | 2 +- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index 3b8c62b79b..bab4a40e13 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -86,14 +86,18 @@ + (NSSize) frameSizeForContentSize: (NSSize) contentSize return contentSize; } -+ (NSSize)frameSizeForContentSize:(NSSize)cSize - horizontalScrollerClass:(Class)horizontalScrollerClass - verticalScrollerClass:(Class)verticalScrollerClass - borderType:(NSBorderType)type - controlSize:(NSControlSize)controlSize - scrollerStyle:(NSScrollerStyle)scrollerStyle ++ (NSSize) frameSizeForContentSize: (NSSize) cSize + horizontalScrollerClass: (Class) horizontalScrollerClass + verticalScrollerClass: (Class) verticalScrollerClass + borderType: (NSBorderType) type + controlSize: (NSControlSize) controlSize + scrollerStyle: (NSScrollerStyle) scrollerStyle { NSUnimplementedMethod(); + return [self frameSizeForContentSize: cSize + hasHorizontalScroller: YES + hasVerticalScroller: YES + borderType: type]; } + (NSSize) contentSizeForFrameSize: (NSSize) frameSize @@ -130,12 +134,12 @@ + (NSSize) contentSizeForFrameSize: (NSSize) frameSize return frameSize; } -+ (NSSize)contentSizeForFrameSize:(NSSize)fSize - horizontalScrollerClass:(Class)horizontalScrollerClass - verticalScrollerClass:(Class)verticalScrollerClass - borderType:(NSBorderType)type - controlSize:(NSControlSize)controlSize - scrollerStyle:(NSScrollerStyle)scrollerStyle ++ (NSSize) contentSizeForFrameSize: (NSSize) fSize + horizontalScrollerClass: (Class) horizontalScrollerClass + verticalScrollerClass: (Class) verticalScrollerClass + borderType: (NSBorderType) type + controlSize: (NSControlSize) controlSize + scrollerStyle: (NSScrollerStyle) scrollerStyle { NSUnimplementedMethod(); } @@ -816,23 +820,35 @@ - (void) setAutohidesScrollers: (BOOL) value { } - (void) setMagnification: (CGFloat) value { + if (value == _magnification) + return; + _magnification = value; - NSUnimplementedMethod(); + + if (_magnification < _minMagnification) + _magnification = _minMagnification; + if (_magnification < _maxMagnification) + _magnification = _maxMagnification; + + // TODO: calculate new bounds and call setBounds } - (void) setMinMagnification: (CGFloat) value { _minMagnification = value; - NSUnimplementedMethod(); + + if (_minMagnification > _magnification) + [self setMagnification: value]; } - (void) setMaxMagnification: (CGFloat) value { _maxMagnification = value; - NSUnimplementedMethod(); + + if (_maxMagnification < _magnification) + [self setMagnification: value]; } - (void) setAllowsMagnification: (BOOL) value { _allowsMagnification = value; - NSUnimplementedMethod(); } - (void) tile { diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index 32f8f73150..56dce211b8 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -62,22 +62,22 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; hasHorizontalScroller: (BOOL) hasHorizontalScroller hasVerticalScroller: (BOOL) hasVerticalScroller borderType: (NSBorderType) borderType; -+ (NSSize)frameSizeForContentSize:(NSSize)cSize - horizontalScrollerClass:(Class)horizontalScrollerClass - verticalScrollerClass:(Class)verticalScrollerClass - borderType:(NSBorderType)type - controlSize:(NSControlSize)controlSize - scrollerStyle:(NSScrollerStyle)scrollerStyle; ++ (NSSize)frameSizeForContentSize: (NSSize)cSize + horizontalScrollerClass: (Class)horizontalScrollerClass + verticalScrollerClass: (Class)verticalScrollerClass + borderType: (NSBorderType)type + controlSize: (NSControlSize)controlSize + scrollerStyle: (NSScrollerStyle)scrollerStyle; + (NSSize) contentSizeForFrameSize: (NSSize) fSize hasHorizontalScroller: (BOOL) hasHorizontalScroller hasVerticalScroller: (BOOL) hasVerticalScroller borderType: (NSBorderType) borderType; -+ (NSSize)contentSizeForFrameSize:(NSSize)fSize - horizontalScrollerClass:(Class)horizontalScrollerClass - verticalScrollerClass:(Class)verticalScrollerClass - borderType:(NSBorderType)type - controlSize:(NSControlSize)controlSize - scrollerStyle:(NSScrollerStyle)scrollerStyle; ++ (NSSize)contentSizeForFrameSize: (NSSize)fSize + horizontalScrollerClass: (Class)horizontalScrollerClass + verticalScrollerClass: (Class)verticalScrollerClass + borderType: (NSBorderType)type + controlSize: (NSControlSize)controlSize + scrollerStyle: (NSScrollerStyle)scrollerStyle; + (void) setRulerViewClass: (Class) aClass; + (Class) rulerViewClass; @@ -141,7 +141,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (void) setMagnification: (CGFloat) value; - (void) setMinMagnification: (CGFloat) value; - (void) setMaxMagnification: (CGFloat) value; -- (BOOL) setAllowsMagnification: (BOOL) value; +- (void) setAllowsMagnification: (BOOL) value; - (void) tile; - (void) reflectScrolledClipView: (NSClipView *) clipView; diff --git a/AppKit/include/AppKit/NSScroller.h b/AppKit/include/AppKit/NSScroller.h index b27d1f5423..5ffb10e829 100644 --- a/AppKit/include/AppKit/NSScroller.h +++ b/AppKit/include/AppKit/NSScroller.h @@ -86,7 +86,7 @@ typedef NSUInteger NSUsableScrollerParts; knobProportion: (CGFloat) zeroToOneKnob; - (void) setArrowsPosition: (NSScrollArrowPosition) position; - (void) setControlSize: (NSControlSize) value; -- (void) setScrollerStyle : (NSScrollerStyle) style; +- (void) setScrollerStyle: (NSScrollerStyle) style; - (NSRect) rectForPart: (NSScrollerPart) part; - (void) checkSpaceForParts; From b3c2e2dea3db91d65606959aab707332df89830e Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Thu, 27 Apr 2023 23:54:21 -0400 Subject: [PATCH 09/20] Implement NSParagraph TabStops properly Implement NSTextTab handling based on the GNUStep implementation, with formatting and other adjustments. --- AppKit/NSMutableParagraphStyle.m | 26 ++++++++++++++----- AppKit/NSParagraphStyle.m | 4 +-- AppKit/NSTextView.subproj/NSTextTab.m | 16 ++++++++++++ .../include/AppKit/NSMutableParagraphStyle.h | 4 +-- AppKit/include/AppKit/NSParagraphStyle.h | 4 +-- AppKit/include/AppKit/NSTextTab.h | 1 + 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/AppKit/NSMutableParagraphStyle.m b/AppKit/NSMutableParagraphStyle.m index 3fbe4b6560..48e092ad58 100644 --- a/AppKit/NSMutableParagraphStyle.m +++ b/AppKit/NSMutableParagraphStyle.m @@ -128,17 +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 { - //NSUnimplementedMethod(); +- (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 { - //NSUnimplementedMethod(); +- (void) removeTabStop: (NSTextTab *) tabStop { + [_tabStops removeObject: tabStop]; } - (void) setHyphenationFactor: (float) factor { diff --git a/AppKit/NSParagraphStyle.m b/AppKit/NSParagraphStyle.m index 0a10fadd6f..09d92da673 100644 --- a/AppKit/NSParagraphStyle.m +++ b/AppKit/NSParagraphStyle.m @@ -34,7 +34,7 @@ + (NSParagraphStyle *) defaultParagraphStyle { return shared; } -+ (NSWritingDirection)defaultWritingDirectionForLanguage:(NSString *)languageName { ++ (NSWritingDirection) defaultWritingDirectionForLanguage: (NSString *) languageName { NSUnimplementedMethod(); return NSWritingDirectionNatural; } @@ -74,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; } diff --git a/AppKit/NSTextView.subproj/NSTextTab.m b/AppKit/NSTextView.subproj/NSTextTab.m index 81722bbad8..d452db1c1a 100644 --- a/AppKit/NSTextView.subproj/NSTextTab.m +++ b/AppKit/NSTextView.subproj/NSTextTab.m @@ -136,4 +136,20 @@ - (BOOL) isEqual: (id) object { return self.location == other.location && self.tabStopType == other.tabStopType; } + +- (NSComparisonResult) compare: (id) anObject { + CGFloat loc; + + if (anObject == self) + return NSOrderedSame; + if (anObject == nil || ![anObject isKindOfClass: [self class]]) + return NSOrderedAscending; + loc = ((NSTextTab *) anObject)->_location; + if (_location < loc) + return NSOrderedAscending; + else if (_location > loc) + return NSOrderedDescending; + else + return NSOrderedSame; +} @end diff --git a/AppKit/include/AppKit/NSMutableParagraphStyle.h b/AppKit/include/AppKit/NSMutableParagraphStyle.h index 253d1e273a..bf719535c9 100644 --- a/AppKit/include/AppKit/NSMutableParagraphStyle.h +++ b/AppKit/include/AppKit/NSMutableParagraphStyle.h @@ -48,8 +48,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - (void) setDefaultTabInterval: (CGFloat) interval; - (void) setTabStops: (NSArray *) tabStops; -- (void) addTabStop:(NSTextTab *) tabStop; -- (void) removeTabStop:(NSTextTab *) tabStop; +- (void) addTabStop: (NSTextTab *) tabStop; +- (void) removeTabStop: (NSTextTab *) tabStop; - (void) setHyphenationFactor: (float) factor; diff --git a/AppKit/include/AppKit/NSParagraphStyle.h b/AppKit/include/AppKit/NSParagraphStyle.h index c3cec80486..13fd29741f 100644 --- a/AppKit/include/AppKit/NSParagraphStyle.h +++ b/AppKit/include/AppKit/NSParagraphStyle.h @@ -45,14 +45,14 @@ typedef enum { CGFloat _lineHeightMultiple; CGFloat _lineSpacing; CGFloat _defaultTabInterval; - NSArray *_tabStops; + NSMutableArray *_tabStops; float _hyphenationFactor; float _tighteningFactorForTruncation; } + (NSParagraphStyle *) defaultParagraphStyle; -+ (NSWritingDirection)defaultWritingDirectionForLanguage:(NSString *)languageName; ++ (NSWritingDirection)defaultWritingDirectionForLanguage: (NSString *)languageName; - (NSWritingDirection) baseWritingDirection; diff --git a/AppKit/include/AppKit/NSTextTab.h b/AppKit/include/AppKit/NSTextTab.h index f52b8da538..bb886e989d 100644 --- a/AppKit/include/AppKit/NSTextTab.h +++ b/AppKit/include/AppKit/NSTextTab.h @@ -49,4 +49,5 @@ APPKIT_EXPORT NSString *NSTabColumnTerminatorsAttributeName; - (CGFloat) location; +- (NSComparisonResult) compare: (id) anObject; @end From a72e58188ca0bffb3927fd4c3ac57b027b5b7c01 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Sat, 14 Oct 2023 11:51:10 -0400 Subject: [PATCH 10/20] Remove redundant declaration of `translatesAutoResizingMaskIntoConstraints` --- AppKit/NSTextView.subproj/NSTextView.m | 2 +- AppKit/NSView.m | 9 --------- AppKit/include/AppKit/NSView.h | 3 --- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/AppKit/NSTextView.subproj/NSTextView.m b/AppKit/NSTextView.subproj/NSTextView.m index 2ad8d1d8d7..f408843134 100644 --- a/AppKit/NSTextView.subproj/NSTextView.m +++ b/AppKit/NSTextView.subproj/NSTextView.m @@ -3979,7 +3979,7 @@ - (void) rulerView: (NSRulerView *) rulerView - (id) replacementObjectForKeyedArchiver { NSUnimplementedMethod(); return self; - +} - (NSTextLayoutOrientation) layoutOrientation { NSUnimplementedMethod(); return _layoutOrientation; diff --git a/AppKit/NSView.m b/AppKit/NSView.m index 9d2d3bc28a..b945e72514 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -887,10 +887,6 @@ - (NSString *) toolTip { return toolTip; } -- (BOOL) translatesAutoresizingMaskIntoConstraints { - return _translatesAutoresizingMaskIntoConstraints; -} - - viewWithTag: (NSInteger) tag { int i, count = [_subviews count]; @@ -1130,11 +1126,6 @@ - (void) setBoundsRotation: (CGFloat) angle { NSUnimplementedMethod(); } -- (void) settranslatesAutoresizingMaskIntoConstraints: (BOOL) value { - _translatesAutoresizingMaskIntoConstraints = value; - NSUnimplementedMethod(); -} - - (void) setPostsFrameChangedNotifications: (BOOL) flag { _postsNotificationOnFrameChange = flag; } diff --git a/AppKit/include/AppKit/NSView.h b/AppKit/include/AppKit/NSView.h index 1dba742b5e..20dbf5c67b 100644 --- a/AppKit/include/AppKit/NSView.h +++ b/AppKit/include/AppKit/NSView.h @@ -136,7 +136,6 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre NSLayoutPriority _verticalContentHuggingPriority; NSLayoutPriority _horizontalContentCompressionResistancePriority; NSLayoutPriority _verticalContentCompressionResistancePriority; - BOOL _translatesAutoresizingMaskIntoConstraints; } @property(class, readonly) BOOL requiresConstraintBasedLayout; @@ -205,7 +204,6 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre - (NSMenu *) menuForEvent: (NSEvent *) event; - (NSMenuItem *) enclosingMenuItem; - (NSString *) toolTip; -- (BOOL) translatesAutoresizingMaskIntoConstraints; - viewWithTag: (NSInteger) tag; - (NSView *) hitTest: (NSPoint) point; @@ -228,7 +226,6 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre - (void) setBoundsSize: (NSSize) size; - (void) setBoundsOrigin: (NSPoint) origin; - (void) setBoundsRotation: (CGFloat) angle; -- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL) value; - (CGFloat) frameRotation; - (CGFloat) boundsRotation; From d6c5c1c8b3d3da3fef87fec643a48c0201363538 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:18:24 -0500 Subject: [PATCH 11/20] Convert hexadecimal color values to CGFloat literals. --- AppKit/X11.backend/X11Display.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AppKit/X11.backend/X11Display.m b/AppKit/X11.backend/X11Display.m index dce249efc8..5f77ffa0dc 100644 --- a/AppKit/X11.backend/X11Display.m +++ b/AppKit/X11.backend/X11Display.m @@ -592,10 +592,10 @@ - (NSColor *) colorWithName: (NSString *) colorName { if ([colorName isEqual: @"windowFrameColor"]) return [NSColor lightGrayColor]; if ([colorName isEqual: @"selectedTextBackgroundColor"]) - return [NSColor colorWithCalibratedRed: 0x33 - green: 0x8f - blue: 0xff - alpha: 1.0f]; + return [NSColor colorWithCalibratedRed: 0.20f + green: 0.55f + blue: 1.00f + alpha: 1.00f]; NSLog(@"missing color for %@", colorName); return [NSColor redColor]; From bce2767698034ffdc5febdc0353f9d2647d195e2 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:14:34 -0500 Subject: [PATCH 12/20] Correct leak in internal NSTextView method. --- AppKit/NSTextView.subproj/NSTextView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/AppKit/NSTextView.subproj/NSTextView.m b/AppKit/NSTextView.subproj/NSTextView.m index f408843134..c66ad8c61f 100644 --- a/AppKit/NSTextView.subproj/NSTextView.m +++ b/AppKit/NSTextView.subproj/NSTextView.m @@ -164,6 +164,7 @@ - (void) _setTextStorage: (NSTextStorage *) storage { [_typingAttributes release]; _typingAttributes = typingAttributes; + [_defaultParagraphStyle release]; if ([typingAttributes objectForKey: NSParagraphStyleAttributeName]) { _defaultParagraphStyle = [[typingAttributes objectForKey: NSParagraphStyleAttributeName] copy]; From 317e0778fc1c5ab386cc1d000890248ae68e9b56 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:24:40 -0500 Subject: [PATCH 13/20] Align implementation of `documentClassForType:` with Apple's developer reference. --- AppKit/NSDocumentController.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AppKit/NSDocumentController.m b/AppKit/NSDocumentController.m index 297e9279e9..70a33ff032 100644 --- a/AppKit/NSDocumentController.m +++ b/AppKit/NSDocumentController.m @@ -185,8 +185,7 @@ - (Class) documentClassForType: (NSString *) type { } } - return (result == nil) ? [_NSUnsupportedDocument class] - : NSClassFromString(result); + return (result == nil) ? nil : NSClassFromString(result); } - (NSArray *) fileExtensionsFromType: (NSString *) type { From 1507165140855d6e2e48c923665a3db0ecf88ccb Mon Sep 17 00:00:00 2001 From: James Park Date: Tue, 6 Feb 2024 18:28:56 -0500 Subject: [PATCH 14/20] initial implementation of scaleUnitSquareToSize --- AppKit/NSView.m | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/AppKit/NSView.m b/AppKit/NSView.m index b945e72514..04752689c6 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -646,8 +646,45 @@ - (BOOL) postsBoundsChangedNotifications { return _postsNotificationOnBoundsChange; } +// todo after implementing this, i need to implement magnification support in nsscrollview - (void) scaleUnitSquareToSize: (NSSize) size { - NSUnimplementedMethod(); + if (size.width != 1.0 || size.height != 1.0) { + if (size.width < 0) { + size.width = 0; + } + if (size.height < 0) { + size.height = 0; + } + if (_bounds == nil) { + // todo set _bounds. would _bounds ever by nil? need to look into that + // _bounds = [NSAffineTransform new] + } + + // todo need to get scaleXBy in here, located in darling-foundation + [_bounds scaleXBy: size.width yBy: size.height]; + + _bounds.origin.x = _bounds.origin.x / size.width; + _bounds.origin.y = _bounds.origin.y / size.height; + _bounds.size.width = _bounds.size.width / size.width; + _bounds.size.height = _bounds.size.height / size.height; + + isRotatedOrScaledFromBase = YES; + + /* code from gnustep + todo flag should be located in appkit/include/nsview.h + + if (_coordinates_valid) + { + (*invalidateImp)(self, invalidateSel); + } + */ + [self resetCursorRects] + if (_postsNotificationOnBoundsChange) { + [[NSNotificationCenter defaultCenter] + postNotificationName: NSViewBoundsDidChangeNotification + object: self]; + } + } } - (NSWindow *) window { From a1e509eca39f4f0bfdddf072f45921c3178cf0c9 Mon Sep 17 00:00:00 2001 From: James Park Date: Fri, 9 Feb 2024 16:49:02 -0500 Subject: [PATCH 15/20] implemented boolean allowsMagnification --- .vscode/settings.json | 7 +++++++ AppKit/NSScrollView.m | 10 +++++++++- AppKit/include/AppKit/NSScrollView.h | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..9376941670 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.embeddedhtml": "html", + "type_traits": "cpp", + "xtr1common": "cpp" + } +} \ No newline at end of file diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index bab4a40e13..cbf7431184 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -189,6 +189,8 @@ - (void) encodeWithCoder: (NSCoder *) coder { _drawsBackground = [_clipView drawsBackground]; } + _allowsMagnification = NO; + _verticalLineScroll = 10.0; // the default value in IB is 10 _verticalPageScroll = 10.0; _horizontalLineScroll = 10.0; @@ -422,6 +424,7 @@ - (void) createHorizontalScrollerIfNeeded { _drawsBackground = YES; _borderType = NSNoBorder; _backgroundColor = [[NSColor controlBackgroundColor] copy]; + _allowsMagnification = NO; [self setLineScroll: 1.0]; [self setPageScroll: 10.0]; // entirely arbitrary @@ -652,7 +655,7 @@ - (CGFloat) maxMagnification { - (BOOL) allowsMagnification { return _allowsMagnification; -} +}; - (void) setDocumentView: (NSView *) view { [_clipView setDocumentView: view]; @@ -819,6 +822,7 @@ - (void) setAutohidesScrollers: (BOOL) value { // FIXME: tile or hide/show scrollers? } +<<<<<<< HEAD - (void) setMagnification: (CGFloat) value { if (value == _magnification) return; @@ -848,6 +852,9 @@ - (void) setMaxMagnification: (CGFloat) value { } - (void) setAllowsMagnification: (BOOL) value { +======= +- (void) allowsMagnification: (BOOL) value { +>>>>>>> e9908511 (implemented boolean allowsMagnification) _allowsMagnification = value; } @@ -1077,4 +1084,5 @@ - (void) resizeSubviewsWithOldSize: (NSSize) oldSize { [self _horizontalScroll: _horizontalScroller]; } + @end diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index 56dce211b8..ccfe5d23ae 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -51,6 +51,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; BOOL _rulersVisible; BOOL _scrollsDynamically; BOOL _autohidesScrollers; + BOOL _allowsMagnification; NSCursor *_documentCursor; BOOL _allowsMagnification; CGFloat _magnification; @@ -110,6 +111,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (CGFloat) pageScroll; - (BOOL) scrollsDynamically; - (BOOL) autohidesScrollers; +- (BOOL) allowsMagnification; - (NSCursor *) documentCursor; - (CGFloat) magnification; From 44a657498dde7618c9883020947374f79875b3da Mon Sep 17 00:00:00 2001 From: James Park Date: Fri, 9 Feb 2024 16:56:28 -0500 Subject: [PATCH 16/20] implemented cgfloat magnification --- AppKit/NSScrollView.m | 14 ++++++++++---- AppKit/include/AppKit/NSScrollView.h | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index cbf7431184..97ed88a407 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -190,6 +190,7 @@ - (void) encodeWithCoder: (NSCoder *) coder { } _allowsMagnification = NO; + _magnification = 1.0; _verticalLineScroll = 10.0; // the default value in IB is 10 _verticalPageScroll = 10.0; @@ -425,6 +426,7 @@ - (void) createHorizontalScrollerIfNeeded { _borderType = NSNoBorder; _backgroundColor = [[NSColor controlBackgroundColor] copy]; _allowsMagnification = NO; + _magnification = 1.0; [self setLineScroll: 1.0]; [self setPageScroll: 10.0]; // entirely arbitrary @@ -657,6 +659,10 @@ - (BOOL) allowsMagnification { return _allowsMagnification; }; +- (CGFloat) magnification { + return _magnification; +} + - (void) setDocumentView: (NSView *) view { [_clipView setDocumentView: view]; [self reflectScrolledClipView: _clipView]; @@ -822,7 +828,6 @@ - (void) setAutohidesScrollers: (BOOL) value { // FIXME: tile or hide/show scrollers? } -<<<<<<< HEAD - (void) setMagnification: (CGFloat) value { if (value == _magnification) return; @@ -851,13 +856,14 @@ - (void) setMaxMagnification: (CGFloat) value { [self setMagnification: value]; } -- (void) setAllowsMagnification: (BOOL) value { -======= - (void) allowsMagnification: (BOOL) value { ->>>>>>> e9908511 (implemented boolean allowsMagnification) _allowsMagnification = value; } +- (void) setMagnification: (CGFloat) value { + _magnification = value; +} + - (void) tile { NSRect frame; diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index ccfe5d23ae..fee3395e34 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -42,6 +42,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; CGFloat _verticalPageScroll; CGFloat _horizontalLineScroll; CGFloat _horizontalPageScroll; + CGFloat _magnification; int _borderType; BOOL _drawsBackground; BOOL _hasVerticalScroller; @@ -109,6 +110,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (CGFloat) horizontalPageScroll; - (CGFloat) lineScroll; - (CGFloat) pageScroll; +- (CGFloat) magnification; - (BOOL) scrollsDynamically; - (BOOL) autohidesScrollers; - (BOOL) allowsMagnification; @@ -144,6 +146,7 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (void) setMinMagnification: (CGFloat) value; - (void) setMaxMagnification: (CGFloat) value; - (void) setAllowsMagnification: (BOOL) value; +- (void) setMagnification: (CGFloat) value; - (void) tile; - (void) reflectScrolledClipView: (NSClipView *) clipView; From 1ab8aac8abeb57148e631baf49d721f62edf24a1 Mon Sep 17 00:00:00 2001 From: James Park Date: Fri, 9 Feb 2024 17:09:29 -0500 Subject: [PATCH 17/20] implemented CGFloats min/max magnification and set up method magnifyToFitRect --- AppKit/NSScrollView.m | 32 ++++++++++++++++++++++++++++ AppKit/include/AppKit/NSScrollView.h | 7 ++++++ 2 files changed, 39 insertions(+) diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index 97ed88a407..d68d6a964f 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -191,6 +191,8 @@ - (void) encodeWithCoder: (NSCoder *) coder { _allowsMagnification = NO; _magnification = 1.0; + _maxMagnification = 4.0; + _minMagnification = 0.25; _verticalLineScroll = 10.0; // the default value in IB is 10 _verticalPageScroll = 10.0; @@ -427,6 +429,8 @@ - (void) createHorizontalScrollerIfNeeded { _backgroundColor = [[NSColor controlBackgroundColor] copy]; _allowsMagnification = NO; _magnification = 1.0; + _maxMagnification = 4.0; + _minMagnification = 0.25; [self setLineScroll: 1.0]; [self setPageScroll: 10.0]; // entirely arbitrary @@ -663,6 +667,14 @@ - (CGFloat) magnification { return _magnification; } +- (CGFloat) maxMagnification { + return _maxMagnification; +} + +- (CGFloat) minMagnification { + return _minMagnification; +} + - (void) setDocumentView: (NSView *) view { [_clipView setDocumentView: view]; [self reflectScrolledClipView: _clipView]; @@ -864,6 +876,18 @@ - (void) setMagnification: (CGFloat) value { _magnification = value; } +- (void) setMaxMagnification: (CGFloat) value { + if (value >= _minMagnification) { + _maxMagnification = value; + } +} + +- (void) setMinMagnification: (CGFloat) value { + if (value <= _maxMagnification) { + _minMagnification = value; + } +} + - (void) tile { NSRect frame; @@ -1090,5 +1114,13 @@ - (void) resizeSubviewsWithOldSize: (NSSize) oldSize { [self _horizontalScroll: _horizontalScroller]; } +- (void) magnifyToFitRect: (NSRect) rect { + NSUnimplementedMethod(); + /* + todo + Magnifies the content view proportionally such that the given rectangle fits centered in the scroll view. + The resulting magnification value is clipped to the minMagnification and maxMagnification values + */ +} @end diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index fee3395e34..19b2353d7b 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -43,6 +43,8 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; CGFloat _horizontalLineScroll; CGFloat _horizontalPageScroll; CGFloat _magnification; + CGFloat _maxMagnification; + CGFloat _minMagnification; int _borderType; BOOL _drawsBackground; BOOL _hasVerticalScroller; @@ -111,6 +113,8 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (CGFloat) lineScroll; - (CGFloat) pageScroll; - (CGFloat) magnification; +- (CGFloat) maxMagnification; +- (CGFLoat) minMagnification; - (BOOL) scrollsDynamically; - (BOOL) autohidesScrollers; - (BOOL) allowsMagnification; @@ -146,9 +150,12 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (void) setMinMagnification: (CGFloat) value; - (void) setMaxMagnification: (CGFloat) value; - (void) setAllowsMagnification: (BOOL) value; +- (void) setMaxMagnification: (CGFloat) value; - (void) setMagnification: (CGFloat) value; +- (void) minMagnification: (CGFloat) value; - (void) tile; - (void) reflectScrolledClipView: (NSClipView *) clipView; +- (void) magnifyToFitRect: (NSRect) rect; @end From 0ae4f4c28bf23a224e2729279b276a8554b06c94 Mon Sep 17 00:00:00 2001 From: James Park Date: Tue, 13 Feb 2024 12:52:51 -0500 Subject: [PATCH 18/20] added exceptions to setting magnification, first implementation of setMagnfication through rect and point, and allowed negative values to be passed to scaleUnitSize --- .vscode/settings.json | 7 ----- AppKit/NSScrollView.m | 47 ++++++++++++++++++++++------ AppKit/NSView.m | 16 ++-------- AppKit/include/AppKit/NSScrollView.h | 3 +- 4 files changed, 41 insertions(+), 32 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9376941670..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "files.associations": { - "*.embeddedhtml": "html", - "type_traits": "cpp", - "xtr1common": "cpp" - } -} \ No newline at end of file diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index d68d6a964f..7ff96f5446 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -872,19 +872,23 @@ - (void) allowsMagnification: (BOOL) value { _allowsMagnification = value; } -- (void) setMagnification: (CGFloat) value { - _magnification = value; -} - - (void) setMaxMagnification: (CGFloat) value { if (value >= _minMagnification) { _maxMagnification = value; + } else { + [NSException raise: NSInvalidArgumentException + format: @"maxMagnification (%.3f) must be greater than or equal to minMagnification (%.3f).", + value, _minMagnification]; } } - (void) setMinMagnification: (CGFloat) value { if (value <= _maxMagnification) { _minMagnification = value; + } else { + [NSException raise: NSInvalidArgumentException + format: @"minMagnification (%.3f) must be less than or equal to maxMagnification (%.3f).", + value, _maxMagnification]; } } @@ -1114,13 +1118,36 @@ - (void) resizeSubviewsWithOldSize: (NSSize) oldSize { [self _horizontalScroll: _horizontalScroller]; } +- (void) setMagnification:(CGFloat) magnification + centeredAtPoint:(NSPoint) point { + // scale the content view centered at the given point + NSRect frame = [_clipView frame]; + NSSize scaledSize = NSMakeSize(frame.size.width*magnification, frame.size.height*magnification); + NSPoint centeredOrigin = NSMakePoint(point.x - (newSize.width/2), point.y - (newSize.height/2)); + [_clipView setFrame:NSMakeRect(centeredOrigin.x, centeredOrigin.y, scaledSize.width, scaledSize.height)]; + + // clip the resulting magnification value to min and max magnification + magnification = MAX(_minMagnification, magnification); + magnification = MIN(_maxMagnification, magnification); + + self._magnification = magnification; +} + - (void) magnifyToFitRect: (NSRect) rect { - NSUnimplementedMethod(); - /* - todo - Magnifies the content view proportionally such that the given rectangle fits centered in the scroll view. - The resulting magnification value is clipped to the minMagnification and maxMagnification values - */ + if (_allowsMagnification) { + // find magnification value needed to scale the content view to the given rectangle without morphing + CGFloat widthMagnification = NSWidth(_clipView.bounds) / NSWidth(rect); + CGFloat heightMagnification = NSHeight(_clipView.bounds) / NSHeight(rect); + CGFloat magnification = MIN(widthMagnification, heightMagnification); + + // The resulting magnification value is clipped to the min/max magnification + magnification = MAX(_minMagnification, magnification); + magnification = MIN(_maxMagnification, magnification); + + (NSPoint) point = NSMakePoint(NSMidX(rect), NSMidY(rect)); + + [_clipView setMagnification:magnification centeredAtPoint:point]; + } } @end diff --git a/AppKit/NSView.m b/AppKit/NSView.m index 04752689c6..533d7daf3c 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -646,21 +646,10 @@ - (BOOL) postsBoundsChangedNotifications { return _postsNotificationOnBoundsChange; } -// todo after implementing this, i need to implement magnification support in nsscrollview - (void) scaleUnitSquareToSize: (NSSize) size { if (size.width != 1.0 || size.height != 1.0) { - if (size.width < 0) { - size.width = 0; - } - if (size.height < 0) { - size.height = 0; - } - if (_bounds == nil) { - // todo set _bounds. would _bounds ever by nil? need to look into that - // _bounds = [NSAffineTransform new] - } + // todo what if width or height is zero? - // todo need to get scaleXBy in here, located in darling-foundation [_bounds scaleXBy: size.width yBy: size.height]; _bounds.origin.x = _bounds.origin.x / size.width; @@ -671,8 +660,7 @@ - (void) scaleUnitSquareToSize: (NSSize) size { isRotatedOrScaledFromBase = YES; /* code from gnustep - todo flag should be located in appkit/include/nsview.h - + todo if (_coordinates_valid) { (*invalidateImp)(self, invalidateSel); diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index 19b2353d7b..26d2d97c42 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -151,11 +151,12 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (void) setMaxMagnification: (CGFloat) value; - (void) setAllowsMagnification: (BOOL) value; - (void) setMaxMagnification: (CGFloat) value; -- (void) setMagnification: (CGFloat) value; - (void) minMagnification: (CGFloat) value; - (void) tile; - (void) reflectScrolledClipView: (NSClipView *) clipView; +- (void) setMagnification:(CGFloat) magnification + centeredAtPoint:(NSPoint) point; - (void) magnifyToFitRect: (NSRect) rect; @end From c190383681e48c6b2213e28dbc6a82990633ad8e Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:13:17 -0500 Subject: [PATCH 19/20] Remove duplicate definition of magnification properties. --- AppKit/NSScrollView.m | 40 ---------------------------- AppKit/include/AppKit/NSScrollView.h | 8 ------ 2 files changed, 48 deletions(-) diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index 7ff96f5446..3bd2e24296 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -663,18 +663,6 @@ - (BOOL) allowsMagnification { return _allowsMagnification; }; -- (CGFloat) magnification { - return _magnification; -} - -- (CGFloat) maxMagnification { - return _maxMagnification; -} - -- (CGFloat) minMagnification { - return _minMagnification; -} - - (void) setDocumentView: (NSView *) view { [_clipView setDocumentView: view]; [self reflectScrolledClipView: _clipView]; @@ -840,34 +828,6 @@ - (void) setAutohidesScrollers: (BOOL) value { // FIXME: tile or hide/show scrollers? } -- (void) setMagnification: (CGFloat) value { - if (value == _magnification) - return; - - _magnification = value; - - if (_magnification < _minMagnification) - _magnification = _minMagnification; - if (_magnification < _maxMagnification) - _magnification = _maxMagnification; - - // TODO: calculate new bounds and call setBounds -} - -- (void) setMinMagnification: (CGFloat) value { - _minMagnification = value; - - if (_minMagnification > _magnification) - [self setMagnification: value]; -} - -- (void) setMaxMagnification: (CGFloat) value { - _maxMagnification = value; - - if (_maxMagnification < _magnification) - [self setMagnification: value]; -} - - (void) allowsMagnification: (BOOL) value { _allowsMagnification = value; } diff --git a/AppKit/include/AppKit/NSScrollView.h b/AppKit/include/AppKit/NSScrollView.h index 26d2d97c42..2ca43aaa6f 100644 --- a/AppKit/include/AppKit/NSScrollView.h +++ b/AppKit/include/AppKit/NSScrollView.h @@ -42,9 +42,6 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; CGFloat _verticalPageScroll; CGFloat _horizontalLineScroll; CGFloat _horizontalPageScroll; - CGFloat _magnification; - CGFloat _maxMagnification; - CGFloat _minMagnification; int _borderType; BOOL _drawsBackground; BOOL _hasVerticalScroller; @@ -54,7 +51,6 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; BOOL _rulersVisible; BOOL _scrollsDynamically; BOOL _autohidesScrollers; - BOOL _allowsMagnification; NSCursor *_documentCursor; BOOL _allowsMagnification; CGFloat _magnification; @@ -112,12 +108,8 @@ APPKIT_EXPORT NSString *const NSScrollViewDidLiveScrollNotification; - (CGFloat) horizontalPageScroll; - (CGFloat) lineScroll; - (CGFloat) pageScroll; -- (CGFloat) magnification; -- (CGFloat) maxMagnification; -- (CGFLoat) minMagnification; - (BOOL) scrollsDynamically; - (BOOL) autohidesScrollers; -- (BOOL) allowsMagnification; - (NSCursor *) documentCursor; - (CGFloat) magnification; From 14cf4f5ee6e7de685644c6e9fc2ea52599009f45 Mon Sep 17 00:00:00 2001 From: James Park Date: Tue, 20 Feb 2024 20:56:34 -0500 Subject: [PATCH 20/20] fixed minor bugs --- AppKit/NSScrollView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppKit/NSScrollView.m b/AppKit/NSScrollView.m index 3bd2e24296..05c702630a 100644 --- a/AppKit/NSScrollView.m +++ b/AppKit/NSScrollView.m @@ -1083,14 +1083,14 @@ - (void) setMagnification:(CGFloat) magnification // scale the content view centered at the given point NSRect frame = [_clipView frame]; NSSize scaledSize = NSMakeSize(frame.size.width*magnification, frame.size.height*magnification); - NSPoint centeredOrigin = NSMakePoint(point.x - (newSize.width/2), point.y - (newSize.height/2)); + NSPoint centeredOrigin = NSMakePoint(point.x - (scaledSize.width/2), point.y - (scaledSize.height/2)); [_clipView setFrame:NSMakeRect(centeredOrigin.x, centeredOrigin.y, scaledSize.width, scaledSize.height)]; // clip the resulting magnification value to min and max magnification magnification = MAX(_minMagnification, magnification); magnification = MIN(_maxMagnification, magnification); - self._magnification = magnification; + _magnification = magnification; } - (void) magnifyToFitRect: (NSRect) rect {