|
1 | 1 | Imports System.Collections.ObjectModel |
2 | 2 | Imports System.ComponentModel |
| 3 | +Imports System.IO |
| 4 | +Imports System.Windows.Interop |
3 | 5 | Imports System.Windows.Markup |
4 | 6 | Imports System.Xml |
5 | 7 | Imports ItemPair = System.Tuple(Of System.Windows.Controls.ListBoxItem, DiagramHelper.DiagramPanel) |
@@ -651,6 +653,8 @@ Public Class Designer |
651 | 653 | diagram2.ClearValue(LayoutTransformProperty) |
652 | 654 | End If |
653 | 655 | End If |
| 656 | + |
| 657 | + If TypeOf diagram2 Is ComboBox Then diagram2.ClearValue(StyleProperty) |
654 | 658 | canvas.Children.Add(diagram2) |
655 | 659 | Next |
656 | 660 |
|
@@ -785,6 +789,11 @@ Public Class Designer |
785 | 789 |
|
786 | 790 | Dim lt = diagram.LayoutTransform |
787 | 791 | diagram.LayoutTransform = Nothing |
| 792 | + |
| 793 | + If TypeOf diagram Is ComboBox Then |
| 794 | + diagram.Style = CType(Application.Current.Resources("ColoredComboBox"), Style) |
| 795 | + End If |
| 796 | + |
788 | 797 | Helper.UpdateControl(diagram) |
789 | 798 | diagram.LayoutTransform = lt |
790 | 799 | End Sub) |
@@ -827,40 +836,50 @@ Public Class Designer |
827 | 836 | Dim Pos = e.GetPosition(Me.DesignerCanvas) |
828 | 837 | If e.Data.GetDataPresent(DataFormats.FileDrop) Then |
829 | 838 | Dim Files() As String = e.Data.GetData(DataFormats.FileDrop) |
830 | | - Dim key = CurrentPage.PageKey |
831 | | - For Each file In Files |
832 | | - Select Case IO.Path.GetExtension(file).ToLower() |
833 | | - Case ".xaml" |
834 | | - SwitchTo(file) |
835 | | - |
836 | | - Case ".bmp", ".jpg", ".jpeg", ".png", ".gif" |
837 | | - SwitchTo(key) |
838 | | - Dim label As New Label() |
839 | | - label.Width = 200 |
840 | | - label.Height = 200 |
841 | | - |
842 | | - Dim newFile = IO.Path.Combine(IO.Path.GetDirectoryName(_codeFile), IO.Path.GetFileName(file)) |
843 | | - Try |
844 | | - IO.File.Copy(file, newFile) |
845 | | - file = newFile |
846 | | - Catch ex As Exception |
847 | | - End Try |
848 | | - |
849 | | - label.Background = New ImageBrush(New BitmapImage(New Uri(file))) |
850 | | - AddToForm(Pos, label, label.GetType(), "Label") |
851 | | - SetControlText(label, "", False) |
852 | | - Pos.X += 10 |
853 | | - Pos.Y += 10 |
854 | | - End Select |
855 | | - Next |
856 | | - |
| 839 | + DropFiles(Pos, Files) |
857 | 840 | Else |
858 | 841 | Dim tbItem As ToolBoxItem = e.Data.GetData(GetType(ToolBoxItem)) |
859 | 842 | DarwDiagram(tbItem, Pos) |
860 | 843 | End If |
861 | 844 |
|
862 | 845 | End Sub |
863 | 846 |
|
| 847 | + Private Sub DropFiles(Pos As Point, Files() As String) |
| 848 | + Dim key = CurrentPage.PageKey |
| 849 | + For Each file In Files |
| 850 | + Select Case IO.Path.GetExtension(file).ToLower() |
| 851 | + Case ".xaml" |
| 852 | + SwitchTo(file) |
| 853 | + |
| 854 | + Case ".bmp", ".jpg", ".jpeg", ".png", ".gif" |
| 855 | + SwitchTo(key) |
| 856 | + Dim label As New Label() |
| 857 | + label.Width = 200 |
| 858 | + label.Height = 200 |
| 859 | + |
| 860 | + Dim newFile = IO.Path.Combine(IO.Path.GetDirectoryName(_codeFile), IO.Path.GetFileName(file)) |
| 861 | + Try |
| 862 | + IO.File.Copy(file, newFile) |
| 863 | + file = newFile |
| 864 | + Catch ex As Exception |
| 865 | + End Try |
| 866 | + |
| 867 | + Dim img As New BitmapImage(New Uri(file)) |
| 868 | + If img.Width > img.Height Then |
| 869 | + label.Width = label.Height * img.Width / img.Height |
| 870 | + Else |
| 871 | + label.Height = label.Width * img.Height / img.Width |
| 872 | + End If |
| 873 | + |
| 874 | + label.Background = New ImageBrush(img) |
| 875 | + AddToForm(Pos, label, label.GetType(), "Label") |
| 876 | + SetControlText(label, "", False) |
| 877 | + Pos.X += 10 |
| 878 | + Pos.Y += 10 |
| 879 | + End Select |
| 880 | + Next |
| 881 | + End Sub |
| 882 | + |
864 | 883 | Private Sub DarwDiagram( |
865 | 884 | tbItem As ToolBoxItem, |
866 | 885 | pos As Point, |
@@ -1040,51 +1059,112 @@ Public Class Designer |
1040 | 1059 | Me.Focus() |
1041 | 1060 | End Sub |
1042 | 1061 |
|
1043 | | - Public Sub Paste() |
| 1062 | + Public Sub Paste(Pos As Point?) |
1044 | 1063 | Try |
1045 | | - Dim xaml As String = Clipboard.GetData(DataFormats.Xaml) |
1046 | | - Dim Lst As ArrayList = XamlReader.Load(XmlReader.Create(New IO.StringReader(xaml))) |
1047 | | - Me.SelectedItems.Clear() |
1048 | | - Dim OldState = New CollectionState(AddressOf AfterRestoreAction, Me.Items) |
1049 | | - AddHandler OldState.BeforeRemoveItem, AddressOf UndoRedo_BeforeRemoveItem |
1050 | | - AddHandler OldState.AfterInsertItem, AddressOf UndoRedo_AfterInsertItem |
1051 | | - |
1052 | | - For Each Diagram As UIElement In Lst |
1053 | | - Dim left = Designer.GetLeft(Diagram) |
1054 | | - Dim top = Designer.GetTop(Diagram) |
1055 | | - Designer.SetLeft(Diagram, left + 10) |
1056 | | - Designer.SetTop(Diagram, top + 10) |
1057 | | - Dim name = GetControlName(Diagram) |
1058 | | - SetControlName(Diagram, GetNextName(name)) |
1059 | | - Dim control = TryCast(Diagram, Control) |
1060 | | - If control IsNot Nothing Then |
1061 | | - Commands.FixImageBrush(control.Background) |
1062 | | - Commands.FixImageBrush(control.Foreground) |
1063 | | - Commands.FixImageBrush(control.BorderBrush) |
| 1064 | + If Clipboard.ContainsData(DataFormats.FileDrop) Then |
| 1065 | + Dim Files() As String = Clipboard.GetData(DataFormats.FileDrop) |
| 1066 | + DropFiles(If(Pos, New Point(0, 0)), Files) |
| 1067 | + |
| 1068 | + ElseIf Clipboard.ContainsData(DataFormats.Bitmap) Then |
| 1069 | + PasteImage(If(Pos, New Point(0, 0))) |
| 1070 | + |
| 1071 | + ElseIf Clipboard.ContainsData(DataFormats.Xaml) Then |
| 1072 | + Dim xaml As String = Clipboard.GetData(DataFormats.Xaml) |
| 1073 | + Dim Lst As ArrayList = XamlReader.Load(XmlReader.Create(New IO.StringReader(xaml))) |
| 1074 | + Me.SelectedItems.Clear() |
| 1075 | + Dim OldState = New CollectionState(AddressOf AfterRestoreAction, Me.Items) |
| 1076 | + AddHandler OldState.BeforeRemoveItem, AddressOf UndoRedo_BeforeRemoveItem |
| 1077 | + AddHandler OldState.AfterInsertItem, AddressOf UndoRedo_AfterInsertItem |
| 1078 | + |
| 1079 | + Dim xOffset = 10 |
| 1080 | + Dim yOffset = 10 |
| 1081 | + |
| 1082 | + If Pos IsNot Nothing Then |
| 1083 | + Dim minX = Double.MaxValue |
| 1084 | + Dim minY = Double.MaxValue |
| 1085 | + |
| 1086 | + For Each Diagram As UIElement In Lst |
| 1087 | + minX = Math.Min(minX, Designer.GetLeft(Diagram)) |
| 1088 | + minY = Math.Min(minY, Designer.GetTop(Diagram)) |
| 1089 | + Next |
| 1090 | + |
| 1091 | + xOffset = Pos.Value.X - minX |
| 1092 | + yOffset = Pos.Value.Y - minY |
1064 | 1093 | End If |
1065 | 1094 |
|
1066 | | - OldState.Add(Diagram) |
1067 | | - Me.Items.Add(Diagram) |
1068 | | - OldState.SetNewValues() |
1069 | | - Next |
| 1095 | + For Each Diagram As UIElement In Lst |
| 1096 | + Dim left = Designer.GetLeft(Diagram) + xOffset |
| 1097 | + Dim top = Designer.GetTop(Diagram) + yOffset |
| 1098 | + Designer.SetLeft(Diagram, left) |
| 1099 | + Designer.SetTop(Diagram, top) |
| 1100 | + Dim name = GetControlName(Diagram) |
| 1101 | + SetControlName(Diagram, GetNextName(name)) |
| 1102 | + Dim control = TryCast(Diagram, Control) |
| 1103 | + If control IsNot Nothing Then |
| 1104 | + Commands.FixImageBrush(control.Background) |
| 1105 | + Commands.FixImageBrush(control.Foreground) |
| 1106 | + Commands.FixImageBrush(control.BorderBrush) |
| 1107 | + End If |
1070 | 1108 |
|
1071 | | - UndoStack.ReportChanges(New UndoRedoUnit(OldState)) |
1072 | | - Helper.UpdateControl(Me) |
| 1109 | + OldState.Add(Diagram) |
| 1110 | + Me.Items.Add(Diagram) |
| 1111 | + OldState.SetNewValues() |
| 1112 | + Next |
1073 | 1113 |
|
1074 | | - For Each Diagram As UIElement In Lst |
1075 | | - Dim Item = Helper.GetListBoxItem(Diagram) |
1076 | | - Item?.Focus() |
1077 | | - Me.ScrollIntoView(Diagram) |
1078 | | - Next |
| 1114 | + UndoStack.ReportChanges(New UndoRedoUnit(OldState)) |
| 1115 | + Helper.UpdateControl(Me) |
1079 | 1116 |
|
1080 | | - xaml = XamlWriter.Save(Lst) |
1081 | | - Clipboard.SetData(DataFormats.Xaml, xaml) |
| 1117 | + For Each Diagram As UIElement In Lst |
| 1118 | + Dim Item = Helper.GetListBoxItem(Diagram) |
| 1119 | + Item?.Focus() |
| 1120 | + Me.ScrollIntoView(Diagram) |
| 1121 | + Next |
| 1122 | + |
| 1123 | + xaml = XamlWriter.Save(Lst) |
| 1124 | + Clipboard.SetData(DataFormats.Xaml, xaml) |
| 1125 | + |
| 1126 | + ElseIf Clipboard.ContainsData(DataFormats.Text) Then |
| 1127 | + Dim txt = Clipboard.GetData(DataFormats.Text) |
| 1128 | + Dim label As New Label() |
| 1129 | + label.Visibility = Visibility.Hidden |
| 1130 | + AddToForm(If(Pos, New Point(10, 10)), label, label.GetType(), "Label") |
| 1131 | + SetControlText(label, txt) |
| 1132 | + Dim tb As TextBlock = label.Content |
| 1133 | + tb.TextWrapping = TextWrapping.NoWrap |
| 1134 | + label.Visibility = Visibility.Visible |
| 1135 | + Dim pnl = Helper.GetDiagramPanel(label) |
| 1136 | + Me.Dispatcher.BeginInvoke( |
| 1137 | + Threading.DispatcherPriority.Background, |
| 1138 | + Sub() |
| 1139 | + pnl.Width = tb.ActualWidth + 15 |
| 1140 | + pnl.Height = tb.ActualHeight + 15 |
| 1141 | + tb.TextWrapping = TextWrapping.Wrap |
| 1142 | + End Sub |
| 1143 | + ) |
| 1144 | + End If |
1082 | 1145 |
|
1083 | 1146 | Catch ex As Exception |
1084 | 1147 |
|
1085 | 1148 | End Try |
1086 | 1149 | End Sub |
1087 | 1150 |
|
| 1151 | + Private Sub PasteImage(pos As Point) |
| 1152 | + Dim files = IO.Directory.GetFiles(IO.Path.GetDirectoryName(_codeFile), "svb_gen_image*.jpg") |
| 1153 | + Dim n = 1 |
| 1154 | + For Each file In files |
| 1155 | + Dim i = CInt(IO.Path.GetFileNameWithoutExtension(file).Substring(13)) |
| 1156 | + If i >= n Then n = i + 1 |
| 1157 | + Next |
| 1158 | + |
| 1159 | + Dim imageName = $"svb_gen_image{n}.jpg" |
| 1160 | + Using fileStream As New FileStream(imageName, FileMode.Create) |
| 1161 | + Dim encoder As New JpegBitmapEncoder() |
| 1162 | + encoder.Frames.Add(BitmapFrame.Create(Clipboard.GetImage())) |
| 1163 | + encoder.Save(fileStream) |
| 1164 | + End Using |
| 1165 | + DropFiles(pos, {imageName}) |
| 1166 | + End Sub |
| 1167 | + |
1088 | 1168 | Private Function GetNextName(name As String) As String |
1089 | 1169 | Dim baseName As String |
1090 | 1170 | Dim num As Integer |
@@ -1117,11 +1197,15 @@ Public Class Designer |
1117 | 1197 | End Function |
1118 | 1198 |
|
1119 | 1199 | Public Function CanPaste() As Boolean |
1120 | | - If Not Clipboard.ContainsData(DataFormats.Xaml) Then Return False |
1121 | | - Dim xaml As String = Clipboard.GetData(DataFormats.Xaml) |
1122 | | - Dim Lst = TryCast(XamlReader.Load(XmlReader.Create(New IO.StringReader(xaml))), ArrayList) |
1123 | | - If Lst Is Nothing Then Return False |
1124 | | - Return True |
| 1200 | + If Clipboard.ContainsData(DataFormats.Bitmap) Then Return True |
| 1201 | + If Clipboard.ContainsData(DataFormats.FileDrop) Then Return True |
| 1202 | + If Clipboard.ContainsData(DataFormats.Xaml) Then |
| 1203 | + Dim xaml As String = Clipboard.GetData(DataFormats.Xaml) |
| 1204 | + Dim Lst = TryCast(XamlReader.Load(XmlReader.Create(New IO.StringReader(xaml))), ArrayList) |
| 1205 | + If Lst Is Nothing Then Return False |
| 1206 | + Return True |
| 1207 | + End If |
| 1208 | + If Clipboard.ContainsData(DataFormats.Text) Then Return True |
1125 | 1209 | End Function |
1126 | 1210 |
|
1127 | 1211 |
|
@@ -1507,7 +1591,7 @@ Public Class Designer |
1507 | 1591 | e.Handled = True |
1508 | 1592 | Return |
1509 | 1593 | Case Key.V |
1510 | | - Me.Paste() |
| 1594 | + Me.Paste(Nothing) |
1511 | 1595 | e.Handled = True |
1512 | 1596 | Return |
1513 | 1597 | Case Key.S |
@@ -2451,6 +2535,8 @@ Public Class Designer |
2451 | 2535 | #End Region |
2452 | 2536 |
|
2453 | 2537 | Dim _mustSaveDesign As Boolean |
| 2538 | + Friend LastMouseDownPos As Point |
| 2539 | + |
2454 | 2540 | Public ReadOnly Property MustSaveDesign As Boolean |
2455 | 2541 | Get |
2456 | 2542 | Return _mustSaveDesign OrElse HasChanges |
|
0 commit comments