Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
RBSplitView(RB___ViewAdditions) Category Reference

#include <RBSplitViewPrivateDefines.h>

Instance Methods

(void) - RB___adjustOutermostIfNeeded
 
(void) - RB___setDragging:
 
(CGFloat) - RB___dividerOrigin:
 
(NSArray *) - RB___subviews
 
(NSUInteger) - RB___numberOfSubviews
 
(void) - RB___adjustSubviewsExcepting:
 
(CGFloat) - RB___dimensionWithoutDividers
 
(CGFloat) - RB___dividerThickness
 
(NSRect) - RB___dividerRect:relativeToView:
 
(void) - RB___setMustClearFractions
 
(BOOL) - RB___shouldResizeWindowForDivider:betweenView:andView:willGrow:
 
(void) - RB___tryToExpandLeading:divider:trailing:delta:
 
(void) - RB___tryToShortenLeading:divider:trailing:delta:always:
 
(void) - RB___tryToExpandTrailing:leading:delta:
 
(void) - RB___tryToShortenTrailing:divider:leading:delta:always:
 
(void) - RB___trackMouseEvent:from:withBase:inDivider:
 
(void) - RB___addCursorRectsTo:forDividerRect:thickness:
 
(NSUInteger) - RB___dividerHitBy:relativeToView:thickness:
 
(void) - RB___drawDividersIn:forDividerRect:thickness:
 

Detailed Description

Definition at line 960 of file RBSplitView.m.

Method Documentation

◆ RB___addCursorRectsTo:forDividerRect:thickness:

- (void) RB___addCursorRectsTo: (RBSplitView*) masterView
forDividerRect: (NSRect) rect
thickness: (CGFloat) delta 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1370 :(RBSplitView*)masterView forDividerRect:(NSRect)rect thickness:(CGFloat)delta {
1371 if (dividers&&[self divider]) {
1372 NSArray* subviews = [self RB___subviews];
1373 NSInteger divcount = [subviews count]-1;
1374 if (divcount<1) {
1375 return;
1376 }
1377 NSInteger i;
1378 NSCursor* cursor = [RBSplitView cursor:RBSV2WayCursor];
1379 BOOL ishor = [self isHorizontal];
1380// Loop over the divider rectangles, intersect them with the view's own, and add the thumb rectangle
1381// to the containing split view.
1382 for (i=0;i<divcount;i++) {
1383 NSRect divdr = dividers[i];
1384 divdr.origin = [self convertPoint:divdr.origin toView:masterView];
1385 OTHER(divdr.origin) -= delta;
1386 OTHER(divdr.size) += 2*delta;
1387 divdr = NSIntersectionRect(divdr,rect);
1388 if (!NSIsEmptyRect(divdr)) {
1389 [masterView addCursorRect:divdr cursor:cursor];
1390 }
1391 }
1392 }
1393}
return self
#define OTHER(x)
NSCursor * cursor:(RBSVCursorType type)
Definition RBSplitView.m:33

◆ RB___adjustOutermostIfNeeded

- (void) RB___adjustOutermostIfNeeded

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1424 {
1425 RBSplitView* sv = [self splitView];
1426 if (sv) {
1428 return;
1429 }
1430 if (mustAdjust&&!isAdjusting) {
1431 [self adjustSubviews];
1432 }
1433}
void RB___adjustOutermostIfNeeded()

◆ RB___adjustSubviewsExcepting:

- (void) RB___adjustSubviewsExcepting: (RBSplitSubview*) excepting

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1440 :(RBSplitSubview*)excepting {
1441 mustAdjust = NO;
1442 NSArray* subviews = [self RB___subviews];
1443 NSUInteger subcount = [subviews count];
1444 if (subcount<1) {
1445 return;
1446 }
1447 NSRect bounds = [self bounds];
1448// Never adjust if the splitview itself is collapsed.
1449 if ((bounds.size.width<1.0)||(bounds.size.height<1.0)) {
1450 return;
1451 }
1452// Prevents adjustSubviews being called recursively, which unfortunately may happen otherwise.
1453 if (isAdjusting) {
1454 return;
1455 }
1456 isAdjusting = YES;
1457// Tell the delegate we're about to adjust subviews.
1458 if ([delegate respondsToSelector:@selector(willAdjustSubviews:)]) {
1459 [delegate willAdjustSubviews:self];
1460 bounds = [self bounds];
1461 }
1462 NSUInteger divcount = subcount-1;
1463 if (divcount<1) {
1464// No dividers at all.
1465 if (dividers) {
1466 free(dividers);
1467 dividers = NULL;
1468 }
1469 } else {
1470// Try to allocate or resize if we already have a dividers array.
1471 NSUInteger divsiz = sizeof(NSRect)*divcount;
1472 dividers = (NSRect*)(dividers?reallocf(dividers,divsiz):malloc(divsiz));
1473 if (!dividers) {
1474 return;
1475 }
1476 }
1477// This C array of subviewCaches is used to cache the subview information.
1478 subviewCache* caches = (subviewCache*)malloc(sizeof(subviewCache)*subcount);
1479 double realsize = 0.0;
1480 double expsize = 0.0;
1481 CGFloat newsize = 0.0;
1482 CGFloat effsize = 0.0;
1483 CGFloat limit;
1484 subviewCache* curr;
1485 NSUInteger i;
1486 BOOL ishor = [self isHorizontal];
1487 CGFloat divt = [self dividerThickness];
1488// First we loop over subviews and cache their information.
1489 for (i=0;i<subcount;i++) {
1490 curr = &caches[i];
1491 [[subviews objectAtIndex:i] RB___copyIntoCache:curr];
1492 }
1493// This is a counter to limit the outer loop to three iterations (six if excepting is non-nil).
1494 NSInteger sanity = excepting?-3:0;
1495 while (sanity++<3) {
1496// We try to accomodate the exception for the first group of loops, turn it off for the second.
1497 if (sanity==1) {
1498 excepting = nil;
1499 }
1500// newsize is the available space for actual subviews (so dividers don't count). It will be an integer.
1501// Same as calling [self RB___dimensionWithoutDividers].
1502 NSUInteger smallest = 0;
1503 CGFloat smalldim = -1.0;
1504 BOOL haveexp = NO;
1505// Loop over subviews and sum the expanded dimensions into expsize, including fractions.
1506// Also find the collapsed subview with the smallest minimum dimension.
1507 for (i=0;i<subcount;i++) {
1508 curr = &caches[i];
1509 curr->constrain = NO;
1510 if (curr->size>0.0) {
1511 expsize += curr->size;
1512 if (!isInScrollView) {
1513// ignore fractions if we're in a NSScrollView, however.
1514 expsize += curr->fraction;
1515 }
1516 haveexp = YES;
1517 } else {
1518 limit = [curr->sub minDimension];
1519 if (smalldim>limit) {
1520 smalldim = limit;
1521 smallest = i;
1522 }
1523 }
1524 }
1525// haveexp should be YES at this point. If not, all subviews were collapsed; can't have that, so we
1526// expand the smallest subview (or the first, if all have the same minimum).
1527 curr = &caches[smallest];
1528 if (!haveexp) {
1529 curr->size = [curr->sub minDimension];
1530 curr->fraction = 0.0;
1531 expsize += curr->size;
1532 }
1533 if (isInScrollView) {
1534// If we're inside an NSScrollView, we just grow the view to accommodate the subviews, instead of
1535// the other way around.
1536 DIM(bounds.size) = expsize;
1537 break;
1538 } else {
1539// If the total dimension of all expanded subviews is less than 1.0 we set the dimension of the smallest
1540// subview (which we're sure is expanded at this point) to the available space.
1541 newsize = DIM(bounds.size)-divcount*divt;
1542 if (expsize<1.0) {
1543 curr->size = newsize;
1544 curr->fraction = 0.0;
1545 expsize = newsize;
1546 }
1547// Loop over the subviews and check if they're within the limits after scaling. We also recalculate the
1548// exposed size and repeat until no more subviews hit the constraints during that loop.
1549 BOOL constrained;
1550 effsize = newsize;// we're caching newsize here, this is an integer.
1551 do {
1552// scale is the scalefactor by which all views should be scaled - assuming none have constraints.
1553// It's a double to (hopefully) keep rounding errors small enough for all practical purposes.
1554 double scale = newsize/expsize;
1555 constrained = NO;
1556 realsize = 0.0;
1557 expsize = 0.0;
1558 for (i=0;i<subcount;i++) {
1559// Loop over the cached subview info.
1560 curr = &caches[i];
1561 if (curr->size>0.0) {
1562// Check non-collapsed subviews only.
1563 if (!curr->constrain) {
1564// Check non-constrained subviews only; calculate the proposed new size.
1565 CGFloat cursize = (curr->size+curr->fraction)*scale;
1566// Check if we hit a limit. limit will contain either the max or min dimension, whichever was hit.
1567 if (([curr->sub RB___animationData:NO resize:NO]&&((limit = curr->size)>=0.0))||
1568 ((curr->sub==excepting)&&((limit = [curr->sub dimension])>0.0))||
1569 (cursize<(limit = [curr->sub minDimension]))||
1570 (cursize>(limit = [curr->sub maxDimension]))) {
1571// If we hit a limit, we mark the view and set to repeat the loop; non-constrained subviews will
1572// have to be recalculated.
1573 curr->constrain = constrained = YES;
1574// We set the new size to the limit we hit, and subtract it from the total size to be subdivided.
1575 cursize = limit;
1576 curr->fraction = 0.0;
1577 newsize -= cursize;
1578 } else {
1579// If we didn't hit a limit, we round the size to the nearest integer and recalculate the fraction.
1580 double rem = fmod(cursize,1.0);
1581 cursize -= rem;
1582 if (rem>0.5) {
1583 ++cursize;
1584 --rem;
1585 }
1586 expsize += cursize;
1587 curr->fraction = rem;
1588 }
1589// We store the new size in the cache.
1590 curr->size = cursize;
1591 }
1592// And add the full size with fraction to the actual sum of all expanded subviews.
1593 realsize += curr->size+curr->fraction;
1594 }
1595 }
1596// At this point, newsize will be the sum of the new dimensions of non-constrained views.
1597// expsize will be the sum of the recalculated dimensions of the same views, if any.
1598// We repeat the loop if any view has been recently constrained, and if there are any
1599// unconstrained views left.
1600 } while (constrained&&(expsize>0.0));
1601// At this point, the difference between realsize and effsize should be less than 1 pixel.
1602// realsize is the total size of expanded subviews as recalculated above, and
1603// effsize is the value realsize should have.
1604 limit = realsize-effsize;
1605 if (limit>=1.0) {
1606// If realsize is larger than effsize by 1 pixel or more, we will need to collapse subviews to make room.
1607// This in turn might expand previously collapsed subviews. So, we'll try collapsing constrained subviews
1608// until we're back into range, and then recalculate everything from the beginning.
1609 for (i=0;i<subcount;i++) {
1610 curr = &caches[i];
1611 if (curr->constrain&&(curr->sub!=excepting)&&([curr->sub RB___animationData:NO resize:NO]==nil)&&[curr->sub canCollapse]) {
1612 realsize -= curr->size;
1613 if (realsize<1.0) {
1614 break;
1615 }
1616 curr->size = 0.0;
1617 if ((realsize-effsize)<1.0) {
1618 break;
1619 }
1620 }
1621 }
1622 } else if (limit<=-1.0) {
1623// If realsize is smaller than effsize by 1 pixel or more, we will need to expand subviews.
1624// This in turn might collapse previously expanded subviews. So, we'll try expanding collapsed subviews
1625// until we're back into range, and then recalculate everything from the beginning.
1626 for (i=0;i<subcount;i++) {
1627 curr = &caches[i];
1628 if (curr->size<=0.0) {
1629 curr->size = [curr->sub minDimension];
1630 curr->fraction = 0.0;
1631 realsize += curr->size;
1632 if ((realsize-effsize)>-1.0) {
1633 break;
1634 }
1635 }
1636 }
1637 } else {
1638// The difference is less than 1 pixel, meaning that in all probability our calculations are
1639// exact or off by at most one pixel after rounding, so we break the loop here.
1640 break;
1641 }
1642 }
1643// After passing through the outer loop a few times, the frames may still be wrong, but there's nothing
1644// else we can do about it. You probably should avoid this by some other means like setting a minimum
1645// or maximum size for the window, for instance, or leaving at least one unlimited subview.
1646 }
1647// newframe is used to reset all subview frames. Subviews always fill the entire RBSplitView along the
1648// current orientation.
1649 NSRect newframe = NSMakeRect(0.0,0.0,bounds.size.width,bounds.size.height);
1650// We now loop over the subviews yet again and set the definite frames, also recalculating the
1651// divider rectangles as we go along, and collapsing and expanding subviews whenever requested.
1652 RBSplitSubview* last = nil;
1653// And we make a note if there's any nested RBSplitView.
1654 NSInteger nested = NSNotFound;
1655// newsize = DIM(bounds.size)-divcount*divt;
1656 for (i=0;i<subcount;i++) {
1657 curr = &caches[i];
1658// If we have a nested split view store its index.
1659 if ((nested==NSNotFound)&&([curr->sub asSplitView]!=nil)) {
1660 nested = i;
1661 }
1662// Adjust the subview to the correct origin and resize it to fit into the "other" dimension.
1663 curr->rect.origin = newframe.origin;
1664 OTHER(curr->rect.size) = OTHER(newframe.size);
1665 DIM(curr->rect.size) = curr->size;
1666// Clear fractions for expanded subviews if requested.
1667 if ((curr->size>0.0)&&mustClearFractions) {
1668 curr->fraction = 0.0;
1669 }
1670// Ask the subview to do the actual moving/resizing etc. from the cache.
1671 [curr->sub RB___updateFromCache:curr withTotalDimension:effsize];
1672// Step to the next position and record the subview if it's not collapsed.
1673 DIM(newframe.origin) += curr->size;
1674 if (curr->size>0.0) {
1675 last = curr->sub;
1676 }
1677 if (i==divcount) {
1678// We're at the last subview, so we now check if the actual and calculated dimensions
1679// are the same.
1680 CGFloat remain = DIM(bounds.size)-DIM(newframe.origin);
1681 if (last&&(fabs(remain)>0.0)) {
1682// We'll resize the last expanded subview to whatever it takes to squeeze within the frame.
1683// Normally the change should be at most one pixel, but if too many subviews were constrained,
1684// this may be a large value, and the last subview may be resized beyond its constraints;
1685// there's nothing else to do at this point.
1686 newframe = [last frame];
1687 DIM(newframe.size) += remain;
1688 [last RB___setFrameSize:newframe.size withFraction:[last RB___fraction]-remain];
1689// And we loop back over the rightmost dividers (if any) to adjust their offsets.
1690 while ((i>0)&&(last!=[subviews objectAtIndex:i])) {
1691 DIM(dividers[--i].origin) += remain;
1692 }
1693 break;
1694 }
1695 } else {
1696// For any but the last subview, we just calculate the divider frame.
1697 DIM(newframe.size) = divt;
1698 if (dividers) { // test for NULL to satisfy the analyzer
1699 dividers[i] = newframe;
1700 }
1701 DIM(newframe.origin) += divt;
1702 }
1703 }
1704// We resize our frame at this point, if we're inside an NSScrollView.
1705 if (isInScrollView) {
1706 [super setFrameSize:bounds.size];
1707 }
1708// If there was at least one nested RBSplitView, we loop over the subviews and adjust those that need it.
1709 for (i=nested;i<subcount;i++) {
1710 curr = &caches[i];
1711 RBSplitView* sv = [curr->sub asSplitView];
1712 if ([sv mustAdjust]) {
1713 [sv adjustSubviews];
1714 }
1715 }
1716// Free the cache array.
1717 free(caches);
1718// Clear cursor rects.
1719 mustAdjust = NO;
1720 mustClearFractions = NO;
1721 [[self window] invalidateCursorRectsForView:self];
1722// Save the state for all subviews.
1723 if (!isDragging) {
1724 [self saveState:NO];
1725 }
1726// If we're a nested RBSplitView, also invalidate cursorRects for the superview.
1727 RBSplitView* sv = [self couplingSplitView];
1728 if (sv) {
1729 [[self window] invalidateCursorRectsForView:sv];
1730 }
1731 isAdjusting = NO;
1732// Tell the delegate we're finished.
1733 if ([delegate respondsToSelector:@selector(didAdjustSubviews:)]) {
1734 [delegate didAdjustSubviews:self];
1735 }
1736}
return nil
#define DIM(x)
void RB___setFrameSize:withFraction:(NSSize size,[withFraction] double value)
void adjustSubviews()
voidpf void uLong size
Definition ioapi.h:134
voidpf uLong int origin
Definition ioapi.h:140

◆ RB___dimensionWithoutDividers

- (CGFloat) RB___dimensionWithoutDividers

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1011 {
1012 BOOL ishor = [self isHorizontal];
1013 NSSize size = [self frame].size;
1014 return fMAX(1.0,DIM(size)-[self dividerThickness]*([self RB___numberOfSubviews]-1));
1015}
static CGFloat fMAX(CGFloat a, CGFloat b)
Definition RBSplitView.m:25

◆ RB___dividerHitBy:relativeToView:thickness:

- (NSUInteger) RB___dividerHitBy: (NSPoint) point
relativeToView: (RBSplitView*) view
thickness: (CGFloat) delta 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1034 :(NSPoint)point relativeToView:(RBSplitView*)view thickness:(CGFloat)delta {
1035 if (!dividers) {
1036 return NSNotFound;
1037 }
1038 NSInteger divcount = [self RB___numberOfSubviews]-1;
1039 if (divcount<1) {
1040 return NSNotFound;
1041 }
1042 NSInteger i;
1043 BOOL ishor = [self isHorizontal];
1044 point = [self convertPoint:point fromView:view];
1045 for (i=0;i<divcount;i++) {
1046 NSRect divdr = dividers[i];
1047 OTHER(divdr.origin) -= delta;
1048 OTHER(divdr.size) += 2*delta;
1049 if ([self mouse:point inRect:divdr]) {
1050 return i;
1051 }
1052 }
1053 return NSNotFound;
1054}

◆ RB___dividerOrigin:

- (CGFloat) RB___dividerOrigin: (NSUInteger) indx

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

983 :(NSUInteger)indx {
984 CGFloat result = 0.0;
985 if (dividers) {
986 BOOL ishor = [self isHorizontal];
987 result = DIM(dividers[indx].origin);
988 }
989 return result;
990}

◆ RB___dividerRect:relativeToView:

- (NSRect) RB___dividerRect: (NSUInteger) indx
relativeToView: (RBSplitView*) view 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1020 :(NSUInteger)indx relativeToView:(RBSplitView*)view {
1021 if (dividers&&(indx<[self RB___numberOfSubviews]-1)) {
1022 NSRect result = dividers[indx];
1023 if (view&&(view!=self)) {
1024 result = [self convertRect:result toView:view];
1025 }
1026 return result;
1027 }
1028 return NSZeroRect;
1029}

◆ RB___dividerThickness

- (CGFloat) RB___dividerThickness

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1006 {
1007 return dividerThickness;
1008}

◆ RB___drawDividersIn:forDividerRect:thickness:

- (void) RB___drawDividersIn: (RBSplitView*) masterView
forDividerRect: (NSRect) rect
thickness: (CGFloat) delta 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1396 :(RBSplitView*)masterView forDividerRect:(NSRect)rect thickness:(CGFloat)delta {
1397 if (!dividers) {
1398 return;
1399 }
1400 NSArray* subviews = [self RB___subviews];
1401 NSInteger divcount = [subviews count]-1;
1402 if (divcount<1) {
1403 return;
1404 }
1405 NSInteger i;
1406 BOOL ishor = [self isHorizontal];
1407// Get the outer split view's divider image.
1408 NSImage* image = [masterView divider];
1409// Loop over the divider rectangles, intersect them with the view's own, and draw the thumb there.
1410 for (i=0;i<divcount;i++) {
1411 NSRect divdr = dividers[i];
1412 divdr.origin = [self convertPoint:divdr.origin toView:masterView];
1413 OTHER(divdr.origin) -= delta;
1414 OTHER(divdr.size) += 2*delta;
1415 divdr = NSIntersectionRect(divdr,rect);
1416 if (!NSIsEmptyRect(divdr)) {
1417 [masterView drawDivider:image inRect:divdr betweenView:nil andView:nil];
1418 }
1419 }
1420}
void drawDivider:inRect:betweenView:andView:(NSImage *anImage,[inRect] NSRect rect,[betweenView] RBSplitSubview *leading,[andView] RBSplitSubview *trailing)
NSImage * divider
Definition RBSplitView.h:28

◆ RB___numberOfSubviews

- (NSUInteger) RB___numberOfSubviews

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

972 {
973 NSUInteger result = 0;
974 for (RBSplitSubview* sub in [self subviews]) {
975 if (![sub isHidden]) {
976 ++result;
977 }
978 }
979 return result;
980}

◆ RB___setDragging:

- (void) RB___setDragging: (BOOL) flag

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

963 :(BOOL)flag {
964 BOOL save = isDragging&&!flag;
965 isDragging = flag;
966 if (save) {
967 [self saveState:NO];
968 }
969}

◆ RB___setMustClearFractions

- (void) RB___setMustClearFractions

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1057 {
1058 mustClearFractions = YES;
1059}

◆ RB___shouldResizeWindowForDivider:betweenView:andView:willGrow:

- (BOOL) RB___shouldResizeWindowForDivider: (NSUInteger) indx
betweenView: (RBSplitSubview*) leading
andView: (RBSplitSubview*) trailing
willGrow: (BOOL) grow 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1063 :(NSUInteger)indx betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing willGrow:(BOOL)grow {
1064 if (!isInScrollView&&[delegate respondsToSelector:@selector(splitView:shouldResizeWindowForDivider:betweenView:andView:willGrow:)]) {
1065 return [delegate splitView:self shouldResizeWindowForDivider:indx betweenView:leading andView:trailing willGrow:grow];
1066 }
1067 return NO;
1068}

◆ RB___subviews

- (NSArray *) RB___subviews

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

993 {
994 NSMutableArray* result = [NSMutableArray arrayWithArray:[self subviews]];
995 NSInteger i;
996 for (i=[result count]-1;i>=0;i--) {
997 RBSplitSubview* view = [result objectAtIndex:i];
998 if ([view isHidden]) {
999 [result removeObjectAtIndex:i];
1000 }
1001 }
1002 return result;
1003}
unsigned count

◆ RB___trackMouseEvent:from:withBase:inDivider:

- (void) RB___trackMouseEvent: (NSEvent*) theEvent
from: (NSPoint) where
withBase: (NSPoint) base
inDivider: (NSUInteger) indx 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1300 :(NSEvent*)theEvent from:(NSPoint)where withBase:(NSPoint)base inDivider:(NSUInteger)indx {
1301 NSArray* subviews = [self RB___subviews];
1302 NSUInteger subcount = [subviews count];
1303// Make sure that the divider number is valid.
1304 if (indx>=subcount) {
1305 return;
1306 }
1307 NSPoint result;
1308 NSUInteger k;
1309// leading and trailing point at the subviews immediately leading and trailing the divider being tracked
1310 RBSplitSubview* leading = [subviews objectAtIndex:indx];
1311 RBSplitSubview* trailing = [subviews objectAtIndex:indx+1];
1312// Convert the mouse coordinates to apply to the same system the divider rects are in.
1313 NSPoint mouse = [self convertPoint:[theEvent locationInWindow] fromView:nil];
1314 mouse.x -= base.x;
1315 mouse.y -= base.y;
1316 result.x = mouse.x-where.x;
1317 result.y = mouse.y-where.y;
1318// delta is the actual amount the mouse has moved in the relevant coordinate since the last event.
1319 BOOL ishor = [self isHorizontal];
1320 CGFloat delta = DIM(result);
1321 if (delta<0.0) {
1322// Negative delta means the mouse is being moved left or upwards.
1323// firstLeading will point at the first expanded subview to the left (or upwards) of the divider.
1324// If there's none (all subviews are collapsed) it will point at the nearest subview.
1325 RBSplitSubview* firstLeading = leading;
1326 k = indx;
1327 while (![firstLeading canShrink]) {
1328 if (k==0) {
1329 firstLeading = leading;
1330 break;
1331 }
1332 firstLeading = [subviews objectAtIndex:--k];
1333 }
1334 if (isInScrollView) {
1335 trailing = nil;
1336 }
1337// If the trailing subview is collapsed, it might be expanded if some conditions are met.
1338 if ([trailing isCollapsed]) {
1339 [self RB___tryToExpandTrailing:trailing leading:firstLeading delta:delta];
1340 } else {
1341 [self RB___tryToShortenLeading:firstLeading divider:indx trailing:trailing delta:delta always:YES];
1342 }
1343 } else if (delta>0.0) {
1344// Positive delta means the mouse is being moved right or downwards.
1345// firstTrailing will point at the first expanded subview to the right (or downwards) of the divider.
1346// If there's none (all subviews are collapsed) it will point at the nearest subview.
1347 RBSplitSubview* firstTrailing = nil;
1348 if (!isInScrollView) {
1349 firstTrailing = trailing;
1350 k = indx+1;
1351 while (![firstTrailing canShrink]) {
1352 if (++k>=subcount) {
1353 firstTrailing = trailing;
1354 break;
1355 }
1356 firstTrailing = [subviews objectAtIndex:k];
1357 }
1358 }
1359// If the leading subview is collapsed, it might be expanded if some conditions are met.
1360 if ([leading isCollapsed]) {
1361 [self RB___tryToExpandLeading:leading divider:indx trailing:firstTrailing delta:delta];
1362 } else {
1363// The leading subview is not collapsed, so we try to shorten or even collapse it
1364 [self RB___tryToShortenTrailing:firstTrailing divider:indx leading:leading delta:delta always:YES];
1365 }
1366 }
1367}
float y
float x

◆ RB___tryToExpandLeading:divider:trailing:delta:

- (void) RB___tryToExpandLeading: (RBSplitSubview*) leading
divider: (NSUInteger) indx
trailing: (RBSplitSubview*) trailing
delta: (CGFloat) delta 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1071 :(RBSplitSubview*)leading divider:(NSUInteger)indx trailing:(RBSplitSubview*)trailing delta:(CGFloat)delta {
1072 NSWindow* window = nil;
1073 NSView* document = nil;
1074 NSSize maxsize = NSMakeSize(WAYOUT,WAYOUT);
1075 NSRect frame = NSZeroRect;
1076 NSRect screen = NSMakeRect(0,0,WAYOUT,WAYOUT);
1077 BOOL ishor = NO;
1078// First we ask the delegate, if there's any, if the window should resize.
1079 BOOL dowin = ([self RB___shouldResizeWindowForDivider:indx betweenView:leading andView:trailing willGrow:YES]);
1080 if (dowin) {
1081// We initialize the other local variables only if we need them for the window.
1082 ishor = [self isHorizontal];
1083 document = [[self enclosingScrollView] documentView];
1084 if (document) {
1085 frame = [document frame];
1086 } else {
1087 window = [self window];
1088 frame = [window frame];
1089 maxsize = [window maxSize];
1090 screen = [[NSScreen mainScreen] visibleFrame];
1091 }
1092 }
1093// The mouse has to move over half of the expanded size (plus hysteresis) and the expansion shouldn't
1094// reduce the trailing subview to less than its minimum size (or grow the window beyond its maximum).
1095 CGFloat limit = [leading minDimension];
1096 CGFloat dimension = 0.0;
1097 if (dowin) {
1098 CGFloat maxd = fMAX(0.0,(ishor?frame.origin.y-screen.origin.y:(screen.origin.x+screen.size.width)-(frame.origin.x+frame.size.width)));
1099 dimension = fMIN(DIM(maxsize)-DIM(frame.size),maxd);
1100 } else {
1101 dimension = trailing?[trailing dimension]:WAYOUT;
1102 }
1103 if (limit>dimension) {
1104 return;
1105 }
1106 if (!dowin&&trailing) {
1107 limit += [trailing minDimension];
1108 if (limit>dimension) {
1109// If the trailing subview is going below its minimum, we try to collapse it first.
1110// However, we don't collapse if that would cause the leading subview to become larger than its maximum.
1111 if (([trailing canCollapse])&&(delta>(0.5+HYSTERESIS)*dimension)&&([leading maxDimension]<=dimension)) {
1112 delta = -[trailing RB___collapse];
1113 [leading changeDimensionBy:delta mayCollapse:NO move:NO];
1114 }
1115 return;
1116 }
1117 }
1118// The leading subview may be expanded normally.
1119 delta = -[leading changeDimensionBy:delta mayCollapse:NO move:NO];
1120 if (dowin) {
1121// If it does expand, we widen the window.
1122 DIM(frame.size) -= delta;
1123 if (ishor) {
1124 DIM(frame.origin) += delta;
1125 }
1126 if (document) {
1127 [document setFrame:frame];
1128 [document setNeedsDisplay:YES];
1129 } else {
1130 [window setFrame:frame display:YES];
1131 }
1132 [self setMustAdjust];
1133 } else {
1134// If it does expand, we shorten the trailing subview.
1135 [trailing changeDimensionBy:delta mayCollapse:NO move:YES];
1136 }
1137}
#define HYSTERESIS
#define WAYOUT
static CGFloat fMIN(CGFloat a, CGFloat b)
Definition RBSplitView.m:21
CGFloat changeDimensionBy:mayCollapse:move:(CGFloat increment,[mayCollapse] BOOL mayCollapse,[move] BOOL move)

◆ RB___tryToExpandTrailing:leading:delta:

- (void) RB___tryToExpandTrailing: (RBSplitSubview*) trailing
leading: (RBSplitSubview*) leading
delta: (CGFloat) delta 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1267 :(RBSplitSubview*)trailing leading:(RBSplitSubview*)leading delta:(CGFloat)delta {
1268// The mouse has to move over half of the expanded size (plus hysteresis) and the expansion shouldn't
1269// reduce the leading subview to less than its minimum size. If it does, we try to collapse it first.
1270// However, we don't collapse if that would cause the trailing subview to become larger than its maximum.
1271 CGFloat limit = trailing?[trailing minDimension]:0.0;
1272 CGFloat dimension = [leading dimension];
1273 if (limit>dimension) {
1274 return;
1275 }
1276 limit += [leading minDimension];
1277 if (limit>dimension) {
1278 if ([leading canCollapse]&&(-delta>(0.5+HYSTERESIS)*dimension)&&((trailing?[trailing maxDimension]:0.0)<=dimension)) {
1279 delta = -[leading RB___collapse];
1280 [trailing changeDimensionBy:delta mayCollapse:NO move:YES];
1281 }
1282 return;
1283 }
1284// The trailing subview may be expanded normally. If it does expand, we shorten the leading subview.
1285 if (trailing) {
1286 delta = -[trailing changeDimensionBy:-delta mayCollapse:NO move:YES];
1287 }
1288 [leading changeDimensionBy:delta mayCollapse:NO move:NO];
1289}

◆ RB___tryToShortenLeading:divider:trailing:delta:always:

- (void) RB___tryToShortenLeading: (RBSplitSubview*) leading
divider: (NSUInteger) indx
trailing: (RBSplitSubview*) trailing
delta: (CGFloat) delta
always: (BOOL) always 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1142 :(RBSplitSubview*)leading divider:(NSUInteger)indx trailing:(RBSplitSubview*)trailing delta:(CGFloat)delta always:(BOOL)always {
1143 NSWindow* window = nil;
1144 NSView* document = nil;
1145 NSSize minsize = NSZeroSize;
1146 NSRect frame = NSZeroRect;
1147 BOOL ishor = NO;
1148// First we ask the delegate, if there's any, if the window should resize.
1149 BOOL dowin = ([self RB___shouldResizeWindowForDivider:indx betweenView:leading andView:trailing willGrow:NO]);
1150 if (dowin) {
1151// We initialize the other local variables only if we need them for the window.
1152 ishor = [self isHorizontal];
1153 document = [[self enclosingScrollView] documentView];
1154 if (document) {
1155 frame = [document frame];
1156 } else {
1157 window = [self window];
1158 frame = [window frame];
1159 minsize = [window minSize];
1160 }
1161 }
1162// We avoid making the trailing subview larger than its maximum, or the window smaller than its minimum.
1163 CGFloat limit = 0.0;
1164 if (dowin) {
1165 limit = DIM(frame.size)-DIM(minsize);
1166 } else {
1167 limit = trailing?([trailing maxDimension]-[trailing dimension]):WAYOUT;
1168 }
1169 if (-delta>limit) {
1170 if (always) {
1171 delta = -limit;
1172 } else {
1173 return;
1174 }
1175 }
1176 BOOL okl = limit>=[leading dimension];
1177 if (always||okl) {
1178// Resize leading.
1179 delta = -[leading changeDimensionBy:delta mayCollapse:okl move:NO];
1180 if (dowin) {
1181// Resize the window.
1182 DIM(frame.size) -= delta;
1183 if (ishor) {
1184 DIM(frame.origin) += delta;
1185 }
1186 if (document) {
1187 [document setFrame:frame];
1188 [document setNeedsDisplay:YES];
1189 } else {
1190 [window setFrame:frame display:YES];
1191 }
1192 [self setMustAdjust];
1193 } else {
1194// Otherwise, resize trailing.
1195 [trailing changeDimensionBy:delta mayCollapse:NO move:YES];
1196 }
1197 }
1198}

◆ RB___tryToShortenTrailing:divider:leading:delta:always:

- (void) RB___tryToShortenTrailing: (RBSplitSubview*) trailing
divider: (NSUInteger) indx
leading: (RBSplitSubview*) leading
delta: (CGFloat) delta
always: (BOOL) always 

Extends class RBSplitView.

Definition at line 25 of file RBSplitView.m.

1203 :(RBSplitSubview*)trailing divider:(NSUInteger)indx leading:(RBSplitSubview*)leading delta:(CGFloat)delta always:(BOOL)always {
1204 NSWindow* window = nil;
1205 NSView* document = nil;
1206 NSSize maxsize = NSMakeSize(WAYOUT,WAYOUT);
1207 NSRect frame = NSZeroRect;
1208 NSRect screen = NSMakeRect(0,0,WAYOUT,WAYOUT);
1209 BOOL ishor = NO;
1210// First we ask the delegate, if there's any, if the window should resize.
1211 BOOL dowin = ([self RB___shouldResizeWindowForDivider:indx betweenView:leading andView:trailing willGrow:YES]);
1212 if (dowin) {
1213// We initialize the other local variables only if we need them for the window.
1214 ishor = [self isHorizontal];
1215 document = [[self enclosingScrollView] documentView];
1216 if (document) {
1217 frame = [document frame];
1218 } else {
1219 window = [self window];
1220 frame = [window frame];
1221 maxsize = [window maxSize];
1222 screen = [[NSScreen mainScreen] visibleFrame];
1223 }
1224 }
1225// We avoid making the leading subview larger than its maximum, or the window larger than its maximum.
1226 CGFloat limit = 0.0;
1227 if (dowin) {
1228 CGFloat maxd = fMAX(0.0,(ishor?frame.origin.y-screen.origin.y:(screen.origin.x+screen.size.width)-(frame.origin.x+frame.size.width)));
1229 limit = fMIN(DIM(maxsize)-DIM(frame.size),maxd);
1230 } else {
1231 limit = [leading maxDimension]-[leading dimension];
1232 }
1233 if (delta>limit) {
1234 if (always) {
1235 delta = limit;
1236 } else {
1237 return;
1238 }
1239 }
1240 BOOL okl = dowin||(limit>=(trailing?[trailing dimension]:WAYOUT));
1241 if (always||okl) {
1242 if (dowin) {
1243// If we should resize the window, resize leading, then the window.
1244 delta = [leading changeDimensionBy:delta mayCollapse:NO move:NO];
1245 DIM(frame.size) += delta;
1246 if (ishor) {
1247 DIM(frame.origin) -= delta;
1248 }
1249 if (document) {
1250 [document setFrame:frame];
1251 [document setNeedsDisplay:YES];
1252 } else {
1253 [window setFrame:frame display:YES];
1254 }
1255 [self setMustAdjust];
1256 } else {
1257// Otherwise, resize trailing, then leading.
1258 if (trailing) {
1259 delta = -[trailing changeDimensionBy:-delta mayCollapse:okl move:YES];
1260 }
1261 [leading changeDimensionBy:delta mayCollapse:NO move:NO];
1262 }
1263 }
1264}

The documentation for this category was generated from the following files: