Re: relation between NSTextStorage and appended NSAttributedString
Re: relation between NSTextStorage and appended NSAttributedString
- Subject: Re: relation between NSTextStorage and appended NSAttributedString
- From: Brock Brandenberg <email@hidden>
- Date: Sun, 06 Oct 2002 10:29:27 -0500
Arthur,
As Dietrich points out, NSTextStorage is a subclass of NSAttributedString,
so if you are using a text hierarchy automatically constructed by Cocoa, you
can access and alter the NSTextStorage like an NSAttributedString. Just make
sure that you respect the fact that all of the objects that make up this
hierarchy message one another with notifications to keep one another
updated. So if you make changes directly to the NSTextStorage mutable
string, make sure that you bracket these changes with beginEditing and
endEditing calls so that it can do all the proper messaging when you're done
with your changes.
If you are or wish to construct your own text hierarchy, you can initialize
an NSTextStorage with your own NSMutableAttributedString by using
initWithAttributedString:. I typically use an NSTextContainer,
NSLayoutManager and NSTextStorage without an associated NSTextView so that I
can utilize the graphical layout mechanism of the text hierarchy, but draw
the text myself using other means like appendBezierPathWithGlyph:. You can
use as much or little of the whole hierarchy as you need. Just recognize
that the text hierarchy objects do a lot of messaging between one another
behind the scenes, so read the docs and make sure that you don't circumvent
the native messaging mechanisms that make them all update properly.
>
I am trying to do something but it is not so clear to me:
>
>
In a NSTextView I have a NSMutableAttributedString object that I append
>
to the text view's NSTextStorage.
>
But if I change the NSMutableAttributedString object, this change is
>
not reflected in the NSTextStorage. And also the other way around: when
>
I type in the NSTextView, the NSMutableAttributedString object is not
>
updated.
>
>
So it seems that [NSMutableAttributedString appendAttributedString]
>
does not keep a pointer reference but makes a copy of the sent
>
attributedString, and then forgets about it.
>
>
The method description in the docs points says it actually:
>
>
appendAttributedString:
>
- (void)appendAttributedString:(NSAttributedString *)attributedString
>
>
Adds the characters and attributes of attributedString to the end of
>
the receiver.
>
>
In my program I *would* like to have a direct relation NSTextStorage
>
<----> pointer to NSMutableAttributedString object.
>
This is somewhat like the relation between a NSTableView and its data
>
source, I guess.
>
>
Would it be unnatural to follow this path?
Brock Brandenberg
----- industrial design @ www.bergdesign.com ------
_______________________________________________
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.