.so runtime linkable libraries as plugs ins; cocoa capability?
I'm writing a plug-in interface for an OSX image processing application. It's designed around the idea that the plug-ins should be as simple as possible, such that a developer can get in there and write an effect within minutes of seeing example code. Towards this end, the examples don't require or use XCode; just gcc. It all works very smoothly, and we have (generally speaking) met all the design goals. We actually generate the UI for the plugins so they don't have to, flexibly and variously thread and phase the plugin, manage its storage, presence and position in control panels, etc., all manner of really cool things. And you can write a fully effective plugin in about six lines of C code. So all is good.
Now, though, I'm turning my eye towards what might be required for a developer to open a CoCoa window if they need a more complex interface than we can generate for them. I find I don't know enough about the internal workings of CoCoa, and I've had a bear of a time finding this particular issue addressed anywhere, because XCode generally hides this sort of implementation detail from you. So here (finally, sorry) is my question:
For a plug-in that wants to open a CoCoa window, what do I need to hand them? Is there a root handle for CoCoa services and resources? Or can they just link with whatever it is they need to link with and open a window?
Right now, the plug-in only receives pointers to very specific image data types. They're in no way associated with the OS开发者_如何学运维. If possible, I'd like to hand them the handle(s) they need in order to open a CoCoa window and have that processed by OSX in the normal way, whatever that might be. Or, if they don't need anything, I'd like a definitive answer. A reference for that answer would be wonderful so I can learn about it either way.
Thanks for any insights.
You don't need anything. They will have to link against the Cocoa framework and call methods on NSWindow. The system takes care of the hard work automatically.
Edit:
How to use a modal window:
NSWindow *theWindow; // create this in code, get it from a variable, or load it from a nib
NSInteger result = [[NSApplication sharedApplication] runModalForWindow:theWindow];
if(result == 0) {
// success, process input from window
} else if(result == NSRunStoppedResponse) {
// stopped with -stopModal instead of stopModalWithCode:. Possibly success
} else if(result == NSRunAbortedResponse) {
// stopped with -abortModal, probably an error
}
//This method is the action for a button on the window
- (IBAction)closeModalWindow:(id)sender {
[[sender window] orderOut:nil];
[[NSApplication sharedApplication] stopModalWithCode:0]; // The 0 will become the result of the runModalForWindow: method. You can use anything else instead
}
精彩评论