Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,236 @@
//------------------------------------------------------------------------------
// <copyright file="ChoiceConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Web.UI.Design.MobileControls.Util;
using System.Web.UI.MobileControls;
using System.Windows.Forms;
/// <summary>
/// <para>
/// Can filter and retrieve several types of values from controls.
/// </para>
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ChoiceConverter: StringConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (context != null && context.Instance is Array)
{
return value;
}
if (value is String)
{
return MatchFilterName((string)value, context);
}
return base.ConvertFrom(context, culture, value);
}
/// <summary>
/// </summary>
protected virtual Object [] GetChoices(Object instance)
{
bool defaultAdded = false;
DeviceSpecific deviceSpecific;
if (instance is System.Web.UI.MobileControls.StyleSheet)
{
StyleSheet ss = (StyleSheet) instance;
ISite componentSite = ss.Site;
Debug.Assert(componentSite != null, "Expected the component to be sited.");
IDesignerHost designerHost = (IDesignerHost) componentSite.GetService(typeof(IDesignerHost));
Debug.Assert(designerHost != null, "Expected a designer host.");
Object designer = designerHost.GetDesigner(ss);
Debug.Assert(designer != null, "Expected a designer for the stylesheet.");
Debug.Assert(designer is StyleSheetDesigner, "Expected a StyleSheet designer.");
StyleSheetDesigner ssd = (StyleSheetDesigner) designer;
Style style = (Style) ssd.CurrentStyle;
if (null != style)
{
deviceSpecific = style.DeviceSpecific;
}
else
{
deviceSpecific = null;
}
}
else if (instance is System.Web.UI.MobileControls.DeviceSpecific)
{
deviceSpecific = (DeviceSpecific) instance;
}
else if (instance is MobileControl)
{
MobileControl mc = (MobileControl) instance;
deviceSpecific = mc.DeviceSpecific;
}
else
{
// Simply return null if the instance is not recognizable.
return null;
}
ArrayList returnArray = new ArrayList();
// entry that corresponds to null CurrentChoice.
returnArray.Add(SR.GetString(SR.DeviceFilter_NoChoice));
if (null == deviceSpecific)
{
return returnArray.ToArray();
}
Debug.Assert(deviceSpecific.Choices != null);
foreach(DeviceSpecificChoice choice in deviceSpecific.Choices)
{
// Choice must have a Name
if (choice.Filter != null && choice.Filter.Length == 0)
{
if (!defaultAdded)
{
returnArray.Add(SR.GetString(SR.DeviceFilter_DefaultChoice));
defaultAdded = true;
}
}
else
{
if (!choice.Filter.Equals(SR.GetString(SR.DeviceFilter_NoChoice)))
{
returnArray.Add(DesignerUtility.ChoiceToUniqueIdentifier(choice));
}
}
}
returnArray.Sort();
return returnArray.ToArray();
}
/// <summary>
/// <para>
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that specifies the location of the context to convert from.
/// </param>
/// <returns>
/// <para>
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
/// </para>
/// </returns>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetChoices(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
private String MatchFilterName(String name, ITypeDescriptorContext context)
{
Debug.Assert(name != null, "Expected an actual device filter name to match.");
// Try a partial match
//
String bestMatch = null;
StandardValuesCollection standardValues = GetStandardValues(context);
if (standardValues == null)
{
return null;
}
IEnumerator e = standardValues.GetEnumerator();
while (e.MoveNext())
{
string filterName = e.Current.ToString();
if (String.Equals(filterName, name, StringComparison.OrdinalIgnoreCase)) {
// For an exact match, return immediately
//
return filterName;
}
else if (e.Current.ToString().StartsWith(name, StringComparison.OrdinalIgnoreCase))
{
if (bestMatch == null || filterName.Length <= bestMatch.Length)
{
bestMatch = filterName;
}
}
}
if (bestMatch == null)
{
// no match... use NoChoice
bestMatch = SR.GetString(SR.DeviceFilter_NoChoice);
}
return bestMatch;
}
}
}

View File

@@ -0,0 +1,236 @@
//------------------------------------------------------------------------------
// <copyright file="DataFieldConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Web.UI.Design;
using System.Web.UI.MobileControls;
using System.Security.Permissions;
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter"]/*' />
/// <devdoc>
/// <para>
/// Provides design-time support for a component's data field properties.
/// </para>
/// </devdoc>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class DataFieldConverter : TypeConverter
{
private const String _dataMemberPropertyName = "DataMember";
private const String _dataSourcePropertyName = "DataSource";
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.DataFieldConverter"]/*' />
/// <devdoc>
/// <para>
/// Initializes a new instance of <see cref='System.Web.UI.Design.DataFieldConverter'/>.
/// </para>
/// </devdoc>
public DataFieldConverter()
{
}
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.CanConvertFrom"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether this converter can
/// convert an object in the given source type to the native type of the converter
/// using the context.
/// </para>
/// </devdoc>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return false;
}
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.ConvertFrom"]/*' />
/// <devdoc>
/// <para>
/// Converts the given object to the converter's native type.
/// </para>
/// </devdoc>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value == null)
{
return String.Empty;
}
else if (value.GetType() == typeof(string))
{
return (string)value;
}
throw GetConvertFromException(value);
}
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValues"]/*' />
/// <devdoc>
/// <para>
/// Gets the fields present within the selected data source if information about them is available.
/// </para>
/// </devdoc>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
object[] names = null;
String dataMember = null;
bool autoGenerateFields = false;
bool autoGenerateFieldsSet = false;
ObjectList objectList = null;
if (context != null)
{
ArrayList list = new ArrayList();
PropertyDescriptorCollection props = null;
IComponent component = context.Instance as IComponent;
if (component is IDeviceSpecificChoiceDesigner)
{
Object owner = ((ChoicePropertyFilter)component).Owner;
PropertyDescriptor pd =
((ICustomTypeDescriptor)component).GetProperties()[_dataMemberPropertyName];
Debug.Assert(pd != null, "Cannot get DataMember");
if (owner is ObjectList)
{
autoGenerateFields = ((ObjectList)owner).AutoGenerateFields;
autoGenerateFieldsSet = true;
}
component = ((IDeviceSpecificChoiceDesigner)component).UnderlyingControl;
// See if owner already has a DataMember
dataMember = (String)pd.GetValue(owner);
Debug.Assert(dataMember != null);
if (dataMember != null && dataMember.Length == 0)
{
// Get it from underlying object.
dataMember = (String)pd.GetValue(component);
Debug.Assert(dataMember != null);
}
}
if (component != null)
{
objectList = component as ObjectList;
if (objectList != null)
{
foreach(ObjectListField field in objectList.Fields)
{
list.Add(field.Name);
}
if (!autoGenerateFieldsSet)
{
autoGenerateFields = objectList.AutoGenerateFields;
}
}
if (objectList == null || autoGenerateFields)
{
ISite componentSite = component.Site;
if (componentSite != null)
{
IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost));
if (designerHost != null)
{
IDesigner designer = designerHost.GetDesigner(component);
if (designer is IDataSourceProvider)
{
IEnumerable dataSource = null;
if (!String.IsNullOrEmpty(dataMember))
{
DataBindingCollection dataBindings =
((HtmlControlDesigner)designer).DataBindings;
DataBinding binding = dataBindings[_dataSourcePropertyName];
if (binding != null)
{
dataSource =
DesignTimeData.GetSelectedDataSource(
component,
binding.Expression,
dataMember);
}
}
else
{
dataSource =
((IDataSourceProvider)designer).GetResolvedSelectedDataSource();
}
if (dataSource != null)
{
props = DesignTimeData.GetDataFields(dataSource);
}
}
}
}
}
}
if (props != null)
{
foreach (PropertyDescriptor propDesc in props)
{
list.Add(propDesc.Name);
}
}
names = list.ToArray();
Array.Sort(names);
}
return new StandardValuesCollection(names);
}
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValuesExclusive"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether the collection of standard values returned from
/// <see cref='System.ComponentModel.TypeConverter.GetStandardValues'/> is an exclusive
/// list of possible values, using the specified context.
/// </para>
/// </devdoc>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValuesSupported"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether this object supports a standard set of values
/// that can be picked from a list.
/// </para>
/// </devdoc>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
if (context.Instance is IComponent)
{
// We only support the dropdown in single-select mode.
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,162 @@
//------------------------------------------------------------------------------
// <copyright file="DataMemberConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Web.UI.Design;
using System.Security.Permissions;
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter"]/*' />
/// <devdoc>
/// <para>
/// Provides design-time support for a component's DataMember properties.
/// </para>
/// </devdoc>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class DataMemberConverter : TypeConverter
{
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.DataMemberConverter"]/*' />
/// <devdoc>
/// <para>
/// Initializes a new instance of <see cref='System.Web.UI.Design.DataFieldConverter'/>.
/// </para>
/// </devdoc>
public DataMemberConverter()
{
}
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.CanConvertFrom"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether this converter can
/// convert an object in the given source type to the native type of the converter
/// using the context.
/// </para>
/// </devdoc>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return false;
}
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.ConvertFrom"]/*' />
/// <devdoc>
/// <para>
/// Converts the given object to the converter's native type.
/// </para>
/// </devdoc>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value == null)
{
return String.Empty;
}
else if (value.GetType() == typeof(string))
{
return (string)value;
}
throw GetConvertFromException(value);
}
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.GetStandardValues"]/*' />
/// <devdoc>
/// <para>
/// Gets the fields present within the selected data source if information about them is available.
/// </para>
/// </devdoc>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
string[] names = null;
if (context != null)
{
IComponent component = context.Instance as IComponent;
if (component is IDeviceSpecificChoiceDesigner)
{
component = ((IDeviceSpecificChoiceDesigner)component).UnderlyingControl;
}
if (component != null)
{
ISite componentSite = component.Site;
if (componentSite != null)
{
IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost));
if (designerHost != null)
{
IDesigner designer = designerHost.GetDesigner(component);
if (designer is IDataSourceProvider)
{
object dataSource = ((IDataSourceProvider)designer).GetSelectedDataSource();
if (dataSource != null)
{
names = DesignTimeData.GetDataMembers(dataSource);
}
}
}
}
}
if (names == null)
{
names = new string[0];
}
Array.Sort(names);
}
return new StandardValuesCollection(names);
}
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.GetStandardValuesExclusive"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether the collection of standard values returned from
/// <see cref='System.ComponentModel.TypeConverter.GetStandardValues'/> is an exclusive
/// list of possible values, using the specified context.
/// </para>
/// </devdoc>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.GetStandardValuesSupported"]/*' />
/// <devdoc>
/// <para>
/// Gets a value indicating whether this object supports a standard set of values
/// that can be picked from a list.
/// </para>
/// </devdoc>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
if (context.Instance is IComponent)
{
// We only support the dropdown in single-select mode.
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,138 @@
//------------------------------------------------------------------------------
// <copyright file="DefaultCommandConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.MobileControls;
/// <summary>
/// <para>
/// Can filter and retrieve several types of values from controls.
/// </para>
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class DefaultCommandConverter : StringConverter
{
private Object[] GetCommands(ObjectList objectList)
{
ObjectListCommandCollection commands = objectList.Commands;
if (commands.Count == 0)
{
return null;
}
ArrayList commandList = new ArrayList(commands.Count);
foreach(ObjectListCommand command in commands)
{
commandList.Add(command.Name);
}
commandList.Sort();
return commandList.ToArray();
}
/// <summary>
/// <para>
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that specifies the location of the context to convert from.
/// </param>
/// <returns>
/// <para>
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
/// </para>
/// </returns>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
ObjectList objectList = null;
if (context.Instance is IDeviceSpecificChoiceDesigner)
{
objectList = ((IDeviceSpecificChoiceDesigner)context.Instance).UnderlyingObject as ObjectList;
}
else if (context.Instance is ObjectList)
{
objectList = (ObjectList)context.Instance;
}
else
{
return null;
}
Debug.Assert(objectList != null);
Object [] objValues = GetCommands(objectList);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
if (context.Instance is IComponent)
{
// We only support the dropdown in single-select mode.
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,167 @@
//------------------------------------------------------------------------------
// <copyright file="FontNameConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using Microsoft.Win32;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Diagnostics;
using System.Globalization;
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal sealed class FontNameConverter : TypeConverter
{
private StandardValuesCollection values;
/// <devdoc>
/// Creates a new font name converter.
/// </devdoc>
public FontNameConverter()
{
// Sink an event to let us know when the installed
// set of fonts changes.
//
SystemEvents.InstalledFontsChanged += new EventHandler(this.OnInstalledFontsChanged);
}
/// <devdoc>
/// Determines if this converter can convert an object in the given source
/// type to the native type of the converter.
/// </devdoc>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
/// <devdoc>
/// Converts the given object to the converter's native type.
/// </devdoc>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return MatchFontName((string)value, context);
}
return base.ConvertFrom(context, culture, value);
}
/// <devdoc>
/// We need to know when we're finalized.
/// </devdoc>
~FontNameConverter()
{
SystemEvents.InstalledFontsChanged -= new EventHandler(this.OnInstalledFontsChanged);
}
/// <devdoc>
/// Retrieves a collection containing a set of standard values
/// for the data type this validator is designed for. This
/// will return null if the data type does not support a
/// standard set of values.
/// </devdoc>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (values == null)
{
FontFamily[] fonts = FontFamily.Families;
Hashtable hash = new Hashtable();
for (int i = 0; i < fonts.Length; i++)
{
string name = fonts[i].Name;
hash[name.ToLower(CultureInfo.InvariantCulture)] = name;
}
object[] array = new object[hash.Values.Count];
hash.Values.CopyTo(array, 0);
Array.Sort(array);
values = new StandardValuesCollection(array);
}
return values;
}
/// <devdoc>
/// Determines if the list of standard values returned from
/// GetStandardValues is an exclusive list. If the list
/// is exclusive, then no other values are valid, such as
/// in an enum data type. If the list is not exclusive,
/// then there are other valid values besides the list of
/// standard values GetStandardValues provides.
/// </devdoc>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <devdoc>
/// Determines if this object supports a standard set of values
/// that can be picked from a list.
/// </devdoc>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
private string MatchFontName(string name, ITypeDescriptorContext context)
{
Debug.Assert(name != null, "Expected an actual font name to match in FontNameConverter::MatchFontName.");
// AUI 2300
if (name.Trim().Length == 0)
{
return String.Empty;
}
// Try a partial match
//
string bestMatch = null;
IEnumerator e = GetStandardValues(context).GetEnumerator();
while (e.MoveNext())
{
string fontName = e.Current.ToString();
if (String.Equals(fontName, name, StringComparison.OrdinalIgnoreCase)) {
// For an exact match, return immediately
//
return fontName;
}
else if (fontName.StartsWith(name, StringComparison.OrdinalIgnoreCase)) {
if (bestMatch == null || fontName.Length <= bestMatch.Length)
{
bestMatch = fontName;
}
}
}
if (bestMatch == null)
{
// no match... fall back on whatever was provided
bestMatch = name;
}
return bestMatch;
}
/// <devdoc>
/// Called by system events when someone adds or removes a font. Here
/// we invalidate our font name collection.
/// </devdoc>
private void OnInstalledFontsChanged(object sender, EventArgs e)
{
values = null;
}
}
}

View File

@@ -0,0 +1,212 @@
//------------------------------------------------------------------------------
// <copyright file="FormConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.Design.MobileControls.Adapters;
/// <summary>
/// <para>
/// Can filter and retrieve several types of values from Style controls.
/// </para>
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class FormConverter : StringConverter
{
private Form GetContainingForm(MobileControl mc)
{
return FindContainer(mc, typeof(Form)) as Form;
}
private StyleSheet GetContainingStyleSheet(MobileControl mc)
{
return FindContainer(mc, typeof(StyleSheet)) as StyleSheet;
}
private Control FindContainer(MobileControl mc, Type containerType)
{
for (Control control = mc; control != null; control = control.Parent)
{
if (containerType.IsAssignableFrom(control.GetType()))
{
return control;
}
}
return null;
}
protected virtual ArrayList GetControls(ITypeDescriptorContext context)
{
ArrayList controlList = new ArrayList();
MobileControl control = null;
IContainer container = context.Container;
if (context.Instance is Array)
{
Array list = (Array)context.Instance;
Debug.Assert(list.Length > 0);
foreach(Object obj in list)
{
Debug.Assert(obj is MobileControl);
Form form = GetContainingForm((MobileControl)obj);
// If the control is not within a Form control or a StyleSheet control,
// simply return the empty combobox.
// If the control is placed at UserControl top level, the ID of the
// containing Form is null.
if ((form == null || form.ID == null) &&
GetContainingStyleSheet((MobileControl)obj) == null)
{
return null;
}
}
control = list.GetValue(0) as MobileControl;
}
else
{
if (context.Instance is MobileControl)
{
control = (MobileControl) context.Instance;
}
else if (context.Instance is ChoicePropertyFilter)
{
ChoicePropertyFilter filter = (ChoicePropertyFilter)context.Instance;
IDeviceSpecificDesigner designer = filter.Designer;
control = designer.UnderlyingObject as MobileControl;
Debug.Assert(control != null, "Not a control");
}
else
{
Debug.Fail("Unrecognized object passed in");
return null;
}
Form form = GetContainingForm(control);
// All controls must be contained within Forms or StyleSheets
// Show empty combobox for the invalid control.
if (form == null)
{
if (GetContainingStyleSheet(control) == null)
{
return null;
}
}
// MobileUserControl has a default Form with null ID
else if (form.ID == null && (GetContainingStyleSheet(control) == null))
{
Debug.Assert(container is IDesignerHost &&
((IDesignerHost)container).RootComponent is MobileUserControl);
// Just return an empty array list, so that url picker still works.
return controlList;
}
}
// If container is null, try to get one from control's IContainer
if (container == null)
{
ISite site = control.Site;
Debug.Assert(site != null);
container = site.Container;
}
// Is this possible?
if (container == null)
{
Debug.Fail("container is null");
return null;
}
foreach(IComponent component in container.Components)
{
Form candidate = component as Form;
if (candidate != null &&
candidate.ID != null &&
candidate.ID.Length != 0)
{
controlList.Add(ProcessControlId(candidate.ID));
}
}
controlList.Sort();
return controlList;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null)
{
return null;
}
ArrayList objValues = GetControls(context);
return (objValues != null? new StandardValuesCollection(objValues) : null);
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
/// <summary>
/// Override to manipulate the control id as it is added to the list.
/// Do not return the original string, make sure a copy is made.
/// See NavigateUrlConverter.cs for an example.
/// </summary>
protected virtual String ProcessControlId(String id)
{
return id;
}
}
}

View File

@@ -0,0 +1,69 @@
//------------------------------------------------------------------------------
// <copyright file="NavigateUrlConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.ComponentModel;
using System.Collections;
using System.Globalization;
using System.Web.UI.MobileControls;
/// <summary>
/// Subclass of FormConverter to handle the special case where we want
/// to select a form OR a valid URL to navigate to.
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class NavigateUrlConverter : FormConverter
{
protected override ArrayList GetControls(ITypeDescriptorContext context)
{
ArrayList formList = base.GetControls(context);
// We disable the "Select Url..." option in multi-selected case
if (formList != null && !(context.Instance is Array))
{
formList.Insert(0, SR.GetString(SR.NavigateUrlConverter_SelectURITarget));
}
return formList;
}
protected override String ProcessControlId(String id)
{
return "#" + id;
}
/// <summary>
/// url = new value in OnPropertyChanged, we check to see if we need to
/// browse for the url. If not, we just return this value.
/// oldUrl = old value of URL, used to initialize URL builder and returned
/// if the user cancels.
/// </summary>
internal static String GetUrl(IComponent component, String url, String oldUrl)
{
if(url == SR.GetString(SR.NavigateUrlConverter_SelectURITarget))
{
url = UrlBuilder.BuildUrl(
component,
null,
oldUrl,
SR.GetString(SR.UrlPicker_DefaultCaption),
SR.GetString(SR.UrlPicker_DefaultFilter)
);
if (url == null)
{
url = oldUrl;
}
}
return url;
}
}
}

View File

@@ -0,0 +1,131 @@
//------------------------------------------------------------------------------
// <copyright file="StyleConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.UI.MobileControls;
/// <summary>
/// <para>
/// Can filter and retrieve several types of values from controls.
/// </para>
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class StyleConverter: StringConverter
{
protected virtual Object [] GetStyles(Object instance)
{
// We do not support anything other than a single styleSheet
if (!(instance is System.Web.UI.MobileControls.StyleSheet))
{
return null;
}
StyleSheet _styleSheet = (StyleSheet)instance;
ICollection styles = _styleSheet.Styles;
ArrayList _styleArray = new ArrayList();
foreach (String key in styles)
{
System.Web.UI.MobileControls.Style style = (System.Web.UI.MobileControls.Style) _styleSheet[key];
if (style.Name != null && style.Name.Length > 0)
{
_styleArray.Add(style.Name);
}
}
if (0 == _styleArray.Count)
{
// add (None) entry for CurrentStyle == null
_styleArray.Add(SR.GetString(SR.StyleSheet_PropNotSet));
}
_styleArray.Sort();
return _styleArray.ToArray();
}
/// <summary>
/// <para>
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that specifies the location of the context to convert from.
/// </param>
/// <returns>
/// <para>
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
/// </para>
/// </returns>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetStyles(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}

View File

@@ -0,0 +1,218 @@
//------------------------------------------------------------------------------
// <copyright file="StyleReferenceConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.Globalization;
using System.ComponentModel;
using System.Web.UI.MobileControls;
using System.Web.UI.Design.MobileControls.Adapters;
using System.Web.UI.Design.MobileControls.Util;
/// <summary>
/// <para>
/// Can filter and retrieve several types of values from controls.
/// </para>
/// </summary>
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class StyleReferenceConverter: StringConverter
{
protected virtual Object [] GetStyles(Object instance)
{
StyleSheet styleSheet = null;
Style instanceStyle = null;
// Remember, ChoicePropertyFilter is a MobileControl, so we must
// check for ChoicePropertyFilter first...
if (instance is IDeviceSpecificChoiceDesigner)
{
instance = ((IDeviceSpecificChoiceDesigner)instance).UnderlyingObject;
}
if (instance is System.Web.UI.MobileControls.Style)
{
instanceStyle = (Style) instance;
if (instanceStyle.Control is StyleSheet)
{
styleSheet = (StyleSheet) instanceStyle.Control;
}
else if ((instanceStyle.Control is Form && instanceStyle is PagerStyle) ||
(instanceStyle.Control is ObjectList))
{
if (instanceStyle.Control.MobilePage != null)
{
styleSheet = instanceStyle.Control.MobilePage.StyleSheet;
}
else
{
return null;
}
}
else
{
Debug.Fail("Unsupported objects passed in");
}
}
else if (instance is System.Web.UI.MobileControls.MobileControl)
{
MobileControl control = (MobileControl)instance;
if (control.MobilePage == null)
{
return null;
}
styleSheet = control.MobilePage.StyleSheet;
}
else if (instance is Array)
{
Array array = (Array)instance;
Debug.Assert(array.Length > 0);
return GetStyles(array.GetValue(0));
}
else
{
Debug.Fail("Unsupported type passed in");
return null;
}
Debug.Assert(null != styleSheet);
ICollection styles = styleSheet.Styles;
ArrayList styleArray = new ArrayList();
foreach (String key in styles)
{
System.Web.UI.MobileControls.Style style = styleSheet[key];
if (style.Name != null && style.Name.Length > 0)
{
if (null == instanceStyle || 0 != String.Compare(instanceStyle.Name, style.Name, StringComparison.Ordinal))
{
styleArray.Add(style.Name);
}
}
}
if (styleSheet == StyleSheet.Default)
{
styleArray.Sort();
return styleArray.ToArray();
}
styles = StyleSheet.Default.Styles;
foreach (String key in styles)
{
System.Web.UI.MobileControls.Style style = StyleSheet.Default[key];
if (style.Name != null && style.Name.Length > 0)
{
if (null == instanceStyle || 0 != String.Compare(instanceStyle.Name, style.Name, StringComparison.Ordinal))
{
styleArray.Add(style.Name);
}
}
}
if (styleArray.Count <= 1)
{
return styleArray.ToArray();
}
styleArray.Sort();
String preID = ((String)styleArray[0]).ToLower(CultureInfo.InvariantCulture);
int i = 1;
while (i < styleArray.Count)
{
if (String.Equals((String)styleArray[i], preID, StringComparison.OrdinalIgnoreCase)) {
styleArray.RemoveAt(i);
}
else
{
preID = ((String)styleArray[i]).ToLower(CultureInfo.InvariantCulture);
i++;
}
}
return styleArray.ToArray();
}
/// <summary>
/// <para>
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that specifies the location of the context to convert from.
/// </param>
/// <returns>
/// <para>
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
/// </para>
/// </returns>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetStyles(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}

View File

@@ -0,0 +1,235 @@
//------------------------------------------------------------------------------
// <copyright file="ValidatedMobileControlConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design.MobileControls.Adapters;
using System.Web.UI.MobileControls;
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ValidatedMobileControlConverter: StringConverter
{
private Form GetContainingForm(MobileControl mc)
{
return FindContainer(mc, typeof(Form)) as Form;
}
private StyleSheet GetContainingStyleSheet(MobileControl mc)
{
return FindContainer(mc, typeof(StyleSheet)) as StyleSheet;
}
private Control FindContainer(MobileControl mc, Type containerType)
{
for (Control control = mc; control != null; control = control.Parent)
{
if (containerType.IsAssignableFrom(control.GetType()))
{
return control;
}
}
return null;
}
protected virtual Object [] GetValidatableControls(Object instance)
{
System.Web.UI.MobileControls.BaseValidator thisValidator = null;
if (instance is Array)
{
Array controlList = (Array)instance;
Debug.Assert(controlList.Length > 0);
thisValidator = (BaseValidator) controlList.GetValue(0);
Form firstForm = GetContainingForm(thisValidator);
for (int i = 1; i < controlList.Length; i++)
{
BaseValidator validator = (BaseValidator)controlList.GetValue(i);
if (GetContainingForm(validator) != firstForm)
{
return null;
}
}
}
if (instance is System.Web.UI.MobileControls.BaseValidator)
{
thisValidator = (System.Web.UI.MobileControls.BaseValidator) instance;
}
else if (instance is ChoicePropertyFilter)
{
IDeviceSpecificDesigner designer =
((ChoicePropertyFilter)instance).Designer;
thisValidator = designer.UnderlyingObject
as System.Web.UI.MobileControls.BaseValidator;
}
if (thisValidator == null)
{
Debug.Fail("Unsupported object passed in");
return null;
}
ArrayList controlArray = new ArrayList();
if (GetContainingStyleSheet(thisValidator) != null)
{
ISite site = thisValidator.Site;
IContainer container = null;
if (site != null)
{
container = site.Container;
Debug.Assert(container != null);
foreach(IComponent component in container.Components)
{
Control control = component as Control;
if (control != null && CanBeValidated(control))
{
controlArray.Add(control.ID);
}
}
}
}
else
{
Form parentForm = GetContainingForm(thisValidator);
if (parentForm != null)
{
ExtractValidatableControls(parentForm, controlArray);
}
else
{
return null;
}
}
controlArray.Sort();
return controlArray.ToArray();
}
private void ExtractValidatableControls(Control parent, ArrayList controlArray)
{
foreach (Control control in parent.Controls)
{
if (CanBeValidated(control))
{
controlArray.Add(control.ID);
}
if (!(control is Form))
{
ExtractValidatableControls(control, controlArray);
}
}
}
private bool CanBeValidated(Control control)
{
// Control must have an ID
if (control.ID == null || control.ID.Length == 0)
{
return false;
}
// Control must have a ValidationProperty attribute
ValidationPropertyAttribute valProp =
(ValidationPropertyAttribute)
TypeDescriptor.GetAttributes(control)[typeof(ValidationPropertyAttribute)];
if (null != valProp && null != valProp.Name)
{
return true;
}
return false;
}
/// <summary>
/// <para>
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that specifies the location of the context to convert from.
/// </param>
/// <returns>
/// <para>
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
/// </para>
/// </returns>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetValidatableControls(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
/// <summary>
/// <para>
/// Gets whether
/// or not the context specified contains exclusive standard values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context contains exclusive standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// <summary>
/// <para>
/// Gets whether or not the specified context contains supported standard
/// values.
/// </para>
/// </summary>
/// <param name='context'>
/// A type descriptor that indicates the context to convert from.
/// </param>
/// <returns>
/// <para>
/// <see langword='true'/> if the specified context conatins supported standard
/// values, otherwise <see langword='false'/>.
/// </para>
/// </returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}