|
@@ -1,21 +1,12 @@
|
|
|
using System.Diagnostics;
|
|
|
-using System.Drawing;
|
|
|
using System.IO;
|
|
|
-using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
-using System.Windows.Controls.Primitives;
|
|
|
using System.Windows.Documents;
|
|
|
using System.Windows.Media;
|
|
|
-using HTMLConverter;
|
|
|
using InABox.WPF;
|
|
|
-using NPOI.OpenXmlFormats.Spreadsheet;
|
|
|
-using NPOI.OpenXmlFormats.Wordprocessing;
|
|
|
using Syncfusion.Windows.Controls.RichTextBoxAdv;
|
|
|
-using Color = System.Windows.Media.Color;
|
|
|
-using Image = System.Windows.Controls.Image;
|
|
|
-using Inline = System.Windows.Documents.Inline;
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
|
{
|
|
@@ -51,17 +42,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
DataContext = new RichTextEditorViewModel();
|
|
|
|
|
|
- ConfigureButton(BoldBtn, Properties.Resources.Bold16);
|
|
|
- ConfigureButton(ItalicBtn, Properties.Resources.Italic16);
|
|
|
- ConfigureButton(UnderlineBtn, Properties.Resources.Underline16);
|
|
|
-
|
|
|
- ConfigureButton(AlignLeftBtn, Properties.Resources.AlignTextLeft16);
|
|
|
- ConfigureButton(AlignCenterBtn, Properties.Resources.AlignTextCenter16);
|
|
|
- ConfigureButton(AlignRightBtn, Properties.Resources.AlignTextRight16);
|
|
|
- ConfigureButton(AlignJustifyBtn, Properties.Resources.AlignTextJustify16);
|
|
|
-
|
|
|
- ConfigureButton(HyperlinkBtn, Properties.Resources.Hyperlink16);
|
|
|
- /*Bold.SmallIcon = Properties.Resources.Bold16.AsBitmapImage(16, 16);
|
|
|
+ Bold.SmallIcon = Properties.Resources.Bold16.AsBitmapImage(16, 16);
|
|
|
Italic.SmallIcon = Properties.Resources.Italic16.AsBitmapImage(16, 16);
|
|
|
Underline.SmallIcon = Properties.Resources.Underline16.AsBitmapImage(16, 16);
|
|
|
AlignLeft.SmallIcon = Properties.Resources.AlignTextLeft16.AsBitmapImage(16, 16);
|
|
@@ -72,18 +53,13 @@ namespace InABox.DynamicGrid
|
|
|
Picture.SmallIcon = Properties.Resources.Picture16.AsBitmapImage(16, 16);
|
|
|
Table.SmallIcon = Properties.Resources.Table16.AsBitmapImage(16, 16);
|
|
|
ZoomIn.SmallIcon = Properties.Resources.zoomin.AsBitmapImage(16, 16);
|
|
|
- ZoomOut.SmallIcon = Properties.Resources.zoomout.AsBitmapImage(16, 16);*/
|
|
|
- /*Editor.CaretBrush = new SolidColorBrush(Colors.Black);
|
|
|
+ ZoomOut.SmallIcon = Properties.Resources.zoomout.AsBitmapImage(16, 16);
|
|
|
+ Editor.CaretBrush = new SolidColorBrush(Colors.Black);
|
|
|
Editor.FontFamily = new FontFamily("Calibri");
|
|
|
Editor.FontSize = 12.0F;
|
|
|
- Editor.Foreground = new SolidColorBrush(Colors.Black);*/
|
|
|
+ Editor.Foreground = new SolidColorBrush(Colors.Black);
|
|
|
ZoomFactor = 150;
|
|
|
- //Text = "";
|
|
|
- }
|
|
|
-
|
|
|
- private void ConfigureButton(ButtonBase button, Bitmap image)
|
|
|
- {
|
|
|
- button.Content = new Image { Source = image.AsBitmapImage(16, 16), Width = 16, Height = 16 };
|
|
|
+ Text = "";
|
|
|
}
|
|
|
|
|
|
public bool HideToolbar
|
|
@@ -102,7 +78,7 @@ namespace InABox.DynamicGrid
|
|
|
set
|
|
|
{
|
|
|
SetValue(ZoomFactorProperty, value);
|
|
|
- //Editor.ZoomFactor = value;
|
|
|
+ Editor.ZoomFactor = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -120,7 +96,7 @@ namespace InABox.DynamicGrid
|
|
|
set
|
|
|
{
|
|
|
SetValue(ColorProperty, value);
|
|
|
- //Editor.Background = new SolidColorBrush(value);
|
|
|
+ Editor.Background = new SolidColorBrush(value);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -130,15 +106,8 @@ namespace InABox.DynamicGrid
|
|
|
content = "";
|
|
|
|
|
|
content = content.Replace("background:#000000", "").Replace("background:NoColor;", "");
|
|
|
- var xaml = content;
|
|
|
- if (xaml.StartsWith("<html>"))
|
|
|
- {
|
|
|
- xaml = HtmlToXamlConverter.ConvertHtmlToXaml(xaml, false);
|
|
|
- }
|
|
|
- var ms = new MemoryStream(Encoding.ASCII.GetBytes(xaml));
|
|
|
- var range = new TextRange(RtbEditor.Document.ContentStart, RtbEditor.Document.ContentEnd);
|
|
|
- range.Load(ms, DataFormats.Text);
|
|
|
- //Editor.Load(ms, FormatType.Html);
|
|
|
+ var ms = new MemoryStream(Encoding.ASCII.GetBytes(content));
|
|
|
+ Editor.Load(ms, FormatType.Html);
|
|
|
VerticalAlignment = VerticalAlignment.Top;
|
|
|
VerticalAlignment = VerticalAlignment.Stretch;
|
|
|
|
|
@@ -152,9 +121,7 @@ namespace InABox.DynamicGrid
|
|
|
if (bdirty)
|
|
|
{
|
|
|
var ms = new MemoryStream();
|
|
|
- //Editor.Save(ms, FormatType.Html);
|
|
|
- var range = new TextRange(RtbEditor.Document.ContentStart, RtbEditor.Document.ContentEnd);
|
|
|
- range.Save(ms, DataFormats.Xaml);
|
|
|
+ Editor.Save(ms, FormatType.Html);
|
|
|
var reader = new StreamReader(ms);
|
|
|
curvalue = Encoding.UTF8.GetString(ms.GetBuffer());
|
|
|
curvalue = curvalue.Replace("background:#000000", "");
|
|
@@ -172,7 +139,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
public void SetColor(Color color)
|
|
|
{
|
|
|
- //Editor.Background = new SolidColorBrush(color);
|
|
|
+ Editor.Background = new SolidColorBrush(color);
|
|
|
}
|
|
|
|
|
|
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
@@ -191,12 +158,12 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void ZoomIn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- //Editor.ZoomFactor = Editor.ZoomFactor * 1.5F;
|
|
|
+ Editor.ZoomFactor = Editor.ZoomFactor * 1.5F;
|
|
|
}
|
|
|
|
|
|
private void ZoomOut_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- //Editor.ZoomFactor = Editor.ZoomFactor / 1.5F;
|
|
|
+ Editor.ZoomFactor = Editor.ZoomFactor / 1.5F;
|
|
|
}
|
|
|
|
|
|
private void Editor_RequestNavigate(object obj, RequestNavigateEventArgs args)
|
|
@@ -205,68 +172,5 @@ namespace InABox.DynamicGrid
|
|
|
processStartInfo.UseShellExecute = true;
|
|
|
Process.Start(processStartInfo);
|
|
|
}
|
|
|
-
|
|
|
- private bool SelectionHasProperty(DependencyProperty property, object? value)
|
|
|
- {
|
|
|
- var temp = RtbEditor.Selection.GetPropertyValue(property);
|
|
|
- return temp != DependencyProperty.UnsetValue && temp.Equals(value);
|
|
|
- }
|
|
|
- private object? SelectionProperty(DependencyProperty property)
|
|
|
- {
|
|
|
- return RtbEditor.Selection.GetPropertyValue(property);
|
|
|
- }
|
|
|
-
|
|
|
- private void UpdateButtons()
|
|
|
- {
|
|
|
- BoldBtn.IsChecked = SelectionHasProperty(Inline.FontWeightProperty, FontWeights.Bold);
|
|
|
- ItalicBtn.IsChecked = SelectionHasProperty(Inline.FontStyleProperty, FontStyles.Italic);
|
|
|
- UnderlineBtn.IsChecked = SelectionHasProperty(Inline.TextDecorationsProperty, TextDecorations.Underline);
|
|
|
-
|
|
|
- AlignLeftBtn.IsChecked = SelectionHasProperty(FlowDocument.TextAlignmentProperty, TextAlignment.Left);
|
|
|
- AlignCenterBtn.IsChecked = SelectionHasProperty(FlowDocument.TextAlignmentProperty, TextAlignment.Center);
|
|
|
- AlignRightBtn.IsChecked = SelectionHasProperty(FlowDocument.TextAlignmentProperty, TextAlignment.Right);
|
|
|
- AlignJustifyBtn.IsChecked = SelectionHasProperty(FlowDocument.TextAlignmentProperty, TextAlignment.Justify);
|
|
|
-
|
|
|
- FontFamilyComboBox.SelectedItem = SelectionProperty(FlowDocument.FontFamilyProperty);
|
|
|
- FontSizeComboBox.Text = SelectionProperty(FlowDocument.FontSizeProperty)?.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- private void RtbEditor_SelectionChanged(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- UpdateButtons();
|
|
|
- }
|
|
|
-
|
|
|
- private void fontFamilyCombo_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
|
- {
|
|
|
- if(FontFamilyComboBox.SelectedItem != null)
|
|
|
- {
|
|
|
- RtbEditor.Selection.ApplyPropertyValue(FlowDocument.FontFamilyProperty, FontFamilyComboBox.SelectedItem);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void fontSizeCombo_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
- {
|
|
|
- var currentValue = SelectionProperty(FlowDocument.FontSizeProperty)?.ToString();
|
|
|
-
|
|
|
- var fontSize = FontSizeComboBox.Text;
|
|
|
- if(double.TryParse(fontSize, out var size))
|
|
|
- {
|
|
|
- RtbEditor.Selection.ApplyPropertyValue(FlowDocument.FontSizeProperty, size);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- FontSizeComboBox.Text = currentValue;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void RtbEditor_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
- {
|
|
|
- UpdateButtons();
|
|
|
- }
|
|
|
-
|
|
|
- private void HyperlinkBtn_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- var selection = RtbEditor.Selection.Text;
|
|
|
- }
|
|
|
}
|
|
|
}
|