NSTextField Bad Behavior
NSTextField Bad Behavior
- Subject: NSTextField Bad Behavior
- From: Robert Clair <email@hidden>
- Date: Fri, 12 Dec 2003 13:13:40 -0500
I'm adding my own dialog of font controls. (Spare me the lectures.
Because I don't like the way the system one looks. Because it thinks
the world is black text on a white background. Because it has the
misguided notion that my screen has only 72 pixels per inch. Because I
WANT to. OK ? :-) )
My current problem is that an NSTextField is misbehaving on me.
I have my panel working with an example area, buttons for Bold and
Italic and a button to
summon the system font panel (at least until I finish this.) I am now
doing the font size.
I added a typical slider/text field/stepper combination all wired to
the same action with
the usual code to keep them in sync:
[fontSizeTextField setIntValue: [sender intValue]];
[fontSizeSlider setIntValue: [sender intValue]];
[fontSizeStepper setIntValue: [sender intValue]];
The problem is the NSTextField (which has a formatter set with a
maximum value of 1000)
won't let me enter "100". I get this garbage:
2003-12-12 12:39:08.985 Zeus[5483] *** Assertion failure in
-[NSMutableRLEArray objectAtIndex:effectiveRange:],
String.subproj/NSAttributedString.m:1002
2003-12-12 12:39:08.986 Zeus[5483] Exception raised during background
layout: Access invalid attribute location 2 (length 2)
2003-12-12 12:39:08.987 Zeus[5483] Access invalid attribute location 2
(length 2)
I disconnected the stepper and the slider and commented out everything
in the action routine except a single printf to log [sender intValue].
Still happens.
There is a routine that gets called at the appropriate times to
validate the panel. (All the dialogs in the app are set up to notice
that the active view has changed and revalidate if the focus has
changed or go dormant if there is no view.) By putting an early return
statement in the routine and moving it down I found the statement
causing the trouble:
- (void) validate
{
NSFontManager* fontManager = [NSFontManager sharedFontManager];
NSFont* currentFont = [fontManager convertFont:[fontManager
selectedFont]];
BOOL isBold = [[NSFontManager sharedFontManager] traitsOfFont:
currentFont]
& NSBoldFontMask;
BOOL isItalic = [[NSFontManager sharedFontManager] traitsOfFont:
currentFont]
& NSItalicFontMask;
BOOL hasView = toolContext ? YES : NO;
[showFontPanelButton setEnabled: hasView];
[boldFontButton setEnabled: hasView];
[italicFontButton setEnabled: hasView];
[fontSizeSlider setEnabled: hasView];
[fontSizeTextField setEnabled: hasView];
[fontSizeStepper setEnabled: hasView];
if ( hasView )
{
[showFontPanelButton setState:
[[NSFontPanel sharedFontPanel] isVisible] ? NSOnState :
NSOffState];
[boldFontButton setState: isBold ? NSOnState : NSOffState];
[italicFontButton setState: isItalic ? NSOnState : NSOffState];
[fontSizeSlider setIntValue: [currentFont pointSize]];
[fontSizeStepper setIntValue: [currentFont pointSize]];
// This cause the problem to occur
[fontSizeTextField setIntValue: [currentFont pointSize]];
}
}
If the marked statement is skipped, no problems. If it is executed -
garbage the next time I try and enter a 3 digit number in the text
field.
This behavior persists even if I change the statement to
[fontSizeTextField setIntValue: 36]; to make sure it is not
somehow getting set to trash.
Any suggestions or work around ideas ?
Thanks,
Bob
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.