General tidyup - make updates work properly etc.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3647 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-02-03 21:53:29 +00:00
parent e7072cb446
commit 951c165938
5 changed files with 1402 additions and 1179 deletions

View file

@ -1220,18 +1220,20 @@ BOOL done = NO;
windows_need_update = flag;
}
- (void)updateWindows // send an update message
- (void) updateWindows // send an update message
{ // to all visible windows
int i, count;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
int i, count;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSArray *window_list = [self windows];
windows_need_update = NO;
// notify that an update is
// imminent
[nc postNotificationName:NSApplicationWillUpdateNotification object:self];
[nc postNotificationName:NSApplicationWillUpdateNotification object: self];
for (i = 0, count = [window_list count]; i < count; i++)
{
NSWindow *win = [window_list objectAtIndex:i];
NSWindow *win = [window_list objectAtIndex: i];
if ([win isVisible]) // send update only if the
[win update]; // window is visible
}

View file

@ -42,7 +42,7 @@
return self;
}
- (void)setDocumentView:(NSView*)aView
- (void) setDocumentView: (NSView*)aView
{
if (_documentView == aView)
return;
@ -81,7 +81,7 @@
[[self superview] reflectScrolledClipView:self];
}
- (void)resetCursorRects
- (void) resetCursorRects
{
[self addCursorRect:[self bounds] cursor:_cursor];
}
@ -95,8 +95,11 @@
}
}
- (void)scrollToPoint:(NSPoint)point
- (void) scrollToPoint: (NSPoint)point
{
NSRect originalBounds = [self bounds];
NSRect newBounds = originalBounds;
NSRect intersection;
#ifdef DEBUGLOG
NSPoint currentPoint = [self bounds].origin;
@ -105,26 +108,101 @@
point.x, point.y);
#endif
point = [self constrainScrollPoint: point];
[self setBoundsOrigin: NSMakePoint(point.x, point.y)];
newBounds.origin = [self constrainScrollPoint: point];
if (NSEqualPoints(originalBounds.origin, newBounds.origin))
return;
// [self setBoundsOrigin: newBounds.origin];
[self setNeedsDisplay: YES];
if (_copiesOnScroll)
/* TODO: move the visible portion of the document */
[_documentView displayRect: bounds];
{
// copy the portion of the view that is common before and after scrolling.
// then tell docview to draw the exposed parts.
// intersection is the common rectangle
intersection = NSIntersectionRect(originalBounds, newBounds);
if (NSEqualRects(intersection, NSZeroRect))
{
// no intersection -- docview should draw everyting
[self setBoundsOrigin: newBounds.origin];
[_documentView setNeedsDisplayInRect: newBounds];
}
else
[_documentView setNeedsDisplayInRect: bounds];
// [_documentView setNeedsDisplay: YES];
[self display];
{
NSPoint destPoint = intersection.origin;
float dx = newBounds.origin.x - originalBounds.origin.x;
float dy = newBounds.origin.y - originalBounds.origin.y;
destPoint.x -= dx;
destPoint.y -= dy;
[self lockFocus];
NSCopyBits(0, intersection, destPoint);
[self unlockFocus];
[self setBoundsOrigin: newBounds.origin];
if (dx != 0)
{
// moved in x -- redraw a full-height rectangle at
// side of intersection
NSRect redrawRect;
redrawRect.origin.y = newBounds.origin.y;
redrawRect.size.height = newBounds.size.height;
redrawRect.size.width = newBounds.size.width
- intersection.size.width;
if (dx < 0)
{
// moved to the left -- redraw at left of intersection
redrawRect.origin.x = newBounds.origin.x;
}
else
{
// moved to the right -- redraw at right of intersection
redrawRect.origin.x = newBounds.origin.x
+ intersection.size.width;
}
[_documentView setNeedsDisplayInRect: redrawRect];
}
if (dy != 0)
{
// moved in y
// -- redraw rectangle with intersection's width over or under it
NSRect redrawRect;
redrawRect.origin.x = intersection.origin.x;
redrawRect.size.width = intersection.size.width;
redrawRect.size.height = newBounds.size.height
- intersection.size.height;
if (dy < 0)
{
// moved down -- redraw under intersection
redrawRect.origin.y = newBounds.origin.y;
}
else
{
// moved up -- redraw over intersection
redrawRect.origin.y = newBounds.origin.y
+ intersection.size.height;
}
[_documentView setNeedsDisplayInRect: redrawRect];
}
}
}
else
{
// dont copy anything -- docview draws it all
[self setBoundsOrigin: newBounds.origin];
[_documentView setNeedsDisplayInRect: newBounds];
}
}
- (NSPoint)constrainScrollPoint:(NSPoint)proposedNewOrigin
- (NSPoint) constrainScrollPoint: (NSPoint)proposedNewOrigin
{
NSRect documentFrame = [_documentView frame];
NSPoint new = proposedNewOrigin;
if (documentFrame.size.width <= bounds.size.width)
new.x = 0.0;
new.x = documentFrame.origin.x;
else if (proposedNewOrigin.x <= documentFrame.origin.x)
new.x = documentFrame.origin.x;
else if (proposedNewOrigin.x
@ -145,7 +223,7 @@
else
{
if (documentFrame.size.height <= bounds.size.height)
new.y = 0.0;
new.y = documentFrame.origin.y;
else if (proposedNewOrigin.y <= documentFrame.origin.y)
new.y = documentFrame.origin.y;
else if (proposedNewOrigin.y
@ -156,7 +234,7 @@
return new;
}
- (NSRect)documentRect
- (NSRect) documentRect
{
NSRect documentFrame = [_documentView frame];
NSRect clipViewBounds = bounds;
@ -169,7 +247,7 @@
return rect;
}
- (NSRect)documentVisibleRect
- (NSRect) documentVisibleRect
{
NSRect documentBounds = [_documentView bounds];
NSRect clipViewBounds = bounds;
@ -183,97 +261,132 @@
return rect;
}
- (void) drawRect:(NSRect)rect
- (void) drawRect: (NSRect)rect
{
[[self backgroundColor] set];
NSRectFill(rect);
}
- (BOOL)autoscroll:(NSEvent*)theEvent
- (BOOL) autoscroll: (NSEvent*)theEvent
{
return 0;
}
- (void)viewBoundsChanged:(NSNotification*)aNotification
- (void) viewBoundsChanged: (NSNotification*)aNotification
{
[super_view reflectScrolledClipView:self];
}
- (void)viewFrameChanged:(NSNotification*)aNotification
- (void) viewFrameChanged: (NSNotification*)aNotification
{
[self setBoundsOrigin: [self constrainScrollPoint: bounds.origin]];
[super_view reflectScrolledClipView:self];
}
- (void)scaleUnitSquareToSize:(NSSize)newUnitSize
- (void) scaleUnitSquareToSize: (NSSize)newUnitSize
{
[super scaleUnitSquareToSize:newUnitSize];
[super_view reflectScrolledClipView:self];
}
- (void)setBoundsOrigin:(NSPoint)aPoint
- (void) setBoundsOrigin: (NSPoint)aPoint
{
[super setBoundsOrigin:aPoint];
[super_view reflectScrolledClipView:self];
}
- (void)setBoundsSize:(NSSize)aSize
- (void) setBoundsSize: (NSSize)aSize
{
[super setBoundsSize:aSize];
[super_view reflectScrolledClipView:self];
}
- (void)setFrameSize:(NSSize)aSize
- (void) setFrameSize: (NSSize)aSize
{
[super setFrameSize:aSize];
[super_view reflectScrolledClipView:self];
}
- (void)setFrameOrigin:(NSPoint)aPoint
- (void) setFrameOrigin: (NSPoint)aPoint
{
[super setFrameOrigin:aPoint];
[super_view reflectScrolledClipView:self];
}
- (void)setFrame:(NSRect)rect
- (void) setFrame: (NSRect)rect
{
[super setFrame:rect];
[super_view reflectScrolledClipView:self];
}
- (void)translateOriginToPoint:(NSPoint)aPoint
- (void) translateOriginToPoint: (NSPoint)aPoint
{
[super translateOriginToPoint:aPoint];
[super_view reflectScrolledClipView:self];
}
- (BOOL)isOpaque { return YES; }
- (id)documentView { return _documentView; }
- (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; }
- (BOOL)copiesOnScroll { return _copiesOnScroll; }
- (void)setDocumentCursor:(NSCursor*)aCursor { ASSIGN(_cursor, aCursor); }
- (NSCursor*)documentCursor { return _cursor; }
- (NSColor*)backgroundColor { return _backgroundColor; }
- (BOOL)isFlipped { return [_documentView isFlipped]; }
- (BOOL)acceptsFirstResponder { return _documentView != nil; }
- (BOOL) isOpaque
{
return YES;
}
- (void)setBackgroundColor:(NSColor*)aColor
- (id) documentView
{
return _documentView;
}
- (void) setCopiesOnScroll: (BOOL)flag
{
_copiesOnScroll = flag;
}
- (BOOL) copiesOnScroll
{
return _copiesOnScroll;
}
- (void) setDocumentCursor: (NSCursor*)aCursor
{
ASSIGN(_cursor, aCursor);
}
- (NSCursor*) documentCursor
{
return _cursor;
}
- (NSColor*) backgroundColor
{
return _backgroundColor;
}
- (BOOL) isFlipped
{
return [_documentView isFlipped];
}
- (BOOL) acceptsFirstResponder
{
return _documentView != nil;
}
- (void) setBackgroundColor: (NSColor*)aColor
{
ASSIGN(_backgroundColor, aColor);
}
/* Disable rotation of clip view */
- (void)rotateByAngle:(float)angle
- (void) rotateByAngle: (float)angle
{}
- (void)setBoundsRotation:(float)angle
- (void) setBoundsRotation: (float)angle
{}
- (void)setFrameRotation:(float)angle
- (void) setFrameRotation: (float)angle
{}
/* Managing responder chain */
- (BOOL)becomeFirstResponder
- (BOOL) becomeFirstResponder
{
return [_documentView becomeFirstResponder];
}

View file

@ -57,27 +57,37 @@ static Class rulerViewClass = nil;
//
// Class methods
//
+ (void)initialize
+ (void) initialize
{
if (self == [NSScrollView class])
{
NSDebugLog(@"Initialize NSScrollView class\n");
[self setVersion:1];
[self setVersion: 1];
}
}
+ (void)setRulerViewClass:(Class)aClass { rulerViewClass = aClass; }
+ (Class)rulerViewClass { return rulerViewClass; }
+ (NSSize)contentSizeForFrameSize:(NSSize)frameSize // calc content size by
hasHorizontalScroller:(BOOL)hFlag // taking into account
hasVerticalScroller:(BOOL)vFlag // the border type
borderType:(NSBorderType)borderType
+ (void) setRulerViewClass: (Class)aClass
{
NSSize size = frameSize;
rulerViewClass = aClass;
}
+ (Class) rulerViewClass
{
return rulerViewClass;
}
+ (NSSize) contentSizeForFrameSize: (NSSize)frameSize
hasHorizontalScroller: (BOOL)hFlag
hasVerticalScroller: (BOOL)vFlag
borderType: (NSBorderType)borderType
{
NSSize size = frameSize;
// Substract 1 from the width and height of
if (hFlag) // the line that separates the horizontal
{ // and vertical scroller from the clip view
// the line that separates the horizontal
// and vertical scroller from the clip view
if (hFlag)
{
size.height -= [NSScroller scrollerWidth];
size.height -= 1;
}
@ -107,15 +117,18 @@ NSSize size = frameSize;
return size;
}
+ (NSSize)frameSizeForContentSize:(NSSize)contentSize
hasHorizontalScroller:(BOOL)hFlag
hasVerticalScroller:(BOOL)vFlag
borderType:(NSBorderType)borderType
+ (NSSize) frameSizeForContentSize: (NSSize)contentSize
hasHorizontalScroller: (BOOL)hFlag
hasVerticalScroller: (BOOL)vFlag
borderType: (NSBorderType)borderType
{
NSSize size = contentSize;
NSSize size = contentSize;
// Add 1 to the width and height for the
if (hFlag) // line that separates the horizontal and
{ // vertical scroller from the clip view.
// line that separates the horizontal and
// vertical scroller from the clip view.
if (hFlag)
{
size.height += [NSScroller scrollerWidth];
size.height += 1;
}
@ -148,10 +161,10 @@ NSSize size = contentSize;
//
// Instance methods
//
- initWithFrame:(NSRect)rect
- initWithFrame: (NSRect)rect
{
[super initWithFrame:rect];
[self setContentView:[[NSClipView new] autorelease]];
[super initWithFrame: rect];
[self setContentView: [[NSClipView new] autorelease]];
_lineScroll = 10;
_pageScroll = 10;
_borderType = NSBezelBorder;
@ -163,10 +176,10 @@ NSSize size = contentSize;
- init
{
return [self initWithFrame:NSZeroRect];
return [self initWithFrame: NSZeroRect];
}
- (void)dealloc
- (void) dealloc
{
[_contentView release];
@ -196,12 +209,12 @@ NSSize size = contentSize;
if (_horizScroller)
{
[_horizScroller setAutoresizingMask: NSViewWidthSizable];
[_horizScroller setTarget:self];
[_horizScroller setAction:@selector(_doScroll:)];
[_horizScroller setTarget: self];
[_horizScroller setAction: @selector(_doScroll:)];
}
}
- (void)setHasHorizontalScroller:(BOOL)flag
- (void) setHasHorizontalScroller: (BOOL)flag
{
if (_hasHorizScroller == flag)
return;
@ -211,8 +224,8 @@ NSSize size = contentSize;
if (_hasHorizScroller)
{
if (!_horizScroller)
[self setHorizontalScroller:[[NSScroller new] autorelease]];
[self addSubview:_horizScroller];
[self setHorizontalScroller: [[NSScroller new] autorelease]];
[self addSubview: _horizScroller];
}
else
[_horizScroller removeFromSuperview];
@ -230,12 +243,12 @@ NSSize size = contentSize;
if (_vertScroller)
{
[_vertScroller setAutoresizingMask: NSViewHeightSizable];
[_vertScroller setTarget:self];
[_vertScroller setAction:@selector(_doScroll:)];
[_vertScroller setTarget: self];
[_vertScroller setAction: @selector(_doScroll:)];
}
}
- (void)setHasVerticalScroller:(BOOL)flag
- (void) setHasVerticalScroller: (BOOL)flag
{
if (_hasVertScroller == flag)
return;
@ -246,11 +259,11 @@ NSSize size = contentSize;
{
if (!_vertScroller)
{
[self setVerticalScroller:[[NSScroller new] autorelease]];
[self setVerticalScroller: [[NSScroller new] autorelease]];
if (_contentView && ![_contentView isFlipped])
[_vertScroller setFloatValue:1];
[_vertScroller setFloatValue: 1];
}
[self addSubview:_vertScroller];
[self addSubview: _vertScroller];
}
else
[_vertScroller removeFromSuperview];
@ -258,23 +271,29 @@ NSSize size = contentSize;
[self tile];
}
- (void)_doScroll:(NSScroller*)scroller
- (void)_doScroll: (NSScroller*)scroller
{
float floatValue = [scroller floatValue];
NSRect clipViewBounds = [_contentView bounds];
NSScrollerPart hitPart = [scroller hitPart];
NSRect documentRect = [_contentView documentRect];
float amount = 0;
NSPoint point;
float floatValue = [scroller floatValue];
NSRect clipViewBounds = [_contentView bounds];
NSScrollerPart hitPart = [scroller hitPart];
NSRect documentRect = [_contentView documentRect];
float amount = 0;
NSPoint point = clipViewBounds.origin;
NSDebugLog (@"_doScroll: float value = %f", floatValue);
// do nothing if scroller is unknown
if (scroller != _horizScroller && scroller != _vertScroller)
return;
_knobMoved = NO;
if(hitPart == NSScrollerKnob)
if (hitPart == NSScrollerKnob || hitPart == NSScrollerKnobSlot)
_knobMoved = YES;
else
{
//FIXME in a page scroll, amount should be the portion of the view that
// stays visible, not the one that disapears
if (hitPart == NSScrollerIncrementLine)
amount = _lineScroll;
else if (hitPart == NSScrollerIncrementPage)
@ -284,7 +303,7 @@ NSPoint point;
else if (hitPart == NSScrollerDecrementPage)
amount = -_pageScroll;
else
_knobMoved = YES;
return;
}
if (!_knobMoved) // button scrolling
@ -292,23 +311,18 @@ NSPoint point;
if (scroller == _horizScroller)
{
point.x = clipViewBounds.origin.x + amount;
point.y = clipViewBounds.origin.y;
}
else
{
if (scroller == _vertScroller)
if ([_contentView isFlipped])
{
point.x = clipViewBounds.origin.x;
// If view is flipped
if ([_contentView isFlipped]) // reverse the scroll
amount = -amount; // direction
// reverse the scroll direction
amount = -amount;
}
NSDebugLog (@"increment/decrement: amount = %f, flipped = %d",
amount, [_contentView isFlipped]);
point.y = clipViewBounds.origin.y + amount;
point.y = point.y < 0 ? 0 : point.y; // FIX ME s/b in
} // clipview
else
return; // do nothing
}
}
else // knob scolling
@ -317,48 +331,35 @@ NSPoint point;
{
point.x = floatValue * (documentRect.size.width
- clipViewBounds.size.width);
point.y = clipViewBounds.origin.y;
}
else
{
if (scroller == _vertScroller)
{
point.x = clipViewBounds.origin.x;
if (![_contentView isFlipped])
floatValue = 1 - floatValue;
point.y = floatValue * (documentRect.size.height
- clipViewBounds.size.height);
}
else
return; // do nothing
}
}
[_contentView scrollToPoint:point]; // scroll clipview
if (!_knobMoved)
{ // if scrolling via
[self reflectScrolledClipView:_contentView]; // buttons update
// if (scroller == _vertScroller) // scroller pos to
// [_vertScroller displayIfNeeded]; // reflect clipview
// else
// [_horizScroller displayIfNeeded];
// [window flushWindow];
}
[_contentView scrollToPoint: point];
// scroll clipview
// reflectScrolledClipView has been called by the clipView.
//FIXME: should this be here?
// NSWindow's doc says update is called for each event
[window update];
}
- (void)reflectScrolledClipView:(NSClipView*)aClipView
- (void) reflectScrolledClipView: (NSClipView*)aClipView
{
NSRect documentFrame = NSZeroRect;
NSRect clipViewBounds = NSZeroRect;
float floatValue;
float knobProportion;
id documentView;
// do nothing if
if(aClipView != _contentView) // aClipView is not
return; // our content view
NSRect documentFrame = NSZeroRect;
NSRect clipViewBounds = NSZeroRect;
float floatValue;
float knobProportion;
id documentView;
// if (_knobMoved) // is this really needed?
// return; // FAR FIX ME ?
if (aClipView != _contentView)
return;
NSDebugLog (@"reflectScrolledClipView:");
@ -369,48 +370,44 @@ id documentView;
if (_hasVertScroller)
{
if (documentFrame.size.height <= clipViewBounds.size.height)
[_vertScroller setEnabled:NO];
[_vertScroller setEnabled: NO];
else
{
[_vertScroller setEnabled:YES];
[_vertScroller setEnabled: YES];
knobProportion = clipViewBounds.size.height /
documentFrame.size.height;
floatValue = clipViewBounds.origin.y / (documentFrame.size.height
- clipViewBounds.size.height);
if (![_contentView isFlipped])
floatValue = 1 - floatValue;
[_vertScroller setFloatValue:floatValue
knobProportion:knobProportion];
[_vertScroller displayIfNeededIgnoringOpacity];
[_vertScroller setFloatValue: floatValue
knobProportion: knobProportion];
}
}
if (_hasHorizScroller)
{
if (documentFrame.size.width <= clipViewBounds.size.width)
[_horizScroller setEnabled:NO];
[_horizScroller setEnabled: NO];
else
{
[_horizScroller setEnabled:YES];
[_horizScroller setEnabled: YES];
knobProportion = clipViewBounds.size.width /
documentFrame.size.width;
floatValue = clipViewBounds.origin.x / (documentFrame.size.width -
clipViewBounds.size.width);
[_horizScroller setFloatValue:floatValue
knobProportion:knobProportion];
[_horizScroller displayIfNeededIgnoringOpacity];
[_horizScroller setFloatValue: floatValue
knobProportion: knobProportion];
}
}
[window flushWindow];
}
- (void)setHorizontalRulerView:(NSRulerView*)aRulerView // FIX ME
- (void) setHorizontalRulerView: (NSRulerView*)aRulerView // FIX ME
{
ASSIGN(_horizRuler, aRulerView);
}
- (void)setHasHorizontalRuler:(BOOL)flag // FIX ME
- (void) setHasHorizontalRuler: (BOOL)flag // FIX ME
{
if (_hasHorizRuler == flag)
return;
@ -418,12 +415,12 @@ id documentView;
_hasHorizRuler = flag;
}
- (void)setVerticalRulerView:(NSRulerView*)ruler // FIX ME
- (void) setVerticalRulerView: (NSRulerView*)ruler // FIX ME
{
ASSIGN(_vertRuler, ruler);
}
- (void)setHasVerticalRuler:(BOOL)flag // FIX ME
- (void) setHasVerticalRuler: (BOOL)flag // FIX ME
{
if (_hasVertRuler == flag)
return;
@ -431,34 +428,34 @@ id documentView;
_hasVertRuler = flag;
}
- (void)setRulersVisible:(BOOL)flag
- (void) setRulersVisible: (BOOL)flag
{
}
- (void)setFrame:(NSRect)rect
- (void) setFrame: (NSRect)rect
{
[super setFrame:rect];
[super setFrame: rect];
[self tile];
}
- (void)setFrameSize:(NSSize)size
- (void) setFrameSize: (NSSize)size
{
[super setFrameSize:size];
[super setFrameSize: size];
[self tile];
}
- (void)tile
- (void) tile
{
NSRect boundsRect = [self bounds];
NSSize contentSize = [isa contentSizeForFrameSize:boundsRect.size
hasHorizontalScroller:_hasHorizScroller
hasVerticalScroller:_hasVertScroller
borderType:_borderType];
float scrollerWidth = [NSScroller scrollerWidth];
NSRect contentRect = { NSZeroPoint, contentSize };
NSRect vertScrollerRect = NSZeroRect;
NSRect horizScrollerRect = NSZeroRect;
float borderThickness = 0;
NSRect boundsRect = [self bounds];
NSSize contentSize = [isa contentSizeForFrameSize: boundsRect.size
hasHorizontalScroller: _hasHorizScroller
hasVerticalScroller: _hasVertScroller
borderType: _borderType];
float scrollerWidth = [NSScroller scrollerWidth];
NSRect contentRect = { NSZeroPoint, contentSize };
NSRect vertScrollerRect = NSZeroRect;
NSRect horizScrollerRect = NSZeroRect;
float borderThickness = 0;
switch ([self borderType])
{
@ -498,19 +495,20 @@ float borderThickness = 0;
contentRect.origin.y += scrollerWidth + 1;
}
// If the document view is not
if (![_contentView isFlipped]) // flipped reverse the meaning
[_vertScroller setFloatValue:1]; // of the vertical scroller's
[_horizScroller setFrame:horizScrollerRect];
[_vertScroller setFrame:vertScrollerRect];
[_contentView setFrame:contentRect];
// If the document view is not flipped reverse the meaning
// of the vertical scroller's
if (![_contentView isFlipped])
[_vertScroller setFloatValue: 1];
[_horizScroller setFrame: horizScrollerRect];
[_vertScroller setFrame: vertScrollerRect];
[_contentView setFrame: contentRect];
}
- (void)drawRect:(NSRect)rect
- (void) drawRect: (NSRect)rect
{
float scrollerWidth = [NSScroller scrollerWidth];
float horizLinePosition, horizLineLength = [self bounds].size.width;
float borderThickness = 0;
float scrollerWidth = [NSScroller scrollerWidth];
float horizLinePosition, horizLineLength = [self bounds].size.width;
float borderThickness = 0;
fprintf (stderr,
"NSScrollView drawRect: origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
@ -562,76 +560,153 @@ float borderThickness = 0;
PSgrestore ();
}
- (NSRect)documentVisibleRect
- (NSRect) documentVisibleRect
{
return [_contentView documentVisibleRect];
}
- (void)setBackgroundColor:(NSColor*)aColor
- (void) setBackgroundColor: (NSColor*)aColor
{
[_contentView setBackgroundColor:aColor];
[_contentView setBackgroundColor: aColor];
}
- (NSColor*)backgroundColor
- (NSColor*) backgroundColor
{
return [_contentView backgroundColor];
}
- (void)setBorderType:(NSBorderType)borderType
- (void) setBorderType: (NSBorderType)borderType
{
_borderType = borderType;
}
- (void)setDocumentView:(NSView*)aView
- (void) setDocumentView: (NSView*)aView
{
[_contentView setDocumentView:aView];
[_contentView setDocumentView: aView];
if (_contentView && ![_contentView isFlipped])
[_vertScroller setFloatValue:1];
[_vertScroller setFloatValue: 1];
[self tile];
#if 0
/* Redundant stuff - done in -tile */
[_contentView viewFrameChanged:nil];
[_contentView viewFrameChanged: nil];
// update scroller
[self reflectScrolledClipView:(NSClipView*)_contentView];
[self reflectScrolledClipView: (NSClipView*)_contentView];
#endif
}
#if 0
/* Don't need to override if we can trust the default autoresizing */
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize
- (void) resizeSubviewsWithOldSize: (NSSize)oldSize
{
fprintf (stderr, "NSScrollView resizeSubviewsWithOldSize \n");
[super resizeSubviewsWithOldSize:oldSize];
[super resizeSubviewsWithOldSize: oldSize];
[self tile];
}
#endif
- (id)documentView { return [_contentView documentView]; }
- (NSCursor*)documentCursor { return [_contentView documentCursor]; }
- (void)setDocumentCursor:(NSCursor*)aCursor
- (id) documentView
{
[_contentView setDocumentCursor:aCursor];
return [_contentView documentView];
}
- (BOOL)isOpaque { return YES; }
- (NSBorderType)borderType { return _borderType; }
- (NSScroller*)verticalScroller { return _vertScroller; }
- (BOOL)hasVerticalScroller { return _hasVertScroller; }
- (BOOL)hasHorizontalRuler { return _hasHorizRuler; }
- (NSSize)contentSize { return [_contentView bounds].size; }
- (NSView*)contentView { return _contentView; }
- (NSRulerView*)horizontalRulerView { return _horizRuler; }
- (BOOL)hasVerticalRuler { return _hasVertRuler; }
- (NSRulerView*)verticalRulerView { return _vertRuler; }
- (BOOL)rulersVisible { return _rulersVisible; }
- (void)setLineScroll:(float)aFloat { _lineScroll = aFloat; }
- (float)lineScroll { return _lineScroll; }
- (void)setPageScroll:(float)aFloat { _pageScroll = aFloat; }
- (float)pageScroll { return _pageScroll; }
- (void)setScrollsDynamically:(BOOL)flag { _scrollsDynamically = flag; }
- (BOOL)scrollsDynamically { return _scrollsDynamically; }
- (NSScroller*)horizontalScroller { return _horizScroller; }
- (BOOL)hasHorizontalScroller { return _hasHorizScroller; }
- (NSCursor*) documentCursor
{
return [_contentView documentCursor];
}
- (void) setDocumentCursor: (NSCursor*)aCursor
{
[_contentView setDocumentCursor: aCursor];
}
- (BOOL) isOpaque
{
return YES;
}
- (NSBorderType) borderType
{
return _borderType;
}
- (BOOL) hasVerticalScroller
{
return _hasVertScroller;
}
- (BOOL) hasHorizontalRuler
{
return _hasHorizRuler;
}
- (NSSize) contentSize
{
return [_contentView bounds].size;
}
- (NSView*) contentView
{
return _contentView;
}
- (NSRulerView*) horizontalRulerView
{
return _horizRuler;
}
- (BOOL) hasVerticalRuler
{
return _hasVertRuler;
}
- (NSRulerView*) verticalRulerView
{
return _vertRuler;
}
- (BOOL) rulersVisible
{
return _rulersVisible;
}
- (void) setLineScroll: (float)aFloat
{
_lineScroll = aFloat;
}
- (float) lineScroll
{
return _lineScroll;
}
- (void) setPageScroll: (float)aFloat
{
_pageScroll = aFloat;
}
- (float) pageScroll
{
return _pageScroll;
}
- (void) setScrollsDynamically: (BOOL)flag
{
_scrollsDynamically = flag;
}
- (BOOL) scrollsDynamically
{
return _scrollsDynamically;
}
- (NSScroller*) horizontalScroller
{
return _horizScroller;
}
- (BOOL) hasHorizontalScroller
{
return _hasHorizScroller;
}
@end

View file

@ -71,40 +71,91 @@ static BOOL preCalcValues = NO;
//
// Class methods
//
+ (void)initialize
+ (void) initialize
{
if (self == [NSScroller class])
[self setVersion:1];
[self setVersion: 1];
}
+ (float)scrollerWidth { return scrollerWidth; }
- (NSScrollArrowPosition)arrowsPosition { return _arrowsPosition; }
- (NSUsableScrollerParts)usableParts { return _usableParts; }
- (float)knobProportion { return _knobProportion; }
- (NSScrollerPart)hitPart { return _hitPart; }
- (float)floatValue { return _floatValue; }
- (void)setAction:(SEL)action { _action = action; }
- (SEL)action { return _action; }
- (void)setTarget:(id)target { ASSIGN(_target, target); }
- (id)target { return _target; }
- (void)encodeWithCoder:aCoder { }
- initWithCoder:aDecoder { return self; }
- (BOOL)isOpaque { return YES; }
- initWithFrame:(NSRect)frameRect
+ (float) scrollerWidth
{
if (frameRect.size.width > frameRect.size.height) // determine the
{ // orientation of
_isHorizontal = YES; // the scroller and
frameRect.size.height = [isa scrollerWidth]; // adjust it's size
} // accordingly
return scrollerWidth;
}
- (NSScrollArrowPosition) arrowsPosition
{
return _arrowsPosition;
}
- (NSUsableScrollerParts) usableParts
{
return _usableParts;
}
- (float) knobProportion
{
return _knobProportion;
}
- (NSScrollerPart) hitPart
{
return _hitPart;
}
- (float) floatValue
{
return _floatValue;
}
- (void) setAction: (SEL)action
{
_action = action;
}
- (SEL) action
{
return _action;
}
- (void) setTarget: (id)target
{
ASSIGN(_target, target);
}
- (id) target
{
return _target;
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
return self;
}
- (BOOL) isOpaque
{
return YES;
}
- (id) initWithFrame: (NSRect)frameRect
{
// determine the orientation of the scroller and adjust it's size accordingly
if (frameRect.size.width > frameRect.size.height)
{
_isHorizontal = YES;
frameRect.size.height = [isa scrollerWidth];
}
else
{
_isHorizontal = NO;
frameRect.size.width = [isa scrollerWidth];
}
[super initWithFrame:frameRect];
[super initWithFrame: frameRect];
if (_isHorizontal)
_arrowsPosition = NSScrollerArrowsMinEnd;
@ -113,152 +164,153 @@ static BOOL preCalcValues = NO;
_hitPart = NSScrollerNoPart;
[self drawParts];
[self setEnabled:NO];
[self setEnabled: NO];
[self checkSpaceForParts];
return self;
}
- init
- (id) init
{
return [self initWithFrame:NSZeroRect];
return [self initWithFrame: NSZeroRect];
}
- (void)drawParts
{ // Create the class variable
if (knobCell) // button cells if they do not
return; // yet exist.
- (void) drawParts
{
// Create the class variable button cells if they do not yet exist.
if (knobCell)
return;
upCell = [NSButtonCell new];
[upCell setHighlightsBy:NSChangeBackgroundCellMask|NSContentsCellMask];
[upCell setImage:[NSImage imageNamed:@"common_ArrowUp"]];
[upCell setAlternateImage:[NSImage imageNamed:@"common_ArrowUpH"]];
[upCell setImagePosition:NSImageOnly];
[upCell setContinuous:YES];
[upCell setPeriodicDelay:0.05 interval:0.05];
[upCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
[upCell setImage: [NSImage imageNamed: @"common_ArrowUp"]];
[upCell setAlternateImage: [NSImage imageNamed: @"common_ArrowUpH"]];
[upCell setImagePosition: NSImageOnly];
[upCell setContinuous: YES];
[upCell setPeriodicDelay: 0.05 interval: 0.05];
downCell = [NSButtonCell new];
[downCell setHighlightsBy:NSChangeBackgroundCellMask|NSContentsCellMask];
[downCell setImage:[NSImage imageNamed:@"common_ArrowDown"]];
[downCell setAlternateImage:[NSImage imageNamed:@"common_ArrowDownH"]];
[downCell setImagePosition:NSImageOnly];
[downCell setContinuous:YES];
[downCell setPeriodicDelay:0.05 interval:0.05];
[downCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
[downCell setImage: [NSImage imageNamed: @"common_ArrowDown"]];
[downCell setAlternateImage: [NSImage imageNamed: @"common_ArrowDownH"]];
[downCell setImagePosition: NSImageOnly];
[downCell setContinuous: YES];
[downCell setPeriodicDelay: 0.05 interval: 0.05];
leftCell = [NSButtonCell new];
[leftCell setHighlightsBy:NSChangeBackgroundCellMask|NSContentsCellMask];
[leftCell setImage:[NSImage imageNamed:@"common_ArrowLeft"]];
[leftCell setAlternateImage:[NSImage imageNamed:@"common_ArrowLeftH"]];
[leftCell setImagePosition:NSImageOnly];
[leftCell setContinuous:YES];
[leftCell setPeriodicDelay:0.05 interval:0.05];
[leftCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
[leftCell setImage: [NSImage imageNamed: @"common_ArrowLeft"]];
[leftCell setAlternateImage: [NSImage imageNamed: @"common_ArrowLeftH"]];
[leftCell setImagePosition: NSImageOnly];
[leftCell setContinuous: YES];
[leftCell setPeriodicDelay: 0.05 interval: 0.05];
rightCell = [NSButtonCell new];
[rightCell setHighlightsBy:NSChangeBackgroundCellMask|NSContentsCellMask];
[rightCell setImage:[NSImage imageNamed:@"common_ArrowRight"]];
[rightCell setAlternateImage:[NSImage imageNamed:@"common_ArrowRightH"]];
[rightCell setImagePosition:NSImageOnly];
[rightCell setContinuous:YES];
[rightCell setPeriodicDelay:0.05 interval:0.05];
[rightCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
[rightCell setImage: [NSImage imageNamed: @"common_ArrowRight"]];
[rightCell setAlternateImage: [NSImage imageNamed: @"common_ArrowRightH"]];
[rightCell setImagePosition: NSImageOnly];
[rightCell setContinuous: YES];
[rightCell setPeriodicDelay: 0.05 interval: 0.05];
knobCell = [NSButtonCell new];
[knobCell setButtonType:NSMomentaryChangeButton];
[knobCell setImage:[NSImage imageNamed:@"common_Dimple"]];
[knobCell setImagePosition:NSImageOnly];
[knobCell setButtonType: NSMomentaryChangeButton];
[knobCell setImage: [NSImage imageNamed: @"common_Dimple"]];
[knobCell setImagePosition: NSImageOnly];
}
- (void)_setTargetAndActionToCells
- (void) _setTargetAndActionToCells
{
[upCell setTarget:_target];
[upCell setAction:_action];
[upCell setTarget: _target];
[upCell setAction: _action];
[downCell setTarget:_target];
[downCell setAction:_action];
[downCell setTarget: _target];
[downCell setAction: _action];
[leftCell setTarget:_target];
[leftCell setAction:_action];
[leftCell setTarget: _target];
[leftCell setAction: _action];
[rightCell setTarget:_target];
[rightCell setAction:_action];
[rightCell setTarget: _target];
[rightCell setAction: _action];
[knobCell setTarget:_target];
[knobCell setAction:_action];
[knobCell setTarget: _target];
[knobCell setAction: _action];
}
- (void)checkSpaceForParts
- (void) checkSpaceForParts
{
NSSize frameSize = [self frame].size;
float size = (_isHorizontal ? frameSize.width : frameSize.height);
float scrollerWidth = [isa scrollerWidth];
NSSize frameSize = [self frame].size;
float size = (_isHorizontal ? frameSize.width : frameSize.height);
float scrollerWidth = [isa scrollerWidth];
if (size > 3 * scrollerWidth + 2)
_usableParts = NSAllScrollerParts;
else
if (size > 2 * scrollerWidth + 1)
else if (size > 2 * scrollerWidth + 1)
_usableParts = NSOnlyScrollerArrows;
else
if (size > scrollerWidth)
_usableParts = NSNoScrollerParts;
}
- (void)setEnabled:(BOOL)flag
- (void) setEnabled: (BOOL)flag
{
if (_isEnabled == flag)
return;
_isEnabled = flag;
[self setNeedsDisplay:YES];
[self setNeedsDisplay: YES];
}
- (void)setArrowsPosition:(NSScrollArrowPosition)where
- (void) setArrowsPosition: (NSScrollArrowPosition)where
{
if (_arrowsPosition == where)
return;
_arrowsPosition = where;
[self setNeedsDisplay:YES];
[self setNeedsDisplay: YES];
}
- (void)setFloatValue:(float)aFloat
- (void) setFloatValue: (float)aFloat
{
if (aFloat == _floatValue)
return;
if (aFloat < 0)
_floatValue = 0;
else
if (aFloat > 1)
else if (aFloat > 1)
_floatValue = 1;
else
_floatValue = aFloat;
[self setNeedsDisplayInRect:[self rectForPart:NSScrollerKnobSlot]];
[self setNeedsDisplayInRect: [self rectForPart: NSScrollerKnobSlot]];
}
- (void)setFloatValue:(float)aFloat knobProportion:(float)ratio
- (void) setFloatValue: (float)aFloat knobProportion: (float)ratio
{
if (ratio < 0)
_knobProportion = 0;
else
if (ratio > 1)
else if (ratio > 1)
_knobProportion = 1;
else
_knobProportion = ratio;
[self setFloatValue:aFloat];
[self setFloatValue: aFloat];
}
- (void)setFrame:(NSRect)frameRect
- (void) setFrame: (NSRect)frameRect
{
if (frameRect.size.width > frameRect.size.height) // determine the
{ // orientation of
_isHorizontal = YES; // the scroller and
frameRect.size.height = [isa scrollerWidth]; // adjust it's size
} // accordingly
// determine the orientation of the scroller and adjust it's size accordingly
if (frameRect.size.width > frameRect.size.height)
{
_isHorizontal = YES;
frameRect.size.height = [isa scrollerWidth];
}
else
{
_isHorizontal = NO;
frameRect.size.width = [isa scrollerWidth];
}
[super setFrame:frameRect];
[super setFrame: frameRect];
if (_isHorizontal)
_arrowsPosition = NSScrollerArrowsMinEnd;
@ -269,57 +321,59 @@ float scrollerWidth = [isa scrollerWidth];
[self checkSpaceForParts];
}
- (void)setFrameSize:(NSSize)size
- (void) setFrameSize: (NSSize)size
{
[super setFrameSize:size];
[super setFrameSize: size];
[self checkSpaceForParts];
[self setNeedsDisplay:YES];
[self setNeedsDisplay: YES];
}
- (NSScrollerPart)testPart:(NSPoint)thePoint // return what part
{ // of the scroller
NSRect rect; // the mouse hit
- (NSScrollerPart)testPart: (NSPoint)thePoint
{
// return what part of the scroller the mouse hit
NSRect rect;
if (thePoint.x < 0 || thePoint.x > frame.size.width
|| thePoint.y < 0 || thePoint.y > frame.size.height)
return NSScrollerNoPart;
rect = [self rectForPart:NSScrollerDecrementLine];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerDecrementLine];
if ([self mouse: thePoint inRect: rect])
return NSScrollerDecrementLine;
rect = [self rectForPart:NSScrollerIncrementLine];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerIncrementLine];
if ([self mouse: thePoint inRect: rect])
return NSScrollerIncrementLine;
rect = [self rectForPart:NSScrollerKnob];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerKnob];
if ([self mouse: thePoint inRect: rect])
return NSScrollerKnob;
rect = [self rectForPart:NSScrollerKnobSlot];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerKnobSlot];
if ([self mouse: thePoint inRect: rect])
return NSScrollerKnobSlot;
rect = [self rectForPart:NSScrollerDecrementPage];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerDecrementPage];
if ([self mouse: thePoint inRect: rect])
return NSScrollerDecrementPage;
rect = [self rectForPart:NSScrollerIncrementPage];
if ([self mouse:thePoint inRect:rect])
rect = [self rectForPart: NSScrollerIncrementPage];
if ([self mouse: thePoint inRect: rect])
return NSScrollerIncrementPage;
return NSScrollerNoPart;
}
- (float)_floatValueForMousePoint:(NSPoint)point
- (float) _floatValueForMousePoint: (NSPoint)point
{
NSRect knobRect = [self rectForPart:NSScrollerKnob];
NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
float floatValue = 0;
float position;
NSRect knobRect = [self rectForPart: NSScrollerKnob];
NSRect slotRect = [self rectForPart: NSScrollerKnobSlot];
float floatValue = 0;
float position;
if (_isHorizontal) // Adjust point to lie
{ // within the knob slot
// Adjust point to lie within the knob slot
if (_isHorizontal)
{
float halfKnobRectWidth = knobRect.size.width / 2;
if (point.x < slotRect.origin.x + halfKnobRectWidth)
@ -332,13 +386,13 @@ float position;
halfKnobRectWidth;
else
position = point.x;
} // Compute float value
// given the knob size
}
// Compute float value given the knob size
floatValue = (position - (slotRect.origin.x + halfKnobRectWidth))
/ (slotRect.size.width - knobRect.size.width);
}
else // Adjust point to lie
{ // within the knob slot
else
{
float halfKnobRectHeight = knobRect.size.height / 2;
if (point.y < slotRect.origin.y + halfKnobRectHeight)
@ -352,7 +406,7 @@ float position;
else
position = point.y;
}
// Compute float value
// Compute float value given the knob size
floatValue = (position - (slotRect.origin.y + halfKnobRectHeight)) /
(slotRect.size.height - knobRect.size.height);
floatValue = 1 - floatValue;
@ -361,12 +415,11 @@ float position;
return floatValue;
}
- (void)_preCalcParts // pre calculate
{ // values to lessen
NSRect knobRect = [self rectForPart:NSScrollerKnob]; // the burden while
// scrolling
slotRect = [self rectForPart:NSScrollerKnobSlot];
- (void) _preCalcParts
{
NSRect knobRect = [self rectForPart: NSScrollerKnob];
slotRect = [self rectForPart: NSScrollerKnobSlot];
halfKnobRectWidth = knobRect.size.width / 2;
slotOriginPlusKnobWidth = slotRect.origin.x + halfKnobRectWidth;
slotOriginPlusSlotWidthMinusHalfKnobWidth = slotRect.origin.x +
@ -380,13 +433,13 @@ NSRect knobRect = [self rectForPart:NSScrollerKnob]; // the burden while
slotHeightMinusKnobHeight = slotRect.size.height - knobRect.size.height;
}
- (float)_floatValueForMousePointFromPreCalc:(NSPoint)point
- (float) _floatValueForMousePointFromPreCalc: (NSPoint)point
{
float floatValue = 0;
float position;
float floatValue = 0;
float position;
if (_isHorizontal) // Adjust point to lie
{ // within the knob slot
if (_isHorizontal)
{
if (point.x < slotOriginPlusKnobWidth)
position = slotOriginPlusKnobWidth;
else
@ -395,13 +448,12 @@ float position;
position = slotOriginPlusSlotWidthMinusHalfKnobWidth;
else
position = point.x;
} // Compute float value
// given the knob size
}
floatValue = (position - slotOriginPlusKnobWidth) /
slotWidthMinusKnobWidth;
}
else // Adjust point to lie
{ // within the knob slot
else
{
if (point.y < slotOriginPlusKnobHeight)
position = slotOriginPlusKnobHeight;
else
@ -411,7 +463,7 @@ float position;
else
position = point.y;
}
// Compute float value
floatValue = (position - slotOriginPlusKnobHeight) /
slotHeightMinusKnobHeight;
floatValue = 1 - floatValue;
@ -420,13 +472,12 @@ float position;
return floatValue;
}
- (void)mouseDown:(NSEvent*)theEvent
- (void) mouseDown: (NSEvent*)theEvent
{
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
NSPoint location = [self convertPoint: [theEvent locationInWindow]
fromView: nil];
[self lockFocus];
_hitPart = [self testPart:location];
_hitPart = [self testPart: location];
[self _setTargetAndActionToCells];
switch (_hitPart)
@ -435,23 +486,20 @@ NSPoint location = [self convertPoint:[theEvent locationInWindow]
case NSScrollerDecrementLine:
case NSScrollerIncrementPage:
case NSScrollerDecrementPage:
[self trackScrollButtons:theEvent];
[self trackScrollButtons: theEvent];
break;
case NSScrollerKnob:
[self trackKnob:theEvent];
[self trackKnob: theEvent];
break;
case NSScrollerKnobSlot:
{
float floatValue = [self _floatValueForMousePoint:location];
float floatValue = [self _floatValueForMousePoint: location];
[self setFloatValue:floatValue];
[self sendAction:_action to:_target];
[self drawKnobSlot];
[self drawKnob];
[window flushWindow];
[self trackKnob:theEvent];
[self setFloatValue: floatValue];
[self sendAction: _action to: _target];
[self trackKnob: theEvent];
break;
}
@ -460,118 +508,105 @@ NSPoint location = [self convertPoint:[theEvent locationInWindow]
}
_hitPart = NSScrollerNoPart;
[self unlockFocus];
}
- (void)trackKnob:(NSEvent*)theEvent
- (void)trackKnob: (NSEvent*)theEvent
{
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSLeftMouseDraggedMask | NSMouseMovedMask
| NSPeriodicMask;
NSApplication *app = [NSApplication sharedApplication];
NSPoint point, apoint;
float oldFloatValue = _floatValue;
float floatValue;
NSDate *theDistantFuture = [NSDate distantFuture];
PSMatrix* matrix;
NSEventType eventType;
NSRect knobRect = {{0,0},{0,0}};
int periodCount = 0; // allows a forced update
NSMutableArray* path = [self _pathBetweenSubview:self
toSuperview:[window contentView]];
NSApplication *app = [NSApplication sharedApplication];
NSPoint point, apoint;
float oldFloatValue = _floatValue;
float floatValue;
NSDate *theDistantFuture = [NSDate distantFuture];
PSMatrix* matrix;
NSEventType eventType;
NSRect knobRect = {{0,0},{0,0}};
int periodCount = 0; // allows a forced update
NSMutableArray* path = [self _pathBetweenSubview: self
toSuperview: [window contentView]];
[path addObject: [window contentView]];
matrix = [self _concatenateMatricesInReverseOrderFromPath:path];
matrix = [self _concatenateMatricesInReverseOrderFromPath: path];
[matrix inverse];
//fprintf(stderr, " trackKnob \n");
//fprintf(stderr, " trackKnob \n");
[self _preCalcParts]; // pre calc scroller parts
preCalcValues = YES;
_hitPart = NSScrollerKnob; // set periodic events rate
// to achieve max of ~30fps
[NSEvent startPeriodicEventsAfterDelay:0.02 withPeriod:0.03];
[[NSRunLoop currentRunLoop] limitDateForMode:NSEventTrackingRunLoopMode];
_hitPart = NSScrollerKnob;
// set periodic events rate to achieve max of ~30fps
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
while ((eventType = [theEvent type]) != NSLeftMouseUp)
{ // user is moving scroller
if (eventType != NSPeriodic) // loop until left mouse up
{
apoint = [theEvent locationInWindow]; // zero the periodic count
periodCount = 0; // whenever a real position
} // event is recieved
if (eventType != NSPeriodic)
{
apoint = [theEvent locationInWindow];
// zero the periodic count whenever a real position event is recieved
periodCount = 0;
}
else
{ // if 6x periods have gone by w/o movement
if(periodCount == 6) // check mouse and update if necessary
{
// if 6x periods have gone by w/o movement
// check mouse and update if necessary
if (periodCount == 6)
apoint = [window mouseLocationOutsideOfEventStream];
point = [matrix pointInMatrixSpace:apoint];
point = [matrix pointInMatrixSpace: apoint];
if (point.x != knobRect.origin.x || point.y != knobRect.origin.y)
{
floatValue = [self _floatValueForMousePointFromPreCalc:point];
floatValue = [self _floatValueForMousePointFromPreCalc: point];
if (floatValue != oldFloatValue)
{
if (floatValue < 0)
_floatValue = 0;
else
{
if (floatValue > 1)
_floatValue = 1;
else
_floatValue = floatValue;
}
[self drawKnobSlot]; // draw the scroller slot
[self drawKnob]; // draw the scroller knob
[_target performSelector:_action withObject:self];
[window flushWindow];
[self setFloatValue: floatValue];
[self sendAction: _action to: _target];
oldFloatValue = floatValue;
} // avoid timing related scrolling
// hesitation by counting number of
knobRect.origin = point; // periodic events since scroll pos
} // was updated, when this reaches
periodCount++; // 6x periodic rate an update is
} // forced on next periodic event
theEvent = [app nextEventMatchingMask:eventMask
untilDate:theDistantFuture
inMode:NSEventTrackingRunLoopMode
dequeue:YES];
[window update];
}
knobRect.origin = point;
}
// avoid timing related scrolling hesitation by counting number of
// periodic events since scroll pos was updated, when this reaches
// 6x periodic rate an update is forced on next periodic event
periodCount++;
}
theEvent = [app nextEventMatchingMask: eventMask
untilDate: theDistantFuture
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
[NSEvent stopPeriodicEvents];
if([_target isKindOf:[NSScrollView class]]) // hack for XRAW FIX ME
{
NSObject *targetCV = (NSObject *)[_target contentView];
if([targetCV respondsToSelector:@selector(_freeMatrix)])
[targetCV _freeMatrix];
}
preCalcValues = NO;
}
- (void)trackScrollButtons:(NSEvent*)theEvent
- (void) trackScrollButtons: (NSEvent*)theEvent
{
NSApplication *theApp = [NSApplication sharedApplication];
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
NSApplication *theApp = [NSApplication sharedApplication];
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
NSLeftMouseDraggedMask | NSMouseMovedMask;
NSPoint location;
BOOL shouldReturn = NO;
id theCell = nil;
NSRect rect;
NSPoint location;
BOOL shouldReturn = NO;
id theCell = nil;
NSRect rect;
NSDebugLog (@"trackScrollButtons");
do {
location = [self convertPoint:[theEvent locationInWindow]fromView:nil];
_hitPart = [self testPart:location];
rect = [self rectForPart:_hitPart];
do
{
location = [self convertPoint: [theEvent locationInWindow]fromView: nil];
_hitPart = [self testPart: location];
rect = [self rectForPart: _hitPart];
switch (_hitPart) // determine which
{ // cell was hit
switch (_hitPart)
{
case NSScrollerIncrementLine:
case NSScrollerIncrementPage:
theCell = (_isHorizontal ? rightCell : upCell);
@ -589,72 +624,57 @@ NSRect rect;
if (theCell)
{
[theCell highlight:YES withFrame:rect inView:self];
[self lockFocus];
[theCell highlight: YES withFrame: rect inView: self];
[self unlockFocus];
[window flushWindow];
NSLog (@"tracking cell %x", theCell);
shouldReturn = [theCell trackMouse:theEvent // Track the mouse
inRect:rect // until left mouse
ofView:self // goes up
untilMouseUp:YES];
shouldReturn = [theCell trackMouse: theEvent
inRect: rect
ofView: self
untilMouseUp: YES];
if([_target isKindOf:[NSScrollView class]]) // a hack for XRAW
{ // FIX ME
NSObject *targetCV = (NSObject *)[_target contentView];
if([targetCV respondsToSelector:@selector(_freeMatrix)])
[targetCV _freeMatrix];
}
[theCell highlight:NO withFrame:rect inView:self];
[self lockFocus];
[theCell highlight: NO withFrame: rect inView: self];
[self unlockFocus];
[window flushWindow];
}
if (shouldReturn)
break;
theEvent = [theApp nextEventMatchingMask:eventMask
untilDate:[NSDate distantFuture]
inMode:NSEventTrackingRunLoopMode
dequeue:YES];
theEvent = [theApp nextEventMatchingMask: eventMask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
while ([theEvent type] != NSLeftMouseUp);
NSDebugLog (@"return from trackScrollButtons");
}
- (BOOL)sendActionO:(SEL)theAction to:(id)theTarget
{ // send action to
BOOL ret = [super sendAction:theAction to:theTarget]; // the target on
// behalf of cell
[self drawKnobSlot]; // lockFocus set in mouseDown method is
[self drawKnob]; // active so we simply redraw the knob and
[window flushWindow]; // slot to reflect the hit scroll button
return ret;
}
//
// draw the scroller
//
- (void)drawRect:(NSRect)rect
- (void) drawRect: (NSRect)rect
{
NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))",
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
[self drawArrow:NSScrollerDecrementArrow highlight:NO];
[self drawArrow:NSScrollerIncrementArrow highlight:NO];
[self drawArrow: NSScrollerDecrementArrow highlight: NO];
[self drawArrow: NSScrollerIncrementArrow highlight: NO];
[self drawKnobSlot];
[self drawKnob];
}
- (void)drawArrow:(NSScrollerArrow)whichButton highlight:(BOOL)flag
- (void) drawArrow: (NSScrollerArrow)whichButton highlight: (BOOL)flag
{
NSRect rect = [self rectForPart:(whichButton == NSScrollerIncrementArrow
NSRect rect = [self rectForPart: (whichButton == NSScrollerIncrementArrow
? NSScrollerIncrementLine : NSScrollerDecrementLine)];
id theCell = nil;
id theCell = nil;
NSDebugLog (@"position of %s cell is (%f, %f)",
(whichButton == NSScrollerIncrementArrow ? "increment" : "decrement"),
@ -670,42 +690,46 @@ id theCell = nil;
break;
}
[theCell drawWithFrame:rect inView:self];
[theCell drawWithFrame: rect inView: self];
}
- (void)drawKnob
- (void) drawKnob
{
[knobCell drawWithFrame:[self rectForPart:NSScrollerKnob] inView:self];
[knobCell drawWithFrame: [self rectForPart: NSScrollerKnob] inView: self];
}
- (void)drawKnobSlot
- (void) drawKnobSlot
{
NSRect rect;
NSRect rect;
if(preCalcValues) // in a modal loop we
rect = slotRect; // have already pre
else // calc'd our parts
rect = [self rectForPart:NSScrollerKnobSlot];
// in a modal loop we have already pre calc'd our parts
if (preCalcValues)
rect = slotRect;
else
rect = [self rectForPart: NSScrollerKnobSlot];
[[NSColor darkGrayColor] set];
NSRectFill(rect); // draw the bar slot
NSRectFill(rect);
}
- (NSRect)rectForPart:(NSScrollerPart)partCode
- (NSRect)rectForPart: (NSScrollerPart)partCode
{
NSRect scrollerFrame = frame;
float x = 1, y = 1, width = 0, height = 0, floatValue;
NSScrollArrowPosition arrowsPosition;
NSUsableScrollerParts usableParts;
// If the scroller is disabled then
if (!_isEnabled) // the scroller buttons and the
usableParts = NSNoScrollerParts; // knob are not displayed at all.
NSRect scrollerFrame = frame;
float x = 1, y = 1, width = 0, height = 0, floatValue;
NSScrollArrowPosition arrowsPosition;
NSUsableScrollerParts usableParts;
// If the scroller is disabled then the scroller buttons and the
// knob are not displayed at all.
if (!_isEnabled)
usableParts = NSNoScrollerParts;
else
usableParts = _usableParts;
// Since we haven't yet flipped views we have
if (!_isHorizontal) // to swap the meaning of the arrows position
{ // if the scroller's orientation is vertical.
// to swap the meaning of the arrows position
// if the scroller's orientation is vertical.
if (!_isHorizontal)
{
if (_arrowsPosition == NSScrollerArrowsMaxEnd)
arrowsPosition = NSScrollerArrowsMinEnd;
else
@ -722,8 +746,10 @@ NSUsableScrollerParts usableParts;
// Assign to `width' and `height' values describing
// the width and height of the scroller regardless
// of its orientation. Also compute the `floatValue'
if (_isHorizontal) // which is essentially the same width as _floatValue
{ // but keeps track of the scroller's orientation.
// which is essentially the same width as _floatValue
// but keeps track of the scroller's orientation.
if (_isHorizontal)
{
width = scrollerFrame.size.height;
height = scrollerFrame.size.width;
floatValue = _floatValue;
@ -733,15 +759,16 @@ NSUsableScrollerParts usableParts;
width = scrollerFrame.size.width;
height = scrollerFrame.size.height;
floatValue = 1 - _floatValue;
} // The x, y, width and height values
// are computed below for the vertical
switch (partCode) // scroller. The height of the scroll
{ // buttons is assumed to be equal to
case NSScrollerKnob: // the width.
}
// The x, y, width and height values are computed below for the vertical
// scroller. The height of the scroll buttons is assumed to be equal to
// the width.
switch (partCode)
{
case NSScrollerKnob:
{
float knobHeight, knobPosition, slotHeight;
// If the scroller does not have parts
// or a knob return a zero rect.
// If the scroller does not have parts or a knob return a zero rect.
if (usableParts == NSNoScrollerParts ||
usableParts == NSOnlyScrollerArrows)
return NSZeroRect;
@ -762,16 +789,17 @@ NSUsableScrollerParts usableParts;
0 : 2 * (buttonsWidth + buttonsDistance));
height = knobHeight;
width = buttonsWidth;
if (_isHorizontal) // keeps horiz knob off
y++; // of the buttons
if (_isHorizontal) // keeps horiz knob off of the buttons
y++;
break;
}
case NSScrollerKnobSlot:
x = 0; // if the scroller does
width = scrollerWidth; // not have buttons the
// slot completely
if (usableParts == NSNoScrollerParts) // fills the scroller.
// if the scroller does not have buttons the slot completely
// fills the scroller.
x = 0;
width = scrollerWidth;
if (usableParts == NSNoScrollerParts)
{
y = 0; // `height' unchanged
break;
@ -795,9 +823,9 @@ NSUsableScrollerParts usableParts;
case NSScrollerDecrementLine:
case NSScrollerDecrementPage:
if (usableParts == NSNoScrollerParts) // if scroller has no
return NSZeroRect; // parts or knob then
// return a zero rect
// if scroller has no parts or knob then return a zero rect
if (usableParts == NSNoScrollerParts)
return NSZeroRect;
width = buttonsWidth;
if (arrowsPosition == NSScrollerArrowsMaxEnd)
y = height - 2 * (buttonsWidth + buttonsDistance);
@ -813,9 +841,8 @@ NSUsableScrollerParts usableParts;
case NSScrollerIncrementLine:
case NSScrollerIncrementPage:
if (usableParts == NSNoScrollerParts) // if scroller has no
return NSZeroRect; // parts or knob then
// return a zero rect
if (usableParts == NSNoScrollerParts)
return NSZeroRect;
width = buttonsWidth;
if (arrowsPosition == NSScrollerArrowsMaxEnd)
y = height - (buttonsWidth + buttonsDistance);

View file

@ -561,7 +561,13 @@ NSPoint basePoint;
- (BOOL)isAutodisplay { return is_autodisplay; }
- (BOOL)isFlushWindowDisabled { return disable_flush_window; }
- (void)setAutodisplay:(BOOL)flag { is_autodisplay = flag; }
- (void)setViewsNeedDisplay:(BOOL)flag { needs_display = flag; }
- (void) setViewsNeedDisplay: (BOOL)flag
{
needs_display = flag;
[[NSApplication sharedApplication] setWindowsNeedUpdate: YES];
}
- (BOOL)viewsNeedDisplay { return needs_display; }
- (void)useOptimizedDrawing:(BOOL)flag { optimize_drawing = flag; }