Beispiel #1
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);
        }
Beispiel #2
0
        private static CultureInfo GetCultureInfo(DependencyObject element)
        {
            XmlLanguage language = (XmlLanguage)element.GetValue(FrameworkElement.LanguageProperty);

            try {
                return(language.GetSpecificCulture());
            }
            catch (InvalidOperationException) {
                // We default to en-US if no part of the language tag is recognized.
                return(CultureInfo.ReadOnly(new CultureInfo("en-us", false)));
            }
        }
Beispiel #3
0
        // ------------------------------------------------------------------
        // Retrieve CultureInfo property from specified element.
        // ------------------------------------------------------------------
        internal static CultureInfo GetCultureInfo(DependencyObject element)
        {
            XmlLanguage language = (XmlLanguage)element.GetValue(FrameworkElement.LanguageProperty);

            try
            {
                return(language.GetSpecificCulture());
            }
            catch (InvalidOperationException)
            {
                // We default to en-US if no part of the language tag is recognized.
                return(System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
            }
        }
Beispiel #4
0
        // Token: 0x0600661B RID: 26139 RVA: 0x001CB5B8 File Offset: 0x001C97B8
        internal static CultureInfo GetCultureInfo(DependencyObject element)
        {
            XmlLanguage xmlLanguage = (XmlLanguage)element.GetValue(FrameworkElement.LanguageProperty);
            CultureInfo result;

            try
            {
                result = xmlLanguage.GetSpecificCulture();
            }
            catch (InvalidOperationException)
            {
                result = TypeConverterHelper.InvariantEnglishUS;
            }
            return(result);
        }
Beispiel #5
0
 public static CultureInfo GetCultureInfo(this XmlLanguage language)
 {
     try
     {
         if (language == null)
         {
             return(InvariantEnglishUS);
         }
         return(language.GetSpecificCulture());
     }
     catch (InvalidOperationException)
     {
         // We default to en-US if no part of the language tag is recognized.
         return(InvariantEnglishUS);
     }
 }
            private void DoDefaultExpansion(TextBlock textBlock, object content, ContentPresenter container)
            {
                Debug.Assert(!(content is String) && !(content is UIElement));  // these are handled by different templates

                Inline inline;

                if ((inline = content as Inline) != null)
                {
                    textBlock.Inlines.Add(inline);
                }
                else
                {
                    bool        succeeded = false;
                    string      stringFormat;
                    XmlLanguage language = container.Language;
                    System.Globalization.CultureInfo culture = language.GetSpecificCulture();
                    container.CacheLanguage(language);

                    if ((stringFormat = container.ContentStringFormat) != null)
                    {
                        try
                        {
                            stringFormat   = Helper.GetEffectiveStringFormat(stringFormat);
                            textBlock.Text = String.Format(culture, stringFormat, content);
                            succeeded      = true;
                        }
                        catch (FormatException)
                        {
                        }
                    }

                    if (!succeeded)
                    {
                        TypeConverter tc      = TypeDescriptor.GetConverter(ReflectionHelper.GetReflectionType(content));
                        TypeContext   context = new TypeContext(content);
                        if (tc != null && (tc.CanConvertTo(context, typeof(String))))
                        {
                            textBlock.Text = (string)tc.ConvertTo(context, culture, content, typeof(string));
                        }
                        else
                        {
                            Debug.Assert(!(tc != null && tc.CanConvertTo(typeof(UIElement))));  // this is handled by a different template
                            textBlock.Text = String.Format(culture, "{0}", content);
                        }
                    }
                }
            }
        /// <summary>
        /// The GetArgumentValue
        /// </summary>
        /// <param name="eventArgs">The <see cref="EventArgs" /></param>
        /// <param name="language">The <see cref="XmlLanguage" /></param>
        /// <returns>The <see cref="object" /></returns>
        internal object GetArgumentValue(EventArgs eventArgs, XmlLanguage language)
        {
            if (Path == null)
            {
                return(eventArgs);
            }

            var value = PropertyPathHelpers.Evaluate(Path, eventArgs);

            if (Converter != null)
            {
                value = Converter.Convert(value, ConverterTargetType ?? typeof(object), ConverterParameter,
                                          ConverterCulture ?? language.GetSpecificCulture());
            }

            return(value);
        }
Beispiel #8
0
        // Token: 0x060038D7 RID: 14551 RVA: 0x00100D38 File Offset: 0x000FEF38
        private static void OnCorrectSpellingError(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null)
            {
                return;
            }
            string text = args.Parameter as string;

            if (text == null)
            {
                return;
            }
            SpellingError spellingErrorAtSelection = TextEditorSpelling.GetSpellingErrorAtSelection(textEditor);

            if (spellingErrorAtSelection == null)
            {
                return;
            }
            using (textEditor.Selection.DeclareChangeBlock())
            {
                ITextPointer textPointer;
                ITextPointer position;
                bool         flag = TextEditorSpelling.IsErrorAtNonMergeableInlineEdge(spellingErrorAtSelection, out textPointer, out position);
                ITextPointer textPointer2;
                if (flag && textPointer is TextPointer)
                {
                    ((TextPointer)textPointer).DeleteTextInRun(textPointer.GetOffsetToPosition(position));
                    textPointer.InsertTextInRun(text);
                    textPointer2 = textPointer.CreatePointer(text.Length, LogicalDirection.Forward);
                }
                else
                {
                    textEditor.Selection.Select(spellingErrorAtSelection.Start, spellingErrorAtSelection.End);
                    if (textEditor.AcceptsRichContent)
                    {
                        ((TextSelection)textEditor.Selection).SpringloadCurrentFormatting();
                    }
                    XmlLanguage xmlLanguage = (XmlLanguage)spellingErrorAtSelection.Start.GetValue(FrameworkElement.LanguageProperty);
                    textEditor.SetSelectedText(text, xmlLanguage.GetSpecificCulture());
                    textPointer2 = textEditor.Selection.End;
                }
                textEditor.Selection.Select(textPointer2, textPointer2);
            }
        }
            // Token: 0x0600872F RID: 34607 RVA: 0x0024F1C0 File Offset: 0x0024D3C0
            private void DoDefaultExpansion(TextBlock textBlock, object content, ContentPresenter container)
            {
                Inline item;

                if ((item = (content as Inline)) != null)
                {
                    textBlock.Inlines.Add(item);
                    return;
                }
                bool        flag            = false;
                XmlLanguage language        = container.Language;
                CultureInfo specificCulture = language.GetSpecificCulture();

                container.CacheLanguage(language);
                string text;

                if ((text = container.ContentStringFormat) != null)
                {
                    try
                    {
                        text           = Helper.GetEffectiveStringFormat(text);
                        textBlock.Text = string.Format(specificCulture, text, new object[]
                        {
                            content
                        });
                        flag = true;
                    }
                    catch (FormatException)
                    {
                    }
                }
                if (!flag)
                {
                    TypeConverter converter = TypeDescriptor.GetConverter(ReflectionHelper.GetReflectionType(content));
                    ContentPresenter.DefaultTemplate.TypeContext context = new ContentPresenter.DefaultTemplate.TypeContext(content);
                    if (converter != null && converter.CanConvertTo(context, typeof(string)))
                    {
                        textBlock.Text = (string)converter.ConvertTo(context, specificCulture, content, typeof(string));
                        return;
                    }
                    textBlock.Text = string.Format(specificCulture, "{0}", new object[]
                    {
                        content
                    });
                }
            }
        // Token: 0x0600580D RID: 22541 RVA: 0x00186220 File Offset: 0x00184420
        private static CultureInfo GetCulture(DependencyObject element)
        {
            object      value  = element.GetValue(FrameworkElement.LanguageProperty);
            CultureInfo result = null;

            if (value != null)
            {
                XmlLanguage xmlLanguage = (XmlLanguage)value;
                try
                {
                    result = xmlLanguage.GetSpecificCulture();
                }
                catch (InvalidOperationException)
                {
                }
            }
            return(result);
        }
Beispiel #11
0
        private static CultureInfo GetCulture(DependencyObject element)
        {
            object      o       = element.GetValue(FrameworkElement.LanguageProperty);
            CultureInfo culture = null;

            if (o != null)
            {
                XmlLanguage language = (XmlLanguage)o;
                try
                {
                    culture = language.GetSpecificCulture();
                }
                catch (InvalidOperationException)
                {
                }
            }

            return(culture);
        }
Beispiel #12
0
        /// <summary>
        /// Return the default view for the given source.  This view is never
        /// affiliated with any CollectionViewSource.  The internal version sets
        /// the culture on the view from the xml:Lang of the host object.
        /// </summary>
        internal static CollectionView GetDefaultCollectionView(object source, DependencyObject d, Func <object, object> GetSourceItem = null)
        {
            CollectionView view = GetDefaultCollectionView(source, true, GetSourceItem);

            // at first use of a view, set its culture from the xml:lang of the
            // element that's using the view
            if (view != null && view.Culture == null)
            {
                XmlLanguage language = (d != null) ? (XmlLanguage)d.GetValue(FrameworkElement.LanguageProperty) : null;
                if (language != null)
                {
                    try
                    {
                        view.Culture = language.GetSpecificCulture();
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
            }

            return(view);
        }
Beispiel #13
0
        internal object?GetArgumentValue(EventArgs eventArgs, XmlLanguage?language)
        {
            if (Path == null)
            {
                return(eventArgs);
            }

            object?value = PropertyPathHelper.Evaluate(Path, eventArgs);

            if (Converter != null)
            {
                value = Converter.Convert(value, ConverterTargetType, ConverterParameter, ConverterCulture ?? language?.GetSpecificCulture() ?? CultureInfo.CurrentUICulture);
            }

            return(value);
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Callback for EditingCommands.CorrectSpellingError.
        //
        // Corrects the error pointed to by Selection.Start with the string
        // specified in args.Data.
        private static void OnCorrectSpellingError(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(target);

            if (This == null)
            {
                return;
            }

            string correctedText = args.Parameter as string;

            if (correctedText == null)
            {
                return;
            }

            SpellingError spellingError = GetSpellingErrorAtSelection(This);

            if (spellingError == null)
            {
                return;
            }

            using (This.Selection.DeclareChangeBlock())
            {
                ITextPointer textStart;
                ITextPointer textEnd;
                bool         dontUseRange = IsErrorAtNonMergeableInlineEdge(spellingError, out textStart, out textEnd);

                ITextPointer caretPosition;

                if (dontUseRange && textStart is TextPointer)
                {
                    // We need a cast because ITextPointer's equivalent to DeleteTextInRun (DeleteContentToPostiion)
                    // will remove empty TextElements, which we do not want.
                    ((TextPointer)textStart).DeleteTextInRun(textStart.GetOffsetToPosition(textEnd));
                    textStart.InsertTextInRun(correctedText);
                    caretPosition = textStart.CreatePointer(+correctedText.Length, LogicalDirection.Forward);
                }
                else
                {
                    This.Selection.Select(spellingError.Start, spellingError.End);

                    // Setting range.Text to correctedText might inadvertantly apply previous Run's formatting properties.
                    // Save current formatting to avoid this.
                    if (This.AcceptsRichContent)
                    {
                        ((TextSelection)This.Selection).SpringloadCurrentFormatting();
                    }

                    // TextEditor.SetSelectedText() replaces current selection with new text and
                    // also applies any springloaded properties to the text.
                    XmlLanguage language = (XmlLanguage)spellingError.Start.GetValue(FrameworkElement.LanguageProperty);
                    This.SetSelectedText(correctedText, language.GetSpecificCulture());

                    caretPosition = This.Selection.End;
                }

                // Collapse the selection to a caret following the new text.
                This.Selection.Select(caretPosition, caretPosition);
            }
        }