Rewrite and tidy of code to constrain scroll point. Incorporate some

ideas from xraw.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3577 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-01-19 10:58:51 +00:00
parent 9ddd4532b3
commit dad20c9355

View file

@ -51,20 +51,31 @@
ASSIGN(_documentView, aView); ASSIGN(_documentView, aView);
if (_documentView) { if (_documentView)
[self addSubview:_documentView]; {
NSRect df;
/* Register for notifications sent by the document view */ [self addSubview: _documentView];
[_documentView setPostsFrameChangedNotifications:YES];
[_documentView setPostsBoundsChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self df = [_documentView frame];
if ([_documentView isFlipped])
df.origin.y += bounds.size.height - df.size.height;
[self setBoundsOrigin: df.origin];
if ([aView respondsToSelector: @selector(backgroundColor)])
[self setBackgroundColor: [(id)aView backgroundColor]];
/* Register for notifications sent by the document view */
[_documentView setPostsFrameChangedNotifications:YES];
[_documentView setPostsBoundsChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(viewFrameChanged:) selector:@selector(viewFrameChanged:)
name:NSViewFrameDidChangeNotification object:_documentView]; name:NSViewFrameDidChangeNotification object:_documentView];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(viewBoundsChanged:) selector:@selector(viewBoundsChanged:)
name:NSViewBoundsDidChangeNotification object:_documentView]; name:NSViewBoundsDidChangeNotification object:_documentView];
} }
/* TODO: invoke superview's reflectScrolledClipView:? */ /* TODO: invoke superview's reflectScrolledClipView:? */
[[self superview] reflectScrolledClipView:self]; [[self superview] reflectScrolledClipView:self];
@ -74,6 +85,15 @@
{ {
[self addCursorRect:[self bounds] cursor:_cursor]; [self addCursorRect:[self bounds] cursor:_cursor];
} }
- (void) resizeSubviewsWithOldSize: (NSSize)old_size
{
[super resizeSubviewsWithOldSize: old_size];
if ([_documentView isFlipped])
{
[self scrollToPoint: bounds.origin];
}
}
- (void)scrollToPoint:(NSPoint)point - (void)scrollToPoint:(NSPoint)point
{ {
@ -85,31 +105,53 @@
point.x, point.y); point.x, point.y);
#endif #endif
point = [self constrainScrollPoint:point]; point = [self constrainScrollPoint: point];
[self setBoundsOrigin:NSMakePoint(point.x, point.y)]; [self setBoundsOrigin: NSMakePoint(point.x, point.y)];
[self setNeedsDisplay: YES];
if (_copiesOnScroll) if (_copiesOnScroll)
/* TODO: move the visible portion of the document */; /* TODO: move the visible portion of the document */
[_documentView displayRect: bounds];
else else
[_documentView setNeedsDisplay:YES]; [_documentView setNeedsDisplayInRect: bounds];
// [_documentView setNeedsDisplay: YES];
[self display];
} }
- (NSPoint)constrainScrollPoint:(NSPoint)proposedNewOrigin - (NSPoint)constrainScrollPoint:(NSPoint)proposedNewOrigin
{ {
NSRect documentFrame = [self documentRect]; NSRect documentFrame = [_documentView frame];
NSPoint new = proposedNewOrigin; NSPoint new = proposedNewOrigin;
if (proposedNewOrigin.x < documentFrame.origin.x) if (documentFrame.size.width <= bounds.size.width)
new.x = 0.0;
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
> documentFrame.size.width - bounds.size.width) >= documentFrame.size.width - bounds.size.width)
new.x = documentFrame.size.width - bounds.size.width; new.x = documentFrame.size.width - bounds.size.width;
if (proposedNewOrigin.y < documentFrame.origin.y) if ([_documentView isFlipped])
new.y = documentFrame.origin.y; {
else if (proposedNewOrigin.y if (documentFrame.size.height <= bounds.size.height)
> documentFrame.size.height - bounds.size.height) new.y = documentFrame.origin.y
new.y = documentFrame.size.height - bounds.size.height; + (documentFrame.size.height - bounds.size.height);
else if (proposedNewOrigin.y <= 0)
new.y = 0;
else if (proposedNewOrigin.y
>= documentFrame.size.height - bounds.size.height)
new.y = documentFrame.size.height - bounds.size.height;
}
else
{
if (documentFrame.size.height <= bounds.size.height)
new.y = 0.0;
else if (proposedNewOrigin.y <= documentFrame.origin.y)
new.y = documentFrame.origin.y;
else if (proposedNewOrigin.y
>= documentFrame.size.height - bounds.size.height)
new.y = documentFrame.size.height - bounds.size.height;
}
return new; return new;
} }
@ -141,6 +183,12 @@
return rect; return rect;
} }
- (void) drawRect:(NSRect)rect
{
[[self backgroundColor] set];
NSRectFill(rect);
}
- (BOOL)autoscroll:(NSEvent*)theEvent - (BOOL)autoscroll:(NSEvent*)theEvent
{ {
return 0; return 0;
@ -153,7 +201,7 @@
- (void)viewFrameChanged:(NSNotification*)aNotification - (void)viewFrameChanged:(NSNotification*)aNotification
{ {
[self setBoundsOrigin:[self constrainScrollPoint:bounds.origin]]; [self setBoundsOrigin: [self constrainScrollPoint: bounds.origin]];
[super_view reflectScrolledClipView:self]; [super_view reflectScrolledClipView:self];
} }