Remove most uses of the method [NSView -removeSubview:].

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33047 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-05-15 14:42:08 +00:00
parent d199cb565e
commit 6c54fd6be5
7 changed files with 50 additions and 21 deletions

View file

@ -1,3 +1,17 @@
2011-05-15 Fred Kiefer <FredKiefer@gmx.de>
* 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 <ewasylishen@gmail.com>
* Source/NSTextView.m: Use pointing hand cursor for links

View file

@ -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

View file

@ -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;

View file

@ -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];
}

View file

@ -1413,7 +1413,7 @@ static BOOL menuBarVisible = YES;
if (_view != nil)
{
// remove the old representation
[contentView removeSubview: _view];
[_view removeFromSuperview];
[_view setMenu: nil];
}

View file

@ -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

View file

@ -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)
}
/**
<p> 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. </p>
<p> Removes the receiver from its superviews list of subviews
and marks the rectangle that the reciever occupied in the
superview as needing redisplay. </p>
<p> 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];
}
}