Getting Started with NOV in MonoMac project

Getting Started with NOV in MonoMac project



NOV can integrate with MonoMac and Xamarin.Mac projects. This topic teaches you how to achieve integration with a MonoMac project.

NOTE - depending on the specific version of Xamarin Studio, the solution templates may be different and some configurations may need to be updated.

System Requirements
The topic has been created with the following system configuration:
  • OS: Mac OS X El Capitan (Version: 10.11);
  • Xamarin Studio Community (Version: 6.0.2);
  • Xcode (Version: 7.3.1);
  • Nevron Open Vision for MonoMac (NOV) 2016.2 (build version: 16.7.6.12);

Downloading and Installing
You can download Xamarin Studio for OS X from the official Xamarin website.
Xamarin Studio will also install the Mono and GTK+ runtimes as well as the Xamarin.Mac framework (for developing Xamarin.Mac applications).

Xcode can be downloaded from the Mac App Store.

From the Nevron Downloads page, download the appropriate NOV package depending on the type of project you want to use:
- NevronOpenVision.MonoMac-[version number].pkg - installs NOV for MonoMac;
- NevronOpenVision.XamarinMac-[version number].pkg - installs NOV for Xamarin.Mac;

After you install the NOV package go to Applications and launch NevronOpenVision.MonoMac. The application has the following UI:
- Start NOV Examples App - it will launch the NOV examples for Mac;
- Open NOV Examples Project - it will launch "Finder" and open the NOV Examples folder. You can double click on the solution file (.sln) contained there (Nevron.Nov.Examples.MonoMac.sln) in order to open the examples in Xamarin Studio;
- Open NOV Binary Files - it will launch "Finder" and open the NOV Bin folder, which contains the redistributable dlls of NOV for MonoMac;
- View NOV Documentation - it will launch your default browser and open the NOV online documentation;

Below those buttons you can also view the generated machine id and the current evaluation key.
- Machine Id - this machine id is used to generate a development license key - see Activation topic for more details.
- License Key(s) - contains the license key currently applied on the examples. At install time the NOV installation will automatically generate a 60 days trial evaluation key which you can also use in your projects for testing.




1. Run Xamarin Studio and create a new Solution - MonoMac (Cocoa App)

  • From File Menu - Choose New Solution
  • Select Other - Miscellaneous - MonoMac - Cocoa App


Click Next, type a name of your project (MonoMacApplication1) and click Create.

This step is not mandatory, because you can integrate NOV in an already existing MonoMac project. It is performed just for the purpose of making a complete installation scenario.

2. Reference the NOV Assemblies
Ensure that your application references the following NOV dlls:
  • Nevron.Nov.Presentation.dll - core NOV portable assembly;
  • Nevron.Nov.Host.MonoMac.dll - presentation host for MonoMac;
  • MonoMac.dll - make sure to reference the MonoMac.dll that comes with the NOV installation and remove the default one, which is created by Xamarin Studio;


You can reference the dlls directly from the System/Applications/NevronOpenVision.MonoMac.app/Contents/Bin folder or copy those dlls to a folder which is more convenient for referencing.



3. Initialize the NOV Application
Open the Main.cs file and ensure that the NNOVApplicationInstaller.Install() method is called before the MonoMac application runs the main form of the application.

using System;
using Nevron.Nov;
using Nevron.Nov.Mac;
 
#if UNIFIEDAPI
using Foundation;
using AppKit;
#else
using MonoMac.Foundation;
using MonoMac.AppKit;
#endif
 
namespace MonoMacApplication1
{
    class MainClass
    {
        static void Main(string[] args)
        {
            NSApplication.Init();
 
            NLicenseManager.Instance.SetLicense(new NLicense("LICENSE KEY"));
 
            // install NOV
            NModule[] modules = new NModule[]
            {
                // TODO: Create modules here
            };
            NNOVApplicationInstaller.Install(modules);
 
            NSApplication.Main(args);
        }
    }
}


4. Say Hello World from NOV
Open the MainWindow.cs file and replace its content with the following code:

using System;
using Nevron.Nov.Mac;
using Nevron.Nov.UI;
 
#if UNIFIEDAPI
using Foundation;
using AppKit;
#else
using MonoMac.Foundation;
using MonoMac.AppKit;
#endif
 
namespace MonoMacApplication1
{
    public partial class MainWindow : NSWindow
    {
        #region Constructors
 
        // Called when created from unmanaged code
        public MainWindow(IntPtr handle)
            : base(handle)
        {
            Initialize();
        }
        // Called when created directly from a XIB file
        [Export("initWithCoder:")]
        public MainWindow(NSCoder coder)
            : base(coder)
        {
            Initialize();
        }
        // Shared initialization code
        void Initialize()
        {
            //NUISettings.EnableMultiThreadedPainting = false;
            //NUISettings.EnablePaintCache = false;
 
            // place the host inside the mac window
            this.ContentView = new NNovWidgetHost(new NLabel("Hello World from Nevron Open Vision"));
        }
 
        #endregion
    }
}


4.1. Open the MainWindowdesigner.cs and replace its content with the following code:

#if UNIFIEDAPI
using Foundation;
#else
using MonoMac.Foundation;
#endif
 
namespace MonoMacApplication1
{
    // Should subclass MonoMac.AppKit.NSWindow
    [Register("MainWindow")]
    public partial class MainWindow
    {
    }
    // Should subclass MonoMac.AppKit.NSWindowController
    [Register("MainWindowController")]
    public partial class MainWindowController
    {
    }
}

4.2. Open the AppDelegate.cs and replace its content with the following code:

#if UNIFIEDAPI
using Foundation;
using AppKit;
#else
using MonoMac.Foundation;
using MonoMac.AppKit;
#endif
 
namespace MonoMacApplication1
{
    public partial class AppDelegate : NSApplicationDelegate
    {
        MainWindowController mainWindowController;
 
        public AppDelegate()
        {
        }
 
#if UNIFIEDAPI
        public override void DidFinishLaunching (NSNotification notification)
        {
            mainWindowController = new MainWindowController ();
            mainWindowController.Window.MakeKeyAndOrderFront (this);
        }
#else
        public override void FinishedLaunching(NSObject notification)
        {
            mainWindowController = new MainWindowController();
            mainWindowController.Window.MakeKeyAndOrderFront(this);
        }
#endif
 
        public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
        {
            return true;
        }
    }
}

4.3. Open the AppDelegate.designer.cs and replace its content with the following code:

#if UNIFIEDAPI
using Foundation;
#else
using MonoMac.Foundation;
#endif
 
namespace MonoMacApplication1
{
    // Should subclass MonoMac.AppKit.NSResponder
    [Register("AppDelegate")]
    public partial class AppDelegate
    {
    }
}

4.4. Open the MainWindowController.cs and replace its content with the following code:

using System;
 
#if UNIFIEDAPI
using Foundation;
using AppKit;
#else
using MonoMac.Foundation;
using MonoMac.AppKit;
#endif
 
namespace MonoMacApplication1
{
    public partial class MainWindowController : NSWindowController
    {
        #region Constructors
 
        // Called when created from unmanaged code
        public MainWindowController(IntPtr handle) : base(handle)
        {
            Initialize();
        }
        // Called when created directly from a XIB file
        [Export("initWithCoder:")]
        public MainWindowController(NSCoder coder) : base(coder)
        {
            Initialize();
        }
        // Call to load from the XIB/NIB file
        public MainWindowController() : base("MainWindow")
        {
            Initialize();
        }
        // Shared initialization code
        void Initialize()
        {
        }
 
        #endregion
 
        //strongly typed window accessor
        public new MainWindow Window
        {
            get
            {
                return (MainWindow)base.Window;
            }
        }
    }
}


Check the Solution Options and make sure you have a Debug and Release configuration with the AnyCPU platform selected. Then from Configuration Mapping select a configuration with AnyCPU.



Build and Run your application - it should display a simple form with a "Hello World from Nevron Open Vision" label inside.



This is as much as is required to host some NOV content in Mono Mac.

The sample just makes a simple label, as content of the NNovWidgetHost is a native MonoMac control, but this control can actually contain any NOV widget. See the NOV Help Documentation -> UI Overview topic for an overview of the User Interface that comes along with NOV.

 
Download Free Trial  Help Documentation
Send Feedback

Article ID: 242, Created On: 8/3/2016, Modified: 8/12/2016