1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
|
/* Implementation of class NSStackView
Copyright (C) 2020 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: 08-08-2020
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#import "AppKit/NSStackView.h"
#import "AppKit/NSTextStorage.h"
#import "AppKit/NSTextContainer.h"
#import "AppKit/NSLayoutManager.h"
#import "AppKit/NSButton.h"
#import "GSFastEnumeration.h"
@interface NSString (__StackViewPrivate__)
- (NSRect) _rectOfString;
@end
@interface NSView (__NSViewPrivateMethods__)
- (void) _insertSubview: (NSView *)sv atIndex: (NSUInteger)idx; // implemented in NSView.m
@end
@interface NSView (__StackViewPrivate__)
- (void) _insertView: (NSView *)v atIndex: (NSUInteger)i;
- (void) _removeAllSubviews;
- (void) _addSubviews: (NSArray *)views;
@end
@interface NSStackViewContainer : NSView
{
NSMutableArray *_nonDroppedViews;
NSMutableDictionary *_customAfterSpaceMap;
}
- (NSArray *) nonDroppedViews;
- (NSDictionary *) customAfterSpaceMap;
@end
@implementation NSString (__StackViewPrivate__)
- (NSRect) _rectOfString;
{
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString: self];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *textContainer = [[NSTextContainer alloc] init];
[layoutManager addTextContainer:textContainer];
[textContainer release];
[textStorage addLayoutManager:layoutManager];
[layoutManager release];
//Figure out the bounding rectangle
NSRect stringRect =
[layoutManager boundingRectForGlyphRange:NSMakeRange(0, [layoutManager numberOfGlyphs])
inTextContainer:textContainer];
return stringRect;
}
@end
@implementation NSStackViewContainer
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
if ([coder containsValueForKey: @"NSStackViewContainerNonDroppedViews"])
{
ASSIGN(_nonDroppedViews,
[coder decodeObjectForKey: @"NSStackViewContainerNonDroppedViews"]);
}
if ([coder containsValueForKey: @"NSStackViewContainerViewToCustomAfterSpaceMap"])
{
ASSIGN(_customAfterSpaceMap,
[coder decodeObjectForKey: @"NSStackViewContainerViewToCustomAfterSpaceMap"]);
}
}
else
{
ASSIGN(_nonDroppedViews, [coder decodeObject]);
ASSIGN(_customAfterSpaceMap, [coder decodeObject]);
}
[self _addSubviews: _nonDroppedViews];
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
[super encodeWithCoder: coder];
if ([coder allowsKeyedCoding])
{
[coder encodeObject: _nonDroppedViews
forKey: @"NSStackViewContainerNonDroppedViews"];
[coder encodeObject: _customAfterSpaceMap
forKey: @"NSStackViewContainerViewToCustomAfterSpaceMap"];
}
else
{
[coder encodeObject: _nonDroppedViews];
[coder encodeObject: _customAfterSpaceMap];
}
}
- (NSArray *) nonDroppedViews
{
return _nonDroppedViews;
}
- (NSDictionary *) customAfterSpaceMap
{
return _customAfterSpaceMap;
}
@end
@implementation NSView (__StackViewPrivate__)
- (void) _insertView: (NSView *)v atIndex: (NSUInteger)i
{
[self _insertSubview: v atIndex: i];
}
- (void) _removeAllSubviews
{
NSArray *subviews = [self subviews];
FOR_IN(NSView*, v, subviews)
{
[v removeFromSuperview];
}
END_FOR_IN(subviews);
}
- (void) _addSubviews: (NSArray *)views
{
FOR_IN(NSView*, v, views)
{
[self addSubview: v];
}
END_FOR_IN(views);
}
@end
@implementation NSStackView
- (void) _layoutViewsWithOrientation: (NSUserInterfaceLayoutOrientation)o
{
NSRect currentFrame = [self frame];
NSRect newFrame = currentFrame;
NSArray *sv = [self subviews];
NSUInteger n = [sv count];
CGFloat sp = [self spacing];
CGFloat x = 0.0;
CGFloat y = 0.0;
CGFloat newHeight = 0.0;
NSUInteger i = 0;
// Advance vertically or horizontally depending on orientation...
if (o == NSUserInterfaceLayoutOrientationVertical)
{
if (sp == 0.0)
{
if (n >= 0)
{
NSView *v = [sv objectAtIndex: 0];
sp = [v frame].size.height;
}
}
newFrame.size.height += sp; // * 2; // expand height
newFrame.origin.y -= (sp / 2.0); // move the view down.
newHeight = newFrame.size.height; // start at top of view...
}
else
{
if (sp == 0.0)
{
if (n >= 0)
{
NSView *v = [sv objectAtIndex: 0];
sp = [v frame].size.width;
}
}
newFrame.size.width += sp;
}
[self setFrame: newFrame];
FOR_IN(NSView*,v,sv)
{
NSRect f;
NSString *str = nil;
NSRect sr = NSZeroRect;
if ([v respondsToSelector: @selector(title)])
{
str = [(NSButton *)v title];
}
f = [v frame];
if (f.origin.x < 0.0)
{
f.origin.x = 0.0;
}
if (str != nil)
{
sr = [str _rectOfString];
}
// Calculate control position...
if (o == NSUserInterfaceLayoutOrientationVertical)
{
y = newHeight - ((CGFloat)i * sp) - f.size.height;
f.origin.y = y;
}
else
{
x = (CGFloat)i * sp;
f.origin.x = x;
}
// expand width if control is too short for title...
if (f.size.width < sr.size.width)
{
f.size.width = sr.size.width + 5.0; //+5 to accomodate border...
}
[v setFrame: f];
i++;
}
END_FOR_IN(sv);
[self setNeedsDisplay: YES];
}
- (void) _refreshView
{
NSRect currentFrame = [self frame];
if (_beginningContainer != nil)
{
NSSize s = currentFrame.size;
NSUInteger i = 0;
CGFloat y = 0.0;
CGFloat x = 0.0;
CGFloat w = 0.0;
CGFloat h = 0.0;
if (_orientation == NSUserInterfaceLayoutOrientationHorizontal)
{
w = s.width / 3.0; // three sections, always.
h = s.height; // since we are horiz. the height is the height of the view
}
else
{
h = s.height / 3.0; // 3 sections
w = s.width;
}
for (i = 0; i < 3; i++)
{
NSRect f;
NSStackViewContainer *c = nil;
if (_orientation == NSUserInterfaceLayoutOrientationHorizontal)
{
x = w * (CGFloat)i;
}
else
{
y = h * (CGFloat)i;
}
f = NSMakeRect(x,y,w,h);
if (i == 0)
{
c = _beginningContainer;
}
if (i == 1)
{
c = _middleContainer;
}
if (i == 2)
{
c = _endContainer;
}
[super addSubview: c];
[c setFrame: f];
}
}
else
{
[self _layoutViewsWithOrientation: _orientation];
}
[self setNeedsDisplay: YES];
}
// Overridden methods
- (NSArray *) subviews
{
if (_beginningContainer != nil)
{
NSMutableArray *result = [NSMutableArray array];
[result addObjectsFromArray: [_beginningContainer nonDroppedViews]];
[result addObjectsFromArray: [_middleContainer nonDroppedViews]];
[result addObjectsFromArray: [_endContainer nonDroppedViews]];
return result;
}
return [super subviews];
}
// Properties
- (void) setDelegate: (id<NSStackViewDelegate>)delegate
{
_delegate = delegate;
}
- (id<NSStackViewDelegate>) delegate
{
return _delegate;
}
- (void) setOrientation: (NSUserInterfaceLayoutOrientation)o
{
_orientation = o;
[self _refreshView];
}
- (NSUserInterfaceLayoutOrientation) orientation
{
return _orientation;
}
- (void) setAlignment: (NSLayoutAttribute)alignment
{
_alignment = alignment;
[self _refreshView];
}
- (NSLayoutAttribute) alignment
{
return _alignment;
}
- (void) setEdgeInsets: (NSEdgeInsets)insets
{
_edgeInsets = insets;
[self _refreshView];
}
- (NSEdgeInsets) edgeInsets
{
return _edgeInsets;
}
- (void) setDistribution: (NSStackViewDistribution)d
{
_distribution = d;
[self _refreshView];
}
- (NSStackViewDistribution) distribution
{
return _distribution;
}
- (void) setSpacing: (CGFloat)f
{
_spacing = f;
[self _refreshView];
}
- (CGFloat) spacing
{
return _spacing;
}
- (void) setDetachesHiddenViews: (BOOL)f
{
_detachesHiddenViews = f;
}
- (BOOL) detachesHiddenViews
{
return _detachesHiddenViews;
}
- (void) setArrangedSubviews: (NSArray *)arrangedSubviews
{
ASSIGN(_arrangedSubviews, arrangedSubviews);
_distribution = NSStackViewDistributionFill;
[self _removeAllSubviews];
_beginningContainer = nil;
_middleContainer = nil;
_endContainer = nil;
[self _addSubviews: arrangedSubviews];
[self _refreshView];
}
- (NSArray *) arrangedSubviews
{
return [self subviews];
}
- (void) setDetachedViews: (NSArray *)detachedViews
{
ASSIGN(_detachedViews, detachedViews);
}
- (NSArray *) detachedViews
{
return _detachedViews;
}
// Instance methods
// Manage views...
- (instancetype) initWithViews: (NSArray *)views
{
self = [super init];
if (self != nil)
{
NSUInteger c = [views count];
_arrangedSubviews = [[NSMutableArray alloc] initWithArray: views];
_detachedViews = [[NSMutableArray alloc] initWithCapacity: c];
ASSIGNCOPY(_views, views);
_customSpacingMap = RETAIN([NSMapTable weakToWeakObjectsMapTable]);
_visiblePriorityMap = RETAIN([NSMapTable weakToWeakObjectsMapTable]);
// Gravity... not used by default.
_beginningContainer = nil;
_middleContainer = nil;
_endContainer = nil;
[self _refreshView];
}
return self;
}
- (void) dealloc
{
RELEASE(_arrangedSubviews);
RELEASE(_detachedViews);
RELEASE(_views);
RELEASE(_customSpacingMap);
RELEASE(_visiblePriorityMap);
RELEASE(_beginningContainer);
RELEASE(_middleContainer);
RELEASE(_endContainer);
_delegate = nil;
[super dealloc];
}
+ (instancetype) stackViewWithViews: (NSArray *)views
{
return AUTORELEASE([[self alloc] initWithViews: views]);
}
- (void) setCustomSpacing: (CGFloat)spacing afterView: (NSView *)v
{
if (_hasEqualSpacing == NO)
{
NSNumber *n = [NSNumber numberWithFloat: spacing];
[_customSpacingMap setObject: n
forKey: v];
[self _refreshView];
}
}
- (CGFloat) customSpacingAfterView: (NSView *)v
{
return [[_customSpacingMap objectForKey: v] floatValue];
}
- (void) addArrangedSubview: (NSView *)v
{
[_arrangedSubviews addObject: v];
[self _refreshView];
}
- (void) insertArrangedSubview: (NSView *)v atIndex: (NSInteger)idx
{
[_arrangedSubviews insertObject: v atIndex: idx];
}
- (void) removeArrangedSubview: (NSView *)v
{
[_arrangedSubviews removeObject: v];
}
// Custom priorities
- (void)setVisibilityPriority: (NSStackViewVisibilityPriority)priority
forView: (NSView *)v
{
NSNumber *n = [NSNumber numberWithInteger: priority];
[_visiblePriorityMap setObject: n
forKey: v];
[self _refreshView];
}
- (NSStackViewVisibilityPriority) visibilityPriorityForView: (NSView *)v
{
NSNumber *n = [_visiblePriorityMap objectForKey: v];
NSStackViewVisibilityPriority p = (NSStackViewVisibilityPriority)[n integerValue];
return p;
}
- (NSLayoutPriority)clippingResistancePriorityForOrientation:(NSLayoutConstraintOrientation)o
{
NSLayoutPriority p = 0L;
if (o == NSLayoutConstraintOrientationHorizontal)
{
p = _horizontalClippingResistancePriority;
}
else if (o == NSLayoutConstraintOrientationVertical)
{
p = _verticalClippingResistancePriority;
}
return p;
}
- (void) setClippingResistancePriority: (NSLayoutPriority)clippingResistancePriority
forOrientation: (NSLayoutConstraintOrientation)o
{
if (o == NSLayoutConstraintOrientationHorizontal)
{
_horizontalClippingResistancePriority = clippingResistancePriority;
}
else if (o == NSLayoutConstraintOrientationVertical)
{
_verticalClippingResistancePriority = clippingResistancePriority;
}
[self _refreshView];
}
- (NSLayoutPriority) huggingPriorityForOrientation: (NSLayoutConstraintOrientation)o
{
NSLayoutPriority p = 0L;
if (o == NSLayoutConstraintOrientationHorizontal)
{
p = _horizontalHuggingPriority;
}
else if (o == NSLayoutConstraintOrientationVertical)
{
p = _verticalHuggingPriority;
}
return p;
}
- (void) setHuggingPriority: (NSLayoutPriority)huggingPriority
forOrientation: (NSLayoutConstraintOrientation)o
{
if (o == NSLayoutConstraintOrientationHorizontal)
{
_horizontalHuggingPriority = huggingPriority;
}
else if (o == NSLayoutConstraintOrientationVertical)
{
_verticalHuggingPriority = huggingPriority;
}
[self _refreshView];
}
- (void) setHasEqualSpacing: (BOOL)f
{
_hasEqualSpacing = f;
}
- (BOOL) hasEqualSpacing
{
return _hasEqualSpacing;
}
- (void)addView: (NSView *)view inGravity: (NSStackViewGravity)gravity
{
if (_beginningContainer != nil)
{
switch (gravity)
{
case NSStackViewGravityTop: // or leading...
[_beginningContainer addSubview: view];
break;
case NSStackViewGravityCenter:
[_middleContainer addSubview: view];
break;
case NSStackViewGravityBottom:
[_endContainer addSubview: view]; // or trailing...
break;
default:
[NSException raise: NSInternalInconsistencyException
format: @"Attempt to add view %@ to unknown container %ld.", view, gravity];
break;
}
}
else
{
[super addSubview: view];
}
[self _refreshView];
}
- (void)insertView: (NSView *)view atIndex: (NSUInteger)index inGravity: (NSStackViewGravity)gravity
{
switch (gravity)
{
case NSStackViewGravityTop: // or leading...
[_beginningContainer _insertView: view atIndex: index];
break;
case NSStackViewGravityCenter:
[_middleContainer _insertView: view atIndex: index];
break;
case NSStackViewGravityBottom:
[_endContainer _insertView: view atIndex: index]; // or trailing...
break;
default:
[NSException raise: NSInternalInconsistencyException
format: @"Attempt insert view %@ at index %ld into unknown container %ld.", view, index, gravity];
break;
}
[self _refreshView];
}
- (void)removeView: (NSView *)view
{
[view removeFromSuperview];
[self _refreshView];
}
- (NSArray *) viewsInGravity: (NSStackViewGravity)gravity
{
NSMutableArray *result = [NSMutableArray array];
if (_beginningContainer != nil)
{
switch (gravity)
{
case NSStackViewGravityTop: // or leading...
[result addObjectsFromArray: [_beginningContainer subviews]];
break;
case NSStackViewGravityCenter:
[result addObjectsFromArray: [_middleContainer subviews]];
break;
case NSStackViewGravityBottom:
[result addObjectsFromArray: [_endContainer subviews]];
break;
default:
[NSException raise: NSInternalInconsistencyException
format: @"Attempt get array of views from unknown gravity %ld.", gravity];
break;
}
}
return result;
}
- (void)setViews: (NSArray *)views inGravity: (NSStackViewGravity)gravity
{
if (_beginningContainer != nil)
{
switch (gravity)
{
case NSStackViewGravityTop: // or leading...
[_beginningContainer _removeAllSubviews];
[_beginningContainer _addSubviews: views];
break;
case NSStackViewGravityCenter:
[_middleContainer _removeAllSubviews];
[_middleContainer _addSubviews: views];
break;
case NSStackViewGravityBottom:
[_endContainer _removeAllSubviews];
[_endContainer _addSubviews: views];
break;
default:
[NSException raise: NSInternalInconsistencyException
format: @"Attempt set array of views %@ into unknown gravity %ld.", views, gravity];
break;
}
}
else
{
[super _addSubviews: views];
}
[self _refreshView];
}
- (void) setViews: (NSArray *)views
{
ASSIGN(_arrangedSubviews, views);
[self _refreshView];
}
- (NSArray *) views
{
return _arrangedSubviews;
}
// Encoding...
- (void) encodeWithCoder: (NSCoder *)coder
{
[super encodeWithCoder: coder];
if ([coder allowsKeyedCoding])
{
[coder encodeInteger: _alignment forKey: @"NSStackViewAlignment"];
[coder encodeObject: _beginningContainer forKey: @"NSStackViewBeginningContainer"];
[coder encodeObject: _middleContainer forKey: @"NSStackViewMiddleContainer"];
[coder encodeObject: _endContainer forKey: @"NSStackViewEndContainer"];
[coder encodeBool: _detachesHiddenViews forKey: @"NSStackViewDetachesHiddenViews"];
[coder encodeFloat: _edgeInsets.bottom forKey: @"NSStackViewEdgeInsets.bottom"];
[coder encodeFloat: _edgeInsets.left forKey: @"NSStackViewEdgeInsets.left"];
[coder encodeFloat: _edgeInsets.right forKey: @"NSStackViewEdgeInsets.right"];
[coder encodeFloat: _edgeInsets.top forKey: @"NSStackViewEdgeInsets.top"];
[coder encodeBool: _hasFlagViewHierarchy forKey: @"NSStackViewHasFlagViewHierarchy"];
[coder encodeFloat: _horizontalClippingResistancePriority forKey: @"NSStackViewHorizontalClippingResistance"];
[coder encodeFloat: _horizontalHuggingPriority forKey: @"NSStackViewHorizontalHuggingPriority"];
[coder encodeInteger: _orientation forKey: @"NSStackViewOrientation"];
[coder encodeInteger: _alignment forKey: @"NSStackViewSecondaryAlignment"];
[coder encodeFloat: _spacing forKey: @"NSStackViewSpacing"];
[coder encodeFloat: _verticalClippingResistancePriority forKey: @"NSStackViewVerticalClippingResistance"];
[coder encodeFloat: _verticalHuggingPriority forKey: @"NSStackViewVerticalHuggingPriority"];
[coder encodeInteger: _distribution forKey: @"NSStackViewdistribution"];
}
else
{
[coder encodeValueOfObjCType: @encode(NSUInteger)
at: &_alignment];
[coder encodeObject: _beginningContainer];
[coder encodeObject: _middleContainer];
[coder encodeObject: _endContainer];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_detachesHiddenViews];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.bottom];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.left];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.right];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.top];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_hasFlagViewHierarchy];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_horizontalClippingResistancePriority];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_horizontalHuggingPriority];
[coder encodeValueOfObjCType: @encode(NSInteger)
at: &_orientation];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_secondaryAlignment];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_spacing];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_verticalClippingResistancePriority];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_verticalHuggingPriority];
[coder encodeValueOfObjCType: @encode(NSInteger)
at: &_distribution];
}
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
if ([coder containsValueForKey: @"NSStackViewAlignment"])
{
_alignment = [coder decodeIntForKey: @"NSStackViewAlignment"];
}
if ([coder containsValueForKey: @"NSStackViewBeginningContainer"])
{
ASSIGN(_beginningContainer, [coder decodeObjectForKey: @"NSStackViewBeginningContainer"]);
}
if ([coder containsValueForKey: @"NSStackViewMiddleContainer"])
{
ASSIGN(_middleContainer, [coder decodeObjectForKey: @"NSStackViewMiddleContainer"]);
}
if ([coder containsValueForKey: @"NSStackViewEndContainer"])
{
ASSIGN(_endContainer, [coder decodeObjectForKey: @"NSStackViewEndContainer"]);
}
if ([coder containsValueForKey: @"NSStackViewDetachesHiddenViews"])
{
_detachesHiddenViews = [coder decodeBoolForKey: @"NSStackViewDetachesHiddenViews"];
}
if ([coder containsValueForKey: @"NSStackViewEdgeInsets.bottom"])
{
_edgeInsets.bottom = [coder decodeFloatForKey: @"NSStackViewEdgeInsets.bottom"];
}
if ([coder containsValueForKey: @"NSStackViewEdgeInsets.left"])
{
_edgeInsets.left = [coder decodeFloatForKey: @"NSStackViewEdgeInsets.left"];
}
if ([coder containsValueForKey: @"NSStackViewEdgeInsets.right"])
{
_edgeInsets.right = [coder decodeFloatForKey: @"NSStackViewEdgeInsets.right"];
}
if ([coder containsValueForKey: @"NSStackViewEdgeInsets.top"])
{
_edgeInsets.top = [coder decodeFloatForKey: @"NSStackViewEdgeInsets.top"];
}
if ([coder containsValueForKey: @"NSStackViewHasFlagViewHierarchy"])
{
_hasFlagViewHierarchy = [coder decodeBoolForKey: @"NSStackViewHasFlagViewHierarchy"];
}
if ([coder containsValueForKey: @"NSStackViewHorizontalClippingResistance"])
{
_horizontalClippingResistancePriority = [coder decodeFloatForKey: @"NSStackViewHorizontalClippingResistance"];
}
if ([coder containsValueForKey: @"NSStackViewHorizontalHuggingPriority"])
{
_horizontalHuggingPriority = [coder decodeFloatForKey: @"NSStackViewHorizontalHuggingPriority"];
}
if ([coder containsValueForKey: @"NSStackViewOrientation"])
{
_orientation = [coder decodeIntForKey: @"NSStackViewOrientation"];
}
if ([coder containsValueForKey: @"NSStackViewSecondaryAlignment"])
{
_secondaryAlignment = [coder decodeFloatForKey: @"NSStackViewSecondaryAlignment"];
}
if ([coder containsValueForKey: @"NSStackViewSpacing"])
{
_spacing = [coder decodeFloatForKey: @"NSStackViewSpacing"];
}
if ([coder containsValueForKey: @"NSStackViewVerticalClippingResistance"])
{
_verticalClippingResistancePriority = [coder decodeFloatForKey: @"NSStackViewVerticalClippingResistance"];
}
if ([coder containsValueForKey: @"NSStackViewVerticalHugging"])
{
_verticalHuggingPriority = [coder decodeFloatForKey: @"NSStackViewVerticalHugging"];
}
if ([coder containsValueForKey: @"NSStackViewdistribution"])
{
_distribution = [coder decodeIntForKey: @"NSStackViewdistribution"];
}
}
else
{
[coder decodeValueOfObjCType: @encode(NSUInteger)
at: &_alignment];
ASSIGN(_beginningContainer, [coder decodeObject]);
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_detachesHiddenViews];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.bottom];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.left];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.right];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_edgeInsets.top];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_hasFlagViewHierarchy];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_horizontalClippingResistancePriority];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_horizontalHuggingPriority];
[coder decodeValueOfObjCType: @encode(NSInteger)
at: &_orientation];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_secondaryAlignment];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_spacing];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_verticalClippingResistancePriority];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_verticalHuggingPriority];
[coder decodeValueOfObjCType: @encode(NSInteger)
at: &_distribution];
}
[self _refreshView];
}
return self;
}
@end
|