Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion src/System.Windows.Forms.Design.Editors/src/Resources/SR.resx
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down Expand Up @@ -159,4 +218,7 @@ Press Ctrl+Enter to accept Text.</value>
<data name="ImageCollectionEditorFormText" xml:space="preserve">
<value>Images Collection Editor</value>
</data>
</root>
<data name="iconFileDescription" xml:space="preserve">
<value>Icon files</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Stisknutím kombinace kláves Ctrl+Enter text přijměte.</target>
<target state="translated">Rastrové soubory</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Všechny soubory obrázků</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Drücken Sie Strg+Eingabetaste, um Text zu übernehmen.</target>
<target state="translated">Bitmapdateien</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Alle Bilddateien</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Presione Ctrl+Entrar para aceptar el texto.</target>
<target state="translated">Archivos de mapas de bits</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Todos los archivos de imagen</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Appuyez sur Ctrl+Entrée pour valider le texte.</target>
<target state="translated">Fichiers bitmap</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Tous les fichiers image</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Per accettare testo premere CTRL+INVIO.</target>
<target state="translated">File bitmap</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Tutti i file di immagine</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Press Ctrl+Enter to accept Text.</source>
<target state="translated">ビットマップ ファイル</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">すべてのイメージ ファイル</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Press Ctrl+Enter to accept Text.</source>
<target state="translated">비트맵 파일</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">모든 이미지 파일</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Naciśnij klawisze Ctrl+Enter, aby zaakceptować tekst.</target>
<target state="translated">Pliki map bitowych</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Wszystkie pliki obrazów</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Pressione Ctrl+Enter para aceitar Texto.</target>
<target state="translated">Arquivos de bitmap</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Todos os arquivos de imagem</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Press Ctrl+Enter to accept Text.</source>
<target state="translated">Файлы точечных рисунков</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Все файлы изображений</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Metni kabul etmek için Ctrl+Enter tuşlarına basın.</target>
<target state="translated">Bit eşlem dosyaları</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">Tüm resim dosyaları</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Press Ctrl+Enter to accept Text.</source>
<target state="translated">位图文件</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">所有图像文件</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ Press Ctrl+Enter to accept Text.</source>
<target state="translated">點陣圖檔</target>
<note />
</trans-unit>
<trans-unit id="iconFileDescription">
<source>Icon files</source>
<target state="new">Icon files</target>
<note />
</trans-unit>
<trans-unit id="imageFileDescription">
<source>All image files</source>
<target state="translated">所有影像檔</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// 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.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace System.Drawing.Design
{
// NOTE: this class should be almost identical to ImageEditor. The main exception is PaintValue, which has logic that should probably be copied into ImageEditor.

/// <summary>
/// Provides an editor for visually picking an icon.
/// </summary>
public class IconEditor : UITypeEditor
{
private static List<string> s_iconExtensions = new List<string>() { "ico" };
private static Type[] s_imageExtenders = Array.Empty<Type>();
private FileDialog _fileDialog;

protected static string CreateExtensionsString(string[] extensions, string sep)
{
const string StarDot = "*.";

if (extensions == null || extensions.Length == 0)
{
return null;
}

string text = string.Empty;
for (int i = 0; i < extensions.Length; i++)
{
text = text + StarDot + extensions[i];
if (i < extensions.Length - 1)
{
text += sep;
}
}

return text;
}

protected static string CreateFilterEntry(IconEditor editor)
{
const string Comma = ",";
const string SemiColon = ";";
const string LeftParan = "(";
const string RightParan = ")";
const string Pipe = "|";

string desc = editor.GetFileDialogDescription();
string exts = CreateExtensionsString(editor.GetExtensions(), Comma);
string extsSemis = CreateExtensionsString(editor.GetExtensions(), SemiColon);
return desc + LeftParan + exts + RightParan + Pipe + extsSemis;
}

/// <summary>
/// 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.
/// </summary>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider == null)
{
return value;
}

var edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc == null)
{
return value;
}

if (_fileDialog == null)
{
_fileDialog = new OpenFileDialog();
var filter = CreateFilterEntry(this);

Debug.Assert(s_imageExtenders.Length <= 0, "Why does IconEditor have subclasses if Icon doesn't?");

_fileDialog.Filter = filter;
}

IntPtr hwndFocus = UnsafeNativeMethods.GetFocus();
try
{
if (_fileDialog.ShowDialog() == DialogResult.OK)
{
var file = new FileStream(_fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = LoadFromStream(file);
}
}
finally
{
if (hwndFocus != IntPtr.Zero)
{
UnsafeNativeMethods.SetFocus(new HandleRef(null, hwndFocus));
}
}

return value;
}

/// <summary>
/// Retrieves the editing style of the Edit method. If the method
/// is not supported, this will return None.
/// </summary>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
=> UITypeEditorEditStyle.Modal;

protected virtual string GetFileDialogDescription()
=> SR.iconFileDescription;

protected virtual string[] GetExtensions()
=> s_iconExtensions.ToArray();

/// <summary>
/// Determines if this editor supports the painting of a representation
/// of an object's value.
/// </summary>
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
=> true;

protected virtual Icon LoadFromStream(Stream stream)
=> new Icon(stream);

/// <summary>
/// Paints a representative value of the given object to the provided
/// canvas. Painting should be done within the boundaries of the
/// provided rectangle.
/// </summary>
public override void PaintValue(PaintValueEventArgs e)
{
if (!(e?.Value is Icon icon))
{
return;
}

// If icon is smaller than rectangle, just center it unscaled in the rectangle
Rectangle rectangle = e.Bounds;
if (icon.Width < rectangle.Width)
{
rectangle.X = (rectangle.Width - icon.Width) / 2;
rectangle.Width = icon.Width;
}
if (icon.Height < rectangle.Height)
{
rectangle.X = (rectangle.Height - icon.Height) / 2;
rectangle.Height = icon.Height;
}

e.Graphics.DrawIcon(icon, rectangle);
}
}
}
Loading