/// <summary>
        /// Returns true if this type converter can convert to the given type.
        /// </summary>
        /// <returns>
        /// bool - True if this converter can convert to the provided type, false if not.
        /// </returns>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="destinationType"> The Type being queried for support. </param>
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                // When invoked by the serialization engine we can convert to string only for some instances
                if (context != null && context.Instance != null)
                {
                    if (!(context.Instance is PathFigureCollection))
                    {
                        throw new ArgumentException(SR.Get(SRID.General_Expected_Type, "PathFigureCollection"), "context");
                    }

                    PathFigureCollection value = (PathFigureCollection)context.Instance;

                    #pragma warning suppress 6506 // value is obviously not null
                    return(value.CanSerializeToString());
                }

                return(true);
            }

            return(base.CanConvertTo(context, destinationType));
        }
Beispiel #2
0
        /// <summary>
        ///     Unlocks the D3DImage
        ///
        ///     Can only be called while locked.
        ///
        ///     If you have dirtied the image with AddDirtyRect, Unlocking will trigger us to
        ///     copy the dirty regions from the back buffer to the front buffer. While this is
        ///     taking place, Lock will block. To avoid locking indefinitely, use TryLock.
        /// </summary>
        public void Unlock()
        {
            WritePreamble();

            if (_lockCount == 0)
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_MustBeLocked));
            }

            --_lockCount;

            if (_isDirty && _lockCount == 0)
            {
                SubscribeToCommittingBatch();
            }

            if (_isChangePending)
            {
                _isChangePending = false;

                WritePostscript();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();

            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return(new PathFigure());
            }
            else if (count == 1)
            {
                return(flattenedGeometry.Figures[0]);
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }
Beispiel #4
0
        /// <summary>
        ///     DPI constructor
        /// </summary>
        public D3DImage(double dpiX, double dpiY)
        {
            SecurityHelper.DemandUnmanagedCode();

            if (dpiX < 0)
            {
                throw new ArgumentOutOfRangeException("dpiX", SR.Get(SRID.ParameterMustBeGreaterThanZero));
            }

            if (dpiY < 0)
            {
                throw new ArgumentOutOfRangeException("dpiY", SR.Get(SRID.ParameterMustBeGreaterThanZero));
            }

            _canWriteEvent       = new ManualResetEvent(true);
            _availableCallback   = Callback;
            _sendPresentDelegate = SendPresent;
            _dpiX = dpiX;
            _dpiY = dpiY;

            _listener = new WeakReference(this);
            AppDomainShutdownMonitor.Add(_listener);
        }
Beispiel #5
0
        void ICollection.CopyTo(Array array, int index)
        {
            VerifyAPIReadOnly();

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

            // The extra "index >= array.Length" check in because even if _collection.Count
            // is 0 the index is not allowed to be equal or greater than the length
            // (from the MSDN ICollection docs)
            if (index < 0 || index >= array.Length || (index + _collection.Count) > array.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (array.Rank != 1)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_BadRank));
            }

            // Elsewhere in the collection we throw an AE when the type is
            // bad so we do it here as well to be consistent
            try
            {
                int count = _collection.Count;
                for (int i = 0; i < count; i++)
                {
                    array.SetValue(_collection[i], index + i);
                }
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_BadDestArray, "Visual3DCollection"), e);
            }
        }
Beispiel #6
0
        void ICollection.CopyTo(Array array, int index)
        {
            ReadPreamble();

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

            // This will not throw in the case that we are copying
            // from an empty collection.  This is consistent with the
            // BCL Collection implementations. (Windows 1587365)
            if (index < 0 || (index + _collection.Count) > array.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (array.Rank != 1)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_BadRank));
            }

            // Elsewhere in the collection we throw an AE when the type is
            // bad so we do it here as well to be consistent
            try
            {
                int count = _collection.Count;
                for (int i = 0; i < count; i++)
                {
                    array.SetValue(_collection[i], index + i);
                }
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_BadDestArray, this.GetType().Name), e);
            }
        }
Beispiel #7
0
        /// <summary>
        /// DisconnectChild
        ///
        ///    This method is called to remove the 2D visual child of the Viewport2DVisual3D
        ///
        /// </summary>
        private void RemoveVisualChild(Visual child)
        {
            if (child == null || child._parent == null)
            {
                return;
            }

            if (child._parent != this)
            {
                throw new ArgumentException(SR.Get(SRID.Visual_NotChild));
            }

            // NOTE: We'll let the VisualBrush handle final cleanup from the channel
            //

            child._parent = null;

            // NOTE: We also let the VisualBrush handle any flag propagation issues (so Visual(3D).RemoveVisualChild for
            //       the things they propagate) as well as layout.

            // Fire notifications
            child.FireOnVisualParentChanged(this);
            OnVisualChildrenChanged(null /* no child added */, child);
        }
Beispiel #8
0
        /// <summary>
        /// AttachChild
        ///
        ///    This method is called to add a 2D Visual child to the Viewport2DVisual3D
        ///
        /// </summary>
        private void AddVisualChild(Visual child)
        {
            if (child == null)
            {
                return;
            }

            if (child._parent != null)
            {
                throw new ArgumentException(SR.Get(SRID.Visual_HasParent));
            }

            // Set the parent pointer.

            child._parent = this;

            // NOTE: Since the 2D object is on a VisualBrush, it will allow it to handle
            // the dirtyness of the 2D object, realization information, as well as layout.  See
            // Visual(3D).AddVisualChild for the things they propagate on adding a new child

            // Fire notifications
            this.OnVisualChildrenChanged(child, null /* no removed child */);
            child.FireOnVisualParentChanged(null);
        }
Beispiel #9
0
        private static bool UnsafeStartComposition(TextComposition composition)
        {
            if (composition == null)
            {
                throw new ArgumentNullException("composition");
            }

            if (composition._InputManager == null)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_NoInputManager, "composition"));
            }

            if (composition.Stage != TextCompositionStage.None)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_TextCompositionHasStarted, "composition"));
            }

            composition.Stage = TextCompositionStage.Started;
            TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition);

            textargs.RoutedEvent = TextCompositionManager.PreviewTextInputStartEvent;
            textargs.Source      = composition.Source;
            return(composition._InputManager.ProcessInput(textargs));
        }
        public void CopyTo(KeyValuePair <XmlLanguage, string>[] array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (index >= array.Length)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, "index", "array"));
            }

            if (_innerDictionary.Count > array.Length - index)
            {
                throw new ArgumentException(SR.Get(SRID.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, "array"));
            }

            _innerDictionary.CopyTo(array, index);
        }
Beispiel #11
0
        /////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     [TBS]
        /// </summary>
        /// <param name="report">[TBS]</param>
        /// <param name="tabletToElementTransform">[TBS]</param>
        /// <param name="targetPlugInCollection">[TBS]</param>
        internal RawStylusInput(
            RawStylusInputReport report,
            GeneralTransform tabletToElementTransform,
            StylusPlugInCollection targetPlugInCollection)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }
            if (tabletToElementTransform.Inverse == null)
            {
                throw new ArgumentException(SR.Get(SRID.Stylus_MatrixNotInvertable), "tabletToElementTransform");
            }
            if (targetPlugInCollection == null)
            {
                throw new ArgumentNullException("targetPlugInCollection");
            }

            // We should always see this GeneralTransform is frozen since we access this from multiple threads.
            System.Diagnostics.Debug.Assert(tabletToElementTransform.IsFrozen);
            _report = report;
            _tabletToElementTransform = tabletToElementTransform;
            _targetPlugInCollection   = targetPlugInCollection;
        }
Beispiel #12
0
        private void LoadFromStream(Stream cursorStream)
        {
            if (MS.Internal.CoreAppContextSwitches.AllowExternalProcessToBlockAccessToTemporaryFiles)
            {
                LegacyLoadFromStream(cursorStream);
                return;
            }

            string filePath = null;

            try
            {
                // Generate a temporary file based on the memory stream.
                using (FileStream fileStream = FileHelper.CreateAndOpenTemporaryFile(out filePath))
                {
                    cursorStream.CopyTo(fileStream);
                }

                // create a cursor from the temp file
                _cursorHandle = UnsafeNativeMethods.LoadImageCursor(IntPtr.Zero,
                                                                    filePath,
                                                                    NativeMethods.IMAGE_CURSOR,
                                                                    0, 0,
                                                                    NativeMethods.LR_DEFAULTCOLOR |
                                                                    NativeMethods.LR_LOADFROMFILE |
                                                                    (_scaleWithDpi? NativeMethods.LR_DEFAULTSIZE : 0x0000));
                if (_cursorHandle == null || _cursorHandle.IsInvalid)
                {
                    throw new ArgumentException(SR.Get(SRID.Cursor_InvalidStream));
                }
            }
            finally
            {
                FileHelper.DeleteTemporaryFile(filePath);
            }
        }
Beispiel #13
0
        ///<summary>
        /// FromAValues - general constructor for multichannel color values with explicit alpha channel and color context, i.e. spectral colors
        ///</summary>
        public static Color FromAValues(float a, float[] values, Uri profileUri)
        {
            Color c1 = Color.FromProfile(profileUri);

            if (values == null)
            {
                throw new ArgumentException(SR.Get(SRID.Color_DimensionMismatch, null));
            }

            if (values.GetLength(0) != c1.nativeColorValue.GetLength(0))
            {
                throw new ArgumentException(SR.Get(SRID.Color_DimensionMismatch, null));
            }

            for (int numChannels = 0; numChannels < values.GetLength(0); numChannels++)
            {
                c1.nativeColorValue[numChannels] = values[numChannels];
            }
            c1.ComputeScRgbValues();
            c1.scRgbColor.a = a;
            if (a < 0.0f)
            {
                a = 0.0f;
            }
            else if (a > 1.0f)
            {
                a = 1.0f;
            }

            c1.sRgbColor.a = (byte)((a * 255.0f) + 0.5f);
            c1.sRgbColor.r = ScRgbTosRgb(c1.scRgbColor.r);
            c1.sRgbColor.g = ScRgbTosRgb(c1.scRgbColor.g);
            c1.sRgbColor.b = ScRgbTosRgb(c1.scRgbColor.b);

            return(c1);
        }
Beispiel #14
0
        protected void Activate()
        {
            if (_isActive)
            {
                throw new InvalidOperationException(SR.Get(SRID.Touch_DeviceAlreadyActivated));
            }

            PromotingToManipulation = false;
            AddActiveDevice(this);
            AttachTouchDevice();
            Synchronize();

            if (_activeDevices.Count == 1)
            {
                _isPrimary = true;
            }

            _isActive = true;

            if (Activated != null)
            {
                Activated(this, EventArgs.Empty);
            }
        }
Beispiel #15
0
        internal static ApplicationGesture[] GetApplicationGestureArrayAndVerify(IEnumerable <ApplicationGesture> applicationGestures)
        {
            if (applicationGestures == null)
            {
                // Null is not allowed as the argument value
                throw new ArgumentNullException("applicationGestures");
            }

            uint count = 0;
            //we need to make a disconnected copy
            ICollection <ApplicationGesture> collection = applicationGestures as ICollection <ApplicationGesture>;

            if (collection != null)
            {
                count = (uint)collection.Count;
            }
            else
            {
                foreach (ApplicationGesture gesture in applicationGestures)
                {
                    count++;
                }
            }

            // Cannot be empty
            if (count == 0)
            {
                // An empty array is not allowed.
                throw new ArgumentException(SR.Get(SRID.ApplicationGestureArrayLengthIsZero), "applicationGestures");
            }

            bool foundAllGestures = false;
            List <ApplicationGesture> gestures = new List <ApplicationGesture>();

            foreach (ApplicationGesture gesture in applicationGestures)
            {
                if (!ApplicationGestureHelper.IsDefined(gesture))
                {
                    throw new ArgumentException(SR.Get(SRID.ApplicationGestureIsInvalid), "applicationGestures");
                }

                //check for allgestures
                if (gesture == ApplicationGesture.AllGestures)
                {
                    foundAllGestures = true;
                }

                //check for dupes
                if (gestures.Contains(gesture))
                {
                    throw new ArgumentException(SR.Get(SRID.DuplicateApplicationGestureFound), "applicationGestures");
                }

                gestures.Add(gesture);
            }

            // AllGesture cannot be specified with other gestures
            if (foundAllGestures && gestures.Count != 1)
            {
                // no dupes allowed
                throw new ArgumentException(SR.Get(SRID.AllGesturesMustExistAlone), "applicationGestures");
            }

            return(gestures.ToArray());
        }
Beispiel #16
0
        private void LegacyLoadFromStream(Stream cursorStream)
        {
            //Generate a temporal file based on the memory stream.

            // GetTempFileName requires unrestricted Environment permission
            // FileIOPermission.Write permission.  However, since we don't
            // know the path of the file to be created we have to give
            // unrestricted permission here.
            // GetTempFileName documentation does not mention that it throws
            // any exception. However, if it does, CLR reverts the assert.

            string filePath = Path.GetTempFileName();

            try
            {
                using (BinaryReader reader = new BinaryReader(cursorStream))
                {
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Write, FileShare.None))
                    {
                        // Read the bytes from the stream, up to BUFFERSIZE
                        byte[] cursorData = reader.ReadBytes(BUFFERSIZE);
                        int    dataSize;

                        // If the buffer is filled up, then write those bytes out and read more bytes up to BUFFERSIZE
                        for (dataSize = cursorData.Length;
                             dataSize >= BUFFERSIZE;
                             dataSize = reader.Read(cursorData, 0 /*index in array*/, BUFFERSIZE /*bytes to read*/))
                        {
                            fileStream.Write(cursorData, 0 /*index in array*/, BUFFERSIZE /*bytes to write*/);
                        }

                        // Write any remaining bytes
                        fileStream.Write(cursorData, 0 /*index in array*/, dataSize /*bytes to write*/);
                    }
                }

                // This method is called with File Write permission still asserted.
                // However, this method just reads this file into an icon.
                _cursorHandle = UnsafeNativeMethods.LoadImageCursor(IntPtr.Zero,
                                                                    filePath,
                                                                    NativeMethods.IMAGE_CURSOR,
                                                                    0, 0,
                                                                    NativeMethods.LR_DEFAULTCOLOR |
                                                                    NativeMethods.LR_LOADFROMFILE |
                                                                    (_scaleWithDpi? NativeMethods.LR_DEFAULTSIZE : 0x0000));
                if (_cursorHandle == null || _cursorHandle.IsInvalid)
                {
                    throw new ArgumentException(SR.Get(SRID.Cursor_InvalidStream));
                }
            }
            finally
            {
                try
                {
                    File.Delete(filePath);
                }
                catch (System.IO.IOException)
                {
                    //  We may not be able to delete the file if it's being used by some other process (e.g. Anti-virus check).
                    // There's nothing we can do in that case, so just eat the exception and leave the file behind
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Subtract operator - substracts each channel of the second color from each channel of the
        /// first and returns the result
        /// </summary>
        /// <param name='color1'>The minuend</param>
        /// <param name='color2'>The subtrahend</param>
        /// <returns>Returns the unclamped differnce</returns>
        public static Color operator -(Color color1, Color color2)
        {
            if (color1.context == null && color2.context == null)
            {
                Color c1 = FromScRgb(
                    color1.scRgbColor.a - color2.scRgbColor.a,
                    color1.scRgbColor.r - color2.scRgbColor.r,
                    color1.scRgbColor.g - color2.scRgbColor.g,
                    color1.scRgbColor.b - color2.scRgbColor.b
                    );
                return(c1);
            }
            else if (color1.context == null || color2.context == null)
            {
                throw new ArgumentException(SR.Get(SRID.Color_ColorContextTypeMismatch, null));
            }
            else if (color1.context == color2.context)
            {
                Color c1 = new Color();
                c1.context = color1.context;

                #pragma warning suppress 6506 // c1.context is obviously not null - both color1.context AND color2.context are not null
                c1.nativeColorValue = new float[c1.context.NumChannels];
                for (int i = 0; i < c1.nativeColorValue.GetLength(0); i++)
                {
                    c1.nativeColorValue[i] = color1.nativeColorValue[i] - color2.nativeColorValue[i];
                }

                Color c2 = Color.FromRgb(0, 0, 0);

                c2.context = new ColorContext(PixelFormats.Bgra32);

                ColorTransform colorTransform = new ColorTransform(c1.context, c2.context);
                float[]        sRGBValue      = new float[3];

                colorTransform.Translate(c1.nativeColorValue, sRGBValue);

                if (sRGBValue[0] < 0.0f)
                {
                    c1.sRgbColor.r = 0;
                }
                else if (sRGBValue[0] > 1.0f)
                {
                    c1.sRgbColor.r = 255;
                }
                else
                {
                    c1.sRgbColor.r = (byte)((sRGBValue[0] * 255.0f) + 0.5f);
                }

                if (sRGBValue[1] < 0.0f)
                {
                    c1.sRgbColor.g = 0;
                }
                else if (sRGBValue[1] > 1.0f)
                {
                    c1.sRgbColor.g = 255;
                }
                else
                {
                    c1.sRgbColor.g = (byte)((sRGBValue[1] * 255.0f) + 0.5f);
                }

                if (sRGBValue[2] < 0.0f)
                {
                    c1.sRgbColor.b = 0;
                }
                else if (sRGBValue[2] > 1.0f)
                {
                    c1.sRgbColor.b = 255;
                }
                else
                {
                    c1.sRgbColor.b = (byte)((sRGBValue[2] * 255.0f) + 0.5f);
                }

                c1.scRgbColor.r = sRgbToScRgb(c1.sRgbColor.r);
                c1.scRgbColor.g = sRgbToScRgb(c1.sRgbColor.g);
                c1.scRgbColor.b = sRgbToScRgb(c1.sRgbColor.b);
                c1.scRgbColor.a = color1.scRgbColor.a - color2.scRgbColor.a;
                if (c1.scRgbColor.a < 0.0f)
                {
                    c1.scRgbColor.a = 0.0f;
                    c1.sRgbColor.a  = 0;
                }
                else if (c1.scRgbColor.a > 1.0f)
                {
                    c1.scRgbColor.a = 1.0f;
                    c1.sRgbColor.a  = 255;
                }
                else
                {
                    c1.sRgbColor.a = (byte)((c1.scRgbColor.a * 255.0f) + 0.5f);
                }

                return(c1);
            }
            else
            {
                throw new ArgumentException(SR.Get(SRID.Color_ColorContextTypeMismatch, null));
            }
        }
        internal TextFormatterContext AcquireContext(
            object owner,
            IntPtr ploc
            )
        {
            Invariant.Assert(owner != null);

            TextFormatterContext context = null;

            int c;
            int contextCount = _contextList.Count;

            for (c = 0; c < contextCount; c++)
            {
                context = (TextFormatterContext)_contextList[c];

                if (ploc == IntPtr.Zero)
                {
                    if (context.Owner == null)
                    {
                        break;
                    }
                }
                else if (ploc == context.Ploc.Value)
                {
                    // LS requires that we use the exact same context for line
                    // destruction or hittesting (part of the reason is that LS
                    // actually caches some run info in the context). So here
                    // we use the actual PLSC as the context signature so we
                    // locate the one we want.

                    Debug.Assert(context.Owner == null);
                    break;
                }
            }

            if (c == contextCount)
            {
                if (contextCount == 0 || !_multipleContextProhibited)
                {
                    //  no free one exists, create a new one
                    context = new TextFormatterContext();
                    _contextList.Add(context);
                }
                else
                {
                    // This instance of TextFormatter only allows a single context, reentering the
                    // same TextFormatter in this case is not allowed.
                    //
                    // This requirement is currently enforced only during optimal break computation.
                    // Client implementing nesting of optimal break content inside another must create
                    // a separate TextFormatter instance for each content in different nesting level.
                    throw new InvalidOperationException(SR.Get(SRID.TextFormatterReentranceProhibited));
                }
            }

            Debug.Assert(context != null);

            context.Owner = owner;
            return(context);
        }
        /// <summary>
        /// Verify all text formatting arguments
        /// </summary>
        private void VerifyTextFormattingArguments(
            TextSource textSource,
            int firstCharIndex,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            TextRunCache textRunCache
            )
        {
            if (textSource == null)
            {
                throw new ArgumentNullException("textSource");
            }

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

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

            if (paragraphProperties.DefaultTextRunProperties == null)
            {
                throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties");
            }

            if (paragraphProperties.DefaultTextRunProperties.Typeface == null)
            {
                throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties.Typeface");
            }

            if (DoubleUtil.IsNaN(paragraphWidth))
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterValueCannotBeNaN));
            }

            if (double.IsInfinity(paragraphWidth))
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterValueCannotBeInfinity));
            }

            if (paragraphWidth < 0 ||
                paragraphWidth > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterMustBeBetween, 0, Constants.RealInfiniteWidth));
            }

            double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;

            if (paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize < 0 ||
                paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize > realMaxFontRenderingEmSize)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize", SR.Get(SRID.ParameterMustBeBetween, 0, realMaxFontRenderingEmSize));
            }

            if (paragraphProperties.Indent > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.Indent", SR.Get(SRID.ParameterCannotBeGreaterThan, Constants.RealInfiniteWidth));
            }

            if (paragraphProperties.LineHeight > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.LineHeight", SR.Get(SRID.ParameterCannotBeGreaterThan, Constants.RealInfiniteWidth));
            }

            if (paragraphProperties.DefaultIncrementalTab < 0 ||
                paragraphProperties.DefaultIncrementalTab > Constants.RealInfiniteWidth)
            {
                throw new ArgumentOutOfRangeException("paragraphProperties.DefaultIncrementalTab", SR.Get(SRID.ParameterMustBeBetween, 0, Constants.RealInfiniteWidth));
            }
        }
Beispiel #20
0
        public void SetBackBuffer(D3DResourceType backBufferType, IntPtr backBuffer, bool enableSoftwareFallback)
        {
            SecurityHelper.DemandUnmanagedCode();

            WritePreamble();
            
            if (_lockCount == 0)
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_MustBeLocked));
            }

            // In case the user passed in something like "(D3DResourceType)-1"
            if (backBufferType != D3DResourceType.IDirect3DSurface9)
            {
                throw new ArgumentOutOfRangeException("backBufferType");
            }

            // Early-out if the current back buffer equals the new one. If the front buffer
            // is not available and software fallback is not enabled, _pUserSurfaceUnsafe 
            // will be null and this check will fail. We don't want a null backBuffer to 
            // early-out when the front buffer isn't available.
            if (backBuffer != IntPtr.Zero && backBuffer == _pUserSurfaceUnsafe)
            {
                return;
            }
            
            SafeMILHandle newBitmap = null;
            uint newPixelWidth = 0;
            uint newPixelHeight = 0;

            // Create a new CInteropDeviceBitmap. Note that a null backBuffer will result 
            // in a null _pInteropDeviceBitmap at the end
            if (backBuffer != IntPtr.Zero)
            {
                HRESULT.Check(UnsafeNativeMethods.InteropDeviceBitmap.Create(
                    backBuffer,
                    _dpiX,
                    _dpiY,
                    ++_version,
                    _availableCallback,
                    enableSoftwareFallback,
                    out newBitmap,
                    out newPixelWidth,
                    out newPixelHeight
                    ));
            }

            //
            // We need to completely disassociate with the old interop bitmap if it
            // exists because it won't be deleted until the composition thread is done 
            // with it or until the garbage collector runs.
            //
            if (_pInteropDeviceBitmap != null)
            {
                // 1. Tell the old bitmap to stop sending front buffer messages because
                //    our new back buffer may be on a different adapter. Plus, tell the
                //    bitmap to release the back buffer in case the user wants to delete
                //    it immediately.
                UnsafeNativeMethods.InteropDeviceBitmap.Detach(_pInteropDeviceBitmap);

                // 2. If we were waiting for a present, unhook from commit
                UnsubscribeFromCommittingBatch();
                
                // 3. We are no longer dirty
                _isDirty = false;

                // Note: We don't need to do anything to the event because we're under
                //       the protection of Lock
            }

            // If anything about the new surface were unacceptible, we would have recieved
            // a bad HRESULT from Create() so everything must be good
            _pInteropDeviceBitmap = newBitmap;
            _pUserSurfaceUnsafe = backBuffer;
            _pixelWidth = newPixelWidth;
            _pixelHeight = newPixelHeight;
            _isSoftwareFallbackEnabled = enableSoftwareFallback;

            // AddDirtyRect is usually what triggers Changed, but AddDirtyRect isn't allowed with
            // no back buffer so we mark for Changed here
            if (_pInteropDeviceBitmap == null)
            {
                _isChangePending = true;
            }

            RegisterForAsyncUpdateResource();
            _waitingForUpdateResourceBecauseBitmapChanged = true;

            // WritePostscript will happen at Unlock
        }
Beispiel #21
0
        internal static object Invoke(AutomationPeer peer, DispatcherOperationCallback work, object arg)
        {
            Dispatcher dispatcher = peer.Dispatcher;

            // Null dispatcher likely means the visual is in bad shape!
            if (dispatcher == null)
            {
                throw new ElementNotAvailableException();
            }

            Exception remoteException = null;
            bool      completed       = false;

            object retVal = dispatcher.Invoke(
                DispatcherPriority.Send,
                TimeSpan.FromMinutes(3),
                (DispatcherOperationCallback) delegate(object unused)
            {
                try
                {
                    return(work(arg));
                }
                catch (Exception e)
                {
                    remoteException = e;
                    return(null);
                }
                catch            //for non-CLS Compliant exceptions
                {
                    remoteException = null;
                    return(null);
                }
                finally
                {
                    completed = true;
                }
            },
                null);

            if (completed)
            {
                if (remoteException != null)
                {
                    throw remoteException;
                }
            }
            else
            {
                bool dispatcherInShutdown = dispatcher.HasShutdownStarted;

                if (dispatcherInShutdown)
                {
                    throw new InvalidOperationException(SR.Get(SRID.AutomationDispatcherShutdown));
                }
                else
                {
                    throw new TimeoutException(SR.Get(SRID.AutomationTimeout));
                }
            }

            return(retVal);
        }
Beispiel #22
0
            internal unsafe void AddFigureToList(bool isFilled, bool isClosed, MilPoint2F *pPoints, UInt32 pointCount, byte *pSegTypes, UInt32 segmentCount)
            {
                if (pointCount >= 1 && segmentCount >= 1)
                {
                    PathFigure figure = new PathFigure();

                    figure.IsFilled   = isFilled;
                    figure.StartPoint = new Point(pPoints->X, pPoints->Y);

                    int pointIndex   = 1;
                    int sameSegCount = 0;

                    for (int segIndex = 0; segIndex < segmentCount; segIndex += sameSegCount)
                    {
                        byte segType = (byte)(pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegTypeMask);

                        sameSegCount = 1;

                        // Look for a run of same-type segments for a PolyXXXSegment.
                        while (((segIndex + sameSegCount) < segmentCount) &&
                               (pSegTypes[segIndex] == pSegTypes[segIndex + sameSegCount]))
                        {
                            sameSegCount++;
                        }

                        bool fStroked = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegIsAGap) == (byte)0;
                        bool fSmooth  = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegSmoothJoin) != (byte)0;

                        if (segType == (byte)MILCoreSegFlags.SegTypeLine)
                        {
                            if (pointIndex + sameSegCount > pointCount)
                            {
                                throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
                            }

                            if (sameSegCount > 1)
                            {
                                PointCollection ptCollection = new PointCollection();
                                for (int i = 0; i < sameSegCount; i++)
                                {
                                    ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y));
                                }
                                ptCollection.Freeze();

                                PolyLineSegment polySeg = new PolyLineSegment(ptCollection, fStroked, fSmooth);
                                polySeg.Freeze();

                                figure.Segments.Add(polySeg);
                            }
                            else
                            {
                                Debug.Assert(sameSegCount == 1);
                                figure.Segments.Add(new LineSegment(new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y), fStroked, fSmooth));
                            }

                            pointIndex += sameSegCount;
                        }
                        else if (segType == (byte)MILCoreSegFlags.SegTypeBezier)
                        {
                            int pointBezierCount = sameSegCount * 3;

                            if (pointIndex + pointBezierCount > pointCount)
                            {
                                throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
                            }

                            if (sameSegCount > 1)
                            {
                                PointCollection ptCollection = new PointCollection();
                                for (int i = 0; i < pointBezierCount; i++)
                                {
                                    ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y));
                                }
                                ptCollection.Freeze();

                                PolyBezierSegment polySeg = new PolyBezierSegment(ptCollection, fStroked, fSmooth);
                                polySeg.Freeze();

                                figure.Segments.Add(polySeg);
                            }
                            else
                            {
                                Debug.Assert(sameSegCount == 1);

                                figure.Segments.Add(new BezierSegment(
                                                        new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y),
                                                        new Point(pPoints[pointIndex + 1].X, pPoints[pointIndex + 1].Y),
                                                        new Point(pPoints[pointIndex + 2].X, pPoints[pointIndex + 2].Y),
                                                        fStroked,
                                                        fSmooth));
                            }

                            pointIndex += pointBezierCount;
                        }
                        else
                        {
                            throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
                        }
                    }

                    if (isClosed)
                    {
                        figure.IsClosed = true;
                    }

                    figure.Freeze();
                    Figures.Add(figure);

                    // Do not bother adding empty figures.
                }
            }
Beispiel #23
0
 /// <summary>
 ///     Viewport3DVisual does not yet support Geometry hit testing.
 /// </summary>
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     throw new NotSupportedException(SR.Get(SRID.HitTest_Invalid, typeof(GeometryHitTestParameters).Name, this.GetType().Name));
 }
Beispiel #24
0
        internal static IList <TextBreakpoint> CreateMultiple(
            TextParagraphCache paragraphCache,
            int firstCharIndex,
            int maxLineWidth,
            TextLineBreak previousLineBreak,
            IntPtr penaltyRestriction,
            out int bestFitIndex
            )
        {
            Invariant.Assert(paragraphCache != null);

            // grab full text state from paragraph cache
            FullTextState fullText = paragraphCache.FullText;

            Invariant.Assert(fullText != null);

            FormatSettings settings = fullText.TextStore.Settings;

            Invariant.Assert(settings != null);

            // update formatting parameters at line start
            settings.UpdateSettingsForCurrentLine(
                maxLineWidth,
                previousLineBreak,
                (firstCharIndex == fullText.TextStore.CpFirst)
                );

            Invariant.Assert(settings.Formatter != null);

            // acquiring LS context
            TextFormatterContext context = settings.Formatter.AcquireContext(fullText, IntPtr.Zero);

            IntPtr previousBreakRecord = IntPtr.Zero;

            if (settings.PreviousLineBreak != null)
            {
                previousBreakRecord = settings.PreviousLineBreak.BreakRecord.Value;
            }

            // need not consider marker as tab since marker does not affect line metrics and it wasnt drawn.
            fullText.SetTabs(context);

            LsBreaks lsbreaks = new LsBreaks();

            LsErr lserr = context.CreateBreaks(
                fullText.GetBreakpointInternalCp(firstCharIndex),
                previousBreakRecord,
                paragraphCache.Ploparabreak.Value,  // para breaking session
                penaltyRestriction,
                ref lsbreaks,
                out bestFitIndex
                );

            // get the exception in context before it is released
            Exception callbackException = context.CallbackException;

            // release the context
            context.Release();

            if (lserr != LsErr.None)
            {
                if (callbackException != null)
                {
                    // rethrow exception thrown in callbacks
                    throw callbackException;
                }
                else
                {
                    // throw with LS error codes
                    TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.CreateBreaksFailure, lserr), lserr);
                }
            }

            // keep context alive at least till here
            GC.KeepAlive(context);

            TextBreakpoint[] breakpoints = new TextBreakpoint[lsbreaks.cBreaks];

            for (int i = 0; i < lsbreaks.cBreaks; i++)
            {
                breakpoints[i] = new FullTextBreakpoint(
                    fullText,
                    firstCharIndex,
                    maxLineWidth,
                    ref lsbreaks,
                    i   // the current break
                    );
            }

            return(breakpoints);
        }
 protected virtual void AddText(string childText)
 {
     throw new InvalidOperationException(SR.Get(SRID.Animation_NoTextChildren));
 }
Beispiel #26
0
        /// <summary>
        /// Recognize the strokes.
        /// </summary>
        /// <param name="strokes"></param>
        /// <returns></returns>
        internal GestureRecognitionResult[] Recognize(StrokeCollection strokes)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("NativeRecognizer");
            }

            //
            // note that we validate this argument from GestureRecognizer
            // but since this is marked TAS, we want to do it here as well
            //
            if (strokes == null)
            {
                throw new ArgumentNullException("strokes"); // Null is not allowed as the argument value
            }
            if (strokes.Count > 2)
            {
                throw new ArgumentException(SR.Get(SRID.StrokeCollectionCountTooBig), "strokes");
            }

            // Create an empty result.
            GestureRecognitionResult[] recResults = new GestureRecognitionResult[] {};

            if (strokes.Count == 0)
            {
                return(recResults);
            }

            int hr = 0;

            try
            {
                // Reset the context
                hr = MS.Win32.Recognizer.UnsafeNativeMethods.ResetContext(_hContext);
                if (HRESULT.Failed(hr))
                {
                    //finally block will clean up and throw
                    return(recResults);
                }

                // Add strokes
                hr = AddStrokes(_hContext, strokes);
                if (HRESULT.Failed(hr))
                {
                    //AddStrokes's finally block will clean up this finally block will throw
                    return(recResults);
                }

                // recognize the ink
                bool bIncremental;
                hr = MS.Win32.Recognizer.UnsafeNativeMethods.Process(_hContext, out bIncremental);

                if (HRESULT.Succeeded(hr))
                {
                    if (s_GetAlternateListExists)
                    {
                        recResults = InvokeGetAlternateList();
                    }
                    else
                    {
                        recResults = InvokeGetLatticePtr();
                    }
                }
            }
            finally
            {
                // Check if we should report any error.
                if (HRESULT.Failed(hr))
                {
                    //don't throw a com exception here, we don't need to pass out any details
                    throw new InvalidOperationException(SR.Get(SRID.UnspecifiedGestureException));
                }
            }

            return(recResults);
        }
        private void Init()
        {
            if (_ploc.Value == System.IntPtr.Zero)
            {
                // Initializing context
                LsErr lserr = LsErr.None;

                LsContextInfo  contextInfo = new LsContextInfo();
                LscbkRedefined lscbkRedef  = new LscbkRedefined();

                _callbacks = new LineServicesCallbacks();
                _callbacks.PopulateContextInfo(ref contextInfo, ref lscbkRedef);


                contextInfo.version = 4;                // we should set this right, they might check it in the future
                contextInfo.pols    = IntPtr.Zero;      // This will be filled in the un-managed code
                contextInfo.cEstimatedCharsPerLine = TextStore.TypicalCharactersPerLine;
                contextInfo.fDontReleaseRuns       = 1; // dont waste time

                // There are 3 justification priorities right now with one considered good
                // and the other two provided for emergency expansion.
                // Future development to enable international justification will likely change this.
                // e.g. Kashida justification would require more than one good priorities.
                contextInfo.cJustPriorityLim = 3;

                // Fill up text configuration
                contextInfo.wchNull     = '\u0000';
                contextInfo.wchUndef    = '\u0001';
                contextInfo.wchTab      = '\u0009';
                contextInfo.wchPosTab   = contextInfo.wchUndef;
                contextInfo.wchEndPara1 = TextStore.CharParaSeparator;              // Unicode para separator
                contextInfo.wchEndPara2 = contextInfo.wchUndef;
                contextInfo.wchSpace    = '\u0020';

                contextInfo.wchHyphen             = MS.Internal.Text.TextInterface.TextAnalyzer.CharHyphen;   //'\x002d';
                contextInfo.wchNonReqHyphen       = '\u00AD';
                contextInfo.wchNonBreakHyphen     = '\u2011';
                contextInfo.wchEnDash             = '\u2013';
                contextInfo.wchEmDash             = '\u2014';
                contextInfo.wchEnSpace            = '\u2002';
                contextInfo.wchEmSpace            = '\u2003';
                contextInfo.wchNarrowSpace        = '\u2009';
                contextInfo.wchJoiner             = '\u200D';
                contextInfo.wchNonJoiner          = '\u200C';
                contextInfo.wchVisiNull           = '\u2050';
                contextInfo.wchVisiAltEndPara     = '\u2051';
                contextInfo.wchVisiEndLineInPara  = '\u2052';
                contextInfo.wchVisiEndPara        = '\u2053';
                contextInfo.wchVisiSpace          = '\u2054';
                contextInfo.wchVisiNonBreakSpace  = '\u2055';
                contextInfo.wchVisiNonBreakHyphen = '\u2056';
                contextInfo.wchVisiNonReqHyphen   = '\u2057';
                contextInfo.wchVisiTab            = '\u2058';
                contextInfo.wchVisiPosTab         = contextInfo.wchUndef;
                contextInfo.wchVisiEmSpace        = '\u2059';
                contextInfo.wchVisiEnSpace        = '\u205A';
                contextInfo.wchVisiNarrowSpace    = '\u205B';
                contextInfo.wchVisiOptBreak       = '\u205C';
                contextInfo.wchVisiNoBreak        = '\u205D';
                contextInfo.wchVisiFESpace        = '\u205E';
                contextInfo.wchFESpace            = '\u3000';
                contextInfo.wchEscAnmRun          = TextStore.CharParaSeparator;
                contextInfo.wchAltEndPara         = contextInfo.wchUndef;
                contextInfo.wchEndLineInPara      = TextStore.CharLineSeparator;
                contextInfo.wchSectionBreak       = contextInfo.wchUndef;
                contextInfo.wchNonBreakSpace      = '\u00A0';
                contextInfo.wchNoBreak            = contextInfo.wchUndef;
                contextInfo.wchColumnBreak        = contextInfo.wchUndef;
                contextInfo.wchPageBreak          = contextInfo.wchUndef;
                contextInfo.wchOptBreak           = contextInfo.wchUndef;
                contextInfo.wchToReplace          = contextInfo.wchUndef;
                contextInfo.wchReplace            = contextInfo.wchUndef;

                IntPtr ploc           = IntPtr.Zero;
                IntPtr ppenaltyModule = IntPtr.Zero;

                lserr = UnsafeNativeMethods.LoCreateContext(
                    ref contextInfo,
                    ref lscbkRedef,
                    out ploc
                    );

                if (lserr != LsErr.None)
                {
                    ThrowExceptionFromLsError(SR.Get(SRID.CreateContextFailure, lserr), lserr);
                }

                _ploc.Value = ploc;
                GC.KeepAlive(contextInfo);

                //  There is a trick here to pass in this resolution as in twips
                //  (1/1440 an inch).
                //
                //  LSCreateLine assumes the max width passed in is in twips so to
                //  allow its client to express their width in page unit. However
                //  it asks client to set up the real device resolution here so
                //  that it can internally translate the "twips" width into client
                //  actual device unit.
                //
                //  We are not device dependent anyway, so instead of following the
                //  rule which will cause us to validate the context every time. We
                //  choose to cheat LS to think that our unit is twips.
                //
                LsDevRes devRes;
                devRes.dxpInch = devRes.dxrInch = TwipsPerInch;
                devRes.dypInch = devRes.dyrInch = TwipsPerInch;

                SetDoc(
                    true,           // Yes, we will be displaying
                    true,           // Yes, reference and presentation are the same device
                    ref devRes      // Device resolutions
                    );

                SetBreaking(BreakStrategies.BreakCJK);
            }
        }
Beispiel #28
0
        private void OpenMedia(Uri source)
        {
            string toOpen = null;

            if (source != null && source.IsAbsoluteUri && source.Scheme == PackUriHelper.UriSchemePack)
            {
                try
                {
                    source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
                }
                catch (InvalidOperationException)
                {
                    source = null;
                    _mediaEventsHelper.RaiseMediaFailed(new System.NotSupportedException(SR.Get(SRID.Media_PackURIsAreNotSupported, null)));
                }
            }

            // Setting a null source effectively disconects the MediaElement.
            if (source != null)
            {
                // keep whether we asserted permissions or not
                bool elevated = false;

                // get the base directory of the application; never expose this
                Uri appBase = SecurityHelper.GetBaseDirectory(AppDomain.CurrentDomain);

                // this extracts the URI to open
                Uri uriToOpen = ResolveUri(source, appBase);

                // access is allowed in the following cases (only 1 & 2 require elevation):
                // 1) to any HTTPS media if app is NOT coming from HTTPS
                // 2) to URI in the current directory of the fusion cache
                // 3) to site of origin media
                if (SecurityHelper.AreStringTypesEqual(uriToOpen.Scheme, Uri.UriSchemeHttps))
                {
                    // target is HTTPS. Then, elevate ONLY if we are NOT coming from HTTPS (=XDomain HTTPS app to HTTPS media disallowed)
                    Uri appDeploymentUri = SecurityHelper.ExtractUriForClickOnceDeployedApp();
                    if (!SecurityHelper.AreStringTypesEqual(appDeploymentUri.Scheme, Uri.UriSchemeHttps))
                    {
                        new WebPermission(NetworkAccess.Connect, BindUriHelper.UriToString(uriToOpen)).Assert();
                        elevated = true;
                    }
                }
                else
                {
                    // elevate to allow access to media in the app's directory in the fusion cache.
                    new FileIOPermission(FileIOPermissionAccess.Read, appBase.LocalPath).Assert();// BlessedAssert
                    elevated = true;
                }

                // demand permissions. if demands succeds, it means we are in one of the cases above.
                try
                {
                    toOpen = DemandPermissions(uriToOpen);
                }
                finally
                {
                    if (elevated)
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            else
            {
                toOpen = null;
            }

            // We pass in exact same URI for which we demanded permissions so that we can be sure
            // there is no discrepancy between the two.
            HRESULT.Check(MILMedia.Open(_nativeMedia, toOpen));
        }
Beispiel #29
0
        /// <summary>
        /// Creates a TextEffectCollection with all of the same elements as collection
        /// </summary>
        public TextEffectCollection(IEnumerable <TextEffect> collection)
        {
            // The WritePreamble and WritePostscript aren't technically necessary
            // in the constructor as of 1/20/05 but they are put here in case
            // their behavior changes at a later date

            WritePreamble();

            if (collection != null)
            {
                bool needsItemValidation = true;
                ICollection <TextEffect> icollectionOfT = collection as ICollection <TextEffect>;

                if (icollectionOfT != null)
                {
                    _collection = new FrugalStructList <TextEffect>(icollectionOfT);
                }
                else
                {
                    ICollection icollection = collection as ICollection;

                    if (icollection != null) // an IC but not and IC<T>
                    {
                        _collection = new FrugalStructList <TextEffect>(icollection);
                    }
                    else // not a IC or IC<T> so fall back to the slower Add
                    {
                        _collection = new FrugalStructList <TextEffect>();

                        foreach (TextEffect item in collection)
                        {
                            if (item == null)
                            {
                                throw new System.ArgumentException(SR.Get(SRID.Collection_NoNull));
                            }
                            TextEffect newValue = item;
                            OnFreezablePropertyChanged(/* oldValue = */ null, newValue);
                            _collection.Add(newValue);
                        }

                        needsItemValidation = false;
                    }
                }

                if (needsItemValidation)
                {
                    foreach (TextEffect item in collection)
                    {
                        if (item == null)
                        {
                            throw new System.ArgumentException(SR.Get(SRID.Collection_NoNull));
                        }
                        OnFreezablePropertyChanged(/* oldValue = */ null, item);
                    }
                }


                WritePostscript();
            }
            else
            {
                throw new ArgumentNullException("collection");
            }
        }
Beispiel #30
0
        // NOTE:  The code here is highly similar to RemoveChildCore in ModelVisual3D,
        //        but slightly different because the parent is 2D here.
        void IVisual3DContainer.RemoveChild(Visual3D child)
        {
            int index = child.ParentIndex;

            // It is invalid to modify the children collection that we
            // might be iterating during a property invalidation tree walk.
            if (IsVisualChildrenIterationInProgress)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotModifyVisualChildrenDuringTreeWalk));
            }

            // invalid during a VisualTreeChanged event
            VisualDiagnostics.VerifyVisualTreeChange(this);

            Debug.Assert(child != null);
            Debug.Assert(child.InternalVisualParent == this);

            VisualDiagnostics.OnVisualChildChanged(this, child, false);

            child.SetParent(/* newParent = */ (Visual)null);   // CS0121: Call is ambigious without casting null to Visual.

            // remove the inheritance context
            if (_inheritanceContextForChildren != null)
            {
                _inheritanceContextForChildren.RemoveSelfAsInheritanceContext(child, null);
            }

            //
            // Remove the child on all channels this visual is marshalled to.
            //

            for (int i = 0, limit = _proxy3D.Count; i < limit; i++)
            {
                DUCE.Channel channel = _proxy3D.GetChannel(i);

                if (child.CheckFlagsAnd(channel, VisualProxyFlags.IsConnectedToParent))
                {
                    child.SetFlags(channel, false, VisualProxyFlags.IsConnectedToParent);
                    DUCE.IResource childResource = (DUCE.IResource)child;
                    childResource.RemoveChildFromParent(this, channel);
                    childResource.ReleaseOnChannel(channel);
                }
            }

            SetFlagsOnAllChannels(true, VisualProxyFlags.IsContentDirty);

            //
            // Force a full precompute and render pass for this visual.
            //

            Visual.PropagateFlags(
                this,
                VisualFlags.IsSubtreeDirtyForPrecompute,
                VisualProxyFlags.IsSubtreeDirtyForRender);

            //


            child.FireOnVisualParentChanged(this);

            OnVisualChildrenChanged(/* visualAdded = */ null, child);
        }