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,74 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerAdRotatorAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerAdRotatorAdapter : System.Web.UI.MobileControls.Adapters.HtmlControlAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
String width = DesignerAdapterUtil.GetWidth(Control);
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteBeginTag("div");
if (alignment == Alignment.Center)
{
writer.WriteAttribute("align", "center");
}
writer.WriteAttribute("style", "padding=2px;overflow-x:hidden;width:" + width);
writer.Write(">");
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", Control.ID);
((DesignerTextWriter)writer).WriteStyleAttribute(Style);
// center alignment not part of HTML for images.
if (alignment == Alignment.Right ||
alignment == Alignment.Left)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.WriteAttribute("height", "40");
writer.WriteAttribute("width", "250");
writer.WriteAttribute("border", "0");
writer.Write(">");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,423 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerAdapterUtil.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Diagnostics;
using System.Globalization;
using System.Web.UI.Design;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 static class DesignerAdapterUtil
{
// margin width is 10px on right (10px on left taken care of by parentChildOffset)
private const int _marginWidth = 10;
// default Panel or Form width
private const int _defaultContainerWidth = 300;
// 11px on the left and the right for padding and margin between levels
private const int _marginPerLevel = 22;
// offset of control within a template is 10px on the left + 11px on the right + 1
private const int _templateParentChildOffset = 22;
// offset of control outside of a template is 11px
private const int _regularParentChildOffset = 11;
// default width for controls in templates. The value doesn't matter as long as it is
// equal or larger than parent width, since the parent control designer will still
// truncate to 100%
internal const int CONTROL_MAX_WIDTH_IN_TEMPLATE = 300;
internal const byte CONTROL_IN_TEMPLATE_NONEDIT = 0x01;
internal const byte CONTROL_IN_TEMPLATE_EDIT = 0x02;
internal static IDesigner ControlDesigner(IComponent component)
{
Debug.Assert(null != component);
ISite compSite = component.Site;
if (compSite != null)
{
return ((IDesignerHost) compSite.GetService(typeof(IDesignerHost))).GetDesigner(component);
}
return null;
}
internal static ContainmentStatus GetContainmentStatus(Control control)
{
ContainmentStatus containmentStatus = ContainmentStatus.Unknown;
Control parent = control.Parent;
if (control == null || parent == null)
{
return containmentStatus;
}
if (parent is Form)
{
containmentStatus = ContainmentStatus.InForm;
}
else if (parent is Panel)
{
containmentStatus = ContainmentStatus.InPanel;
}
else if (parent is Page || parent is UserControl)
{
containmentStatus = ContainmentStatus.AtTopLevel;
}
else if (InTemplateFrame(control))
{
containmentStatus = ContainmentStatus.InTemplateFrame;
}
return containmentStatus;
}
internal static IComponent GetRootComponent(IComponent component)
{
Debug.Assert(null != component);
ISite compSite = component.Site;
if (compSite != null)
{
IDesignerHost host = (IDesignerHost)compSite.GetService(typeof(IDesignerHost));
if (host != null)
{
return host.RootComponent;
}
}
return null;
}
internal static String GetWidth(Control control)
{
if (DesignerAdapterUtil.GetContainmentStatus(control) == ContainmentStatus.AtTopLevel)
{
return Constants.ControlSizeAtToplevelInNonErrorMode;
}
return Constants.ControlSizeInContainer;
}
internal static bool InMobilePage(Control control)
{
return (control != null && control.Page is MobilePage);
}
internal static bool InUserControl(IComponent component)
{
return GetRootComponent(component) is UserControl;
}
internal static bool InMobileUserControl(IComponent component)
{
return GetRootComponent(component) is MobileUserControl;
}
// Returns true if the closest templateable ancestor is in template editing mode.
internal static bool InTemplateFrame(Control control)
{
if (control.Parent == null)
{
return false;
}
TemplatedControlDesigner designer =
ControlDesigner(control.Parent) as TemplatedControlDesigner;
if (designer == null)
{
return InTemplateFrame(control.Parent);
}
if (designer.InTemplateMode)
{
return true;
}
return false;
}
internal static void AddAttributesToProperty(
Type designerType,
IDictionary properties,
String propertyName,
Attribute[] attributeArray)
{
Debug.Assert (propertyName != null &&
propertyName.Length != 0);
PropertyDescriptor prop = (PropertyDescriptor)properties[propertyName];
Debug.Assert(prop != null);
prop = TypeDescriptor.CreateProperty (
designerType,
prop,
attributeArray);
properties[propertyName] = prop;
}
internal static void AddAttributesToPropertiesOfDifferentType(
Type designerType,
Type newType,
IDictionary properties,
String propertyName,
Attribute newAttribute)
{
Debug.Assert (propertyName != null &&
propertyName.Length != 0);
PropertyDescriptor prop = (PropertyDescriptor)properties[propertyName];
Debug.Assert(prop != null);
// we can't create the designer DataSource property based on the runtime property since their
// types do not match. Therefore, we have to copy over all the attributes from the runtime
// and use them that way.
System.ComponentModel.AttributeCollection runtimeAttributes = prop.Attributes;
Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1];
runtimeAttributes.CopyTo(attrs, 0);
attrs[runtimeAttributes.Count] = newAttribute;
prop = TypeDescriptor.CreateProperty (
designerType,
propertyName,
newType,
attrs);
properties[propertyName] = prop;
}
internal static int NestingLevel(Control control,
out bool inTemplate,
out int defaultControlWidthInTemplate)
{
int level = -1;
defaultControlWidthInTemplate = 0;
inTemplate = false;
if (control != null)
{
Control parent = control.Parent;
while (parent != null)
{
level++;
IDesigner designer = ControlDesigner(parent);
if (designer is MobileTemplatedControlDesigner)
{
defaultControlWidthInTemplate =
((MobileTemplatedControlDesigner) designer).TemplateWidth -
_templateParentChildOffset;
inTemplate = true;
return level;
}
parent = parent.Parent;
}
}
return level;
}
internal static void SetStandardStyleAttributes(IHtmlControlDesignerBehavior behavior,
ContainmentStatus containmentStatus)
{
if (behavior == null) {
return;
}
bool controlAtTopLevel = (containmentStatus == ContainmentStatus.AtTopLevel);
Color cw = SystemColors.Window;
Color ct = SystemColors.WindowText;
Color c = Color.FromArgb((Int16)(ct.R * 0.1 + cw.R * 0.9),
(Int16)(ct.G * 0.1 + cw.G * 0.9),
(Int16)(ct.B * 0.1 + cw.B * 0.9));
behavior.SetStyleAttribute("borderColor", true, ColorTranslator.ToHtml(c), true);
behavior.SetStyleAttribute("borderStyle", true, "solid", true);
behavior.SetStyleAttribute("borderWidth", true, "1px", true);
behavior.SetStyleAttribute("marginLeft", true, "5px", true);
behavior.SetStyleAttribute("marginRight", true, controlAtTopLevel ? "30%" : "5px", true);
behavior.SetStyleAttribute("marginTop", true, controlAtTopLevel ? "5px" : "2px", true);
behavior.SetStyleAttribute("marginBottom", true, controlAtTopLevel ? "5px" : "2px", true);
}
internal static String GetDesignTimeErrorHtml(
String errorMessage,
bool infoMode,
Control control,
IHtmlControlDesignerBehavior behavior,
ContainmentStatus containmentStatus)
{
String id = String.Empty;
Debug.Assert(control != null, "control is null");
if (control.Site != null)
{
id = control.Site.Name;
}
if (behavior != null) {
behavior.SetStyleAttribute("borderWidth", true, "0px", true);
}
return String.Format(CultureInfo.CurrentCulture,
MobileControlDesigner.defaultErrorDesignTimeHTML,
new Object[]
{
control.GetType().Name,
id,
errorMessage,
infoMode? MobileControlDesigner.infoIcon : MobileControlDesigner.errorIcon,
((containmentStatus == ContainmentStatus.AtTopLevel) ?
Constants.ControlSizeAtToplevelInErrormode :
Constants.ControlSizeInContainer)
});
}
internal static int GetMaxWidthToFit(MobileControl control, out byte templateStatus)
{
IDesigner parentDesigner = ControlDesigner(control.Parent);
IDesigner controlDesigner = ControlDesigner(control);
int defaultControlWidthInTemplate;
NativeMethods.IHTMLElement2 htmlElement2Parent = null;
if (controlDesigner == null)
{
templateStatus = CONTROL_IN_TEMPLATE_NONEDIT;
return 0;
}
Debug.Assert(controlDesigner is MobileControlDesigner ||
controlDesigner is MobileTemplatedControlDesigner,
"controlDesigner is not MobileControlDesigner or MobileTemplatedControlDesigner");
templateStatus = 0x00;
if (parentDesigner is MobileTemplatedControlDesigner)
{
htmlElement2Parent =
(NativeMethods.IHTMLElement2)
((MobileTemplatedControlDesigner) parentDesigner).DesignTimeElementInternal;
}
else if (parentDesigner is MobileContainerDesigner)
{
htmlElement2Parent =
(NativeMethods.IHTMLElement2)
((MobileContainerDesigner) parentDesigner).DesignTimeElementInternal;
}
bool inTemplate;
int nestingLevel = DesignerAdapterUtil.NestingLevel(control, out inTemplate, out defaultControlWidthInTemplate);
if (inTemplate)
{
templateStatus = CONTROL_IN_TEMPLATE_EDIT;
}
if (htmlElement2Parent != null)
{
int maxWidth;
if (!inTemplate)
{
Debug.Assert(control.Parent is MobileControl);
Style parentStyle = ((MobileControl) control.Parent).Style;
Alignment alignment = (Alignment) parentStyle[Style.AlignmentKey, true];
int parentChildOffset=0;
// AUI 2786
if (alignment != Alignment.NotSet && alignment != Alignment.Left)
{
parentChildOffset = _regularParentChildOffset;
}
else
{
NativeMethods.IHTMLRectCollection rectColl = null;
NativeMethods.IHTMLRect rect = null;
int index = 0;
Object obj = index;
NativeMethods.IHTMLElement2 htmlElement2;
if (controlDesigner is MobileControlDesigner)
{
htmlElement2 = (NativeMethods.IHTMLElement2) ((MobileControlDesigner) controlDesigner).DesignTimeElementInternal;
}
else
{
htmlElement2 = (NativeMethods.IHTMLElement2) ((MobileTemplatedControlDesigner) controlDesigner).DesignTimeElementInternal;
}
if (null == htmlElement2)
{
return 0;
}
try
{
rectColl = htmlElement2.GetClientRects();
}
catch (Exception)
{
// this happens when switching from Design view to HTML view
return 0;
}
if( rectColl.GetLength() >= 1)
{
rect = (NativeMethods.IHTMLRect)rectColl.Item(ref obj);
parentChildOffset = rect.GetLeft();
rectColl = htmlElement2Parent.GetClientRects();
//Debug.Assert(rectColl.GetLength() == 1);
rect = (NativeMethods.IHTMLRect) rectColl.Item(ref obj);
parentChildOffset -= rect.GetLeft();
}
}
maxWidth = GetLength(htmlElement2Parent) - _marginWidth - parentChildOffset;
if (maxWidth > 0 && maxWidth > _defaultContainerWidth - nestingLevel * _marginPerLevel)
{
maxWidth = _defaultContainerWidth - nestingLevel * _marginPerLevel;
}
}
else
{
int parentWidth = GetLength(htmlElement2Parent);
if (parentWidth == 0)
{
// AUI 4525
maxWidth = defaultControlWidthInTemplate;
}
else
{
maxWidth = parentWidth - _templateParentChildOffset;
}
if (maxWidth > 0 && maxWidth > defaultControlWidthInTemplate - nestingLevel * _marginPerLevel)
{
maxWidth = defaultControlWidthInTemplate - nestingLevel * _marginPerLevel;
}
}
return maxWidth;
}
return 0;
}
private static int GetLength(NativeMethods.IHTMLElement2 element) {
NativeMethods.IHTMLRectCollection rectColl = element.GetClientRects();
//Debug.Assert(rectColl.GetLength() == 1);
Object obj = rectColl.GetLength() - 1;
NativeMethods.IHTMLRect rect = (NativeMethods.IHTMLRect)rectColl.Item(ref obj);
return rect.GetRight() - rect.GetLeft();
}
}
}

View File

@@ -0,0 +1,56 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerCalendarAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Drawing;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerCalendarAdapter : HtmlCalendarAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
writer.WriteBeginTag("div");
String width = DesignerAdapterUtil.GetWidth(Control);
writer.WriteAttribute("style", "cellpadding=2px;width:" + width);
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write("/>");
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
//Note: Although this is an internal method of runtime, but it is still
// pretty easy to achieve the same goal without using this method.
Style.ApplyTo(Control.WebCalendar);
base.Render(writer);
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,212 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerCommandAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.IO;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerCommandAdapter : HtmlCommandAdapter
{
// required width may differ a little bit from actual exact pixel value
private const int SAFETY_MARGIN = 8;
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
// Invalid text writers are not supported in this Adapter.
if (!(writer is DesignerTextWriter))
{
return;
}
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
String width = DesignerAdapterUtil.GetWidth(Control);
if (Control.ImageUrl.Length == 0)
{
if (Control.Format == CommandFormat.Button)
{
if (maxWidth == 0 && templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_NONEDIT)
{
maxWidth = DesignerAdapterUtil.CONTROL_MAX_WIDTH_IN_TEMPLATE;
}
if (maxWidth == 0 && DesignerAdapterUtil.InMobileUserControl(Control))
{
maxWidth = Constants.ControlMaxsizeAtToplevel;
}
if (maxWidth == 0)
{
// Render will be called a second time for which maxWidth != 0
return;
}
String additionalStyle = null;
String controlText = Control.Text;
String commandCaption;
int requiredWidth = 0;
DesignerTextWriter twTmp;
twTmp = new DesignerTextWriter();
twTmp.WriteBeginTag("input");
twTmp.WriteStyleAttribute(Style, null);
twTmp.WriteAttribute("type", "submit");
twTmp.Write(" value=\"");
twTmp.WriteText(controlText, true);
twTmp.Write("\"/>");
String htmlFragment = twTmp.ToString();
MSHTMLHostUtil.ApplyStyle(String.Empty, String.Empty, null);
requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(htmlFragment);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
if (requiredWidth + SAFETY_MARGIN > maxWidth)
{
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
int tmpRequiredWidth, allowedLength;
int captionLength = controlText.Length;
twTmp = new DesignerTextWriter();
twTmp.WriteBeginTag("input");
twTmp.WriteStyleAttribute(Style, null);
twTmp.WriteAttribute("type", "submit");
twTmp.WriteAttribute("value", "{0}");
twTmp.Write("/>");
htmlFragment = twTmp.ToString();
// At least 10 characters can fit into the caption of the command
for (allowedLength = (captionLength < 10 ? captionLength : 10); allowedLength <= captionLength; allowedLength++)
{
tmpRequiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(String.Format(CultureInfo.CurrentCulture, htmlFragment, HttpUtility.HtmlEncode(controlText.Substring(0, allowedLength))));
if (tmpRequiredWidth + SAFETY_MARGIN > maxWidth)
{
break;
}
}
commandCaption = controlText.Substring(0, allowedLength - 1);
}
else
{
commandCaption = controlText;
}
}
else
{
writer.WriteAttribute("style", "width:" + width);
commandCaption = controlText;
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
writer.EnterLayout(Style);
writer.WriteBeginTag("input");
if (requiredWidth + SAFETY_MARGIN > maxWidth)
{
additionalStyle = String.Format(CultureInfo.CurrentCulture, "width:{0};", width);
}
((DesignerTextWriter)writer).WriteStyleAttribute(Style, additionalStyle);
writer.WriteAttribute("type", "submit");
writer.Write(" value=\"");
writer.WriteText(commandCaption, true);
writer.Write("\"/>");
writer.ExitLayout(Style);
}
else
{
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
if (!wrap)
{
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
}
else
{
writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
writer.WriteBeginTag("a");
writer.WriteAttribute("href", "NavigationUrl");
writer.Write(">");
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
writer.WriteEndTag("a");
}
writer.WriteEndTag("div");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
else
{
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteBeginTag("div");
if (alignment == Alignment.Center)
{
writer.WriteAttribute("align", "center");
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
writer.Write(">");
writer.WriteBeginTag("img");
((DesignerTextWriter)writer).WriteStyleAttribute(Style);
writer.WriteAttribute("src", Control.ImageUrl, true);
// center alignment not part of HTML for images.
if (alignment == Alignment.Right ||
alignment == Alignment.Left)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.WriteAttribute("border", "0");
writer.Write(">");
writer.WriteEndTag("div");
}
}
}
}

View File

@@ -0,0 +1,80 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerImageAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.ComponentModel.Design;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerImageAdapter : HtmlImageAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
String width = DesignerAdapterUtil.GetWidth(Control);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteBeginTag("div");
if (alignment == Alignment.Center)
{
writer.WriteAttribute("align", "center");
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
writer.Write(">");
String source = Control.ImageUrl;
writer.WriteBeginTag("img");
((DesignerTextWriter)writer).WriteStyleAttribute(Style);
if (!String.IsNullOrEmpty(source))
{
writer.WriteAttribute("src", source, true);
}
if (!String.IsNullOrEmpty(Control.AlternateText))
{
writer.Write(" alt=\"");
writer.WriteText(Control.AlternateText, true);
writer.Write("\"");
}
// center alignment not part of HTML for images.
if (alignment == Alignment.Right ||
alignment == Alignment.Left)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.WriteAttribute("border", "0");
writer.Write(">");
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,69 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerLableAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerLabelAdapter : System.Web.UI.MobileControls.Adapters.HtmlLabelAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
// Style.SetControl(Control);
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
String width = DesignerAdapterUtil.GetWidth(Control);
if (!wrap)
{
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
}
else
{
writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
writer.WriteEndTag("div");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
}
}

View File

@@ -0,0 +1,72 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerLinkAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerLinkAdapter : HtmlLinkAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
String width = DesignerAdapterUtil.GetWidth(Control);
if (!wrap)
{
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
}
else
{
writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
writer.WriteBeginTag("a");
writer.WriteAttribute("href", "NavigationUrl");
writer.Write(">");
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
writer.WriteEndTag("a");
writer.WriteEndTag("div");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
}
}

View File

@@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerListAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Drawing;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerListAdapter : HtmlListAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
writer.WriteBeginTag("div");
((DesignerTextWriter)writer).WriteDesignerStyleAttributes(Control, Style);
writer.Write("\">");
base.Render(writer);
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerObjectListAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Drawing;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerObjectListAdapter : HtmlObjectListAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
writer.WriteBeginTag("div");
((DesignerTextWriter)writer).WriteDesignerStyleAttributes(Control, Style);
writer.Write("\">");
base.Render(writer);
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerSelectionListAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Diagnostics;
using System.Drawing;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerSelectionListAdapter : HtmlSelectionListAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
writer.WriteBeginTag("div");
((DesignerTextWriter)writer).WriteDesignerStyleAttributes(Control, Style);
writer.Write("\">");
base.Render(writer);
writer.WriteEndTag("div");
}
}
}

View File

@@ -0,0 +1,178 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerTextBoxAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.IO;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerTextBoxAdapter : HtmlTextBoxAdapter
{
// required width may differ a little bit from actual exact pixel value
private const int SAFETY_MARGIN = 12;
// size after which we simply assume the control is too large to fit
// into its container.
private const int LARGESIZE_THRESHOLD = 100;
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
// Invalid text writers are not supported in this Adapter.
if (!(writer is DesignerTextWriter))
{
return;
}
byte templateStatus;
bool pwd = Control.Password;
int size = Control.Size;
int fittingSize;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (maxWidth == 0)
{
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_NONEDIT)
{
maxWidth = DesignerAdapterUtil.CONTROL_MAX_WIDTH_IN_TEMPLATE;
}
else if (DesignerAdapterUtil.InMobileUserControl(Control))
{
maxWidth = Constants.ControlMaxsizeAtToplevel;
}
}
if (maxWidth == 0)
{
return;
}
bool restoreEmptyFontName = false;
if (String.IsNullOrEmpty((String) Style[Style.FontNameKey, true]))
{
// MSHTMLHostUtil is using another font by default.
// Setting the font name to the one that is actually
// used by default for the desig-time rendering
// assures that the requiredWidth returned by
// MSHTMLHostUtil.GetHtmlFragmentWidth is accurate.
Style[Style.FontNameKey] = "Arial";
restoreEmptyFontName = true;
}
int requiredWidth = 0;
DesignerTextWriter tw;
tw = new DesignerTextWriter(false);
tw.EnterLayout(Style);
String enterLayout = tw.ToString();
tw = new DesignerTextWriter(false);
tw.ExitLayout(Style);
String exitLayout = tw.ToString();
tw = new DesignerTextWriter(false);
tw.WriteBeginTag("input");
tw.WriteStyleAttribute(Style, null);
if (size > 0)
{
tw.WriteAttribute("size", "{0}");
}
tw.Write("/>");
String htmlFragment = tw.ToString();
MSHTMLHostUtil.ApplyStyle(enterLayout, exitLayout, null);
if (size < LARGESIZE_THRESHOLD)
{
requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(size > 0 ? String.Format(CultureInfo.InvariantCulture, htmlFragment, size) : htmlFragment);
}
if (requiredWidth + SAFETY_MARGIN > maxWidth || size >= LARGESIZE_THRESHOLD)
{
if (size == 0)
{
tw = new DesignerTextWriter(false);
tw.WriteBeginTag("input");
tw.WriteStyleAttribute(Style, null);
tw.WriteAttribute("size", "{0}");
tw.Write("/>");
htmlFragment = tw.ToString();
}
fittingSize = 0;
do
{
fittingSize++;
requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(String.Format(CultureInfo.InvariantCulture, htmlFragment, fittingSize));
}
while (requiredWidth + SAFETY_MARGIN <= maxWidth);
if (fittingSize > 1)
{
fittingSize--;
}
}
else
{
fittingSize = size;
}
if (restoreEmptyFontName)
{
Style[Style.FontNameKey] = String.Empty;
}
Alignment alignment = (Alignment) Style[Style.AlignmentKey, true];
String width = DesignerAdapterUtil.GetWidth(Control);
writer.Write("<div style='width:" + width);
if (alignment != Alignment.NotSet)
{
writer.Write(";text-align:" + Enum.GetName(typeof(Alignment), alignment));
}
writer.Write("'>");
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.EnterLayout(Style);
writer.WriteBeginTag("input");
((DesignerTextWriter)writer).WriteStyleAttribute(Style, null);
if (!String.IsNullOrEmpty(Control.Text))
{
writer.Write(" value=\"");
writer.WriteText(Control.Text, true);
writer.Write("\" ");
}
if (fittingSize > 0)
{
writer.WriteAttribute("size", fittingSize.ToString(CultureInfo.InvariantCulture));
}
if (pwd)
{
writer.WriteAttribute("type", "password");
}
writer.Write("/>");
writer.ExitLayout(Style);
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
writer.Write("</div>");
}
}
}

View File

@@ -0,0 +1,321 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerTextViewAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.Text;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerTextViewAdapter : System.Web.UI.MobileControls.Adapters.HtmlControlAdapter
{
protected new TextView Control
{
get
{
return (TextView)base.Control;
}
}
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Alignment alignment = (Alignment) Style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
String width = DesignerAdapterUtil.GetWidth(Control);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
if (!wrap)
{
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
}
else
{
writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
MSHTMLHostUtil.ApplyStyle(null, null, null);
String filteredText = FilterTags(Control.Text.Trim());
int uniqueLineHeight = MSHTMLHostUtil.GetHtmlFragmentHeight("a");
int requiredHeight = MSHTMLHostUtil.GetHtmlFragmentHeight(filteredText);
int requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(filteredText);
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, (requiredHeight > uniqueLineHeight || requiredWidth > 1) ? filteredText : "&nbsp;", false);
writer.WriteEndTag("div");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
private enum CursorStatus
{
OutsideTag,
InsideTagName,
InsideAttributeName,
InsideAttributeValue,
ExpectingAttributeValue
}
private String FilterTags(String text)
{
StringBuilder filteredText = new StringBuilder();
// StringBuilder hrefValue = null;
int len = text.Length, i;
int tagBegin = 0; //, attribBegin = 0;
bool doubleQuotedAttributeValue = false;
// bool cacheHRefValue = false;
CursorStatus cs = CursorStatus.OutsideTag;
String tagName = String.Empty;
for (i = 0; i < len; i++)
{
switch (text[i])
{
case '<':
{
switch (cs)
{
case CursorStatus.OutsideTag:
{
cs = CursorStatus.InsideTagName;
tagBegin = i;
break;
}
}
break;
}
case '=':
{
switch (cs)
{
case CursorStatus.InsideAttributeName:
{
// cacheHRefValue = text.Substring(attribBegin, i-attribBegin).Trim().ToUpper() == "HREF";
// hrefValue = null;
cs = CursorStatus.ExpectingAttributeValue;
break;
}
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
break;
}
case '"':
{
switch (cs)
{
case CursorStatus.ExpectingAttributeValue:
{
cs = CursorStatus.InsideAttributeValue;
doubleQuotedAttributeValue = true;
//if (cacheHRefValue)
//{
// hrefValue = new StringBuilder("\"");
//}
break;
}
case CursorStatus.InsideAttributeValue:
{
//if (cacheHRefValue)
//{
// hrefValue.Append('"');
//}
if (text[i-1] != '\\' && doubleQuotedAttributeValue)
{
// leaving attribute value
cs = CursorStatus.InsideAttributeName;
// attribBegin = i;
break;
}
break;
}
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
break;
}
case '\'':
{
switch (cs)
{
case CursorStatus.ExpectingAttributeValue:
{
cs = CursorStatus.InsideAttributeValue;
//if (cacheHRefValue)
//{
// hrefValue = new StringBuilder("'");
//}
doubleQuotedAttributeValue = false;
break;
}
case CursorStatus.InsideAttributeValue:
{
//if (cacheHRefValue)
//{
// hrefValue.Append('\'');
//}
if (text[i-1] != '\\' && !doubleQuotedAttributeValue)
{
// leaving attribute value
cs = CursorStatus.InsideAttributeName;
// attribBegin = i;
break;
}
break;
}
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
break;
}
case '/':
{
switch (cs)
{
case CursorStatus.InsideTagName:
{
tagName = text.Substring(tagBegin+1, i-tagBegin-1).Trim().ToUpper(CultureInfo.InvariantCulture);
if (tagName.Trim().Length > 0)
{
cs = CursorStatus.InsideAttributeName;
// attribBegin = i;
}
break;
}
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
break;
}
case '>':
{
switch (cs)
{
case CursorStatus.InsideTagName:
case CursorStatus.InsideAttributeName:
case CursorStatus.ExpectingAttributeValue:
{
// leaving tag
if (cs == CursorStatus.InsideTagName)
{
tagName = text.Substring(tagBegin+1, i-tagBegin-1).Trim().ToUpper(CultureInfo.InvariantCulture);
}
cs = CursorStatus.OutsideTag;
switch (tagName)
{
case "A":
{
//filteredText.Append(String.Format("<A HREF={0}>",
// hrefValue == null ? String.Empty : hrefValue.ToString()));
filteredText.Append("<A HREF=\"\">");
break;
}
case "/A":
case "B":
case "/B":
case "BR":
case "/BR":
case "I":
case "/I":
case "P":
case "/P":
{
filteredText.Append("<" + tagName + ">");
break;
}
}
tagName = String.Empty;
break;
}
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
break;
}
default:
{
if (Char.IsWhiteSpace(text[i]))
{
switch (cs)
{
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
case CursorStatus.InsideTagName:
{
cs = CursorStatus.InsideAttributeName;
// attribBegin = i;
tagName = text.Substring(tagBegin+1, i-tagBegin-1).Trim().ToUpper(CultureInfo.InvariantCulture);
break;
}
}
}
else
{
switch (cs)
{
case CursorStatus.OutsideTag:
{
filteredText.Append(text[i]);
break;
}
}
}
break;
}
}
}
return filteredText.ToString();
}
}
}

View File

@@ -0,0 +1,230 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerTextWriter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Web.UI.Design.MobileControls;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerTextWriter : HtmlMobileTextWriter
{
private readonly WriterStyle _defaultWriterStyle;
internal DesignerTextWriter() : this(false)
{
}
internal DesignerTextWriter(bool maintainState) :
base(new StringWriter(CultureInfo.CurrentCulture), DesignerCapabilities.Instance)
{
MaintainState = maintainState;
_defaultWriterStyle = new WriterStyle();
}
internal void EnterZeroFontSizeTag()
{
WriteBeginTag("font");
WriteAttribute("size", "+0");
Write("/>");
WriteBeginTag("div");
WriteAttribute("style", "font-weight:normal;font-style:normal");
Write(">");
}
internal void ExitZeroFontSizeTag()
{
WriteEndTag("div");
WriteEndTag("font");
}
public override String ToString()
{
return InnerWriter.ToString();
}
internal void WriteDesignerStyleAttributes(MobileControl control,
Style style)
{
Alignment alignment = (Alignment) style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) style[Style.WrappingKey, true];
Color backColor = (Color) style[Style.BackColorKey, true];
bool align = (alignment != Alignment.NotSet);
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
String width = DesignerAdapterUtil.GetWidth(control);
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
if (!wrap)
{
Write(" style=\"overflow-x:hidden;width:" + width);
}
else
{
Write(" style=\"word-wrap:break-word;overflow-x:hidden;width:" + width);
}
if (backColor != Color.Empty)
{
Write(";background-color:" + ColorTranslator.ToHtml(backColor));
}
if (align)
{
Write(";text-align:" + Enum.GetName(typeof(Alignment), alignment));
}
}
internal void WriteStyleAttribute(Style style)
{
WriteStyleAttribute(style, null);
}
internal void WriteStyleAttribute(Style style, String additionalStyle)
{
// Style attributes not written for device without CSS support
if (!Device.SupportsCss)
{
return;
}
bool bold = (BooleanOption)style[Style.BoldKey, true] == BooleanOption.True;
bool italic = (BooleanOption)style[Style.ItalicKey, true] == BooleanOption.True;
FontSize fontSize = (FontSize) style[Style.FontSizeKey , true];
String fontName = (String) style[Style.FontNameKey , true];
Color foreColor = (Color) style[Style.ForeColorKey, true];
Color backColor = (Color) style[Style.BackColorKey, true];
Write(" style=\"");
if (null != additionalStyle)
{
Write(additionalStyle);
}
if (bold)
{
Write("font-weight:bold;");
}
if (italic)
{
Write("font-style:italic;");
}
if (fontSize == FontSize.Large)
{
Write("font-size:larger;");
}
else if (fontSize == FontSize.Small)
{
Write("font-size:smaller;");
}
if (!String.IsNullOrEmpty(fontName))
{
Write("font-family:");
Write(fontName);
Write(';');
}
if (foreColor != Color.Empty)
{
Write("color:");
Write(ColorTranslator.ToHtml(foreColor));
Write(';');
}
if (backColor != Color.Empty)
{
Write("background-color:");
Write(ColorTranslator.ToHtml(backColor));
Write(';');
Write("border-color:");
Write(ColorTranslator.ToHtml(backColor));
Write(';');
}
Write("\"");
}
internal void WriteCssStyleText(Style style,
String additionalStyle,
String text,
bool encodeText)
{
EnterLayout(style);
WriteBeginTag("div");
WriteStyleAttribute(style, additionalStyle);
Write(">");
WriteText(text, encodeText);
WriteEndTag("div");
ExitLayout(style);
}
public override void EnterLayout(Style style)
{
if(MaintainState)
{
base.EnterLayout(style);
return;
}
//we are not maintaining state, so begin a new context
BeginStyleContext();
//create a WriterStyle and turn off formatting output
WriterStyle newStyle = new WriterStyle(style);
newStyle.Format = false;
//transition to the new style, capturing output
_currentState.Transition(newStyle);
//Clear stack so we do not interfere with Write*()
_currentState.Transition(_defaultWriterStyle, false);
//restore the context
EndStyleContext();
}
public override void ExitLayout(Style style, bool breakAfter)
{
if(MaintainState)
{
base.ExitLayout(style, breakAfter);
return;
}
//we are not maintaining state, so begin a new context
BeginStyleContext();
//create a WriterStyle and turn off formatting output
WriterStyle newStyle = new WriterStyle(style);
newStyle.Format = false;
//Setup stack like it would be after base.EnterLayout()
_currentState.Transition(newStyle, false);
//transition to default state and capture output
_currentState.Transition(_defaultWriterStyle);
//close the context, to flush all pending tags
EndStyleContext();
}
public override void ExitLayout(Style style)
{
ExitLayout(style, false);
}
}
}

View File

@@ -0,0 +1,87 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerValidationSummaryAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Diagnostics;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerValidationSummaryAdapter : HtmlValidationSummaryAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
String additionalStyle;
Alignment alignment = (Alignment) Style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
String width = DesignerAdapterUtil.GetWidth(Control);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.EnterLayout(Style);
writer.WriteBeginTag("div");
if (!wrap)
{
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
additionalStyle = "overflow-x:hidden;width:" + width + ";";
}
else
{
additionalStyle = "word-wrap:break-word;width:" + width + ";";
}
((DesignerTextWriter)writer).WriteStyleAttribute(Style, additionalStyle);
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
writer.WriteText(Control.HeaderText, true);
writer.WriteFullBeginTag("ul");
for (int i = 1; i <= 2; i++)
{
writer.WriteFullBeginTag("li");
writer.Write(SR.GetString(SR.ValidationSummary_ErrorMessage, i.ToString(CultureInfo.InvariantCulture)));
writer.WriteEndTag("li");
}
writer.WriteEndTag("ul");
writer.WriteBeginTag("a");
writer.WriteAttribute("href", "NavigationUrl");
writer.Write(">");
writer.WriteText(String.IsNullOrEmpty(Control.BackLabel) ? GetDefaultLabel(BackLabel) : Control.BackLabel, true);
writer.WriteEndTag("a");
writer.WriteEndTag("div");
writer.ExitLayout(Style);
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
}
}

View File

@@ -0,0 +1,76 @@
//------------------------------------------------------------------------------
// <copyright file="DesignerValidatorAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Globalization;
using System.Web.Mobile;
using System.Web.UI.Design.MobileControls;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Diagnostics;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 DesignerValidatorAdapter : HtmlValidatorAdapter
{
public override MobileCapabilities Device
{
get
{
return DesignerCapabilities.Instance;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Alignment alignment = (Alignment) Style[Style.AlignmentKey, true];
Wrapping wrapping = (Wrapping) Style[Style.WrappingKey, true];
bool wrap = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
String width = DesignerAdapterUtil.GetWidth(Control);
((DesignerTextWriter)writer).EnterZeroFontSizeTag();
writer.WriteBeginTag("div");
if (!wrap)
{
byte templateStatus;
int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
{
width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
}
writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
}
else
{
writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
}
if (alignment != Alignment.NotSet)
{
writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
}
writer.Write(">");
if (Control.Text.Trim().Length > 0)
{
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
}
else
{
((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.ErrorMessage, true);
}
writer.WriteEndTag("div");
((DesignerTextWriter)writer).ExitZeroFontSizeTag();
}
}
}

View File

@@ -0,0 +1,98 @@
//------------------------------------------------------------------------------
// <copyright file="MSHTMLHostUtil.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Drawing;
using System.Web.UI.Design.MobileControls.Util;
namespace System.Web.UI.Design.MobileControls.Adapters
{
[
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 static class MSHTMLHostUtil
{
private const int CONTROL_WIDTH = 64;
private const int CONTROL_HEIGHT = 4096;
private static MSHTMLHost _tridentControl;
private static NativeMethods.IHTMLElement _htmlBody;
private static NativeMethods.IHTMLElement _htmlDivOuter;
private static NativeMethods.IHTMLElement _htmlDivInner;
private static void CreateControl()
{
if (null != _tridentControl && null != _htmlBody)
{
return;
}
_tridentControl = new MSHTMLHost();
_tridentControl.Size = new Size(CONTROL_WIDTH, CONTROL_HEIGHT);
_tridentControl.CreateTrident();
_tridentControl.ActivateTrident();
NativeMethods.IHTMLDocument2 htmlDoc2 = _tridentControl.GetDocument();
_htmlBody = htmlDoc2.GetBody();
}
internal static void ApplyStyle(String enterStyle, String exitStyle, String cssStyle)
{
MSHTMLHostUtil.CreateControl();
String bodyInnerHTML = "<div id=__divOuter nowrap style='width:1px; height:10px'>" +
enterStyle +
"<div id=__divInner" + cssStyle + "></div>" +
exitStyle +
"</div>";
// MessageBox.Show("Body HTML for empty content: " + bodyInnerHTML);
_htmlBody.SetInnerHTML(bodyInnerHTML);
NativeMethods.IHTMLDocument3 htmlDoc3 = (NativeMethods.IHTMLDocument3) _tridentControl.GetDocument();
Debug.Assert(null != htmlDoc3);
_htmlDivInner = htmlDoc3.GetElementById("__divInner");
_htmlDivOuter = htmlDoc3.GetElementById("__divOuter");
Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner);
}
#if UNUSED_CODE
internal static int GetTextWidth(String text)
{
Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner);
_htmlDivInner.SetInnerText(text);
NativeMethods.IHTMLElement2 htmlElement2 = (NativeMethods.IHTMLElement2) _htmlDivOuter;
Debug.Assert(null != htmlElement2);
return htmlElement2.GetClientWidth();
}
#endif
internal static int GetHtmlFragmentWidth(String htmlFragment)
{
Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner);
_htmlDivInner.SetInnerHTML(htmlFragment);
NativeMethods.IHTMLElement2 htmlElement2 = (NativeMethods.IHTMLElement2) _htmlDivOuter;
Debug.Assert(null != htmlElement2);
return htmlElement2.GetClientWidth();
}
internal static int GetHtmlFragmentHeight(String htmlFragment)
{
Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner);
_htmlDivInner.SetInnerHTML(htmlFragment);
NativeMethods.IHTMLElement2 htmlElement2 = (NativeMethods.IHTMLElement2) _htmlDivOuter;
Debug.Assert(null != htmlElement2);
return htmlElement2.GetClientHeight();
}
}
}