⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widget.cs

📁 一种.net实现ajax方法的类库
💻 CS
📖 第 1 页 / 共 3 页
字号:
/** Copyright (c) 2006, All-In-One Creations, Ltd.*  All rights reserved.* * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:* *     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.*     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.*     * Neither the name of All-In-One Creations, Ltd. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**//** * Project: emergetk: stateful web framework for the masses * File name: .cs * Description: *    * Author: Ben Joldersma *    */using System;using System.Web;using System.Reflection;using System.Data;using System.ComponentModel;using System.Collections.Generic;using System.Xml;using System.Text.RegularExpressions;using EmergeTk.Model;using EmergeTk.Widgets.Html;namespace EmergeTk{    public delegate string DynamicIdDelegate(Widget sender);    public delegate void DelayedMouseOverHandler(Widget source, int mouseX, int mouseY);    public delegate void DelayedMouseOutHandler(Widget source);    public delegate void ReceiveDropHandler(Widget source, string dropMessage);    public delegate void OnClickHandler( Widget source, string args );    	/// <summary>	/// Summary description for Widget.	/// </summary>    public class Widget : ICloneable, IDataBindable	{        public Widget() { if( this.GetType() == typeof( Widget ) ) throw new System.NotSupportedException("Cannot directly instantiate widgets.  Widget would be abstract, but for the lack of variance in C#."); }       	public string id;		private string className = null;		private bool visible = true;		public bool rendered = false;        protected string OverrideBaseElement;		protected Widget parent;		public Context root;		public int position = -1;        private Dictionary<string,object> stateBag;        public Dictionary<string,object> StateBag        {            get { if (stateBag == null) stateBag = new Dictionary<string, object>();  return stateBag; }        }        private string clientClass;        public virtual string ClientClass        {            set            {                clientClass = value;            }            get            {                if (clientClass == null)                {                    string typeName = this.GetType().FullName;                    typeName = typeName.Replace("EmergeTk.Widgets.Html", "");                    typeName = typeName.Replace("EmergeTk.Widgets", "");                    typeName = typeName.Replace("EmergeTk", "");                    typeName = typeName.Replace(RootContext.DefaultNamespace, "").Replace(".", "");                                                           clientClass = typeName;                    int tildeIndex = clientClass.IndexOf('`');                    if (tildeIndex > 0)                    {                        clientClass = clientClass.Substring(0, tildeIndex);                    }                }                return clientClass;            }        }        private string appearEffect;        public string AppearEffect        {            get { return appearEffect; }            set { appearEffect = value; ClientArguments["appearEffect"] = "'" + Util.FormatForClient( value ) + "'"; }        }        private Dictionary<string, Model.NotifyPropertyChanged> notifyPropertyChangedHandlers;        public Dictionary<string, Model.NotifyPropertyChanged> NotifyPropertyChangedHandlers        {            get            {                return notifyPropertyChangedHandlers;            }        }        private List<Binding> bindings;        public List<Binding> Bindings { get { return bindings; } }        public Binding Bind(string property, IDataBindable source, string field)        {            Binding b = new Binding(this, property, source, field);            b.UpdateDestination();            Bind(b);            return b;        }        public void BindProperty( string name, NotifyPropertyChanged del )        {            if (notifyPropertyChangedHandlers == null)                    notifyPropertyChangedHandlers = new Dictionary<string, Model.NotifyPropertyChanged>();            if (NotifyPropertyChangedHandlers.ContainsKey(name))                NotifyPropertyChangedHandlers[name] += del;            else                NotifyPropertyChangedHandlers[name] = del;        }        public void Bind(Binding b)        {            if (this is IDataBindable)            {                if( b.OnDestinationChanged != null )                    BindProperty(b.DestinationProperty,b.OnDestinationChanged);                if (b.Source is Widget)                {                    Widget source = b.Source as Widget;                    source.BindProperty(b.SourceProperty,b.OnSourceChanged);                }            }            if (bindings == null) bindings = new List<Binding>();            bindings.Add(b);        }        /// <summary>        /// Binds to default property, if it's available.        /// </summary>        /// <param name="source"></param>        /// <param name="field"></param>        public void Bind(IDataBindable source, string field)        {            if (this is IDataBindable)            {                IDataBindable db = this as IDataBindable;                Bind(db.DefaultProperty, source, field);            }        }        public void Bind(IDataBindable source)        {            if (this is IDataBindable)            {                IDataBindable db = this as IDataBindable;                Bind(db.DefaultProperty, source, source.DefaultProperty);            }        }        public void Unbind()        {            if (bindings != null)            {                while (bindings.Count > 0)                    Unbind(bindings[0]);                bindings.Clear();            }        }        public void Unbind(Binding binding)        {            NotifyPropertyChangedHandlers[binding.DestinationProperty] -= binding.OnDestinationChanged;            if (this.NotifyPropertyChangedHandlers[binding.DestinationProperty] == null)                NotifyPropertyChangedHandlers.Remove(binding.DestinationProperty);            binding.Source.Unbind(binding);            bindings.Remove(binding);        }        private Dictionary<string, string> styleArguments;        public Dictionary<string, string> StyleArguments        {            get { if (styleArguments == null) styleArguments = new Dictionary<string, string>(); return styleArguments; }        }        private Dictionary<string, string> clientArguments;        public Dictionary<string,string> ClientArguments        {            get { if( clientArguments == null ) clientArguments = new Dictionary<string, string>(); return clientArguments; }        }        private Dictionary<string, string> elementArguments;        public Dictionary<string, string> ElementArguments        {            get { if(elementArguments == null) elementArguments = new Dictionary<string, string>(); return elementArguments; }        }        public void AddQuotedElementArg(string key, string value)        {            ElementArguments[key] = Util.Quotize(value);        }        public void AddQuotedArg(string key, string value)        {            ClientArguments[key] = Util.Quotize(value);        }		private WidgetCollection widgets;		public WidgetCollection Widgets { get { return widgets; } }		protected System.Collections.Queue ClientEvents;		Dictionary<string,string> DataBoundAttributes;        private Model.AbstractRecord record;				/// <summary>		/// Property Record (Model.Record)		/// </summary>		public Model.AbstractRecord Record		{			get			{				return this.record;			}			set			{				this.record = value;			}		}        private bool isSafe = true;        virtual public bool IsSafe        {            get { return isSafe; }            set { isSafe = value; }        }				public virtual string BaseElement         {             get             {                if (OverrideBaseElement != null)                    return OverrideBaseElement;                else                    return UID.Replace(".", "_") + ".elem";             }            set             {                 OverrideBaseElement = value;             }        }        virtual public string ClassName        {            get            {                return className;            }            set            {                if (rendered)                {                    SendCommand("SetAttribute({0},'{1}','{2}');", this.UID, "class", value);                }                className = value;            }        }		private const string updateFormat = 			@"Replacewidget( {0}, new {1}( '{0}', {2}, '{5}'{4} {3} ) );";		public Context RootContext		{            get            {                if (root != null)                {                    Widget currentRoot = root;                    while (currentRoot.parent != null)                    {                        currentRoot = currentRoot.parent;                    }                    return currentRoot as Context;                }                else if (HttpContext.Current != null)                {                    return HttpContext.Current.Items["context"] as Context;                }                return null;            }			set { root = value; }		}                        public object ObjectId        {            get { return id; }        }		public string Id		{			get { return id; }			set { id = value; }		}		public Widget Parent		{			get { return parent; }			set { parent = value; }		}        public DynamicIdDelegate GetDynamicId;		public string UID		{			get			{                if (GetDynamicId != null)                    return GetDynamicId(this);				if( Parent != RootContext && Parent != null )				{					return Parent.UID + "_" + Id;				}				else                     return Id;			}		}        public string ClientId        {            get { return UID.Replace(".", "_"); }        }		public bool VisibleToRoot		{			get			{				Widget c = this;				while( c != null )				{					if( ! c.Visible )					{						return false;					}					c = c.Parent;				}				return true;			}		}		public T FindAncestor<T>() where T : Widget		{            Widget p = Parent;			while( p != null )			{				if( p is T )					return p as T;				p = p.Parent;			}			return null;		}        public T FindAncestor<T>(string ID) where T : Widget		{			Widget p = this;			while(p != null && p.Id != ID )			{                p = p.Parent;            }			return p as T;		}		virtual public bool Visible		{			get { return visible; }            set { if (visible == value) return; if (value)RootContext.ShowWidget(this); else RootContext.HideWidget(this); visible = value; }		}		public virtual void Init()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -