Пример #1
0
        private static NativeClassDefinition CreateWindowDelegate()
        {
            var definition = NativeClassDefinition.FromObject(
                "SpiderEyeWindowDelegate",
                AppKit.GetProtocol("NSWindowDelegate"));

            definition.AddMethod <WindowShouldCloseDelegate>(
                "windowShouldClose:",
                "c@:@",
                (self, op, window) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                var args     = new CancelableEventArgs();
                instance.Closing?.Invoke(instance, args);

                return(args.Cancel ? (byte)0 : (byte)1);
            });

            definition.AddMethod <NotificationDelegate>(
                "windowWillClose:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaWindow>(self);
                instance.webview.TitleChanged -= instance.Webview_TitleChanged;
                instance.Closed?.Invoke(instance, EventArgs.Empty);
            });

            definition.FinishDeclaration();

            return(definition);
        }
Пример #2
0
        public CocoaWindow(WindowConfiguration config, WebviewBridge bridge)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            Handle = AppKit.Call("NSWindow", "alloc");

            canResizeField = config.CanResize;
            var style = GetWantedStyleMask();

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Size.Width, config.Size.Height),
                new UIntPtr((uint)style),
                new UIntPtr(2),
                false);

            webview = new CocoaWebview(bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            webview.TitleChanged += Webview_TitleChanged;

            windowDelegate = WindowDelegateDefinition.CreateInstance(this);
            ObjC.Call(Handle, "setDelegate:", windowDelegate.Handle);
        }
Пример #3
0
        private static NativeClassDefinition CreateAppDelegate()
        {
            var definition = NativeClassDefinition.FromClass(
                "SpiderEyeAppDelegate",
                AppKit.GetClass("NSResponder"),
                // note: NSApplicationDelegate is not available at runtime and returns null
                AppKit.GetProtocol("NSApplicationDelegate"),
                AppKit.GetProtocol("NSTouchBarProvider"));

            definition.AddMethod <ShouldTerminateDelegate>(
                "applicationShouldTerminateAfterLastWindowClosed:",
                "c@:@",
                (self, op, notification) => (byte)(Application.ExitWithLastWindow ? 1 : 0));

            definition.AddMethod <NotificationDelegate>(
                "applicationDidFinishLaunching:",
                "v@:@",
                (self, op, notification) =>
            {
                var instance = definition.GetParent <CocoaApplication>(self);
                ObjC.Call(instance.Handle, "activateIgnoringOtherApps:", true);
            });

            definition.FinishDeclaration();

            return(definition);
        }
		public static NSImage createGradientImageWidth(CGFloat pixelsWide) height(CGFloat pixelsHigh) fromColor(NSColor fromColor) toColor(NSColor toColor)
		{
			CGImageRef theCGImage = null;
			CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
			//  create the bitmap context
			CGContextRef gradientBitmapContext = CGBitmapContextCreate(null, (size_t)pixelsWide, (size_t)pixelsHigh, 8, 0, colorSpace, CGImageAlphaInfo.kCGImageAlphaNoneSkipFirst as CGBitmapInfo);
			//  define the start and end grayscale values (with the alpha, even though
			//  our bitmap context doesn't support alpha the gradient requires it)
			CGColorRef start = fromColor.CGColor();
			CGColorRef end = toColor.CGColor();
			CGColorRef[] colors = new [] {start, end};
			//  CGFloat locations[2] = { 0.0, 1.0 };
			CFArrayRef colorArray = CFArrayCreate(null, &colors, 2, null);
			//  create the CGGradient and then release the gray color space
			CGGradientRef grayScaleGradient = CGGradientCreateWithColors(null, colorArray, null);
			CGColorSpaceRelease(colorSpace);
			CFRelease(colorArray);
			//  create the start and end points for the gradient vector (straight down)
			CGPoint gradientStartPoint = CGPointZero;
			CGPoint gradientEndPoint = CGPointMake(pixelsWide / 2, pixelsHigh);
			//  draw the gradient into the gray bitmap context
			CGContextDrawLinearGradient(gradientBitmapContext, grayScaleGradient, gradientStartPoint, gradientEndPoint, kCGGradientDrawsAfterEndLocation);
			CGGradientRelease(grayScaleGradient);
			//  convert the context into a CGImageRef and release the context
			theCGImage = CGBitmapContextCreateImage(gradientBitmapContext);
			CGContextRelease(gradientBitmapContext);
			//  return the imageref containing the gradient
			NSImage theImage = this.imageFromCGImageRef(theCGImage);
			//  [NSImage imageWithCGImage:theCGImage];
			CGImageRelease(theCGImage);
			return theImage;
		}
Пример #5
0
		partial void powerStateChanged (AppKit.NSSegmentedControl sender)
		{
			NSError error;
			CurrentInterface.SetPower(powerState.SelectedSegment == 0, out error);

			if(error != null)
				Console.WriteLine("Error occurred while changing interface power state: {0}", error.LocalizedDescription);
		}
		partial void didRegister(AppKit.NSButton sender)
		{
			//register for an event
			MessageBus.Default.Register (MessageHandler);

			//register for CustomMessageBusEvent 
			MessageBus.Default.Register<CustomMessageBusEvent> (CustomMessageEventHandler);
		}
Пример #7
0
        public CocoaStatusIcon()
        {
            var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar");

            statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size
            ObjC.Call(statusItem, "setHighlightMode:", true);
            statusBarButton = ObjC.Call(statusItem, "button");
            ObjC.Call(statusBarButton, "setImageScaling:", 3); // 3 = scale proportionally up or down
        }
Пример #8
0
        public CocoaWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            windowShouldCloseDelegate = WindowShouldCloseCallback;
            windowWillCloseDelegate   = WindowWillCloseCallback;

            Handle = AppKit.Call("NSWindow", "alloc");

            var style = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable | NSWindowStyleMask.Miniaturizable;

            if (config.CanResize)
            {
                style |= NSWindowStyleMask.Resizable;
            }

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Width, config.Height),
                (int)style,
                2,
                0);

            Title = config.Title;

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new CocoaWebview(config, contentProvider, bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetWindowDelegate(Handle);
        }
Пример #9
0
 private CocoaLabelMenuItem(string label, string action)
     : base(AppKit.Call("NSMenuItem", "alloc"))
 {
     ObjC.Call(
         Handle,
         "initWithTitle:action:keyEquivalent:",
         NSString.Create(label),
         ObjC.RegisterName(action),
         NSString.Create(string.Empty));
 }
Пример #10
0
        public CocoaStatusIcon(string title)
        {
            var statusBar = AppKit.Call("NSStatusBar", "systemStatusBar");

            statusItem = ObjC.Call(statusBar, "statusItemWithLength:", -2.0); // -1 = variable size; -2 = square size
            ObjC.Call(statusItem, "setHighlightMode:", true);
            statusBarButton = ObjC.Call(statusItem, "button");
            ObjC.Call(statusBarButton, "setImageScaling:", new UIntPtr((uint)NSImageScaling.ProportionallyUpOrDown));
            Title = title;
        }
Пример #11
0
partial         void OnClickedLoad(AppKit.NSButton sender)
        {
            try
            {
                grvAvatar.Avatar = new Gravatar(txtEmail.StringValue);
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
            }
        }
Пример #12
0
        public CocoaApplication()
        {
            Factory = new CocoaUiFactory();
            SynchronizationContext = new CocoaSynchronizationContext();

            Handle      = AppKit.Call("NSApplication", "sharedApplication");
            appDelegate = AppDelegateDefinition.CreateInstance(this);

            ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero);
            ObjC.Call(Handle, "setDelegate:", appDelegate.Handle);
        }
        public override void windowDidLoad()
        {
            base.windowDidLoad();

            myWebView.frameLoadDelegate = new MyFrameLoadDelegate();

            NSUserDefaults.standardUserDefaults.setBool(true) forKey("WebKitDeveloperExtras");
            NSUserDefaults.standardUserDefaults.synchronize();

            NSURLRequest req = new NSURLRequest withURL(new NSURL withString("http://demo.desktopjavascript.com/"));
            myWebView.mainFrame.loadRequest(req);
        }
Пример #14
0
 public CocoaMenu(string title)
 {
     if (title != null)
     {
         Handle = AppKit.Call("NSMenu", "alloc");
         ObjC.Call(Handle, "initWithTitle:", NSString.Create(title));
     }
     else
     {
         Handle = AppKit.Call("NSMenu", "new");
     }
 }
Пример #15
0
        public CocoaApplication()
        {
            Factory = new CocoaUiFactory();
            SynchronizationContext = new CocoaSynchronizationContext();

            Handle      = AppKit.Call("NSApplication", "sharedApplication");
            appDelegate = AppDelegateDefinition.CreateInstance(this);

            ObjC.Call(Handle, "setActivationPolicy:", IntPtr.Zero);
            ObjC.Call(Handle, "setDelegate:", appDelegate.Handle);

            ObjC.SetProperty(AppKit.GetClass("NSWindow"), "allowsAutomaticWindowTabbing", false);
        }
Пример #16
0
		partial void didSendMessage(AppKit.NSButton sender)
		{
			var message = txtMessage.StringValue;

			//Creare a MessageBusEvent
			var aEvent = new CoreMessageBusEvent (kEventID) {
				Sender = this,
				Data = new object[]{ message },
			};

			//send it
			MessageBus.Default.Post (aEvent);
		}
Пример #17
0
        public CocoaLabelMenuItem(string label)
            : base(AppKit.Call("NSMenuItem", "alloc"))
        {
            // need to keep the delegate around or it will get garbage collected
            menuDelegate = MenuCallback;

            ObjC.Call(
                Handle,
                "initWithTitle:action:keyEquivalent:",
                NSString.Create(label),
                ObjC.RegisterName("menuCallback:"),
                NSString.Create(string.Empty));

            SetCallbackClass();
        }
		public AppKit.NSView GetViewForItem (AppKit.NSTableView tableView, AppKit.NSTableColumn tableColumn, System.nint row)
		{
			if (viewModel.Tweets.Count < row)
				return null;

			TweetView view = (TweetView)tableView.MakeView (identifer, this);
			if (view == null) {
				TweetViewController c = new TweetViewController ();
				view = c.View;
				view.Frame = new CGRect (0, 0, tableView.Frame.Width, 0);
				view.Identifier = identifer;
			}
			view.Tweet = viewModel.Tweets [(int)row];

			return view;
		}
Пример #19
0
		partial void NotifyMeAction (AppKit.NSButton sender)
		{
			// First we create our notification and customize as needed
			NSUserNotification not = null;

			try {
				not = new NSUserNotification();
			} catch {
				new NSAlert {
					MessageText = "NSUserNotification Not Supported",
					InformativeText = "This API was introduced in OS X Mountain Lion (10.8)."
				}.RunSheetModal (this);
				return;
			}

			not.Title = "Hello World";
			not.InformativeText = "This is an informative text";
			not.DeliveryDate = (NSDate)DateTime.Now;
			not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName;

			// We get the Default notification Center
			NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;
			
			center.DidDeliverNotification += (s, e) => 
			{
				Console.WriteLine("Notification Delivered");
				DeliveredColorWell.Color = NSColor.Green;
			};
			
			center.DidActivateNotification += (s, e) => 
			{
				Console.WriteLine("Notification Touched");
				TouchedColorWell.Color = NSColor.Green;
			};

			// If we return true here, Notification will show up even if your app is TopMost.
			center.ShouldPresentNotification = (c, n) => { return true; };
			
			center.ScheduleNotification(not);

		}
Пример #20
0
		partial void okButtonClicked (AppKit.NSButton sender)
		{
			spinner.Hidden = false;
			spinner.StartAnimation(this);

			NSError error;
			var networkName = nameTextField.StringValue;
			var password = passwordTextField.StringValue;
			var channelNumber = UInt32.Parse(channelPicker.SelectedItem.Title);
			var security = string.IsNullOrEmpty(password) ? CWIbssModeSecurity.None : CWIbssModeSecurity.WEP40;

			CurrentInterface.StartIbssModeWithSsid(new NSData(), security, channelNumber, password, out error);

			spinner.StopAnimation(this);
			spinner.Hidden = true;

			if(error != null)
				NSAlert.WithError(error).RunModal();
			else
				Window.Close();
		}
Пример #21
0
        private unsafe void UpdateIcon(AppIcon?icon)
        {
            var image = IntPtr.Zero;

            if (icon != null && icon.Icons.Length > 0)
            {
                byte[] data = icon.GetIconData(icon.DefaultIcon);
                fixed(byte *dataPtr = data)
                {
                    IntPtr nsData = Foundation.Call(
                        "NSData",
                        "dataWithBytesNoCopy:length:freeWhenDone:",
                        (IntPtr)dataPtr,
                        new IntPtr(data.Length),
                        IntPtr.Zero);

                    image = AppKit.Call("NSImage", "alloc");
                    ObjC.Call(image, "initWithData:", nsData);
                    ObjC.Call(statusBarButton, "setImage:", image);
                }
            }

            ObjC.Call(statusBarButton, "setImage:", image);
        }
		partial void BtnClickBasicSidebarPlusImages (AppKit.NSButton sender);
		partial void BtnClickBasicSidebarPlusText (AppKit.NSButton sender);
Пример #24
0
		partial void didPostEvent(AppKit.NSButton sender)
		{
			MessageBus.Default.Post (new CustomMessageBusEvent ());
		}
Пример #25
0
 internal static IntPtr GetApp()
 {
     return(AppKit.Call("NSApplication", "sharedApplication"));
 }
		partial void BtnVibrantControlsCaveatsBehindWindowClicked (AppKit.NSButton sender);
Пример #27
0
        public static IntPtr FromHex(string?hex)
        {
            ColorTools.ParseHex(hex, out byte r, out byte g, out byte b);

            return(AppKit.Call("NSColor", "colorWithRed:green:blue:alpha:", r / 255d, g / 255d, b / 255d, 1d));
        }
Пример #28
0
        public static NSDialog CreateOpenPanel()
        {
            var panel = AppKit.Call("NSOpenPanel", "openPanel");

            return(new NSDialog(panel, panel, false));
        }
		partial void BtnPerformanceExampleClicked (AppKit.NSButton sender);
Пример #30
0
		partial void done (AppKit.NSButton sender);
Пример #31
0
		partial void cancelButtonClicked (AppKit.NSButton sender)
		{
			Window.Close();
		}
Пример #32
0
		bool IsRootGdkQuartzView (AppKit.NSView view)
		{
			return view.ToString ().Contains ("GdkQuartzView");
		}
partial         void OnClickedLoad(AppKit.NSButton sender);
Пример #34
0
		bool IsEmbeddedNSView (AppKit.NSView view)
		{
			if (IsRootGdkQuartzView (view))
				return true;
			if (view.Superview != null)
				return IsEmbeddedNSView (view.Superview);
			return false;
		}
		partial void BtnDemoFacetimeClicked (AppKit.NSButton sender);
Пример #36
0
 public void AddSeparatorMenuItem()
 {
     var item = AppKit.Call("NSMenuItem", "separatorItem");
     AddItem(item);
 }
		partial void BtnMaskImageWindowClicked (AppKit.NSButton sender);
partial         void clickButton(AppKit.NSButton sender);
		partial void BtnSampleMapsClicked (AppKit.NSButton sender);
Пример #40
0
        public static NSDialog CreateSavePanel()
        {
            var panel = AppKit.Call("NSSavePanel", "savePanel");

            return(new NSDialog(panel, panel, false));
        }
		partial void BtnVibrantControlsClicked (AppKit.NSButton sender);
Пример #42
0
        public static NSDialog CreateAlert()
        {
            var alert = AppKit.Call("NSAlert", "new");

            return(new NSDialog(alert, ObjC.Call(alert, "window"), true));
        }
Пример #43
0
 public CocoaMenu()
     : base(AppKit.Call("NSMenu", "new"))
 {
     ObjC.Call(Handle, "setAutoenablesItems:", false);
 }
		partial void BtnClickBasicSidebarPlusCustomViews2 (AppKit.NSButton sender);
Пример #45
0
 public CocoaSeparatorMenuItem()
     : base(AppKit.Call("NSMenuItem", "separatorItem"))
 {
 }
Пример #46
0
		AppKit.NSEvent OnNSEventKeyPress (AppKit.NSEvent ev)
		{
			// If we have a native window that can handle this command, let it process
			// the keys itself and do not go through the command manager.
			// Events in Gtk windows do not pass through here except when they're done
			// in native NSViews. PerformKeyEquivalent for them will not return true,
			// so we're always going to fallback to the command manager for them.
			// If no window is focused, it's probably because a gtk window had focus
			// and the focus didn't go to any other window on close. (debug popup on hover
			// that gets closed on unhover). So if no keywindow is focused, events will
			// pass through here and let us use the command manager.
			var window = AppKit.NSApplication.SharedApplication.KeyWindow;
			if (window != null) {
				// Try the handler in the native window.
				if (window.PerformKeyEquivalent (ev))
					return null;

				// If the window is a gtk window and is registered in the command manager
				// process the events through the handler.
				var gtkWindow = MonoDevelop.Components.Mac.GtkMacInterop.GetGtkWindow (window);
				if (gtkWindow != null && !TopLevelWindowStack.Contains (gtkWindow))
					return null;
			}

			var gdkev = MonoDevelop.Components.Mac.GtkMacInterop.ConvertKeyEvent (ev);
			if (gdkev != null) {
				if (ProcessKeyEvent (gdkev))
					return null;
			}
			return ev;
		}
partial         void OnClickedCircle(AppKit.NSButton sender);
 partial void StartSearch (AppKit.NSSearchField sender)
 {
     SearchCertificates (sender.StringValue);
 }
partial         void OnClickedSquare(AppKit.NSButton sender);
Пример #50
0
		partial void cancel (AppKit.NSButton sender);