mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 19:50:38 +00:00
* 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:
parent
a2088a66a9
commit
79ee526fc5
3 changed files with 62 additions and 0 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue