2008-03-13 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / HotSpot.cs
1 //
2 // System.Web.UI.WebControls.HotSpot.cs
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 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 #if NET_2_0
32
33 using System.ComponentModel;
34 using System.Security.Permissions;
35
36 namespace System.Web.UI.WebControls
37 {
38         [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
39         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41         public abstract class HotSpot: IStateManager
42         {
43                 StateBag viewState = new StateBag ();
44                 
45                 [LocalizableAttribute (true)]
46                 [DefaultValueAttribute ("")]
47                 public virtual string AccessKey {
48                         get {
49                                 object o = viewState ["AccessKey"];
50                                 return o != null ? (string) o : "";
51                         }
52                         set {
53                                 if (value == null || value.Length < 2)
54                                         viewState ["AccessKey"] = value;
55                                 else
56                                         throw new ArgumentOutOfRangeException ("value", "AccessKey can only be null, empty or a single character");
57                         }
58                 }
59                 
60                 [LocalizableAttribute (true)]
61                 [NotifyParentPropertyAttribute (true)]
62                 [WebCategoryAttribute ("Behavior")]
63                 [DefaultValueAttribute ("")]
64                 [BindableAttribute (true)]
65                 public virtual string AlternateText {
66                         get {
67                                 object o = viewState ["AlternateText"];
68                                 return o != null ? (string) o : "";
69                         }
70                         set {
71                                 viewState ["AlternateText"] = value;
72                         }
73                 }
74                 
75                 [WebCategoryAttribute ("Behavior")]
76                 [DefaultValueAttribute (HotSpotMode.NotSet)]
77                 [NotifyParentPropertyAttribute (true)]
78                 public virtual HotSpotMode HotSpotMode {
79                         get {
80                                 object o = viewState ["HotSpotMode"];
81                                 return o != null ? (HotSpotMode) o : HotSpotMode.NotSet;
82                         }
83                         set {
84                                 if ((int) value < 0 || (int) value > 3)
85                                         throw new ArgumentOutOfRangeException ("value");
86                                 viewState ["HotSpotMode"] = value;
87                         }
88                 }
89                 
90                 [DefaultValueAttribute ("")]
91                 [BindableAttribute (true)]
92                 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
93                 [NotifyParentPropertyAttribute (true)]
94                 [UrlPropertyAttribute]
95                 public string NavigateUrl {
96                         get {
97                                 object o = viewState ["NavigateUrl"];
98                                 return o != null ? (string) o : "";
99                         }
100                         set {
101                                 viewState ["NavigateUrl"] = value;
102                         }
103                 }
104                 
105                 [BindableAttribute (true)]
106                 [WebCategoryAttribute ("Behavior")]
107                 [DefaultValueAttribute ("")]
108                 [NotifyParentPropertyAttribute (true)]
109                 public string PostBackValue {
110                         get {
111                                 object o = viewState ["PostBackValue"];
112                                 return o != null ? (string) o : "";
113                         }
114                         set {
115                                 viewState ["PostBackValue"] = value;
116                         }
117                 }
118                 
119                 [DefaultValueAttribute ((short)0)]
120                 [WebCategoryAttribute ("Accessibility")]
121                 public virtual short TabIndex {
122                         get {
123                                 object o = viewState ["TabIndex"];
124                                 return o != null ? (short) o : (short) 0;
125                         }
126                         set {
127                                 viewState ["TabIndex"] = value;
128                         }
129                 }
130                 
131                 [WebCategoryAttribute ("Behavior")]
132                 [NotifyParentPropertyAttribute (true)]
133                 [DefaultValueAttribute ("")]
134                 [TypeConverterAttribute (typeof(TargetConverter))]
135                 public virtual string Target {
136                         get {
137                                 object o = viewState ["Target"];
138                                 return o != null ? (string) o : "";
139                         }
140                         set {
141                                 viewState ["Target"] = value;
142                         }
143                 }
144                 
145                 [Browsable (false)]
146                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
147                 protected StateBag ViewState {
148                         get { return viewState; }
149                 } 
150                 
151                 protected virtual void LoadViewState (object savedState)
152                 {
153                         viewState.LoadViewState (savedState);
154                 }
155                 
156                 protected virtual object SaveViewState ()
157                 {
158                         return viewState.SaveViewState ();
159                 }
160                 
161                 protected virtual void TrackViewState ()
162                 {
163                         viewState.TrackViewState ();
164                 }
165                 
166                 protected virtual bool IsTrackingViewState
167                 {
168                         get { return viewState.IsTrackingViewState; }
169                 }
170         
171                 void IStateManager.LoadViewState (object savedState)
172                 {
173                         LoadViewState (savedState);
174                 }
175                 
176                 object IStateManager.SaveViewState ()
177                 {
178                         return SaveViewState ();
179                 }
180                 
181                 void IStateManager.TrackViewState ()
182                 {
183                         TrackViewState ();
184                 }
185                 
186                 bool IStateManager.IsTrackingViewState
187                 {
188                         get { return IsTrackingViewState; }
189                 }
190                 
191                 public override string ToString ()
192                 {
193                         return GetType().Name;
194                 }
195                 
196                 internal void SetDirty ()
197                 {
198                         viewState.SetDirty (true);
199                 }
200         
201                 public abstract string GetCoordinates ();
202                 
203                 protected internal abstract string MarkupName { get; }
204         }
205 }
206
207 #endif