Permalink
Browse files

Merge branch 'master' of github.com:cappuccino/cappuccino

  • Loading branch information...
2 parents c5afd3d + 2fd67f6 commit 44521a3c222697fd4d3bd4d7319d588afdb0e968 @aljungberg aljungberg committed Apr 23, 2012
Showing with 59 additions and 27 deletions.
  1. +59 −27 AppKit/CPSplitView.j
View
86 AppKit/CPSplitView.j
@@ -117,8 +117,9 @@ var CPSplitViewHorizontalImage = nil,
return;
var bundle = [CPBundle bundleForClass:self];
- CPSplitViewHorizontalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewHorizontal.png"] size:CPSizeMake(5.0, 10.0)];
- CPSplitViewVerticalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewVertical.png"] size:CPSizeMake(10.0, 5.0)];
+
+ CPSplitViewHorizontalImage = CPImageInBundle("CPSplitView/CPSplitViewHorizontal.png", CGSizeMake(5.0, 10.0), bundle);
+ CPSplitViewVerticalImage = CPImageInBundle("CPSplitView/CPSplitViewVertical.png", CGSizeMake(10.0, 5.0), bundle);
}
- (id)initWithFrame:(CGRect)aFrame
@@ -178,14 +179,17 @@ var CPSplitViewHorizontalImage = nil,
count = _subviews.length;
if ([self isVertical])
+ {
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(ROUND((eachSize + dividerThickness) * index), 0, eachSize, frame.size.height)];
+ }
else
+ {
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(0, ROUND((eachSize + dividerThickness) * index), frame.size.width, eachSize)];
+ }
[self setNeedsDisplay:YES];
-
[self _postNotificationDidResize];
}
@@ -261,7 +265,6 @@ var CPSplitViewHorizontalImage = nil,
rect = CGRectMakeZero();
rect.size = [self frame].size;
-
rect.size[_sizeComponent] = [self dividerThickness];
rect.origin[_originComponent] = frame.origin[_originComponent] + frame.size[_sizeComponent];
@@ -370,28 +373,33 @@ var CPSplitViewHorizontalImage = nil,
_needsResizeSubviews = NO;
+ [self resizeSubviewsWithOldSize:[self _calculateSize]];
+}
+
+- (CGSize)_calculateSize
+{
var subviews = [self subviews],
count = subviews.length,
- oldSize = CGSizeMakeZero();
+ size = CGSizeMakeZero();
if ([self isVertical])
{
- oldSize.width += [self dividerThickness] * (count - 1);
- oldSize.height = CGRectGetHeight([self frame]);
+ size.width += [self dividerThickness] * (count - 1);
+ size.height = CGRectGetHeight([self frame]);
}
else
{
- oldSize.width = CGRectGetWidth([self frame]);
- oldSize.height += [self dividerThickness] * (count - 1);
+ size.width = CGRectGetWidth([self frame]);
+ size.height += [self dividerThickness] * (count - 1);
}
while (count--)
- oldSize[_sizeComponent] += [subviews[count] frame].size[_sizeComponent];
+ size[_sizeComponent] += [subviews[count] frame].size[_sizeComponent];
- [self resizeSubviewsWithOldSize:oldSize];
+ return size;
}
-- (BOOL)cursorAtPoint:(CPPoint)aPoint hitDividerAtIndex:(int)anIndex
+- (BOOL)cursorAtPoint:(CGPoint)aPoint hitDividerAtIndex:(int)anIndex
{
var frame = [_subviews[anIndex] frame],
startPosition = frame.origin[_originComponent] + frame.size[_sizeComponent],
@@ -455,10 +463,11 @@ var CPSplitViewHorizontalImage = nil,
if (type == CPLeftMouseDown)
{
- var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
+ var point = [self convertPoint:[anEvent locationInWindow] fromView:nil],
+ count = [_subviews count] - 1;
_currentDivider = CPNotFound;
- var count = [_subviews count] - 1;
+
for (var i = 0; i < count; i++)
{
var frame = [_subviews[i] frame],
@@ -574,9 +583,11 @@ var CPSplitViewHorizontalImage = nil,
if (sizeA === 0)
canGrow = YES; // Subview is collapsed.
else if (!canShrink &&
- [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
- [_delegate splitView:self canCollapseSubview:_subviews[i]])
+ [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
+ [_delegate splitView:self canCollapseSubview:_subviews[i]])
+ {
canShrink = YES; // Subview is collapsible.
+ }
if (sizeB === 0)
{
@@ -586,9 +597,11 @@ var CPSplitViewHorizontalImage = nil,
canShrink = YES;
}
else if (!canGrow &&
- [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
- [_delegate splitView:self canCollapseSubview:_subviews[i + 1]])
+ [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
+ [_delegate splitView:self canCollapseSubview:_subviews[i + 1]])
+ {
canGrow = YES; // Right/lower subview is collapsible.
+ }
if (_isVertical && canShrink && canGrow)
cursor = [CPCursor resizeLeftRightCursor];
@@ -665,13 +678,15 @@ var CPSplitViewHorizontalImage = nil,
if ([_delegate respondsToSelector:@selector(splitView:constrainMinCoordinate:ofSubviewAt:)])
{
var proposedActualMin = [_delegate splitView:self constrainMinCoordinate:proposedMin ofSubviewAt:dividerIndex];
+
if (_IS_NUMERIC(proposedActualMin))
actualMin = proposedActualMin;
}
if ([_delegate respondsToSelector:@selector(splitView:constrainMaxCoordinate:ofSubviewAt:)])
{
var proposedActualMax = [_delegate splitView:self constrainMaxCoordinate:proposedMax ofSubviewAt:dividerIndex];
+
if (_IS_NUMERIC(proposedActualMax))
actualMax = proposedActualMax;
}
@@ -685,6 +700,7 @@ var CPSplitViewHorizontalImage = nil,
if ([_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)])
if ([_delegate splitView:self canCollapseSubview:viewA])
realPosition = proposedMin;
+
// We can also collapse to the right.
if (position > proposedMax - (proposedMax - actualMax) / 2)
if ([_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)])
@@ -704,18 +720,19 @@ var CPSplitViewHorizontalImage = nil,
SPLIT_VIEW_SUPPRESS_RESIZE_NOTIFICATIONS(YES);
[self _adjustSubviewsWithCalculatedSize];
- var realPosition = [self _realPositionForPosition:position ofDividerAtIndex:dividerIndex];
-
- var viewA = _subviews[dividerIndex],
+ var realPosition = [self _realPositionForPosition:position ofDividerAtIndex:dividerIndex],
+ viewA = _subviews[dividerIndex],
frameA = [viewA frame],
viewB = _subviews[dividerIndex + 1],
frameB = [viewB frame],
- _preCollapsePosition = 0;
+ _preCollapsePosition = 0,
+ preSize = frameA.size[_sizeComponent];
- var preSize = frameA.size[_sizeComponent];
frameA.size[_sizeComponent] = realPosition - frameA.origin[_originComponent];
+
if (preSize !== 0 && frameA.size[_sizeComponent] === 0)
_preCollapsePosition = preSize;
+
if (preSize !== frameA.size[_sizeComponent])
{
SPLIT_VIEW_MAYBE_POST_WILL_RESIZE();
@@ -724,11 +741,15 @@ var CPSplitViewHorizontalImage = nil,
}
preSize = frameB.size[_sizeComponent];
+
var preOrigin = frameB.origin[_originComponent];
frameB.size[_sizeComponent] = frameB.origin[_originComponent] + frameB.size[_sizeComponent] - realPosition - [self dividerThickness];
+
if (preSize !== 0 && frameB.size[_sizeComponent] === 0)
_preCollapsePosition = frameB.origin[_originComponent];
+
frameB.origin[_originComponent] = realPosition + [self dividerThickness];
+
if (preSize !== frameB.size[_sizeComponent] || preOrigin !== frameB.origin[_originComponent])
{
SPLIT_VIEW_MAYBE_POST_WILL_RESIZE();
@@ -743,6 +764,7 @@ var CPSplitViewHorizontalImage = nil,
if (SPLIT_VIEW_DID_SUPPRESS_RESIZE_NOTIFICATION())
[self _postNotificationDidResize];
+
SPLIT_VIEW_SUPPRESS_RESIZE_NOTIFICATIONS(NO);
}
@@ -773,6 +795,11 @@ var CPSplitViewHorizontalImage = nil,
return;
}
+ [self adjustSubviews];
+}
+
+- (void)adjustSubviews
+{
var count = [_subviews count];
if (!count)
@@ -784,6 +811,7 @@ var CPSplitViewHorizontalImage = nil,
var index = 0,
bounds = [self bounds],
boundsSize = bounds.size[_sizeComponent],
+ oldSize = [self _calculateSize],
dividerThickness = [self dividerThickness],
totalDividers = count - 1,
oldFlexibleSpace = 0,
@@ -810,8 +838,8 @@ var CPSplitViewHorizontalImage = nil,
size = [view frame].size[_sizeComponent];
isSizableMap[index] = isSizable;
-
viewSizes.push(size);
+
if (isSizable)
{
oldFlexibleSpace += size;
@@ -831,6 +859,7 @@ var CPSplitViewHorizontalImage = nil,
}
var remainingFixedPanes = count - totalSizablePanes;
+
for (index = 0; index < count; ++index)
{
var view = _subviews[index],
@@ -858,11 +887,8 @@ var CPSplitViewHorizontalImage = nil,
targetSize = newFlexibleSpace / totalSizablePanes;
targetSize = MAX(0, ROUND(targetSize));
-
viewFrame.size[_sizeComponent] = targetSize;
-
[view setFrame:viewFrame];
-
bounds.origin[_originComponent] += targetSize + dividerThickness;
}
@@ -1020,6 +1046,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
{
if (_autosaveName == autosaveName)
return;
+
_autosaveName = autosaveName;
}
@@ -1079,6 +1106,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
position = 0;
_shouldAutosave = NO;
+
for (var i = 0, count = [frames count] - 1; i < count; i++)
{
var frame = CPRectFromString(frames[i]);
@@ -1088,12 +1116,14 @@ The sum of the views and the sum of the dividers should be equal to the size of
position += dividerThickness;
}
+
_shouldAutosave = YES;
}
if (preCollapseArray)
{
_preCollapsePositions = [CPMutableDictionary new];
+
for (var i = 0, count = [preCollapseArray count]; i < count; i++)
[_preCollapsePositions setObject:preCollapseArray[i] forKey:i + ""];
}
@@ -1106,6 +1136,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
{
if (!theAutosaveName)
return nil;
+
return @"CPSplitView Subview Frames " + theAutosaveName;
}
@@ -1116,6 +1147,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
{
if (!theAutosaveName)
return nil;
+
return @"CPSplitView Subview Precollapse Positions " + theAutosaveName;
}

0 comments on commit 44521a3

Please sign in to comment.