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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
//------------------------------------------------------------------------------
// <copyright file="WmlControlAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Diagnostics;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Web.Security;
using System.Text;
using System.Security.Permissions;
#if COMPILING_FOR_SHIPPED_SOURCE
namespace System.Web.UI.MobileControls.ShippedAdapterSource
#else
namespace System.Web.UI.MobileControls.Adapters
#endif
{
/*
* WmlControlAdapter base class contains wml specific methods.
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter"]/*' />
[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 WmlControlAdapter : System.Web.UI.MobileControls.Adapters.ControlAdapter
{
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.PageAdapter"]/*' />
protected WmlPageAdapter PageAdapter
{
get
{
return ((WmlPageAdapter)Page.Adapter);
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.FormAdapter"]/*' />
protected WmlFormAdapter FormAdapter
{
get
{
return (WmlFormAdapter)Control.Form.Adapter;
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.Render"]/*' />
public override void Render(HtmlTextWriter writer)
{
Render((WmlMobileTextWriter)writer);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.Render1"]/*' />
public virtual void Render(WmlMobileTextWriter writer)
{
RenderChildren(writer);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderLink"]/*' />
protected void RenderLink(WmlMobileTextWriter writer,
String targetUrl,
String softkeyLabel,
bool implicitSoftkeyLabel,
bool mapToSoftkey,
String text,
bool breakAfter)
{
RenderBeginLink(writer, targetUrl, softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
writer.RenderText(text);
RenderEndLink(writer, targetUrl, breakAfter);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderBeginLink"]/*' />
protected void RenderBeginLink(WmlMobileTextWriter writer,
String targetUrl,
String softkeyLabel,
bool implicitSoftkeyLabel,
bool mapToSoftkey)
{
if (mapToSoftkey && !writer.IsValidSoftkeyLabel(softkeyLabel))
{
// If softkey label was specified explicitly, then truncate.
if (!implicitSoftkeyLabel && softkeyLabel.Length > 0)
{
softkeyLabel = softkeyLabel.Substring(0, Device.MaximumSoftkeyLabelLength);
}
else
{
softkeyLabel = GetDefaultLabel(LinkLabel);
implicitSoftkeyLabel = true;
}
}
String postback = DeterminePostBack(targetUrl);
if (postback != null)
{
writer.RenderBeginPostBack(softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
}
else
{
String prefix = Constants.FormIDPrefix;
if (targetUrl.StartsWith(prefix, StringComparison.Ordinal))
{
String formID = targetUrl.Substring(prefix.Length);
Form form = Control.ResolveFormReference(formID);
targetUrl = prefix + form.ClientID;
}
else
{
bool absoluteUrl = ( (targetUrl.StartsWith("http:", StringComparison.Ordinal)) || (targetUrl.StartsWith("https:", StringComparison.Ordinal)) );
// AUI 3652
targetUrl = Control.ResolveUrl(targetUrl);
bool queryStringWritten = targetUrl.IndexOf('?') != -1;
IDictionary dictionary = PageAdapter.CookielessDataDictionary;
String formsAuthCookieName = FormsAuthentication.FormsCookieName;
if((dictionary != null) && (!absoluteUrl) && (Control.MobilePage.Adapter.PersistCookielessData))
{
StringBuilder sb = new StringBuilder(targetUrl);
foreach(String name in dictionary.Keys)
{
if(queryStringWritten)
{
sb.Append("&");
}
else
{
sb.Append("?");
queryStringWritten = true;
}
if(name.Equals(formsAuthCookieName) && Device.CanRenderOneventAndPrevElementsTogether )
{
sb.Append(name);
sb.Append("=$(");
sb.Append(writer.MapClientIDToShortName("__facn",false));
sb.Append(")");
}
else
{
sb.Append(name);
sb.Append("=");
sb.Append(dictionary[name]);
}
}
targetUrl = sb.ToString();
}
}
writer.RenderBeginHyperlink(targetUrl,
false,
softkeyLabel,
implicitSoftkeyLabel,
mapToSoftkey);
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderEndLink"]/*' />
protected void RenderEndLink(WmlMobileTextWriter writer, String targetUrl, bool breakAfter)
{
String postback = DeterminePostBack(targetUrl);
if (postback != null)
{
writer.RenderEndPostBack(Control.UniqueID, postback, WmlPostFieldType.Normal, false, breakAfter);
}
else
{
writer.RenderEndHyperlink(breakAfter);
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.DeterminePostBack"]/*' />
protected String DeterminePostBack(String target)
{
String postback = null;
String prefix = Constants.FormIDPrefix;
if (target.StartsWith(prefix, StringComparison.Ordinal)) // link to another form
{
String formID = target.Substring(prefix.Length);
Form form = Control.ResolveFormReference(formID);
Form thisForm = Control.Form;
// must postback to forms not rendered in deck (not visible) or links to same form,
// as long as it's safe to do so.
if (form == thisForm ||
!PageAdapter.IsFormRendered(form) ||
thisForm.HasDeactivateHandler() ||
form.HasActivateHandler())
{
postback = form.UniqueID;
}
}
return postback;
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderSubmitEvent"]/*' />
protected void RenderSubmitEvent(
WmlMobileTextWriter writer,
String softkeyLabel,
String text,
bool breakAfter)
{
RenderPostBackEvent(writer, null, softkeyLabel, true,
text, breakAfter, WmlPostFieldType.Submit);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderPostBackEvent"]/*' />
protected void RenderPostBackEvent(
WmlMobileTextWriter writer,
String argument,
String softkeyLabel,
bool mapToSoftkey,
String text,
bool breakAfter)
{
RenderPostBackEvent(writer, argument, softkeyLabel, mapToSoftkey,
text, breakAfter, WmlPostFieldType.Normal);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderPostBackEvent1"]/*' />
protected void RenderPostBackEvent(
WmlMobileTextWriter writer,
String argument,
String softkeyLabel,
bool mapToSoftkey,
String text,
bool breakAfter,
WmlPostFieldType postBackType)
{
bool implicitSoftkeyLabel = false;
if (mapToSoftkey)
{
if (softkeyLabel == null || softkeyLabel.Length == 0)
{
softkeyLabel = text;
implicitSoftkeyLabel = true;
}
if (!writer.IsValidSoftkeyLabel(softkeyLabel))
{
// If softkey label was specified explicitly, then truncate.
if (!implicitSoftkeyLabel && softkeyLabel.Length > 0)
{
softkeyLabel = softkeyLabel.Substring(0, Device.MaximumSoftkeyLabelLength);
}
else
{
softkeyLabel = GetDefaultLabel(GoLabel);
implicitSoftkeyLabel = true;
}
}
}
writer.RenderBeginPostBack(softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
writer.RenderText(text);
writer.RenderEndPostBack(Control.UniqueID, argument, postBackType, true, breakAfter);
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.GetPostBackValue"]/*' />
protected virtual String GetPostBackValue()
{
return null;
}
internal String GetControlPostBackValue(MobileControl ctl)
{
WmlControlAdapter adapter = ctl.Adapter as WmlControlAdapter;
return adapter != null ? adapter.GetPostBackValue() : null;
}
/////////////////////////////////////////////////////////////////////////
// SECONDARY UI SUPPORT
/////////////////////////////////////////////////////////////////////////
internal const int NotSecondaryUIInit = -1; // For initialization of private consts in derived classes.
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.NotSecondaryUI"]/*' />
protected static readonly int NotSecondaryUI = NotSecondaryUIInit;
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.SecondaryUIMode"]/*' />
protected int SecondaryUIMode
{
get
{
if (Control == null || Control.Form == null)
{
return NotSecondaryUI;
}
else
{
return ((WmlFormAdapter)Control.Form.Adapter).GetSecondaryUIMode(Control);
}
}
set
{
((WmlFormAdapter)Control.Form.Adapter).SetSecondaryUIMode(Control, value);
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.ExitSecondaryUIMode"]/*' />
protected void ExitSecondaryUIMode()
{
SecondaryUIMode = NotSecondaryUI;
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.LoadAdapterState"]/*' />
public override void LoadAdapterState(Object state)
{
if (state != null)
{
SecondaryUIMode = (int)state;
}
}
/// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.SaveAdapterState"]/*' />
public override Object SaveAdapterState()
{
int mode = SecondaryUIMode;
if (mode != NotSecondaryUI)
{
return mode;
}
else
{
return null;
}
}
}
}
|