|
@@ -8,6 +8,7 @@ using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using System.Windows.Controls.Primitives;
|
|
|
using System.Windows.Data;
|
|
|
using System.Windows.Documents;
|
|
|
using System.Windows.Input;
|
|
@@ -21,22 +22,44 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
/// <summary>
|
|
|
/// StickyNotePopup.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
+
|
|
|
+ public class GripThumb : Thumb
|
|
|
+ {
|
|
|
+ private Pen DrawPen;
|
|
|
+ private Brush FillBrush;
|
|
|
+ public GripThumb()
|
|
|
+ {
|
|
|
+ DefaultStyleKey = typeof(GripThumb);
|
|
|
+ DrawPen = new Pen(new SolidColorBrush(Colors.Blue), 2);
|
|
|
+ FillBrush = new SolidColorBrush(Color.FromArgb(0x0A, 0xFF, 0xFF, 0xFF));
|
|
|
+ }
|
|
|
+ protected override void OnRender(DrawingContext DrawContext)
|
|
|
+ {
|
|
|
+ DrawContext.DrawRectangle(FillBrush, null, new Rect(0, 0, Width, Height));
|
|
|
+ DrawContext.DrawLine(DrawPen, new Point(Width, 0), new Point(0, Height));
|
|
|
+ DrawContext.DrawLine(DrawPen, new Point(Width, Height / 3), new Point(Width / 3, Height));
|
|
|
+ DrawContext.DrawLine(DrawPen, new Point(Width, Height * 2 / 3), new Point(Width * 2 / 3, Height));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// StickyNotePopup.xaml 的交互逻辑
|
|
|
+ /// </summary>
|
|
|
public partial class StickyNotePopup : StickyPopupExt
|
|
|
{
|
|
|
private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
|
|
|
private Point PressPoint;
|
|
|
public Point OffsetParent;
|
|
|
+
|
|
|
private byte saveOpacity = 1;
|
|
|
- public bool CanMove { get; set; } = true;
|
|
|
public StickyNotePopup()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
AddHandler(MouseUpEvent, new MouseButtonEventHandler(StickyPopupControl_MouseUp), true);
|
|
|
ContentText.AddHandler(MouseDownEvent, new MouseButtonEventHandler(StickyPopupControl_MouseDown), true);
|
|
|
Loaded += StickyPopupControl_Loaded;
|
|
|
- Unloaded += StickyPopupControl_Unloaded;
|
|
|
ContentText.GotFocus += ContentText_GotFocus;
|
|
|
ContentText.LostFocus += ContentText_LostFocus;
|
|
|
+
|
|
|
colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10)));
|
|
|
colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0x10, 0x10)));
|
|
|
colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
|
|
@@ -44,7 +67,6 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
ListColor.ItemsSource = colors;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void ContentText_LostFocus(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
e.Handled = true;
|
|
@@ -52,10 +74,6 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
bkColor.A = saveOpacity;
|
|
|
border.BorderBrush = new SolidColorBrush(bkColor);
|
|
|
CloseText_MouseUp(this, null);
|
|
|
- border.BorderBrush = this.Background;
|
|
|
- this.Background = new SolidColorBrush(Colors.Transparent);
|
|
|
- AuthorText.Text = this.Author;
|
|
|
- DateTextui.Text = this.DateText;
|
|
|
}
|
|
|
|
|
|
private void ContentText_GotFocus(object sender, RoutedEventArgs e)
|
|
@@ -64,19 +82,13 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
saveOpacity = bkColor.A;
|
|
|
bkColor.A = 255;
|
|
|
border.BorderBrush = new SolidColorBrush(bkColor);
|
|
|
-
|
|
|
- border.BorderBrush = this.Background;
|
|
|
- this.Background = new SolidColorBrush(Colors.Transparent);
|
|
|
- AuthorText.Text = this.Author;
|
|
|
- DateTextui.Text = this.DateText;
|
|
|
+ this.Background = new SolidColorBrush(this.StickyColor);
|
|
|
}
|
|
|
|
|
|
private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ContentText.Focus();
|
|
|
ContentText.CaretIndex = ContentText.Text.Length;
|
|
|
- ContentText.Text = this.StickyNote;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e)
|
|
@@ -87,6 +99,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
private void StickyPopupControl_MouseUp(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
CanMove = true;
|
|
|
+ GripControl.ReleaseMouseCapture();
|
|
|
}
|
|
|
|
|
|
public string StickyText
|
|
@@ -101,6 +114,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public string StickyAuthor
|
|
|
{
|
|
|
get
|
|
@@ -117,11 +131,39 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- return DateTextui.Text;
|
|
|
+ return DateText.Text;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
- DateTextui.Text = value;
|
|
|
+ DateText.Text = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool CanMove { get; set; } = true;
|
|
|
+ private void ResizeGrip_MouseMove(object sender, MouseEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ if (e.LeftButton == MouseButtonState.Pressed)
|
|
|
+ {
|
|
|
+ Point currentPos = e.GetPosition(ContainerElement);
|
|
|
+ double newWidth = GridUi.ActualWidth + currentPos.X - PressPoint.X;
|
|
|
+ double newHeight = GridUi.ActualHeight + currentPos.Y - PressPoint.Y;
|
|
|
+ if (Left + newWidth >= ContainerElement.ActualWidth)
|
|
|
+ {
|
|
|
+ newWidth = ContainerElement.ActualWidth - Left - 5;
|
|
|
+ }
|
|
|
+ if (Top + newHeight >= ContainerElement.ActualHeight)
|
|
|
+ {
|
|
|
+ newHeight = ContainerElement.ActualHeight - Top - 5;
|
|
|
+ }
|
|
|
+ GridUi.Width = newWidth;
|
|
|
+ GridUi.Height = newHeight;
|
|
|
+ PressPoint = currentPos;
|
|
|
+ CanMove = false;
|
|
|
+ if (GripControl.IsMouseCaptured == false)
|
|
|
+ {
|
|
|
+ GripControl.CaptureMouse();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,19 +182,142 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected override void OnMouseDown(MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ PressPoint = e.GetPosition(ContainerElement);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnMouseEnter(MouseEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ if (PlaceChange != null)
|
|
|
+ {
|
|
|
+ PlaceChange.Invoke(this, new EventArgs());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnMouseLeave(MouseEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ if (PlaceChange != null)
|
|
|
+ {
|
|
|
+ PlaceChange.Invoke(null, new EventArgs());
|
|
|
+ }
|
|
|
+ PressPoint = new Point(0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnMouseUp(MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ CanMove = true;
|
|
|
+ if (PlaceChange != null)
|
|
|
+ {
|
|
|
+ PlaceChange.Invoke(this, new EventArgs());
|
|
|
+ }
|
|
|
+ PressPoint = new Point(0, 0);
|
|
|
+ GripControl.ReleaseMouseCapture();
|
|
|
+ }
|
|
|
+ protected override void OnMouseMove(MouseEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ if (e.LeftButton == MouseButtonState.Pressed && e.Source.GetType() != typeof(TextBox) && e.Source.GetType() != typeof(GripThumb))
|
|
|
+ {
|
|
|
+ if (CanMove == false || (PressPoint.X == 0 && PressPoint.Y == 0))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Point currentPoint = e.GetPosition(ContainerElement);
|
|
|
+ double newLeft = Left + currentPoint.X - PressPoint.X;
|
|
|
+ double newTop = Top + currentPoint.Y - PressPoint.Y;
|
|
|
+ if (newLeft < 0)
|
|
|
+ {
|
|
|
+ newLeft = 0;
|
|
|
+ }
|
|
|
+ if (newLeft + GridUi.ActualWidth > ContainerElement.ActualWidth)
|
|
|
+ {
|
|
|
+ newLeft = ContainerElement.ActualWidth - GridUi.ActualWidth;
|
|
|
+ }
|
|
|
+ if (newTop < 0)
|
|
|
+ {
|
|
|
+ newTop = 0;
|
|
|
+ }
|
|
|
+ if (newTop + GridUi.ActualHeight > ContainerElement.ActualHeight)
|
|
|
+ {
|
|
|
+ newTop = ContainerElement.ActualHeight - GridUi.ActualHeight;
|
|
|
+ }
|
|
|
+ Left = newLeft;
|
|
|
+ Top = newTop;
|
|
|
+ PressPoint = currentPoint;
|
|
|
+ if (PlaceChange != null)
|
|
|
+ {
|
|
|
+ PlaceChange.Invoke(null, new EventArgs());
|
|
|
+ }
|
|
|
+ RefreshPosition();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetAuthor(string author)
|
|
|
+ {
|
|
|
+ base.SetAuthor(author);
|
|
|
+ StickyAuthor = author;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetDateText(string dateText)
|
|
|
+ {
|
|
|
+ base.SetDateText(dateText);
|
|
|
+ StickyDate = dateText;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetStickyColor(Color newColor)
|
|
|
+ {
|
|
|
+ base.SetStickyColor(newColor);
|
|
|
+ border.BorderBrush = new SolidColorBrush(newColor);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetStickyNote(string note)
|
|
|
+ {
|
|
|
+ base.SetStickyNote(note);
|
|
|
+ StickyText = note;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetReadOnly(bool readOnly)
|
|
|
+ {
|
|
|
+ base.SetReadOnly(readOnly);
|
|
|
+ ContentText.IsReadOnly = readOnly;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override string GetText()
|
|
|
+ {
|
|
|
+ return StickyText;
|
|
|
+ }
|
|
|
+
|
|
|
private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
var color = ListColor.SelectedItem as ColorItem;
|
|
|
- if(color != null)
|
|
|
+ if (color != null)
|
|
|
{
|
|
|
this.SetStickyColor((color.Color as SolidColorBrush).Color);
|
|
|
+ border.BorderBrush = new SolidColorBrush((color.Color as SolidColorBrush).Color);
|
|
|
+ this.Background = new SolidColorBrush((color.Color as SolidColorBrush).Color);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void StickyPopupControl_Unloaded(object sender, RoutedEventArgs e)
|
|
|
+ private void BtnDelete_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (StickyNote != ContentText.Text)
|
|
|
- this.SetStickyNote(ContentText.Text);
|
|
|
+ ContentText.Text = "";
|
|
|
+ this.SetStickyNote("");
|
|
|
+ Closed.Invoke(sender, EventArgs.Empty);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ var frame = e.OriginalSource as Control;
|
|
|
+ if(frame != null)
|
|
|
+ {
|
|
|
+ var color = frame.Background as SolidColorBrush;
|
|
|
+ if(color != null && color.Color == Colors.Transparent)
|
|
|
+ Closed.Invoke(sender, EventArgs.Empty);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|