/******** * @version : 1.6.0 - Ext.NET Pro License * @author : Ext.NET, Inc. http://www.ext.net/ * @date : 2012-11-21 * @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved. * @license : See license.txt and http://www.ext.net/license/. ********/ using System; using System.ComponentModel; using System.Web.UI; using System.Drawing; using Ext.Net.Utilities; namespace Ext.Net { /// /// Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind navigation keys to function calls that will get called when the keys are pressed, providing an easy way to implement custom navigation schemes for any UI component. /// [Meta] [ToolboxData("<{0}:KeyNav runat=\"server\">")] [ToolboxBitmap(typeof(KeyNav), "Build.ToolboxIcons.KeyMap.bmp")] [Designer(typeof(EmptyDesigner))] [Description("Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind navigation keys to function calls that will get called when the keys are pressed, providing an easy way to implement custom navigation schemes for any UI component.")] public partial class KeyNav : Observable { /// /// /// [Description("")] public KeyNav() { } /// /// /// [Category("0. About")] [Description("")] public override string InstanceOf { get { return "Ext.KeyNav"; } } internal override string GetClientConstructor(bool instanceOnly, string body) { if (this.Target.IsEmpty()) { throw new ArgumentNullException("Target", "The Target must defined for KeyNav control"); } if (this.IsDefault) { return ""; } this.InitOwer(); string template = (instanceOnly) ? "new {1}(Ext.net.getEl({2}),{3})" : "this.{0}=new {1}(Ext.net.getEl({2}),{3});"; return string.Format(template, this.ClientID, "Ext.KeyNav", this.TargetProxy, this.InitialConfig); } /// /// /// [Description("")] public override bool IsDefault { get { return this.Left.IsDefault && this.Right.IsDefault && this.Up.IsDefault && this.Down.IsDefault && this.PageDown.IsDefault && this.PageUp.IsDefault && this.Home.IsDefault && this.End.IsDefault && this.Tab.IsDefault && this.Del.IsDefault && this.Esc.IsDefault && this.Enter.IsDefault; } } private void InitOwer() { this.Left.Owner = this; this.Right.Owner = this; this.Up.Owner = this; this.Down.Owner = this; this.PageDown.Owner = this; this.PageUp.Owner = this; this.Home.Owner = this; this.End.Owner = this; this.Tab.Owner = this; this.Del.Owner = this; this.Esc.Owner = this; this.Enter.Owner = this; } private string TargetProxy { get { string parsedTarget = TokenUtils.ParseTokens(this.Target, this); if (TokenUtils.IsRawToken(parsedTarget)) { return TokenUtils.ReplaceRawToken(parsedTarget); } return "\"".ConcatWith(parsedTarget, "\""); } } /// /// The element to bind to /// [Meta] [Category("3. KeyNav")] [DefaultValue("")] [Description("The element to bind to")] public virtual string Target { get { return (string)this.ViewState["Target"] ?? ""; } set { this.ViewState["Target"] = value; } } private JFunction left; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Left { get { if (this.left == null) { this.left = new JFunction(null, "e"); } return this.left; } } private JFunction right; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Right { get { if (this.right == null) { this.right = new JFunction(null, "e"); } return this.right; } } private JFunction up; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Up { get { if (this.up == null) { this.up = new JFunction(null, "e"); } return this.up; } } private JFunction down; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Down { get { if (this.down == null) { this.down = new JFunction(null, "e"); } return this.down; } } private JFunction pageUp; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction PageUp { get { if (this.pageUp == null) { this.pageUp = new JFunction(null, "e"); } return this.pageUp; } } private JFunction pageDown; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction PageDown { get { if (this.pageDown == null) { this.pageDown = new JFunction(null, "e"); } return this.pageDown; } } private JFunction del; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Del { get { if (this.del == null) { this.del = new JFunction(null, "e"); } return this.del; } } private JFunction home; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Home { get { if (this.home == null) { this.home = new JFunction(null, "e"); } return this.home; } } private JFunction end; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction End { get { if (this.end == null) { this.end = new JFunction(null, "e"); } return this.end; } } private JFunction enter; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Enter { get { if (this.enter == null) { this.enter = new JFunction(null, "e"); } return this.enter; } } private JFunction esc; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Esc { get { if (this.esc == null) { this.esc = new JFunction(null, "e"); } return this.esc; } } private JFunction tab; /// /// /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [PersistenceMode(PersistenceMode.InnerProperty)] [TypeConverter(typeof(ExpandableObjectConverter))] [Description("")] public JFunction Tab { get { if (this.tab == null) { this.tab = new JFunction(null, "e"); } return this.tab; } } /// /// The method to call on the Ext.EventObject after this KeyNav intercepts a key. Valid values are Ext.EventObject.stopEvent, Ext.EventObject.preventDefault and Ext.EventObject.stopPropagation (defaults to 'stopEvent') /// [Meta] [ConfigOption] [Category("3. KeyNav")] [DefaultValue(KeyEventAction.StopEvent)] [NotifyParentProperty(true)] [Description("The method to call on the Ext.EventObject after this KeyNav intercepts a key. Valid values are Ext.EventObject.stopEvent, Ext.EventObject.preventDefault and Ext.EventObject.stopPropagation (defaults to 'stopEvent')")] public virtual KeyEventAction DefaultEventAction { get { object obj = this.ViewState["DefaultEventAction"]; return (obj == null) ? KeyEventAction.StopEvent : (KeyEventAction)obj; } set { this.ViewState["DefaultEventAction"] = value; } } /// /// True to disable this KeyNav instance (defaults to false) /// [Meta] [ConfigOption] [Category("3. KeyNav")] [DefaultValue(false)] [NotifyParentProperty(true)] [DirectEventUpdate(MethodName="SetDisabled")] [Description("True to disable this KeyNav instance (defaults to false)")] public virtual bool Disabled { get { object obj = this.ViewState["Disabled"]; return (obj == null) ? false : (bool)obj; } set { this.ViewState["Disabled"] = value; } } /// /// Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since IE does not propagate special keys on keypress, but setting this to true will force other browsers to also handle keydown instead of keypress. /// [Meta] [ConfigOption] [Category("3. KeyNav")] [DefaultValue(false)] [NotifyParentProperty(true)] [Description("Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since IE does not propagate special keys on keypress, but setting this to true will force other browsers to also handle keydown instead of keypress.")] public virtual bool ForceKeyDown { get { object obj = this.ViewState["ForceKeyDown"]; return (obj == null) ? false : (bool)obj; } set { this.ViewState["ForceKeyDown"] = value; } } /// /// The scope of the callback function /// [Meta] [ConfigOption(JsonMode.Raw)] [Category("3. KeyNav")] [DefaultValue("")] [NotifyParentProperty(true)] [Description("The scope of the callback function")] public virtual string Scope { get { object obj = this.ViewState["Scope"]; return (obj == null) ? "" : (string)obj; } set { this.ViewState["Scope"] = value; } } /// /// /// /// [Description("")] private void SetDisabled(bool disabled) { this.AddScript("{0}.{1}();", this.ClientID, disabled ? "disable" : "enable"); } } }