毎晩のWebkitビルドのNetscapeCocoaPluginの例に従い、Cocoaイベントモデルを使用するNPAPIスタイルのプラグインをビルドできます。
ここでの私の質問は、NPP_SetWindow内でNSViewを取得する方法です。
このスレッドのポスターには、[NSView focusView]を使用して可能であると書かれていますが、これを機能させることができませんでした
私の現在の関数は次のようになります。
NPError NPP_SetWindow(NPP instance, NPWindow* window)
{
PluginObject *obj = instance->pdata;
obj->window = *window;
NSLog(@"Set Window called");
NSView* currentView = [NSView focusView];
[[NSColor redColor] set]; // Sets current drawing color.
NSRectFill(NSMakeRect(10, 10, 2, 20)); // Defines a rectangle and then fills it with the current drawing color.
[[NSColor colorWithCalibratedRed:0.7 green:0.9 blue:0.3 alpha:1.0] set]; // Sets a new color.
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(5, 0, 10, 10)] fill]; // Draws a circle in the new color.
[currentView setNeedsDisplay:YES];
return NPERR_NO_ERROR;
}