Files
mono/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/HtmlCommandAdapter.cs
T
Gaurav Vaish e2e5b97f94 2003-09-04 Gaurav Vaish <gvaish_mono AT lycos.com>
* ControlAdapter.cs     : Control property         - Marked virtual
                        : LoadPostData(...)        - Marked virtual
* HtmlCommandAdapter.cs : Implemented.
* HtmlControlAdapter.cs : RenderEndLink(...)       - Correct signature
* HtmlMobileTextWriter.cs
                        : Added several properties,
                        : Stubbed several methods

svn path=/trunk/mcs/; revision=17861
2003-09-04 09:37:54 +00:00

116 lines
2.7 KiB
C#

/**
* Project : Mono
* Namespace : System.Web.UI.MobileControls.Adapters
* Class : HtmlCommandAdapter
* Author : Gaurav Vaish
*
* Copyright : 2003 with Gaurav Vaish, and with
* Ximian Inc
*/
using System;
using System.Collections.Specialized;
using System.Web.Mobile;
using System.Web.UI.MobileControls;
namespace System.Web.UI.MobileControls.Adapters
{
public class HtmlCommandAdapter : HtmlControlAdapter
{
public HtmlCommandAdapter() : base()
{
}
protected new Command Control
{
get
{
return base.Control as Command;
}
}
public override bool LoadPostData(string postKey,
NameValueCollection data,
object privateControlData, out bool dataChanged)
{
dataChanged = false;
bool retVal = false;
if(Control != null)
{
string id = Control.UniqueID;
string ctrl = data[id + ".x"];
string evnt = data[id + ".y"];
if(ctrl != null && evnt != null && ctrl.Length > 0 && evnt.Length > 0)
{
dataChanged = true;
retVal = true;
}
}
return retVal;
}
public override void Render(HtmlMobileTextWriter writer)
{
bool supportsImgSbt = false;
bool supportsJavascript = false;
Form mobileForm = null;
if(Control != null)
{
if(Control.ImageUrl != String.Empty && Device.SupportsImageSubmit)
{
supportsImgSbt = true;
if(Control.Format == CommandFormat.Link)
{
if(Device.JavaScript)
{
supportsJavascript = true;
}
}
}
}
if(supportsJavascript)
{
writer.EnterStyle(Style);
mobileForm = Control.Form;
if(mobileForm.Action.Length > 0)
{
writer.Write("<a href=\"javascript:document.");
writer.Write(mobileForm.ClientID);
writer.Write(".submit()\"");
base.AddAttributes(writer);
writer.Write(">");
writer.WriteText(Control.Text, false);
writer.WriteEndTag("a");
} else
{
base.RenderBeginLink(writer, Constants.FormIDPrefix + mobileForm.UniqueID);
writer.WriteText(Control.Text, true);
base.RenderEndLink(writer);
}
writer.ExitStyle(Style, Control.BreakAfter);
} else
{
writer.EnterLayout(Style);
writer.WriteBeginTag("input");
writer.WriteAttribute("name", Control.UniqueID);
if(supportsImgSbt)
{
writer.WriteAttribute("type", "image");
writer.WriteAttribute("src", Control.ResolveUrl(Control.ImageUrl));
writer.WriteAttribute("alt", Control.Text);
} else
{
writer.WriteAttribute("type", "submit");
writer.Write("value=\"");
writer.WriteText(Control.Text, true);
}
writer.Write("\"");
base.AddAttributes(writer);
writer.Write("/>");
writer.ExitLayout(Style, Control.BreakAfter);
}
}
}
}