1 //------------------------------------------------------------------------------ 2 // <copyright file="HotSpot.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 namespace System.Web.UI.WebControls { 7 8 using System; 9 using System.Collections; 10 using System.ComponentModel; 11 using System.Drawing.Design; 12 using System.Web.UI; 13 using System.Globalization; 14 15 /// <devdoc> 16 /// <para>Defines abstract class from which all HotSpot shapes must inherit.</para> 17 /// </devdoc> 18 [ 19 TypeConverter(typeof(ExpandableObjectConverter)) 20 ] 21 public abstract class HotSpot : IStateManager { 22 23 private bool _isTrackingViewState; 24 private StateBag _viewState; 25 26 27 /// <devdoc> 28 /// <para>Gets or sets the keyboard shortcut key (AccessKey) for setting focus to the 29 /// HotSpot.</para> 30 /// </devdoc> 31 [ 32 DefaultValue(""), 33 Localizable(true), 34 WebCategory("Accessibility"), 35 WebSysDescription(SR.HotSpot_AccessKey) 36 ] 37 public virtual string AccessKey { 38 get { 39 string s = (string)ViewState["AccessKey"]; 40 if (s != null) { 41 return s; 42 } 43 return String.Empty; 44 } 45 set { 46 // Valid values are null, String.Empty, and single character strings 47 if ((value != null) && (value.Length > 1)) { 48 throw new ArgumentOutOfRangeException("value"); 49 } 50 51 ViewState["AccessKey"] = value; 52 } 53 } 54 55 56 /// <devdoc> 57 /// <para>Gets or sets the tool tip displayed over the 58 /// hotspot and the text for device-specific display.</para> 59 /// </devdoc> 60 [ 61 Localizable(true), 62 Bindable(true), 63 WebCategory("Behavior"), 64 DefaultValue(""), 65 WebSysDescription(SR.HotSpot_AlternateText), 66 NotifyParentProperty(true) 67 ] 68 public virtual String AlternateText { 69 get { 70 object text = ViewState["AlternateText"]; 71 return (text == null)? String.Empty : (string)text; 72 } 73 set { 74 ViewState["AlternateText"] = value; 75 } 76 } 77 78 79 /// <devdoc> 80 /// <para>Gets or sets the HotSpotMode to either postback or navigation.</para> 81 /// </devdoc> 82 [ 83 WebCategory("Behavior"), 84 DefaultValue(HotSpotMode.NotSet), 85 WebSysDescription(SR.HotSpot_HotSpotMode), 86 NotifyParentProperty(true) 87 ] 88 public virtual HotSpotMode HotSpotMode { 89 get { 90 object obj = ViewState["HotSpotMode"]; 91 return (obj == null) ? HotSpotMode.NotSet : (HotSpotMode)obj; 92 } 93 set { 94 if (value < HotSpotMode.NotSet || value > HotSpotMode.Inactive) { 95 throw new ArgumentOutOfRangeException("value"); 96 } 97 ViewState["HotSpotMode"] = value; 98 } 99 } 100 101 102 103 /// <devdoc> 104 /// <para>Gets or sets the argument for postback event.</para> 105 /// </devdoc> 106 [ 107 Bindable(true), 108 WebCategory("Behavior"), 109 DefaultValue(""), 110 WebSysDescription(SR.HotSpot_PostBackValue), 111 NotifyParentProperty(true) 112 ] 113 public String PostBackValue { 114 get { 115 object value = ViewState["PostBackValue"]; 116 return (value == null)? String.Empty : (string)value; 117 } 118 set { 119 ViewState["PostBackValue"] = value; 120 } 121 } 122 123 124 /// <devdoc> 125 /// <para>Gets the markup language string representation of the shape name.</para> 126 /// </devdoc> 127 protected internal abstract string MarkupName { 128 get; 129 } 130 131 132 /// <devdoc> 133 /// <para>Gets or sets the navigation url.</para> 134 /// </devdoc> 135 [ 136 Bindable(true), 137 WebCategory("Behavior"), 138 DefaultValue(""), 139 WebSysDescription(SR.HotSpot_NavigateUrl), 140 NotifyParentProperty(true), 141 UrlProperty(), 142 Editor("System.Web.UI.Design.UrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), 143 ] 144 public String NavigateUrl { 145 get { 146 object value = ViewState["NavigateUrl"]; 147 return (value == null)? String.Empty : (string)value; 148 } 149 set { 150 ViewState["NavigateUrl"] = value; 151 } 152 } 153 154 /// <devdoc> 155 /// <para> 156 /// Gets or 157 /// sets the tab index of the HotSpot.</para> 158 /// </devdoc> 159 [ 160 DefaultValue((short)0), 161 WebCategory("Accessibility"), 162 WebSysDescription(SR.HotSpot_TabIndex) 163 ] 164 public virtual short TabIndex { 165 get { 166 object o = ViewState["TabIndex"]; 167 if (o != null) { 168 return (short) o; 169 } 170 return (short)0; 171 } 172 set { 173 ViewState["TabIndex"] = value; 174 } 175 } 176 177 178 /// <devdoc> 179 /// <para>Gets or sets the name of the window for navigation.</para> 180 /// </devdoc> 181 [ 182 WebCategory("Behavior"), 183 DefaultValue(""), 184 TypeConverter(typeof(TargetConverter)), 185 WebSysDescription(SR.HotSpot_Target), 186 NotifyParentProperty(true) 187 ] 188 public virtual string Target { 189 get { 190 object value = ViewState["Target"]; 191 return (value == null)? String.Empty : (string)value; 192 } 193 set { 194 ViewState["Target"] = value; 195 } 196 } 197 198 199 [ 200 Browsable(false), 201 DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) 202 ] 203 protected StateBag ViewState { 204 get { 205 if (_viewState == null) { 206 _viewState = new StateBag(false); 207 if (_isTrackingViewState) ((IStateManager)_viewState).TrackViewState(); 208 } 209 return _viewState; 210 } 211 } 212 213 214 /// <devdoc> 215 /// <para>Returns a representation of the coordinates according to HTML standards.</para> 216 /// </devdoc> GetCoordinates()217 public abstract string GetCoordinates(); 218 SetDirty()219 internal void SetDirty() { 220 if (_viewState != null) { 221 _viewState.SetDirty(true); 222 } 223 } 224 225 ToString()226 public override string ToString () { 227 return GetType().Name; 228 } 229 230 #region IStatemanager implementation 231 232 /// <devdoc> 233 /// <para>Gets a value indicating whether a server control is tracking its view state changes.</para> 234 /// </devdoc> 235 protected virtual bool IsTrackingViewState { 236 get { 237 return _isTrackingViewState; 238 } 239 } 240 241 242 /// <devdoc> 243 /// <para>Restores view-state information that was saved by SaveViewState.</para> 244 /// </devdoc> LoadViewState(object savedState)245 protected virtual void LoadViewState(object savedState) { 246 if (savedState != null) { 247 ViewState.LoadViewState(savedState); 248 } 249 } 250 251 252 /// <devdoc> 253 /// <para>Saves any server control view-state changes that have 254 /// occurred since the time the page was posted back to the server.</para> 255 /// </devdoc> SaveViewState()256 protected virtual object SaveViewState() { 257 if (_viewState != null) { 258 return _viewState.SaveViewState(); 259 } 260 return null; 261 } 262 263 /// <devdoc> 264 /// <para>Causes the tracking of view-state changes to the server control.</para> 265 /// </devdoc> TrackViewState()266 protected virtual void TrackViewState() { 267 _isTrackingViewState = true; 268 269 if (_viewState != null) { 270 _viewState.TrackViewState(); 271 } 272 } 273 274 // private implementation of IStateManager 275 276 277 /// <internalonly/> 278 bool IStateManager.IsTrackingViewState { 279 get { 280 return IsTrackingViewState; 281 } 282 } 283 284 /// <internalonly/> IStateManager.LoadViewState(object savedState)285 void IStateManager.LoadViewState(object savedState) { 286 LoadViewState(savedState); 287 } 288 289 /// <internalonly/> IStateManager.SaveViewState()290 object IStateManager.SaveViewState() { 291 return SaveViewState(); 292 } 293 294 /// <internalonly/> IStateManager.TrackViewState()295 void IStateManager.TrackViewState() { 296 TrackViewState(); 297 } 298 #endregion 299 } 300 } 301