Re: Dragging in an NSTextView
Re: Dragging in an NSTextView
- Subject: Re: Dragging in an NSTextView
- From: Glen Simmons <email@hidden>
- Date: Tue, 18 Jan 2005 21:15:31 -0600
On 18 Jan, 2005, at 6:17 PM, Glen Simmons wrote:
I'm having a problem with dragging in an NSTextView subclass. I'm
getting an exception when I start the drag:
2005-01-18 17:45:32.697 MyApp[1047] *** -[NSCFDictionary
setObject:forKey:]: attempt to insert nil value
The backtrace from the exception is:
#0 0x97e54864 in -[NSException raise] ()
#1 0x97e547ec in +[NSException raise:format:] ()
#2 0x97df4c5c in -[NSCFDictionary setObject:forKey:] ()
#3 0x97e15cf4 in -[NSMutableDictionary addEntriesFromDictionary:]
()
#4 0x97e46458 in -[NSMutableAttributedString
addAttributes:range:] ()
#5 0x93177074 in -[NSTextView attributedSubstringFromRange:] ()
#6 0x93136dac in -[NSTextView(NSPasteboard)
writablePasteboardTypes] ()
#7 0x00029418 in -[MyTextView writablePasteboardTypes] ()
#8 0x9332bed4 in -[NSTextView(NSDragging)
dragSelectionWithEvent:offset:slideBack:] ()
#9 0x00029f0c in -[MyTextView mouseDown:] ()
#10 0x930c1698 in -[NSWindow sendEvent:] ()
#11 0x930a94ec in -[NSApplication sendEvent:] ()
#12 0x930b2418 in -[NSApplication run] ()
#13 0x931605cc in NSApplicationMain ()
#14 0x00009b0c in main (argc=1, argv=0xbffffd34) at
/Users/glen/Development/84 Emulator/Mac/main.m:18
#15 0x000095c4 in _start (argc=1, argv=0xbffffd34,
envp=0xbffffd3c) at /SourceCache/Csu/Csu-47/crt.c:267
#16 0x8fe190f4 in __dyld__dyld_start ()
My subclass overrides -mouseDown: and handles the text selection (1).
If the user clicks on selected text and holds, I start a drag by
calling -dragSelectionWithEvent:offset:slideBack: (2). I don't think
I'm doing anything too odd here, but obviously I'm not making somebody
happy.
Thanks,
Glen
(1) I'm handling the text selection b/c my text is actually a bunch of
NSTextAttachments with small images. NSTextView stinks at selecting
image attachments. Drop a few small images in TextEdit and try to
select the middle one.
(2) Here's the full method:
<snip>
FYI:
I was stripping the code down to a test case and found the culprit.
It's not in my -mouseDown: override at all. In fact, I can duplicate
the problem with a plain NSTextView. In another part of my code, I was
setting the minimum line height on the text view to be the height of
the images. This was to work around what appears to be a bug in 10.2
that would cause images to overlap vertically. Apparently
-attributedSubstringFromRange: or something it calls doesn't deal well
with paragraph styles. Here's the problem code:
if (floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_2) {
NSDictionary *theAttrs = [inAttrStr attributesAtIndex:0
effectiveRange:nil];
NSTextAttachment *theTA = [theAttrs objectForKey:@"NSAttachment"];
id <NSTextAttachmentCell> theCell = [theTA attachmentCell];
float minHeight = 40;
NSRange wholeRange;
NSParagraphStyle *paraStyle;
NSMutableParagraphStyle *newParaStyle;
NSTextStorage *theTS = [scriptViewOutlet textStorage];
if (theCell) {
minHeight = [theCell cellSize].height;
}
paraStyle = [theTS attribute:NSParagraphStyleAttributeName
atIndex:0
effectiveRange:nil];
newParaStyle = [paraStyle mutableCopy];
[newParaStyle setMinimumLineHeight:minHeight];
wholeRange = NSMakeRange(0, [theTS length]);
[theTS addAttribute:NSParagraphStyleAttributeName
value:newParaStyle
range:wholeRange];
}
If anyone sees something wrong, please let me know. For now, I'm
assuming it's a bug in the AppKit on 10.2. I'm thinking I'll override
-attributedSubstringFromRange: and remove the custom paragraph style
before calling super and then put it back.
Glen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden