private UIView AddDummyViewToContainerView(UIView containerView, INativeObject topItem, INativeObject bottomItem, List<NSLayoutConstraint> constraints)
		{
			UIView dummyView = new UIView {
				TranslatesAutoresizingMaskIntoConstraints = false
			};

			containerView.AddSubview (dummyView);

			// The horizontal layout of the dummy view does not matter, but for completeness, we give it a width of 0 and center it horizontally.
			constraints.AddRange (new NSLayoutConstraint[] {
				NSLayoutConstraint.Create(dummyView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0f, 0f),
				NSLayoutConstraint.Create(dummyView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterX, 1f, 0f),
				NSLayoutConstraint.Create(dummyView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, topItem, NSLayoutAttribute.Bottom,  1f, 0f),
				NSLayoutConstraint.Create(dummyView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, bottomItem, NSLayoutAttribute.Top, 1f, 0f)
			});

			return dummyView;
		}
Ejemplo n.º 2
0
		public static CFDictionary FromObjectsAndKeys (INativeObject[] objects, INativeObject[] keys)
		{
			if (objects == null)
				throw new ArgumentNullException ("objects");

			if (keys == null)
				throw new ArgumentNullException ("keys");

			if (objects.Length != keys.Length)
				throw new ArgumentException ("The length of both arrays must be the same");

			IntPtr [] k = new IntPtr [keys.Length];
			IntPtr [] v = new IntPtr [keys.Length];
			
			for (int i = 0; i < k.Length; i++) {
				k [i] = keys [i].Handle;
				v [i] = objects [i].Handle;
			}

			return new CFDictionary (CFDictionaryCreate (IntPtr.Zero, k, v, k.Length, KeyCallbacks, ValueCallbacks), true);
		}
Ejemplo n.º 3
0
		public static AnimationElement Layer (CALayer viewLayer, string keyPath, INativeObject from, INativeObject to)
		{
			return new AnimationElement {
				View = viewLayer,
				KeyPath = keyPath,
				FromValue = from,
				ToValue = to
			};
		}
Ejemplo n.º 4
0
		public static AnimationElement Layer (CALayer viewLayer, string keyPath, INativeObject to)
		{
			return Layer (viewLayer, keyPath, null, to);
		}
Ejemplo n.º 5
0
        public static NSObject FromObject(object obj)
        {
            if (obj == null)
            {
                return(NSNull.Null);
            }
            var t = obj.GetType();

            if (t == typeof(NSObject) || t.IsSubclassOf(typeof(NSObject)))
            {
                return((NSObject)obj);
            }

            switch (Type.GetTypeCode(t))
            {
            case TypeCode.Boolean:
                return(new NSNumber((bool)obj));

            case TypeCode.Char:
                return(new NSNumber((ushort)(char)obj));

            case TypeCode.SByte:
                return(new NSNumber((sbyte)obj));

            case TypeCode.Byte:
                return(new NSNumber((byte)obj));

            case TypeCode.Int16:
                return(new NSNumber((short)obj));

            case TypeCode.UInt16:
                return(new NSNumber((ushort)obj));

            case TypeCode.Int32:
                return(new NSNumber((int)obj));

            case TypeCode.UInt32:
                return(new NSNumber((uint)obj));

            case TypeCode.Int64:
                return(new NSNumber((long)obj));

            case TypeCode.UInt64:
                return(new NSNumber((ulong)obj));

            case TypeCode.Single:
                return(new NSNumber((float)obj));

            case TypeCode.Double:
                return(new NSNumber((double)obj));

            case TypeCode.String:
                return(new NSString((string)obj));

            default:
                if (t == typeof(IntPtr))
                {
                    return(NSValue.ValueFromPointer((IntPtr)obj));
                }
#if !NO_SYSTEM_DRAWING
                if (t == typeof(SizeF))
                {
                    return(NSValue.FromSizeF((SizeF)obj));
                }
                else if (t == typeof(RectangleF))
                {
                    return(NSValue.FromRectangleF((RectangleF)obj));
                }
                else if (t == typeof(PointF))
                {
                    return(NSValue.FromPointF((PointF)obj));
                }
#endif
#if XAMCORE_2_0
                if (t == typeof(nint))
                {
                    return(NSNumber.FromNInt((nint)obj));
                }
                else if (t == typeof(nuint))
                {
                    return(NSNumber.FromNUInt((nuint)obj));
                }
                else if (t == typeof(nfloat))
                {
                    return(NSNumber.FromNFloat((nfloat)obj));
                }
                else if (t == typeof(CGSize))
                {
                    return(NSValue.FromCGSize((CGSize)obj));
                }
                else if (t == typeof(CGRect))
                {
                    return(NSValue.FromCGRect((CGRect)obj));
                }
                else if (t == typeof(CGPoint))
                {
                    return(NSValue.FromCGPoint((CGPoint)obj));
                }
#endif

#if !MONOMAC
                if (t == typeof(CGAffineTransform))
                {
                    return(NSValue.FromCGAffineTransform((CGAffineTransform)obj));
                }
                else if (t == typeof(UIEdgeInsets))
                {
                    return(NSValue.FromUIEdgeInsets((UIEdgeInsets)obj));
                }
#if !WATCH
                else if (t == typeof(CATransform3D))
                {
                    return(NSValue.FromCATransform3D((CATransform3D)obj));
                }
#endif
#endif
                // last chance for types like CGPath, CGColor... that are not NSObject but are CFObject
                // see https://bugzilla.xamarin.com/show_bug.cgi?id=8458
                INativeObject native = (obj as INativeObject);
                if (native != null)
                {
                    return(Runtime.GetNSObject(native.Handle));
                }
                return(null);
            }
        }
Ejemplo n.º 6
0
 protected abstract bool DoSetProperty(NSString name, INativeObject value);
Ejemplo n.º 7
0
		protected override bool DoSetProperty (NSString name, INativeObject value)
		{
			return CFReadStreamSetProperty (Handle, name.Handle, value.Handle);
		}
Ejemplo n.º 8
0
		public void SetCFProperties (INativeObject properties)
		{
			ThrowIfDisposed ();
			var result = IORegistryEntrySetCFProperties (Handle, properties.Handle);
			ThrowIfError (result);
		}
Ejemplo n.º 9
0
 public void PostNotification(string notification, INativeObject objectToObserve, NSDictionary userInfo = null, bool deliverImmediately = false, bool postOnAllSessions = false)
 {
     var strHandle = NSString.CreateNative (notification);
     CFNotificationCenterPostNotificationWithOptions (
         center: handle,
         name: strHandle,
         obj: objectToObserve == null ? IntPtr.Zero : objectToObserve.Handle,
         userInfo: userInfo == null ? IntPtr.Zero : userInfo.Handle,
         options: (deliverImmediately ? 1 : 0) | (postOnAllSessions ? 2 : 0));
     NSString.ReleaseNative (strHandle);
 }
Ejemplo n.º 10
0
        public CFNotificationObserverToken AddObserver(string name, INativeObject objectToObserve, Action<string,NSDictionary> notificationHandler,
            CFNotificationSuspensionBehavior suspensionBehavior = CFNotificationSuspensionBehavior.DeliverImmediately)
        {
            if (darwinnc != null && darwinnc.Handle == Handle){
                if (name == null)
                    throw new ArgumentNullException ("name", "When using the Darwin Notification Center, the value passed must not be null");
            }

            var strHandle = name == null ? IntPtr.Zero : NSString.CreateNative (name);
            var token = new CFNotificationObserverToken () {
                stringName = name,
                centerHandle = handle,
                nameHandle = strHandle,
                observedObject = objectToObserve == null ? IntPtr.Zero : objectToObserve.Handle,
                listener = notificationHandler
            };

            //
            // To allow callbacks to add observers, we duplicate the list of listeners on AddObserver
            // We do the duplication on AddObserver, instead of making a copy on the notification
            // callback, as we expect the notification callback to be a more common operation
            // than the AddObserver operation
            //
            List<CFNotificationObserverToken> listenersForName;
            lock (listeners){
                if (!listeners.TryGetValue (name, out listenersForName)){
                    listenersForName = new List<CFNotificationObserverToken> (1);
                    CFNotificationCenterAddObserver (center: handle,
                                     observer: handle,
                                     callback: NotificationCallback,
                                     name: strHandle,
                                     obj: token.observedObject,
                                     suspensionBehavior: (IntPtr) suspensionBehavior);
                } else
                    listenersForName = new List<CFNotificationObserverToken> (listenersForName);
                listenersForName.Add (token);
                listeners [name] = listenersForName;
            }
            return token;
        }
Ejemplo n.º 11
0
 protected override bool DoSetProperty(NSString name, INativeObject value)
 {
     if (name == null)
         throw new ArgumentNullException ("name");
     return CFReadStreamSetProperty (Handle, name.Handle, value == null ? IntPtr.Zero : value.Handle);
 }
Ejemplo n.º 12
0
 public AttachableNativeObject(INativeObject obj)
 {
     nativeObj = obj;
 }
Ejemplo n.º 13
0
 public static CFDictionary FromObjectAndKey(INativeObject obj, INativeObject key)
 {
     return(new CFDictionary(CFDictionaryCreate(IntPtr.Zero, new IntPtr[] { key.Handle }, new IntPtr [] { obj.Handle }, 1, KeyCallbacks, ValueCallbacks), true));
 }
Ejemplo n.º 14
0
 public AttachableNativeObject(INativeObject obj)
 {
     nativeObj = obj;
 }
Ejemplo n.º 15
0
 internal static void SetNSAccessibilityElement(Atk.Object o, INativeObject native)
 {
     GtkWorkarounds.SetData(o, XamarinPrivateAtkCocoaNSAccessibilityKey, native.Handle);
 }
 protected void TryListenController(INativeObject item)
 {
     var viewControllerView = item.FindParent<IViewControllerView>();
     if (viewControllerView != null)
     {
         InitializeListener();
         viewControllerView.Mediator.DisposeHandler += _listener.Handle;
     }
 }
Ejemplo n.º 17
0
 protected ManagedObject(INativeObject nativeObject)
 {
     _nativeObject = nativeObject;
 }
Ejemplo n.º 18
0
		public void SetCFProperty (string name, INativeObject value)
		{
			ThrowIfDisposed ();
			var nameCFString = new CFString (name);
			var result = IOConnectSetCFProperty (Handle, nameCFString.Handle, value.Handle);
			ThrowIfError (result);
		}
Ejemplo n.º 19
0
		public void SetCFProperty (string propertyName, INativeObject properties)
		{
			ThrowIfDisposed ();
			var propertyNameAsCFString = new CFString (propertyName);
			var result = IORegistryEntrySetCFProperty (Handle, propertyNameAsCFString.Handle, properties.Handle);
			ThrowIfError (result);
		}
Ejemplo n.º 20
0
		public static AnimationElement TextColor (UILabel view, INativeObject to)
		{
			return TextColor (view, null, to);
		}
Ejemplo n.º 21
0
		public static CFDictionary FromObjectAndKey (INativeObject obj, INativeObject key)
		{
			return new CFDictionary (CFDictionaryCreate (IntPtr.Zero, new IntPtr[] { key.Handle }, new IntPtr [] { obj.Handle }, 1, KeyCallbacks, ValueCallbacks), true);
		}
Ejemplo n.º 22
0
		public static AnimationElement TintColor (UIButton view, INativeObject to)
		{
			return TintColor (view, null, to);
		}
Ejemplo n.º 23
0
 internal void SetProperty(NSString name, INativeObject value)
 {
     CheckHandle ();
     if (DoSetProperty (name, value))
         return;
     throw new InvalidOperationException (string.Format (
         "Cannot set property '{0}' on {1}.", name, GetType ().Name)
     );
 }
Ejemplo n.º 24
0
		public static AnimationElement TintColor (UIButton view, INativeObject from, INativeObject to)
		{
			return new AnimationElement {
				View = view,
				KeyPath = "tintColor",
				FromValue = from,
				ToValue = to
			};
		}
Ejemplo n.º 25
0
		//
		// It really should be ICFType, and we should pepper various classes with ICFType
		//
		public void Enqueue (INativeObject cftypeBuffer)
		{
			if (cftypeBuffer == null)
				throw new ArgumentNullException ("cftypeBuffer");
			lock (queueObjects){
				var cfh = cftypeBuffer.Handle;
				CMBufferQueueEnqueue (handle, cfh);
				if (!queueObjects.ContainsKey (cfh))
					queueObjects [cfh] = cftypeBuffer;
			}
		}
Ejemplo n.º 26
0
 public static void DisposeEx(this INativeObject nativeObject)
 {
     NativeObjectManager?.Dispose(nativeObject, null);
 }