Better handling of various textview/container offset by rulers & markers

This commit is contained in:
Airy ANDRE 2013-04-02 14:59:36 -07:00
parent 29cec72aa5
commit 368cfb8838
3 changed files with 26 additions and 22 deletions

View File

@ -147,13 +147,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
location = [_ruler convertPoint:location fromView:[[_ruler enclosingScrollView] documentView]];
}
float offset = [_ruler originOffset];
if ([_ruler orientation] == NSHorizontalRuler) {
rect.origin.x += location.x;
rect.origin.x += offset;
} else {
rect.origin.y += location.y; // how does a flipped system affect this? hm
rect.origin.y += offset;
}
rect.origin.x -= _imageOrigin.x;
rect.origin.y -= _imageOrigin.y;
@ -184,11 +181,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- (float)_markerLocationFromLocation:(NSPoint)point
{
if ([_ruler orientation] == NSHorizontalRuler) {
point.x -= [_ruler originOffset];
} else {
point.y -= [_ruler originOffset];
}
NSView *trackedView = _ruler.clientView;
if (trackedView == nil) {
trackedView = _ruler.enclosingScrollView.documentView;
@ -196,11 +188,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
point = [_ruler convertPoint:point toView:trackedView];
float newLocation = [_ruler orientation] == NSHorizontalRuler ? point.x : point.y;
if ([[_ruler clientView] respondsToSelector:@selector(rulerView:willAddMarker:atLocation:)])
newLocation = [[_ruler clientView] rulerView:_ruler willAddMarker:self atLocation:newLocation];
else
newLocation = newLocation;
return newLocation;
}
@ -227,7 +214,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
_markerLocation = [self _markerLocationFromLocation:point];
if ([[_ruler clientView] respondsToSelector:@selector(rulerView:willAddMarker:atLocation:)]) {
_markerLocation = [[_ruler clientView] rulerView:_ruler willAddMarker:self atLocation:_markerLocation];
}
// Draw the ruler + the new marker
[_ruler lockFocus];
[_ruler drawRect:[_ruler bounds]];
@ -275,6 +265,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
}
_markerLocation = [self _markerLocationFromLocation:point];
if ([[_ruler clientView] respondsToSelector:@selector(rulerView:willMoveMarker:toLocation:)]) {
_markerLocation = [[_ruler clientView] rulerView:_ruler willMoveMarker:self toLocation:_markerLocation];
}
[_ruler setNeedsDisplay:YES];
}
event = [[_ruler window] nextEventMatchingMask:NSLeftMouseUpMask|NSLeftMouseDraggedMask];

View File

@ -1744,7 +1744,7 @@ static inline void _appendRectToCache(NSLayoutManager *self,NSRect rect){
{
NSMutableArray *markers = [NSMutableArray array];
float delta = view.textContainer.lineFragmentPadding;
float delta = view.textContainer.lineFragmentPadding + view.textContainerOrigin.x;
// Add the margins markers
#if 0

View File

@ -725,7 +725,7 @@ NSString * const NSOldSelectedCharacterRange=@"NSOldSelectedCharacterRange";
NSRulerView *ruler = [[self enclosingScrollView] horizontalRulerView];
if(ruler!=nil){
[ruler setOriginOffset:[self textContainerOrigin].x];
[ruler setOriginOffset:self.textContainerOrigin.x + self.textContainer.lineFragmentPadding];
NSDictionary *typingAttributes = [self typingAttributes];
NSParagraphStyle *style=[typingAttributes objectForKey:NSParagraphStyleAttributeName];
@ -3054,8 +3054,9 @@ NSString * const NSOldSelectedCharacterRange=@"NSOldSelectedCharacterRange";
{
// Add a new tab stop - PQRulerView style
NSPoint point = [self convertPoint: event.locationInWindow fromView: nil];
float delta = rulerView.originOffset;
NSRulerMarker *marker = [NSRulerMarker leftTabMarkerWithRulerView:rulerView
location:point.x + self.textContainer.lineFragmentPadding];
location:point.x + delta];
NSTextTab *tabstop = [[[NSTextTab alloc] initWithType: NSLeftTabStopType location: point.x] autorelease];
[marker setRepresentedObject: tabstop];
[rulerView trackMarker: marker withMouseEvent: event];
@ -3068,12 +3069,18 @@ NSString * const NSOldSelectedCharacterRange=@"NSOldSelectedCharacterRange";
-(float)rulerView:(NSRulerView *)rulerView willMoveMarker:(NSRulerMarker *)marker toLocation:(float)location
{
if (location < rulerView.originOffset) {
location = rulerView.originOffset;
}
if (location > self.textContainer.containerSize.width - self.textContainer.lineFragmentPadding) {
location = self.textContainer.containerSize.width - self.textContainer.lineFragmentPadding;
}
return location;
}
-(void)rulerView:(NSRulerView *)rulerView didMoveMarker:(NSRulerMarker *)marker
{
float delta = self.textContainer.lineFragmentPadding;
float delta = rulerView.originOffset;
float location = marker.markerLocation - delta;
id representedObject = marker.representedObject;
@ -3146,12 +3153,19 @@ NSString * const NSOldSelectedCharacterRange=@"NSOldSelectedCharacterRange";
-(float)rulerView:(NSRulerView *)rulerView willAddMarker:(NSRulerMarker *)marker atLocation:(float)location
{
if (location < rulerView.originOffset) {
location = rulerView.originOffset;
}
if (location > self.textContainer.containerSize.width - self.textContainer.lineFragmentPadding) {
location = self.textContainer.containerSize.width - self.textContainer.lineFragmentPadding;
}
return location;
}
-(void)rulerView:(NSRulerView *)rulerView didAddMarker:(NSRulerMarker *)marker
{
float delta = self.textContainer.lineFragmentPadding;
float delta = rulerView.originOffset;
float location = marker.markerLocation - delta;
id representedObject = marker.representedObject;
@ -3215,9 +3229,6 @@ NSString * const NSOldSelectedCharacterRange=@"NSOldSelectedCharacterRange";
-(void)rulerView:(NSRulerView *)rulerView didRemoveMarker:(NSRulerMarker *)marker
{
float delta = self.textContainer.lineFragmentPadding;
float location = marker.markerLocation - delta;
id representedObject = marker.representedObject;
if ([representedObject isKindOfClass:[NSTextTab class]]) {
NSTextTab *textTab = (NSTextTab *)representedObject;