diff --git a/src/Common/src/Interop/Kernel32/Interop.MultiByteToWideChar.cs b/src/Common/src/Interop/Kernel32/Interop.MultiByteToWideChar.cs new file mode 100644 index 00000000000..9ae5bdb6c0a --- /dev/null +++ b/src/Common/src/Interop/Kernel32/Interop.MultiByteToWideChar.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; + +internal partial class Interop +{ + internal partial class Kernel32 + { + // SECREVIEW: From MSDN: Using the MultiByteToWideChar/WideCharToMultiByte function incorrectly can compromise the security of your application. + // Calling the WideCharToMultiByte function can easily cause a buffer overrun because the size of the In buffer equals the number + // of WCHARs in the string, while the size of the Out buffer equals the number of bytes. To avoid a buffer overrun, be sure to specify + // a buffer size appropriate for the data type the buffer receives. For more information, see Security Considerations: International Features. + // Always call these functions passing a null destination buffer to get its size and the create the buffer with the exact size. + [DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + public static extern int MultiByteToWideChar(int CodePage, int dwFlags, byte[] lpMultiByteStr, int cchMultiByte, char[] lpWideCharStr, int cchWideChar); + } +} diff --git a/src/System.Windows.Forms.Design/src/Resources/SR.resx b/src/System.Windows.Forms.Design/src/Resources/SR.resx index edb4b780160..ff7b603fc93 100644 --- a/src/System.Windows.Forms.Design/src/Resources/SR.resx +++ b/src/System.Windows.Forms.Design/src/Resources/SR.resx @@ -753,4 +753,19 @@ '{0}' - + + All Files + + + Error writing to file: {0} + + + ByteArray + + + Save File As + + + Byte Array Property Editor + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/BinaryEditor.resx b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/BinaryEditor.resx new file mode 100644 index 00000000000..9847a579d99 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/BinaryEditor.resx @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + 0, 0 + + + 634, 192 + + + + 0 + + + + + + byteViewer + + + System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + overarchingTableLayoutPanel + + + 0 + + + Left, Right + + + True + + + 0, 0 + + + 75, 23 + + + 0 + + + OK + + + buttonOK + + + System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + okSaveTableLayoutPanel + + + 0 + + + Left, Right + + + True + + + 81, 0 + + + 75, 23 + + + 1 + + + &Save... + + + buttonSave + + + System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + okSaveTableLayoutPanel + + + 1 + + + Left, Right + + + True + + + True + + + 4 + + + Left + + + True + + + 462, 0 + + + 61, 17 + + + 3 + + + &Unicode + + + radioUnicode + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + radioButtonsTableLayoutPanel + + + 0 + + + Left + + + True + + + 0, 0 + + + 43, 17 + + + 0 + + + &Auto + + + radioAuto + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + radioButtonsTableLayoutPanel + + + 1 + + + Left + + + True + + + 309, 0 + + + 46, 17 + + + 2 + + + A&NSI + + + radioAnsi + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + radioButtonsTableLayoutPanel + + + 2 + + + Left + + + True + + + 156, 0 + + + 82, 17 + + + 1 + + + &Hexadecimal + + + radioHex + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + radioButtonsTableLayoutPanel + + + 3 + + + 9, 22 + + + 1 + + + 613, 17 + + + 0 + + + radioButtonsTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBoxMode + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="radioUnicode" Row="0" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="radioAuto" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="radioAnsi" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="radioHex" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Percent,25,Percent,25,Percent,25,Percent,25" /><Rows Styles="AutoSize,0" /></TableLayoutSettings> + + + 0, 198 + + + 634, 48 + + + 1 + + + Display Mode + + + groupBoxMode + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + overarchingTableLayoutPanel + + + 1 + + + Right + + + True + + + 2 + + + 472, 255 + + + 1 + + + 156, 23 + + + 2 + + + okSaveTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + overarchingTableLayoutPanel + + + 2 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="buttonOK" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="buttonSave" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="Percent,50,Percent,50" /><Rows Styles="Percent,50" /></TableLayoutSettings> + + + Top, Bottom, Left, Right + + + 1 + + + 12, 12 + + + 3 + + + True + + + 634, 291 + + + 0 + + + overarchingTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="byteViewer" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="groupBoxMode" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="okSaveTableLayoutPanel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,50" /><Rows Styles="Percent,100,AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + + True + + + 6, 13 + + + 658, 315 + + + CenterParent + + + Byte Array Property Editor + + + BinaryUI + + + System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.cs.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.cs.xlf new file mode 100644 index 00000000000..2050162a26f --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.cs.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.de.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.de.xlf new file mode 100644 index 00000000000..e93c7231415 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.de.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.es.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.es.xlf new file mode 100644 index 00000000000..ea2f5050488 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.es.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.fr.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.fr.xlf new file mode 100644 index 00000000000..bfdbbd7e74f --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.fr.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.it.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.it.xlf new file mode 100644 index 00000000000..f19c035af3c --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.it.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ja.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ja.xlf new file mode 100644 index 00000000000..8c1d9e1a145 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ja.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ko.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ko.xlf new file mode 100644 index 00000000000..395e5ab6a12 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ko.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pl.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pl.xlf new file mode 100644 index 00000000000..ed96ab7ffc5 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pl.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pt-BR.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pt-BR.xlf new file mode 100644 index 00000000000..efce5f05dec --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.pt-BR.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ru.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ru.xlf new file mode 100644 index 00000000000..6d2ee06df78 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.ru.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.tr.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.tr.xlf new file mode 100644 index 00000000000..caa7030fb6c --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.tr.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hans.xlf new file mode 100644 index 00000000000..4f8e3fb8a11 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hans.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hant.xlf new file mode 100644 index 00000000000..68854707dc0 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/Resources/System/ComponentModel/Design/xlf/BinaryEditor.zh-Hant.xlf @@ -0,0 +1,47 @@ + + + + + + Byte Array Property Editor + Byte Array Property Editor + + + + OK + OK + + + + &Save... + &Save... + + + + Display Mode + Display Mode + + + + A&NSI + A&NSI + + + + &Auto + &Auto + + + + &Hexadecimal + &Hexadecimal + + + + &Unicode + &Unicode + + + + + \ No newline at end of file diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf index 905626c3538..8da3c304732 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf @@ -32,6 +32,31 @@ Změna velikosti - {0} ovládacích prvků + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Úložiště serializace je zavřeno. Do zavřeného úložiště nelze přidávat nové objekty. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf index 66b6f0a960d..2416d455fce 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf @@ -32,6 +32,31 @@ Größe von {0}-Steuerelementen ändern + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Der Serialisierungsspeicher ist geschlossen. Neue Objekte können nicht zu einem geschlossenen Speicher hinzugefügt werden. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf index 2e082e3aa2b..15f1284670c 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf @@ -32,6 +32,31 @@ Cambiar tamaño de {0} controles + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. El almacén de serialización está cerrado. No se pueden agregar nuevos objetos a un almacén cerrado. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf index 8f654146236..c05bd3f45cb 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf @@ -32,6 +32,31 @@ Redimensionner les contrôles {0} + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Le magasin de sérialisation est fermé. Impossible d'ajouter de nouveaux objets à un magasin fermé. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf index 1230b0f888b..1957559e7db 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf @@ -32,6 +32,31 @@ Ridimensiona {0} controlli + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. L'archivio di serializzazione è chiuso. Non è possibile aggiungere nuovi oggetti a un archivio chiuso. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf index e5bf346044d..d3edea42914 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf @@ -32,6 +32,31 @@ {0} コントロールのサイズの変更 + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. シリアル化ストアは閉じられています。 閉じられたストアに新しいオブジェクトを追加することはできません。 diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf index e6d9d0fcecd..ab5114348c2 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf @@ -32,6 +32,31 @@ {0}개 컨트롤 크기 조정 + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Serialization 저장소가 닫혀 있습니다. 닫힌 저장소에는 새 개체를 추가할 수 없습니다. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf index 12b8d5404e5..2a616876053 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf @@ -32,6 +32,31 @@ Zmień rozmiar formantów {0} + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Magazyn serializacji jest zamknięty. Do zamkniętego magazynu nie można dodawać nowych obiektów. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf index a3960ce4e93..215bdd54917 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf @@ -32,6 +32,31 @@ Redimensionar {0} Controles + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. O repositório de serialização está fechado. Não é possível adicionar novos objetos a um repositório fechado. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf index 19c80274b5d..2e2badfb4cf 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf @@ -32,6 +32,31 @@ Изменить размер {0} элементов управления + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Хранилище сериализованных объектов закрыто. Добавление новых объектов в закрытое хранилище невозможно. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf index d562b7bd4ad..125ec5cd2b5 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf @@ -32,6 +32,31 @@ {0} Denetimi yeniden boyutlandır + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. Serileştirme deposu kapalı. Kapalı depoya yeni nesneler eklenemez. diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf index a69d9eecce0..43556a2d9e9 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf @@ -32,6 +32,31 @@ 调整 {0} 控件的大小 + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. 序列化存储区已关闭。新对象无法添加到已关闭的存储区中。 diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf index 562cf2a4ded..159261f2c7f 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf @@ -32,6 +32,31 @@ 重新調整 {0} 控制項大小 + + All Files + All Files + + + + Error writing to file: {0} + Error writing to file: {0} + + + + ByteArray + ByteArray + + + + Save File As + Save File As + + + + Byte Array Property Editor + Byte Array Property Editor + + The serialization store is closed. New objects cannot be added to a closed store. 序列化存放區已關閉。新物件無法加入已關閉的存放區。 diff --git a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj index d935ace9788..3d531ab25d5 100644 --- a/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj +++ b/src/System.Windows.Forms.Design/src/System.Windows.Forms.Design.csproj @@ -33,6 +33,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/BinaryEditor.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/BinaryEditor.cs new file mode 100644 index 00000000000..9b7997ffc76 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/BinaryEditor.cs @@ -0,0 +1,435 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Design; +using System.IO; +using System.Text; +using System.Windows.Forms; +using System.Windows.Forms.Design; + +namespace System.ComponentModel.Design +{ + /// + /// Generic editor for editing binary data. This presents a hex editing window to the user. + /// + public sealed class BinaryEditor : UITypeEditor + { + private const string HELP_KEYWORD = "System.ComponentModel.Design.BinaryEditor"; + private ITypeDescriptorContext _context; + private BinaryUI _binaryUI; + + internal object GetService(Type serviceType) + { + if (_context == null) + { + return null; + } + + IDesignerHost host = _context.GetService(typeof(IDesignerHost)) as IDesignerHost; + if (host == null) + { + return _context.GetService(serviceType); + } + + return host.GetService(serviceType); + } + + /// + /// Converts the given object to an array of bytes to be manipulated + /// by the editor. The default implementation of this supports + /// byte[] and stream objects. + /// + internal byte[] ConvertToBytes(object value) + { + if (value is Stream s) + { + s.Position = 0; + int byteCount = (int)(s.Length - s.Position); + byte[] bytes = new byte[byteCount]; + s.Read(bytes, 0, byteCount); + return bytes; + } + + if (value is byte[] b) + { + return b; + } + + if (value is string str) + { + int size = str.Length * 2; + byte[] buffer = new byte[size]; + Encoding.Unicode.GetBytes(str.ToCharArray(), 0, size / 2, buffer, 0); + return buffer; + } + + Debug.Fail("No conversion from " + value == null ? "null" : value.GetType().FullName + " to byte[]"); + return null; + } + + /// + /// Converts the given byte array back into a native object. If + /// the object itself needs to be replace (as is the case for arrays), + /// then a new object may be assigned out through the parameter. + /// + internal void ConvertToValue(byte[] bytes, ref object value) + { + if (value is Stream s) + { + s.Position = 0; + s.Write(bytes, 0, bytes.Length); + } + else if (value is byte[]) + { + value = bytes; + } + else if (value is string) + { + value = BitConverter.ToString(bytes); + } + else + { + Debug.Fail("No conversion from byte[] to " + value == null ? "null" : value.GetType().FullName); + } + } + + /// + /// Edits the given object value using the editor style provided by GetEditorStyle. + /// A service provider is provided so that any required editing services can be obtained. + /// + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + { + if (provider == null) + { + return value; + } + + _context = context; + + IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); + if (edSvc == null) + { + return value; + } + + if (_binaryUI == null) + { + // child modal dialog -launching in System Aware mode + _binaryUI = DpiHelper.CreateInstanceInSystemAwareContext(() => new BinaryUI(this)); + } + + _binaryUI.Value = value; + if (edSvc.ShowDialog(_binaryUI) == DialogResult.OK) + { + value = _binaryUI.Value; + } + _binaryUI.Value = null; + + return value; + } + + /// + /// Retrieves the editing style of the Edit method. If the method is not supported, this will return None. + /// + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.Modal; + } + + internal void ShowHelp() + { + IHelpService helpService = GetService(typeof(IHelpService)) as IHelpService; + if (helpService != null) + { + helpService.ShowHelpFromKeyword(HELP_KEYWORD); + } + else + { + Debug.Fail("Unable to get IHelpService."); + } + } + + private class BinaryUI : Form + { + private readonly BinaryEditor _editor; + private object _value; + + private RadioButton _radioAuto; + private Button _buttonSave; + private Button _buttonOK; + private ByteViewer _byteViewer; + private GroupBox _groupBoxMode; + private RadioButton _radioHex; + private RadioButton _radioAnsi; + private TableLayoutPanel _radioButtonsTableLayoutPanel; + private TableLayoutPanel _okSaveTableLayoutPanel; + private TableLayoutPanel _overarchingTableLayoutPanel; + private RadioButton _radioUnicode; + + public BinaryUI(BinaryEditor editor) + { + _editor = editor; + InitializeComponent(); + } + + public object Value + { + get + { + return _value; + } + set + { + _value = value; + byte[] bytes = null; + + if (value != null) + { + bytes = _editor.ConvertToBytes(value); + } + + if (bytes != null) + { + _byteViewer.SetBytes(bytes); + _byteViewer.Enabled = true; + } + else + { + _byteViewer.SetBytes(new byte[0]); + _byteViewer.Enabled = false; + } + } + } + + private void RadioAuto_checkedChanged(object source, EventArgs e) + { + if (_radioAuto.Checked) + _byteViewer.SetDisplayMode(DisplayMode.Auto); + } + + private void RadioHex_checkedChanged(object source, EventArgs e) + { + if (_radioHex.Checked) + _byteViewer.SetDisplayMode(DisplayMode.Hexdump); + } + + private void RadioAnsi_checkedChanged(object source, EventArgs e) + { + if (_radioAnsi.Checked) + _byteViewer.SetDisplayMode(DisplayMode.Ansi); + } + + private void RadioUnicode_checkedChanged(object source, EventArgs e) + { + if (_radioUnicode.Checked) + _byteViewer.SetDisplayMode(DisplayMode.Unicode); + } + + private void ButtonOK_click(object source, EventArgs e) + { + object localValue = _value; + _editor.ConvertToValue(_byteViewer.GetBytes(), ref localValue); + _value = localValue; + } + + private void ButtonSave_click(object source, EventArgs e) + { + try + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.FileName = SR.BinaryEditorFileName; + sfd.Title = SR.BinaryEditorSaveFile; + sfd.Filter = SR.BinaryEditorAllFiles + " (*.*)|*.*"; + + DialogResult result = sfd.ShowDialog(); + if (result == DialogResult.OK) + { + _byteViewer.SaveToFile(sfd.FileName); + } + } + catch (IOException x) + { + RTLAwareMessageBox.Show(null, string.Format(SR.BinaryEditorFileError, x.Message), + SR.BinaryEditorTitle, MessageBoxButtons.OK, + MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); + } + } + + private void Form_HelpRequested(object sender, HelpEventArgs e) + { + _editor.ShowHelp(); + } + + private void Form_HelpButtonClicked(object sender, CancelEventArgs e) + { + e.Cancel = true; + _editor.ShowHelp(); + } + + private void InitializeComponent() + { + ComponentResourceManager resources = new ComponentResourceManager(typeof(BinaryEditor)); + _byteViewer = new ByteViewer(); + _buttonOK = new Button(); + _buttonSave = new Button(); + _groupBoxMode = new GroupBox(); + _radioButtonsTableLayoutPanel = new TableLayoutPanel(); + _radioUnicode = new RadioButton(); + _radioAuto = new RadioButton(); + _radioAnsi = new RadioButton(); + _radioHex = new RadioButton(); + _okSaveTableLayoutPanel = new TableLayoutPanel(); + _overarchingTableLayoutPanel = new TableLayoutPanel(); + _byteViewer.SuspendLayout(); + _groupBoxMode.SuspendLayout(); + _radioButtonsTableLayoutPanel.SuspendLayout(); + _okSaveTableLayoutPanel.SuspendLayout(); + _overarchingTableLayoutPanel.SuspendLayout(); + SuspendLayout(); + + // + // byteViewer + // + resources.ApplyResources(_byteViewer, "byteViewer"); + _byteViewer.SetDisplayMode(DisplayMode.Auto); + _byteViewer.Name = "byteViewer"; + _byteViewer.Margin = Padding.Empty; + _byteViewer.Dock = DockStyle.Fill; + // + // buttonOK + // + resources.ApplyResources(_buttonOK, "buttonOK"); + _buttonOK.AutoSizeMode = AutoSizeMode.GrowAndShrink; + _buttonOK.DialogResult = DialogResult.OK; + _buttonOK.Margin = new Padding(0, 0, 3, 0); + _buttonOK.MinimumSize = new Size(75, 23); + _buttonOK.Name = "buttonOK"; + _buttonOK.Padding = new Padding(10, 0, 10, 0); + _buttonOK.Click += new EventHandler(ButtonOK_click); + // + // buttonSave + // + resources.ApplyResources(_buttonSave, "buttonSave"); + _buttonSave.AutoSizeMode = AutoSizeMode.GrowAndShrink; + _buttonSave.Margin = new Padding(3, 0, 0, 0); + _buttonSave.MinimumSize = new Size(75, 23); + _buttonSave.Name = "buttonSave"; + _buttonSave.Padding = new Padding(10, 0, 10, 0); + _buttonSave.Click += new EventHandler(ButtonSave_click); + // + // groupBoxMode + // + resources.ApplyResources(_groupBoxMode, "groupBoxMode"); + _groupBoxMode.AutoSizeMode = AutoSizeMode.GrowAndShrink; + _groupBoxMode.Controls.Add(_radioButtonsTableLayoutPanel); + _groupBoxMode.Margin = new Padding(0, 3, 0, 3); + _groupBoxMode.Name = "groupBoxMode"; + _groupBoxMode.Padding = new Padding(0); + _groupBoxMode.TabStop = false; + // + // radioButtonsTableLayoutPanel + // + resources.ApplyResources(_radioButtonsTableLayoutPanel, "radioButtonsTableLayoutPanel"); + _radioButtonsTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + _radioButtonsTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + _radioButtonsTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + _radioButtonsTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); + _radioButtonsTableLayoutPanel.Controls.Add(_radioUnicode, 3, 0); + _radioButtonsTableLayoutPanel.Controls.Add(_radioAuto, 0, 0); + _radioButtonsTableLayoutPanel.Controls.Add(_radioAnsi, 2, 0); + _radioButtonsTableLayoutPanel.Controls.Add(_radioHex, 1, 0); + _radioButtonsTableLayoutPanel.Margin = new Padding(9); + _radioButtonsTableLayoutPanel.Name = "radioButtonsTableLayoutPanel"; + _radioButtonsTableLayoutPanel.RowStyles.Add(new RowStyle()); + // + // radioUnicode + // + resources.ApplyResources(_radioUnicode, "radioUnicode"); + _radioUnicode.Margin = new Padding(3, 0, 0, 0); + _radioUnicode.Name = "radioUnicode"; + _radioUnicode.CheckedChanged += new EventHandler(RadioUnicode_checkedChanged); + // + // radioAuto + // + resources.ApplyResources(_radioAuto, "radioAuto"); + _radioAuto.Checked = true; + _radioAuto.Margin = new Padding(0, 0, 3, 0); + _radioAuto.Name = "radioAuto"; + _radioAuto.CheckedChanged += new EventHandler(RadioAuto_checkedChanged); + // + // radioAnsi + // + resources.ApplyResources(_radioAnsi, "radioAnsi"); + _radioAnsi.Margin = new Padding(3, 0, 3, 0); + _radioAnsi.Name = "radioAnsi"; + _radioAnsi.CheckedChanged += new EventHandler(RadioAnsi_checkedChanged); + // + // radioHex + // + resources.ApplyResources(_radioHex, "radioHex"); + _radioHex.Margin = new Padding(3, 0, 3, 0); + _radioHex.Name = "radioHex"; + _radioHex.CheckedChanged += new EventHandler(RadioHex_checkedChanged); + // + // okSaveTableLayoutPanel + // + resources.ApplyResources(_okSaveTableLayoutPanel, "okSaveTableLayoutPanel"); + _okSaveTableLayoutPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; + _okSaveTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _okSaveTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _okSaveTableLayoutPanel.Controls.Add(_buttonOK, 0, 0); + _okSaveTableLayoutPanel.Controls.Add(_buttonSave, 1, 0); + _okSaveTableLayoutPanel.Margin = new Padding(0, 9, 0, 0); + _okSaveTableLayoutPanel.Name = "okSaveTableLayoutPanel"; + _okSaveTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); + // + // overarchingTableLayoutPanel + // + resources.ApplyResources(_overarchingTableLayoutPanel, "overarchingTableLayoutPanel"); + _overarchingTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + _overarchingTableLayoutPanel.Controls.Add(_byteViewer, 0, 0); + _overarchingTableLayoutPanel.Controls.Add(_groupBoxMode, 0, 1); + _overarchingTableLayoutPanel.Controls.Add(_okSaveTableLayoutPanel, 0, 2); + _overarchingTableLayoutPanel.Name = "overarchingTableLayoutPanel"; + _overarchingTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + _overarchingTableLayoutPanel.RowStyles.Add(new RowStyle()); + _overarchingTableLayoutPanel.RowStyles.Add(new RowStyle()); + + // + // BinaryUI + // + AcceptButton = _buttonOK; + resources.ApplyResources(this, "$this"); + AutoScaleMode = AutoScaleMode.Font; + CancelButton = _buttonOK; + Controls.Add(_overarchingTableLayoutPanel); + FormBorderStyle = FormBorderStyle.FixedDialog; + HelpButton = true; + MaximizeBox = false; + MinimizeBox = false; + Name = "BinaryUI"; + ShowIcon = false; + ShowInTaskbar = false; + HelpRequested += new HelpEventHandler(Form_HelpRequested); + HelpButtonClicked += new CancelEventHandler(Form_HelpButtonClicked); + _byteViewer.ResumeLayout(false); + _byteViewer.PerformLayout(); + _groupBoxMode.ResumeLayout(false); + _groupBoxMode.PerformLayout(); + _radioButtonsTableLayoutPanel.ResumeLayout(false); + _radioButtonsTableLayoutPanel.PerformLayout(); + _okSaveTableLayoutPanel.ResumeLayout(false); + _okSaveTableLayoutPanel.PerformLayout(); + _overarchingTableLayoutPanel.ResumeLayout(false); + _overarchingTableLayoutPanel.PerformLayout(); + ResumeLayout(false); + + } + } + } +} + + diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ByteViewer.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ByteViewer.cs new file mode 100644 index 00000000000..911696f07a5 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ByteViewer.cs @@ -0,0 +1,753 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace System.ComponentModel.Design +{ + /// + /// Displays byte arrays in HEXDUMP, ANSI and Unicode formats. + /// + [ToolboxItem(false)] + [DesignTimeVisible(false)] + public class ByteViewer : TableLayoutPanel + { + private const int DEFAULT_COLUMN_COUNT = 16; + private const int DEFAULT_ROW_COUNT = 25; + private const int COLUMN_COUNT = 16; + private const int BORDER_GAP = 2; + private const int INSET_GAP = 3; + private const int CELL_HEIGHT = 21; + private const int CELL_WIDTH = 25; + private const int CHAR_WIDTH = 8; + private const int ADDRESS_WIDTH = 69; // this is ceiling(sizeof("DDDDDDDD").width) + 1 + private const int HEX_WIDTH = CELL_WIDTH * COLUMN_COUNT; + private const int DUMP_WIDTH = CHAR_WIDTH * COLUMN_COUNT; + private const int HEX_DUMP_GAP = 5; + private const int ADDRESS_START_X = BORDER_GAP + INSET_GAP; + private const int CLIENT_START_Y = BORDER_GAP + INSET_GAP; + private const int LINE_START_Y = CLIENT_START_Y + CELL_HEIGHT / 8; + private const int HEX_START_X = ADDRESS_START_X + ADDRESS_WIDTH; + private const int DUMP_START_X = HEX_START_X + HEX_WIDTH + HEX_DUMP_GAP; + private const int SCROLLBAR_START_X = DUMP_START_X + DUMP_WIDTH + HEX_DUMP_GAP; + + private static readonly Font ADDRESS_FONT = new Font("Microsoft Sans Serif", 8.0f); + private static readonly Font HEXDUMP_FONT = new Font("Courier New", 8.0f); + + private int SCROLLBAR_HEIGHT; + private int SCROLLBAR_WIDTH; + private VScrollBar _scrollBar; + private TextBox _edit; + private readonly int _columnCount = DEFAULT_COLUMN_COUNT; + private int _rowCount = DEFAULT_ROW_COUNT; + private byte[] _dataBuf; + private int _startLine; + private int _displayLinesCount; + private int _linesCount; + private DisplayMode _displayMode; + private DisplayMode _realDisplayMode; + + /// + /// Initializes a new instance of the class. + /// + public ByteViewer() + : base() + { + SuspendLayout(); + CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; + + ColumnCount = 1; + ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + + RowCount = 1; + RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + + InitUI(); + + ResumeLayout(); + + _displayMode = DisplayMode.Hexdump; + _realDisplayMode = DisplayMode.Hexdump; + DoubleBuffered = true; + SetStyle(ControlStyles.ResizeRedraw, true); + } + + // Stole this code from XmlSanner + private static int AnalizeByteOrderMark(byte[] buffer, int index) + { + int c1 = buffer[index + 0] << 8 | buffer[index + 1]; + int c2 = buffer[index + 2] << 8 | buffer[index + 3]; + int c4, c5; + + //Assign an index (label) value for first two bytes + c4 = GetEncodingIndex(c1); + //Assign an index (label) value for 3rd and 4th byte + c5 = GetEncodingIndex(c2); + + //Bellow table is to identify Encoding type based on + //first four bytes, those we have converted in index + //values for this look up table + //values on column are first two bytes and + //values on rows are 3rd and 4th byte + + int[,] encodings = { + //Unknown 0000 feff fffe efbb 3c00 003c 3f00 003f 3c3f 786d 4c6f a794 + /*Unknown*/ {1 ,5 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*0000*/ {1 ,1 ,1 ,11 ,1 ,10 ,4 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*feff*/ {2 ,9 ,5 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 }, + /*fffe*/ {3 ,7 ,3 ,7 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 }, + /*efbb*/ {14 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*3c00*/ {1 ,6 ,1 ,1 ,1 ,1 ,1 ,3 ,1 ,1 ,1 ,1 ,1 }, + /*003c*/ {1 ,8 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 }, + /*3f00*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*003f*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*3c3f*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,13 ,1 ,1 }, + /*786d*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }, + /*4c6f*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,12 }, + /*a794*/ {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 } + }; + + return encodings[c4, c5]; + } + + /// + /// Calculates an index for a cell in the HEX grid + /// + private int CellToIndex(int column, int row) + { + return row * _columnCount + column; + } + + /// + /// Copies the line from main data buffer to a line buffer + /// + private byte[] ComposeLineBuffer(int startLine, int line) + { + byte[] lineBuffer; + + int offset = startLine * _columnCount; + if (offset + (line + 1) * _columnCount > _dataBuf.Length) + { + lineBuffer = new byte[_dataBuf.Length % _columnCount]; + } + else + { + lineBuffer = new byte[_columnCount]; + } + + for (int i = 0; i < lineBuffer.Length; i++) + { + lineBuffer[i] = _dataBuf[offset + CellToIndex(i, line)]; + } + + return lineBuffer; + } + + /// + /// Draws an adress part in the HEXDUMP view + /// + private void DrawAddress(Graphics g, int startLine, int line) + { + Font font = ADDRESS_FONT; + + string hexString = ((startLine + line) * _columnCount).ToString("X8", CultureInfo.InvariantCulture); + + using Brush foreground = new SolidBrush(ForeColor); + g.DrawString(hexString, font, foreground, ADDRESS_START_X, LINE_START_Y + line * CELL_HEIGHT); + } + + /// + /// Draws the client background and frames + /// + /// + private void DrawClient(Graphics g) + { + using (Brush brush = new SolidBrush(SystemColors.ControlLightLight)) + { + g.FillRectangle(brush, new Rectangle(HEX_START_X, + CLIENT_START_Y, + HEX_WIDTH + HEX_DUMP_GAP + DUMP_WIDTH + HEX_DUMP_GAP, + _rowCount * CELL_HEIGHT)); + } + + using (Pen pen = new Pen(SystemColors.ControlDark)) + { + g.DrawRectangle(pen, new Rectangle(HEX_START_X, + CLIENT_START_Y, + HEX_WIDTH + HEX_DUMP_GAP + DUMP_WIDTH + HEX_DUMP_GAP - 1, + _rowCount * CELL_HEIGHT - 1)); + g.DrawLine(pen, DUMP_START_X - HEX_DUMP_GAP, + CLIENT_START_Y, + DUMP_START_X - HEX_DUMP_GAP, + CLIENT_START_Y + _rowCount * CELL_HEIGHT - 1); + } + } + + // Char.IsPrintable is going away because it's a mostly meaningless concept. + // Copied code here to preserve semantics. -- BrianGru, 10/3/2000 + private static bool CharIsPrintable(char c) + { + UnicodeCategory uc = Char.GetUnicodeCategory(c); + return (!(uc == UnicodeCategory.Control) || (uc == UnicodeCategory.Format) || + (uc == UnicodeCategory.LineSeparator) || (uc == UnicodeCategory.ParagraphSeparator) || + (uc == UnicodeCategory.OtherNotAssigned)); + } + + /// + /// Draws the "DUMP" part in the HEXDUMP view + /// + private void DrawDump(Graphics g, byte[] lineBuffer, int line) + { + char c; + StringBuilder sb = new StringBuilder(lineBuffer.Length); + for (int i = 0; i < lineBuffer.Length; i++) + { + c = Convert.ToChar(lineBuffer[i]); + if (CharIsPrintable(c)) + { + sb.Append(c); + } + else + { + sb.Append('.'); + } + } + + Font font = HEXDUMP_FONT; + + using Brush foreground = new SolidBrush(ForeColor); + g.DrawString(sb.ToString(), font, foreground, DUMP_START_X, LINE_START_Y + line * CELL_HEIGHT); + } + + /// + /// Draws the "HEX" part in the HEXDUMP view + /// + /// + private void DrawHex(Graphics g, byte[] lineBuffer, int line) + { + Font font = HEXDUMP_FONT; + + StringBuilder result = new StringBuilder(lineBuffer.Length * 3 + 1); + for (int i = 0; i < lineBuffer.Length; i++) + { + result.Append(lineBuffer[i].ToString("X2", CultureInfo.InvariantCulture)); + result.Append(" "); + if (i == _columnCount / 2 - 1) + { + result.Append(" "); //add one extra in the middle + } + } + + using Brush foreground = new SolidBrush(ForeColor); + g.DrawString(result.ToString(), font, foreground, HEX_START_X + BORDER_GAP, LINE_START_Y + line * CELL_HEIGHT); + + /* ISSUE a-gregka: If perf problem, could be done this way to eliminate drawing twice on repaint + The current solution good enough for a dialog box + int hdc = g.getHandle(); + Windows.SelectObject(hdc, HEXDUMP_FONT.getHandle(g)); + Windows.ExtTextOut(hdc, HEX_START_X, LINE_START_Y - 1 + line * CELL_HEIGHT, + win.ETO_OPAQUE, + Utils.createRECT(HEX_START_X, LINE_START_Y -1 + line * CELL_HEIGHT, HEX_WIDTH, CELL_HEIGHT), + out, columnCount * 3 + 1, null); + */ + } + + /// + /// Draws the all lines (a line includes address, hex and dump part) for the HEXDUMP view + /// + private void DrawLines(Graphics g, int startLine, int linesCount) + { + for (int i = 0; i < linesCount; i++) + { + byte[] lineBuffer = ComposeLineBuffer(startLine, i); + DrawAddress(g, startLine, i); + DrawHex(g, lineBuffer, i); + DrawDump(g, lineBuffer, i); + } + } + + /// + /// Establishes the display mode for the control based on the contents of the buffer. + /// This is based on the following algorithm: + /// * Count number of zeros, prinables and other characters in the half of the dataBuffer + /// * Base on the following table establish the mode: + /// - 80% Characters or digits -> ANSI + /// - 80% Valid Unicode chars -> Unicode + /// - All other cases -> HEXDUMP + /// Also for the buffer of size [0..5] it returns the HEXDUMP mode + /// + /// + private DisplayMode GetAutoDisplayMode() + { + int printablesCount = 0; + int unicodeCount = 0; + int size; + + if ((_dataBuf == null) || (_dataBuf.Length >= 0 && (_dataBuf.Length < 8))) + { + return DisplayMode.Hexdump; + } + + switch (AnalizeByteOrderMark(_dataBuf, 0)) + { + case 2: + //_Encoding = Encoding.BigEndianUnicode; + return DisplayMode.Hexdump; + case 3: + //_Encoding = Encoding.Unicode; + return DisplayMode.Unicode; + case 4: + case 5: + //_Encoding = Ucs4Encoding.UCS4_Bigendian; + return DisplayMode.Hexdump; + case 6: + case 7: + //_Encoding = Ucs4Encoding.UCS4_Littleendian; + return DisplayMode.Hexdump; + case 8: + case 9: + //_Encoding = Ucs4Encoding.UCS4_3412; + return DisplayMode.Hexdump; + case 10: + case 11: + //_Encoding = Ucs4Encoding.UCS4_2143; + return DisplayMode.Hexdump; + case 12: + //8 ebcdic + return DisplayMode.Hexdump; + case 13: //9 + //_Encoding = new UTF8Encoding(false); + return DisplayMode.Ansi; + case 14: + return DisplayMode.Ansi; + default: + //If ByteOrderMark not detected try + if (_dataBuf.Length > 1024) + { + size = 512; + } + else + { + size = _dataBuf.Length / 2; + } + + for (int i = 0; i < size; i++) + { + char c = (char)_dataBuf[i]; //OK we do not care for Unicode now + if (Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c)) + { + printablesCount++; + } + } + for (int i = 0; i < size; i += 2) + { + char[] unicodeChars = new char[1]; + Encoding.Unicode.GetChars(_dataBuf, i, 2, unicodeChars, 0); + if (CharIsPrintable(unicodeChars[0])) + { + unicodeCount++; + } + } + + if (unicodeCount * 100 / (size / 2) > 80) + { + return DisplayMode.Unicode; + } + + if (printablesCount * 100 / size > 80) + { + return DisplayMode.Ansi; + } + + return DisplayMode.Hexdump; + } + } + + /// + /// Gets the bytes in the buffer. + /// + public virtual byte[] GetBytes() + { + return _dataBuf; + } + + /// + /// Gets the display mode for the control. + /// + public virtual DisplayMode GetDisplayMode() + { + return _displayMode; + } + + // Stole this code from XmlSanner + private static int GetEncodingIndex(int c1) + { + switch (c1) + { + case 0x0000: + return 1; + case 0xfeff: + return 2; + case 0xfffe: + return 3; + case 0xefbb: + return 4; + case 0x3c00: + return 5; + case 0x003c: + return 6; + case 0x3f00: + return 7; + case 0x003f: + return 8; + case 0x3c3f: + return 9; + case 0x786d: + return 10; + case 0x4c6f: + return 11; + case 0xa794: + return 12; + default: + return 0; //unknown + } + } + + /// + /// Initializes the ansi string variable that will be assigned to the edit box. + /// + private void InitAnsi() + { + int size = _dataBuf.Length; + char[] text = new char[size + 1]; + size = Interop.Kernel32.MultiByteToWideChar(0, 0, _dataBuf, size, text, size); + text[size] = (char)0; + + for (int i = 0; i < size; i++) + { + if (text[i] == '\0') + { + text[i] = (char)0x0B; + } + } + + _edit.Text = new string(text); + } + + /// + /// Initializes the Unicode string varible that will be assigned to the edit box + /// + private void InitUnicode() + { + char[] text = new char[_dataBuf.Length / 2 + 1]; + Encoding.Unicode.GetChars(_dataBuf, 0, _dataBuf.Length, text, 0); + for (int i = 0; i < text.Length; i++) + if (text[i] == '\0') + text[i] = (char)0x0B; + + text[text.Length - 1] = '\0'; + _edit.Text = new string(text); + } + + /// + /// Initializes the UI components of a control + /// + private void InitUI() + { + SCROLLBAR_HEIGHT = SystemInformation.HorizontalScrollBarHeight; + SCROLLBAR_WIDTH = SystemInformation.VerticalScrollBarWidth; + // For backwards compat + Size = new Size(SCROLLBAR_START_X + SCROLLBAR_WIDTH + BORDER_GAP + INSET_GAP, + 2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT)); + + _scrollBar = new VScrollBar(); + _scrollBar.ValueChanged += new EventHandler(ScrollChanged); + _scrollBar.TabStop = true; + _scrollBar.TabIndex = 0; + _scrollBar.Dock = DockStyle.Right; + _scrollBar.Visible = false; + + _edit = new TextBox(); + _edit.AutoSize = false; + _edit.BorderStyle = BorderStyle.None; + _edit.Multiline = true; + _edit.ReadOnly = true; + _edit.ScrollBars = ScrollBars.Both; + _edit.AcceptsTab = true; + _edit.AcceptsReturn = true; + _edit.Dock = DockStyle.Fill; + _edit.Margin = Padding.Empty; + _edit.WordWrap = false; + _edit.Visible = false; + + Controls.Add(_scrollBar, 0, 0); + Controls.Add(_edit, 0, 0); + } + + /// + /// Initializes some important variables + /// + private void InitState() + { + // calculate number of lines required (being careful to count 1 for the last partial line) + _linesCount = (_dataBuf.Length + _columnCount - 1) / _columnCount; + + _startLine = 0; + if (_linesCount > _rowCount) + { + _displayLinesCount = _rowCount; + _scrollBar.Hide(); + _scrollBar.Maximum = _linesCount - 1; + _scrollBar.LargeChange = _rowCount; + _scrollBar.Show(); + _scrollBar.Enabled = true; + } + else + { + _displayLinesCount = _linesCount; + _scrollBar.Hide(); + _scrollBar.Maximum = _rowCount; + _scrollBar.LargeChange = _rowCount; + _scrollBar.Show(); + _scrollBar.Enabled = false; + } + _scrollBar.Select(); + Invalidate(); + } + + /// + /// KeyDown handler. + /// + protected override void OnKeyDown(KeyEventArgs e) + { + _scrollBar.Select(); + } + + /// + /// Paint handler for the control. + /// + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + Graphics g = e.Graphics; + + switch (_realDisplayMode) + { + case DisplayMode.Hexdump: + SuspendLayout(); + _edit.Hide(); + _scrollBar.Show(); + ResumeLayout(); + DrawClient(g); + DrawLines(g, _startLine, _displayLinesCount); + break; + + case DisplayMode.Ansi: + _edit.Invalidate(); + break; + + case DisplayMode.Unicode: + _edit.Invalidate(); + break; + } + } + + /// + /// Resize handler for the control. + /// + protected override void OnLayout(LayoutEventArgs e) + { + // Must call this first since we might return + base.OnLayout(e); + + int rows = (ClientSize.Height - 2 * (BORDER_GAP + INSET_GAP)) / CELL_HEIGHT; + if (rows >= 0 && rows != _rowCount) + { + _rowCount = rows; + } + else + { + return; + } + + if (Dock == DockStyle.None) + { + // For backwards compatibility + Size = new Size(SCROLLBAR_START_X + SCROLLBAR_WIDTH + BORDER_GAP + INSET_GAP, + 2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT)); + } + + if (_scrollBar != null) + { + if (_linesCount > _rowCount) + { + _scrollBar.Hide(); + _scrollBar.Maximum = _linesCount - 1; + _scrollBar.LargeChange = _rowCount; + _scrollBar.Show(); + _scrollBar.Enabled = true; + _scrollBar.Select(); + } + else + { + _scrollBar.Enabled = false; + } + } + + _displayLinesCount = (_startLine + _rowCount < _linesCount) ? _rowCount : _linesCount - _startLine; + + } + + /// + /// Writes the raw data from the data buffer to a file. + /// + public virtual void SaveToFile(string path) + { + if (_dataBuf == null) + { + return; + } + + FileStream currentFile = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); + try + { + currentFile.Write(_dataBuf, 0, _dataBuf.Length); + currentFile.Close(); + } + catch + { + currentFile.Close(); + throw; + } + } + + /// + /// Scroll event handler. + /// + protected virtual void ScrollChanged(object source, EventArgs e) + { + _startLine = _scrollBar.Value; + + Invalidate(); + } + + /// + /// Sets the byte array to be displayed in the viewer. + /// + public virtual void SetBytes(byte[] bytes) + { + if (bytes == null) + { + throw new ArgumentNullException("bytes"); + } + + if (_dataBuf != null) + { + _dataBuf = null; + } + + _dataBuf = bytes; + InitState(); + SetDisplayMode(_displayMode); + } + + /// + /// Sets the current display mode. + /// + public virtual void SetDisplayMode(DisplayMode mode) + { + if (!ClientUtils.IsEnumValid(mode, (int)mode, (int)DisplayMode.Hexdump, (int)DisplayMode.Auto)) + { + throw new InvalidEnumArgumentException("mode", (int)mode, typeof(DisplayMode)); + } + + _displayMode = mode; + _realDisplayMode = (mode == DisplayMode.Auto) ? GetAutoDisplayMode() : mode; + + switch (_realDisplayMode) + { + case DisplayMode.Ansi: + InitAnsi(); + SuspendLayout(); + _edit.Show(); + _scrollBar.Hide(); + ResumeLayout(); + Invalidate(); + break; + + case DisplayMode.Unicode: + InitUnicode(); + SuspendLayout(); + _edit.Show(); + _scrollBar.Hide(); + ResumeLayout(); + Invalidate(); + break; + + case DisplayMode.Hexdump: + SuspendLayout(); + _edit.Hide(); + if (_linesCount > _rowCount) + { + if (!_scrollBar.Visible) + { + _scrollBar.Show(); + ResumeLayout(); + _scrollBar.Invalidate(); + _scrollBar.Select(); + } + else + { + ResumeLayout(); + } + } + else + { + ResumeLayout(); + } + break; + } + } + + /// + /// Sets the file to be displayed in the viewer. + /// + public virtual void SetFile(string path) + { + FileStream currentFile = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None); + try + { + int length = (int)currentFile.Length; + byte[] buf = new byte[length + 1]; + currentFile.Read(buf, 0, length); + SetBytes(buf); + currentFile.Close(); + } + catch + { + currentFile.Close(); + throw; + } + } + + /// + /// Sets the current line for the HEXDUMP view. + /// + public virtual void SetStartLine(int line) + { + if (line < 0 || line >= _linesCount || line > _dataBuf.Length / _columnCount) + { + _startLine = 0; + } + else + { + _startLine = line; + } + } + } +} diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DisplayMode.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DisplayMode.cs new file mode 100644 index 00000000000..f71404e4577 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DisplayMode.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.ComponentModel.Design +{ + /// + /// Specifies identifiers to indicate the display modes used by . + /// + public enum DisplayMode + { + /// + /// Indicates using Hexadecimal format. + /// + Hexdump = 1, + + /// + /// Indicates using ANSI format. + /// + Ansi = 2, + + /// + /// Indicates using Unicode format. + /// + Unicode = 3, + + /// + /// Indicates using automatic format selection. + /// + Auto = 4, + + } +}