Ejemplo n.º 1
0
 public static object GetAnimationBaseValue(INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
 {
     if (dp == null)
     {
         throw new ArgumentNullException("dp");
     }
     return(Value.ToObject(null, NativeMethods.dependency_object_get_animation_base_value(wrapper.NativeHandle, dp.Native)));
 }
Ejemplo n.º 2
0
 public static void ClearValue(INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
 {
     if (dp == null)
     {
         throw new ArgumentNullException("dp");
     }
     NativeMethods.dependency_object_clear_value(wrapper.NativeHandle, dp.Native, true);
 }
Ejemplo n.º 3
0
		public static object GetValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			object result = null;
			
			if (dp == null)
				throw new ArgumentNullException ("property");
			
			CheckNativeAndThread (wrapper);

			IntPtr val = NativeMethods.dependency_object_get_value (wrapper.NativeHandle, Deployment.Current.Types.TypeToKind (wrapper.GetType ()), dp.Native);
			return Value.ToObject (dp.PropertyType, val);
		}
Ejemplo n.º 4
0
        private static void CheckNativeAndThread(INativeDependencyObjectWrapper wrapper)
        {
            if (wrapper.NativeHandle == IntPtr.Zero)
            {
                throw new Exception(
                          string.Format("Uninitialized object: this object ({0}) has not set its native handle set", wrapper.GetType().FullName));
            }

            if (!wrapper.CheckAccess())
            {
                throw new UnauthorizedAccessException("Invalid access of Moonlight from an external thread");
            }
        }
Ejemplo n.º 5
0
        public static object GetValue(INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
        {
            if (dp == null)
            {
                throw new ArgumentNullException("property");
            }

            CheckNativeAndThread(wrapper);

            IntPtr val = Mono.NativeMethods.dependency_object_get_value(wrapper.NativeHandle, dp.Native);

            return(Value.ToObject(dp.PropertyType, val));
        }
Ejemplo n.º 6
0
        public static object ReadLocalValue(INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
        {
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            IntPtr val = NativeMethods.dependency_object_read_local_value(wrapper.NativeHandle, dp.Native);

            if (val == IntPtr.Zero)
            {
                return(DependencyProperty.UnsetValue);
            }
            else
            {
                // We can get a style or bindingexpression or something else here
                // so the Value* will not always be of type 'DP.PropertyType'.
                return(Value.ToObject(dp.PropertyType, val));
            }
        }
Ejemplo n.º 7
0
		public static void SetValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp, object value)
		{
			Type object_type;

			if (dp == null)
				throw new ArgumentNullException ("property");

			CheckNativeAndThread (wrapper);
			
			if (dp.DeclaringType != null && !dp.IsAttached) {
				if (!dp.DeclaringType.IsAssignableFrom (wrapper.GetType ()))
					throw new System.ArgumentException (string.Format ("The DependencyProperty '{2}', registered on type {0} can't be used to set a value on an object of type {1}", dp.DeclaringType.AssemblyQualifiedName, wrapper.GetType ().AssemblyQualifiedName, dp.Name));
			}
			
			if (value == null) {
				using (var val = new Value { k = NativeMethods.dependency_property_get_property_type(dp.Native), IsNull = true }) {
					var v = val;
					NativeMethods.dependency_object_set_value (wrapper.NativeHandle, dp.Native, ref v);
				}
				return;
			}

			if (value == DependencyProperty.UnsetValue) {
				// Setting to UnsetValue appears to be equivalent to ClearValue
				ClearValue (wrapper, dp);
				return;
			}

			// XXX we need this to work with all
			// INativeDependencyObjectWrapper, I expect..
			// but right now the only one other than DO is
			// Application, which doesn't have any
			// settable properties, so we're safe for now.
			if (wrapper is DependencyObject)
				dp.Validate ((DependencyObject)wrapper, dp, value);

			object_type = value.GetType ();

			bool type_valid = false;
			if (dp.PropertyType.IsGenericTypeDefinition) {
				Type t = object_type;
				while (t != null) {
					if (dp.PropertyType.IsAssignableFrom (t)) {
						type_valid = true;
						break;
					}

					if (t.IsGenericType && !t.IsGenericTypeDefinition)
						t = t.GetGenericTypeDefinition ();
					else
						t = t.BaseType;
				}
			}
			else {
				type_valid = dp.PropertyType.IsAssignableFrom (object_type);
			}

			if (!type_valid) {
				throw new ArgumentException (string.Format ("The DependencyProperty '{3}.{2}', whose property type is {0} can't be set to value whose type is {1}", dp.PropertyType.FullName, object_type.FullName, dp.Name, dp.DeclaringType.FullName));
			}
				                     
			using (var val = Value.FromObject (value, dp is CustomDependencyProperty)) {
				var v = val;
				NativeMethods.dependency_object_set_value (wrapper.NativeHandle, dp.Native, ref v);
			}
		}
Ejemplo n.º 8
0
		public static object GetValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			if (dp == null)
				throw new ArgumentNullException ("property");
			
			CheckNativeAndThread (wrapper);

			IntPtr val = Mono.NativeMethods.dependency_object_get_value (wrapper.NativeHandle, dp.Native);
			return Value.ToObject (dp.PropertyType, val);
		}
Ejemplo n.º 9
0
 public static bool CheckAccess(this INativeDependencyObjectWrapper native_do)
 {
     return(Thread.CurrentThread == DependencyObject.moonlight_thread);
 }
Ejemplo n.º 10
0
 public static void ClearValue(this INativeDependencyObjectWrapper native_do, DependencyProperty dp)
 {
     NativeDependencyObjectHelper.ClearValue(native_do, dp);
 }
Ejemplo n.º 11
0
 public static object GetAnimationBaseValue(this INativeDependencyObjectWrapper native_do, DependencyProperty dp)
 {
     return(NativeDependencyObjectHelper.GetAnimationBaseValue(native_do, dp));
 }
Ejemplo n.º 12
0
		public static void ClearValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			if (dp == null)
				throw new ArgumentNullException ("dp");
			NativeMethods.dependency_object_clear_value (wrapper.NativeHandle, dp.Native, true);
		}
Ejemplo n.º 13
0
        public static void SetValue(INativeDependencyObjectWrapper wrapper, DependencyProperty dp, object value)
        {
            Type object_type;

            if (dp == null)
            {
                throw new ArgumentNullException("property");
            }

            CheckNativeAndThread(wrapper);

            if (dp.DeclaringType != null && !dp.IsAttached)
            {
                if (!dp.DeclaringType.IsAssignableFrom(wrapper.GetType()))
                {
                    throw new System.ArgumentException(string.Format("The DependencyProperty '{2}', registered on type {0} can't be used to set a value on an object of type {1}", dp.DeclaringType.AssemblyQualifiedName, wrapper.GetType().AssemblyQualifiedName, dp.Name));
                }
            }

            if (value == null)
            {
                using (var val = new Value {
                    k = NativeMethods.dependency_property_get_property_type(dp.Native), IsNull = true
                }) {
                    var v = val;
                    NativeMethods.dependency_object_set_value(wrapper.NativeHandle, dp.Native, ref v);
                }
                return;
            }

            if (value == DependencyProperty.UnsetValue)
            {
                // Setting to UnsetValue appears to be equivalent to ClearValue
                ClearValue(wrapper, dp);
                return;
            }

            // XXX we need this to work with all
            // INativeDependencyObjectWrapper, I expect..
            // but right now the only one other than DO is
            // Application, which doesn't have any
            // settable properties, so we're safe for now.
            if (wrapper is DependencyObject)
            {
                dp.Validate((DependencyObject)wrapper, dp, value);
            }

            object_type = value.GetType();

            bool type_valid = false;

            if (dp.PropertyType.IsGenericTypeDefinition)
            {
                Type t = object_type;
                while (t != null)
                {
                    if (dp.PropertyType.IsAssignableFrom(t))
                    {
                        type_valid = true;
                        break;
                    }

                    if (t.IsGenericType && !t.IsGenericTypeDefinition)
                    {
                        t = t.GetGenericTypeDefinition();
                    }
                    else
                    {
                        t = t.BaseType;
                    }
                }
            }
            else
            {
                type_valid = dp.PropertyType.IsAssignableFrom(object_type);
            }

            if (!type_valid)
            {
                throw new ArgumentException(string.Format("The DependencyProperty '{3}.{2}', whose property type is {0} can't be set to value whose type is {1}", dp.PropertyType.FullName, object_type.FullName, dp.Name, dp.DeclaringType.FullName));
            }

            using (var val = Value.FromObject(value, dp is CustomDependencyProperty)) {
                var v = val;
                NativeMethods.dependency_object_set_value(wrapper.NativeHandle, dp.Native, ref v);
            }
        }
Ejemplo n.º 14
0
		public static object ReadLocalValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			if (dp == null)
				throw new ArgumentNullException ("dp");

			IntPtr val = NativeMethods.dependency_object_read_local_value (wrapper.NativeHandle, dp.Native);
			if (val == IntPtr.Zero) {
				return DependencyProperty.UnsetValue;
			} else {
				// We can get a style or bindingexpression or something else here
				// so the Value* will not always be of type 'DP.PropertyType'.
				return Value.ToObject (dp.PropertyType, val);
			}
		}
Ejemplo n.º 15
0
 public static void SetValue(this INativeDependencyObjectWrapper native_do, DependencyProperty dp, object value)
 {
     NativeDependencyObjectHelper.SetValue(native_do, dp, value);
 }
Ejemplo n.º 16
0
		public static object GetAnimationBaseValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			if (dp == null)
				throw new ArgumentNullException ("dp");
			return Value.ToObject (null, NativeMethods.dependency_object_get_animation_base_value (wrapper.NativeHandle, dp.Native));
		}
Ejemplo n.º 17
0
 public static object ReadLocalValue(this INativeDependencyObjectWrapper native_do, DependencyProperty dp)
 {
     return(NativeDependencyObjectHelper.ReadLocalValue(native_do, dp));
 }
Ejemplo n.º 18
0
		private static void CheckNativeAndThread (INativeDependencyObjectWrapper wrapper)
		{
			if (wrapper.NativeHandle == IntPtr.Zero) {
				throw new Exception (
					string.Format ("Uninitialized object: this object ({0}) has not set its native handle set", wrapper.GetType ().FullName));
			}

			if (!wrapper.CheckAccess ())
				throw new UnauthorizedAccessException ("Invalid access of Moonlight from an external thread");
		}
Ejemplo n.º 19
0
		public static object GetAnimationBaseValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp)
		{
			throw new NotImplementedException ();
		}