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

@ -1225,6 +1225,8 @@ BOOL done = NO;
int i, count; int i, count;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSArray *window_list = [self windows]; NSArray *window_list = [self windows];
windows_need_update = NO;
// notify that an update is // notify that an update is
// imminent // imminent
[nc postNotificationName:NSApplicationWillUpdateNotification object: self]; [nc postNotificationName:NSApplicationWillUpdateNotification object: self];

View file

@ -97,6 +97,9 @@
- (void) scrollToPoint: (NSPoint)point - (void) scrollToPoint: (NSPoint)point
{ {
NSRect originalBounds = [self bounds];
NSRect newBounds = originalBounds;
NSRect intersection;
#ifdef DEBUGLOG #ifdef DEBUGLOG
NSPoint currentPoint = [self bounds].origin; NSPoint currentPoint = [self bounds].origin;
@ -105,17 +108,92 @@
point.x, point.y); point.x, point.y);
#endif #endif
point = [self constrainScrollPoint: point]; newBounds.origin = [self constrainScrollPoint: point];
[self setBoundsOrigin: NSMakePoint(point.x, point.y)];
if (NSEqualPoints(originalBounds.origin, newBounds.origin))
return;
// [self setBoundsOrigin: newBounds.origin];
[self setNeedsDisplay: YES];
if (_copiesOnScroll) 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 else
[_documentView setNeedsDisplayInRect: bounds]; {
// [_documentView setNeedsDisplay: YES]; NSPoint destPoint = intersection.origin;
[self display]; 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
@ -124,7 +202,7 @@
NSPoint new = proposedNewOrigin; NSPoint new = proposedNewOrigin;
if (documentFrame.size.width <= bounds.size.width) if (documentFrame.size.width <= bounds.size.width)
new.x = 0.0; new.x = documentFrame.origin.x;
else if (proposedNewOrigin.x <= documentFrame.origin.x) else if (proposedNewOrigin.x <= documentFrame.origin.x)
new.x = documentFrame.origin.x; new.x = documentFrame.origin.x;
else if (proposedNewOrigin.x else if (proposedNewOrigin.x
@ -145,7 +223,7 @@
else else
{ {
if (documentFrame.size.height <= bounds.size.height) if (documentFrame.size.height <= bounds.size.height)
new.y = 0.0; new.y = documentFrame.origin.y;
else if (proposedNewOrigin.y <= documentFrame.origin.y) else if (proposedNewOrigin.y <= documentFrame.origin.y)
new.y = documentFrame.origin.y; new.y = documentFrame.origin.y;
else if (proposedNewOrigin.y else if (proposedNewOrigin.y
@ -247,15 +325,50 @@
[super_view reflectScrolledClipView:self]; [super_view reflectScrolledClipView:self];
} }
- (BOOL)isOpaque { return YES; } - (BOOL) isOpaque
- (id)documentView { return _documentView; } {
- (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; } return YES;
- (BOOL)copiesOnScroll { return _copiesOnScroll; } }
- (void)setDocumentCursor:(NSCursor*)aCursor { ASSIGN(_cursor, aCursor); }
- (NSCursor*)documentCursor { return _cursor; } - (id) documentView
- (NSColor*)backgroundColor { return _backgroundColor; } {
- (BOOL)isFlipped { return [_documentView isFlipped]; } return _documentView;
- (BOOL)acceptsFirstResponder { return _documentView != nil; } }
- (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 - (void) setBackgroundColor: (NSColor*)aColor
{ {

View file

@ -66,18 +66,28 @@ static Class rulerViewClass = nil;
} }
} }
+ (void)setRulerViewClass:(Class)aClass { rulerViewClass = aClass; } + (void) setRulerViewClass: (Class)aClass
+ (Class)rulerViewClass { return rulerViewClass; } {
rulerViewClass = aClass;
}
+ (NSSize)contentSizeForFrameSize:(NSSize)frameSize // calc content size by + (Class) rulerViewClass
hasHorizontalScroller:(BOOL)hFlag // taking into account {
hasVerticalScroller:(BOOL)vFlag // the border type return rulerViewClass;
}
+ (NSSize) contentSizeForFrameSize: (NSSize)frameSize
hasHorizontalScroller: (BOOL)hFlag
hasVerticalScroller: (BOOL)vFlag
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = frameSize; NSSize size = frameSize;
// Substract 1 from the width and height of // Substract 1 from the width and height of
if (hFlag) // the line that separates the horizontal // the line that separates the horizontal
{ // and vertical scroller from the clip view // and vertical scroller from the clip view
if (hFlag)
{
size.height -= [NSScroller scrollerWidth]; size.height -= [NSScroller scrollerWidth];
size.height -= 1; size.height -= 1;
} }
@ -113,9 +123,12 @@ NSSize size = frameSize;
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = contentSize; NSSize size = contentSize;
// Add 1 to the width and height for the // Add 1 to the width and height for the
if (hFlag) // line that separates the horizontal and // line that separates the horizontal and
{ // vertical scroller from the clip view. // vertical scroller from the clip view.
if (hFlag)
{
size.height += [NSScroller scrollerWidth]; size.height += [NSScroller scrollerWidth];
size.height += 1; size.height += 1;
} }
@ -265,16 +278,22 @@ NSRect clipViewBounds = [_contentView bounds];
NSScrollerPart hitPart = [scroller hitPart]; NSScrollerPart hitPart = [scroller hitPart];
NSRect documentRect = [_contentView documentRect]; NSRect documentRect = [_contentView documentRect];
float amount = 0; float amount = 0;
NSPoint point; NSPoint point = clipViewBounds.origin;
NSDebugLog (@"_doScroll: float value = %f", floatValue); NSDebugLog (@"_doScroll: float value = %f", floatValue);
// do nothing if scroller is unknown
if (scroller != _horizScroller && scroller != _vertScroller)
return;
_knobMoved = NO; _knobMoved = NO;
if(hitPart == NSScrollerKnob) if (hitPart == NSScrollerKnob || hitPart == NSScrollerKnobSlot)
_knobMoved = YES; _knobMoved = YES;
else 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) if (hitPart == NSScrollerIncrementLine)
amount = _lineScroll; amount = _lineScroll;
else if (hitPart == NSScrollerIncrementPage) else if (hitPart == NSScrollerIncrementPage)
@ -284,7 +303,7 @@ NSPoint point;
else if (hitPart == NSScrollerDecrementPage) else if (hitPart == NSScrollerDecrementPage)
amount = -_pageScroll; amount = -_pageScroll;
else else
_knobMoved = YES; return;
} }
if (!_knobMoved) // button scrolling if (!_knobMoved) // button scrolling
@ -292,23 +311,18 @@ NSPoint point;
if (scroller == _horizScroller) if (scroller == _horizScroller)
{ {
point.x = clipViewBounds.origin.x + amount; point.x = clipViewBounds.origin.x + amount;
point.y = clipViewBounds.origin.y;
} }
else else
{ {
if (scroller == _vertScroller) if ([_contentView isFlipped])
{ {
point.x = clipViewBounds.origin.x;
// If view is flipped // If view is flipped
if ([_contentView isFlipped]) // reverse the scroll // reverse the scroll direction
amount = -amount; // direction amount = -amount;
}
NSDebugLog (@"increment/decrement: amount = %f, flipped = %d", NSDebugLog (@"increment/decrement: amount = %f, flipped = %d",
amount, [_contentView isFlipped]); amount, [_contentView isFlipped]);
point.y = clipViewBounds.origin.y + amount; 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 else // knob scolling
@ -317,33 +331,23 @@ NSPoint point;
{ {
point.x = floatValue * (documentRect.size.width point.x = floatValue * (documentRect.size.width
- clipViewBounds.size.width); - clipViewBounds.size.width);
point.y = clipViewBounds.origin.y;
} }
else else
{ {
if (scroller == _vertScroller)
{
point.x = clipViewBounds.origin.x;
if (![_contentView isFlipped]) if (![_contentView isFlipped])
floatValue = 1 - floatValue; floatValue = 1 - floatValue;
point.y = floatValue * (documentRect.size.height point.y = floatValue * (documentRect.size.height
- clipViewBounds.size.height); - clipViewBounds.size.height);
} }
else
return; // do nothing
}
} }
[_contentView scrollToPoint:point]; // scroll clipview [_contentView scrollToPoint: point];
if (!_knobMoved) // scroll clipview
{ // if scrolling via // reflectScrolledClipView has been called by the clipView.
[self reflectScrolledClipView:_contentView]; // buttons update
// if (scroller == _vertScroller) // scroller pos to //FIXME: should this be here?
// [_vertScroller displayIfNeeded]; // reflect clipview // NSWindow's doc says update is called for each event
// else [window update];
// [_horizScroller displayIfNeeded];
// [window flushWindow];
}
} }
- (void) reflectScrolledClipView: (NSClipView*)aClipView - (void) reflectScrolledClipView: (NSClipView*)aClipView
@ -353,12 +357,9 @@ NSRect clipViewBounds = NSZeroRect;
float floatValue; float floatValue;
float knobProportion; float knobProportion;
id documentView; id documentView;
// do nothing if
if(aClipView != _contentView) // aClipView is not
return; // our content view
// if (_knobMoved) // is this really needed? if (aClipView != _contentView)
// return; // FAR FIX ME ? return;
NSDebugLog (@"reflectScrolledClipView:"); NSDebugLog (@"reflectScrolledClipView:");
@ -381,7 +382,6 @@ id documentView;
floatValue = 1 - floatValue; floatValue = 1 - floatValue;
[_vertScroller setFloatValue: floatValue [_vertScroller setFloatValue: floatValue
knobProportion: knobProportion]; knobProportion: knobProportion];
[_vertScroller displayIfNeededIgnoringOpacity];
} }
} }
@ -398,11 +398,8 @@ id documentView;
clipViewBounds.size.width); clipViewBounds.size.width);
[_horizScroller setFloatValue: floatValue [_horizScroller setFloatValue: floatValue
knobProportion: knobProportion]; knobProportion: knobProportion];
[_horizScroller displayIfNeededIgnoringOpacity];
} }
} }
[window flushWindow];
} }
- (void) setHorizontalRulerView: (NSRulerView*)aRulerView // FIX ME - (void) setHorizontalRulerView: (NSRulerView*)aRulerView // FIX ME
@ -498,9 +495,10 @@ float borderThickness = 0;
contentRect.origin.y += scrollerWidth + 1; contentRect.origin.y += scrollerWidth + 1;
} }
// If the document view is not // If the document view is not flipped reverse the meaning
if (![_contentView isFlipped]) // flipped reverse the meaning // of the vertical scroller's
[_vertScroller setFloatValue:1]; // of the vertical scroller's if (![_contentView isFlipped])
[_vertScroller setFloatValue: 1];
[_horizScroller setFrame: horizScrollerRect]; [_horizScroller setFrame: horizScrollerRect];
[_vertScroller setFrame: vertScrollerRect]; [_vertScroller setFrame: vertScrollerRect];
[_contentView setFrame: contentRect]; [_contentView setFrame: contentRect];
@ -606,32 +604,109 @@ float borderThickness = 0;
} }
#endif #endif
- (id)documentView { return [_contentView documentView]; } - (id) documentView
- (NSCursor*)documentCursor { return [_contentView documentCursor]; } {
return [_contentView documentView];
}
- (NSCursor*) documentCursor
{
return [_contentView documentCursor];
}
- (void) setDocumentCursor: (NSCursor*)aCursor - (void) setDocumentCursor: (NSCursor*)aCursor
{ {
[_contentView setDocumentCursor: aCursor]; [_contentView setDocumentCursor: aCursor];
} }
- (BOOL)isOpaque { return YES; } - (BOOL) isOpaque
- (NSBorderType)borderType { return _borderType; } {
- (NSScroller*)verticalScroller { return _vertScroller; } return YES;
- (BOOL)hasVerticalScroller { return _hasVertScroller; } }
- (BOOL)hasHorizontalRuler { return _hasHorizRuler; }
- (NSSize)contentSize { return [_contentView bounds].size; } - (NSBorderType) borderType
- (NSView*)contentView { return _contentView; } {
- (NSRulerView*)horizontalRulerView { return _horizRuler; } return _borderType;
- (BOOL)hasVerticalRuler { return _hasVertRuler; } }
- (NSRulerView*)verticalRulerView { return _vertRuler; }
- (BOOL)rulersVisible { return _rulersVisible; } - (BOOL) hasVerticalScroller
- (void)setLineScroll:(float)aFloat { _lineScroll = aFloat; } {
- (float)lineScroll { return _lineScroll; } return _hasVertScroller;
- (void)setPageScroll:(float)aFloat { _pageScroll = aFloat; } }
- (float)pageScroll { return _pageScroll; }
- (void)setScrollsDynamically:(BOOL)flag { _scrollsDynamically = flag; } - (BOOL) hasHorizontalRuler
- (BOOL)scrollsDynamically { return _scrollsDynamically; } {
- (NSScroller*)horizontalScroller { return _horizScroller; } return _hasHorizRuler;
- (BOOL)hasHorizontalScroller { return _hasHorizScroller; } }
- (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 @end

View file

@ -77,27 +77,78 @@ static BOOL preCalcValues = NO;
[self setVersion: 1]; [self setVersion: 1];
} }
+ (float)scrollerWidth { return scrollerWidth; } + (float) 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
{ {
if (frameRect.size.width > frameRect.size.height) // determine the return scrollerWidth;
{ // orientation of }
_isHorizontal = YES; // the scroller and
frameRect.size.height = [isa scrollerWidth]; // adjust it's size - (NSScrollArrowPosition) arrowsPosition
} // accordingly {
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 else
{ {
_isHorizontal = NO; _isHorizontal = NO;
@ -119,15 +170,16 @@ static BOOL preCalcValues = NO;
return self; return self;
} }
- init - (id) init
{ {
return [self initWithFrame: NSZeroRect]; return [self initWithFrame: NSZeroRect];
} }
- (void) drawParts - (void) drawParts
{ // Create the class variable {
if (knobCell) // button cells if they do not // Create the class variable button cells if they do not yet exist.
return; // yet exist. if (knobCell)
return;
upCell = [NSButtonCell new]; upCell = [NSButtonCell new];
[upCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask]; [upCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
@ -193,11 +245,9 @@ float scrollerWidth = [isa scrollerWidth];
if (size > 3 * scrollerWidth + 2) if (size > 3 * scrollerWidth + 2)
_usableParts = NSAllScrollerParts; _usableParts = NSAllScrollerParts;
else else if (size > 2 * scrollerWidth + 1)
if (size > 2 * scrollerWidth + 1)
_usableParts = NSOnlyScrollerArrows; _usableParts = NSOnlyScrollerArrows;
else else
if (size > scrollerWidth)
_usableParts = NSNoScrollerParts; _usableParts = NSNoScrollerParts;
} }
@ -221,10 +271,12 @@ float scrollerWidth = [isa scrollerWidth];
- (void) setFloatValue: (float)aFloat - (void) setFloatValue: (float)aFloat
{ {
if (aFloat == _floatValue)
return;
if (aFloat < 0) if (aFloat < 0)
_floatValue = 0; _floatValue = 0;
else else if (aFloat > 1)
if (aFloat > 1)
_floatValue = 1; _floatValue = 1;
else else
_floatValue = aFloat; _floatValue = aFloat;
@ -236,8 +288,7 @@ float scrollerWidth = [isa scrollerWidth];
{ {
if (ratio < 0) if (ratio < 0)
_knobProportion = 0; _knobProportion = 0;
else else if (ratio > 1)
if (ratio > 1)
_knobProportion = 1; _knobProportion = 1;
else else
_knobProportion = ratio; _knobProportion = ratio;
@ -247,11 +298,12 @@ float scrollerWidth = [isa scrollerWidth];
- (void) setFrame: (NSRect)frameRect - (void) setFrame: (NSRect)frameRect
{ {
if (frameRect.size.width > frameRect.size.height) // determine the // determine the orientation of the scroller and adjust it's size accordingly
{ // orientation of if (frameRect.size.width > frameRect.size.height)
_isHorizontal = YES; // the scroller and {
frameRect.size.height = [isa scrollerWidth]; // adjust it's size _isHorizontal = YES;
} // accordingly frameRect.size.height = [isa scrollerWidth];
}
else else
{ {
_isHorizontal = NO; _isHorizontal = NO;
@ -276,9 +328,10 @@ float scrollerWidth = [isa scrollerWidth];
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
- (NSScrollerPart)testPart:(NSPoint)thePoint // return what part - (NSScrollerPart)testPart: (NSPoint)thePoint
{ // of the scroller {
NSRect rect; // the mouse hit // return what part of the scroller the mouse hit
NSRect rect;
if (thePoint.x < 0 || thePoint.x > frame.size.width if (thePoint.x < 0 || thePoint.x > frame.size.width
|| thePoint.y < 0 || thePoint.y > frame.size.height) || thePoint.y < 0 || thePoint.y > frame.size.height)
@ -318,8 +371,9 @@ NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
float floatValue = 0; float floatValue = 0;
float position; float position;
if (_isHorizontal) // Adjust point to lie // Adjust point to lie within the knob slot
{ // within the knob slot if (_isHorizontal)
{
float halfKnobRectWidth = knobRect.size.width / 2; float halfKnobRectWidth = knobRect.size.width / 2;
if (point.x < slotRect.origin.x + halfKnobRectWidth) if (point.x < slotRect.origin.x + halfKnobRectWidth)
@ -332,13 +386,13 @@ float position;
halfKnobRectWidth; halfKnobRectWidth;
else else
position = point.x; position = point.x;
} // Compute float value }
// given the knob size // Compute float value given the knob size
floatValue = (position - (slotRect.origin.x + halfKnobRectWidth)) floatValue = (position - (slotRect.origin.x + halfKnobRectWidth))
/ (slotRect.size.width - knobRect.size.width); / (slotRect.size.width - knobRect.size.width);
} }
else // Adjust point to lie else
{ // within the knob slot {
float halfKnobRectHeight = knobRect.size.height / 2; float halfKnobRectHeight = knobRect.size.height / 2;
if (point.y < slotRect.origin.y + halfKnobRectHeight) if (point.y < slotRect.origin.y + halfKnobRectHeight)
@ -352,7 +406,7 @@ float position;
else else
position = point.y; position = point.y;
} }
// Compute float value // Compute float value given the knob size
floatValue = (position - (slotRect.origin.y + halfKnobRectHeight)) / floatValue = (position - (slotRect.origin.y + halfKnobRectHeight)) /
(slotRect.size.height - knobRect.size.height); (slotRect.size.height - knobRect.size.height);
floatValue = 1 - floatValue; floatValue = 1 - floatValue;
@ -361,12 +415,11 @@ float position;
return floatValue; return floatValue;
} }
- (void)_preCalcParts // pre calculate - (void) _preCalcParts
{ // values to lessen {
NSRect knobRect = [self rectForPart:NSScrollerKnob]; // the burden while NSRect knobRect = [self rectForPart: NSScrollerKnob];
// scrolling
slotRect = [self rectForPart:NSScrollerKnobSlot];
slotRect = [self rectForPart: NSScrollerKnobSlot];
halfKnobRectWidth = knobRect.size.width / 2; halfKnobRectWidth = knobRect.size.width / 2;
slotOriginPlusKnobWidth = slotRect.origin.x + halfKnobRectWidth; slotOriginPlusKnobWidth = slotRect.origin.x + halfKnobRectWidth;
slotOriginPlusSlotWidthMinusHalfKnobWidth = slotRect.origin.x + slotOriginPlusSlotWidthMinusHalfKnobWidth = slotRect.origin.x +
@ -385,8 +438,8 @@ NSRect knobRect = [self rectForPart:NSScrollerKnob]; // the burden while
float floatValue = 0; float floatValue = 0;
float position; float position;
if (_isHorizontal) // Adjust point to lie if (_isHorizontal)
{ // within the knob slot {
if (point.x < slotOriginPlusKnobWidth) if (point.x < slotOriginPlusKnobWidth)
position = slotOriginPlusKnobWidth; position = slotOriginPlusKnobWidth;
else else
@ -395,13 +448,12 @@ float position;
position = slotOriginPlusSlotWidthMinusHalfKnobWidth; position = slotOriginPlusSlotWidthMinusHalfKnobWidth;
else else
position = point.x; position = point.x;
} // Compute float value }
// given the knob size
floatValue = (position - slotOriginPlusKnobWidth) / floatValue = (position - slotOriginPlusKnobWidth) /
slotWidthMinusKnobWidth; slotWidthMinusKnobWidth;
} }
else // Adjust point to lie else
{ // within the knob slot {
if (point.y < slotOriginPlusKnobHeight) if (point.y < slotOriginPlusKnobHeight)
position = slotOriginPlusKnobHeight; position = slotOriginPlusKnobHeight;
else else
@ -411,7 +463,7 @@ float position;
else else
position = point.y; position = point.y;
} }
// Compute float value
floatValue = (position - slotOriginPlusKnobHeight) / floatValue = (position - slotOriginPlusKnobHeight) /
slotHeightMinusKnobHeight; slotHeightMinusKnobHeight;
floatValue = 1 - floatValue; floatValue = 1 - floatValue;
@ -425,7 +477,6 @@ float position;
NSPoint location = [self convertPoint: [theEvent locationInWindow] NSPoint location = [self convertPoint: [theEvent locationInWindow]
fromView: nil]; fromView: nil];
[self lockFocus];
_hitPart = [self testPart: location]; _hitPart = [self testPart: location];
[self _setTargetAndActionToCells]; [self _setTargetAndActionToCells];
@ -448,9 +499,6 @@ NSPoint location = [self convertPoint:[theEvent locationInWindow]
[self setFloatValue: floatValue]; [self setFloatValue: floatValue];
[self sendAction: _action to: _target]; [self sendAction: _action to: _target];
[self drawKnobSlot];
[self drawKnob];
[window flushWindow];
[self trackKnob: theEvent]; [self trackKnob: theEvent];
break; break;
} }
@ -460,7 +508,6 @@ NSPoint location = [self convertPoint:[theEvent locationInWindow]
} }
_hitPart = NSScrollerNoPart; _hitPart = NSScrollerNoPart;
[self unlockFocus];
} }
- (void)trackKnob: (NSEvent*)theEvent - (void)trackKnob: (NSEvent*)theEvent
@ -489,21 +536,24 @@ NSMutableArray* path = [self _pathBetweenSubview:self
[self _preCalcParts]; // pre calc scroller parts [self _preCalcParts]; // pre calc scroller parts
preCalcValues = YES; preCalcValues = YES;
_hitPart = NSScrollerKnob; // set periodic events rate _hitPart = NSScrollerKnob;
// to achieve max of ~30fps // set periodic events rate to achieve max of ~30fps
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03]; [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode]; [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
while ((eventType = [theEvent type]) != NSLeftMouseUp) while ((eventType = [theEvent type]) != NSLeftMouseUp)
{ // user is moving scroller
if (eventType != NSPeriodic) // loop until left mouse up
{ {
apoint = [theEvent locationInWindow]; // zero the periodic count if (eventType != NSPeriodic)
periodCount = 0; // whenever a real position {
} // event is recieved apoint = [theEvent locationInWindow];
// zero the periodic count whenever a real position event is recieved
periodCount = 0;
}
else 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]; apoint = [window mouseLocationOutsideOfEventStream];
point = [matrix pointInMatrixSpace: apoint]; point = [matrix pointInMatrixSpace: apoint];
@ -514,28 +564,20 @@ NSMutableArray* path = [self _pathBetweenSubview:self
if (floatValue != oldFloatValue) if (floatValue != oldFloatValue)
{ {
if (floatValue < 0) [self setFloatValue: floatValue];
_floatValue = 0; [self sendAction: _action to: _target];
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];
oldFloatValue = floatValue; oldFloatValue = floatValue;
} // avoid timing related scrolling [window update];
// hesitation by counting number of }
knobRect.origin = point; // periodic events since scroll pos knobRect.origin = point;
} // was updated, when this reaches }
periodCount++; // 6x periodic rate an update is // avoid timing related scrolling hesitation by counting number of
} // forced on next periodic event // 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 theEvent = [app nextEventMatchingMask: eventMask
untilDate: theDistantFuture untilDate: theDistantFuture
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
@ -543,14 +585,6 @@ NSMutableArray* path = [self _pathBetweenSubview:self
} }
[NSEvent stopPeriodicEvents]; [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; preCalcValues = NO;
} }
@ -565,13 +599,14 @@ id theCell = nil;
NSRect rect; NSRect rect;
NSDebugLog (@"trackScrollButtons"); NSDebugLog (@"trackScrollButtons");
do { do
{
location = [self convertPoint: [theEvent locationInWindow]fromView: nil]; location = [self convertPoint: [theEvent locationInWindow]fromView: nil];
_hitPart = [self testPart: location]; _hitPart = [self testPart: location];
rect = [self rectForPart: _hitPart]; rect = [self rectForPart: _hitPart];
switch (_hitPart) // determine which switch (_hitPart)
{ // cell was hit {
case NSScrollerIncrementLine: case NSScrollerIncrementLine:
case NSScrollerIncrementPage: case NSScrollerIncrementPage:
theCell = (_isHorizontal ? rightCell : upCell); theCell = (_isHorizontal ? rightCell : upCell);
@ -589,25 +624,21 @@ NSRect rect;
if (theCell) if (theCell)
{ {
[self lockFocus];
[theCell highlight: YES withFrame: rect inView: self]; [theCell highlight: YES withFrame: rect inView: self];
[self unlockFocus];
[window flushWindow]; [window flushWindow];
NSLog (@"tracking cell %x", theCell); NSLog (@"tracking cell %x", theCell);
shouldReturn = [theCell trackMouse:theEvent // Track the mouse shouldReturn = [theCell trackMouse: theEvent
inRect:rect // until left mouse inRect: rect
ofView:self // goes up ofView: self
untilMouseUp: YES]; untilMouseUp: YES];
if([_target isKindOf:[NSScrollView class]]) // a hack for XRAW [self lockFocus];
{ // FIX ME
NSObject *targetCV = (NSObject *)[_target contentView];
if([targetCV respondsToSelector:@selector(_freeMatrix)])
[targetCV _freeMatrix];
}
[theCell highlight: NO withFrame: rect inView: self]; [theCell highlight: NO withFrame: rect inView: self];
[self unlockFocus];
[window flushWindow]; [window flushWindow];
} }
@ -624,17 +655,6 @@ NSRect rect;
NSDebugLog (@"return from trackScrollButtons"); 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 // draw the scroller
// //
@ -682,13 +702,14 @@ id theCell = nil;
{ {
NSRect rect; NSRect rect;
if(preCalcValues) // in a modal loop we // in a modal loop we have already pre calc'd our parts
rect = slotRect; // have already pre if (preCalcValues)
else // calc'd our parts rect = slotRect;
else
rect = [self rectForPart: NSScrollerKnobSlot]; rect = [self rectForPart: NSScrollerKnobSlot];
[[NSColor darkGrayColor] set]; [[NSColor darkGrayColor] set];
NSRectFill(rect); // draw the bar slot NSRectFill(rect);
} }
- (NSRect)rectForPart: (NSScrollerPart)partCode - (NSRect)rectForPart: (NSScrollerPart)partCode
@ -697,15 +718,18 @@ NSRect scrollerFrame = frame;
float x = 1, y = 1, width = 0, height = 0, floatValue; float x = 1, y = 1, width = 0, height = 0, floatValue;
NSScrollArrowPosition arrowsPosition; NSScrollArrowPosition arrowsPosition;
NSUsableScrollerParts usableParts; NSUsableScrollerParts usableParts;
// If the scroller is disabled then // If the scroller is disabled then the scroller buttons and the
if (!_isEnabled) // the scroller buttons and the // knob are not displayed at all.
usableParts = NSNoScrollerParts; // knob are not displayed at all. if (!_isEnabled)
usableParts = NSNoScrollerParts;
else else
usableParts = _usableParts; usableParts = _usableParts;
// Since we haven't yet flipped views we have // Since we haven't yet flipped views we have
if (!_isHorizontal) // to swap the meaning of the arrows position // to swap the meaning of the arrows position
{ // if the scroller's orientation is vertical. // if the scroller's orientation is vertical.
if (!_isHorizontal)
{
if (_arrowsPosition == NSScrollerArrowsMaxEnd) if (_arrowsPosition == NSScrollerArrowsMaxEnd)
arrowsPosition = NSScrollerArrowsMinEnd; arrowsPosition = NSScrollerArrowsMinEnd;
else else
@ -722,8 +746,10 @@ NSUsableScrollerParts usableParts;
// Assign to `width' and `height' values describing // Assign to `width' and `height' values describing
// the width and height of the scroller regardless // the width and height of the scroller regardless
// of its orientation. Also compute the `floatValue' // of its orientation. Also compute the `floatValue'
if (_isHorizontal) // which is essentially the same width as _floatValue // which is essentially the same width as _floatValue
{ // but keeps track of the scroller's orientation. // but keeps track of the scroller's orientation.
if (_isHorizontal)
{
width = scrollerFrame.size.height; width = scrollerFrame.size.height;
height = scrollerFrame.size.width; height = scrollerFrame.size.width;
floatValue = _floatValue; floatValue = _floatValue;
@ -733,15 +759,16 @@ NSUsableScrollerParts usableParts;
width = scrollerFrame.size.width; width = scrollerFrame.size.width;
height = scrollerFrame.size.height; height = scrollerFrame.size.height;
floatValue = 1 - _floatValue; floatValue = 1 - _floatValue;
} // The x, y, width and height values }
// are computed below for the vertical // The x, y, width and height values are computed below for the vertical
switch (partCode) // scroller. The height of the scroll // scroller. The height of the scroll buttons is assumed to be equal to
{ // buttons is assumed to be equal to // the width.
case NSScrollerKnob: // the width. switch (partCode)
{
case NSScrollerKnob:
{ {
float knobHeight, knobPosition, slotHeight; float knobHeight, knobPosition, slotHeight;
// If the scroller does not have parts // If the scroller does not have parts or a knob return a zero rect.
// or a knob return a zero rect.
if (usableParts == NSNoScrollerParts || if (usableParts == NSNoScrollerParts ||
usableParts == NSOnlyScrollerArrows) usableParts == NSOnlyScrollerArrows)
return NSZeroRect; return NSZeroRect;
@ -762,16 +789,17 @@ NSUsableScrollerParts usableParts;
0 : 2 * (buttonsWidth + buttonsDistance)); 0 : 2 * (buttonsWidth + buttonsDistance));
height = knobHeight; height = knobHeight;
width = buttonsWidth; width = buttonsWidth;
if (_isHorizontal) // keeps horiz knob off if (_isHorizontal) // keeps horiz knob off of the buttons
y++; // of the buttons y++;
break; break;
} }
case NSScrollerKnobSlot: case NSScrollerKnobSlot:
x = 0; // if the scroller does // if the scroller does not have buttons the slot completely
width = scrollerWidth; // not have buttons the // fills the scroller.
// slot completely x = 0;
if (usableParts == NSNoScrollerParts) // fills the scroller. width = scrollerWidth;
if (usableParts == NSNoScrollerParts)
{ {
y = 0; // `height' unchanged y = 0; // `height' unchanged
break; break;
@ -795,9 +823,9 @@ NSUsableScrollerParts usableParts;
case NSScrollerDecrementLine: case NSScrollerDecrementLine:
case NSScrollerDecrementPage: case NSScrollerDecrementPage:
if (usableParts == NSNoScrollerParts) // if scroller has no // if scroller has no parts or knob then return a zero rect
return NSZeroRect; // parts or knob then if (usableParts == NSNoScrollerParts)
// return a zero rect return NSZeroRect;
width = buttonsWidth; width = buttonsWidth;
if (arrowsPosition == NSScrollerArrowsMaxEnd) if (arrowsPosition == NSScrollerArrowsMaxEnd)
y = height - 2 * (buttonsWidth + buttonsDistance); y = height - 2 * (buttonsWidth + buttonsDistance);
@ -813,9 +841,8 @@ NSUsableScrollerParts usableParts;
case NSScrollerIncrementLine: case NSScrollerIncrementLine:
case NSScrollerIncrementPage: case NSScrollerIncrementPage:
if (usableParts == NSNoScrollerParts) // if scroller has no if (usableParts == NSNoScrollerParts)
return NSZeroRect; // parts or knob then return NSZeroRect;
// return a zero rect
width = buttonsWidth; width = buttonsWidth;
if (arrowsPosition == NSScrollerArrowsMaxEnd) if (arrowsPosition == NSScrollerArrowsMaxEnd)
y = height - (buttonsWidth + buttonsDistance); y = height - (buttonsWidth + buttonsDistance);

View file

@ -561,7 +561,13 @@ NSPoint basePoint;
- (BOOL)isAutodisplay { return is_autodisplay; } - (BOOL)isAutodisplay { return is_autodisplay; }
- (BOOL)isFlushWindowDisabled { return disable_flush_window; } - (BOOL)isFlushWindowDisabled { return disable_flush_window; }
- (void)setAutodisplay:(BOOL)flag { is_autodisplay = flag; } - (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; } - (BOOL)viewsNeedDisplay { return needs_display; }
- (void)useOptimizedDrawing:(BOOL)flag { optimize_drawing = flag; } - (void)useOptimizedDrawing:(BOOL)flag { optimize_drawing = flag; }