| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- /**
- * Project : Mono
- * Namespace : System.Web.UI.MobileControls.Adapters
- * Class : ControlAdapter
- * 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;
- using System.Web.UI.MobileControls;
- namespace System.Web.UI.MobileControls.Adapters
- {
- public abstract class ControlAdapter : IControlAdapter
- {
- private MobileControl control = null;
- protected static readonly int BackLabel = 0x00;
- protected static readonly int GoLabel = 0x01;
- protected static readonly int OKLabel = 0x02;
- protected static readonly int MoreLabel = 0x03;
- protected static readonly int OptionsLabel = 0x04;
- protected static readonly int NextLabel = 0x05;
- protected static readonly int PreviousLabel = 0x06;
- protected static readonly int LinkLabel = 0x07;
- protected static readonly int CallLabel = 0x08;
- private static string[] labelIDs = {
- "ControlAdapter_Back",
- "ControlAdapter_Go",
- "ControlAdapter_OK",
- "ControlAdapter_More",
- "ControlAdapter_Options",
- "ControlAdapter_Next",
- "ControlAdapter_Previous",
- "ControlAdapter_Link",
- "ControlAdapter_Call"
- };
- private string[] defaultLabels = null;
- public ControlAdapter()
- {
- }
- public MobileCapabilities Device
- {
- get
- {
- if(Page != null)
- {
- return (MobileCapabilities) Page.Request.Browser;
- }
- return null;
- }
- }
- public System.Web.UI.MobileControls.Style Style
- {
- get
- {
- return Control.Style;
- }
- }
- public virtual MobileControl Control
- {
- get
- {
- return this.control;
- }
- set
- {
- this.control = value;
- }
- }
- public int ItemWeight
- {
- get
- {
- return ControlPager.UseDefaultWeight;
- }
- }
- public MobilePage Page
- {
- get
- {
- if(Control != null)
- return Control.MobilePage;
- return null;
- }
- }
- public int VisibleWeight
- {
- get
- {
- return ControlPager.UseDefaultWeight;
- }
- }
- public void CreateTemplatedUI(bool doDataBind)
- {
- Control.CreateDefaultTemplatedUI(doDataBind);
- }
- public virtual bool HandlePostBackEvent(string eventArguments)
- {
- return false;
- }
- public virtual void LoadAdapterState(object state)
- {
- }
- public virtual bool LoadPostData(string postKey,
- NameValueCollection postCollection,
- object privateControlData, out bool dataChanged)
- {
- dataChanged = false;
- return false;
- }
- public virtual void OnInit(EventArgs e)
- {
- return;
- }
- public virtual void OnLoad(EventArgs e)
- {
- return;
- }
- public virtual void OnPreRender(EventArgs e)
- {
- return;
- }
- public virtual void OnUnload(EventArgs e)
- {
- return;
- }
- public virtual void Render(HtmlTextWriter writer)
- {
- RenderChildren(writer);
- }
- public virtual object SaveAdapterState()
- {
- return null;
- }
- protected void RenderChildren(HtmlTextWriter writer)
- {
- if(Control != null && Control.HasControls())
- {
- foreach(Control cCtrl in Control.Controls)
- {
- cCtrl.RenderControl(writer);
- }
- if(Control.Controls.GetEnumerator() is IDisposable)
- {
- ((IDisposable)Control.Controls.GetEnumerator()).Dispose();
- }
- }
- }
- protected int CalculateOptimumPageWeight(int defaultPageWeight)
- {
- int defWt = defaultPageWeight;
- if(Device != null)
- {
- string httpDefWt = Device[Constants.OptimumPageWeightParameter];
- if(httpDefWt != null)
- {
- try
- {
- defWt = Convert.ToInt32(httpDefWt);
- } catch { }
- }
- }
- return -1;
- }
- protected string GetDefaultLabel(int labelID)
- {
- if(labelID < 0 || labelID >= labelIDs.Length)
- {
- // FIXME
- throw new ArgumentException("ControlAdapter" +
- "_InvalidDefaultLabel");
- }
- string retVal = null;
- if(Page != null)
- {
- ControlAdapter ca = (ControlAdapter)Page.Adapter;
- if(defaultLabels == null)
- {
- defaultLabels = new string[labelIDs.Length];
- Array.Copy(labelIDs, defaultLabels, labelIDs.Length);
- }
- retVal = defaultLabels[labelID];
- }
- if(retVal == null)
- {
- retVal = labelIDs[labelID];
- }
- return retVal;
- }
- }
- }
|