views:

146

answers:

1

I'm trying to re-write an old image-viewing plugin for the mac. The old version uses QuickDraw (I said it was old) and resources (really really old) and so it doesn't work in Firefox 3.6 (which is why I'm re-writing it)

I know some Objective C, and so I figure I'm going co re-write this in that using new-fangled Mac routines and nibs, etc. However, I don't know how to start. I've got the BasicPlugin example that comes with mozilla source, so I know how to create a plugin with entrypoints, etc. However, I don't know how to create the nib, and how to interface Obj-C with the entrypoints, etc.

Does anyone know of a more advanced sample for mac than BasicPlugin.bundle? (Preferably simple enough that I can just look at it and understand it...)

thanks.

+2  A: 

Sadly i don't really know of any good "intermediate" example. However, integrating Obj-C isn't that difficult. Thus, following is a short overview of what needs to be done.

You can use Obj-C and C/C++-sources in the same project, its just recommendable to keep them seperated to some extent. This can for example be done by letting the source file with the entry-points and other NPAPI-interfacing stay plain C or C++ files and e.g. forward calls into the plugin from there.
Opaque pointers help to keep a clean seperation, see e.g. here.

The main changes to your plugin include switching to different drawing and event models. These have to be negotiated in NPP_New(), here is an example for the drawing model. When using Cocoa and to support 64bit enviroments, you need to use the Cocoa event model.

To draw UI elements you should be able to use a NSGraphicsContext from the CGContextRef and then draw an NSView in the context. See also the details provided in this post and its follow-ups.

Georg Fritzsche
Actually my main problem (at the moment) is integrating nibs into the project. In particular, how to get an NSView into my plugin space... I've got the NPAPI stuff, and a simple extern "C" should take care of anything with that, if it's even needed...
Brian Postow
You don't get child-windows on MacOSX, so there is nothing you could attach your NSView to. Why can't you draw directly into the context you get?
Georg Fritzsche
but then how do I get buttons, scrollbars, etc? I think that the context I get is a Quartz/Carbon context, but I don't think that's supported, hence, I'm a little confused... or alternatively, I don't know how to draw into the context...
Brian Postow
The NPAPI does only guarantee here that you can draw in a certain context in the window - getting complete views is browser-specific and bound to fail even for different versions. As for how to use that to draw UI-elements - good question, i haven't needed to do that yet. If i stumble upon something i'll update.
Georg Fritzsche
In particular, I look at the Mozilla documentation, which makes it look like I'm being given a CGrafPtr, which is a QUICKDRAW thing, and that documentation is 2.5 years old!
Brian Postow
MDC is in parts horribly outdated - take a look here - https://wiki.mozilla.org/Mac%3aNPAPI_Drawing_Models#The_CoreGraphics_drawing_model. Also get yourself up-to-date headers and just look in there.
Georg Fritzsche
Interesting. I've actually heard from Josh Aas, the guy who wrote the Mac Plugin parts of Mozilla, that the "correct" way is to use Quartz and Core Graphics, so I have to figure out how to get a "buttons" on a CGContext... I can get my image into a CGImage, and draw that, but the next part.... we'll see.
Brian Postow
If you only want to draw your images do that, if you need to draw UI elements as you said take a look at the pointers above for drawing NSViews etc. in the context you get.
Georg Fritzsche
Thanks... The headers don't help because the thing I'm working with is a void*... but those links seem to help.
Brian Postow
Ok, those links tell me how to get an NSGraphicsContext, and that's great, because I can draw NSImages into it. But I can't see how to draw an NSView (or NSScrollView in particular) into an NSGraphicsContext... The post seems to leave off that step...
Brian Postow
I linked to the `NSView` method `- (void)displayRectIgnoringOpacity:inContext:` above which should do it. That was mentioned somewhere in the posts too.
Georg Fritzsche
I looked at that, and aside from the comment saying "I'm not sure if this actually does anything..." It's unclear what that does if the view isn't actually already IN any context... But it's something I should play with on Monday.
Brian Postow
FireBreath now has an example of most of what you need, in the trunk and the latest nightly snapshot. It's scheduled for the 1.2 release. http://firebreath.googlecode.com
Taxilian