Search code examples
cocoamacosreverse-engineeringmacos-carbon

NSWindowGraphicContext?


I was wondering what is NSWindowGraphicContext and how can I access it? It seems hidden. Anyway when I following code className turns out to be NSWindowGraphicContext.

NSGraphicsContext *graphiccontext = [NSGraphicsContext currentContext];
const char* className             = class_getName([graphiccontext class]);

Same thing with CGContextRef.

Documentation says

"A window graphics context is a graphics context that you can use to draw into a window. Note that because Quartz 2D is a graphics engine and not a window management system, you use one of the application frameworks to obtain a graphics context for a window."

But it does not give the name of the header or details for creating that like it does for bitmap context and PDF graphics context? I would like to know more about them.

I assume Apple don't want to expose those details to user. But I need to know more.


Solution

  • That is a private subclass used by Apple which you aren't supposed to know about. As such, there is no public documentation or headers. It will be created automatically for your windows. You can get it either by accessing the current context (as you do in your question), or like this:

    [NSGraphicsContext graphicsContextWithWindow:theWindow];
    

    If you want to know more about the class, you can run class-dump on AppKit to get a header. Using the information from the header, you might be able to create new contexts, but they will likely be hard to set up properly, and it is better to ask the system for one.