1 //------------------------------------------------------------------------------ 2 // <copyright file="XhtmlBasicPhoneCallAdapter.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 using System; 8 using System.Globalization; 9 using System.Security.Permissions; 10 using System.Web.Mobile; 11 using System.Web.UI.MobileControls; 12 using System.Web.UI.MobileControls.Adapters; 13 14 #if COMPILING_FOR_SHIPPED_SOURCE 15 namespace System.Web.UI.MobileControls.ShippedAdapterSource.XhtmlAdapters 16 #else 17 namespace System.Web.UI.MobileControls.Adapters.XhtmlAdapters 18 #endif 19 { 20 21 /// <include file='doc\XhtmlBasicPhoneCallAdapter.uex' path='docs/doc[@for="XhtmlPhoneCallAdapter"]/*' /> 22 [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 23 [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 24 [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.")] 25 public class XhtmlPhoneCallAdapter : XhtmlControlAdapter { 26 /// <include file='doc\XhtmlBasicPhoneCallAdapter.uex' path='docs/doc[@for="XhtmlPhoneCallAdapter.Control"]/*' /> 27 protected new PhoneCall Control { 28 get { 29 return base.Control as PhoneCall; 30 } 31 } 32 33 /// <include file='doc\XhtmlBasicPhoneCallAdapter.uex' path='docs/doc[@for="XhtmlPhoneCallAdapter.Render"]/*' /> Render(XhtmlMobileTextWriter writer)34 public override void Render(XhtmlMobileTextWriter writer) 35 { 36 ConditionalClearPendingBreak(writer); 37 Style style = Style; 38 StyleFilter filter = writer.CurrentStyleClass.GetFilter(style); 39 if ((filter & XhtmlConstants.Layout) != 0) { 40 ConditionalEnterLayout(writer, style); 41 } 42 if (Device.CanInitiateVoiceCall) { 43 String text = Control.Text; 44 String phoneNumber = Control.PhoneNumber; 45 46 if (text == null || text.Length == 0) { 47 text = phoneNumber; 48 } 49 50 writer.WriteBeginTag("a"); 51 52 if ((String)Device["supportsWtai"] == "true") { 53 writer.Write(" href=\"wtai://wp/mc;"); 54 } 55 else { 56 writer.Write(" href=\"tel:"); 57 } 58 59 foreach (char ch in phoneNumber) { 60 if (ch >= '0' && ch <= '9' || ch == '#' || ch == '+') { 61 writer.Write(ch); 62 } 63 } 64 writer.Write("\""); 65 ConditionalRenderCustomAttribute(writer, XhtmlConstants.AccessKeyCustomAttribute); 66 String cssClass = GetCustomAttributeValue(XhtmlConstants.CssClassCustomAttribute); 67 if (CssLocation != StyleSheetLocation.PhysicalFile) { 68 String className = writer.GetCssFormatClassName(style); 69 if (className != null) { 70 writer.WriteAttribute ("class", className); 71 } 72 } 73 else if (cssClass != null && cssClass.Length > 0) { 74 writer.WriteAttribute ("class", cssClass, true /* encode */); 75 } 76 writer.Write(">"); 77 writer.WriteEncodedText(text); 78 writer.WriteEndTag("a"); 79 ConditionalSetPendingBreakAfterInline(writer); 80 } 81 else { 82 // Format the text string based on properties 83 String text = String.Format( 84 CultureInfo.CurrentCulture, 85 Control.AlternateFormat, 86 Control.Text, 87 Control.PhoneNumber); 88 String url = Control.AlternateUrl; 89 90 // If URI specified, create a link. Otherwise, only text is displayed. 91 if (url != null && url.Length > 0) { 92 String cssClass = GetCustomAttributeValue(XhtmlConstants.CssClassCustomAttribute); 93 String accessKey = GetCustomAttributeValue(XhtmlConstants.AccessKeyCustomAttribute); 94 RenderBeginLink(writer, url, accessKey, style, cssClass); 95 writer.WriteEncodedText(text); 96 RenderEndLink(writer); 97 ConditionalSetPendingBreakAfterInline(writer); 98 } 99 else { 100 writer.WritePendingBreak(); 101 ConditionalEnterFormat(writer, style); 102 ConditionalRenderOpeningSpanElement(writer); 103 writer.WriteEncodedText(text); 104 ConditionalRenderClosingSpanElement(writer); 105 ConditionalExitFormat(writer, style); 106 ConditionalSetPendingBreak(writer); 107 } 108 } 109 if ((filter & XhtmlConstants.Layout) != 0) { 110 ConditionalExitLayout(writer, style); 111 } 112 } 113 114 } 115 } 116