Implemented [setRulerViewClass:] and preset to NSRulerView. Cache

the scrollerWidth in a class var, use this in all methods.
Use _sizeForBorderType() from NSCell to determine the border size
in all methods that handle borderType. Replaced all uses of
AUTORELEASE with explicit RELEASE calls. In [setContentView:]
don't RETAIN the content view, as this is handled by the normal
subview mechanism. (Don't RELEASE it in [dealloc] and
[removeSubview:]) Added dummy method [scrollWheel:].
Implemented the ruler methods, but this are still not handled in
[tile] and [drawRect:].


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11210 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2001-10-21 23:29:29 +00:00
parent 424c51335e
commit 2fdcec8859

View file

@ -29,12 +29,10 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/ */
#include <gnustep/gui/config.h>
#include <math.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <AppKit/NSScroller.h> #include <AppKit/NSScroller.h>
#include <AppKit/NSColor.h> #include <AppKit/NSColor.h>
#include <AppKit/NSCell.h>
#include <AppKit/NSClipView.h> #include <AppKit/NSClipView.h>
#include <AppKit/NSScrollView.h> #include <AppKit/NSScrollView.h>
#include <AppKit/NSRulerView.h> #include <AppKit/NSRulerView.h>
@ -49,6 +47,7 @@
* Class variables * Class variables
*/ */
static Class rulerViewClass = nil; static Class rulerViewClass = nil;
static float scrollerWidth;
/* /*
* Class methods * Class methods
@ -58,6 +57,8 @@ static Class rulerViewClass = nil;
if (self == [NSScrollView class]) if (self == [NSScrollView class])
{ {
NSDebugLog(@"Initialize NSScrollView class\n"); NSDebugLog(@"Initialize NSScrollView class\n");
[self setRulerViewClass: [NSRulerView class]];
scrollerWidth = [NSScroller scrollerWidth];
[self setVersion: 1]; [self setVersion: 1];
} }
} }
@ -78,6 +79,7 @@ static Class rulerViewClass = nil;
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = frameSize; NSSize size = frameSize;
NSSize border = _sizeForBorderType(borderType);
/* /*
* Substract 1 from the width and height of * Substract 1 from the width and height of
@ -86,31 +88,15 @@ static Class rulerViewClass = nil;
*/ */
if (hFlag) if (hFlag)
{ {
size.height -= [NSScroller scrollerWidth]; size.height -= scrollerWidth + 1;
size.height -= 1;
} }
if (vFlag) if (vFlag)
{ {
size.width -= [NSScroller scrollerWidth]; size.width -= scrollerWidth + 1;
size.width -= 1;
} }
switch (borderType) size.width -= 2*border.width;
{ size.height -= 2*border.height;
case NSNoBorder:
break;
case NSLineBorder:
size.width -= 2;
size.height -= 2;
break;
case NSBezelBorder:
case NSGrooveBorder:
size.width -= 4;
size.height -= 4;
break;
}
return size; return size;
} }
@ -121,6 +107,7 @@ static Class rulerViewClass = nil;
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = contentSize; NSSize size = contentSize;
NSSize border = _sizeForBorderType(borderType);
/* /*
* Add 1 to the width and height for the line that separates the * Add 1 to the width and height for the line that separates the
@ -128,31 +115,15 @@ static Class rulerViewClass = nil;
*/ */
if (hFlag) if (hFlag)
{ {
size.height += [NSScroller scrollerWidth]; size.height += scrollerWidth + 1;
size.height += 1;
} }
if (vFlag) if (vFlag)
{ {
size.width += [NSScroller scrollerWidth]; size.width += scrollerWidth + 1;
size.width += 1;
} }
switch (borderType) size.width += 2*border.width;
{ size.height += 2*border.height;
case NSNoBorder:
break;
case NSLineBorder:
size.width += 2;
size.height += 2;
break;
case NSBezelBorder:
case NSGrooveBorder:
size.width += 4;
size.height += 4;
break;
}
return size; return size;
} }
@ -162,8 +133,11 @@ static Class rulerViewClass = nil;
*/ */
- (id) initWithFrame: (NSRect)rect - (id) initWithFrame: (NSRect)rect
{ {
[super initWithFrame: rect]; NSClipView *clipView = [NSClipView new];
[self setContentView: AUTORELEASE([NSClipView new])];
self = [super initWithFrame: rect];
[self setContentView: clipView];
RELEASE(clipView);
_hLineScroll = 10; _hLineScroll = 10;
_hPageScroll = 10; _hPageScroll = 10;
_vLineScroll = 10; _vLineScroll = 10;
@ -182,8 +156,6 @@ static Class rulerViewClass = nil;
- (void) dealloc - (void) dealloc
{ {
TEST_RELEASE(_contentView);
TEST_RELEASE(_horizScroller); TEST_RELEASE(_horizScroller);
TEST_RELEASE(_vertScroller); TEST_RELEASE(_vertScroller);
TEST_RELEASE(_horizRuler); TEST_RELEASE(_horizRuler);
@ -205,11 +177,11 @@ static Class rulerViewClass = nil;
if ([aView isKindOfClass: [NSView class]] == NO) if ([aView isKindOfClass: [NSView class]] == NO)
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"Attempt to set non-view object as content view"]; format: @"Attempt to set non-view object as content view"];
if (aView != _contentView) if (aView != _contentView)
{ {
NSView *docView = [aView documentView]; NSView *docView = [aView documentView];
RETAIN(aView);
[_contentView removeFromSuperview]; [_contentView removeFromSuperview];
_contentView = aView; _contentView = aView;
[self addSubview: _contentView]; [self addSubview: _contentView];
@ -227,7 +199,6 @@ static Class rulerViewClass = nil;
{ {
_contentView = nil; _contentView = nil;
[super removeSubview: aView]; [super removeSubview: aView];
RELEASE(aView);
[self tile]; [self tile];
} }
else else
@ -263,7 +234,12 @@ static Class rulerViewClass = nil;
if (_hasHorizScroller) if (_hasHorizScroller)
{ {
if (!_horizScroller) if (!_horizScroller)
[self setHorizontalScroller: AUTORELEASE([NSScroller new])]; {
NSScroller *scroller = [NSScroller new];
[self setHorizontalScroller: scroller];
RELEASE(scroller);
}
[self addSubview: _horizScroller]; [self addSubview: _horizScroller];
} }
else else
@ -300,7 +276,10 @@ static Class rulerViewClass = nil;
{ {
if (!_vertScroller) if (!_vertScroller)
{ {
[self setVerticalScroller: AUTORELEASE([NSScroller new])]; NSScroller *scroller = [NSScroller new];
[self setVerticalScroller: scroller];
RELEASE(scroller);
if (_contentView && !_contentView->_rFlags.flipped_view) if (_contentView && !_contentView->_rFlags.flipped_view)
[_vertScroller setFloatValue: 1]; [_vertScroller setFloatValue: 1];
} }
@ -312,6 +291,11 @@ static Class rulerViewClass = nil;
[self tile]; [self tile];
} }
- (void) scrollWheel: (NSEvent *)theEvent
{
// FIXME
}
- (void) _doScroll: (NSScroller*)scroller - (void) _doScroll: (NSScroller*)scroller
{ {
float floatValue = [scroller floatValue]; float floatValue = [scroller floatValue];
@ -502,36 +486,77 @@ static Class rulerViewClass = nil;
} }
- (void) setHorizontalRulerView: (NSRulerView*)aRulerView // FIX ME - (void) setHorizontalRulerView: (NSRulerView*)aRulerView
{ {
ASSIGN(_horizRuler, aRulerView); ASSIGN(_horizRuler, aRulerView);
} }
- (void) setHasHorizontalRuler: (BOOL)flag // FIX ME - (void) setHasHorizontalRuler: (BOOL)flag
{ {
if (_hasHorizRuler == flag) if (_hasHorizRuler == flag)
return; return;
_hasHorizRuler = flag; _hasHorizRuler = flag;
if (_hasHorizRuler)
{
if (!_horizRuler)
{
NSRulerView *rulerView = [rulerViewClass new];
[self setHorizontalRulerView: rulerView];
RELEASE(rulerView);
}
}
else
[_horizRuler removeFromSuperview];
} }
- (void) setVerticalRulerView: (NSRulerView*)ruler // FIX ME - (void) setVerticalRulerView: (NSRulerView*)ruler
{ {
ASSIGN(_vertRuler, ruler); ASSIGN(_vertRuler, ruler);
} }
- (void) setHasVerticalRuler: (BOOL)flag // FIX ME - (void) setHasVerticalRuler: (BOOL)flag
{ {
if (_hasVertRuler == flag) if (_hasVertRuler == flag)
return; return;
_hasVertRuler = flag; _hasVertRuler = flag;
if (_hasVertRuler)
{
if (!_vertRuler)
{
NSRulerView *rulerView = [rulerViewClass new];
[self setVerticalRulerView: rulerView];
RELEASE(rulerView);
}
}
else
[_vertRuler removeFromSuperview];
} }
- (void) setRulersVisible: (BOOL)flag - (void) setRulersVisible: (BOOL)flag
{ {
// FIX ME if (_rulersVisible == flag)
return;
_rulersVisible = flag; _rulersVisible = flag;
if (flag)
{
if (_hasVertRuler)
[self addSubview: _vertRuler];
if (_hasHorizRuler)
[self addSubview: _horizRuler];
}
else
{
if (_hasVertRuler)
[_vertRuler removeFromSuperview];
if (_hasHorizRuler)
[_horizRuler removeFromSuperview];
}
[self tile];
} }
- (void) setFrame: (NSRect)rect - (void) setFrame: (NSRect)rect
@ -549,11 +574,8 @@ static Class rulerViewClass = nil;
- (void) tile - (void) tile
{ {
NSSize contentSize; NSSize contentSize;
float scrollerWidth = [NSScroller scrollerWidth];
NSRect contentRect; NSRect contentRect;
NSRect vertScrollerRect = NSZeroRect; NSSize border = _sizeForBorderType(_borderType);
NSRect horizScrollerRect = NSZeroRect;
float borderThickness = 0;
/* NSTableView related vars */ /* NSTableView related vars */
float headerViewHeight = 0; float headerViewHeight = 0;
NSView *cornerView = nil; NSView *cornerView = nil;
@ -577,24 +599,8 @@ static Class rulerViewClass = nil;
hasVerticalScroller: _hasVertScroller hasVerticalScroller: _hasVertScroller
borderType: _borderType]; borderType: _borderType];
contentRect = NSMakeRect (0, 0, contentSize.width, contentSize.height); contentRect = NSMakeRect (0, 0, contentSize.width, contentSize.height);
contentRect.origin.x = border.width;
switch (_borderType) contentRect.origin.y = border.height;
{
case NSNoBorder:
break;
case NSLineBorder:
borderThickness = 1;
break;
case NSBezelBorder:
case NSGrooveBorder:
borderThickness = 2;
break;
}
contentRect.origin.x = borderThickness;
contentRect.origin.y = borderThickness;
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
{ {
@ -603,11 +609,13 @@ static Class rulerViewClass = nil;
if (_hasVertScroller) if (_hasVertScroller)
{ {
vertScrollerRect.origin.x = _bounds.origin.x + borderThickness; NSRect vertScrollerRect = NSZeroRect;
vertScrollerRect.origin.y = _bounds.origin.y + borderThickness;
vertScrollerRect.origin.x = _bounds.origin.x + border.width;
vertScrollerRect.origin.y = _bounds.origin.y + border.height;
vertScrollerRect.size.width = scrollerWidth; vertScrollerRect.size.width = scrollerWidth;
vertScrollerRect.size.height = fakeBoundsSize.height vertScrollerRect.size.height = fakeBoundsSize.height
- 2 * borderThickness; - 2 * border.height;
contentRect.origin.x += scrollerWidth + 1; contentRect.origin.x += scrollerWidth + 1;
@ -615,12 +623,15 @@ static Class rulerViewClass = nil;
{ {
vertScrollerRect.origin.y += headerViewHeight; vertScrollerRect.origin.y += headerViewHeight;
} }
[_vertScroller setFrame: vertScrollerRect];
} }
if (_hasHorizScroller) if (_hasHorizScroller)
{ {
NSRect horizScrollerRect = NSZeroRect;
horizScrollerRect.origin.x = contentRect.origin.x; horizScrollerRect.origin.x = contentRect.origin.x;
horizScrollerRect.origin.y = _bounds.origin.y + borderThickness; horizScrollerRect.origin.y = _bounds.origin.y + border.height;
horizScrollerRect.size.width = contentRect.size.width; horizScrollerRect.size.width = contentRect.size.width;
horizScrollerRect.size.height = scrollerWidth; horizScrollerRect.size.height = scrollerWidth;
@ -633,6 +644,7 @@ static Class rulerViewClass = nil;
{ {
contentRect.origin.y += scrollerWidth + 1; contentRect.origin.y += scrollerWidth + 1;
} }
[_horizScroller setFrame: horizScrollerRect];
} }
if (_hasHeaderView) if (_hasHeaderView)
@ -642,12 +654,12 @@ static Class rulerViewClass = nil;
rect.origin.x = contentRect.origin.x; rect.origin.x = contentRect.origin.x;
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
{ {
rect.origin.y = _bounds.origin.y + borderThickness; rect.origin.y = _bounds.origin.y + border.height;
} }
else else
{ {
rect.origin.y = NSMaxY (_bounds); rect.origin.y = NSMaxY (_bounds);
rect.origin.y -= headerViewHeight + borderThickness; rect.origin.y -= headerViewHeight + border.height;
} }
rect.size.width = contentRect.size.width; rect.size.width = contentRect.size.width;
rect.size.height = headerViewHeight; rect.size.height = headerViewHeight;
@ -658,29 +670,27 @@ static Class rulerViewClass = nil;
{ {
NSPoint origin; NSPoint origin;
origin.x = _bounds.origin.x + borderThickness; origin.x = _bounds.origin.x + border.width;
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
{ {
origin.y = _bounds.origin.y + borderThickness; origin.y = _bounds.origin.y + border.height;
} }
else else
{ {
origin.y = NSMaxY (_bounds) - headerViewHeight - borderThickness; origin.y = NSMaxY (_bounds) - headerViewHeight - border.height;
} }
[cornerView setFrameOrigin: origin]; [cornerView setFrameOrigin: origin];
} }
[_horizScroller setFrame: horizScrollerRect]; // FIXME: The Rulers should be positioned too
[_vertScroller setFrame: vertScrollerRect];
[_contentView setFrame: contentRect]; [_contentView setFrame: contentRect];
} }
- (void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
float scrollerWidth = [NSScroller scrollerWidth];
float horizLinePosition, horizLineLength = _bounds.size.width; float horizLinePosition, horizLineLength = _bounds.size.width;
float borderThickness = 0; NSSize border = _sizeForBorderType(_borderType);
float headerViewHeight = 0; float headerViewHeight = 0;
if (_hasHeaderView == YES) if (_hasHeaderView == YES)
@ -701,53 +711,50 @@ static Class rulerViewClass = nil;
break; break;
case NSLineBorder: case NSLineBorder:
borderThickness = 1;
[[NSColor controlDarkShadowColor] set]; [[NSColor controlDarkShadowColor] set];
NSFrameRect(_bounds); NSFrameRect(_bounds);
break; break;
case NSBezelBorder: case NSBezelBorder:
borderThickness = 2;
NSDrawGrayBezel(_bounds, rect); NSDrawGrayBezel(_bounds, rect);
break; break;
case NSGrooveBorder: case NSGrooveBorder:
borderThickness = 2;
NSDrawGroove(_bounds, rect); NSDrawGroove(_bounds, rect);
break; break;
} }
horizLinePosition = borderThickness; horizLinePosition = border.width;
DPSsetlinewidth(ctxt, 1); DPSsetlinewidth(ctxt, 1);
DPSsetgray(ctxt, 0); DPSsetgray(ctxt, 0);
if (_hasVertScroller) if (_hasVertScroller)
{ {
horizLinePosition = scrollerWidth + borderThickness; horizLinePosition = scrollerWidth + border.width;
horizLineLength -= scrollerWidth + 2 * borderThickness; horizLineLength -= scrollerWidth + 2 * border.width;
DPSmoveto(ctxt, horizLinePosition, borderThickness); DPSmoveto(ctxt, horizLinePosition, border.height);
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
{ {
DPSrmoveto(ctxt, 0, headerViewHeight); DPSrmoveto(ctxt, 0, headerViewHeight);
} }
DPSrlineto(ctxt, 0, _bounds.size.height - headerViewHeight DPSrlineto(ctxt, 0, _bounds.size.height - headerViewHeight
- 2 * borderThickness - 1); - 2 * border.height - 1);
DPSstroke(ctxt); DPSstroke(ctxt);
if ((_hasHeaderView == YES) && (_hasCornerView == NO)) if ((_hasHeaderView == YES) && (_hasCornerView == NO))
{ {
float yStart = borderThickness + headerViewHeight - 1; float yStart = border.height + headerViewHeight - 1;
if (_rFlags.flipped_view == NO) if (_rFlags.flipped_view == NO)
yStart = _bounds.size.height - yStart; yStart = _bounds.size.height - yStart;
DPSmoveto(ctxt, horizLinePosition, yStart); DPSmoveto(ctxt, horizLinePosition, yStart);
DPSlineto(ctxt, borderThickness, yStart); DPSlineto(ctxt, border.width, yStart);
DPSstroke(ctxt); DPSstroke(ctxt);
} }
} }
if (_hasHorizScroller) if (_hasHorizScroller)
{ {
float ypos = scrollerWidth + borderThickness + 1; float ypos = scrollerWidth + border.height + 1;
if (_rFlags.flipped_view) if (_rFlags.flipped_view)
ypos = _bounds.size.height - ypos; ypos = _bounds.size.height - ypos;