Hi,
I've made a patch for NSTextView.m and GSSimpleLayoutManager.m so that
we really use the insets in NSTextView when drawing the content to the
screen.
I've done a lot of testing and it seems to work very well.
Thanks a lot,
Ludovic
--
Live as if you were to die tomorrow.
Learn as if you were to live forever.
- Gandhi
--- /tmp/gui/Source/NSTextView.m Tue Oct 30 20:09:07 2001
+++ NSTextView.m Wed Oct 31 18:14:03 2001
@@ -229,6 +229,7 @@
[self setTypingAttributes: [isa defaultTypingAttributes]];
+ [self setTextContainerInset: NSMakeSize(0,0)];
[self setBackgroundColor: [NSColor textBackgroundColor]];
[aTextContainer setTextView: self];
@@ -1037,11 +1038,13 @@
_textContainerOrigin.x += usedRect.origin.x;
/* First get the pure text container origin */
- _textContainerOrigin.y = NSMaxY (_bounds);
- _textContainerOrigin.y -= _textContainerInset.height;
- _textContainerOrigin.y -= textContainerSize.height;
+ //_textContainerOrigin.y = NSMaxY (_bounds);
+ //_textContainerOrigin.y -= _textContainerInset.height;
+ //_textContainerOrigin.y -= textContainerSize.height;
/* Then move to the used rect origin */
- _textContainerOrigin.y += usedRect.origin.y;
+ //_textContainerOrigin.y += usedRect.origin.y;
+
+ _textContainerOrigin.y = _textContainerInset.height;
}
- (NSLayoutManager*) layoutManager
@@ -2116,6 +2119,10 @@
possible) */
startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
+
+ startPoint.x += _textContainerInset.width;
+ startPoint.y += _textContainerInset.height;
+
startIndex = [self characterIndexForPoint: startPoint];
if ([_textStorage containsAttachments])
--- /tmp/gui/Source/GSSimpleLayoutManager.m Sun Sep 23 18:09:48 2001
+++ GSSimpleLayoutManager.m Wed Oct 31 18:20:38 2001
@@ -361,6 +361,8 @@
{
//FIXME: This currently ignores most of its arguments
+ NSSize insets = [[aTextContainer textView] textContainerInset];
+
if (!rectCount)
return _rects;
@@ -387,7 +389,7 @@
width - startRect.origin.x,
startRect.size.height);
// second line
- _rects[1] = NSMakeRect (0, endRect.origin.y, endRect.origin.x,
+ _rects[1] = NSMakeRect (insets.width, endRect.origin.y, endRect.origin.x -
+insets.width,
endRect.size.height);
*rectCount = 2;
}
@@ -400,11 +402,11 @@
width - startRect.origin.x,
startRect.size.height);
// intermediate lines
- _rects[1] = NSMakeRect (0, NSMaxY(startRect),
- width,
+ _rects[1] = NSMakeRect (insets.width, NSMaxY(startRect),
+ width - insets.width,
endRect.origin.y - NSMaxY (startRect));
// last line
- _rects[2] = NSMakeRect (0, endRect.origin.y, endRect.origin.x,
+ _rects[2] = NSMakeRect (insets.width, endRect.origin.y, endRect.origin.x -
+insets.width,
endRect.size.height);
*rectCount = 3;
}
@@ -502,6 +504,10 @@
NSRect rect = [self boundingRectForGlyphRange: glyphRange
inTextContainer: aTextContainer];
+ rect.origin.y -= containerOrigin.y;
+ rect.size.width += 2 * containerOrigin.x;
+ rect.size.height += 2 * containerOrigin.y;
+
/* FIXME: Which means that the following <which assumes we are
drawing in a text view> can't be correct */
// clear area under text
@@ -870,6 +876,8 @@
// for optimization detection
NSMutableArray *ghostArray = nil;
+ NSSize insets = [[aTextContainer textView] textContainerInset];
+
if (maxLines)
{
int insertionLineIndex = [self lineLayoutIndexForGlyphIndex:
@@ -914,7 +922,7 @@
lineLayoutWithRange: NSMakeRange (0, 0)
rect: NSMakeRect (0, 0, width, 12)
usedRect: NSMakeRect (0, 0, 0, 12)]];
- return NSMakeRange(0,1);
+ return NSMakeRange(0 + insets.width, 1 + insets.height);
}
currentLineIndex = aLine;
@@ -970,7 +978,7 @@
if (NSIsEmptyRect(remainingRect))
{
- fragmentRect = NSMakeRect (0, drawingPoint.y, HUGE, HUGE);
+ fragmentRect = NSMakeRect (0+insets.width, drawingPoint.y+insets.height,
+HUGE, HUGE);
}
else
{