RemObjects Software Gears
 
       

Adventures in Mac World - Part 1

{#} by marc hoffman 08/11/07 02:56:35 pm, 1011 words, Categories: RemObjects, Oxygene, .NET, Visual Studio, Mono, Cocoa, Mac

I needed to get myself a new laptop, and after much deliberation decided to treat myself to a Mac, for a variety of reasons, not the least of it being that i was curious about the Mac platform and wanted an option to test our products on Mac OS X - including Chrome and our Mono libraries, but also the new FPC support we have been shipping in ‘Vinci’, as well. At the very worst, i figured, the MacBook Pro would make a great Vista machine if i found i really couldn’t stand Mac OS.

As it turns out, i’m very happy with Mac OS X so far, and liking it quite a bit. And the new VMware Fusion (conveniently released the day before my MBP arrived) makes it easy to fall back to Windows apps - such as Visual Studio or our internal BugClient - where needed

One of the first things i tried, naturally, was to install Mono and Chrome and test the command line compiler and apps. But running the FileFind sample got boring after a few minutes, and i wanted to try some more exciting things, such as creating a proper Mac OS GUI app. The first obvious choice was, of course, WinForms, which i am familiar with and is by now well supported by Mono, as well. After figuring out i had to manually install X11 off the Mac OS CDs, WinForms apps ran well, however, they did not really feel “native Mac” - no icon in the dock, no proper top menu, etc.

It turns out, to get proper Mac OS X feel from a Mono app, the only real choice is to use Cocoa#, the managed wrapper for Apple’s standard UI framework. Documentation on Cocoa# is next to non-existent (and the bit i did find was hopelessly out of date and wrong), after with a bit of experimenting, it all worked surprisingly well.

Setup

To get started, let’s look at the tools and software that’s required. I’m running Mac OS X 10.4 (Tiger) and also installed Xcode Tools (which might or might not be pre-installed on your Mac; if not, you can install it using the “Optional Components” setup found on the Mac OS X install CDs). Lastly, on the Mac side, you will need Mono 1.2.4 for Mac OS (available here).

To make development easier, i also installed Chrome with Visual Studio inside VMware Fusion, and installed Mono 1.2.4 for Windows (also available here), so i can directly link against Mono from inside Visual Studio.

Mono for Windows does not deploy the Cocoa# dll (which soft of makes sense, since it won’t work under Windows), but i manually copied it over so i can use it from Visual Studio. You can find cocoa-sharp.dll in

/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/cocoa-sharp

on your Mac and simply copy it over to

C:\Program Files]Mono-1.2.4\lib\mono\cocoa-sharp

Note that the the cocoa-sharp.dll found i the above folder most likely is a symbolic link, which VMware Fusion apparently cannot directly copy to the VM directly via drag and drop; you might need to follow the link back to the real file.

Getting Started

If you’re running Chrome ‘Joyride’ 2.0.3 or later, you will find a new ready-made template for Cocoa# in the New Projects dialog (in the MonoChrome subfolder). Use this template to create a new project.

Working with Cocoa# will require a lot of switching back between Mac OS and the Windows VM, so rather then copying the project back and forth frequently, i suggest creating it in the shared folder that VMware Fusion created for you, sharing your Mac home directory. In my case, this was mapped to drive Z:\ under Windows, and mapped to my ~mh folder, Mac Side.

First thing after creating the project, you will notice a few unfamiliar files - a .ICNS file containing the application icon, and a .NIB folder containing the Cocoa interface definition that describes the UI of your application. Visual Studio will not be able to edit the files in this folder (except in text or binary mode, which is quite useless), but fortunately Interface Builder, provided as part of the Xcode Tools, can.

So, switch back to Mac OS, locate your project folder in Finder and double-click the Interface.nib (you will notice that Finder treats the entire folder as a single file, a so called “package”, even though in Visual Studio it appears as a folder) to open Interface Builder:

As you see, Interface Builder opens with four windows:

  • A design surface for your application’s main form
  • A designer for the application menu
  • The Toolbox
  • The project window containing all elements defined for your UI.

Going into the details of designing Cocoa GUIs would go beyond the scope of this text, so lets simply drop a text control on the form and double-click it to change its caption to “Hello World!”, and also double-click the “NewApplication” in the main menu to change it, too, to “Hello World”, the name of our project.

Being happy with the UI, do File|Save (⌘S) and switch back to Visual Studio. There’s not really anything we need to do in code for our simple Hello World, so just do a Build|Build Solution to compile the project.

We’re almost ready to run now; as a last step, we need to package our project as a Mac .APP application, so we can run it. To do this, open a Terminal window, and navigate to your project’s bin/Debug folder (ie ~mh/Hello World/bin/Debug in my case), and run the following command:

macpack -m:2 -n:HelloWorld -a:HelloWorld.exe -r:Interface.nib -i:App.icns

As a result, a HelloWorld.app (this again is a package folder that Finder will treat as a single file) will be generated, which will behave like any other Mac app - you can deploy it to the Applications folder, drag it to the Dock and, of course, double-click it in Finder to launch it:

Comments, Pingbacks:

Comment from: Dominique. [Visitor] · http://www.pascalgamedevelopment.com
Wow Very very cool indeed!
PermalinkPermalink 08/11/07 @ 23:46
Comment from: C Johnson [Visitor]
So, for the record, you are saying that MS has started something that the community has run with to make cross platform development more of a reality than it was before MS started?

Yer saying the doom sayers are wrong, and dotNet is actually about openning up possibilities rather than locking people into MS based operating systems?

Shocking, positively shocked. Surely tens of thousands (or, indeed more!) of paranoid individuals couldn't possibly be wrong could they?

I look forward to seeing more cross platform goodness (now if only we could convince you guys to write a native code compiler or two, give codegear the direct competition it so desprately needs to reinvigorate the pascal industry...)
PermalinkPermalink 08/12/07 @ 01:51
Comment from: timo [Visitor] · http://www.travity-internetagentur.de
Sehr cool!
PermalinkPermalink 08/12/07 @ 09:56
Comment from: Martin Schmid [Visitor] · http://www.equitania.de
I tried like you post it, but I can't found the cocoa application (MacOS X) in my visual studio.

May it depend on my Chrome Joyride version. I downloaded the latest 2.0.1.401 from the remobjects homepage. I own a license.

I copied the cocoa-sharp dll from macosx to my vmware.

Where can I get the version 2.0.3 of chrome?
PermalinkPermalink 08/12/07 @ 11:22
Comment from: marc hoffman [Member] Email
Martin: the Cocoa template is new for the next release, due at the end of the month ;)
PermalinkPermalink 08/12/07 @ 11:27
Comment from: Robert [Visitor]
you dirty little teaser, you. *g*
Nice post and nice to now that OSX/Cocoa is right on your radar.

There's one thing that bugged me about your post though: Your XP theme in Fusion!
Try this one, I use it @work: http://www.deviantart.com/view/17625638/
PermalinkPermalink 08/12/07 @ 12:34
Comment from: marc hoffman [Member] Email
Robert: LOL. i guess there is a certain level of irony in using whats actually the "Zune"* theme, on an Apple . But i've always been a Royale fan ever since it was released, and this pretty much is Royale in black.

the Tiger theme certainly looks nice - but i think using that might be even more confusing (to me, but more so to the reader), if you cannot tell Windows and MacOS apps apart :)

As for teasing: yeah, well... . we've got some more cool stuff coming up on this front (*probably* for 2.0.3, but no promises, yet) that will make Cocoa# development even more streamlined. Suffice to say i'm very interested in the platform, personally, and you can rest assured we'll do more and more to make Mac development in MonoChrome easier, over time.




[*i don't use a Zune myself, just to avoid any misconceptions (does anyone?). iPod nano, black, for me.]
PermalinkPermalink 08/12/07 @ 17:57
Comment from: Robert [Visitor]
> But i've always been a Royale fan ever
> since it was released,
>

Same here, it was only this Tiger theme that made me cheat on Royale blue. *g*

> and this pretty much is Royale in
> black.


Kinda, but then again it has this sick orange in it.
It has the same foul taste like the device it's trying to advertise.

but understood, the reader might not know that he can tell windows apps by their clumsy menus. *g*
PermalinkPermalink 08/12/07 @ 20:45
Comment from: marc hoffman [Member] Email
> Kinda, but then again it has this sick orange in it.

ah, but the beauty of VMware Fusion is that you don't see the Start button ;)
PermalinkPermalink 08/12/07 @ 23:58
Comment from: Weyert de Boer [Visitor]
Really cool Marc! I will give it a try later one. Currently, busy preparing for my trip back to Europe.
PermalinkPermalink 08/13/07 @ 06:13
Comment from: Barry Carr [Visitor] · http://www.barrycarr.org.uk
DZoned!

Very cool indeed. Marc
PermalinkPermalink 08/13/07 @ 11:36
Comment from: Jody Dawkins [Visitor]
Thanks! So when do we get to read part two?
PermalinkPermalink 08/17/07 @ 21:23
Comment from: marc hoffman [Member] Email
Jody: soon, we've got some more cool stuff for Cocoa# coming in 2.0.3 (due in about a week)...
PermalinkPermalink 08/18/07 @ 00:56
Comment from: Ron Grove [Visitor]
Looking forward to working on these new possibilities. It looks like we'll be getting a Mac to replace the old computer at home my wife uses. One of the reasons for doing that is to figure out if I can make a few bucks somehow making some OS X software. I've always heard there was no software, but don't know how true that is. But that seems to frequently be translated as "my favorite PC game doesn't run on it so it must not have any software".
PermalinkPermalink 08/23/07 @ 23:27
Comment from: marc hoffman [Member] Email
Ron: you won't regret it, trust me. i'm absolutely loving it - i'm wish i could install MacOS X on my desktop as well (or justify replacing my box with a MacPro <g>).

As for development, we got lots of cool Cocoa# and MonoChrome stuff coming (some in 2.0.3 tonight, which i'll blog about later this weekend; some later). i'm personally very interested in making Cocoa# development with Chrome a joy ;).

What the software market is concerned, i must say i'm pleasantly surprised, there's lots of good Mac stuff out there ad (not so good if you're n the selling side) usually pretty well priced, too. But there's ALWAYS room for new good software, on any platform ;)
PermalinkPermalink 08/24/07 @ 12:11
Comment from: Ron Grove [Visitor]
Well, we went to the Apple Store at the mall last night and after the sales person got done showing us around and left I looked at my wife and her eyes were wide as saucers. All I heard was "Vista sucks right?" She wanted that 24" iMac, so now I'm sitting here at work running updates on the thing and figuring out how stuff works. What they've done with the remote control is really quite stunning. And all the integration to the web excites her because she can publish movies and pictures of our two year old son (and hopefully in February a new addition to the family) FAR more easily than she can now. The iLife suite seems to be custom made for her and her computing needs. I'm not Vista's greatest fan, and I'm not a fan of the direction MS has gone with Office. All it means for me is tons of grief on support calls from people who don't want to learn new things on the computer. They just want to do their job and the old interfaces were comfortable to them. I understand the need for change by MS, but they went pretty far. So far as my wife is concerned having to learn too much more opened the possibility of looking at other options, like the new iMac, and she was quickly sold on it. I have to say we're quite impressed here in the office as well. I'm looking forward to seeing what you put together for developing on these things. iPod and iPhone have seriously increased foot traffic into Apple stores and I suspect more than just my wife will be sold on these things. I'd love to be ahead of the curve in application development if Apple is able to increase desktop market share.
PermalinkPermalink 08/24/07 @ 17:32
Comment from: marc hoffman [Member] Email
Ron: excellent, picture me envious ;).
PermalinkPermalink 08/24/07 @ 17:49
Comment from: Roberto [Visitor] Email
Marc,

we use to use Mac Pros for cross development, previously we're buying Dell, but if you compare prices Mac Pros are the best buy.

We have Quad Cores with 8 MB of RAM running several virtual machines with out any problems.

And we got MacBooks Pro to work mobile.

I can use the best of both worlds OS X and Windows.
PermalinkPermalink 12/23/07 @ 12:59
Comment from: marc hoffman [Member] Email
Roberto: yeah, i'll most likely consider getting a Mac Pro myself, early next year. I'm not really a laptop worker, yet i find myself drawn to use my MBP for stuff id normally be doing on the desktop, all the time ;)
PermalinkPermalink 12/23/07 @ 16:51

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

 

marc hoffman

Chief Software Architect &
Spare-time Photographer

mh

Links

Twitter

marc hoffman (follow)
    loading...
Mike Orriss (follow)
    loading...

Navigation

XML Feeds 

Who's Online?

  • Guest Users: 7