* Source/NSView.m (-setSubviews:): New method.

Code by Banlu Kemiyatorn <object@gmail.com>.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33068 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-05-19 08:19:13 +00:00
parent 2608a790ed
commit f4a8cab41b
3 changed files with 62 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2011-05-19 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSView.h,
* Source/NSView.m (-setSubviews:): New method.
Code by Banlu Kemiyatorn <object@gmail.com>.
2011-05-18 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSBitmapImageRep+ICNS.h

View file

@ -178,6 +178,9 @@ PACKAGE_SCOPE
- (void) sortSubviewsUsingFunction: (int (*)(id ,id ,void*))compare
context: (void*)context;
- (NSArray*) subviews;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (void) setSubviews: (NSArray *)newSubviews;
#endif
- (NSView*) superview;
- (NSWindow*) window;
- (void) viewWillMoveToSuperview: (NSView*)newSuper;

View file

@ -1056,6 +1056,59 @@ GSSetDragTypes(NSView* obj, NSArray *types)
}
}
- (void) setSubviews: (NSArray *)newSubviews
{
NSEnumerator *en;
NSView *aView;
NSMutableArray *uniqNew = [NSMutableArray array];
if (nil == newSubviews)
{
[NSException raise: NSInvalidArgumentException
format: @"Setting nil as new subviews."];
}
// Use a copy as we remove from the subviews array
en = [[NSArray arrayWithArray: _sub_views] objectEnumerator];
while ((aView = [en nextObject]))
{
if (NO == [newSubviews containsObject: aView])
{
[aView removeFromSuperview];
}
}
en = [newSubviews objectEnumerator];
while ((aView = [en nextObject]))
{
id supersub = [aView superview];
if (supersub != nil && supersub != self)
{
[NSException raise: NSInvalidArgumentException
format: @"Superviews of new subviews must be either nil or receiver."];
}
if ([uniqNew containsObject: aView])
{
[NSException raise: NSInvalidArgumentException
format: @"Duplicated new subviews."];
}
if (NO == [_sub_views containsObject: aView])
{
[self addSubview: aView];
}
[uniqNew addObject: aView];
}
ASSIGN(_sub_views, uniqNew);
// The order of the subviews may have changed
[self setNeedsDisplay: YES];
}
- (void) sortSubviewsUsingFunction: (int (*)(id ,id ,void*))compare
context: (void*)context
{