Add support for dividerThickness and bump version of NSSplitView to 1

This commit is contained in:
Gregory John Casamento 2021-10-13 19:03:02 -04:00
parent 8fa489282b
commit 54e555bc33
2 changed files with 111 additions and 25 deletions

View file

@ -57,6 +57,9 @@ typedef NSInteger NSSplitViewDividerStyle;
BOOL _isVertical;
BOOL _never_displayed_before;
BOOL _is_pane_splitter;
NSSplitViewDividerStyle _dividerStyle;
BOOL _arrangesAllSubviews;
NSMutableArray *_arrangedSubviews;
}
- (void) setDelegate: (id)anObject;

View file

@ -45,6 +45,7 @@
#import <Foundation/NSUserDefaults.h>
#import "AppKit/NSApplication.h"
#import "AppKit/NSBezierPath.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSCursor.h"
#import "AppKit/NSEvent.h"
@ -60,6 +61,7 @@ static NSNotificationCenter *nc = nil;
+ (void) initialize
{
[self setVersion: 1];
nc = [NSNotificationCenter defaultCenter];
}
@ -70,8 +72,9 @@ static NSNotificationCenter *nc = nil;
{
if ((self = [super initWithFrame: frameRect]) != nil)
{
_dividerStyle = NSSplitViewDividerStyleThick;
_dividerWidth = [self dividerThickness];
_draggedBarWidth = 8; // default bigger than dividerThickness
_draggedBarWidth = _dividerWidth + 2;
_isVertical = NO;
ASSIGN(_dividerColor, [NSColor controlShadowColor]);
ASSIGN(_dimpleImage, [NSImage imageNamed: @"common_Dimple"]);
@ -83,6 +86,32 @@ static NSNotificationCenter *nc = nil;
return self;
}
- (NSRect) _dividerRectForIndex: (NSUInteger)index
{
const SEL selector = @selector(splitView:effectiveRect:forDrawnRect:ofDividerAtIndex:);
NSRect rect = [[[self subviews] objectAtIndex: index] frame];
{
if (_isVertical == NO)
{
rect.origin.y = NSMaxY (rect);
rect.size.height = _dividerWidth;
}
else
{
rect.origin.x = NSMaxX (rect);
rect.size.width = _dividerWidth;
}
rect = NSIntersectionRect(rect, [self visibleRect]);
// Check with delegate for hit rect...
if (_delegate && [_delegate respondsToSelector: selector])
{
rect = [_delegate splitView: self effectiveRect: rect forDrawnRect: rect ofDividerAtIndex: index];
}
}
return rect;
}
- (void) dealloc
{
RELEASE(_backgroundColor);
@ -402,8 +431,9 @@ static NSNotificationCenter *nc = nil;
- (void) mouseDown: (NSEvent*)theEvent
{
NSApplication *app = [NSApplication sharedApplication];
NSPoint p = NSZeroPoint,
op = NSZeroPoint;
NSPoint p = NSZeroPoint;
NSPoint op = NSZeroPoint;
NSPoint poffset = NSZeroPoint;
NSEvent *e;
NSRect r, r1, bigRect, vis;
id v = nil, prev = nil;
@ -453,7 +483,23 @@ static NSNotificationCenter *nc = nil;
{
NSDebugLLog(@"NSSplitView",
@"NSSplitView got mouseDown in subview area");
return;
// If this is the first view then we're done...
if (i == 0)
return;
// Otherwise, check whether the delegate wants a larger rectangle
// for the divider grab area that may overlap the view and validate
// the point within that area...
r = [self _dividerRectForIndex: i-1];
if (NSPointInRect(p, r) == NO)
return;
// Capture the offset for use during the resize loop below...
poffset = NSMakePoint(r.origin.x-p.x, r.origin.y-p.y);
// Force the view processing below to select this view...
p = r.origin;
}
if (_isVertical == NO)
{
@ -712,7 +758,8 @@ static NSNotificationCenter *nc = nil;
if ((_isVertical == YES && p.x != op.x)
|| (_isVertical == NO && p.y != op.y))
{
[self _resize: v withOldSplitView: prev withFrame: r fromPoint: p
NSPoint point = NSMakePoint(p.x+poffset.x, p.y+poffset.y);
[self _resize: v withOldSplitView: prev withFrame: r fromPoint: point
withBigRect: bigRect divHorizontal: divHorizontal
divVertical: divVertical];
[_window invalidateCursorRectsForView: self];
@ -979,7 +1026,15 @@ static NSNotificationCenter *nc = nil;
* dividerThickness (or, without need for subclassing, invoke
* setDimpleImage:resetDividerThickness:YES below)
*/
return 6;
if (_dividerStyle == NSSplitViewDividerStyleThin)
return 1;
if (_dividerStyle == NSSplitViewDividerStyleThick)
return 6;
if (_dividerStyle == NSSplitViewDividerStylePaneSplitter)
return 6;
NSWarnMLog(@"unsupported divider style: %ld", (long)_dividerStyle);
return 0;
}
static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
@ -990,7 +1045,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return p;
}
- (void) drawDividerInRect: (NSRect)aRect
- (void) drawThickDividerInRect: (NSRect)aRect
{
NSPoint dimpleOrigin;
NSSize dimpleSize;
@ -1016,6 +1071,35 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
operation: NSCompositeSourceOver];
}
- (void) drawThinDividerInRect: (NSRect) aRect
{
CGFloat lineWidth = (_isVertical ? aRect.size.width : aRect.size.height);
NSPoint startPoint = aRect.origin;
NSPoint endPoint = NSMakePoint(NSMaxX(aRect), NSMinY(aRect));
NSBezierPath *path = [NSBezierPath bezierPath];
if (_isVertical)
{
endPoint = NSMakePoint(NSMinX(aRect), NSMaxY(aRect));
}
[path setLineWidth: lineWidth];
[path moveToPoint: startPoint];
[path lineToPoint: endPoint];
[path closePath];
[path stroke];
}
- (void) drawDividerInRect: (NSRect)aRect
{
if (_dividerStyle == NSSplitViewDividerStyleThick)
[self drawThickDividerInRect: aRect];
else if (_dividerStyle == NSSplitViewDividerStyleThin)
[self drawThinDividerInRect: aRect];
else if (_dividerStyle == NSSplitViewDividerStylePaneSplitter)
[self drawThickDividerInRect: aRect];
}
/* Vertical splitview has a vertical split bar */
- (void) setVertical: (BOOL)flag
{
@ -1301,7 +1385,6 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
NSArray *subs = [self subviews];
NSUInteger i;
const NSUInteger count = [subs count];
const NSRect visibleRect = [self visibleRect];
NSCursor *cursor;
if (_isVertical)
@ -1315,20 +1398,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
for (i = 0; (i + 1) < count; i++)
{
NSView *v = [subs objectAtIndex: i];
NSRect divRect = [v frame];
if (_isVertical == NO)
{
divRect.origin.y = NSMaxY (divRect);
divRect.size.height = _dividerWidth;
}
else
{
divRect.origin.x = NSMaxX (divRect);
divRect.size.width = _dividerWidth;
}
divRect = NSIntersectionRect(divRect, visibleRect);
NSRect divRect = [self _dividerRectForIndex: i];
if (!NSEqualRects(NSZeroRect, divRect))
{
[self addCursorRect: divRect cursor: cursor];
@ -1343,13 +1413,12 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (NSSplitViewDividerStyle) dividerStyle
{
// FIXME
return NSSplitViewDividerStyleThick;
return _dividerStyle;
}
- (void) setDividerStyle: (NSSplitViewDividerStyle)dividerStyle
{
// FIXME
_dividerStyle = dividerStyle;
}
/*
@ -1363,6 +1432,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
{
[aCoder encodeBool: _isVertical forKey: @"NSIsVertical"];
[aCoder encodeObject: _autosaveName forKey: @"NSAutosaveName"];
[aCoder encodeInteger: _dividerStyle forKey: @"NSDividerStyle"];
}
else
{
@ -1386,6 +1456,11 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
*/
[aCoder encodeValueOfObjCType: @encode(int) at: &draggedBarWidth];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isVertical];
/*
* Encode Divider style
*/
[aCoder encodeValueOfObjCType: @encode(int) at: &_dividerStyle];
}
}
@ -1427,6 +1502,8 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
}
else
{
int version = [aDecoder versionForClassName: @"NSSplitView"];
// FIXME: No idea why this as encode as int
int draggedBarWidth;
@ -1446,8 +1523,14 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
_draggedBarWidth = draggedBarWidth;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isVertical];
if (version == 1)
{
[aDecoder decodeValueOfObjCType: @encode(int) at: &_dividerStyle];
}
_dividerWidth = [self dividerThickness];
_never_displayed_before = YES;
_draggedBarWidth = _dividerWidth + 2;
}
return self;