2
2
3
3
NSString * const constDiscontiguousTabViewHierarchyString = @" Discontiguous tab view hierarchy" ;
4
4
5
+ @interface NSView (SSYTabSubviews)
5
6
6
- @implementation SSYHierarchicalTabViewItem
7
+ - ( NSTabViewItem *) deeplySelectedTabViewItem ;
7
8
8
- - (NSTabViewItem *)selectedChild {
9
+ @end
10
+
11
+ @implementation NSView (SSYTabSubviews)
12
+
13
+ - (NSTabViewItem *)deeplySelectedTabViewItem {
9
14
NSTabViewItem * selectedChild = nil ;
10
- for (NSTabView * subview in [[self view ] subviews ]) {
11
- if ([subview isKindOfClass: [NSTabView class ]]) {
12
- selectedChild = [subview selectedTabViewItem ] ;
13
- // Note that we consider only the *first* subview which is an
14
- // NSTabView. For this method to make sense, this must also be the
15
- // *only* subview which is an NSTabViewItem.
16
- break ;
17
- }
15
+ if ([self respondsToSelector: @selector (selectedTabViewItem )]) {
16
+ // self is a tab view
17
+ selectedChild = [(NSTabView *)self selectedTabViewItem ] ;
18
18
}
19
-
20
- // The following code seems to have been a good guess. That is,
21
- // it seems to work, but I haven't really thought it through.
22
- // The idea is that it can reach down to find a tab view through, I
23
- // think, one level of NSView subview. I need this for the topTabView
24
- // in BookMacster. This "feature" is not explained in the header doc.
25
- if (!selectedChild) {
26
- for (NSView * subview in [[self view ] subviews ]) {
27
- // NSLog(@"2 Considering subview %@", subview) ;
28
- if ([subview respondsToSelector: @selector (subviews )]) {
29
- for (NSTabView * innerSubview in [subview subviews ]) {
30
- // NSLog(@"3 Considering innerSubview %@", innerSubview) ;
31
- if ([innerSubview isKindOfClass: [NSTabView class ]]) {
32
- selectedChild = [innerSubview selectedTabViewItem ] ;
33
- // Note that we consider only the *first* subview which is an
34
- // NSTabView. For this method to make sense, this must also be the
35
- // *only* subview which is an NSTabViewItem.
36
- break ;
37
- }
38
- }
39
- }
40
-
19
+ else {
20
+ for (NSView * subview in [self subviews ]) {
21
+ selectedChild = [subview deeplySelectedTabViewItem ] ;
41
22
if (selectedChild) {
42
23
break ;
43
24
}
@@ -47,58 +28,37 @@ - (NSTabViewItem*)selectedChild {
47
28
return selectedChild ;
48
29
}
49
30
31
+
32
+ @end
33
+
34
+ @implementation SSYHierarchicalTabViewItem
35
+
36
+ - (NSTabViewItem *)selectedChild {
37
+ NSTabViewItem * selectedChild = [[self view ] deeplySelectedTabViewItem ] ;
38
+
39
+ return selectedChild ;
40
+ }
41
+
50
42
- (NSTabViewItem *)selectedLeafmostTabViewItem {
51
43
NSTabViewItem * leafItem = self ;
52
44
NSTabViewItem * selectedChild = nil ;
53
- do {
45
+ do {
54
46
// This is in case the leaf item in a tree of SSYHierarchicalTabViewItem
55
47
// objects is not itself a class descendant of
56
48
// SSYHierarchicalTabViewItem. It is also for safety,
57
49
// in case someone sends this message to a tab view item
58
50
// which is not or does not inherit from this class.
59
51
if (![leafItem respondsToSelector: @selector (selectedChild )]) {
60
- break ;
52
+ break ;
61
53
}
62
54
63
55
selectedChild = [(SSYHierarchicalTabViewItem*)leafItem selectedChild ] ;
64
- if ([selectedChild isKindOfClass: [NSTabViewItem class ]]) {
56
+ if ([selectedChild isKindOfClass: [NSTabViewItem class ]]) {
65
57
leafItem = selectedChild ;
66
58
}
67
59
} while (selectedChild != nil ) ;
68
60
69
61
return leafItem ;
70
62
}
71
63
72
- - (BOOL )isDeeplySelected {
73
- NSView * view = [[[self view ] window ] contentView ] ;
74
- NSTabViewItem * tabViewItem = nil ;
75
- BOOL answer = NO ;
76
- while (view != nil ) {
77
- NSArray * subviews = [view subviews ] ;
78
- view = nil ;
79
- for (NSTabView * tabView in subviews) {
80
- // Of course, tabView is not necessarily an NSTabView. Test it…
81
- if ([tabView isKindOfClass: [NSTabView class ]]) {
82
- tabViewItem = [tabView selectedTabViewItem ] ;
83
- view = [tabViewItem view ] ;
84
- break ;
85
- }
86
- }
87
-
88
- if (tabViewItem == self) {
89
- answer = YES ;
90
- break ;
91
- }
92
- else if (!tabViewItem) {
93
- NSLog (
94
- @" %@ : %@ " ,
95
- constDiscontiguousTabViewHierarchyString,
96
- [self identifier ]) ;
97
- }
98
- }
99
- // NSLog(@"<< %s is returning %hhd for %@", __PRETTY_FUNCTION__, answer, [self identifier]) ;
100
-
101
- return answer ;
102
- }
103
-
104
64
@end
0 commit comments