|
@@ -1,11 +1,21 @@
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
|
|
+using System.Drawing;
|
|
using System.IO;
|
|
using System.IO;
|
|
|
|
+using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
|
|
+using System.Windows.Controls.Primitives;
|
|
|
|
+using System.Windows.Documents;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
|
|
+using HTMLConverter;
|
|
using InABox.WPF;
|
|
using InABox.WPF;
|
|
|
|
+using NPOI.OpenXmlFormats.Spreadsheet;
|
|
|
|
+using NPOI.OpenXmlFormats.Wordprocessing;
|
|
using Syncfusion.Windows.Controls.RichTextBoxAdv;
|
|
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
|
|
namespace InABox.DynamicGrid
|
|
{
|
|
{
|
|
@@ -41,7 +51,17 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
DataContext = new RichTextEditorViewModel();
|
|
DataContext = new RichTextEditorViewModel();
|
|
|
|
|
|
- Bold.SmallIcon = Properties.Resources.Bold16.AsBitmapImage(16, 16);
|
|
|
|
|
|
+ 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);
|
|
Italic.SmallIcon = Properties.Resources.Italic16.AsBitmapImage(16, 16);
|
|
Italic.SmallIcon = Properties.Resources.Italic16.AsBitmapImage(16, 16);
|
|
Underline.SmallIcon = Properties.Resources.Underline16.AsBitmapImage(16, 16);
|
|
Underline.SmallIcon = Properties.Resources.Underline16.AsBitmapImage(16, 16);
|
|
AlignLeft.SmallIcon = Properties.Resources.AlignTextLeft16.AsBitmapImage(16, 16);
|
|
AlignLeft.SmallIcon = Properties.Resources.AlignTextLeft16.AsBitmapImage(16, 16);
|
|
@@ -52,13 +72,18 @@ namespace InABox.DynamicGrid
|
|
Picture.SmallIcon = Properties.Resources.Picture16.AsBitmapImage(16, 16);
|
|
Picture.SmallIcon = Properties.Resources.Picture16.AsBitmapImage(16, 16);
|
|
Table.SmallIcon = Properties.Resources.Table16.AsBitmapImage(16, 16);
|
|
Table.SmallIcon = Properties.Resources.Table16.AsBitmapImage(16, 16);
|
|
ZoomIn.SmallIcon = Properties.Resources.zoomin.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.FontFamily = new FontFamily("Calibri");
|
|
Editor.FontSize = 12.0F;
|
|
Editor.FontSize = 12.0F;
|
|
- Editor.Foreground = new SolidColorBrush(Colors.Black);
|
|
|
|
|
|
+ Editor.Foreground = new SolidColorBrush(Colors.Black);*/
|
|
ZoomFactor = 150;
|
|
ZoomFactor = 150;
|
|
- Text = "";
|
|
|
|
|
|
+ //Text = "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ConfigureButton(ButtonBase button, Bitmap image)
|
|
|
|
+ {
|
|
|
|
+ button.Content = new Image { Source = image.AsBitmapImage(16, 16), Width = 16, Height = 16 };
|
|
}
|
|
}
|
|
|
|
|
|
public bool HideToolbar
|
|
public bool HideToolbar
|
|
@@ -77,7 +102,7 @@ namespace InABox.DynamicGrid
|
|
set
|
|
set
|
|
{
|
|
{
|
|
SetValue(ZoomFactorProperty, value);
|
|
SetValue(ZoomFactorProperty, value);
|
|
- Editor.ZoomFactor = value;
|
|
|
|
|
|
+ //Editor.ZoomFactor = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -95,7 +120,7 @@ namespace InABox.DynamicGrid
|
|
set
|
|
set
|
|
{
|
|
{
|
|
SetValue(ColorProperty, value);
|
|
SetValue(ColorProperty, value);
|
|
- Editor.Background = new SolidColorBrush(value);
|
|
|
|
|
|
+ //Editor.Background = new SolidColorBrush(value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,8 +130,15 @@ namespace InABox.DynamicGrid
|
|
content = "";
|
|
content = "";
|
|
|
|
|
|
content = content.Replace("background:#000000", "").Replace("background:NoColor;", "");
|
|
content = content.Replace("background:#000000", "").Replace("background:NoColor;", "");
|
|
- var ms = new MemoryStream(Encoding.ASCII.GetBytes(content));
|
|
|
|
- Editor.Load(ms, FormatType.Html);
|
|
|
|
|
|
+ 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);
|
|
VerticalAlignment = VerticalAlignment.Top;
|
|
VerticalAlignment = VerticalAlignment.Top;
|
|
VerticalAlignment = VerticalAlignment.Stretch;
|
|
VerticalAlignment = VerticalAlignment.Stretch;
|
|
|
|
|
|
@@ -120,7 +152,9 @@ namespace InABox.DynamicGrid
|
|
if (bdirty)
|
|
if (bdirty)
|
|
{
|
|
{
|
|
var ms = new MemoryStream();
|
|
var ms = new MemoryStream();
|
|
- Editor.Save(ms, FormatType.Html);
|
|
|
|
|
|
+ //Editor.Save(ms, FormatType.Html);
|
|
|
|
+ var range = new TextRange(RtbEditor.Document.ContentStart, RtbEditor.Document.ContentEnd);
|
|
|
|
+ range.Save(ms, DataFormats.Xaml);
|
|
var reader = new StreamReader(ms);
|
|
var reader = new StreamReader(ms);
|
|
curvalue = Encoding.UTF8.GetString(ms.GetBuffer());
|
|
curvalue = Encoding.UTF8.GetString(ms.GetBuffer());
|
|
curvalue = curvalue.Replace("background:#000000", "");
|
|
curvalue = curvalue.Replace("background:#000000", "");
|
|
@@ -138,7 +172,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
public void SetColor(Color color)
|
|
public void SetColor(Color color)
|
|
{
|
|
{
|
|
- Editor.Background = new SolidColorBrush(color);
|
|
|
|
|
|
+ //Editor.Background = new SolidColorBrush(color);
|
|
}
|
|
}
|
|
|
|
|
|
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
@@ -157,12 +191,12 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void ZoomIn_Click(object sender, RoutedEventArgs e)
|
|
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)
|
|
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)
|
|
private void Editor_RequestNavigate(object obj, RequestNavigateEventArgs args)
|
|
@@ -171,5 +205,68 @@ namespace InABox.DynamicGrid
|
|
processStartInfo.UseShellExecute = true;
|
|
processStartInfo.UseShellExecute = true;
|
|
Process.Start(processStartInfo);
|
|
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;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|