Esempio n. 1
0
        private void OnPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            if (e.Property.Name == FontFamilyProperty.Name)
            {
                FontFamily ff = (FontFamily)e.NewValue;
                using (var us = new Utf8String(ff.Source))
                {
                    _scintilla.CallScintilla(SCI_STYLESETFONT, new IntPtr(Index), us.Pointer);
                }
                return;
            }

            if (e.Property.Name == FontSizeProperty.Name)
            {
                double size = (double)e.NewValue;
                _scintilla.CallScintilla(SCI_STYLESETSIZE, Index, (int)size);
                return;
            }

            if (e.Property.Name == ForegroundProperty.Name)
            {
                _scintilla.CallScintilla(SCI_STYLESETFORE, Index, ToScintillaColor(Foreground, Colors.Black));
                return;
            }

            if (e.Property.Name == BackgroundProperty.Name)
            {
                _scintilla.CallScintilla(SCI_STYLESETBACK, Index, ToScintillaColor(Background, Colors.White));
                return;
            }

            if (e.Property.Name == FontWeightProperty.Name)
            {
                FontWeight w = (FontWeight)e.NewValue;
                int        h = w.GetHashCode(); // yes, it's the value
                _scintilla.CallScintilla(SCI_STYLESETWEIGHT, Index, h);
                return;
            }

            if (e.Property.Name == TextDecorationsProperty.Name)
            {
                bool underline = false;
                foreach (var td in TextDecorations)
                {
                    if (td.Location == TextDecorationLocation.Underline)
                    {
                        underline = true;
                        _scintilla.CallScintilla(SCI_STYLESETUNDERLINE, Index, 1);
                    }
                }

                if (!underline)
                {
                    _scintilla.CallScintilla(SCI_STYLESETUNDERLINE, Index, 0);
                }
                return;
            }

            if (e.Property.Name == IsVisibleProperty.Name)
            {
                _scintilla.CallScintilla(SCI_STYLESETVISIBLE, Index, (bool)e.NewValue ? 1 : 0);
                return;
            }

            if (e.Property.Name == FontStyleProperty.Name)
            {
                FontStyle s = (FontStyle)e.NewValue;
                if (FontStyles.Italic.Equals(s))
                {
                    _scintilla.CallScintilla(SCI_STYLESETITALIC, Index, 1);
                }
                else if (FontStyles.Normal.Equals(s))
                {
                    _scintilla.CallScintilla(SCI_STYLESETITALIC, Index, 0);
                }
                return;
            }
        }