using ComPDFKitViewer; using PDF_Office.CustomControl.CompositeControl; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; 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; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PDF_Office.Views.PropertyPanel.AnnotPanel { /// /// StickyNotePopup.xaml 的交互逻辑 /// 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)); } } /// /// StickyNotePopup.xaml 的交互逻辑 /// public partial class StickyNotePopup : StickyPopupExt { private ObservableCollection colors = new ObservableCollection(); private Point PressPoint; public Point OffsetParent; private byte saveOpacity = 1; public StickyNotePopup() { InitializeComponent(); AddHandler(MouseUpEvent, new MouseButtonEventHandler(StickyPopupControl_MouseUp), true); ContentText.AddHandler(MouseDownEvent, new MouseButtonEventHandler(StickyPopupControl_MouseDown), true); Loaded += StickyPopupControl_Loaded; 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))); colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0x70, 0xFF))); ListColor.ItemsSource = colors; } private void ContentText_LostFocus(object sender, RoutedEventArgs e) { e.Handled = true; Color bkColor = (border.BorderBrush as SolidColorBrush).Color; bkColor.A = saveOpacity; border.BorderBrush = new SolidColorBrush(bkColor); CloseText_MouseUp(this, null); } private void ContentText_GotFocus(object sender, RoutedEventArgs e) { Color bkColor = (border.BorderBrush as SolidColorBrush).Color; saveOpacity = bkColor.A; bkColor.A = 255; border.BorderBrush = new SolidColorBrush(bkColor); this.Background = new SolidColorBrush(this.StickyColor); } private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e) { ContentText.Focus(); ContentText.CaretIndex = ContentText.Text.Length; } private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e) { PressPoint = new Point(0, 0); } private void StickyPopupControl_MouseUp(object sender, MouseButtonEventArgs e) { CanMove = true; GripControl.ReleaseMouseCapture(); } public string StickyText { get { return ContentText.Text; } set { ContentText.Text = value; } } public string StickyAuthor { get { return AuthorText.Text; } set { AuthorText.Text = value; } } public string StickyDate { get { return DateText.Text; } set { 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(); } } } private void CloseText_MouseUp(object sender, MouseButtonEventArgs e) { if (e != null) { e.Handled = true; } PlaceChange = null; RemoveFromLayer(); if (Closed != null) { Closed.Invoke(sender, EventArgs.Empty); } } 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) { 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 BtnDelete_Click(object sender, RoutedEventArgs e) { 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); } } } }