Prefixed ivar names with underscore; fixing dividerThickiness stuff, tidyup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5577 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 1999-12-18 15:47:25 +00:00
parent 8898d2c51e
commit dd6b697b40

View file

@ -1,5 +1,5 @@
/* /*
NSSplitView.h NSSplitView.m
Allows multiple views to share a region in a window Allows multiple views to share a region in a window
@ -45,6 +45,19 @@
// //
// Instance methods // Instance methods
// //
- (id) initWithFrame: (NSRect)frameRect
{
if ((self = [super initWithFrame: frameRect]) != nil)
{
_dividerWidth = [self dividerThickness];
_draggedBarWidth = 8; // default bigger than dividerThickness
_isVertical = NO;
ASSIGN (_dividerColor, [NSColor controlShadowColor]);
ASSIGN (_backgroundColor, [NSColor controlBackgroundColor]);
ASSIGN (_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]);
}
return self;
}
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent - (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
{ {
return YES; return YES;
@ -60,9 +73,8 @@
id v = nil, prev = nil; id v = nil, prev = nil;
float minCoord, maxCoord; float minCoord, maxCoord;
NSArray *subs = [self subviews]; NSArray *subs = [self subviews];
int offset = 0,i,count = [subs count]; int offset = 0, i, count = [subs count];
float divVertical, divHorizontal, div = [self dividerThickness]; float divVertical, divHorizontal;
NSColor *divColor = [self dividerColor];
NSDate *farAway = [NSDate distantFuture]; NSDate *farAway = [NSDate distantFuture];
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSLeftMouseDraggedMask | NSMouseMovedMask | NSLeftMouseDraggedMask | NSMouseMovedMask
@ -89,7 +101,7 @@
NSLog(@"NSSplitView got mouseDown that should have gone to subview"); NSLog(@"NSSplitView got mouseDown that should have gone to subview");
goto RETURN_LABEL; goto RETURN_LABEL;
} }
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
if (NSMaxY(r) < p.y) if (NSMaxY(r) < p.y)
{ // can happen only when i>0. { // can happen only when i>0.
@ -137,9 +149,9 @@
prev = v; prev = v;
} }
} }
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
divVertical = div; divVertical = _dividerWidth;
divHorizontal = NSWidth(frame); divHorizontal = NSWidth(frame);
/* set the default limits on the dragging */ /* set the default limits on the dragging */
minCoord = NSMinY(bigRect) + divVertical; minCoord = NSMinY(bigRect) + divVertical;
@ -147,7 +159,7 @@
} }
else else
{ {
divHorizontal = div; divHorizontal = _dividerWidth;
divVertical = NSHeight(frame); divVertical = NSHeight(frame);
/* set the default limits on the dragging */ /* set the default limits on the dragging */
minCoord = NSMinX(bigRect) + divHorizontal; minCoord = NSMinX(bigRect) + divHorizontal;
@ -156,16 +168,16 @@
/* find out what the dragging limit is */ /* find out what the dragging limit is */
if (delegate && [delegate respondsToSelector: if (_delegate && [_delegate respondsToSelector:
@selector(splitView:constrainMinCoordinate:maxCoordinate:ofSubviewAt:)]) @selector(splitView:constrainMinCoordinate:maxCoordinate:ofSubviewAt:)])
{ {
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
float delMinY= minCoord, delMaxY= maxCoord; float delMinY= minCoord, delMaxY= maxCoord;
[delegate splitView: self [_delegate splitView: self
constrainMinCoordinate: &delMinY constrainMinCoordinate: &delMinY
maxCoordinate: &delMaxY maxCoordinate: &delMaxY
ofSubviewAt: offset]; ofSubviewAt: offset];
/* we are still constrained by the original bounds */ /* we are still constrained by the original bounds */
if (delMinY > minCoord) if (delMinY > minCoord)
minCoord = delMinY; minCoord = delMinY;
@ -175,10 +187,10 @@
else else
{ {
float delMinX= minCoord, delMaxX= maxCoord; float delMinX= minCoord, delMaxX= maxCoord;
[delegate splitView: self [_delegate splitView: self
constrainMinCoordinate: &delMinX constrainMinCoordinate: &delMinX
maxCoordinate: &delMaxX maxCoordinate: &delMaxX
ofSubviewAt: offset]; ofSubviewAt: offset];
/* we are still constrained by the original bounds */ /* we are still constrained by the original bounds */
if (delMinX > minCoord) if (delMinX > minCoord)
minCoord = delMinX; minCoord = delMinX;
@ -194,7 +206,7 @@
[NSEvent startPeriodicEventsAfterDelay: 0.1 withPeriod: 0.1]; [NSEvent startPeriodicEventsAfterDelay: 0.1 withPeriod: 0.1];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode]; [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
[divColor set]; [_dividerColor set];
r.size.width = divHorizontal; r.size.width = divHorizontal;
r.size.height = divVertical; r.size.height = divVertical;
e = [app nextEventMatchingMask: eventMask e = [app nextEventMatchingMask: eventMask
@ -207,7 +219,7 @@
{ {
if ([e type] != NSPeriodic) if ([e type] != NSPeriodic)
p = [self convertPoint: [e locationInWindow] fromView: nil]; p = [self convertPoint: [e locationInWindow] fromView: nil];
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
if (p.y < minCoord) if (p.y < minCoord)
p.y = minCoord; p.y = minCoord;
@ -228,14 +240,14 @@
NSDebugLog(@"drawing divider at x: %d, y: %d, w: %d, h: %d\n", NSDebugLog(@"drawing divider at x: %d, y: %d, w: %d, h: %d\n",
(int)NSMinX(r),(int)NSMinY(r),(int)NSWidth(r), (int)NSMinX(r),(int)NSMinY(r),(int)NSWidth(r),
(int)NSHeight(r)); (int)NSHeight(r));
[dividerColor set]; [_dividerColor set];
NSHighlightRect(r); NSHighlightRect(r);
oldRect = r; oldRect = r;
e = [app nextEventMatchingMask: eventMask e = [app nextEventMatchingMask: eventMask
untilDate: farAway untilDate: farAway
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
[dividerColor set]; [_dividerColor set];
NSHighlightRect(oldRect); NSHighlightRect(oldRect);
} }
@ -244,7 +256,7 @@
/* resize the subviews accordingly */ /* resize the subviews accordingly */
r = [prev frame]; r = [prev frame];
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
r.size.height = p.y - NSMinY(bigRect) - (divVertical/2.); r.size.height = p.y - NSMinY(bigRect) - (divVertical/2.);
if (NSHeight(r) < 1.) if (NSHeight(r) < 1.)
@ -261,7 +273,7 @@
(int)NSMinX(r),(int)NSMinY(r),(int)NSWidth(r),(int)NSHeight(r)); (int)NSMinX(r),(int)NSMinY(r),(int)NSWidth(r),(int)NSHeight(r));
r1 = [v frame]; r1 = [v frame];
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
r1.origin.y = p.y + (divVertical/2.); r1.origin.y = p.y + (divVertical/2.);
if (NSMinY(r1) < 0.) if (NSMinY(r1) < 0.)
@ -296,15 +308,15 @@ RETURN_LABEL:
- (void) adjustSubviews - (void) adjustSubviews
{ {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSRect fr = [self frame];
[nc postNotificationName: NSSplitViewWillResizeSubviewsNotification [nc postNotificationName: NSSplitViewWillResizeSubviewsNotification
object: self]; object: self];
if (delegate && [delegate respondsToSelector: if (_delegate && [_delegate
@selector(splitView:resizeSubviewsWithOldSize:)]) respondsToSelector:
@selector(splitView:resizeSubviewsWithOldSize:)])
{ {
[delegate splitView: self resizeSubviewsWithOldSize: fr.size]; [_delegate splitView: self resizeSubviewsWithOldSize: frame.size];
} }
else else
{ /* split the area up evenly */ { /* split the area up evenly */
@ -312,7 +324,6 @@ RETURN_LABEL:
unsigned count = [subs count]; unsigned count = [subs count];
NSView *views[count]; NSView *views[count];
NSRect frames[count]; NSRect frames[count];
float thickness = [self dividerThickness];
NSSize newSize; NSSize newSize;
NSPoint newPoint; NSPoint newPoint;
unsigned i; unsigned i;
@ -323,9 +334,9 @@ RETURN_LABEL:
float running; float running;
[subs getObjects: views]; [subs getObjects: views];
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
newTotal = NSHeight(bounds) - thickness*(count - 1); newTotal = NSHeight(bounds) - _dividerWidth*(count - 1);
oldTotal = 0.0; oldTotal = 0.0;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
@ -347,14 +358,14 @@ RETURN_LABEL:
newSize = NSMakeSize(NSWidth(bounds), newHeight); newSize = NSMakeSize(NSWidth(bounds), newHeight);
running -= newHeight; running -= newHeight;
newPoint = NSMakePoint(0.0, running); newPoint = NSMakePoint(0.0, running);
running -= thickness; running -= _dividerWidth;
[views[i] setFrameSize: newSize]; [views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint]; [views[i] setFrameOrigin: newPoint];
} }
} }
else else
{ {
newTotal = NSWidth(bounds) - thickness*(count - 1); newTotal = NSWidth(bounds) - _dividerWidth*(count - 1);
oldTotal = 0.0; oldTotal = 0.0;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
@ -374,7 +385,7 @@ RETURN_LABEL:
newWidth = ceil(newWidth); newWidth = ceil(newWidth);
newSize = NSMakeSize(newWidth, NSHeight(bounds)); newSize = NSMakeSize(newWidth, NSHeight(bounds));
newPoint = NSMakePoint(running, 0.0); newPoint = NSMakePoint(running, 0.0);
running += newWidth + thickness; running += newWidth + _dividerWidth;
[views[i] setFrameSize: newSize]; [views[i] setFrameSize: newSize];
[views[i] setFrameOrigin: newPoint]; [views[i] setFrameOrigin: newPoint];
} }
@ -398,26 +409,26 @@ RETURN_LABEL:
[self adjustSubviews]; [self adjustSubviews];
} }
- (float) dividerThickness //defaults to 8 - (float) dividerThickness
{ {
return dividerWidth; // You need to override this method in subclasses to change the
} // dividerThickness (or, without need for subclassing, invoke
// setDimpleImage:resetDividerThickness:YES below)
- (void) setDividerThickNess: (float)newWidth return 6;
{
dividerWidth = ceil(newWidth);
} }
// FIXME: Perhaps the following two should be removed and _dividerWidth
// should be used also for dragging?
- (float) draggedBarWidth //defaults to 8 - (float) draggedBarWidth //defaults to 8
{ {
return draggedBarWidth; return _draggedBarWidth;
} }
- (void) setDraggedBarWidth: (float)newWidth - (void) setDraggedBarWidth: (float)newWidth
{ {
draggedBarWidth = newWidth; _draggedBarWidth = newWidth;
} }
//
static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect) static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
{ {
NSPoint p; NSPoint p;
@ -432,9 +443,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
NSSize dimpleSize; NSSize dimpleSize;
/* focus is already on self */ /* focus is already on self */
if (!dimpleImage) if (!_dimpleImage)
return; return;
dimpleSize = [dimpleImage size]; dimpleSize = [_dimpleImage size];
dimpleOrigin = centerSizeInRect(dimpleSize, aRect); dimpleOrigin = centerSizeInRect(dimpleSize, aRect);
/* /*
@ -443,31 +454,35 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
*/ */
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
dimpleOrigin.y -= dimpleSize.height; dimpleOrigin.y -= dimpleSize.height;
[dimpleImage compositeToPoint: dimpleOrigin operation: NSCompositeSourceOver]; [_dimpleImage compositeToPoint: dimpleOrigin
operation: NSCompositeSourceOver];
} }
/* Vertical splitview has a vertical split bar */ /* Vertical splitview has a vertical split bar */
- (void) setVertical: (BOOL)flag - (void) setVertical: (BOOL)flag
{ {
isVertical = flag; _isVertical = flag;
} }
- (BOOL) isVertical - (BOOL) isVertical
{ {
return isVertical; return _isVertical;
} }
- (void) setDimpleImage: (NSImage *)anImage resetDividerThickness: (BOOL)flag - (void) setDimpleImage: (NSImage *)anImage resetDividerThickness: (BOOL)flag
{ {
ASSIGN(dimpleImage, anImage); ASSIGN(_dimpleImage, anImage);
if (flag) if (flag)
{ {
NSSize s = NSMakeSize(8., 8.); NSSize s = NSMakeSize(6., 6.);
if (dimpleImage) if (_dimpleImage)
s = [dimpleImage size]; s = [_dimpleImage size];
[self setDividerThickNess: isVertical ? s.width : s.height]; if (_isVertical)
_dividerWidth = s.width;
else
_dividerWidth = s.height;
} }
} }
@ -480,7 +495,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
if ([self isOpaque]) if ([self isOpaque])
{ {
[[self backgroundColor] set]; [_backgroundColor set];
NSRectFill(r); NSRectFill(r);
} }
@ -490,15 +505,15 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
{ {
v = [subs objectAtIndex: i]; v = [subs objectAtIndex: i];
divRect = [v frame]; divRect = [v frame];
if ([self isVertical] == NO) if (_isVertical == NO)
{ {
divRect.size.height = [self dividerThickness]; divRect.size.height = _dividerWidth;
divRect.origin.y -= divRect.size.height; divRect.origin.y -= divRect.size.height;
} }
else else
{ {
divRect.origin.x = NSMaxX(divRect); divRect.origin.x = NSMaxX(divRect);
divRect.size.width = [self dividerThickness]; divRect.size.width = _dividerWidth;
} }
[self drawDividerInRect: divRect]; [self drawDividerInRect: divRect];
} }
@ -507,7 +522,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (NSImage*) dimpleImage - (NSImage*) dimpleImage
{ {
return dimpleImage; return _dimpleImage;
} }
/* Overridden Methods */ /* Overridden Methods */
@ -521,21 +536,6 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return YES; return YES;
} }
- (id) initWithFrame: (NSRect)frameRect
{
if ((self = [super initWithFrame: frameRect]) != nil)
{
dividerWidth = 8;
draggedBarWidth = 8;
isVertical = NO;
[self setDividerColor: [NSColor controlShadowColor]];
[self setBackgroundColor: [NSColor controlBackgroundColor]];
[self setDimpleImage:
[NSImage imageNamed: @"common_Dimple.tiff"] resetDividerThickness: YES];
}
return self;
}
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize - (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{ {
[super resizeWithOldSuperviewSize: oldSize]; [super resizeWithOldSuperviewSize: oldSize];
@ -545,20 +545,20 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (id) delegate - (id) delegate
{ {
return delegate; return _delegate;
} }
- (void) setDelegate: (id)anObject - (void) setDelegate: (id)anObject
{ {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
if (delegate) if (_delegate)
[nc removeObserver: delegate name: nil object: self]; [nc removeObserver: _delegate name: nil object: self];
delegate = anObject; _delegate = anObject;
#define SET_DELEGATE_NOTIFICATION(notif_name) \ #define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([delegate respondsToSelector: @selector(splitView##notif_name:)]) \ if ([_delegate respondsToSelector: @selector(splitView##notif_name:)]) \
[nc addObserver: delegate \ [nc addObserver: _delegate \
selector: @selector(splitView##notif_name: ) \ selector: @selector(splitView##notif_name: ) \
name: NSSplitView##notif_name##Notification \ name: NSSplitView##notif_name##Notification \
object: self] object: self]
@ -569,22 +569,22 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (NSColor*) dividerColor - (NSColor*) dividerColor
{ {
return dividerColor; return _dividerColor;
} }
- (void) setDividerColor: (NSColor*) aColor - (void) setDividerColor: (NSColor*) aColor
{ {
ASSIGN(dividerColor, aColor); ASSIGN(_dividerColor, aColor);
} }
- (NSColor*) backgroundColor - (NSColor*) backgroundColor
{ {
return backgroundColor; return _backgroundColor;
} }
- (void) setBackgroundColor: (NSColor*)aColor - (void) setBackgroundColor: (NSColor*)aColor
{ {
ASSIGN(backgroundColor, aColor); ASSIGN(_backgroundColor, aColor);
} }
// //
@ -597,22 +597,22 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
/* /*
* Encode objects we don't own. * Encode objects we don't own.
*/ */
[aCoder encodeConditionalObject: delegate]; [aCoder encodeConditionalObject: _delegate];
[aCoder encodeConditionalObject: splitCursor]; [aCoder encodeConditionalObject: _splitCursor]; // ?
/* /*
* Encode the objects we do own. * Encode the objects we do own.
*/ */
[aCoder encodeObject: dimpleImage]; // FIXME When encoding/decoding of images is supported.
[aCoder encodeObject: backgroundColor]; // [aCoder encodeObject: _dimpleImage];
[aCoder encodeObject: dividerColor]; [aCoder encodeObject: _backgroundColor];
[aCoder encodeObject: _dividerColor];
/* /*
* Encode the rest of the ivar data. * Encode the rest of the ivar data.
*/ */
[aCoder encodeValueOfObjCType: @encode(int) at: &dividerWidth]; [aCoder encodeValueOfObjCType: @encode(int) at: &_draggedBarWidth];
[aCoder encodeValueOfObjCType: @encode(int) at: &draggedBarWidth]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isVertical];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &isVertical];
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
@ -622,31 +622,39 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
/* /*
* Decode objects that we don't retain. * Decode objects that we don't retain.
*/ */
delegate = [aDecoder decodeObject]; [self setDelegate: [aDecoder decodeObject]];
splitCursor = [aDecoder decodeObject]; _splitCursor = [aDecoder decodeObject]; // ?
/* /*
* Decode objects that we do retain. * Decode objects that we do retain.
*/ */
[aDecoder decodeValueOfObjCType: @encode(id) at: &dimpleImage];
[aDecoder decodeValueOfObjCType: @encode(id) at: &backgroundColor]; // FIXME When encoding/decoding of images is supported.
[aDecoder decodeValueOfObjCType: @encode(id) at: &dividerColor]; //[aDecoder decodeValueOfObjCType: @encode(id) at: &_dimpleImage];
ASSIGN (_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]);
[aDecoder decodeValueOfObjCType: @encode(id) at: &_backgroundColor];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_dividerColor];
/* /*
* Decode non-object data. * Decode non-object data.
*/ */
[aDecoder decodeValueOfObjCType: @encode(int) at: &dividerWidth]; [aDecoder decodeValueOfObjCType: @encode(int) at: &_draggedBarWidth];
[aDecoder decodeValueOfObjCType: @encode(int) at: &draggedBarWidth]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isVertical];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &isVertical];
/*
*
*/
_dividerWidth = [self dividerThickness];
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
[backgroundColor release]; [_backgroundColor release];
[dividerColor release]; [_dividerColor release];
[dimpleImage release]; [_dimpleImage release];
[super dealloc]; [super dealloc];
} }