Implemented adjusting subviews only the first time the splitview is

displayed; fixed some delegate messaging which was done the wrong way


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9040 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2001-02-07 22:06:32 +00:00
parent d598cf4c69
commit c5f8ada48b

View file

@ -3,14 +3,16 @@
Allows multiple views to share a region in a window Allows multiple views to share a region in a window
Copyright (C) 1996 Free Software Foundation, Inc. Copyright (C) 1996, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Author: Robert Vasvari < vrobi@ddrummer.com > Author: Robert Vasvari <vrobi@ddrummer.com>
Date: Jul 1998 Date: Jul 1998
Author: Felipe A. Rodriguez < far@ix.netcom.com > Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: November 1998 Date: November 1998
Author: Richard Frith-Macdonald < richard@brainstorm.co.uk > Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: January 1999 Date: January 1999
Author: Nicola Pero <n.pero@mi.flashnet.it>
Date: 2000, 2001
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
@ -56,6 +58,7 @@
ASSIGN (_backgroundColor, [NSColor controlBackgroundColor]); ASSIGN (_backgroundColor, [NSColor controlBackgroundColor]);
ASSIGN (_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]); ASSIGN (_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]);
_never_displayed_before = YES;
_autoresizes_subviews = NO; _autoresizes_subviews = NO;
} }
return self; return self;
@ -392,115 +395,107 @@
[self display]; [self display];
} }
- (void) _adjustSubviews
{
SEL delegateMethod = @selector (splitView:resizeSubviewsWithOldSize:);
if (_delegate != nil && [_delegate respondsToSelector: delegateMethod])
{
[_delegate splitView: self resizeSubviewsWithOldSize: _frame.size];
}
else
{
[self adjustSubviews];
}
}
- (void) adjustSubviews - (void) adjustSubviews
{ {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSArray *subs = [self subviews];
unsigned count = [subs count];
NSView *views[count];
NSRect frames[count];
NSSize newSize;
NSPoint newPoint;
unsigned i;
NSRect r;
float oldTotal;
float newTotal;
float scale;
float running;
[nc postNotificationName: NSSplitViewWillResizeSubviewsNotification [nc postNotificationName: NSSplitViewWillResizeSubviewsNotification
object: self]; object: self];
if (_delegate && [_delegate
respondsToSelector: [subs getObjects: views];
@selector(splitView:resizeSubviewsWithOldSize:)]) if (_isVertical == NO)
{ {
[_delegate splitView: self resizeSubviewsWithOldSize: _frame.size]; newTotal = NSHeight(_bounds) - _dividerWidth*(count - 1);
oldTotal = 0.0;
for (i = 0; i < count; i++)
{
frames[i] = [views[i] frame];
oldTotal += NSHeight(frames[i]);
}
scale = newTotal/oldTotal;
running = 0.0;
for (i = 0; i < count; i++)
{
float newHeight;
r = [views[i] frame];
newHeight = NSHeight(frames[i]) * scale;
if (i == count - 1)
{
newHeight = floor(newHeight);
}
else
{
newHeight = ceil(newHeight);
}
newSize = NSMakeSize(NSWidth(_bounds), newHeight);
newPoint = NSMakePoint(0.0, running);
running += newHeight + _dividerWidth;
[views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint];
}
} }
else else
{ /* split the area up evenly */ {
NSArray *subs = [self subviews]; newTotal = NSWidth(_bounds) - _dividerWidth*(count - 1);
unsigned count = [subs count]; oldTotal = 0.0;
NSView *views[count]; for (i = 0; i < count; i++)
NSRect frames[count];
NSSize newSize;
NSPoint newPoint;
unsigned i;
NSRect r;
float oldTotal;
float newTotal;
float scale;
float running;
[subs getObjects: views];
if (_isVertical == NO)
{ {
newTotal = NSHeight(_bounds) - _dividerWidth*(count - 1); oldTotal += NSWidth([views[i] frame]);
oldTotal = 0.0;
for (i = 0; i < count; i++)
{
frames[i] = [views[i] frame];
oldTotal += NSHeight(frames[i]);
}
scale = newTotal/oldTotal;
running = 0.0;
for (i = 0; i < count; i++)
{
float newHeight;
r = [views[i] frame];
newHeight = NSHeight(frames[i]) * scale;
if (i == count - 1)
{
newHeight = floor(newHeight);
}
else
{
newHeight = ceil(newHeight);
}
newSize = NSMakeSize(NSWidth(_bounds), newHeight);
newPoint = NSMakePoint(0.0, running);
running += newHeight + _dividerWidth;
[views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint];
}
} }
else scale = newTotal/oldTotal;
running = 0.0;
for (i = 0; i < count; i++)
{ {
newTotal = NSWidth(_bounds) - _dividerWidth*(count - 1); float newWidth;
oldTotal = 0.0;
for (i = 0; i < count; i++) r = [views[i] frame];
newWidth = NSWidth(r) * scale;
if (i == count - 1)
{ {
oldTotal += NSWidth([views[i] frame]); newWidth = floor(newWidth);
} }
scale = newTotal/oldTotal; else
running = 0.0;
for (i = 0; i < count; i++)
{ {
float newWidth; newWidth = ceil(newWidth);
r = [views[i] frame];
newWidth = NSWidth(r) * scale;
if (i == count - 1)
{
newWidth = floor(newWidth);
}
else
{
newWidth = ceil(newWidth);
}
newSize = NSMakeSize(newWidth, NSHeight(_bounds));
newPoint = NSMakePoint(running, 0.0);
running += newWidth + _dividerWidth;
[views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint];
} }
newSize = NSMakeSize(newWidth, NSHeight(_bounds));
newPoint = NSMakePoint(running, 0.0);
running += newWidth + _dividerWidth;
[views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint];
} }
} }
[nc postNotificationName: NSSplitViewDidResizeSubviewsNotification [nc postNotificationName: NSSplitViewDidResizeSubviewsNotification
object: self]; object: self];
}
- (void) addSubview: (NSView*)aView
positioned: (NSWindowOrderingMode)place
relativeTo: (NSView*)otherView
{
[super addSubview: aView positioned: place relativeTo: otherView];
[self adjustSubviews];
}
- (void) addSubview: aView
{
[super addSubview: aView];
[self adjustSubviews];
} }
- (float) dividerThickness - (float) dividerThickness
@ -603,24 +598,22 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
} }
/* draw the dimples */ /* draw the dimples */
{ for (i = 0; i < (count-1); i++)
for (i = 0; i < (count-1); i++) {
{ v = [subs objectAtIndex: i];
v = [subs objectAtIndex: i]; divRect = [v frame];
divRect = [v frame]; if (_isVertical == NO)
if (_isVertical == NO) {
{ divRect.origin.y = NSMaxY (divRect);
divRect.origin.y = NSMaxY (divRect); divRect.size.height = _dividerWidth;
divRect.size.height = _dividerWidth; }
} else
else {
{ divRect.origin.x = NSMaxX (divRect);
divRect.origin.x = NSMaxX (divRect); divRect.size.width = _dividerWidth;
divRect.size.width = _dividerWidth; }
} [self drawDividerInRect: divRect];
[self drawDividerInRect: divRect]; }
}
}
} }
- (NSImage*) dimpleImage - (NSImage*) dimpleImage
@ -642,10 +635,44 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize - (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{ {
[super resizeWithOldSuperviewSize: oldSize]; [super resizeWithOldSuperviewSize: oldSize];
[self adjustSubviews]; [self _adjustSubviews];
[_window invalidateCursorRectsForView: self]; [_window invalidateCursorRectsForView: self];
} }
- (void) displayIfNeededInRectIgnoringOpacity: (NSRect)aRect
{
if (_window == nil)
{
return;
}
if (_never_displayed_before == YES)
{
[self _adjustSubviews];
_never_displayed_before = NO;
}
[super displayIfNeededInRectIgnoringOpacity: aRect];
}
- (void) displayRectIgnoringOpacity: (NSRect)aRect
{
if (_window == nil)
{
return;
}
if (_never_displayed_before == YES)
{
[self _adjustSubviews];
_never_displayed_before = NO;
}
[super displayRectIgnoringOpacity: aRect];
}
- (id) delegate - (id) delegate
{ {
return _delegate; return _delegate;