Exemplo n.º 1
0
        static NSApplication()
        {
            Cocoa.Initialize();

            // Register a Quit method to be called on cmd-q
            IntPtr nsapp = Class.Get("NSApplication");

            Class.RegisterMethod(nsapp, OnQuitHandler, "quit", "v@:");

            // Fetch the application handle
            Handle = Cocoa.SendIntPtr(nsapp, Selector.Get("sharedApplication"));

            // Setup the application
            Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular);
            Cocoa.SendVoid(Handle, Selector.Get("discardEventsMatchingMask:beforeEvent:"), uint.MaxValue, IntPtr.Zero);
            Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true);

            if (Cocoa.SendIntPtr(Handle, Selector.Get("mainMenu")) == IntPtr.Zero)
            {
                // Create the menu bar
                var menubar  = Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc);
                var menuItem = Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc);

                // Add menu item to bar, and bar to application
                Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
                Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);

                // Add a "Quit" menu item and bind the button.
                var appMenu      = Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc);
                var quitMenuItem = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc),
                                                    Selector.Get("initWithTitle:action:keyEquivalent:"), Cocoa.ToNSString("Quit"), selQuit, Cocoa.ToNSString("q"));

                Cocoa.SendIntPtr(appMenu, Selector.Get("addItem:"), quitMenuItem);
                Cocoa.SendIntPtr(menuItem, Selector.Get("setSubmenu:"), appMenu);

                // Tell cocoa we're ready to run the application (usually called by [NSApp run]).
                // Note: if a main menu exists, then this method has already been called and
                // calling it again will result in a crash. For this reason, we only call it
                // when we create our own main menu.
                Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
            }

            // Disable momentum scrolling and long-press key pop-ups
            IntPtr settings = Cocoa.SendIntPtr(Class.NSDictionary, Selector.Alloc);
            //IntPtr momentum_scrolling = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false);
            IntPtr press_and_hold = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false);

            // Initialize and register the settings dictionary
            settings =
                Cocoa.SendIntPtr(settings, Selector.Get("initWithObjectsAndKeys:"),
                                 //momentum_scrolling, Cocoa.ToNSString("AppleMomentumScrollSupported"),
                                 press_and_hold, Cocoa.ToNSString("ApplePressAndHoldEnabled"),
                                 IntPtr.Zero);
            Cocoa.SendVoid(
                Cocoa.SendIntPtr(Class.NSUserDefaults, Selector.Get("standardUserDefaults")),
                Selector.Get("registerDefaults:"),
                settings);
            Cocoa.SendVoid(settings, Selector.Release);
        }
Exemplo n.º 2
0
        internal static void Initialize()
        {
            // Create the NSAutoreleasePool
            AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.NSAutoreleasePool, Selector.Alloc), Selector.Init);

            // Register a Quit method to be called on cmd-q
            IntPtr nsapp = Class.Get("NSApplication");

            Class.RegisterMethod(nsapp, new OnQuitDelegate(OnQuit), "quit", "v@:");

            // Fetch the application handle
            Handle = Cocoa.SendIntPtr(nsapp, Selector.Get("sharedApplication"));

            // Setup the application
            Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular);
            Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true);

            // Create the menu bar
            var menubar = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
                                           Selector.Autorelease);

            var menuItem = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc),
                                            Selector.Autorelease);

            // Add menu item to bar, and bar to application
            Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
            Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);

            // Add a "Quit" menu item and bind the button.
            var appMenu = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
                                           Selector.Autorelease);
            var quitMenuItem = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc),
                                                                 Selector.Get("initWithTitle:action:keyEquivalent:"), Cocoa.ToNSString("Quit"), selQuit, Cocoa.ToNSString("q")),
                                                Selector.Autorelease);

            Cocoa.SendIntPtr(appMenu, Selector.Get("addItem:"), quitMenuItem);
            Cocoa.SendIntPtr(menuItem, Selector.Get("setSubmenu:"), appMenu);

            // Tell cocoa we're ready to run the application (usually called by [NSApp run]).
            Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));

            // Disable momentum scrolling and long-press key pop-ups
            IntPtr settings           = Cocoa.SendIntPtr(Class.NSDictionary, Selector.Alloc);
            IntPtr momentum_scrolling = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false);
            IntPtr press_and_hold     = Cocoa.SendIntPtr(Class.NSNumber, Selector.Get("numberWithBool:"), false);

            // Initialize and register the settings dictionary
            settings =
                Cocoa.SendIntPtr(settings, Selector.Get("initWithObjectsAndKeys:"),
                                 //momentum_scrolling, Cocoa.ToNSString("AppleMomentumScrollSupported"),
                                 press_and_hold, Cocoa.ToNSString("ApplePressAndHoldEnabled"),
                                 IntPtr.Zero);
            Cocoa.SendVoid(
                Cocoa.SendIntPtr(Class.NSUserDefaults, Selector.Get("standardUserDefaults")),
                Selector.Get("registerDefaults:"),
                settings);
            Cocoa.SendVoid(settings, Selector.Release);
        }
Exemplo n.º 3
0
        private void SetTitle(string newTitle, bool callEvent)
        {
            title = newTitle ?? "";

            Cocoa.SendIntPtr(windowInfo.Handle, selSetTitle, Cocoa.ToNSString(title));
            if (callEvent)
            {
                OnTitleChanged(EventArgs.Empty);
            }
        }