Hi,

My program allows the user to switch between different text documents by 
choosing them from a source list; the documents are displayed on the right. 
Each document has its own text storage. I switch between text storages using 
[textStorage removeLayoutManager:textViewLayoutManager], [newTextStorage 
addLayoutManager:textViewLayoutManager]. Obviously, this is much simplified, 
but this is the basic setup.

Just recently I added a pages view to my program, so that the user can choose 
to see a page layout view instead of a straight text view. The pages view is 
pretty much based on TextEdit. However, I have found that switching text 
storages on a multiple pages view such as the one in TextEdit causes certain 
drawing problems; the interface doesn't get updated properly. In my case this 
means that I have a footer view showing the number of pages that reports the 
wrong number and lines dividing the text views that are either missing or only 
half-drawn. If I resize the window as soon as it appears, these strange 
artefacts disappear. NSLogging shows that the correct info (number of pages 
etc) is being sent, it just isn't being displayed (even if I try to force it). 
I posted a question relating to this here a little while ago:

http://www.cocoabuilder.com/archive/message/cocoa/2008/3/9/200843

Now it seems that this is not so much a problem of my view not forcing display 
properly, though, as just a problem with switching text storages in a multiple 
page view. I tested it out in TextEdit and found redrawing problems there, too. 
In TextEdit, I just added the following code to DocumentWindowController.m:

- (IBAction)reloadText:(id)sender
{
    [[[self firstTextView] textStorage] removeLayoutManager:layoutMgr];
   
    MultiplePageView *pagesView = [scrollView documentView];

    // Trim pages, otherwise we get all sorts of problems (clickable areas
    // not responding, drawing errors where text disappears etc).
    while ([pagesView numberOfPages] > 1)
        [self removePage];
   
    // Switch for a text storage that contains a couple of pages' worth
    // of text.
    NSData *rtfData = [[NSData alloc] initWithContentsOfFile:[[NSBundle 
mainBundle] pathForResource:@"Text" ofType:@"rtf"]];
    NSTextStorage *text = [[NSTextStorage alloc] initWithRTF:rtfData 
documentAttributes:nil];
    [text addLayoutManager:layoutMgr];
    [rtfData release];
    // Yes, I know, this leaks, but this is just test code :)
}

When this is called, there will be drawing problems in the second page in 
TextEdit (the border doesn't get drawn etc).

Background layout seems to be the culprit... At the moment I am working around 
this by forcing foreground layout using code based on 
doForegroundLayoutToCharacterIndex: from text edit, forcing layout of the first 
50,000 characters (hopefully enough so that it forces the visible pages to get 
laid out). This makes sure that there are no drawing problems.

Am I taking the wrong approach here? If I want to swap the text storage for a 
multiple pages view such as the one in TextEdit, what is the best way to do it? 
Why do I need to force layout like this? If anyone has any suggestions, 
solutions, or just reasons for why I might be encountering these problems, I 
would be very grateful.

Many thanks in advance and all the best,
Keith



      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to