• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problem displaying html in NSTextView...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem displaying html in NSTextView...


  • Subject: Re: problem displaying html in NSTextView...
  • From: Markus Hitter <email@hidden>
  • Date: Thu, 18 Oct 2001 22:28:44 +0200

Am Donnerstag, 18. Oktober 2001 um 19:49 schrieb Thierry Bucco:

Hi,

I have an NSTextView which displays html strings.

I want to open an url when I click on a link, it works right now, my problem is I want to convert html string to readable text, I am using the following code :

// range of my string to be inserted in the NSTextField
//

// textView is my NSTextView
// text is my NSString to be inserted in my NSTextView

begin = [[textView string] length];
end = begin + [text length];

Do you acually use "end" anywhere?

[textStorage beginEditing];


/*
^^^^
This comments out your changes to the textView.

// works only alone, whitout the link attribute below
//

theData = [text dataUsingEncoding:NSUTF8StringEncoding];
attrText = [[[NSAttributedString alloc] initWithHTML:theData documentAttributes:nil] autorelease];

[textStorage setAttributedString:attrText];

// I use this to display and convert html, in order to be readable...

*/

aaah, here we continue :-)


// Insert link into the NSTextField
[textView insertText:text]; // -->


// we write the link, in order to open the clicked url
//

theLinkColor = [NSColor colorWithDeviceCyan:.57 magenta:.30 yellow:.10 black:.6 alpha:1];

linkAttributes= [NSDictionary dictionaryWithObjectsAndKeys:url, NSLinkAttributeName,
[NSNumber numberWithInt:NSSingleUnderlineStyle], theLinkColor,
theLinkColor, NSForegroundColorAttributeName,NULL];

[textStorage addAttributes:linkAttributes range:NSMakeRange(begin,[text length])];

You probably want:
[textSto... range:NSMakeRange(begin,[[textStorage string] length])];

Well, didn't look up wether a NSTextStorage actually responds to "length", but I guess you got the idea.


[textStorage endEditing];


This code crashes,

But where?

have you an idea ?

Maybe this line I corrected ...


Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/


  • Prev by Date: Re: Help with pasteboard
  • Next by Date: Re: Finding which control is selected
  • Previous by thread: Re: Finding which control is selected
  • Next by thread: run application with console or shell
  • Index(es):
    • Date
    • Thread