-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYSizeFixxerSubview.m
51 lines (40 loc) · 1.64 KB
/
SSYSizeFixxerSubview.m
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
#import "SSYSizeFixxerSubview.h"
@implementation SSYSizeFixxerSubview
+ (BOOL)shallowlyGetFixedSize_p:(NSSize *)size_p
defaultSize:(NSSize)defaultSize
fromSubviews:(NSArray *)subviews {
// Set a large default fixed size for defensive programming
*size_p = defaultSize ;
// Set to the size of the Size Fixxer Subview
BOOL didFindSSYSizeFixxerSubview = NO ;
for (NSView* subview in subviews) {
if ([subview isKindOfClass:[SSYSizeFixxerSubview class]]) {
*size_p = [subview frame].size ;
didFindSSYSizeFixxerSubview = YES ;
break ;
}
}
return didFindSSYSizeFixxerSubview ;
}
+ (NSSize)fixedSizeAmongSubviews:(NSArray *)subviews
defaultSize:(NSSize)defaultSize {
NSSize size;
BOOL didFindSSYSizeFixxerSubview = [self shallowlyGetFixedSize_p:&size
defaultSize:defaultSize
fromSubviews:subviews] ;
if (!didFindSSYSizeFixxerSubview) {
if ([subviews count] == 1) {
// The subview is a thin wrapper around another view.
NSView* innerView = [subviews objectAtIndex:0] ;
NSArray* innerSubviews = [innerView subviews] ;
didFindSSYSizeFixxerSubview = [self shallowlyGetFixedSize_p:&size
defaultSize:defaultSize
fromSubviews:innerSubviews] ;
}
}
if (!didFindSSYSizeFixxerSubview) {
// This will occur for the two spacers, NSToolbarFlexibleSpaceItem
}
return size ;
}
@end