> An NSTextField is an NSControl, so it has a setAttributedString: method.
> I'm not sure what you mean about the field editor's text storage;
> perhaps you should show your code. m.
> > An NSTextField is an NSControl, so it has a setAttributedString: method.
> > I'm not sure what you mean about the field editor's text storage;
[quoted text clipped - 5 lines]
> thing funny is that when I click the link, the textfield's font changes
> to a smaller font... Don't know why that's happening...
You still are not showing any code so it's impossible to guess. m.

Signature
matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com
Ulrich Hobelmann - 28 Nov 2006 20:06 GMT
> > The textfield even interprets my LinkAttribute correctly. The only
> > thing funny is that when I click the link, the textfield's font changes
> > to a smaller font... Don't know why that's happening...
>
> You still are not showing any code so it's impossible to guess. m.
Well, the code is boring, and doesn't really do much... That's why I'm
wondering at the behavior.
[textfield setAllowsEditingTextAttributes:YES];
NSString *url = @"http://someurl/";
NSString *s = [NSString stringWithFormat:@"Look at: %@", url];
NSMutableAttributedString *str =
[[[NSMutableAttributedString alloc] initWithString:s] autorelease];
NSRange urlRange = [s rangeOfString:@"http://"];
urlRange.length = [s length] - urlRange.location;
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString:url], NSLinkAttributeName,
[NSNumber
numberWithInt:NSSingleUnderlineStyle],NSUnderlineStyleAttributeName,
[NSColor blueColor], NSForegroundColorAttributeName, NULL];
[str beginEditing];
[str addAttributes:attrs range:urlRange];
[str endEditing];
[textfield setAttributedStringValue:str];
matt neuburg - 28 Nov 2006 22:33 GMT
> > > The textfield even interprets my LinkAttribute correctly. The only
> > > thing funny is that when I click the link, the textfield's font changes
[quoted text clipped - 21 lines]
> [str endEditing];
> [textfield setAttributedStringValue:str];
Ah, I see. The problem is that this is an editable text field but at the
time you are issuing this command it is not actually being edited. (Try
it. You will see that if you are actually editing the field at the time
you issue this command, it starts out with the smaller font.) It is not
changing because you are clicking the link; it is changing because you
are starting to edit the field. (Try it: click in "Look at", not at the
link, and you will see the font become smaller.)
The reason is that you are not supplying any font and size information,
so the font and size for the text field and the field editor are in
conflict. Try this:
NSMutableAttributedString *str =
[[[NSMutableAttributedString alloc] initWithString:s
attributes:
[NSDictionary dictionaryWithObject:
[NSFont fontWithName:@"Lucida Grande" size:13]
forKey: NSFontAttributeName]] autorelease];
Problem solved. m.

Signature
matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com
Ulrich Hobelmann - 29 Nov 2006 09:19 GMT
> The reason is that you are not supplying any font and size information,
> so the font and size for the text field and the field editor are in
> conflict. Try this:
Oh, I didn't know the field editor installs its own font attributes...
Thanks a lot, Matt!
(I have another related question though: because I also want my
textfield to be selectable, when the user clicks in it, the cursor is
displayed (non-blinking). I think this shouldn't happen, but I don't
know how to turn it off.)
Ulrich Hobelmann - 28 Nov 2006 20:06 GMT
> > The textfield even interprets my LinkAttribute correctly. The only
> > thing funny is that when I click the link, the textfield's font changes
> > to a smaller font... Don't know why that's happening...
>
> You still are not showing any code so it's impossible to guess. m.
Well, the code is boring, and doesn't really do much... That's why I'm
wondering at the behavior.
[textfield setAllowsEditingTextAttributes:YES];
NSString *url = @"http://someurl/";
NSString *s = [NSString stringWithFormat:@"Look at: %@", url];
NSMutableAttributedString *str =
[[[NSMutableAttributedString alloc] initWithString:s] autorelease];
NSRange urlRange = [s rangeOfString:@"http://"];
urlRange.length = [s length] - urlRange.location;
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString:url], NSLinkAttributeName,
[NSNumber
numberWithInt:NSSingleUnderlineStyle],NSUnderlineStyleAttributeName,
[NSColor blueColor], NSForegroundColorAttributeName, NULL];
[str beginEditing];
[str addAttributes:attrs range:urlRange];
[str endEditing];
[textfield setAttributedStringValue:str];