Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
cocoa web browser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cocoa web browser



I'm attempting to make a simple html browser using the following:

a NSURLHandle to download the data
a NSTextView to display the HTML

To know when an image is loaded I register for HTMLDocumentChangedNotification, and on the notification I wish to refresh the NSTextView. To do this I am calling [myTextView setNeedsDisplay:YES]; only this causes the following message in stdout and no refresh:

2002-08-14 11:06:16.338 WeBrowser[896] drawWithOuterFrame:contentFrame:clipping: called on cell 0x1570b60 which has not yet measured! thread Thread 0x800013b8

If I comment out the setNeedsDisplay line and resize the window after the page first loads (manually) I get the webpage in it's full glory, but this is obviously not the best solution...

Any idea what is causing the error?? Otherwise, any ideas how to refresh the NSTextView effiecently?
(I've tried things like programmatically altering the window frame then returning it to the original size (slow) and passing the html data back to the NSTextView (even slower))


I'm having difficulty posting the code up on the internet so I've added it to the end of the email...

Thanks for any help,

Matt Smith


#import <Cocoa/Cocoa.h>

@interface AppController : NSObject
{
IBOutlet id myWindow;
IBOutlet id textThingy; // The textview
IBOutlet id URLField; // textfield containing url
NSURL * myURL;
NSURLHandle * myHandle;
NSData * responseData;
NSMutableAttributedString * responseString;
}
- (IBAction)go:(id)sender;
- (BOOL)textView: (NSTextView *)textView clickedOnLink: (id)link atIndex: (unsigned)charIndex;
- (void)HTMLChanged:(NSNotification *)notification;
@end


@implementation AppController

-(void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HTMLChanged:) name:@"HTMLDocumentChangedNotification" object:nil];
[URLField setStringValue:@"http://www.apple.com/";];
[self go:self];
}


- (IBAction)go:(id)sender
{
    if (myURL)
        [myURL release];
    myURL = [NSURL URLWithString:[URLField stringValue]];
    if (myHandle)
        [myHandle release];
    myHandle = [myURL URLHandleUsingCache:YES];

responseData = [[myHandle resourceData] autorelease];
responseString = [[[NSMutableAttributedString alloc] initWithHTML:responseData baseURL:myURL documentAttributes:nil] autorelease];
[[textThingy textStorage] setAttributedString:responseString];
}


- (BOOL)textView: (NSTextView *)textView clickedOnLink: (id)link atIndex: (unsigned)charIndex
{
myURL = [NSURL URLWithString: (NSString *) link relativeToURL:myURL];


    [URLField setStringValue:[myURL absoluteString]];

    myHandle = [myURL URLHandleUsingCache:YES];

responseData = [[myHandle resourceData] autorelease];
responseString = [[[NSMutableAttributedString alloc] initWithHTML:responseData baseURL:myURL documentAttributes:nil] autorelease];
[[textThingy textStorage] setAttributedString:responseString];
return true;
}


- (void)HTMLChanged:(NSNotification *)notification
{
    [textThingy setNeedsDisplay:YES];
}

@end
_______________________________________________
studentdev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/studentdev
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.