public static void ApplyPropertyToFlowDocument(FlowDocument flowDocument, StylePropertyType propertyType, object value) { switch (propertyType) { case StylePropertyType.FontColor: flowDocument.Foreground = (Brush)value; break; case StylePropertyType.FontSize: flowDocument.FontSize = (double)value; break; case StylePropertyType.IsBold: flowDocument.FontWeight = (bool)value == true ? FontWeights.Bold : FontWeights.Normal; break; case StylePropertyType.IsItalic: flowDocument.FontStyle = (bool)value == true ? FontStyles.Italic : FontStyles.Normal; break; case StylePropertyType.IsStrike: break; case StylePropertyType.IsUnderlined: break; case StylePropertyType.Typeface: flowDocument.FontFamily = (FontFamily)value; break; } }
internal void UpdateStyle(BaseStyle activeStyle, StylePropertyType stylePropertyType, object value) { LevelStyle levelStyle = activeStyle as LevelStyle; InlineNoteStyle inlineStyle = activeStyle as InlineNoteStyle; WalkRecursively(__FakeRootNote, delegate(OutlinerNote note, out bool shouldWalkSubnotes, out bool shouldContinue) { shouldContinue = true; shouldWalkSubnotes = true; if (activeStyle.StyleType == StyleType.Inline) { if (!note.HasInlineNote) { return; } TextRange range = new TextRange(note.InlineNoteDocument.ContentStart, note.InlineNoteDocument.ContentEnd); UndoManager.PushUndoAction(new Undo.UndoFlowDocumentFormatting(note, 0, true, false)); LevelStyle.ApplyPropertyToRange(range, stylePropertyType, value); LevelStyle.ApplyPropertyToFlowDocument(note.InlineNoteDocument, stylePropertyType, value); } else // if (activeStyle.StyleType == StyleType.Level) { if (note.Level == levelStyle.Level || levelStyle.Level == -1) { ApplyStylePropertyForAllColumns(stylePropertyType, value, levelStyle, note); } } }); }
public static void ApplyPropertyToRange(TextRange range, StylePropertyType propertyType, object value) { switch (propertyType) { case StylePropertyType.FontColor: range.ApplyPropertyValue(Run.ForegroundProperty, value); break; case StylePropertyType.FontSize: range.ApplyPropertyValue(Run.FontSizeProperty, (double)value); break; case StylePropertyType.IsBold: TextRangeHelpers.SetBold(range, (bool)value); break; case StylePropertyType.IsItalic: TextRangeHelpers.SetItalic(range, (bool)value); break; case StylePropertyType.IsStrike: TextRangeHelpers.SetTextDecorationOnSelection(range, TextDecorationLocation.Strikethrough, TextDecorations.Strikethrough, (bool)value); break; case StylePropertyType.IsUnderlined: TextRangeHelpers.SetTextDecorationOnSelection(range, TextDecorationLocation.Underline, TextDecorations.Underline, (bool)value); break; case StylePropertyType.Typeface: range.ApplyPropertyValue(Control.FontFamilyProperty, value); break; } }
internal static object GetValueFromString(StylePropertyType propertyType, string value) { switch (propertyType) { case StylePropertyType.FontColor: object c = ColorConverter.ConvertFromString(value); if (c == null) { return(null); } return(new SolidColorBrush((Color)c)); case StylePropertyType.FontSize: double result; if (double.TryParse(value, out result) == false) { return(null); } return(result); case StylePropertyType.IsBold: if (value == bool.TrueString) { return(true); } return(false); case StylePropertyType.IsItalic: if (value == bool.TrueString) { return(true); } return(false); case StylePropertyType.IsStrike: if (value == bool.TrueString) { return(true); } return(false); case StylePropertyType.IsUnderlined: if (value == bool.TrueString) { return(true); } return(false); case StylePropertyType.Typeface: return(new FontFamily(value)); } return(null); }
public void AddProperty(StylePropertyType propertyType, object value) { for (int i = 0; i < __StyleList.Count; i++) { if (__StyleList[i].PropertyType == propertyType) { __StyleList[i].Value = value; UpdateInspectorStyles(); return; } } __StyleList.Add(new LevelStyleProperty(propertyType, value)); UpdateInspectorStyles(); }
private void ApplyStylePropertyForAllColumns(StylePropertyType stylePropertyType, object value, LevelStyle levelStyle, OutlinerNote note) { for (int i = 0; i < note.Columns.Count; i++) { if (note.Columns[i].DataType != ColumnDataType.RichText) { continue; } FlowDocument flowDocument = (FlowDocument)note.Columns[i].ColumnData; TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); UndoManager.PushUndoAction(new Undo.UndoFlowDocumentFormatting(note, i, false, false)); LevelStyle.ApplyPropertyToRange(range, stylePropertyType, value); LevelStyle.ApplyPropertyToFlowDocument(flowDocument, stylePropertyType, value); // If document style gets modified, level style should be applied afterwards if (levelStyle.Level == -1) { LevelStyle currentLevelStyle = note.Document.Styles.GetStyleForLevel(note.Level); for (int si = 0; si < currentLevelStyle.Properties.Count; si++) { if (currentLevelStyle.Properties[si].PropertyType == stylePropertyType) { LevelStyle.ApplyPropertyToRange(range, stylePropertyType, currentLevelStyle.Properties[si].Value); LevelStyle.ApplyPropertyToFlowDocument( flowDocument, stylePropertyType, currentLevelStyle.Properties[si].Value); } } } } }
private bool IsDefaultValue(StylePropertyType propertyType, object value) { if (propertyType == StylePropertyType.FontSize && (double)value == Settings.DefaultFontSize) { return(true); } if (propertyType == StylePropertyType.FontColor && ((SolidColorBrush)value).Equals(Settings.DefaultFontColor)) { return(true); } if (propertyType == StylePropertyType.Typeface && ((FontFamily)value).Equals(Settings.DefaultFontFamily)) { return(true); } if (value is bool && (bool)value == false) { return(true); } return(false); }
private static void ReadStyles(XmlReader reader, OutlinerDocument rnl) { XmlReader subtree = reader.ReadSubtree(); while (subtree.ReadToFollowing("Style")) { if (subtree.MoveToFirstAttribute()) { string type = "Level"; int level = -1; if (subtree.Name == "Type") { type = subtree.Value; if (type == "Level") { subtree.MoveToNextAttribute(); } } if (type == "Level") { if (subtree.Name != "Level") { continue; } try { level = int.Parse(subtree.Value); } catch { continue; } } BaseStyle style; if (type == "Inline") { style = rnl.Styles.InlineNoteStyle; } else { if (level <= 0) { style = rnl.Styles.WholeDocumentStyle; } else { style = rnl.Styles.GetStyleForLevel(level); } } while (subtree.MoveToNextAttribute()) { if (OutlinerStyles.StringToStylePropertyTypes.ContainsKey(subtree.Name)) { StylePropertyType propertyType = OutlinerStyles.StringToStylePropertyTypes[subtree.Name]; object value = LevelStyle.GetValueFromString(propertyType, subtree.Value); if (value != null) { style.AddProperty(propertyType, value); } } } } } }
private bool IsDefaultValue(StylePropertyType propertyType, object value) { if (propertyType == StylePropertyType.FontSize && (double)value == Settings.DefaultFontSize) return true; if (propertyType == StylePropertyType.FontColor && ((SolidColorBrush)value).Equals(Settings.DefaultFontColor)) return true; if (propertyType == StylePropertyType.Typeface && ((FontFamily)value).Equals(Settings.DefaultFontFamily)) return true; if (value is bool && (bool)value == false) return true; return false; }
internal static object GetValueFromString(StylePropertyType propertyType, string value) { switch (propertyType) { case StylePropertyType.FontColor: object c = ColorConverter.ConvertFromString(value); if (c == null) return null; return new SolidColorBrush((Color)c); case StylePropertyType.FontSize: double result; if (double.TryParse(value, out result) == false) return null; return result; case StylePropertyType.IsBold: if (value == bool.TrueString) return true; return false; case StylePropertyType.IsItalic: if (value == bool.TrueString) return true; return false; case StylePropertyType.IsStrike: if (value == bool.TrueString) return true; return false; case StylePropertyType.IsUnderlined: if (value == bool.TrueString) return true; return false; case StylePropertyType.Typeface: return new FontFamily(value); } return null; }
public LevelStyleProperty(StylePropertyType propertyType, object value) { __PropertyType = propertyType; __Value = value; }
private void UpdateStyle(StylePropertyType stylePropertyType, object value) { if (__ActiveStyle == null && Document.AutoStyles == false) return; LevelStyle levelStyle = null; if (__ActiveStyle != null) { Document.UndoManager.PushUndoAction(new UndoStyleChange(__ActiveStyle)); __ActiveStyle.AddProperty(stylePropertyType, value); Document.UpdateStyle(__ActiveStyle, stylePropertyType, value); } else { if (value == null) return; OutlinerNote currentNote = OutlinerTree.SelectedItem; if (currentNote == null) return; if (value == null) return; levelStyle = Document.Styles.GetStyleForLevel(currentNote.Level); Document.UndoManager.PushUndoAction(new UndoStyleChange(levelStyle)); levelStyle.AddProperty(stylePropertyType, value); } }
private object GetPropertyForStyle(StylePropertyType stylePropertyType) { OutlinerNote currentNote = OutlinerTree.SelectedItem; if (currentNote == null) return null; TextRange range = new TextRange(currentNote.DefaultRichTextDocument.ContentStart, currentNote.DefaultRichTextDocument.ContentEnd); switch (stylePropertyType) { case StylePropertyType.IsBold: return TextRangeHelpers.IsBold(range); case StylePropertyType.IsItalic: return TextRangeHelpers.IsItalic(range); case StylePropertyType.IsStrike: return TextRangeHelpers.IsStrike(range); case StylePropertyType.IsUnderlined: return TextRangeHelpers.IsUnderlined(range); } return null; }