コード例 #1
0
        public override void Instantiate()
        {
            base.Instantiate();
            this.CopyProperty(RichTextBoxElement.VerticalScrollBarVisibilityProperty);
            this.CopyProperty(RichTextBoxElement.HorizontalScrollBarVisibilityProperty);
            this.CopyProperty(RichTextBoxRangeElement.TextBlockTextAlignmentPropertyId);
            if (this.TextSource.ProjectContext.ResolveProperty(RichTextBoxElement.CaretBrushProperty) != null)
            {
                this.CopyProperty(RichTextBoxElement.CaretBrushProperty);
            }
            ITextFlowSceneNode textFlowSceneNode = (ITextFlowSceneNode)this.TextSource;
            DocumentNodePath   documentNodePath  = this.TextSource.DocumentNodePath;
            SceneViewModel     viewModel         = this.TextSource.ViewModel;
            IDocumentContext   documentContext   = viewModel.Document.DocumentContext;
            IProjectContext    projectContext    = viewModel.Document.ProjectContext;

            using (InstanceBuilderContext instanceBuilderContext = new InstanceBuilderContext(projectContext, viewModel, true, (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode)null))
            {
                using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                {
                    instanceBuilderContext.ViewNodeManager.RootNodePath = documentNodePath;
                    instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                }
                this.UpdateUIChildrenInstances((IInstanceBuilderContext)instanceBuilderContext);
                ReferenceStep referenceStep = (ReferenceStep)projectContext.ResolveProperty(textFlowSceneNode.TextChildProperty);
                bool          flag1         = false;
                bool          flag2         = false;
                bool          flag3         = false;
                FlowDocument  flowDocument  = (FlowDocument)referenceStep.GetCurrentValue(instanceBuilderContext.ViewNodeManager.Root.Instance);
                DependencyPropertyReferenceStep shadowProperty = DesignTimeProperties.GetShadowProperty(projectContext.ResolveProperty(TextElementSceneElement.FontFamilyProperty), (ITypeId)null);
                if (flowDocument == null)
                {
                    flowDocument = new FlowDocument();
                }
                else
                {
                    flag1 = ((ReferenceStep)projectContext.ResolveProperty(TextElementSceneElement.FontSizeProperty)).IsSet((object)flowDocument);
                    flag2 = ((ReferenceStep)projectContext.ResolveProperty(ParagraphElement.TextAlignmentProperty)).IsSet((object)flowDocument);
                    flag3 = shadowProperty.IsSet((object)flowDocument);
                }
                double        fontSize      = flowDocument.FontSize;
                FontFamily    fontFamily    = (FontFamily)shadowProperty.GetValue((object)flowDocument);
                Thickness     pagePadding   = flowDocument.PagePadding;
                TextAlignment textAlignment = flowDocument.TextAlignment;
                referenceStep.SetValue(instanceBuilderContext.ViewNodeManager.Root.Instance, (object)new FlowDocument());
                this.RichTextBox.Document = (IViewFlowDocument)this.TextSource.Platform.ViewObjectFactory.Instantiate((object)flowDocument);
                if (flag1)
                {
                    flowDocument.FontSize = fontSize;
                }
                if (flag3)
                {
                    if (!DesignTimeProperties.UseShadowPropertyForInstanceBuilding(this.TypeResolver, ControlElement.FontFamilyProperty))
                    {
                        flowDocument.FontFamily = fontFamily;
                    }
                    else
                    {
                        shadowProperty.SetValue((object)flowDocument, (object)fontFamily);
                    }
                }
                if (flag2)
                {
                    flowDocument.TextAlignment = textAlignment;
                }
                flowDocument.PagePadding = pagePadding;
            }
        }
コード例 #2
0
        protected virtual DocumentNode ResolveDefaultStyleAsDocumentNode(IType targetType, IPropertyId propertyKey)
        {
            DocumentNode node      = (DocumentNode)null;
            IViewStyle   viewStyle = (IViewStyle)null;

            if (this.IsViewObjectValid)
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                {
                    viewStyle = this.Platform.ViewObjectFactory.Instantiate(referenceStep.GetCurrentValue(this.ViewObject.PlatformSpecificObject)) as IViewStyle;
                    if (viewStyle != null && viewStyle.StyleTargetType != targetType.RuntimeType)
                    {
                        viewStyle = (IViewStyle)null;
                    }
                    if (viewStyle != null)
                    {
                        node = this.ViewModel.DefaultView.GetCorrespondingDocumentNode((IViewObject)viewStyle, true);
                        if (node == null && this.DesignerContext.DesignerDefaultPlatformService.DefaultPlatform == this.Platform)
                        {
                            node = this.CreateNode(viewStyle.PlatformSpecificObject);
                        }
                    }
                }
            }
            for (IType type = this.ProjectContext.GetType(this.MetadataFactory.GetMetadata(targetType.RuntimeType).GetStylePropertyTargetType(propertyKey)); node == null && type != null && !PlatformTypes.Object.Equals((object)type); type = type.BaseType)
            {
                IList <DocumentCompositeNode> auxillaryResources = (IList <DocumentCompositeNode>)null;
                if (PlatformTypes.IsPlatformType((ITypeId)type))
                {
                    node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromPlatform(this.Platform, (object)type.RuntimeType, out auxillaryResources);
                }
                else
                {
                    foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                    {
                        IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                        if (projectContext != null && type.RuntimeAssembly.Equals((object)projectContext.ProjectAssembly))
                        {
                            node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromProject(project, (object)type.RuntimeType, out auxillaryResources);
                            if (node == null && !this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromAssembly(this.ProjectContext, type.RuntimeAssembly, type.RuntimeAssembly, (object)type.RuntimeType, out auxillaryResources);
                            }
                        }
                    }
                }
                if (node != null)
                {
                    node = node.Clone(this.DocumentContext);
                    if (auxillaryResources != null && auxillaryResources.Count > 0)
                    {
                        StyleNode styleNode = (StyleNode)this.ViewModel.GetSceneNode(node);
                        if (styleNode.AreResourcesSupported)
                        {
                            if (styleNode.Resources == null)
                            {
                                styleNode.Resources = (ResourceDictionaryNode)this.ViewModel.CreateSceneNode(PlatformTypes.ResourceDictionary);
                            }
                            for (int index = auxillaryResources.Count - 1; index >= 0; --index)
                            {
                                DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.ViewModel.GetSceneNode(auxillaryResources[index].Clone(this.DocumentContext));
                                styleNode.Resources.Insert(0, dictionaryEntryNode);
                            }
                        }
                    }
                }
            }
            if (viewStyle == null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null)
                {
                    System.Windows.Style style = referenceStep.GetDefaultValue(targetType.RuntimeType) as System.Windows.Style;
                    if (style != null)
                    {
                        node = this.CreateNode((object)style);
                    }
                }
            }
            return(node);
        }
コード例 #3
0
        private void UpdateTranslation(bool scrollNow)
        {
            SceneView      activeView = this.ActiveView;
            SceneViewModel viewModel  = activeView.ViewModel;
            Vector         delta      = this.dragCurrentPosition - this.dragStartPosition;

            if (this.isConstraining)
            {
                delta = this.ConstrainDeltaToAxis(delta);
            }
            if (delta == this.lastMove || this.IsAltDown)
            {
                return;
            }
            this.EnsureEditTransaction();
            Vector       vector1          = delta - this.lastMove;
            SceneElement primarySelection = viewModel.ElementSelectionSet.PrimarySelection;

            if (primarySelection == null)
            {
                return;
            }
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection);

            if (propertyReference == null)
            {
                return;
            }
            object computedValue = primarySelection.GetComputedValue(propertyReference);

            if (computedValue != null && !PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)primarySelection.ProjectContext))
            {
                Vector vector2 = vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true);
                if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool)
                {
                    ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.StartPointProperty);
                    ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.EndPointProperty);
                    Point         point1         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2);
                    Point         point2         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2);
                    this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point1);
                    this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point2);
                }
                else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool)
                {
                    ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.CenterProperty);
                    ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.GradientOriginProperty);
                    Point         point1         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2);
                    Point         point2         = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2);
                    this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point1);
                    this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point2);
                }
                else
                {
                    this.TranslateBrushPosition(vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, false), primarySelection);
                }
            }
            activeView.EnsureVisible(this.dragStartPosition + delta, scrollNow);
            this.lastMove = delta;
            this.UpdateEditTransaction();
        }
コード例 #4
0
        public void TranslateBrushPosition(Vector elementDelta, SceneElement element)
        {
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)element);

            if (propertyReference == null)
            {
                return;
            }
            object computedValue = element.GetComputedValue(propertyReference);

            if (computedValue == null || PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)element.ProjectContext))
            {
                return;
            }
            ReferenceStep      referenceStep      = (ReferenceStep)element.Platform.Metadata.ResolveProperty(BrushNode.RelativeTransformProperty);
            object             obj                = element.ViewModel.DefaultView.ConvertToWpfValue(referenceStep.GetCurrentValue(computedValue));
            CanonicalTransform canonicalTransform = !(obj is Transform) ? new CanonicalTransform(Matrix.Identity) : new CanonicalTransform((Transform)obj);

            elementDelta *= canonicalTransform.TransformGroup.Value;
            double valueToSet1 = RoundingHelper.RoundLength(canonicalTransform.TranslationX + elementDelta.X);
            double valueToSet2 = RoundingHelper.RoundLength(canonicalTransform.TranslationY + elementDelta.Y);

            this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationXReference, valueToSet1);
            this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationYReference, valueToSet2);
        }
コード例 #5
0
ファイル: BrushAdorner.cs プロジェクト: radtek/Shopdrawing
        public static object GetBrushPropertyAsWpf(Base2DElement element, object brush, IPropertyId key)
        {
            ReferenceStep referenceStep = (ReferenceStep)element.Platform.Metadata.ResolveProperty(key);

            return(element.ViewModel.DefaultView.ConvertToWpfValue(referenceStep.GetCurrentValue(brush)));
        }
コード例 #6
0
        private void UpdateScale()
        {
            SceneElement primarySelection = this.ActiveView.ElementSelectionSet.PrimarySelection;

            if (primarySelection == null)
            {
                return;
            }
            PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection);

            if (propertyReference == null)
            {
                return;
            }
            this.EnsureEditTransaction();
            if (!this.HasMouseMovedAfterDown)
            {
                this.CopyPrimaryBrushToSelection();
            }
            ReferenceStep referenceStep1 = (ReferenceStep)this.ActiveView.ProjectContext.ResolveProperty(RadialGradientBrushNode.RadiusXProperty);
            ReferenceStep referenceStep2 = (ReferenceStep)this.ActiveView.ProjectContext.ResolveProperty(RadialGradientBrushNode.RadiusYProperty);

            if (!this.HasMouseMovedAfterDown)
            {
                object computedValue = primarySelection.GetComputedValue(propertyReference);
                this.radiusX = (double)referenceStep1.GetCurrentValue(computedValue);
                this.radiusY = (double)referenceStep2.GetCurrentValue(computedValue);
            }
            Vector vector = new Vector(0.0, 0.0);
            bool   flag   = false;

            if (this.ActiveAdorner.TestFlags(EdgeFlags.LeftOrRight))
            {
                vector.X = this.currentPointerPosition.X - this.initialPointerPosition.X;
                if (this.ActiveAdorner.TestFlags(EdgeFlags.Left) && this.radiusX > 0.0 || this.ActiveAdorner.TestFlags(EdgeFlags.Right) && this.radiusX < 0.0)
                {
                    vector.X *= -1.0;
                }
                if (this.constrainAspectRatio && Math.Abs(this.radiusX) > 0.001)
                {
                    vector.Y = vector.X * this.radiusY / this.radiusX;
                    flag     = true;
                }
            }
            if (this.ActiveAdorner.TestFlags(EdgeFlags.TopOrBottom))
            {
                vector.Y = this.currentPointerPosition.Y - this.initialPointerPosition.Y;
                if (this.ActiveAdorner.TestFlags(EdgeFlags.Top) && this.radiusY > 0.0 || this.ActiveAdorner.TestFlags(EdgeFlags.Bottom) && this.radiusY < 0.0)
                {
                    vector.Y *= -1.0;
                }
                if (this.constrainAspectRatio && Math.Abs(this.radiusY) > 0.001)
                {
                    vector.X = vector.Y * this.radiusX / this.radiusY;
                    flag     = true;
                }
            }
            vector.X = RoundingHelper.RoundLength(vector.X + this.radiusX);
            vector.Y = RoundingHelper.RoundLength(vector.Y + this.radiusY);
            if (this.ActiveAdorner.TestFlags(EdgeFlags.LeftOrRight) || flag)
            {
                this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)vector.X);
            }
            if (this.ActiveAdorner.TestFlags(EdgeFlags.TopOrBottom) || flag)
            {
                this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)vector.Y);
            }
            this.UpdateEditTransaction();
        }