Re: NSLayoutManager strangeness
Re: NSLayoutManager strangeness
- Subject: Re: NSLayoutManager strangeness
- From: Satoshi Matsumoto <email@hidden>
- Date: Fri, 05 Aug 2005 18:22:17 +0900
on 05.8.5 1:57 PM, Duncan Campbell at email@hidden wrote:
> However, if I try to use my own NSLayoutManager, my draw code does
> not work correctly until i press a key.
>
> Even if I simply do:
>
> NSLayoutManager *lm = [[NSLayoutManager alloc] init];
> [[self textContainer] replaceLayoutManager:lm];
> [lm release];
>
> In my NSTextView's initWithFrame: (i.e. no subclass code at all)
> things break.
Try the code below in your awakeFromNib of NSTextView subclass.
Because the hierarchy of the text system is:
NSTextStrage->NSLayoutManager->NSTextContainer->NSTextView
- (void)awakeFromNib
{
NSLayoutManager *oldLayoutManager;
NSLayoutManager *newLayoutManager;
NSTextContainer *textContainer;
NSTextStorage *text = [self textStorage];
oldLayoutManager = [self layoutManager];
newLayoutManager = [[NSLayoutManager alloc] init];
textContainer = [self textContainer];
[textContainer retain];
[oldLayoutManager removeTextContainerAtIndex:0];
[newLayoutManager addTextContainer:textContainer];
[text addLayoutManager:newLayoutManager];
[text removeLayoutManager:oldLayoutManager];
[textContainer release];
[newLayoutManager release];
.......
}
Satoshi
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden