@@ -9,6 +9,7 @@ @implementation SSYLazyView
9
9
- (id )initWithFrame : (NSRect )frame {
10
10
self = [super initWithFrame: frame] ;
11
11
if (self) {
12
+ /* SSYDBL*/ NSLog (@" %@ did init" , self) ;
12
13
// Initialization code here.
13
14
}
14
15
@@ -23,43 +24,80 @@ + (NSString*)lazyNibName {
23
24
return @" Internal Error 939-7834" ;
24
25
}
25
26
26
- - (void )load {
27
- #if 11
28
- #warning Not loading any tabs
29
- return ;
30
- #endif
31
- if ([self isLoaded ]) {
27
+ - (void )loadInWindow : (NSWindow *)window {
28
+ if ([self isLoaded ]) {
32
29
return ;
33
30
}
34
31
35
32
NSString * nibName = [[self class ] lazyNibName ] ;
36
33
Class viewControllerClass = [[self class ] lazyViewControllerClass ] ;
37
34
SSYExtrospectiveViewController* viewCon = [(SSYExtrospectiveViewController*)[viewControllerClass alloc ] initWithNibName: nibName
38
35
bundle: nil ] ;
39
- /* SSYDBL*/ NSLog (@" %@ will load nib %@ and instantiate %@ " , [self className ], nibName, [viewCon className ]) ;
40
36
[self setViewController: viewCon] ;
41
- [viewCon setWindow: [self window ]] ; // experimental
42
- // /*SSYDBL*/ NSLog(@"7651 %@ has view %@ in window %@", viewCon, [viewCon view], [viewCon window]) ;
37
+ [viewCon setWindow: window] ; // experimental
43
38
[viewCon release ] ;
44
39
[viewCon loadView ] ;
45
40
46
- [self addSubview: [viewCon view ]] ;
41
+ // Remove any placeholder subviews. In BookMacster, there are two…
42
+ // (0) An SSYSizeFixxerSubview.
43
+ // (1) A text field with a string that says "Loading <Something>…"
44
+ NSInteger nSubviews = [[self subviews ] count ] ;
45
+ for (NSInteger i=(nSubviews-1 ); i>=0 ; i--) {
46
+ NSView * subview = [[self subviews ] objectAtIndex: i] ;
47
+ [subview removeFromSuperviewWithoutNeedingDisplay ] ;
48
+ }
49
+
50
+ // Resize the incoming new view
51
+ NSView * newView = [viewCon view ] ;
52
+ NSRect frame = NSMakeRect (
53
+ [newView frame ].origin .x ,
54
+ [newView frame ].origin .y ,
55
+ [self frame ].size .width ,
56
+ [self frame ].size .height
57
+ ) ;
58
+ [newView setFrame: frame] ;
59
+
60
+ // Place the incoming new view.
61
+ [self addSubview: newView] ;
62
+ [self display ] ;
63
+
64
+ #if 0
65
+ /*
66
+ I considered actually swapping in [viewCon view] in place of the
67
+ receiver, and allowing the receiver to be released and deallocced.
68
+ But that is too messy because not only does the tab view item need
69
+ to get a new view, but the outlet to this Lazy View, needed for other
70
+ purposes, from the window controller, would need to be rewired.
71
+ Before realizing that this was approach was the more problematic,
72
+ I solved the first problem, but not the second, by doing this…
73
+ */
74
+ if (parentTabViewItem) {
75
+ // parentTabViewItem is an outlet. (More mess)
76
+ [parentTabViewItem setView:[viewCon view]] ;
77
+ }
78
+ else {
79
+ NSView* superview = [self superview] ;
80
+ [superview addSubview:[viewCon view]] ;
81
+ }
82
+ #endif
47
83
48
84
[self setIsLoaded: YES ] ;
49
85
}
50
86
51
87
- (void )viewDidMoveToWindow {
88
+ /* SSYDBL*/ NSLog (@" %@ did move to window" , self) ;
52
89
[super viewDidMoveToWindow ] ;
53
90
54
91
#if 11
55
- #define LAZY_LOAD_DELAY 1 .0
92
+ #define LAZY_LOAD_DELAY 0 .0
56
93
#endif
57
- [self performSelector: @selector (load )
58
- withObject: nil
94
+ [self performSelector: @selector (loadInWindow: )
95
+ withObject: [ self window ]
59
96
afterDelay: LAZY_LOAD_DELAY] ;
60
97
}
61
98
62
99
- (void )dealloc {
100
+ /* SSYDBL*/ NSLog (@" %@ is dealloccing" , self) ;
63
101
[m_viewController release ] ;
64
102
65
103
[super dealloc ] ;
0 commit comments