title: NPAPI drawPlugin retrieve cgContext from NPP instance
body: <p>Im trying to draw a png in my (NPAPI)webplugin for Mac based on <a href="http://code.google.com/p/npapi-sdk/" rel="nofollow">basic-plugin</a>.</p>
  
  <p>I would like to redraw the plugin on a <code>NPCocoaEventMouseDown</code> but I'm having trouwens to retrieve the <code>cgContextRef</code>. </p>
  
  <p>The methode below works for the <code>NPCocoaEventDrawRect</code> but doesn't for the <code>NPCocoaEventMouseDown</code> because then I can't use <code>event-&gt;data.draw.context</code>. I tried to retrieve the <code>cgContextRef</code> with </p>
  
  <pre><code>
  
      CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window
  
  
  </code></pre>
  
  <p>but that didn't seem to work. Here's my function:</p>
  
  <pre><code>
  
      void drawPlugin(NPP instance, NPCocoaEvent* event)
      {
          char* path = "/shot.png";
          if(!instance || !event)
              return;
          PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
          //CGContextRef cgContext = event->data.draw.context; //works with DrawRect
          CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window;
          if (!cgContext) {
              return;
          }
          float windowWidth = currentInstance->window.width;
          float windowHeight = currentInstance->window.height;
  
          CGContextSaveGState(cgContext);
          //.....
          CGContextRestoreGState(cgContext);
      }
  
  </code></pre>
  
  <p>And the function is called here:</p>
  
  <pre><code>
  
      int16_t NPP_HandleEvent(NPP instance, void* event)
      {
        NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
        if (cocoaEvent && (cocoaEvent->type == NPCocoaEventDrawRect)) {
            return 1;
          }
  
        if(cocoaEvent)
        {
          switch (cocoaEvent->type) {
              case NPCocoaEventDrawRect:
                  drawPlugin(instance, (NPCocoaEvent*)event);
                  break;
              case NPCocoaEventMouseDown:
                  drawPlugin(instance, (NPCocoaEvent*)event);
                  break;
              default:
                  break;
          }  
            return 1;
        }
          return 0;
      }
  
  </code></pre>
  
  <p>How can I retrieve the <code>cgContextRef</code> in a <code>NPCocoaEventMouseDown</code>?</p>