Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Flipped view confusion



Hello list,

I was working on a project involving getting a NSTextFieldCell to use only part of its bounding rect when I noticed some odd behavior. Everything worked perfectly when the text wasn't being selected or edited (i.e. drawWithFrame was called), but every time I caused a call to either selectWithFrame or editWithFrame graphical artifacts appeared.

I eventually tracked the problem down to NSGraphicsContext's - isFlipped method. When -isFlipped was called on the current graphical context, it returned YES in drawWithFrame and NO in both editWithFrame and selectWithFrame. Oddly, calling -isFlipped on the controlView for my cell returned the correct (YES) value in all three. What is causing the current context to lie and say the opposite of the control view? I'm using a 1x1 NSMatrix to contain my cell as it seemed to be a good testbed.

As a simple "Try it at home" example, all it takes is a 1x1 NSMatrix with a custom NSTextFieldCell. If the -drawWithFrame, -editWithFrame, and -selectWithFrame methods are overridden as:


- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSLog(@"drawWithFrame: control: %d graphicsContext: %d", [controlView isFlipped], [[NSGraphicsContext currentContext] isFlipped]);


        [super drawWithFrame:cellFrame inView:controlView];
}

-(void)editWithFrame:(NSRect)cellFrame inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
NSLog(@"editWithFrame: control: %d graphicsContext: %d", [controlView isFlipped], [[NSGraphicsContext currentContext] isFlipped]);


[super editWithFrame:cellFrame inView:controlView editor:textObj delegate:anObject event:theEvent];
}
-(void)selectWithFrame:(NSRect)cellFrame inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength
{
NSLog(@"selectWithFrame: control: %d graphicsContext: %d", [controlView isFlipped], [[NSGraphicsContext currentContext] isFlipped]);


[super selectWithFrame:cellFrame inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}



you will see output similar to:

TestFlipped[284] selectWithFrame: control: 1 graphicsContext: 0
TestFlipped[284] drawWithFrame: control: 1 graphicsContext: 1
TestFlipped[284] editWithFrame: control: 1 graphicsContext: 0

Any help with understanding what's happing would be greatly appreciated. Also, as a general rule, which isFlipped method would be better to use, as they seem to be non-equivalent?

Thanks,

Seth
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.