Re: NSTextView and Line Numbering
Re: NSTextView and Line Numbering
- Subject: Re: NSTextView and Line Numbering
- From: James Derry <email@hidden>
- Date: Sun, 23 Feb 2003 13:36:57 -0500
I've been swapping in the new text container in the subclassed NSTextView's
initWithFrame method, and I know it's getting used:
- (id)initWithFrame:(NSRect)frameRect {
[super initWithFrame:frameRect]; // inherited initWithFrame
NSTextContainer *oldContainer = [self textContainer];
JSDLineNumberTextContainer *newContainer = [[JSDLineNumberTextContainer
alloc]
initWithContainerSize: [oldContainer containerSize]];
[self replaceTextContainer:newContainer];
return self;
} // initWithFrame
But I think I found out what's causing the conflict. On this same NSTextView
subclass I also implement this copied from Apple's TextSizingExample:
-(void)setWordWrapping:(BOOL)state {
// only support turning wrapping to NO for right now.
if (!state) {
const float LargeNumberForText = 1.0e7;
NSScrollView *scrollView = (NSScrollView *)[[self superview]
superview]; // get the TextView's scroll-view.
NSTextContainer *container = [self textContainer]; //
get the textContainer object.
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutoresizingMask:(NSViewWidthSizable |
NSViewHeightSizable)];
[[scrollView contentView] setAutoresizesSubviews:YES];
[container setContainerSize:NSMakeSize(LargeNumberForText,
LargeNumberForText)];
[container setWidthTracksTextView:NO];
[container setHeightTracksTextView:NO];
[self setMaxSize:NSMakeSize(LargeNumberForText,
LargeNumberForText)];
[self setHorizontallyResizable:YES];
[self setVerticallyResizable:YES];
[self setAutoresizingMask:NSViewNotSizable];
} // if
} // setWordWrapping
So, as long I DON'T mess with the original wrapping/sizing behavior of the
NSTextView, your routines worked perfectly for me. Using the setWordWrapping
I implemented above causes your routines to behave strangely for me.
The good news is I'm learning a LOT more about the Cocoa text system than
I'd planned, and I think I'll find a way around it.
As always, thanks!
On 2/23/03 12:54 PM, "Koen van der Drift" <email@hidden> wrote:
>
At 10:25 AM -0500 2/23/03, James Derry wrote:
>
>
> I am having a little bit of difficulty with the pasting text into the
>
> TextView with the line numbers displayed. Do you get strange behavior?
>
>
No - I have no problems. One thing I added later is a force redraw of the
>
linenumbers when a sheet comes up. I used the windowDidUpdate notification
>
for this.
>
>
>
If I
>
> step through lineFragmentRectForProposedRect:, it always properly returns
>
> the correct corrected rectangle, but I get two types of misbehavior: (1) if
>
> I paste in multiple lines, all of the text appears shifted to the left UNDER
>
> the "left margin" area. If I paste in a single line, it appears okay, but
>
> further lines have the insertion point shifted to the right by the "left
>
> margin" distance -- but when typed is inserted into the correct spot.
>
>
Are you sure that you added myViewContainer to myTextView? In
>
myWindowController awakeFromNib I call:
>
>
contentSize = [scrollView contentSize];
>
frame = NSMakeRect(0, 0, contentSize.width, contentSize.height);
>
myContainer = [[MyViewContainer allocWithZone:[self zone]]
>
initWithContainerSize:NSMakeSize(frame.size.width, 100000)];
>
>
[myContainer setWidthTracksTextView:YES];
>
[myContainer setHeightTracksTextView:NO];
>
>
myTextView = [[MyTextView alloc] initWithFrame:frame];
>
[myTextView replaceTextContainer:myContainer];
>
>
[myContainer release];
>
>
>
>
>
hth,
>
>
- Koen.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.