1 //
2 // System.Web.UI.WebControls.HotSpot.cs
3 //
4 // Authors:
5 //	Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005-2010 Novell, Inc (http://www.novell.com)
8 //
9 
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 
31 using System.ComponentModel;
32 using System.Security.Permissions;
33 
34 namespace System.Web.UI.WebControls
35 {
36 	[TypeConverterAttribute (typeof(ExpandableObjectConverter))]
37 	[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 	public abstract class HotSpot: IStateManager
40 	{
41 		StateBag viewState = new StateBag ();
42 
43 		[LocalizableAttribute (true)]
44 		[DefaultValueAttribute ("")]
45 		public virtual string AccessKey {
46 			get {
47 				object o = viewState ["AccessKey"];
48 				return o != null ? (string) o : String.Empty;
49 			}
50 			set {
51 				if (value == null || value.Length < 2)
52 					viewState ["AccessKey"] = value;
53 				else
54 					throw new ArgumentOutOfRangeException ("value", "AccessKey can only be null, empty or a single character");
55 			}
56 		}
57 
58 		[LocalizableAttribute (true)]
59 		[NotifyParentPropertyAttribute (true)]
60 		[WebCategoryAttribute ("Behavior")]
61 		[DefaultValueAttribute ("")]
62 		[BindableAttribute (true)]
63 		public virtual string AlternateText {
64 			get {
65 				object o = viewState ["AlternateText"];
66 				return o != null ? (string) o : String.Empty;
67 			}
68 			set { viewState ["AlternateText"] = value; }
69 		}
70 
71 		[WebCategoryAttribute ("Behavior")]
72 		[DefaultValueAttribute (HotSpotMode.NotSet)]
73 		[NotifyParentPropertyAttribute (true)]
74 		public virtual HotSpotMode HotSpotMode {
75 			get {
76 				object o = viewState ["HotSpotMode"];
77 				return o != null ? (HotSpotMode) o : HotSpotMode.NotSet;
78 			}
79 			set {
80 				if ((int) value < 0 || (int) value > 3)
81 					throw new ArgumentOutOfRangeException ("value");
82 				viewState ["HotSpotMode"] = value;
83 			}
84 		}
85 
86 		[DefaultValueAttribute ("")]
87 		[BindableAttribute (true)]
88 		[EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
89 		[NotifyParentPropertyAttribute (true)]
90 		[UrlPropertyAttribute]
91 		public string NavigateUrl {
92 			get {
93 				object o = viewState ["NavigateUrl"];
94 				return o != null ? (string) o : String.Empty;
95 			}
96 			set { viewState ["NavigateUrl"] = value; }
97 		}
98 
99 		[BindableAttribute (true)]
100 		[WebCategoryAttribute ("Behavior")]
101 		[DefaultValueAttribute ("")]
102 		[NotifyParentPropertyAttribute (true)]
103 		public string PostBackValue {
104 			get {
105 				object o = viewState ["PostBackValue"];
106 				return o != null ? (string) o : String.Empty;
107 			}
108 			set { viewState ["PostBackValue"] = value; }
109 		}
110 
111 		[DefaultValueAttribute ((short)0)]
112 		[WebCategoryAttribute ("Accessibility")]
113 		public virtual short TabIndex {
114 			get {
115 				object o = viewState ["TabIndex"];
116 				return o != null ? (short) o : (short) 0;
117 			}
118 			set { viewState ["TabIndex"] = value; }
119 		}
120 
121 		[WebCategoryAttribute ("Behavior")]
122 		[NotifyParentPropertyAttribute (true)]
123 		[DefaultValueAttribute ("")]
124 		[TypeConverterAttribute (typeof(TargetConverter))]
125 		public virtual string Target {
126 			get {
127 				object o = viewState ["Target"];
128 				return o != null ? (string) o : String.Empty;
129 			}
130 			set { viewState ["Target"] = value; }
131 		}
132 
133 		[Browsable (false)]
134 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
135 		protected StateBag ViewState {
136 			get { return viewState; }
137 		}
138 
LoadViewState(object savedState)139 		protected virtual void LoadViewState (object savedState)
140 		{
141 			viewState.LoadViewState (savedState);
142 		}
143 
SaveViewState()144 		protected virtual object SaveViewState ()
145 		{
146 			return viewState.SaveViewState ();
147 		}
148 
TrackViewState()149 		protected virtual void TrackViewState ()
150 		{
151 			viewState.TrackViewState ();
152 		}
153 
154 		protected virtual bool IsTrackingViewState
155 		{
156 			get { return viewState.IsTrackingViewState; }
157 		}
158 
IStateManager.LoadViewState(object savedState)159 		void IStateManager.LoadViewState (object savedState)
160 		{
161 			LoadViewState (savedState);
162 		}
163 
IStateManager.SaveViewState()164 		object IStateManager.SaveViewState ()
165 		{
166 			return SaveViewState ();
167 		}
168 
IStateManager.TrackViewState()169 		void IStateManager.TrackViewState ()
170 		{
171 			TrackViewState ();
172 		}
173 
174 		bool IStateManager.IsTrackingViewState {
175 			get { return IsTrackingViewState; }
176 		}
177 
ToString()178 		public override string ToString ()
179 		{
180 			return GetType().Name;
181 		}
182 
SetDirty()183 		internal void SetDirty ()
184 		{
185 			viewState.SetDirty (true);
186 		}
187 
GetCoordinates()188 		public abstract string GetCoordinates ();
189 
190 		protected internal abstract string MarkupName { get; }
191 	}
192 }
193 
194