Inc. NeXT, Inc., Sun Microsystems The GNUstep Project MacApp Cocoa NeXTSTEP OPENSTEP (OpenStep) GNUstep Cocotron platform Mac OS macOS (Mac OS X) NeXTStep Solaris, Windows NT, Unix-likes Windows, Unix-likes, etc. Windows 2000, XP, Vista, Linux, Darwin, Solaris framework – Foundation, AppKit, CoreData – Foundation Kit, Application Kit, PostScript Base Library, GUI Library Foundation, AppKit* language Pascal → C++ Objective-C → Swift Objective-C Objective-C Objective-C Objective-C development closed closed closed closed OSS github.com/ gnustep OSS github.com/ cjwl/cocotron year 1984-1999 2001-present 1989-1997 1994 1994-present 2006-2015? *AppKitWindowsͷΈ
Apple history: NeXT customers get early taste of OS X”, Cult of Mac, 2017-09 https://www.cultofmac.com/503084/today-apple-history-next-customers-get-early-taste-os-x/ NeXTSTEP
Chapter 1: Application Kit NSView Inherits From: NSResponder : NSObject Conforms To: NSCoding (NSResponder) NSObject (NSObject) Declared In: AppKit/NSView.h AppKit/NSClipView.h Class Description NSView is an abstract class that provides its subclasses with a structure for drawing and for handling events. Any application that needs to display, print, or receive events must use NSView objects. To be displayed, a view must be placed in a window (represented by an NSWindow object). All the views within a window are arranged in a hierarchy, with each view having a single superview and zero or more subviews. Each view has its own area to draw in and its own coordinate system, expressed as a transformation of its superview’s coordinate system. An NSView object can scale, translate, or rotate its coordinates, or flip the polarity of its y-axis. An NSView keeps track of its size and location in two ways: as a frame rectangle (expressed in its superview’s coordinate system) and as a bounds rectangle (expressed in its own coordinate system). Both are represented by NSRect structures. Subclasses of NSView typically override drawRect: to implement an object’s distinctive appearance. They also frequently override one or more of NSView’s or NSResponder’s event-handling methods, to react to the user’s manipulations of the mouse and keyboard. Initializing NSView Objects – (id)initWithFrame:(NSRect)frameRect Initializes a new NSView object to the location and dimensions of frameRect. Managing the NSView Hierarchy – (void)addSubview:(NSView *)aView Makes aView a subview of the receiving view object. – (void)addSubview:(NSView *)aView Makes aView a subview of the receiving view object. positioned:(NSWindowOrderingMode)place It is positioned relative to otherView according to relativeTo:(NSView *)otherView place. OpenStep Specification—10/19/94 1-220 Chapter 1: Application Kit – (void)setFrameRotation:(float)angle Rotates the view’s frame to angle. This method posts the NSViewFocusChangedNotification notification with the receiving object to the default notification center. – (void)setFrameSize:(NSSize)newSize Resizes the view’s frame to newSize. This method posts the NSViewFrameChangedNotification and NSViewFocusChangedNotification notifications with the receiving object to the default notification center. Modifying the Coordinate System – (float)boundsRotation Returns the rotation of the view’s coordinate system. – (NSRect)bounds Gets the view’s bounds rectangle. – (BOOL)isFlipped Returns whether the view is flipped. – (BOOL)isRotatedFromBase Returns whether the view is rotated. – (BOOL)isRotatedOrScaledFromBase Returns whether the view is rotated or scaled. – (void)scaleUnitSquareToSize:(NSSize)newSize Scales the NSView’s coordinate system unit size to newSize. This method posts the notification NSViewFocusChangedNotification with the receiving object to the default notification center. – (void)setBounds:(NSRect)aRect Sets the NSView’s bounds rectangle to aRect. – (void)setBoundsOrigin:(NSPoint)newOrigin Sets the NSView’s drawing origin to newOrigin. This method posts the NSViewFocusChangedNotification notification with the receiving object to the default notification center. – (void)setBoundsRotation:(float)angle Rotates the NSView’s coordinate system to angle. This method posts the NSViewFocusChangedNotification notification with the receiving object to the default notification center. – (void)setBoundsSize:(NSSize)newSize Resizes the NSView’s coordinate system to newSize. This method posts the NSViewFocusChangedNotification notification with the receiving object to the default notification center. – (void)translateOriginToPoint:(NSPoint)point Shifts the NSView’s coordinate system to point. This method posts the NSViewFocusChangedNotification notification with the receiving object to the default notification center.
/* TODO: find out what affinity is supposed to mean My current assumption: Affinity deals with which direction we are selecting in, ie. which end of the selected range is the moving end, and which is the anchor. NSSelectionAffinityUpstream means that the minimum index of the selected range is moving (ie. _selected_range.location). NSSelectionAffinityDownstream means that the maximum index of the selected range is moving (ie. _selected_range.location+_selected_range.length). Thus, when moving and selecting, we use the affinity to find out which end of the selected range to move, and after moving, we compare the character index we moved to with the anchor and set the range and affinity. The affinity is important when making keyboard selection have sensible behavior. Example: If, in the string "abcd", the insertion point is between the "c" and the "d" (selected range is (3,0)), and the user hits shift-left twice, we select the "c" and "b" (1,2) and set the affinity to NSSelectionAffinityUpstream. If the user hits shift-right, only the "c" will be selected (2,1). If the insertion point is between the "a" and the "b" (1,0) and the user hits shift-right twice, we again select the "b" and "c" (1,2), but the affinity is NSSelectionAffinityDownstream. If the user hits shift-right, the "d" is added to the selection (1,3). */ - (unsigned int) _movementOrigin { NSRange range = [self selectedRange];
for (range, color) in highlights { layoutManager.addTemporaryAttribute(.foregroundColor, value: color, forCharacterRange: range) } Swift めちゃ時間かかる... γϯλοΫεϋΠϥΠτͰϝΠϯεϨουͰΒͳ͍ͱ͍͚ͳ͍࡞ۀ Reference NSLayoutManager.addTemporaryAttributes(_:forCharacterRange:) Discussion Temporary attributes are used only for onscreen drawing and are not persistent in any way. NSTextView uses them to color misspelled words when continuous spell checking is enabled. Currently the only temporary attributes recognized are those that do not affect layout (colors, underlines, and so on). ෦తͳattributeσʔλΛมߋ͢Δ͚ͩͰԿ͠ͳ͍ͷͰ…?