diff --git a/ChangeLog b/ChangeLog index cc0453422..b55359964 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-05-15 Fred Kiefer + + * Source/NSView.m (-removeFromSuperview): Use + removeFromSuperviewWithoutNeedingDisplay. + * Source/GSWindowDecorationView.m: Add method [NSWindow + -_clearContentView] to avoid recursion when removing the content view. + * Source/GSWindowDecorationView.m: Replace the method + -removeSubview: with -willRemoveSubview:. + * Source/NSScrollView.m: Dito. + * Source/NSClipView.m (-initWithCoder:): Use -removeFromSuperview + instead of -removeSubview:. + * Source/NSMenu.m (-setMenuRepresentation:): Dito. + * Source/NSColorPanel.m (-setAccessoryView:): Dito. + 2011-05-15 Eric Wasylishen * Source/NSTextView.m: Use pointing hand cursor for links diff --git a/Source/GSWindowDecorationView.m b/Source/GSWindowDecorationView.m index ffd88fad2..18322f8d9 100644 --- a/Source/GSWindowDecorationView.m +++ b/Source/GSWindowDecorationView.m @@ -38,6 +38,20 @@ #import "NSToolbarFrameworkPrivate.h" +@interface NSWindow (GSWindowDecorationView) +- (void)_clearContentView; +@end + +@implementation NSWindow (GSWindowDecorationView) +/* This method prevents a recursion when removing the contet view of a window. + The method [NSWindow -setContentView:] would again lead to a call to -willRemoveSubview:. +*/ +- (void)_clearContentView +{ + _contentView = nil; +} +@end + @implementation GSWindowDecorationView static inline NSRect RectWithSizeScaledByFactor(NSRect aRect, CGFloat factor) @@ -229,21 +243,19 @@ static inline NSRect RectWithSizeScaledByFactor(NSRect aRect, CGFloat factor) * the old window will automatically disappear (this is how it works * on Apple too). */ -- (void) removeSubview: (NSView*)aView +- (void) willRemoveSubview: (NSView*)aView { - RETAIN(aView); /* * If the content view is removed (for example, because it was added * to another view in another window), we must let the window know. * Otherwise, it would keep trying to resize/manage it as if it was * its content view, while it actually is now in another window! */ - [super removeSubview: aView]; + [super willRemoveSubview: aView]; if (aView == [_window contentView]) { - [_window setContentView: nil]; + [_window _clearContentView]; } - RELEASE(aView); } - (void) setBackgroundColor: (NSColor *)color diff --git a/Source/NSClipView.m b/Source/NSClipView.m index 97c149c04..6bf8c7fb3 100644 --- a/Source/NSClipView.m +++ b/Source/NSClipView.m @@ -773,6 +773,11 @@ static inline NSRect integralRect (NSRect rect, NSView *view) - (id) initWithCoder: (NSCoder*)aDecoder { self = [super initWithCoder: aDecoder]; + if (self == nil) + { + return nil; + } + if ([aDecoder allowsKeyedCoding]) { [self setAutoresizesSubviews: YES]; @@ -793,7 +798,6 @@ static inline NSRect integralRect (NSRect rect, NSView *view) if ([[self subviews] count] > 0) { NSRect rect; - id document = [aDecoder decodeObjectForKey: @"NSDocView"]; NSAssert([document class] != [NSCustomView class], @@ -802,14 +806,13 @@ static inline NSRect integralRect (NSRect rect, NSView *view) rect.origin = NSZeroPoint; [document setFrame: rect]; RETAIN(document); // prevent it from being released. - [self removeSubview: document]; + [document removeFromSuperview]; [self setDocumentView: document]; RELEASE(document); } } else { - NSView *document; BOOL temp; [self setAutoresizesSubviews: YES]; @@ -822,9 +825,11 @@ static inline NSRect integralRect (NSRect rect, NSView *view) if ([[self subviews] count] > 0) { - document = AUTORELEASE(RETAIN([[self subviews] objectAtIndex: 0])); - [self removeSubview: document]; + NSView *document = [[self subviews] objectAtIndex: 0]; + RETAIN(document); // prevent it from being released. + [document removeFromSuperview]; [self setDocumentView: document]; + RELEASE(document); } } return self; diff --git a/Source/NSColorPanel.m b/Source/NSColorPanel.m index 83c921170..9bbb2c94a 100644 --- a/Source/NSColorPanel.m +++ b/Source/NSColorPanel.m @@ -547,7 +547,7 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel; return; if (_accessoryView != nil) - [_splitView removeSubview: _accessoryView]; + [_accessoryView removeFromSuperview]; _accessoryView = aView; [_splitView addSubview: _accessoryView]; } diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 02520ae06..f4384ae59 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -1413,7 +1413,7 @@ static BOOL menuBarVisible = YES; if (_view != nil) { // remove the old representation - [contentView removeSubview: _view]; + [_view removeFromSuperview]; [_view setMenu: nil]; } diff --git a/Source/NSScrollView.m b/Source/NSScrollView.m index 55fa363a8..1f6ec3d31 100644 --- a/Source/NSScrollView.m +++ b/Source/NSScrollView.m @@ -278,7 +278,7 @@ static float scrollerWidth; [self tile]; } -- (void) removeSubview: (NSView *)aView +- (void) willRemoveSubview: (NSView *)aView { if (aView == _contentView) { @@ -292,7 +292,7 @@ static float scrollerWidth; { _cornerView = nil; } - [super removeSubview: aView]; + [super willRemoveSubview: aView]; } - (void) setHorizontalScroller: (NSScroller*)aScroller diff --git a/Source/NSView.m b/Source/NSView.m index fca5e7ac0..7608e6188 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -900,8 +900,7 @@ GSSetDragTypes(NSView* obj, NSArray *types) } /** - * Removes the receiver from its superviews list of subviews, by - * invoking the superviews [-removeSubview:] method. + * Removes the receiver from its superviews list of subviews. */ - (void) removeFromSuperviewWithoutNeedingDisplay { @@ -912,10 +911,9 @@ GSSetDragTypes(NSView* obj, NSArray *types) } /** -

Removes the receiver from its superviews list of subviews, by - invoking the superviews -removeSubview: method, and marks the - rectangle that the reciever occupied in the superview as needing - redisplay.

+

Removes the receiver from its superviews list of subviews + and marks the rectangle that the reciever occupied in the + superview as needing redisplay.

This is dangerous to use during display, since it alters the rectangles needing display. In this case, you can use the @@ -925,7 +923,7 @@ GSSetDragTypes(NSView* obj, NSArray *types) if (_super_view != nil) { [_super_view setNeedsDisplayInRect: _frame]; - [_super_view removeSubview: self]; + [self removeFromSuperviewWithoutNeedingDisplay]; } }