1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 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");
}
}
}
}
|