示例#1
0
            public RichTextBoxRangeElement Instantiate(IViewTextRange textRange, SceneViewModel viewModel, ITypeId targetType)
            {
                RichTextBoxRangeElement textBoxRangeElement = (RichTextBoxRangeElement)this.Instantiate(viewModel, targetType);

                textBoxRangeElement.SetTextRange(textRange);
                return(textBoxRangeElement);
            }
示例#2
0
        public object GetTextValue(IViewTextRange textRange, PropertyReference propertyReference)
        {
            object textRangeValue = RichTextBoxRangeElement.GetTextRangeValue(textRange, propertyReference);

            if (DependencyProperty.UnsetValue == textRangeValue)
            {
                return(MixedProperty.Mixed);
            }
            return(textRangeValue);
        }
示例#3
0
        private static object GetUpdatedComplexProperty(IViewTextRange target, PropertyReference propertyReference, int index, object value, SceneNode.Modification modification)
        {
            ReferenceStep firstStep = propertyReference.FirstStep;
            IProperty     property  = target.Platform.Metadata.ResolveProperty((IPropertyId)firstStep);

            if (property != null && RichTextBoxRangeElement.IsComplexProperty((IPlatformMetadata)target.Platform.Metadata, property) && propertyReference.Count > 1)
            {
                PropertyReference subReference = RichTextBoxRangeElement.CreateSubReference(propertyReference);
                object            target1;
                if (target.IsEmpty)
                {
                    target1 = target.GetPropertyValue((IPropertyId)property);
                }
                else
                {
                    IViewTextPointer viewTextPointer = target.Start;
                    if (!viewTextPointer.IsAtInsertionPosition)
                    {
                        viewTextPointer = viewTextPointer.GetNextInsertionPosition(LogicalDirection.Forward);
                    }
                    target1 = !RichTextBoxElement.IsParagraphProperty(propertyReference) ? viewTextPointer.Parent.GetValue(property) : viewTextPointer.Paragraph.GetValue(property);
                }
                Freezable freezable = target1 as Freezable;
                if (freezable != null)
                {
                    target1 = (object)freezable.Clone();
                }
                if (target1 != null)
                {
                    switch (modification)
                    {
                    case SceneNode.Modification.SetValue:
                        target1 = subReference.SetValue(target1, value);
                        break;

                    case SceneNode.Modification.InsertValue:
                        subReference.Insert(target1, index, value);
                        break;

                    case SceneNode.Modification.RemoveValue:
                        subReference.RemoveAt(target1, index);
                        break;

                    default:
                        throw new InvalidEnumArgumentException("modification", (int)modification, typeof(SceneNode.Modification));
                    }
                }
                value = target1;
            }
            return(value);
        }
示例#4
0
        private static object GetTextRangeValue(IViewTextRange textRange, PropertyReference propertyReference)
        {
            object        target    = (object)null;
            ReferenceStep firstStep = propertyReference.FirstStep;
            IProperty     property  = textRange.Platform.Metadata.ResolveProperty((IPropertyId)firstStep);

            if (property != null)
            {
                target = textRange.GetPropertyValue((IPropertyId)property, true);
                if (target == DependencyProperty.UnsetValue || propertyReference.Count <= 1)
                {
                    return(target);
                }
                target = RichTextBoxRangeElement.CreateSubReference(propertyReference).GetValue(target);
            }
            return(target);
        }
示例#5
0
 private void SetTextRange(IViewTextRange textRange)
 {
     this.textRange = textRange;
 }
示例#6
0
        private void ModifyTextValue(IViewTextRange textRange, PropertyReference propertyReference, int index, object value, SceneNode.Modification modification)
        {
            if (value is Microsoft.Expression.DesignModel.DocumentModel.DocumentNode || value is MarkupExtension)
            {
                return;
            }
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.TextSetProperty);
            value = RichTextBoxRangeElement.GetUpdatedComplexProperty(textRange, propertyReference, index, value, modification);
            ReferenceStep firstStep = propertyReference.FirstStep;
            IProperty     property  = textRange.Platform.Metadata.ResolveProperty((IPropertyId)firstStep);

            if (property != null)
            {
                if (modification == SceneNode.Modification.ClearValue)
                {
                    value = this.ViewModel.DefaultView.ConvertToWpfValue(this.ViewModel.DefaultView.ConvertFromWpfPropertyReference(propertyReference).LastStep.GetDefaultValue(typeof(object)));
                }
                if (property.Equals((object)RichTextBoxRangeElement.TextIndentPropertyId) && (double)value < 0.0)
                {
                    value = (object)0.0;
                }
                textRange.ApplyPropertyValue((IPropertyId)property, value);
                bool flag = RichTextBoxElement.IsParagraphProperty(propertyReference);
                PropertyReference propertyReference1 = DesignTimeProperties.GetShadowPropertyReference(propertyReference, (ITypeId)this.Type);
                if (propertyReference1 != null && !DesignTimeProperties.UseShadowPropertyForInstanceBuilding(this.ViewModel.Document.DocumentContext.TypeResolver, (IPropertyId)propertyReference1.FirstStep))
                {
                    propertyReference1 = (PropertyReference)null;
                }
                if (modification == SceneNode.Modification.ClearValue && propertyReference1 == null)
                {
                    propertyReference1 = propertyReference;
                }
                if (propertyReference1 != null)
                {
                    IViewTextElement viewTextElement1 = (IViewTextElement)null;
                    if (textRange.Start.CompareTo(textRange.End) != 0 || textRange.Start.CompareTo(((IViewTextElement)textRange.Start.Parent).ContentStart) != 0 && textRange.Start.CompareTo(((IViewTextElement)textRange.Start.Parent).ContentEnd) != 0)
                    {
                        for (IViewTextPointer viewTextPointer = textRange.Start; viewTextPointer != null && viewTextPointer.CompareTo(textRange.End) <= 0; viewTextPointer = viewTextPointer.GetNextInsertionPosition(LogicalDirection.Forward))
                        {
                            IViewTextElement viewTextElement2 = viewTextPointer.Parent as IViewTextElement;
                            if (viewTextElement2 != null && (viewTextElement1 == null || viewTextElement1.PlatformSpecificObject != viewTextElement2.PlatformSpecificObject))
                            {
                                viewTextElement1 = viewTextElement2;
                                if (viewTextElement1 != null && (flag && viewTextElement1 is Paragraph || !flag && viewTextElement1 is Run))
                                {
                                    if (modification == SceneNode.Modification.ClearValue)
                                    {
                                        propertyReference1.ClearValue((object)viewTextElement1);
                                    }
                                    else
                                    {
                                        propertyReference1.SetValue((object)viewTextElement1, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (property.Equals((object)RichTextBoxRangeElement.ForegroundProperty) || property.Equals((object)RichTextBoxRangeElement.TextElementForegroundProperty))
            {
                TextBlockEditProxy textBlockEditProxy = this.TextEditProxy as TextBlockEditProxy;
                if (textBlockEditProxy != null)
                {
                    textBlockEditProxy.UpdateCaretBrush();
                }
            }
            if (this.TextEditProxy == null)
            {
                return;
            }
            this.TextEditProxy.Serialize();
            this.TextEditProxy.UpdateDocumentModel();
        }
示例#7
0
 public void ClearTextValue(IViewTextRange textRange, PropertyReference propertyReference)
 {
     this.ModifyTextValue(textRange, propertyReference, -1, (object)null, SceneNode.Modification.ClearValue);
 }
示例#8
0
 public void RemoveTextValueAt(IViewTextRange textRange, PropertyReference propertyReference, int index)
 {
     this.ModifyTextValue(textRange, propertyReference, index, (object)null, SceneNode.Modification.RemoveValue);
 }
示例#9
0
 public void InsertTextValue(IViewTextRange textRange, PropertyReference propertyReference, int index, object value)
 {
     this.ModifyTextValue(textRange, propertyReference, index, value, SceneNode.Modification.InsertValue);
 }
示例#10
0
 public void SetTextValue(IViewTextRange textRange, PropertyReference propertyReference, object value)
 {
     this.ModifyTextValue(textRange, propertyReference, -1, value, SceneNode.Modification.SetValue);
 }
示例#11
0
 public PropertyState IsValueSetOnTextRange(IViewTextRange textRange, PropertyReference propertyReference)
 {
     return(RichTextBoxRangeElement.GetTextRangeValue(textRange, propertyReference) == null ? PropertyState.Unset : PropertyState.Set);
 }
示例#12
0
        public override void Serialize()
        {
            IDocumentContext documentContext = this.TextSource.DocumentContext;
            IPlatformTypes   metadata        = this.ProxyPlatform.Metadata;
            DependencyPropertyReferenceStep propertyReferenceStep = DesignTimeProperties.ResolveDesignTimeReferenceStep(DesignTimeProperties.UpdateContextProperty, (IPlatformMetadata)metadata);

            switch (this.SerializationType)
            {
            case RichTextSerializationType.FlowDocument:
                this.richTextBox.SetValue(metadata.DefaultTypeResolver, (IProperty)propertyReferenceStep, (object)this.instanceDictionary);
                this.flowDocumentNode = (DocumentCompositeNode)documentContext.CreateNode(typeof(FlowDocument), (object)(FlowDocument)this.richTextBox.Document.PlatformSpecificObject);
                this.richTextBox.ClearValue((IProperty)propertyReferenceStep);
                break;

            case RichTextSerializationType.BlockCollection:
                this.richTextBox.SetValue(metadata.DefaultTypeResolver, (IProperty)propertyReferenceStep, (object)this.instanceDictionary);
                this.blockCollectionNode = documentContext.CreateNode(PlatformTypes.BlockCollection);
                foreach (IViewBlock viewBlock in (IEnumerable <IViewBlock>) this.richTextBox.BlockContainer.Blocks)
                {
                    IViewParagraph viewParagraph = viewBlock as IViewParagraph;
                    if (viewParagraph == null)
                    {
                        IViewTextRange textRange = this.ProxyPlatform.ViewTextObjectFactory.CreateTextRange(this.richTextBox.BlockContainer, viewBlock.ContentStart, viewBlock.ContentEnd);
                        viewParagraph = this.ProxyPlatform.ViewTextObjectFactory.CreateParagraph();
                        IViewRun run = this.ProxyPlatform.ViewTextObjectFactory.CreateRun();
                        run.Text = textRange.Text;
                        viewParagraph.Inlines.Add((IViewInline)run);
                    }
                    this.blockCollectionNode.Children.Add(this.PostProcessDocumentNodeFromEditProxy(this.TextSource.ViewModel.DefaultView.ConvertFromWpfValueAsDocumentNode(viewParagraph.PlatformSpecificObject)));
                }
                this.richTextBox.ClearValue((IProperty)propertyReferenceStep);
                break;

            case RichTextSerializationType.InlineCollection:
                this.inlinesCollectionNode = documentContext.CreateNode(PlatformTypes.InlineCollection);
                using (IEnumerator <IViewBlock> enumerator = this.richTextBox.Document.Blocks.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IViewBlock     current       = enumerator.Current;
                        IViewParagraph viewParagraph = current as IViewParagraph;
                        if (viewParagraph != null)
                        {
                            this.ProcessInlinesForSerialization(viewParagraph.Inlines);
                            if (current.PlatformSpecificObject != ((FlowDocument)this.richTextBox.Document.PlatformSpecificObject).Blocks.LastBlock)
                            {
                                this.inlinesCollectionNode.Children.Add(this.TextSource.ViewModel.DefaultView.ConvertFromWpfValueAsDocumentNode((object)new LineBreak()));
                            }
                        }
                        else
                        {
                            Microsoft.Expression.DesignModel.DocumentModel.DocumentNode documentNode = this.TextSource.ViewModel.DefaultView.ConvertFromWpfValueAsDocumentNode((object)new Run(new TextRange(((TextElement)current.PlatformSpecificObject).ContentStart, ((TextElement)current.PlatformSpecificObject).ContentEnd).Text));
                            if (documentNode != null)
                            {
                                this.inlinesCollectionNode.Children.Add(documentNode);
                            }
                        }
                    }
                    break;
                }
            }
        }