Beispiel #1
0
		public GraphicsHandler(NSView view)
		{
			this.view = view;
			graphicsContext = NSGraphicsContext.FromWindow(view.Window);
			graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			disposeContext = true;
			Control = graphicsContext.GraphicsPort;

			view.PostsFrameChangedNotifications = true;
			AddObserver(NSView.FrameChangedNotification, FrameDidChange, view);

			// if control is in a scrollview, we need to trap when it's scrolled as well
			var parent = view.Superview;
			while (parent != null)
			{
				var scroll = parent as NSScrollView;
				if (scroll != null)
				{
					scroll.ContentView.PostsBoundsChangedNotifications = true;
					AddObserver(NSView.BoundsChangedNotification, FrameDidChange, scroll.ContentView);
				}
				parent = parent.Superview;
			}

			SetDefaults();
			InitializeContext(view.IsFlipped);
		}
Beispiel #2
0
		public override void LoadView ()
		{
			var view = new NSView(new RectangleF(0,100,320,500));
			//view.BackgroundColor = NSColor.Gray;
			View = view;
			ViewDidLoad ();
		}
		public static void BringSubviewToFront(this NSView superView, NSView theView)
		{
			if(theView == null || !superView.Subviews.Contains(theView))
				return;
			theView.RemoveFromSuperview();
			superView.AddSubview(theView);
		}
		public override void ViewDidLoad ()
		{
			View = new NSView (new RectangleF (0, 0, 320, 400));
			base.ViewDidLoad ();

			var textEditFirst = new NSTextField(new System.Drawing.RectangleF(0,0,320,40));
			View.AddSubview (textEditFirst);
			var textEditSecond = new NSTextField(new System.Drawing.RectangleF(0,50,320,40));
			View.AddSubview(textEditSecond);
			var slider = new NSSlider(new System.Drawing.RectangleF(0,150,320,40));
			slider.MinValue = 0;
			slider.MaxValue = 100;
			slider.IntValue = 23;
			View.AddSubview(slider);
			var labelFull = new NSTextField(new System.Drawing.RectangleF(0,100,320,40));
			labelFull.Editable = false;
			labelFull.Bordered = false;
			labelFull.AllowsEditingTextAttributes = false;
			labelFull.DrawsBackground = false;
			View.AddSubview (labelFull);
			var sw = new NSButton(new RectangleF(0,200,320,40));
			sw.SetButtonType (NSButtonType.Switch);
			View.AddSubview (sw);
			//sw.AddObserver()

			var set = this.CreateBindingSet<SecondViewController, SecondViewModel> ();
			set.Bind (textEditFirst).For(v => v.StringValue).To (vm => vm.FirstName);
			set.Bind (textEditSecond).For(v => v.StringValue).To (vm => vm.LastName);
			set.Bind (labelFull).Described("SliderValue + ' ' + OnOffValue").For("StringValue");	
			set.Bind (slider).For("IntValue").To (vm => vm.SliderValue);
			set.Bind (sw).For(c => c.State).To (vm => vm.OnOffValue);


			set.Apply ();
		}
Beispiel #5
0
		public static Point GetLocation (NSView view, NSEvent theEvent)
		{
			var loc = view.ConvertPointFromView (theEvent.LocationInWindow, null);
			if (!view.IsFlipped)
				loc.Y = view.Frame.Height - loc.Y;
			return Generator.ConvertF (loc);
		}
Beispiel #6
0
			public override void LoadView ()
			{
				var backend = (ViewBackend)Toolkit.GetBackend (child);
				view = ((ViewBackend)backend).NativeWidget as NSView;
				backend.SetAutosizeMode (true);
				ForceChildLayout ();
				// FIXME: unset when the popover is closed
			}
		void SetNativeView (NSView aView)
		{
			if (innerView != null)
				innerView.RemoveFromSuperview ();
			innerView = aView;
			innerView.Frame = Widget.Bounds;
			Widget.AddSubview (innerView);
		}
Beispiel #8
0
		public void SetContent (object nativeWidget)
		{
			if (nativeWidget is NSView) {
				if (ViewObject == null)
					innerView = (NSView)nativeWidget;
				else
					SetNativeView ((NSView)nativeWidget);
			}
		}
Beispiel #9
0
		public override void Initialize ()
		{
			ViewObject = new WidgetView (EventSink, ApplicationContext);
			if (innerView != null) {
				var aView = innerView;
				innerView = null;
				SetNativeView (aView);
			}
		}
Beispiel #10
0
 public void AddSubview(NSView view, float extent)
 {
     base.AddSubview(view);
     _children.Add(new Child
     {
         View = view,
         Extent = extent,
     });
 }
		public ICredentials GetCredentials (Uri uri, IWebProxy proxy, CredentialType credentialType, ICredentials existingCredentials, bool retrying)
		{
			bool result = false;
			DispatchService.GuiSyncDispatch (() => {
				using (var ns = new NSAutoreleasePool ()) {
					var message = string.Format ("{0} needs {1} credentials to access {2}.", BrandingService.ApplicationName, 
					                             credentialType == CredentialType.ProxyCredentials ? "proxy" : "request", uri.Host);

					NSAlert alert = NSAlert.WithMessage ("Credentials Required", "OK", "Cancel", null, message);
					alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

					NSView view = new NSView (new RectangleF (0, 0, 313, 91));

					var creds = Utility.GetCredentialsForUriFromICredentials (uri, existingCredentials);

					var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) {
						Identifier = "usernameLabel",
						StringValue = "Username:"******"Password:",
						Alignment = NSTextAlignment.Right,
						Editable = false,
						Bordered = false,
						DrawsBackground = false,
						Bezeled = false,
						Selectable = false,
					};
					view.AddSubview (passwordLabel);

					var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22));
					passwordInput.StringValue = creds != null ? creds.Password : string.Empty;
					view.AddSubview (passwordInput);

					alert.AccessoryView = view;
					result = alert.RunModal () == 1;

					username = usernameInput.StringValue;
					password = passwordInput.StringValue;
				}
			});

			return result ? new NetworkCredential (username, password) : null;
		}
		public override void ViewWillMoveToSuperview (NSView newSuperview)
		{
			if (newSuperview != null)
			{
				base.ViewWillMoveToSuperview (newSuperview);

				if (_controller != null)
					_controller.RefreshBasket ();
			}
		}
Beispiel #13
0
        public static void MouseUp(NSView view, IControlMouseInteraction control, NSEvent theEvent, bool isRightButton)
        {
            var button = MouseButtonType.Right;
            if(!isRightButton)
                button = GetMouseButtonType(theEvent);

            var point = GetMouseLocation(view, theEvent);
            var keysHeld = GetKeysHeld(theEvent);
            //Console.WriteLine("GenericControlHelper - MouseUp - point: {0} button: {1} bounds: {2}", point, button, view.Bounds);
            control.MouseUp(point.X, point.Y, button, keysHeld);
        }    
Beispiel #14
0
        public NSString ViewStringForToolTip(NSView view, NSObject tooltipTag, PointF point, IntPtr data)
        {
            int index = data.ToInt32();
            if (index >= 0 && index < imageViewItems.Count)
            {
                return (NSString) imageViewItems[index].Keywords;
            }

            logger.Info("Nothing for {0}", index);
            return null;
        }
Beispiel #15
0
		public override void InitializeBackend (object frontend, ApplicationContext context)
		{
			base.InitializeBackend (frontend, context);

			buttonBox = new HBox () {
				Spacing = 0,
				Margin = 0
			};
			buttonBoxView = ((ViewBackend)buttonBox.GetBackend ()).Widget;
			ContentView.AddSubview (buttonBoxView);
		}
Beispiel #16
0
		public override void DrawInteriorWithFrame (RectangleF cellFrame, NSView inView)
		{
			CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;
			
			var backend = new CGContextBackend {
				Context = ctx,
				InverseViewTransform = ctx.GetCTM ().Invert ()
			};
			Frontend.ApplicationContext.InvokeUserCode (delegate {
				Frontend.Draw (backend, new Rectangle (cellFrame.X, cellFrame.Y, cellFrame.Width, cellFrame.Height));
			});
		}
Beispiel #17
0
			public override void LoadView ()
			{
				var backend = (ViewBackend)Toolkit.GetBackend (child);
				view = ((ViewBackend)backend).NativeWidget as NSView;

				if (view.Layer == null)
					view.WantsLayer = true;
				if (BackgroundColor != null)
					view.Layer.BackgroundColor = BackgroundColor;
				backend.SetAutosizeMode (true);
				ForceChildLayout ();
				// FIXME: unset when the popover is closed
			}
Beispiel #18
0
		void SetNativeView (NSView aView)
		{
			if (innerView != null)
				innerView.RemoveFromSuperview ();
			innerView = aView;
			innerView.Frame = Widget.Bounds;

			innerView.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
			innerView.TranslatesAutoresizingMaskIntoConstraints = true;
			Widget.AutoresizesSubviews = true;

			Widget.AddSubview (innerView);
		}
		public override void DrawWithFrame (RectangleF cellFrame, NSView inView)
		{
			borderColor.SetFill ();

			NSGraphics.RectFill (
				new RectangleF (
					cellFrame.X + padding / 2,
					cellFrame.Y + padding / 2,
					cellFrame.Width - padding,
					cellFrame.Height - padding
				)
			);

			base.DrawWithFrame (cellFrame, inView);
		}
Beispiel #20
0
		public static void Colourize(NSView control, Color color, Action drawAction)
		{
			var size = control.Frame.Size;
			if (size.Width <= 0 || size.Height <= 0)
				return;
			var image = new NSImage(size);
			
			image.LockFocusFlipped(control.IsFlipped);
			drawAction();
			image.UnlockFocus();
			
			var ciImage = CIImage.FromCGImage(image.CGImage);

			SD.SizeF realSize;
			if (control.RespondsToSelector(selConvertSizeToBacking))
				realSize = control.ConvertSizeToBacking(size);
			else
				realSize = control.ConvertSizeToBase(size);

			if (control.IsFlipped)
			{
				var affineTransform = new NSAffineTransform();
				affineTransform.Translate(0, realSize.Height);
				affineTransform.Scale(1, -1);
				var filter1 = new CIAffineTransform();
				filter1.Image = ciImage;
				filter1.SetValueForKey(affineTransform, CIInputTransform);
				ciImage = filter1.ValueForKey(CIOutputImage) as CIImage;
			}

			var filter2 = new CIColorControls();
			filter2.SetDefaults();
			filter2.Image = ciImage;
			filter2.Saturation = 0.0f;
			ciImage = filter2.ValueForKey(CIOutputImage) as CIImage;
			
			var filter3 = new CIColorMatrix();
			filter3.SetDefaults();
			filter3.Image = ciImage;
			filter3.RVector = new CIVector(0, color.R, 0);
			filter3.GVector = new CIVector(color.G, 0, 0);
			filter3.BVector = new CIVector(0, 0, color.B);
			ciImage = filter3.ValueForKey(CIOutputImage) as CIImage;

			ciImage.Draw(new SD.RectangleF(SD.PointF.Empty, size), new SD.RectangleF(SD.PointF.Empty, realSize), NSCompositingOperation.SourceOver, 1);
		}
Beispiel #21
0
		public static void Colourize (NSView control, Color color, Action drawAction)
		{
			var size = control.Frame.Size;
			var image = new NSImage (size);
			
			image.LockFocusFlipped (control.IsFlipped);
			drawAction ();
			image.UnlockFocus ();
			
			var ciImage = CIImage.FromData (image.AsTiff ());
			
			if (control.IsFlipped) {
				var realSize = control.ConvertSizeToBase (size);
				var affineTransform = new NSAffineTransform ();
				affineTransform.Translate (0, realSize.Height);
				affineTransform.Scale (1, -1);
				var filter1 = CIFilter.FromName ("CIAffineTransform");
				filter1.SetValueForKey (ciImage, CIInputImage);
				filter1.SetValueForKey (affineTransform, CIInputTransform);
				ciImage = filter1.ValueForKey (CIOutputImage) as CIImage;
			}
			
			var filter2 = CIFilter.FromName ("CIColorControls");
			filter2.SetDefaults ();
			filter2.SetValueForKey (ciImage, CIInputImage);
			filter2.SetValueForKey (new NSNumber (0.0f), CIInputSaturation);
			ciImage = filter2.ValueForKey (CIOutputImage) as CIImage;
			
			var filter3 = CIFilter.FromName ("CIColorMatrix");
			filter3.SetDefaults ();
			filter3.SetValueForKey (ciImage, CIInputImage);
			filter3.SetValueForKey (new CIVector (0, color.R, 0), CIInputRVector);
			filter3.SetValueForKey (new CIVector (color.G, 0, 0), CIInputGVector);
			filter3.SetValueForKey (new CIVector (0, 0, color.B), CIInputBVector);
			ciImage = filter3.ValueForKey (CIOutputImage) as CIImage;
			
			image = new NSImage (size);
			var rep = NSCIImageRep.FromCIImage (ciImage);
			image.AddRepresentation (rep);
			image.Draw (SD.PointF.Empty, new SD.RectangleF (SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);
			/* Use this when implemented in maccore:
			ciImage.Draw (SD.PointF.Empty, new SD.RectangleF (SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);
			 */
		}
		public override void ViewDidLoad ()
		{
			View = new NSView(new RectangleF(0,100,320, 400));
			base.ViewDidLoad ();

			var textEditFirst = new NSTextField(new System.Drawing.RectangleF(10,0,320,40));
			View.AddSubview (textEditFirst);
			var textEditSecond = new NSTextField(new System.Drawing.RectangleF(10,50,320,40));
			View.AddSubview(textEditSecond);
			var labelFull = new NSTextField(new System.Drawing.RectangleF(10,100,320,40));
			View.AddSubview (labelFull);
			var bu = new NSButton (new RectangleF (0, 150, 320, 40));
			bu.Title = "Hello";
			View.AddSubview (bu);

			var set = this.CreateBindingSet<FirstViewController, FirstViewModel> ();
			set.Bind (textEditFirst).For(v => v.StringValue).To (vm => vm.FirstName);
			set.Bind (textEditSecond).For(v => v.StringValue).To (vm => vm.LastName);
			set.Bind (labelFull).For(v => v.StringValue).To (vm => vm.FullName);	
			set.Bind (bu).For("Activated").To ("GoCommand");
			set.Apply ();
		}
Beispiel #23
0
		public static void Colourize(NSView control, Color color, Action drawAction)
		{
			var size = control.Frame.Size;
			if (size.Width <= 0 || size.Height <= 0)
				return;
			var image = new NSImage(size);
			
			image.LockFocusFlipped(!control.IsFlipped);
			drawAction();
			image.UnlockFocus();

			var ciImage = CIImage.FromCGImage(image.CGImage);

			CGSize realSize;
			if (control.RespondsToSelector(selConvertSizeToBacking))
				realSize = control.ConvertSizeToBacking(size);
			else
				realSize = control.ConvertSizeToBase(size);

			var filter2 = new CIColorControls();
			filter2.SetDefaults();
			filter2.Image = ciImage;
			filter2.Saturation = 0.0f;
			ciImage = (CIImage)filter2.ValueForKey(CIOutputImage);

			var filter3 = new CIColorMatrix();
			filter3.SetDefaults();
			filter3.Image = ciImage;
			filter3.RVector = new CIVector(0, color.R, 0);
			filter3.GVector = new CIVector(color.G, 0, 0);
			filter3.BVector = new CIVector(0, 0, color.B);
			ciImage = (CIImage)filter3.ValueForKey(CIOutputImage);

			// create separate context so we can force using the software renderer, which is more than fast enough for this
			var ciContext = CIContext.FromContext(NSGraphicsContext.CurrentContext.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true });
			ciContext.DrawImage(ciImage, new CGRect(CGPoint.Empty, size), new CGRect(CGPoint.Empty, realSize));
		}
        //    public override void DrawWithFrame(RectangleF cellFrame, NSView inView) {
        //       float iconX = 0f;
        //       float iconY = 0f;
        //       float iconWidth = 0f;
        //       float iconHeight = 0f;
        //    
        //       cellFrame.X = cellFrame.X - 10;
        //       cellFrame.Height = cellFrame.Height - 1;
        //       RectangleF newRect = cellFrame;
        //    
        //       if (image != null) {
        //          iconX = cellFrame.X + 1;
        //          iconY = cellFrame.Y + 2;
        //          iconWidth = image.Size.Width;
        //          iconHeight = image.Size.Height;
        //        
        //          image.Draw(new RectangleF(iconX, iconY, iconWidth, iconHeight), image.AlignmentRect, NSCompositingOperation.SourceOver, 1.0f, true, null);
        //        
        //          newRect = new RectangleF(iconX + iconWidth, cellFrame.Y, cellFrame.Width - iconX - iconWidth, cellFrame.Height - 1);
        //       }
        //    
        //       base.DrawWithFrame(newRect, inView);
        //    }
        public override void DrawInteriorWithFrame(RectangleF cellFrame, NSView inView)
        {
            float iconX = 0f;
             float iconY = 0f;
             float iconWidth = 0f;
             float iconHeight = 0f;

             cellFrame.X = cellFrame.X - 10;
             cellFrame.Height = cellFrame.Height - 1;
             RectangleF newRect = cellFrame;

             if (image != null) {
            iconX = cellFrame.X + 1;
            iconY = cellFrame.Y + 2;
            iconWidth = image.Size.Width;
            iconHeight = image.Size.Height;

            image.Draw (new RectangleF (iconX, iconY, iconWidth, iconHeight), image.AlignmentRect, NSCompositingOperation.SourceOver, 1.0f, true, null);

            newRect = new RectangleF (iconX + iconWidth, cellFrame.Y, cellFrame.Width - iconX - iconWidth, cellFrame.Height - 1);
             }

             base.DrawInteriorWithFrame (newRect, inView);
        }
		// Helper method to animate the sub view
		private void animateView(NSView subView, RectangleF toFrame) 
		{
#if true
			// Simple animation: assign the new value, and let CoreAnimation
			// take it from here
			
			((NSView) subView.Animator).Frame = toFrame;
#else
			//
			// Performing the animation by hand, every step of the way
			//
			var animationY = CABasicAnimation.FromKeyPath("position.y");
			animationY.To = NSNumber.FromFloat(toFrame.Y);
			animationY.AnimationStopped += delegate {
				//Console.WriteLine("animation stopped");
				subView.Layer.Frame = toFrame;
			};
			
			var animationX = CABasicAnimation.FromKeyPath("position.x");
			animationX.To = NSNumber.FromFloat(toFrame.X);
			
			animationY.AutoReverses = false;
			animationX.AutoReverses = false;
			
			animationY.RemovedOnCompletion = false;
			animationX.RemovedOnCompletion = false;
			
			animationY.FillMode = CAFillMode.Forwards;
			animationX.FillMode = CAFillMode.Forwards;
			
			subView.Layer.AddAnimation(animationX,"moveX");
			subView.Layer.AddAnimation(animationY,"moveY");
#endif
		}
		static ICredentials GetCredentialsFromUser (Uri uri, IWebProxy proxy, CredentialType credentialType)
		{
			NetworkCredential result = null;

			DispatchService.GuiSyncDispatch (() => {

				using (var ns = new NSAutoreleasePool ()) {
					var message = credentialType == CredentialType.ProxyCredentials
						? GettextCatalog.GetString (
							"{0} needs credentials to access the proxy server {1}.",
							BrandingService.ApplicationName,
							uri.Host
						)
						: GettextCatalog.GetString (
							"{0} needs credentials to access {1}.",
							BrandingService.ApplicationName,
							uri.Host
						);

					var alert = NSAlert.WithMessage (
						GettextCatalog.GetString ("Credentials Required"),
						GettextCatalog.GetString ("OK"),
						GettextCatalog.GetString ("Cancel"),
						null,
						message
					);

					alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

					var view = new NSView (new RectangleF (0, 0, 313, 91));

					var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) {
						Identifier = "usernameLabel",
						StringValue = "Username:"******"Password:",
						Alignment = NSTextAlignment.Right,
						Editable = false,
						Bordered = false,
						DrawsBackground = false,
						Bezeled = false,
						Selectable = false,
					};
					view.AddSubview (passwordLabel);

					var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22));
					view.AddSubview (passwordInput);

					alert.AccessoryView = view;

					if (alert.RunModal () != 1)
						return;

					var username = usernameInput.StringValue;
					var password = passwordInput.StringValue;
					result = new NetworkCredential (username, password);
				}
			});

			// store the obtained credentials in the keychain
			// but don't store for the root url since it may have other credentials
			if (result != null)
				Keychain.AddInternetPassword (uri, result.UserName, result.Password);

			return result;
		}
Beispiel #27
0
 public override void StopTracking(PointF lastPoint, PointF stopPoint, NSView inView, bool mouseIsUp)
 {
     if (trackingCell != null) {
         try {
             trackingCell.StopTracking (lastPoint, stopPoint, inView, mouseIsUp);
         } finally {
             trackingCell = null;
         }
     }
 }
Beispiel #28
0
 public override bool StartTracking(PointF startPoint, NSView inView)
 {
     foreach (NSCell c in cells) {
         if (c.StartTracking (startPoint, inView)) {
             trackingCell = c;
             return true;
         }
     }
     return false;
 }
Beispiel #29
0
 public override NSCellHit HitTest(NSEvent forEvent, RectangleF inRect, NSView ofView)
 {
     foreach (CellPos cp in GetCells(inRect)) {
         var h = cp.Cell.HitTest (forEvent, cp.Frame, ofView);
         if (h != NSCellHit.None)
             return h;
     }
     return NSCellHit.None;
 }
Beispiel #30
0
 public override void Highlight(bool flag, RectangleF withFrame, NSView inView)
 {
     foreach (CellPos cp in GetCells(withFrame)) {
         cp.Cell.Highlight (flag, cp.Frame, inView);
     }
 }