Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 44521a3c222697fd4d3bd4d7319d588afdb0e968 2 parents c5afd3d + 2fd67f6
Alexander Ljungberg authored April 23, 2012

Showing 1 changed file with 59 additions and 27 deletions. Show diff stats Hide diff stats

  1. 86  AppKit/CPSplitView.j
86  AppKit/CPSplitView.j
@@ -117,8 +117,9 @@ var CPSplitViewHorizontalImage = nil,
117 117
         return;
118 118
 
119 119
     var bundle = [CPBundle bundleForClass:self];
120  
-    CPSplitViewHorizontalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewHorizontal.png"] size:CPSizeMake(5.0, 10.0)];
121  
-    CPSplitViewVerticalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewVertical.png"] size:CPSizeMake(10.0, 5.0)];
  120
+
  121
+    CPSplitViewHorizontalImage = CPImageInBundle("CPSplitView/CPSplitViewHorizontal.png", CGSizeMake(5.0, 10.0), bundle);
  122
+    CPSplitViewVerticalImage = CPImageInBundle("CPSplitView/CPSplitViewVertical.png", CGSizeMake(10.0, 5.0), bundle);
122 123
 }
123 124
 
124 125
 - (id)initWithFrame:(CGRect)aFrame
@@ -178,14 +179,17 @@ var CPSplitViewHorizontalImage = nil,
178 179
         count = _subviews.length;
179 180
 
180 181
     if ([self isVertical])
  182
+    {
181 183
         for (; index < count; ++index)
182 184
             [_subviews[index] setFrame:CGRectMake(ROUND((eachSize + dividerThickness) * index), 0, eachSize, frame.size.height)];
  185
+    }
183 186
     else
  187
+    {
184 188
         for (; index < count; ++index)
185 189
             [_subviews[index] setFrame:CGRectMake(0, ROUND((eachSize + dividerThickness) * index), frame.size.width, eachSize)];
  190
+    }
186 191
 
187 192
     [self setNeedsDisplay:YES];
188  
-
189 193
     [self _postNotificationDidResize];
190 194
 
191 195
 }
@@ -261,7 +265,6 @@ var CPSplitViewHorizontalImage = nil,
261 265
         rect = CGRectMakeZero();
262 266
 
263 267
     rect.size = [self frame].size;
264  
-
265 268
     rect.size[_sizeComponent] = [self dividerThickness];
266 269
     rect.origin[_originComponent] = frame.origin[_originComponent] + frame.size[_sizeComponent];
267 270
 
@@ -370,28 +373,33 @@ var CPSplitViewHorizontalImage = nil,
370 373
 
371 374
     _needsResizeSubviews = NO;
372 375
 
  376
+    [self resizeSubviewsWithOldSize:[self _calculateSize]];
  377
+}
  378
+
  379
+- (CGSize)_calculateSize
  380
+{
373 381
     var subviews = [self subviews],
374 382
         count = subviews.length,
375  
-        oldSize = CGSizeMakeZero();
  383
+        size = CGSizeMakeZero();
376 384
 
377 385
     if ([self isVertical])
378 386
     {
379  
-        oldSize.width += [self dividerThickness] * (count - 1);
380  
-        oldSize.height = CGRectGetHeight([self frame]);
  387
+        size.width += [self dividerThickness] * (count - 1);
  388
+        size.height = CGRectGetHeight([self frame]);
381 389
     }
382 390
     else
383 391
     {
384  
-        oldSize.width = CGRectGetWidth([self frame]);
385  
-        oldSize.height += [self dividerThickness] * (count - 1);
  392
+        size.width = CGRectGetWidth([self frame]);
  393
+        size.height += [self dividerThickness] * (count - 1);
386 394
     }
387 395
 
388 396
     while (count--)
389  
-        oldSize[_sizeComponent] += [subviews[count] frame].size[_sizeComponent];
  397
+        size[_sizeComponent] += [subviews[count] frame].size[_sizeComponent];
390 398
 
391  
-    [self resizeSubviewsWithOldSize:oldSize];
  399
+    return size;
392 400
 }
393 401
 
394  
-- (BOOL)cursorAtPoint:(CPPoint)aPoint hitDividerAtIndex:(int)anIndex
  402
+- (BOOL)cursorAtPoint:(CGPoint)aPoint hitDividerAtIndex:(int)anIndex
395 403
 {
396 404
     var frame = [_subviews[anIndex] frame],
397 405
         startPosition = frame.origin[_originComponent] + frame.size[_sizeComponent],
@@ -455,10 +463,11 @@ var CPSplitViewHorizontalImage = nil,
455 463
 
456 464
     if (type == CPLeftMouseDown)
457 465
     {
458  
-        var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
  466
+        var point = [self convertPoint:[anEvent locationInWindow] fromView:nil],
  467
+            count = [_subviews count] - 1;
459 468
 
460 469
         _currentDivider = CPNotFound;
461  
-        var count = [_subviews count] - 1;
  470
+
462 471
         for (var i = 0; i < count; i++)
463 472
         {
464 473
             var frame = [_subviews[i] frame],
@@ -574,9 +583,11 @@ var CPSplitViewHorizontalImage = nil,
574 583
             if (sizeA === 0)
575 584
                 canGrow = YES; // Subview is collapsed.
576 585
             else if (!canShrink &&
577  
-                [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
578  
-                [_delegate splitView:self canCollapseSubview:_subviews[i]])
  586
+                     [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
  587
+                     [_delegate splitView:self canCollapseSubview:_subviews[i]])
  588
+            {
579 589
                 canShrink = YES; // Subview is collapsible.
  590
+            }
580 591
 
581 592
             if (sizeB === 0)
582 593
             {
@@ -586,9 +597,11 @@ var CPSplitViewHorizontalImage = nil,
586 597
                 canShrink = YES;
587 598
             }
588 599
             else if (!canGrow &&
589  
-                [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
590  
-                [_delegate splitView:self canCollapseSubview:_subviews[i + 1]])
  600
+                     [_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)] &&
  601
+                     [_delegate splitView:self canCollapseSubview:_subviews[i + 1]])
  602
+            {
591 603
                 canGrow = YES; // Right/lower subview is collapsible.
  604
+            }
592 605
 
593 606
             if (_isVertical && canShrink && canGrow)
594 607
                 cursor = [CPCursor resizeLeftRightCursor];
@@ -665,6 +678,7 @@ var CPSplitViewHorizontalImage = nil,
665 678
     if ([_delegate respondsToSelector:@selector(splitView:constrainMinCoordinate:ofSubviewAt:)])
666 679
     {
667 680
         var proposedActualMin = [_delegate splitView:self constrainMinCoordinate:proposedMin ofSubviewAt:dividerIndex];
  681
+
668 682
         if (_IS_NUMERIC(proposedActualMin))
669 683
             actualMin = proposedActualMin;
670 684
     }
@@ -672,6 +686,7 @@ var CPSplitViewHorizontalImage = nil,
672 686
     if ([_delegate respondsToSelector:@selector(splitView:constrainMaxCoordinate:ofSubviewAt:)])
673 687
     {
674 688
         var proposedActualMax = [_delegate splitView:self constrainMaxCoordinate:proposedMax ofSubviewAt:dividerIndex];
  689
+
675 690
         if (_IS_NUMERIC(proposedActualMax))
676 691
             actualMax = proposedActualMax;
677 692
     }
@@ -685,6 +700,7 @@ var CPSplitViewHorizontalImage = nil,
685 700
         if ([_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)])
686 701
             if ([_delegate splitView:self canCollapseSubview:viewA])
687 702
                 realPosition = proposedMin;
  703
+
688 704
     // We can also collapse to the right.
689 705
     if (position > proposedMax - (proposedMax - actualMax) / 2)
690 706
         if ([_delegate respondsToSelector:@selector(splitView:canCollapseSubview:)])
@@ -704,18 +720,19 @@ var CPSplitViewHorizontalImage = nil,
704 720
     SPLIT_VIEW_SUPPRESS_RESIZE_NOTIFICATIONS(YES);
705 721
     [self _adjustSubviewsWithCalculatedSize];
706 722
 
707  
-    var realPosition = [self _realPositionForPosition:position ofDividerAtIndex:dividerIndex];
708  
-
709  
-    var viewA = _subviews[dividerIndex],
  723
+    var realPosition = [self _realPositionForPosition:position ofDividerAtIndex:dividerIndex],
  724
+        viewA = _subviews[dividerIndex],
710 725
         frameA = [viewA frame],
711 726
         viewB = _subviews[dividerIndex + 1],
712 727
         frameB = [viewB frame],
713  
-        _preCollapsePosition = 0;
  728
+        _preCollapsePosition = 0,
  729
+        preSize = frameA.size[_sizeComponent];
714 730
 
715  
-    var preSize = frameA.size[_sizeComponent];
716 731
     frameA.size[_sizeComponent] = realPosition - frameA.origin[_originComponent];
  732
+
717 733
     if (preSize !== 0 && frameA.size[_sizeComponent] === 0)
718 734
         _preCollapsePosition = preSize;
  735
+
719 736
     if (preSize !== frameA.size[_sizeComponent])
720 737
     {
721 738
         SPLIT_VIEW_MAYBE_POST_WILL_RESIZE();
@@ -724,11 +741,15 @@ var CPSplitViewHorizontalImage = nil,
724 741
     }
725 742
 
726 743
     preSize = frameB.size[_sizeComponent];
  744
+
727 745
     var preOrigin = frameB.origin[_originComponent];
728 746
     frameB.size[_sizeComponent] = frameB.origin[_originComponent] + frameB.size[_sizeComponent] - realPosition - [self dividerThickness];
  747
+
729 748
     if (preSize !== 0 && frameB.size[_sizeComponent] === 0)
730 749
         _preCollapsePosition = frameB.origin[_originComponent];
  750
+
731 751
     frameB.origin[_originComponent] = realPosition + [self dividerThickness];
  752
+
732 753
     if (preSize !== frameB.size[_sizeComponent] || preOrigin !== frameB.origin[_originComponent])
733 754
     {
734 755
         SPLIT_VIEW_MAYBE_POST_WILL_RESIZE();
@@ -743,6 +764,7 @@ var CPSplitViewHorizontalImage = nil,
743 764
 
744 765
     if (SPLIT_VIEW_DID_SUPPRESS_RESIZE_NOTIFICATION())
745 766
         [self _postNotificationDidResize];
  767
+
746 768
     SPLIT_VIEW_SUPPRESS_RESIZE_NOTIFICATIONS(NO);
747 769
 }
748 770
 
@@ -773,6 +795,11 @@ var CPSplitViewHorizontalImage = nil,
773 795
         return;
774 796
     }
775 797
 
  798
+    [self adjustSubviews];
  799
+}
  800
+
  801
+- (void)adjustSubviews
  802
+{
776 803
     var count = [_subviews count];
777 804
 
778 805
     if (!count)
@@ -784,6 +811,7 @@ var CPSplitViewHorizontalImage = nil,
784 811
     var index = 0,
785 812
         bounds = [self bounds],
786 813
         boundsSize = bounds.size[_sizeComponent],
  814
+        oldSize = [self _calculateSize],
787 815
         dividerThickness = [self dividerThickness],
788 816
         totalDividers = count - 1,
789 817
         oldFlexibleSpace = 0,
@@ -810,8 +838,8 @@ var CPSplitViewHorizontalImage = nil,
810 838
             size = [view frame].size[_sizeComponent];
811 839
 
812 840
         isSizableMap[index] = isSizable;
813  
-
814 841
         viewSizes.push(size);
  842
+
815 843
         if (isSizable)
816 844
         {
817 845
             oldFlexibleSpace += size;
@@ -831,6 +859,7 @@ var CPSplitViewHorizontalImage = nil,
831 859
     }
832 860
 
833 861
     var remainingFixedPanes = count - totalSizablePanes;
  862
+
834 863
     for (index = 0; index < count; ++index)
835 864
     {
836 865
         var view = _subviews[index],
@@ -858,11 +887,8 @@ var CPSplitViewHorizontalImage = nil,
858 887
             targetSize = newFlexibleSpace / totalSizablePanes;
859 888
 
860 889
         targetSize = MAX(0, ROUND(targetSize));
861  
-
862 890
         viewFrame.size[_sizeComponent] = targetSize;
863  
-
864 891
         [view setFrame:viewFrame];
865  
-
866 892
         bounds.origin[_originComponent] += targetSize + dividerThickness;
867 893
     }
868 894
 
@@ -1020,6 +1046,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
1020 1046
 {
1021 1047
     if (_autosaveName == autosaveName)
1022 1048
         return;
  1049
+
1023 1050
     _autosaveName = autosaveName;
1024 1051
 }
1025 1052
 
@@ -1079,6 +1106,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
1079 1106
             position = 0;
1080 1107
 
1081 1108
         _shouldAutosave = NO;
  1109
+
1082 1110
         for (var i = 0, count = [frames count] - 1; i < count; i++)
1083 1111
         {
1084 1112
             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
1088 1116
 
1089 1117
             position += dividerThickness;
1090 1118
         }
  1119
+
1091 1120
         _shouldAutosave = YES;
1092 1121
     }
1093 1122
 
1094 1123
     if (preCollapseArray)
1095 1124
     {
1096 1125
         _preCollapsePositions = [CPMutableDictionary new];
  1126
+
1097 1127
         for (var i = 0, count = [preCollapseArray count]; i < count; i++)
1098 1128
             [_preCollapsePositions setObject:preCollapseArray[i] forKey:i + ""];
1099 1129
     }
@@ -1106,6 +1136,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
1106 1136
 {
1107 1137
     if (!theAutosaveName)
1108 1138
         return nil;
  1139
+
1109 1140
     return @"CPSplitView Subview Frames " + theAutosaveName;
1110 1141
 }
1111 1142
 
@@ -1116,6 +1147,7 @@ The sum of the views and the sum of the dividers should be equal to the size of
1116 1147
 {
1117 1148
     if (!theAutosaveName)
1118 1149
         return nil;
  1150
+
1119 1151
     return @"CPSplitView Subview Precollapse Positions " + theAutosaveName;
1120 1152
 }
1121 1153
 

0 notes on commit 44521a3

Please sign in to comment.
Something went wrong with that request. Please try again.