discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSText and the font panel. (II)


From: Fred Kiefer
Subject: Re: NSText and the font panel. (II)
Date: Wed, 01 Mar 2006 14:53:12 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921

Marko Riedel wrote:
>> when I switched to WindowMaker from KDE I was able to set fonts with the
>> font panel and have them display correctly in the NSText object. I would
>> still like to be able to let the user edit text attributes but not
>> characters. I guess I could do this by overriding cut:, paste: and
>> insertText:. Is there an easier way?
>>
> 
> I figured it out: changeFont: does the trick:
> 
>     fontdisp = [[NSText alloc] initWithFrame:[[box contentView] frame]];
>     [fontdisp setString:
>       _(@"The quick brown fox jumps over the lazy dog.")];
>     [fontdisp setAlignment:NSCenterTextAlignment];
>     [fontdisp setFont:[NSFont userFontOfSize:24]];
>     [fontdisp setUsesFontPanel:NO];
>     [fontdisp setSelectable:NO];
>     [box setContentView:fontdisp];
> 
> and
> 
> - changeFont:(id)sender
> {
>     NSFont *cfont =
>         [[NSFontManager sharedFontManager] convertFont:[fontdisp font]];
>     [fontdisp setFont:cfont];
>     return self;
> }
> 

Do I understand this correctly in that you switched off using the font
panel, but changed the changeFont: method to ignore that setting and
this does the trick for you?
With setting selectable to NO, you have the method
rangeForUserTextChange retuning an empty range. So this should help
against insertText: and the like.
Perhaps it would be even better, if you just overwrote
rangeForUserCharacterAttributeChange to ignore the editable setting?
That way you could keep the usesFontPanel setting to its actual value
and have all the other character format changes active as well.

Cheers
Fred




reply via email to

[Prev in Thread] Current Thread [Next in Thread]