Alternative Cocoa framework, anyone?

I’ve put together a slightly monstrous means of using Cocoa within Xojo, sort of on the idea of MacOSLib, but with a significantly different approach. I designed it for myself, and not necessarily for public use, so it’s more geared toward someone familiar with Objective C/Cocoa rather than trying to maintain strict Xojo-ness. It’s the sort of thing that will never be truly complete, and I’m sure it has loads of naive omissions and possible bugs. It works well for my own in-house use. However, it occurred to me that this sort of thing might benefit greatly from being properly open-sourced, and therefore plenty of people might benefit from it.

If anyone with a qualified opinion would like to have a look, and maybe help get it out there as an open source project, I’d be willing to discuss it. If not, also fine. I’m perfectly content either way.

Here’s an illustration of what I’m talking about.

What are the dependencies? Could I copy just CALayer to my project and it’ll work?

It’s a little more complex than that, but not much. I’m using a single class I call NSPtr to represent a Cocoa object, so that would be helpful to keep, although I suppose if you wanted to you could use the native Ptr object and manage it yourself. In essence, you should be able to delete a ton of the modules you’re not interested in and still be able to use CALayer effectively. All these really are are collections of functions and subs with all the declares already done, which can be called with handy dot syntax.

I deliberately sought to avoid the all-or-nothing trap MacOSLib put me in.

Here’s a look inside the module. Note that it’s just declares. I’ve even included Apple’s documentation on the call;

Oh - and for the record I did not manually type all these functions. I’m not that insane. I wrote myself an app to download pages from Apple’s developer documentation and chew them up into Xojo XML which I can then import as a module of functions with the relevant declares. They require some editing, but it’s not difficult. As a result of this semi-automated process, however, there are probably some lurking issues I haven’t seen.

Overall, though, it works quite well for me. I’ve been able to do an awful lot with it.

Looks Good and I’m ready to play!

OK. I slapped a BSD license on it, and I’ll post a link shortly. Be gentle. Like I said, I’m sure there are some internal problems I haven’t seen. There may even be some boneheaded design choices.

Also, I apologize in advance for the tone of my notes and comments. I was really only writing to myself.

Here ya go;

If anyone wants to do the legwork to get this onto something like git, it could become a real project, I think.

A few offhand comments that are important:

  • Structures should all have the “StructureSize” attribute set to 0 so that they get laid out in memory correctly.
  • Where applicable, structures should use the CGFloat data type instead of Single in order to work on 64-bit.
  • Delete the XOJView and XOJWindow modules. No good can come of them.
  • Don’t hardcode things like __NSCFNumber. Use isKindOfClass: in order to avoid embedding knowledge of private Apple classes and to work correctly with class clusters.

Those XOJ things were just in there as experiments. I should have deleted them.

As for CGFloat, I’m still on 2016 3.1, and it doesn’t seem to know about it. I really need to update.

Re: “__NSCFNumber” - Yeah. I thought that was a bit hacky. Thanks for the advice.

There. The download is altered to remove the XOJ modules.

Fantastic. I really don’t have time to dive in right now (but I did :slight_smile: ). To get it running I commenting out the 2 errors in w_About.Open and removed CojoMetalWindow and CojoWidgetWindow. I like the altered application menu. And the dock badge can be an emoji (’<

Congratulations Daniel.

As I noted above, I really need to get up to the latest IDE. I’m sure that’s where the errors are coming from.

Will: The CojoMetalWindow isn’t something I’ve really used much lately. It’s a shame about the widget window, though. I’ve used that to great effect. Here’s an example of what I’ve done with it;

This just floats on my desktop below all my regular app windows and remotely monitors the temperature in my house. I can drag it around and everything. Very useful. I’ll get on that.

jean-paul: Damn! I totally forgot about that! Those are things I moved into a plugin I wrote. I completely forgot. Sorry!!

As time permits, I’ll try to backpedal from the plugin stuff.

OK, Jean-Paul, et. al. I removed my own plugins, and saw the errors. It took me about 20 minutes to re-write the plugin code for the relevant functions using my Cojo syntax. If you re-download the file from the original link above, you’ll see the new functions in the Window extension module. I put underscores at the ends of the names to avoid conflicts with my own plugins. I only did this to get it to compile and run. I have not tested them, but they should work.