/// <summary>Gets the service object of the specified type.</summary>
        /// <param name="serviceType">The type of service object to get. </param>
        /// <returns>A service object of type <paramref name="serviceType" />, or <see langword="null" /> if there is no service object of type <paramref name="serviceType" />.</returns>
        // Token: 0x06005D7B RID: 23931 RVA: 0x001A5254 File Offset: 0x001A3454
        protected object GetService(Type serviceType)
        {
            object result = null;

            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }
            this.CheckDisposed();
            if (this._documentPaginator != null && this._documentPaginator is IServiceProvider)
            {
                if (serviceType == typeof(ITextView))
                {
                    if (this._textView == null)
                    {
                        ITextContainer textContainer = ((IServiceProvider)this._documentPaginator).GetService(typeof(ITextContainer)) as ITextContainer;
                        if (textContainer != null)
                        {
                            this._textView = new DocumentPageTextView(this, textContainer);
                        }
                    }
                    result = this._textView;
                }
                else if (serviceType == typeof(TextContainer) || serviceType == typeof(ITextContainer))
                {
                    result = ((IServiceProvider)this._documentPaginator).GetService(serviceType);
                }
            }
            return(result);
        }
 internal StaticTextPointer(ITextContainer textContainer, object handle0, int handle1)
 {
     _textContainer = textContainer;
     _generation = (textContainer != null) ? textContainer.Generation : 0;
     _handle0 = handle0;
     _handle1 = handle1;
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Returns ITextPointers positioned at the start and end of an element
        ///     that contains text.
        /// </summary>
        private bool GetNodesStartAndEnd(DependencyObject startNode, out ITextPointer start, out ITextPointer end)
        {
            start = null;
            end   = null;

            ITextContainer textContainer = GetTextContainer(startNode);

            if (textContainer != null)
            {
                start = textContainer.Start;
                end   = textContainer.End;
            }
            else
            {
                // Special case for TextElement which doesn't expose its TextContainer
                TextElement textElement = startNode as TextElement;
                if (textElement != null)
                {
                    start = textElement.ContentStart;
                    end   = textElement.ContentEnd;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
        // Token: 0x06007CBC RID: 31932 RVA: 0x00231444 File Offset: 0x0022F644
        public void Activate(bool active)
        {
            if (this._active == active)
            {
                return;
            }
            if (this._attachedAnnotation == null)
            {
                throw new InvalidOperationException(SR.Get("NoAttachedAnnotationToModify"));
            }
            TextAnchor textAnchor = this._attachedAnnotation.AttachedAnchor as TextAnchor;

            Invariant.Assert(textAnchor != null, "AttachedAnchor is not a text anchor");
            ITextContainer textContainer = textAnchor.Start.TextContainer;

            Invariant.Assert(textContainer != null, "TextAnchor does not belong to a TextContainer");
            AnnotationHighlightLayer annotationHighlightLayer = textContainer.Highlights.GetLayer(typeof(HighlightComponent)) as AnnotationHighlightLayer;

            Invariant.Assert(annotationHighlightLayer != null, "AnnotationHighlightLayer is not initialized");
            annotationHighlightLayer.ActivateRange(this, active);
            this._active = active;
            if (active)
            {
                this.HighlightBrush = new SolidColorBrush(this._selectedBackground);
                return;
            }
            this.HighlightBrush = new SolidColorBrush(this._background);
        }
Exemplo n.º 5
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var italic = new Italic();

            parent.Add(italic);
            context.RenderNode(element, new SpanContainer(italic));
        }
        //------------------------------------------------------
        //
        //  Privte Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Private helper that adds a new UIElementPropertyUndoUnit to the undo stack.
        private static void AddPrivate(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, object newValue)
        {
            UndoManager undoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (undoManager == null)
            {
                return;
            }

            object currentValue = uiElement.ReadLocalValue(property);

            if (currentValue is Expression)
            {
                // Can't undo when old value is an expression, so clear the stack.
                if (undoManager.IsEnabled)
                {
                    undoManager.Clear();
                }
                return;
            }

            if (currentValue.Equals(newValue))
            {
                // No property change.
                return;
            }

            undoManager.Add(new UIElementPropertyUndoUnit(uiElement, property, currentValue));
        }
        // Token: 0x06007CC6 RID: 31942 RVA: 0x0023171C File Offset: 0x0022F91C
        private ITextContainer CheckInputData(IAttachedAnnotation attachedAnnotation)
        {
            if (attachedAnnotation == null)
            {
                throw new ArgumentNullException("attachedAnnotation");
            }
            TextAnchor textAnchor = attachedAnnotation.AttachedAnchor as TextAnchor;

            if (textAnchor == null)
            {
                throw new ArgumentException(SR.Get("InvalidAttachedAnchor"), "attachedAnnotation");
            }
            ITextContainer textContainer = textAnchor.Start.TextContainer;

            Invariant.Assert(textContainer != null, "TextAnchor does not belong to a TextContainer");
            if (attachedAnnotation.Annotation == null)
            {
                throw new ArgumentException(SR.Get("AnnotationIsNull"), "attachedAnnotation");
            }
            if (!this._type.Equals(attachedAnnotation.Annotation.AnnotationType))
            {
                throw new ArgumentException(SR.Get("NotHighlightAnnotationType", new object[]
                {
                    attachedAnnotation.Annotation.AnnotationType.ToString()
                }), "attachedAnnotation");
            }
            return(textContainer);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the CultureInfoculture of a TextContainer parent.
        /// </summary>
        private static CultureInfo GetDocumentCultureInfo(ITextContainer textContainer)
        {
            CultureInfo cultureInfo = null;

            if (textContainer.Parent != null)
            {
                XmlLanguage language = (XmlLanguage)textContainer.Parent.GetValue(FrameworkElement.LanguageProperty);
                if (language != null)
                {
                    try
                    {
                        cultureInfo = language.GetSpecificCulture();
                    }
                    catch (InvalidOperationException)
                    {
                        // Someone set a bogus language on the document.
                        cultureInfo = null;
                    }
                }
            }

            if (cultureInfo == null)
            {
                cultureInfo = CultureInfo.CurrentCulture;
            }

            return(cultureInfo);
        }
        // Token: 0x06007CB9 RID: 31929 RVA: 0x00231278 File Offset: 0x0022F478
        public void AddAttachedAnnotation(IAttachedAnnotation attachedAnnotation)
        {
            if (this._attachedAnnotation != null)
            {
                throw new ArgumentException(SR.Get("MoreThanOneAttachedAnnotation"));
            }
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedHighlightBegin);
            ITextContainer textContainer = this.CheckInputData(attachedAnnotation);
            TextAnchor     range         = attachedAnnotation.AttachedAnchor as TextAnchor;

            this.GetColors(attachedAnnotation.Annotation, out this._background, out this._selectedBackground);
            this._range = range;
            Invariant.Assert(textContainer.Highlights != null, "textContainer.Highlights is null");
            AnnotationHighlightLayer annotationHighlightLayer = textContainer.Highlights.GetLayer(typeof(HighlightComponent)) as AnnotationHighlightLayer;

            if (annotationHighlightLayer == null)
            {
                annotationHighlightLayer = new AnnotationHighlightLayer();
                textContainer.Highlights.AddLayer(annotationHighlightLayer);
            }
            this._attachedAnnotation = attachedAnnotation;
            this._attachedAnnotation.Annotation.CargoChanged += this.OnAnnotationUpdated;
            annotationHighlightLayer.AddRange(this);
            this.HighlightBrush   = new SolidColorBrush(this._background);
            base.IsHitTestVisible = false;
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedHighlightEnd);
        }
Exemplo n.º 10
0
        public void Draw(ITextContainer parent, Matrix baseTransform, FontRenderer renderer, TextCursorPosition cursorPos)
        {
            renderer.DrawChars(BackgroundText, Width, Height, FormatBack, Dialog, Position.Transform * baseTransform, cursorPos);
            var offset = GetBackgroundWidth() - GetForegroundWidth();

            renderer.DrawChars(ForegroundText, Width, Height, FormatFront, Dialog, Matrix.CreateTranslation(offset, 0, 0) * Position.Transform * baseTransform, cursorPos);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Checks if this attachedAnnotation data - AttachedAnchor and Annotation
        /// </summary>
        /// <param name="attachedAnnotation">The AttachedAnnotation</param>
        /// <returns>The AttachedAnchor TextContainer</returns>
        private ITextContainer CheckInputData(IAttachedAnnotation attachedAnnotation)
        {
            if (attachedAnnotation == null)
            {
                throw new ArgumentNullException("attachedAnnotation");
            }

            TextAnchor textAnchor = attachedAnnotation.AttachedAnchor as TextAnchor;

            if (textAnchor == null)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidAttachedAnchor), "attachedAnnotation");
            }

            //this should be in a fixed or flow textcontainer
            ITextContainer textContainer = textAnchor.Start.TextContainer;

            Invariant.Assert(textContainer != null, "TextAnchor does not belong to a TextContainer");

            if (attachedAnnotation.Annotation == null)
            {
                throw new ArgumentException(SR.Get(SRID.AnnotationIsNull), "attachedAnnotation");
            }

            //check annotation type
            if (!_type.Equals(attachedAnnotation.Annotation.AnnotationType))
            {
                throw new ArgumentException(SR.Get(SRID.NotHighlightAnnotationType, attachedAnnotation.Annotation.AnnotationType.ToString()), "attachedAnnotation");
            }

            return(textContainer);
        }
Exemplo n.º 12
0
        private static void checkMultiValues(
            ICollection <SignValueStatement> statements,
            ITextContainer result,
            ISemanticNetwork semanticNetwork)
        {
            var clasifications = semanticNetwork.Statements.OfType <IsStatement>().ToList();

            foreach (var concept in semanticNetwork.Concepts)
            {
                var parents = clasifications.GetParentsOneLevel(concept);
                foreach (var sign in HasSignStatement.GetSigns(semanticNetwork.Statements, concept, true))
                {
                    if (statements.FirstOrDefault(sv => sv.Concept == concept && sv.Sign == sign.Sign) == null &&
                        parents.Select(p => SignValueStatement.GetSignValue(semanticNetwork.Statements, p, sign.Sign)).Count(r => r != null) > 1)
                    {
                        result.Append(
                            language => language.GetExtension <ILanguageSetModule>().Statements.Consistency.ErrorMultipleSignValue,
                            new Dictionary <String, IKnowledge>
                        {
                            { Semantics.Localization.Strings.ParamConcept, concept },
                            { Strings.ParamSign, sign.Sign },
                        });
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void Draw(ITextContainer parent, Matrix baseTransform, FontRenderer renderer, TextCursorPosition cursorPos)
        {
            var sprite   = SpriteLoader.Instance.AddSprite("content/ui_slider_bar");
            var cursor   = SpriteLoader.Instance.AddSprite("content/cursor");
            var barSlide = BarSlide();
            int bars     = (int)Math.Round(BarCount * barSlide);

            if (bars <= 0 && barSlide > 0)
            {
                bars = 1;
            }
            if (bars >= BarCount - 1 && barSlide < 1)
            {
                bars = BarCount - 1;
            }
            renderer.Scene.PushSpriteBatch(transform: Position.Transform * baseTransform);
            if (barSlide > 0)
            {
                renderer.Scene.DrawSprite(cursor, 0, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0);
            }
            for (int i = 0; i < BarCount; i++)
            {
                renderer.Scene.DrawSprite(sprite, 0, new Vector2(16 + i * 5 - 1, 0), SpriteEffects.None, i < bars ? Color.White : Color.Gray, 0);
            }
            if (barSlide < 1)
            {
                renderer.Scene.DrawSprite(cursor, 0, new Vector2(16 + BarCount * 5 - 1, 0), SpriteEffects.None, 0);
            }
            renderer.Scene.PopSpriteBatch();
        }
Exemplo n.º 14
0
 public TextBuilder(float width, float height, TextFormatting defaultFormat = null, DialogFormatting defaultDialog = null)
 {
     Root = new TextElementContainer(width, height);
     ContainerStack.Push(Root);
     DefaultFormat = defaultFormat ?? new TextFormatting();
     DefaultDialog = defaultDialog ?? new DialogFormattingIdentity();
 }
Exemplo n.º 15
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var a = (IHtmlAnchorElement)element;

            if (a.ChildElementCount == 0)
            {
                var anchor = new Hyperlink
                {
                    Foreground = new SolidColorBrush(Colors.LightBlue)
                };
                anchor.Click += async (sender, args) =>
                {
                    var dialog = new MessageDialog(a.Href, "使用浏览器打开");
                    dialog.Commands.Add(new UICommand("确定", async cmd =>
                    {
                        var success = await Launcher.LaunchUriAsync(new Uri(a.Href, UriKind.Absolute));
                        if (success)
                        {
                            anchor.Foreground = new SolidColorBrush(Colors.Purple);
                        }
                    }));
                    dialog.Commands.Add(new UICommand("取消"));
                    await dialog.ShowAsync();
                };

                parent.Add(anchor);

                context.RenderNode(element, new SpanContainer(anchor));
            }
            else
            {
                context.RenderNode(element,parent);
            }
        }
Exemplo n.º 16
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var richEditBox = new RichEditBox();

            richEditBox.Document.SetText(TextSetOptions.None, element.TextContent);
            parent.Add(richEditBox);
        }
        /// <summary>
        /// Returns service objects associated with this control.
        /// This method should be called by IServiceProvider.GetService implementation 
        /// for DocumentPageView or subclasses.
        /// </summary>
        /// <param name="serviceType">Specifies the type of service object to get.</param>
        protected object GetService(Type serviceType)
        {
            object service = null;
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }
            CheckDisposed();

            // No service is available if the Content does not provide
            // any services.
            if (_documentPaginator != null && _documentPaginator is IServiceProvider)
            {
                // Following services are available:
                // (1) TextView - wrapper for TextView exposed by the current page.
                // (2) TextContainer - the service object is retrieved from DocumentPaginator.
                if (serviceType == typeof(ITextView))
                {
                    if (_textView == null)
                    {
                        ITextContainer tc = ((IServiceProvider)_documentPaginator).GetService(typeof(ITextContainer)) as ITextContainer;
                        if (tc != null)
                        {
                            _textView = new DocumentPageTextView(this, tc);
                        }
                    }
                    service = _textView;
                }
                else if (serviceType == typeof(TextContainer) || serviceType == typeof(ITextContainer))
                {
                    service = ((IServiceProvider)_documentPaginator).GetService(serviceType);
                }
            }
            return service;
        }
Exemplo n.º 18
0
        private float GetAlignmentOffset(ITextContainer parent)
        {
            float xOffset = 0;
            float width   = parent.Width;

            if (width >= float.PositiveInfinity)
            {
                width = 0;
            }
            switch (Alignment)
            {
            case (LineAlignment.Left):
                xOffset = 0;
                break;

            case (LineAlignment.Center):
                xOffset = (width - Width) / 2;
                break;

            case (LineAlignment.Right):
                xOffset = width - Width;
                break;
            }

            return(xOffset);
        }
        // Token: 0x06007CC9 RID: 31945 RVA: 0x00231834 File Offset: 0x0022FA34
        private void OnAnnotationUpdated(object sender, AnnotationResourceChangedEventArgs args)
        {
            Invariant.Assert(this._attachedAnnotation != null && this._attachedAnnotation.Annotation == args.Annotation, "_attachedAnnotation is different than the input one");
            Invariant.Assert(this._range != null, "The highlight range is null");
            TextAnchor textAnchor = this._attachedAnnotation.AttachedAnchor as TextAnchor;

            Invariant.Assert(textAnchor != null, "wrong anchor type of the saved attached annotation");
            ITextContainer textContainer = textAnchor.Start.TextContainer;

            Invariant.Assert(textContainer != null, "TextAnchor does not belong to a TextContainer");
            Color color;
            Color color2;

            this.GetColors(args.Annotation, out color, out color2);
            if (!this._background.Equals(color) || !this._selectedBackground.Equals(color2))
            {
                Invariant.Assert(textContainer.Highlights != null, "textContainer.Highlights is null");
                AnnotationHighlightLayer annotationHighlightLayer = textContainer.Highlights.GetLayer(typeof(HighlightComponent)) as AnnotationHighlightLayer;
                if (annotationHighlightLayer == null)
                {
                    throw new InvalidDataException(SR.Get("MissingAnnotationHighlightLayer"));
                }
                this._background         = color;
                this._selectedBackground = color2;
                annotationHighlightLayer.ModifiedRange(this);
            }
        }
Exemplo n.º 20
0
 public static void Trace(ITextContainer textContainer)
 {
     if (!Server.Instance.Config.TraceLogDisable)
     {
         Server.Instance?.Logger.OutputLogger.Trace(textContainer.GetText());
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// <see cref="AutomationPeer.GetAutomationControlTypeCore"/>
        /// </summary>
        public override object GetPattern(PatternInterface patternInterface)
        {
            object returnValue = null;

            if (patternInterface == PatternInterface.Text)
            {
                if (_textPattern == null)
                {
                    if (Owner is IServiceProvider)
                    {
                        ITextContainer textContainer = ((IServiceProvider)Owner).GetService(typeof(ITextContainer)) as ITextContainer;
                        if (textContainer != null)
                        {
                            _textPattern = new TextAdaptor(this, textContainer);
                        }
                    }
                }
                returnValue = _textPattern;
            }
            else
            {
                returnValue = base.GetPattern(patternInterface);
            }
            return(returnValue);
        }
Exemplo n.º 22
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var paragraph = new Paragraph();

            parent.Add(paragraph);
            context.RenderNode(element, new OrderListContainer(paragraph));
        }
Exemplo n.º 23
0
        // Returns the local UndoManager.
        // Returns null if there is no undo service or if the service exists
        // but is disabled or if there is no open parent undo unit.
        internal static UndoManager GetOrClearUndoManager(ITextContainer textContainer)
        {
            UndoManager undoManager;

            undoManager = textContainer.UndoManager;
            if (undoManager == null)
            {
                return(null);
            }

            if (!undoManager.IsEnabled)
            {
                return(null);
            }

            if (undoManager.OpenedUnit == null)
            {
                // There's no parent undo unit, so we can't open a child.
                //
                // Clear the undo stack -- since we depend on symbol offsets
                // matching the original document state when an undo unit is
                // executed, any of our units currently in the stack will be
                // corrupted after we finished the operation in progress.
                undoManager.Clear();
                return(null);
            }

            return(undoManager);
        }
Exemplo n.º 24
0
 internal StaticTextPointer(ITextContainer textContainer, object handle0, int handle1)
 {
     _textContainer = textContainer;
     _generation    = (textContainer != null) ? textContainer.Generation : 0;
     _handle0       = handle0;
     _handle1       = handle1;
 }
Exemplo n.º 25
0
        // ------------------------------------------------------------------
        //
        //  TextSource Implementation
        //
        // ------------------------------------------------------------------

        #region TextSource Implementation

        /// <summary>
        /// Get a text run at specified text source position and return it.
        /// </summary>
        /// <param name="dcp">
        /// dcp of position relative to start of line
        /// </param>
        internal override TextRun GetTextRun(int dcp)
        {
            TextRun           run           = null;
            ITextContainer    textContainer = _paraClient.Paragraph.StructuralCache.TextContainer;
            StaticTextPointer position      = textContainer.CreateStaticPointerAtOffset(_cpPara + dcp);

            switch (position.GetPointerContext(LogicalDirection.Forward))
            {
            case TextPointerContext.Text:
                run = HandleText(position);
                break;

            case TextPointerContext.ElementStart:
                run = HandleElementStartEdge(position);
                break;

            case TextPointerContext.ElementEnd:
                run = HandleElementEndEdge(position);
                break;

            case TextPointerContext.EmbeddedElement:
                run = HandleEmbeddedObject(dcp, position);
                break;

            case TextPointerContext.None:
                run = new ParagraphBreakRun(_syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph);
                break;
            }
            Invariant.Assert(run != null, "TextRun has not been created.");
            Invariant.Assert(run.Length > 0, "TextRun has to have positive length.");

            return(run);
        }
Exemplo n.º 26
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var a = (IHtmlAnchorElement)element;

            if (a.ChildElementCount == 0)
            {
                var anchor = new Hyperlink
                {
                    Foreground = new SolidColorBrush(Colors.LightBlue)
                };
                anchor.Click += async(sender, args) =>
                {
                    var dialog = new MessageDialog(a.Href, "使用浏览器打开");
                    dialog.Commands.Add(new UICommand("确定", async cmd =>
                    {
                        var success = await Launcher.LaunchUriAsync(new Uri(a.Href, UriKind.Absolute));
                        if (success)
                        {
                            anchor.Foreground = new SolidColorBrush(Colors.Purple);
                        }
                    }));
                    dialog.Commands.Add(new UICommand("取消"));
                    await dialog.ShowAsync();
                };

                parent.Add(anchor);

                context.RenderNode(element, new SpanContainer(anchor));
            }
            else
            {
                context.RenderNode(element, parent);
            }
        }
Exemplo n.º 27
0
        //--------------------------------------------------------------------
        //
        // Private Methods
        //
        //---------------------------------------------------------------------

        #region Private Methods
        private void _EnsureBlockLoaded()
        {
            if (_HasStatus(BlockStatus.UnloadedBlock))
            {
                _ClearStatus(BlockStatus.UnloadedBlock);

                DocumentsTrace.FixedDocumentSequence.TextOM.Trace("Loading TextContainer " + _docRef.ToString());
                // Load the TextContainer
                IDocumentPaginatorSource idp = _docRef.GetDocument(false /*forceReload*/);
                IServiceProvider         isp = idp as IServiceProvider;
                if (isp != null)
                {
                    ITextContainer tc = isp.GetService(typeof(ITextContainer)) as ITextContainer;
                    if (tc != null)
                    {
                        _container = tc;
                        DocumentsTrace.FixedDocumentSequence.TextOM.Trace("Got ITextContainer");
                    }
                }

                if (_container == null)
                {
                    _container = new NullTextContainer();
                }
            }
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var bold = new Bold();

            parent.Add(bold);
            context.RenderNode(element, new SpanContainer(bold));
        }
Exemplo n.º 29
0
        /// <summary>
        /// Calculate visible rectangle.
        /// </summary>
        private Rect CalculateBoundingRect(bool clipToVisible, out UIElement uiScope)
        {
            uiScope = null;
            Rect boundingRect = Rect.Empty;

            if (Owner is IServiceProvider)
            {
                ITextContainer textContainer = ((IServiceProvider)Owner).GetService(typeof(ITextContainer)) as ITextContainer;
                ITextView      textView      = (textContainer != null) ? textContainer.TextView : null;
                if (textView != null)
                {
                    // Make sure TextView is updated
                    if (!textView.IsValid)
                    {
                        if (!textView.Validate())
                        {
                            textView = null;
                        }
                        if (textView != null && !textView.IsValid)
                        {
                            textView = null;
                        }
                    }
                    // Get bounding rect from TextView.
                    if (textView != null)
                    {
                        boundingRect = new Rect(textView.RenderScope.RenderSize);
                        uiScope      = textView.RenderScope;

                        // Compute visible portion of the rectangle.
                        if (clipToVisible)
                        {
                            Visual visual = textView.RenderScope;
                            while (visual != null && boundingRect != Rect.Empty)
                            {
                                if (VisualTreeHelper.GetClip(visual) != null)
                                {
                                    GeneralTransform transform = textView.RenderScope.TransformToAncestor(visual).Inverse;
                                    // Safer version of transform to descendent (doing the inverse ourself),
                                    // we want the rect inside of our space. (Which is always rectangular and much nicer to work with)
                                    if (transform != null)
                                    {
                                        Rect clipBounds = VisualTreeHelper.GetClip(visual).Bounds;
                                        clipBounds = transform.TransformBounds(clipBounds);
                                        boundingRect.Intersect(clipBounds);
                                    }
                                    else
                                    {
                                        // No visibility if non-invertable transform exists.
                                        boundingRect = Rect.Empty;
                                    }
                                }
                                visual = VisualTreeHelper.GetParent(visual) as Visual;
                            }
                        }
                    }
                }
            }
            return(boundingRect);
        }
Exemplo n.º 30
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var span = new Span();

            var color = element.Style("color");

            if (string.IsNullOrEmpty(color) == false)
            {
                color = color.Trim().TrimStart('#');
                if (color.Length == 6)
                {
                    var  sR = color.Substring(0, 2);
                    var  sG = color.Substring(2, 2);
                    var  sB = color.Substring(4, 2);
                    byte r, g, b;
                    if (byte.TryParse(sR, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r) &&
                        byte.TryParse(sG, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g) &&
                        byte.TryParse(sB, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                    {
                        var value = Color.FromArgb(255, r, g, b);
                        if (value != Colors.White && value != Colors.Black)
                        {
                            span.Foreground = new SolidColorBrush(value);
                        }
                    }
                }
            }

            parent.Add(span);
            context.RenderNode(element, new SpanContainer(span));
        }
Exemplo n.º 31
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var span = new Span();

            parent.Add(span);
            context.RenderNode(element, new SpanContainer(span));
        }
 // Token: 0x06002B48 RID: 11080 RVA: 0x000C5798 File Offset: 0x000C3998
 internal ChangeBlockUndoRecord(ITextContainer textContainer, string actionDescription)
 {
     if (textContainer.UndoManager != null)
     {
         this._undoManager = textContainer.UndoManager;
         if (this._undoManager.IsEnabled)
         {
             if (textContainer.TextView != null)
             {
                 if (this._undoManager.OpenedUnit == null)
                 {
                     if (textContainer.TextSelection != null)
                     {
                         this._parentUndoUnit = new TextParentUndoUnit(textContainer.TextSelection);
                     }
                     else
                     {
                         this._parentUndoUnit = new ParentUndoUnit(actionDescription);
                     }
                     this._undoManager.Open(this._parentUndoUnit);
                     return;
                 }
             }
             else
             {
                 this._undoManager.Clear();
             }
         }
     }
 }
Exemplo n.º 33
0
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText.Trim(new char[] {'\n'}) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            var inlineElt = new InlineUIContainer();
                            var hyperlink = new HyperlinkButton();
                            inlineElt.Child = hyperlink;
                            hyperlink.Style = (Style)App.Current.Resources["HyperlinkButtonStyle"];
                            hyperlink.Content = e.InnerText;
                            hyperlink.Click += delegate(object sender, RoutedEventArgs eventArgs)
                            {
                                string uriString = e.GetAttribute("href");
                                Messenger.Default.Send<LinkClickedMessage>(new LinkClickedMessage()
                                {
                                    UriToNavigate = uriString
                                });
                            };
                            parent.Add(inlineElt);
                            //ParseElement(e, parent);
                            break;
                        case "BR":
                                parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var groupbox = parent as GroupBoxContainer;
     if (groupbox != null)
     {
         groupbox.SetHeader(element.TextContent);
     }
 }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var button = new Button()
     {
         Content = element.TextContent
     };
     parent.Add(button);
 }
Exemplo n.º 36
0
        //------------------------------------------------------------------- 
        //
        //  Constructors
        //
        //------------------------------------------------------------------- 

        #region Constructors 
 
        /// <summary>
        /// Constructor. 
        /// </summary>
        /// <param name="viewer">Viewer associated with TextView.</param>
        /// <param name="renderScope">Render scope - root of layout structure visualizing content.</param>
        /// <param name="textContainer">TextContainer representing content.</param> 
        internal MultiPageTextView(DocumentViewerBase viewer, UIElement renderScope, ITextContainer textContainer)
        { 
            _viewer = viewer; 
            _renderScope = renderScope;
            _textContainer = textContainer; 
            _pageTextViews = new List<DocumentPageTextView>();
            OnPagesUpdatedCore();
        }
Exemplo n.º 37
0
        //----------------------------------------------------- 
        //
        //  Constructors 
        // 
        //-----------------------------------------------------
 
        #region Constructors

        /// <summary>
        /// Initialize the TextEditor 
        /// </summary>
        /// <param name="textContainer"> 
        /// TextContainer representing a content to edit. 
        /// </param>
        /// <param name="uiScope"> 
        /// FrameworkElement on which all events for the user interaction will be
        /// processed.
        /// </param>
        /// <param name="isUndoEnabled"> 
        /// If true the TextEditor will enable undo support
        /// </param> 
        internal TextEditor(ITextContainer textContainer, FrameworkElement uiScope, bool isUndoEnabled) 
        {
            // Validate parameters 
            Invariant.Assert(uiScope != null);

            // Set non-zero property defaults.
            _acceptsRichContent = true; 

            // Attach the editor  instance to the scope 
            _textContainer = textContainer; 
            _uiScope = uiScope;
 
            // Enable undo manager for this uiScope
            if (isUndoEnabled && _textContainer is TextContainer)
            {
                ((TextContainer)_textContainer).EnableUndo(_uiScope); 
            }
 
            // Create TextSelection and link it to text container 
            _selection = new TextSelection(this);
            textContainer.TextSelection = _selection; 

            // Create DragDropProcess
            //
 
            _dragDropProcess = new TextEditorDragDrop._DragDropProcess(this);
 
            // By default we use IBeam cursor 
            _cursor = Cursors.IBeam;
 
            // Add InputLanguageChanged event handler
            TextEditorTyping._AddInputLanguageChangedEventHandler(this);

            // Listen to both TextContainer.EndChanging and TextContainer.Changed events 
            TextContainer.Changed += new TextContainerChangedEventHandler(OnTextContainerChanged);
 
            // Add IsEnabled event handler for cleaning the caret element when uiScope is disabled 
            _uiScope.IsEnabledChanged += new DependencyPropertyChangedEventHandler(OnIsEnabledChanged);
 
            // Attach this instance of text editor to its uiScope
            _uiScope.SetValue(TextEditor.InstanceProperty, this);

            // The IsSpellerEnabled property might have been set before this 
            // TextEditor was instantiated -- check if we need to rev
            // up speller support. 
            if ((bool)_uiScope.GetValue(SpellCheck.IsEnabledProperty)) 
            {
                SetSpellCheckEnabled(true); 
                SetCustomDictionaries(true);
            }

            // If no IME/TextServices are installed, we have no native reasources 
            // to clean up at Finalizer.
            if (!TextServicesLoader.ServicesInstalled) 
            { 
                GC.SuppressFinalize(this);
            } 
        }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var paragraph = new Paragraph()
     {
         TextAlignment = TextAlignment.Center
     };
     parent.Add(paragraph);
     context.RenderNode(element, new ParagraphContainer(paragraph));
 }
Exemplo n.º 39
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var line = new Rectangle
     {
         MinWidth = double.MaxValue,
         MinHeight = 1,
         Fill = new SolidColorBrush(Colors.Gray),
         Margin = new Thickness(0, 5, 0, 5)
     };
     parent.Add(line);
 }
Exemplo n.º 40
0
 internal TextContentRange(int cpFirst, int cpLast, ITextContainer textContainer)
 { 
     Invariant.Assert(cpFirst <= cpLast);
     Invariant.Assert(cpFirst >= 0); 
     Invariant.Assert(textContainer != null); 
     Invariant.Assert(cpLast <= textContainer.SymbolCount);
     _cpFirst = cpFirst; 
     _cpLast = cpLast;
     _size = 0;
     _ranges = null;
     _textContainer = textContainer; 
 }
Exemplo n.º 41
0
        //-------------------------------------------------------------------
        //
        //  Constructors
        //
        //-------------------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="textPeer">Automation Peer representing element for the ui scope of the text</param>
        /// <param name="textContainer">ITextContainer</param>
        internal TextAdaptor(AutomationPeer textPeer, ITextContainer textContainer)
        {
            Invariant.Assert(textContainer != null, "Invalid ITextContainer");
            Invariant.Assert(textPeer is TextAutomationPeer || textPeer is ContentTextAutomationPeer, "Invalid AutomationPeer");
            _textPeer = textPeer;
            _textContainer = textContainer;
            _textContainer.Changed += new TextContainerChangedEventHandler(OnTextContainerChanged);
            if (_textContainer.TextSelection != null)
            {
                _textContainer.TextSelection.Changed += new EventHandler(OnTextSelectionChanged);
            }
        }
Exemplo n.º 42
0
        // Verifies a TextPointer is non-null and is associated with a given TextContainer.
        //
        // Throws an appropriate exception if a test fails.
        internal static void VerifyPosition(ITextContainer container, ITextPointer position, string paramName)
        {
            if (position == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (position.TextContainer != container)
            {
                throw new ArgumentException(SR.Get(SRID.NotInAssociatedTree, paramName));
            }
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var audio = (IHtmlAudioElement)element;

            var mediaElement = new MediaElement
            {
                Source = new Uri(audio.Source),
                AreTransportControlsEnabled = true,
                MinHeight = 65
            };

            parent.Add(mediaElement);
            context.RenderNode(element, parent);
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var border = new Border
            {
                BorderThickness = new Thickness(1),
                BorderBrush = new SolidColorBrush(Colors.Gray),
                Margin = new Thickness(0, 5, 0, 5),
                Padding = new Thickness(10)
            };
            parent.Add(border);

            var richTextBlock = new RichTextBlock();
            border.Child = richTextBlock;
            context.RenderNode(element, new RichTextBlockContainer(richTextBlock));
        }
Exemplo n.º 45
0
 /// <summary> 
 /// Constructor. 
 /// </summary>
 /// <param name="owner"> 
 /// Root of layout structure visualizing content of a page.
 /// </param>
 /// <param name="textContainer">
 /// TextContainer representing content. 
 /// </param>
 internal DocumentPageTextView(FlowDocumentView owner, ITextContainer textContainer) 
 { 
     Invariant.Assert(owner != null && textContainer != null);
     _owner = owner; 
     _page = owner.DocumentPage;
     _textContainer = textContainer;
     // Retrive inner TextView
     if (_page is IServiceProvider) 
     {
         _pageTextView = ((IServiceProvider)_page).GetService(typeof(ITextView)) as ITextView; 
     } 
     if (_pageTextView != null)
     { 
         _pageTextView.Updated += new EventHandler(HandlePageTextViewUpdated);
     }
 }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var input = (IHtmlInputElement)element;
            var type = input.Type ?? string.Empty;
            type = type.Trim();
            if (type.Length == 0)
            {
                type = "text";
            }
            type = type.ToLower();

            switch (type)
            {
                case "text":
                    {
                        var textbox = new TextBox
                        {
                            Text = input.Value
                        };
                        parent.Add(textbox);
                        break;
                    }
                case "button":
                    {
                        var button = new Button
                        {
                            Content = input.Value
                        };
                        parent.Add(button);
                        break;
                    }
                default:
                    {
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        var textblock = new TextBlock
                        {
                            Text = string.Format("input type=\"{0}\" is not support.", input.Type)
                        };
                        parent.Add(textblock);
                        break;
                    }
            }
        }
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            ParseElement(e, parent);
                            break;
                        case "BR":
                            parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var table = (IHtmlTableElement)element;

            var grid = new Grid();

            foreach (var child in table.Rows)
            {
                var row = child as IHtmlTableRowElement;
                if (row != null)
                {
                    grid.RowDefinitions.Add(new RowDefinition());
                    int columnCount = 0;
                    foreach (var column in row.Cells)
                    {
                        var richTextBlock = new RichTextBlock()
                        {
                            IsTextSelectionEnabled = false
                        };
                        var cellRender = new Border()
                        {
                            Child = richTextBlock,
                            Padding = new Thickness(5)
                        };
                        context.RenderNode(column, new RichTextBlockContainer(richTextBlock));
                        Grid.SetColumn(cellRender, columnCount);
                        Grid.SetRow(cellRender, grid.RowDefinitions.Count - 1);
                        grid.Children.Add(cellRender);

                        columnCount++;

                        if (grid.ColumnDefinitions.Count < columnCount)
                        {
                            grid.ColumnDefinitions.Add(new ColumnDefinition());
                        }
                    }
                }
            }

            parent.Add(grid);
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        // Constructor, called when a change block is opening.
        internal ChangeBlockUndoRecord(ITextContainer textContainer, string actionDescription)
        {
            if (textContainer.UndoManager != null)
            {
                _undoManager = textContainer.UndoManager;

                if (_undoManager.IsEnabled)
                {
                    // Don't bother opening an undo unit if the owning control is
                    // still being initialized (ie, programmatic load by parser).
                    if (textContainer.TextView != null)
                    {
                        // Don't bother opening a new undo unit if we're already nested
                        // inside another.
                        if (_undoManager.OpenedUnit == null)
                        {
                            if (textContainer.TextSelection != null)
                            {
                                _parentUndoUnit = new TextParentUndoUnit(textContainer.TextSelection);
                            }
                            else
                            {
                                _parentUndoUnit = new ParentUndoUnit(actionDescription);
                            }

                            _undoManager.Open(_parentUndoUnit);
                        }
                    }
                    else
                    {
                        // If the owning control isn't initialized (parser is still running),
                        // don't add anything to the undo record.  Instead, clear it.
                        _undoManager.Clear();
                    }
                }
            }
        }
Exemplo n.º 50
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Verifies a TextPointer is non-null and
        // is associated with a given TextContainer.
        //
        // Throws an appropriate exception if a test fails.
        internal static void VerifyPosition(ITextContainer tree, ITextPointer position)
        {
            VerifyPosition(tree, position, "position");
        }
Exemplo n.º 51
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var img = (IHtmlImageElement)element;
            var source = img.Source;
            if (string.IsNullOrEmpty(source))
            {
                return;
            }

            var image = new Image
            {
                Source = new BitmapImage(new Uri(source, UriKind.Absolute))
            };

            double scale = 1.0;

            int? width = img.Width();
            if (width.HasValue)
            {
                if (width.Value > Window.Current.Bounds.Width - 40)
                {
                    scale = (Window.Current.Bounds.Width - 40) / width.Value;
                }

                image.Width = width.Value * scale;
            }
            int? height = img.Height();
            if (height.HasValue)
            {
                image.Height = height.Value * scale;
            }

            DisplayInformation.GetForCurrentView().OrientationChanged +=
                (DisplayInformation sender, object args) =>
                {
                    if (sender.CurrentOrientation == DisplayOrientations.Portrait)
                    {
                        double scale1 = 1.0;

                        int? width1 = img.Width();
                        if (width1.HasValue)
                        {
                            if (width1.Value > Window.Current.Bounds.Width - 40)
                            {
                                scale1 = (Window.Current.Bounds.Width - 40) / width1.Value;
                            }

                            image.Width = width1.Value * scale1;
                        }
                        int? height1 = img.Height();
                        if (height1.HasValue)
                        {
                            image.Height = height1.Value * scale1;
                        }
                    }
                    else if (sender.CurrentOrientation == DisplayOrientations.Landscape || sender.CurrentOrientation == DisplayOrientations.LandscapeFlipped)
                    {
                        double scale1 = 1.0;

                        int? width1 = img.Width();
                        if (width1.HasValue)
                        {
                            if (width1.Value > Window.Current.Bounds.Width - 40)
                            {
                                scale1 = (Window.Current.Bounds.Width - 40) / width1.Value;
                            }

                            image.Width = width1.Value * scale1;
                        }
                        int? height1 = img.Height();
                        if (height1.HasValue)
                        {
                            image.Height = height1.Value * scale1;
                        }
                    }
                };

            parent.Add(image);
        }
Exemplo n.º 52
0
        //-----------------------------------------------------
        //
        //  Constructors
        // 
        //-----------------------------------------------------
 
        #region Constructors 

        internal DeferredTextReference(ITextContainer textContainer) 
        {
            _textContainer = textContainer;
        }
Exemplo n.º 53
0
        //-------------------------------------------------------------------
        // 
        //  Constructors 
        //
        //------------------------------------------------------------------- 

        #region Constructors

        /// <summary> 
        /// Constructor.
        /// </summary> 
        /// <param name="owner"> 
        /// Root of layout structure visualizing content.
        /// </param> 
        /// <param name="textContainer">
        /// TextContainer providing content for this view.
        /// </param>
        internal TextDocumentView(FlowDocumentPage owner, ITextContainer textContainer) 
        {
            _owner = owner; 
            _textContainer = textContainer; 
        }
 public ParagraphTextContainer(ITextContainer parent, Paragraph block)
 {
     _block = block;
     _parent = parent;
 }
Exemplo n.º 55
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var parentContainer = (parent as RichTextBlockContainer).Get();

            Span span = new Span();
            Underline underline = null;

            var textDecoration = element.Style("text-decoration");
            if (!string.IsNullOrEmpty(textDecoration))
            {
                if (textDecoration == "underline")
                {
                    underline = new Underline();
                    underline.Inlines.Add(span);
                }
            }

            var color = element.Style("color");
            if (string.IsNullOrEmpty(color) == false)
            {
                color = color.Trim().TrimStart('#');
                if (color.Length == 6)
                {
                    var sR = color.Substring(0, 2);
                    var sG = color.Substring(2, 2);
                    var sB = color.Substring(4, 2);
                    byte r, g, b;
                    if (byte.TryParse(sR, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r)
                        && byte.TryParse(sG, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g)
                        && byte.TryParse(sB, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                    {
                        var value = Color.FromArgb(255, r, g, b);
                        if (value != Colors.White && value != Colors.Black)
                        {
                            if (underline != null)
                            {
                                underline.Foreground = new SolidColorBrush(value);
                            }
                            else
                            {
                                span.Foreground = new SolidColorBrush(value);
                            }
                        }
                    }
                }
            }

            var fontSize = element.Style("font-size");
            if (!string.IsNullOrEmpty(fontSize))
            {
                fontSize = fontSize.Replace("px", "");
                if (underline != null)
                {
                    underline.FontSize = double.Parse(fontSize);
                }
                else
                {
                    span.FontSize = double.Parse(fontSize);
                }
            }

            var fontWeight = element.Style("font-weight");
            if (!string.IsNullOrEmpty(fontWeight))
            {
                if (underline != null)
                {
                    underline.FontWeight = FontWeights.Bold;
                }
                else
                {
                    span.FontWeight = FontWeights.Bold;
                }
            }


            var textAlign = element.Style("text-align");
            if (!string.IsNullOrEmpty(textAlign))
            {
                if (textAlign == "left")
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
                }
                else if (textAlign == "right")
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
                }
                else
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
                }
            }

            var textStyle = element.Style("text-style");
            if (!string.IsNullOrEmpty(textStyle))
            {
                if (textStyle == "italic")
                {
                    if (underline != null)
                    {
                        underline.FontStyle = FontStyle.Italic;
                    }
                    else
                    {
                        span.FontStyle = FontStyle.Italic;
                    }
                }
            }

            if (underline != null)
            {
                parent.Add(underline);
                context.RenderNode(element, new SpanContainer(underline));
            }
            else
            {
                parent.Add(span);
                context.RenderNode(element, new SpanContainer(span));
            }
        }
Exemplo n.º 56
0
 public void OpenDocument(DocumentId documentId, ITextContainer textContainer)
 {
     OnDocumentOpened(documentId, textContainer);
 }
 // Add a new UIElementPropertyUndoUnit to the undo stack for FlowDirection property.
 internal static void Add(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, FlowDirection newValue)
 {
     AddPrivate(textContainer, uiElement, property, newValue);
 }
Exemplo n.º 58
0
        /// <summary>
        /// Returns the CultureInfoculture of a TextContainer parent.
        /// </summary>
        private static CultureInfo GetDocumentCultureInfo(ITextContainer textContainer)
        {
            CultureInfo cultureInfo = null;

            if (textContainer.Parent != null)
            {
                XmlLanguage language = (XmlLanguage)textContainer.Parent.GetValue(FrameworkElement.LanguageProperty);
                if (language != null)
                {
                    try
                    {
                        cultureInfo = language.GetSpecificCulture();
                    }
                    catch (InvalidOperationException)
                    {
                        // Someone set a bogus language on the document.
                        cultureInfo = null;
                    }
                }
            }

            if (cultureInfo == null)
            {
                cultureInfo = CultureInfo.CurrentCulture;
            }

            return cultureInfo;
        }
Exemplo n.º 59
0
        // Returns the local UndoManager.
        // Returns null if there is no undo service or if the service exists
        // but is disabled or if there is no open parent undo unit.
        internal static UndoManager GetOrClearUndoManager(ITextContainer textContainer)
        {
            UndoManager undoManager;

            undoManager = textContainer.UndoManager;
            if (undoManager == null)
                return null;

            if (!undoManager.IsEnabled)
                return null;

            if (undoManager.OpenedUnit == null)
            {
                // There's no parent undo unit, so we can't open a child.
                //
                // Clear the undo stack -- since we depend on symbol offsets
                // matching the original document state when an undo unit is
                // executed, any of our units currently in the stack will be
                // corrupted after we finished the operation in progress.
                undoManager.Clear();
                return null;
            }

            return undoManager;
        }
        //------------------------------------------------------
        //
        //  Privte Methods
        //
        //------------------------------------------------------

        #region Private Methods
        
        // Private helper that adds a new UIElementPropertyUndoUnit to the undo stack.
        private static void AddPrivate(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, object newValue)
        {
            UndoManager undoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (undoManager == null)
            {
                return;
            }

            object currentValue = uiElement.ReadLocalValue(property);

            if (currentValue is Expression)
            {
                // Can't undo when old value is an expression, so clear the stack.
                if (undoManager.IsEnabled)
                {
                    undoManager.Clear();
                }
                return;
            }

            if (currentValue.Equals(newValue))
            {
                // No property change.
                return;
            }

            undoManager.Add(new UIElementPropertyUndoUnit(uiElement, property, currentValue));
        }