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:
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?