Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / Design / Adapters / DesignerCommandAdapter.cs / 1305376 / DesignerCommandAdapter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- 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"); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- 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"); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StringResourceManager.cs
- XPathNavigatorReader.cs
- VirtualDirectoryMappingCollection.cs
- GenericWebPart.cs
- WebPartHeaderCloseVerb.cs
- SqlMethodAttribute.cs
- WebEvents.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- Expression.cs
- ImageList.cs
- GcHandle.cs
- XmlHelper.cs
- DataGridState.cs
- SqlNotificationRequest.cs
- ToggleProviderWrapper.cs
- CancelEventArgs.cs
- HotSpotCollection.cs
- WhiteSpaceTrimStringConverter.cs
- DataGridViewBand.cs
- GreenMethods.cs
- WebConvert.cs
- ConfigurationSchemaErrors.cs
- MILUtilities.cs
- GraphicsPath.cs
- Application.cs
- Binding.cs
- ColorPalette.cs
- LinkedResource.cs
- IdentityHolder.cs
- SelectionRange.cs
- WrappedIUnknown.cs
- InputLanguage.cs
- LiteralDesigner.cs
- EventLogTraceListener.cs
- XmlSchemaValidationException.cs
- EventRecord.cs
- VisualTreeHelper.cs
- ByteStream.cs
- RemoteWebConfigurationHost.cs
- TextEditorCharacters.cs
- XmlQueryTypeFactory.cs
- _UriTypeConverter.cs
- Propagator.cs
- MultiBinding.cs
- HyperlinkAutomationPeer.cs
- PropertyToken.cs
- StateDesignerConnector.cs
- RouteValueExpressionBuilder.cs
- PageContentCollection.cs
- CodeMethodReturnStatement.cs
- ProfileEventArgs.cs
- uribuilder.cs
- Drawing.cs
- CodeTypeDeclaration.cs
- XmlAttributeCache.cs
- SocketElement.cs
- ToolStripItem.cs
- Win32PrintDialog.cs
- SubMenuStyle.cs
- CompilationPass2TaskInternal.cs
- CustomAttributeFormatException.cs
- XmlMessageFormatter.cs
- WebPartCatalogCloseVerb.cs
- SimpleHandlerFactory.cs
- DataGridRow.cs
- IdentityNotMappedException.cs
- Descriptor.cs
- SqlEnums.cs
- XmlSerializerVersionAttribute.cs
- OdbcConnection.cs
- LogArchiveSnapshot.cs
- TranslateTransform.cs
- Semaphore.cs
- HttpModuleActionCollection.cs
- FontDriver.cs
- Nodes.cs
- WsdlBuildProvider.cs
- Util.cs
- AutomationIdentifierGuids.cs
- ConfigXmlDocument.cs
- IssuanceLicense.cs
- sortedlist.cs
- SelectionItemProviderWrapper.cs
- RecordConverter.cs
- CacheEntry.cs
- AccessDataSourceWizardForm.cs
- SrgsDocumentParser.cs
- ContentElement.cs
- OperandQuery.cs
- ContentPresenter.cs
- ExceptionUtil.cs
- ObjectStateEntryDbDataRecord.cs
- ServiceContractDetailViewControl.cs
- mactripleDES.cs
- SingleSelectRootGridEntry.cs
- FrameworkReadOnlyPropertyMetadata.cs
- XPathDocument.cs
- StrokeNodeEnumerator.cs
- ExeContext.cs
- DataGridState.cs