mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 15:51:55 +00:00
(-scrollRectToVisible:): Implement correctly, patch from Andrew Ruder.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19968 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9c44969b67
commit
73cac47b98
2 changed files with 30 additions and 30 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-09-02 00:17 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
* Source/NSView.m (-replaceSubview:with:): Clarify documentation.
|
||||||
|
(-scrollRectToVisible:): Implement correctly, patch from Andrew
|
||||||
|
Ruder. Document.
|
||||||
|
|
||||||
2004-08-30 Quentin Mathe <qmathe@club-internet.fr>
|
2004-08-30 Quentin Mathe <qmathe@club-internet.fr>
|
||||||
|
|
||||||
* Headers/AppKit/NSCell.h:
|
* Headers/AppKit/NSCell.h:
|
||||||
|
|
|
@ -635,7 +635,9 @@ GSSetDragTypes(NSView* obj, NSArray *types)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes oldView from the receiver and places newView in its place.
|
* Removes oldView, which should be a subview of the receiver, from the
|
||||||
|
* receiver and places newView in its place. If newView is nil, just
|
||||||
|
* removes oldView. If oldView is nil, just adds newView.
|
||||||
*/
|
*/
|
||||||
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
|
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
|
||||||
{
|
{
|
||||||
|
@ -2379,6 +2381,11 @@ in the main thread.
|
||||||
- (void) scrollRect: (NSRect)aRect by: (NSSize)delta
|
- (void) scrollRect: (NSRect)aRect by: (NSSize)delta
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Scrolls the nearest enclosing clip view the minimum required distance
|
||||||
|
necessary to make aRect (or as much of it possible) in the receiver visible.
|
||||||
|
Returns YES iff any scrolling was done.
|
||||||
|
*/
|
||||||
- (BOOL) scrollRectToVisible: (NSRect)aRect
|
- (BOOL) scrollRectToVisible: (NSRect)aRect
|
||||||
{
|
{
|
||||||
NSClipView *s = (NSClipView*)_super_view;
|
NSClipView *s = (NSClipView*)_super_view;
|
||||||
|
@ -2391,42 +2398,29 @@ in the main thread.
|
||||||
{
|
{
|
||||||
NSRect vRect = [self visibleRect];
|
NSRect vRect = [self visibleRect];
|
||||||
NSPoint aPoint = vRect.origin;
|
NSPoint aPoint = vRect.origin;
|
||||||
BOOL shouldScroll = NO;
|
// Ok we assume that the rectangle is origined at the bottom left
|
||||||
|
// and goes to the top and right as it grows in size for the naming
|
||||||
|
// of these variables
|
||||||
|
float ldiff, rdiff, tdiff, bdiff;
|
||||||
|
|
||||||
if (vRect.size.width == 0 && vRect.size.height == 0)
|
if (vRect.size.width == 0 && vRect.size.height == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
if (!(NSMinX(vRect) <= NSMinX(aRect)
|
// Find the differences on each side.
|
||||||
&& (NSMaxX(vRect) >= NSMaxX(aRect))))
|
ldiff = NSMinX(vRect) - NSMinX(aRect);
|
||||||
{
|
rdiff = NSMaxX(aRect) - NSMaxX(vRect);
|
||||||
shouldScroll = YES;
|
bdiff = NSMinY(vRect) - NSMinY(aRect);
|
||||||
if (aRect.origin.x < vRect.origin.x)
|
tdiff = NSMaxY(aRect) - NSMaxY(vRect);
|
||||||
aPoint.x = aRect.origin.x;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float visibleRange = vRect.origin.x + vRect.size.width;
|
|
||||||
float aRectRange = aRect.origin.x + aRect.size.width;
|
|
||||||
|
|
||||||
aPoint.x = vRect.origin.x + (aRectRange - visibleRange);
|
// If the diff's have the same sign then nothing needs to be scrolled
|
||||||
}
|
if ((ldiff * rdiff) >= 0.0) ldiff = rdiff = 0.0;
|
||||||
}
|
if ((bdiff * tdiff) >= 0.0) bdiff = tdiff = 0.0;
|
||||||
|
|
||||||
if (!(NSMinY(vRect) <= NSMinY(aRect)
|
// Move the smallest difference
|
||||||
&& (NSMaxY(vRect) >= NSMaxY(aRect))))
|
aPoint.x += (fabs(ldiff) < fabs(rdiff)) ? (-ldiff) : rdiff;
|
||||||
{
|
aPoint.y += (fabs(bdiff) < fabs(tdiff)) ? (-bdiff) : tdiff;
|
||||||
shouldScroll = YES;
|
|
||||||
if (aRect.origin.y < vRect.origin.y)
|
|
||||||
aPoint.y = aRect.origin.y;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float visibleRange = vRect.origin.y + vRect.size.height;
|
|
||||||
float aRectRange = aRect.origin.y + aRect.size.height;
|
|
||||||
|
|
||||||
aPoint.y = vRect.origin.y + (aRectRange - visibleRange);
|
if (aPoint.x != vRect.origin.x || aPoint.y != vRect.origin.y)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldScroll)
|
|
||||||
{
|
{
|
||||||
aPoint = [self convertPoint: aPoint toView: s];
|
aPoint = [self convertPoint: aPoint toView: s];
|
||||||
[s scrollToPoint: aPoint];
|
[s scrollToPoint: aPoint];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue