Pen.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Core / System / Windows / Media / Generated / Pen.cs / 2 / Pen.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// This file was generated, please do not edit it directly. 
// 
// Please see [....]/default.aspx/Microsoft.Projects.Avalon/MilCodeGen.html for more information.
// 
//---------------------------------------------------------------------------

using MS.Internal;
using MS.Internal.KnownBoxes; 
using MS.Internal.Collections;
using MS.Internal.PresentationCore; 
using MS.Utility; 
using System;
using System.Collections; 
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization; 
using System.Reflection;
using System.Runtime.InteropServices; 
using System.ComponentModel.Design.Serialization; 
using System.Text;
using System.Windows; 
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation; 
using System.Windows.Media.Composition;
using System.Windows.Media.Imaging; 
using System.Windows.Markup; 
using System.Windows.Media.Converters;
using System.Security; 
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
// These types are aliased to match the unamanaged names used in interop 
using BOOL = System.UInt32;
using WORD = System.UInt16; 
using Float = System.Single; 

namespace System.Windows.Media 
{


 
    sealed partial class Pen : Animatable, DUCE.IResource
    { 
        #region Constructors 

        //----------------------------------------------------- 
        //
        //  Constructors
        //
        //----------------------------------------------------- 

        static Pen() 
        { 
            // We check our static default fields which are of type Freezable
            // to make sure that they are not mutable, otherwise we will throw 
            // if these get touched by more than one thread in the lifetime
            // of your app.  (Windows OS Bug #947272)
            //
            Debug.Assert(s_DashStyle == null || s_DashStyle.IsFrozen, 
                "Detected context bound default value Pen.s_DashStyle (See OS Bug #947272).");
 
        } 

 

        #endregion Constructors

        //------------------------------------------------------ 
        //
        //  Public Methods 
        // 
        //-----------------------------------------------------
 
        #region Public Methods

        /// 
        ///     Shadows inherited Clone() with a strongly typed 
        ///     version for convenience.
        ///  
        public new Pen Clone() 
        {
            return (Pen)base.Clone(); 
        }

        /// 
        ///     Shadows inherited CloneCurrentValue() with a strongly typed 
        ///     version for convenience.
        ///  
        public new Pen CloneCurrentValue() 
        {
            return (Pen)base.CloneCurrentValue(); 
        }


 

        #endregion Public Methods 
 
        //------------------------------------------------------
        // 
        //  Public Properties
        //
        //------------------------------------------------------
 
        private static void BrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        { 
 

 
            if (e.IsASubPropertyChange)
            {
                return;
            } 

 
            Pen target = ((Pen) d); 

 
            Brush oldV = (Brush) e.OldValue;
            Brush newV = (Brush) e.NewValue;
            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;
 
            if (dispatcher != null)
            { 
                DUCE.IResource targetResource = (DUCE.IResource)target; 
                using (CompositionEngineLock.Acquire())
                { 
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    { 
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel); 
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull); 
                        target.ReleaseResource(oldV,channel);
                        target.AddRefResource(newV,channel); 
                    }
                }
            }
 
            target.PropertyChanged(BrushProperty);
        } 
        private static void ThicknessPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        {
            Pen target = ((Pen) d); 


            target.PropertyChanged(ThicknessProperty);
        } 
        private static void StartLineCapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        { 
            Pen target = ((Pen) d); 

 
            target.PropertyChanged(StartLineCapProperty);
        }
        private static void EndLineCapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        { 
            Pen target = ((Pen) d);
 
 
            target.PropertyChanged(EndLineCapProperty);
        } 
        private static void DashCapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Pen target = ((Pen) d);
 

            target.PropertyChanged(DashCapProperty); 
        } 
        private static void LineJoinPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        { 
            Pen target = ((Pen) d);


            target.PropertyChanged(LineJoinProperty); 
        }
        private static void MiterLimitPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        { 
            Pen target = ((Pen) d);
 

            target.PropertyChanged(MiterLimitProperty);
        }
        private static void DashStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        {
 
 

            if (e.IsASubPropertyChange) 
            {
                return;
            }
 

            Pen target = ((Pen) d); 
 

            DashStyle oldV = (DashStyle) e.OldValue; 
            DashStyle newV = (DashStyle) e.NewValue;
            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null) 
            {
                DUCE.IResource targetResource = (DUCE.IResource)target; 
                using (CompositionEngineLock.Acquire()) 
                {
                    int channelCount = targetResource.GetChannelCount(); 

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex); 
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull); 
                        target.ReleaseResource(oldV,channel); 
                        target.AddRefResource(newV,channel);
                    } 
                }
            }

            target.PropertyChanged(DashStyleProperty); 
        }
 
 
        #region Public Properties
 
        /// 
        ///     Brush - Brush.  Default value is null.
        /// 
        public Brush Brush 
        {
            get 
            { 
                return (Brush) GetValue(BrushProperty);
            } 
            set
            {
                SetValueInternal(BrushProperty, value);
            } 
        }
 
        ///  
        ///     Thickness - double.  Default value is 1.0.
        ///  
        public double Thickness
        {
            get
            { 
                return (double) GetValue(ThicknessProperty);
            } 
            set 
            {
                SetValueInternal(ThicknessProperty, value); 
            }
        }

        ///  
        ///     StartLineCap - PenLineCap.  Default value is PenLineCap.Flat.
        ///  
        public PenLineCap StartLineCap 
        {
            get 
            {
                return (PenLineCap) GetValue(StartLineCapProperty);
            }
            set 
            {
                SetValueInternal(StartLineCapProperty, value); 
            } 
        }
 
        /// 
        ///     EndLineCap - PenLineCap.  Default value is PenLineCap.Flat.
        /// 
        public PenLineCap EndLineCap 
        {
            get 
            { 
                return (PenLineCap) GetValue(EndLineCapProperty);
            } 
            set
            {
                SetValueInternal(EndLineCapProperty, value);
            } 
        }
 
        ///  
        ///     DashCap - PenLineCap.  Default value is PenLineCap.Square.
        ///  
        public PenLineCap DashCap
        {
            get
            { 
                return (PenLineCap) GetValue(DashCapProperty);
            } 
            set 
            {
                SetValueInternal(DashCapProperty, value); 
            }
        }

        ///  
        ///     LineJoin - PenLineJoin.  Default value is PenLineJoin.Miter.
        ///  
        public PenLineJoin LineJoin 
        {
            get 
            {
                return (PenLineJoin) GetValue(LineJoinProperty);
            }
            set 
            {
                SetValueInternal(LineJoinProperty, value); 
            } 
        }
 
        /// 
        ///     MiterLimit - double.  Default value is 10.0.
        /// 
        public double MiterLimit 
        {
            get 
            { 
                return (double) GetValue(MiterLimitProperty);
            } 
            set
            {
                SetValueInternal(MiterLimitProperty, value);
            } 
        }
 
        ///  
        ///     DashStyle - DashStyle.  Default value is DashStyles.Solid.
        ///  
        public DashStyle DashStyle
        {
            get
            { 
                return (DashStyle) GetValue(DashStyleProperty);
            } 
            set 
            {
                SetValueInternal(DashStyleProperty, value); 
            }
        }

        #endregion Public Properties 

        //----------------------------------------------------- 
        // 
        //  Protected Methods
        // 
        //------------------------------------------------------

        #region Protected Methods
 
        /// 
        /// Implementation of Freezable.CreateInstanceCore. 
        ///  
        /// The new Freezable.
        protected override Freezable CreateInstanceCore() 
        {
            return new Pen();
        }
 

 
        #endregion ProtectedMethods 

        //----------------------------------------------------- 
        //
        //  Internal Methods
        //
        //----------------------------------------------------- 

        #region Internal Methods 
 
        /// 
        ///     Critical: This code calls into an unsafe code block 
        ///     TreatAsSafe: This code does not return any critical data.It is ok to expose
        ///     Channels are safe to call into and do not go cross domain and cross process
        /// 
        [SecurityCritical,SecurityTreatAsSafe] 
        internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
        { 
            // If we're told we can skip the channel check, then we must be on channel 
            Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));
 
            if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
            {
                base.UpdateResource(channel, skipOnChannelCheck);
 
                // Read values of properties into local variables
                Brush vBrush = Brush; 
                DashStyle vDashStyle = DashStyle; 

                // Obtain handles for properties that implement DUCE.IResource 
                DUCE.ResourceHandle hBrush = vBrush != null ? ((DUCE.IResource)vBrush).GetHandle(channel) : DUCE.ResourceHandle.Null;
                DUCE.ResourceHandle hDashStyle = vDashStyle != null ? ((DUCE.IResource)vDashStyle).GetHandle(channel) : DUCE.ResourceHandle.Null;

                // Obtain handles for animated properties 
                DUCE.ResourceHandle hThicknessAnimations = GetAnimationResourceHandle(ThicknessProperty, channel);
 
                // Pack & send command packet 
                DUCE.MILCMD_PEN data;
                unsafe 
                {
                    data.Type = MILCMD.MilCmdPen;
                    data.Handle = _duceResource.GetHandle(channel);
                    data.hBrush = hBrush; 
                    if (hThicknessAnimations.IsNull)
                    { 
                        data.Thickness = Thickness; 
                    }
                    data.hThicknessAnimations = hThicknessAnimations; 
                    data.StartLineCap = StartLineCap;
                    data.EndLineCap = EndLineCap;
                    data.DashCap = DashCap;
                    data.LineJoin = LineJoin; 
                    data.MiterLimit = MiterLimit;
                    data.hDashStyle = hDashStyle; 
 
                    // Send packed command structure
                    channel.SendCommand( 
                        (byte*)&data,
                        sizeof(DUCE.MILCMD_PEN));
                }
            } 
        }
        DUCE.ResourceHandle DUCE.IResource.AddRefOnChannel(DUCE.Channel channel) 
        { 
            using (CompositionEngineLock.Acquire())
            { 
                if (_duceResource.CreateOrAddRefOnChannel(channel, System.Windows.Media.Composition.DUCE.ResourceType.TYPE_PEN))
                {
                    Brush vBrush = Brush;
                    if (vBrush != null) ((DUCE.IResource)vBrush).AddRefOnChannel(channel); 
                    DashStyle vDashStyle = DashStyle;
                    if (vDashStyle != null) ((DUCE.IResource)vDashStyle).AddRefOnChannel(channel); 
 
                    AddRefOnChannelAnimations(channel);
 

                    UpdateResource(channel, true /* skip "on channel" check - we already know that we're on channel */ );
                }
 
                return _duceResource.GetHandle(channel);
            } 
        } 
        void DUCE.IResource.ReleaseOnChannel(DUCE.Channel channel)
        { 
            using (CompositionEngineLock.Acquire())
            {
                Debug.Assert(_duceResource.IsOnChannel(channel));
 
                if (_duceResource.ReleaseOnChannel(channel))
                { 
                    Brush vBrush = Brush; 
                    if (vBrush != null) ((DUCE.IResource)vBrush).ReleaseOnChannel(channel);
                    DashStyle vDashStyle = DashStyle; 
                    if (vDashStyle != null) ((DUCE.IResource)vDashStyle).ReleaseOnChannel(channel);

                    ReleaseOnChannelAnimations(channel);
 
                }
            } 
        } 
        DUCE.ResourceHandle DUCE.IResource.GetHandle(DUCE.Channel channel)
        { 
            DUCE.ResourceHandle h;
            // Reconsider the need for this lock when removing the MultiChannelResource.
            using (CompositionEngineLock.Acquire())
            { 
                h = _duceResource.GetHandle(channel);
            } 
            return h; 
        }
        int DUCE.IResource.GetChannelCount() 
        {
            // must already be in composition lock here
            return _duceResource.GetChannelCount();
        } 
        DUCE.Channel DUCE.IResource.GetChannel(int index)
        { 
            // in a lock already 
            return _duceResource.GetChannel(index);
        } 


        #endregion Internal Methods
 
        //-----------------------------------------------------
        // 
        //  Internal Properties 
        //
        //------------------------------------------------------ 

        #region Internal Properties

 

 
 
        #endregion Internal Properties
 
        //-----------------------------------------------------
        //
        //  Dependency Properties
        // 
        //------------------------------------------------------
 
        #region Dependency Properties 

        ///  
        ///     The DependencyProperty for the Pen.Brush property.
        /// 
        public static readonly DependencyProperty BrushProperty
            = RegisterProperty("Brush", 
                               typeof(Brush),
                               typeof(Pen), 
                               null, 
                               new PropertyChangedCallback(BrushPropertyChanged),
                               null, 
                               /* isIndependentlyAnimated  = */ false,
                               /* coerceValueCallback */ null);
        /// 
        ///     The DependencyProperty for the Pen.Thickness property. 
        /// 
        public static readonly DependencyProperty ThicknessProperty 
            = RegisterProperty("Thickness", 
                               typeof(double),
                               typeof(Pen), 
                               1.0,
                               new PropertyChangedCallback(ThicknessPropertyChanged),
                               null,
                               /* isIndependentlyAnimated  = */ true, 
                               /* coerceValueCallback */ null);
        ///  
        ///     The DependencyProperty for the Pen.StartLineCap property. 
        /// 
        public static readonly DependencyProperty StartLineCapProperty 
            = RegisterProperty("StartLineCap",
                               typeof(PenLineCap),
                               typeof(Pen),
                               PenLineCap.Flat, 
                               new PropertyChangedCallback(StartLineCapPropertyChanged),
                               new ValidateValueCallback(System.Windows.Media.ValidateEnums.IsPenLineCapValid), 
                               /* isIndependentlyAnimated  = */ false, 
                               /* coerceValueCallback */ null);
        ///  
        ///     The DependencyProperty for the Pen.EndLineCap property.
        /// 
        public static readonly DependencyProperty EndLineCapProperty
            = RegisterProperty("EndLineCap", 
                               typeof(PenLineCap),
                               typeof(Pen), 
                               PenLineCap.Flat, 
                               new PropertyChangedCallback(EndLineCapPropertyChanged),
                               new ValidateValueCallback(System.Windows.Media.ValidateEnums.IsPenLineCapValid), 
                               /* isIndependentlyAnimated  = */ false,
                               /* coerceValueCallback */ null);
        /// 
        ///     The DependencyProperty for the Pen.DashCap property. 
        /// 
        public static readonly DependencyProperty DashCapProperty 
            = RegisterProperty("DashCap", 
                               typeof(PenLineCap),
                               typeof(Pen), 
                               PenLineCap.Square,
                               new PropertyChangedCallback(DashCapPropertyChanged),
                               new ValidateValueCallback(System.Windows.Media.ValidateEnums.IsPenLineCapValid),
                               /* isIndependentlyAnimated  = */ false, 
                               /* coerceValueCallback */ null);
        ///  
        ///     The DependencyProperty for the Pen.LineJoin property. 
        /// 
        public static readonly DependencyProperty LineJoinProperty 
            = RegisterProperty("LineJoin",
                               typeof(PenLineJoin),
                               typeof(Pen),
                               PenLineJoin.Miter, 
                               new PropertyChangedCallback(LineJoinPropertyChanged),
                               new ValidateValueCallback(System.Windows.Media.ValidateEnums.IsPenLineJoinValid), 
                               /* isIndependentlyAnimated  = */ false, 
                               /* coerceValueCallback */ null);
        ///  
        ///     The DependencyProperty for the Pen.MiterLimit property.
        /// 
        public static readonly DependencyProperty MiterLimitProperty
            = RegisterProperty("MiterLimit", 
                               typeof(double),
                               typeof(Pen), 
                               10.0, 
                               new PropertyChangedCallback(MiterLimitPropertyChanged),
                               null, 
                               /* isIndependentlyAnimated  = */ false,
                               /* coerceValueCallback */ null);
        /// 
        ///     The DependencyProperty for the Pen.DashStyle property. 
        /// 
        public static readonly DependencyProperty DashStyleProperty 
            = RegisterProperty("DashStyle", 
                               typeof(DashStyle),
                               typeof(Pen), 
                               DashStyles.Solid,
                               new PropertyChangedCallback(DashStylePropertyChanged),
                               null,
                               /* isIndependentlyAnimated  = */ false, 
                               /* coerceValueCallback */ null);
 
        #endregion Dependency Properties 

        //------------------------------------------------------ 
        //
        //  Internal Fields
        //
        //----------------------------------------------------- 

        #region Internal Fields 
 

 
        internal System.Windows.Media.Composition.DUCE.MultiChannelResource _duceResource = new System.Windows.Media.Composition.DUCE.MultiChannelResource();

        internal const double c_Thickness = 1.0;
        internal const PenLineCap c_StartLineCap = PenLineCap.Flat; 
        internal const PenLineCap c_EndLineCap = PenLineCap.Flat;
        internal const PenLineCap c_DashCap = PenLineCap.Square; 
        internal const PenLineJoin c_LineJoin = PenLineJoin.Miter; 
        internal const double c_MiterLimit = 10.0;
        internal static DashStyle s_DashStyle = DashStyles.Solid; 

        #endregion Internal Fields

 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK