Re: Changing the textStorage in a textView
Re: Changing the textStorage in a textView
- Subject: Re: Changing the textStorage in a textView
- From: Mike Ferris <email@hidden>
- Date: Sat, 11 Jan 2003 10:33:55 -0800
[[textView layoutManager] replaceTextStorage:textStorage] should do it.
However, you might want to consider more specifically what you're
trying to accomplish. If you simply want to use a custom NSTextStorage
subclass or something, use that method.
But, for example, if you're setting up a text view that will have
different "documents" swapped into it at different times (like the
editor in an all-in-one Project Builder window), then you should learn
more about the text system objects and their relationships and do this
a bit different. The docs go into detail, but the summary is:
- NSTextStorage has-a and owns list of NSLayoutManagers
- NSLayoutManager has-a and owns a list of NSTextContainers
- NSTextContainer has-a and owns an NSTextView
- If you use -initWithFrame: to create an NSTextView (or get it out
of a nib file) it actually creates one of each of these and arranges
(through some ref-counting magic) to have the NSTextView own the whole
web. (Yes this is a retain loop, but that's what the ref-counting
magic is for.)
If you want to share a view among different backing stores at different
times, the best way to go is to create the NSLayoutManager,
NSTextContainer and NSTextView and get them all hooked together:
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
NSTextContainer *tc = [[NSTextContainer alloc]
initWithContainerSize:NSMakeSize(width, 1.0e7)];
NSTextView *tv = [[NSTextView alloc] initWithFrame:frame
textContainer:tc];
[lm addTextContainer:tc];
[tc release];
[tv release];
// Hold on to lm
Now you have a complete web except for the backing store. You hold
onto lm and it holds on to everything else.
To change backing stores:
NSTextStorage *oldts, *newts; // assume these exist...
if (oldts) {
[oldts removeLayoutManager:lm];
}
if (newts) {
[ts addLayoutManager:lm];
}
Mike
_______________________________________________
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.