mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-26 21:40:44 +00:00
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
This commit is contained in:
parent
fd68ee23c7
commit
5300f80f18
@ -30,7 +30,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
#import <AppKit/NSTypesetter.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
|
||||
#import <Foundation/NSRangeEntries.h>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
@ -39,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <Foundation/NSKeyedArchiver.h>
|
||||
#import <Foundation/NSRaiseException.h>
|
||||
#import <Foundation/NSRangeEntries.h>
|
||||
|
||||
#import "NSBidiHelper.h"
|
||||
#import "NSRulerMarker+NSTextExtensions.h"
|
||||
@ -177,13 +177,17 @@ static inline NSGlyphFragment *fragmentAtGlyphIndex(NSLayoutManager *self,
|
||||
}
|
||||
|
||||
- (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 @@ static inline NSGlyphFragment *fragmentAtGlyphIndex(NSLayoutManager *self,
|
||||
}
|
||||
|
||||
- (BOOL) allowsNonContiguousLayout {
|
||||
NSUnimplementedMethod();
|
||||
return _allowsNonContiguousLayout;
|
||||
}
|
||||
|
||||
@ -1381,7 +1384,8 @@ static inline void _appendRectToCache(NSLayoutManager *self, NSRect rect) {
|
||||
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
|
||||
|
@ -189,6 +189,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
- (void) setLayoutManager: (NSLayoutManager *) layoutManager {
|
||||
_layoutManager = layoutManager;
|
||||
[_textView _setTextStorage: [_layoutManager textStorage]];
|
||||
}
|
||||
|
||||
- (void) replaceLayoutManager: (NSLayoutManager *) layoutManager {
|
||||
|
@ -143,6 +143,36 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
- 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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
_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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
- (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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
}
|
||||
|
||||
- (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 @@ NSString *const NSAllRomanInputSourcesLocaleIdentifier =
|
||||
return _layoutOrientation;
|
||||
}
|
||||
|
||||
- (void)setLayoutOrientation:(NSTextLayoutOrientation)orientation {
|
||||
- (void) setLayoutOrientation: (NSTextLayoutOrientation) orientation {
|
||||
_layoutOrientation = orientation;
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
- (BOOL) usesFindBar {
|
||||
NSUnimplementedMethod();
|
||||
return _usesFindBar;
|
||||
}
|
||||
|
||||
- (void) setUsesFindBar: (BOOL) value {
|
||||
NSUnimplementedMethod();
|
||||
_usesFindBar = value;
|
||||
}
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
- (void) setUsesInspectorBar: (BOOL) value {
|
||||
NSUnimplementedMethod();
|
||||
_usesInspectorBar = 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();
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user