1c1d7154578566a88791100d0f0e45f73200da84
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ImageButton.cs
1 //
2 // System.Web.UI.WebControls.ImageButton.cs
3 //
4 // Authors:
5 //      Jordi Mas i Hernandez (jordi@ximian.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 using System.Collections.Specialized;
32 using System.ComponentModel;
33
34 namespace System.Web.UI.WebControls {
35         [DefaultEvent("Click")]
36 #if NET_2_0
37         [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
38 #endif          
39         public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler
40 #if NET_2_0
41         , IButtonControl
42 #endif  
43         {
44
45                 private static readonly object ClickEvent = new object ();
46                 private static readonly object CommandEvent = new object ();
47                 private int pos_x, pos_y;
48
49                 public ImageButton ()
50                 {
51
52                 }
53
54 #if ONLY_1_1
55                 [Bindable(false)]
56 #endif          
57                 [DefaultValue(true)]
58                 [WebSysDescription ("")]
59                 [WebCategory ("Behavior")]
60 #if NET_2_0
61                 [Themeable (false)]
62                 public virtual
63 #else           
64                 public
65 #endif          
66                 bool CausesValidation {
67                         get {
68                                 return ViewState.GetBool ("CausesValidation", true);
69                         }
70
71                         set {
72                                 ViewState ["CausesValidation"] = value;
73                         }
74                 }
75
76                 [Bindable(true)]
77                 [DefaultValue("")]
78                 [WebSysDescription ("")]
79                 [WebCategory ("Behavior")]
80 #if NET_2_0
81                 [Themeable (false)]
82                 public virtual
83 #else           
84                 public
85 #endif          
86                 string CommandArgument {
87                         get {
88                                 return ViewState.GetString ("CommandArgument", "");
89                         }
90                         set {
91                                 ViewState ["CommandArgument"] = value;
92                         }
93                 }
94
95                 [DefaultValue("")]
96                 [WebSysDescription ("")]
97                 [WebCategory ("Behavior")]
98 #if NET_2_0
99                 [Themeable (false)]
100                 public virtual
101 #else           
102                 public
103 #endif          
104                 string CommandName {
105                         get {
106                                 return ViewState.GetString ("CommandName", "");
107                         }
108                         set {
109                                 ViewState ["CommandName"] = value;
110                         }
111                 }
112
113 #if NET_2_0
114                 [EditorBrowsable (EditorBrowsableState.Always)]
115                 [Browsable (true)]
116                 [DefaultValue (true)]
117                 [Bindable (true)]
118                 [MonoTODO]
119                 public virtual new bool Enabled
120                 {
121                         get {
122                                 throw new NotImplementedException ();
123                         }
124                         set {
125                                 throw new NotImplementedException ();
126                         }
127                 }
128
129                 [Browsable (false)]
130                 [EditorBrowsable (EditorBrowsableState.Never)]
131                 [Themeable (false)]
132                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
133                 [MonoTODO]
134                 public virtual new bool GenerateEmptyAlternateText
135                 {
136                         get {
137                                 throw new NotImplementedException ();
138                         }
139                         set {
140                                 throw new NotImplementedException ();
141                         }
142                 }
143
144                 [DefaultValue ("")]
145                 [Themeable (false)]
146                 [MonoTODO]
147                 public virtual string OnClientClick 
148                 {
149                         get {
150                                 throw new NotImplementedException ();
151                         }
152                         set {
153                                 throw new NotImplementedException ();
154                         }
155                 }
156
157                 [Themeable (false)]
158 #if NET_2_0
159                 [UrlProperty ("*.aspx")]
160 #else
161                 [UrlProperty]
162 #endif
163                 [DefaultValue ("")]
164                 [Editor ("System.Web.UI.Design.UrlEditor, "  + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
165                 [MonoTODO]
166                 public virtual string PostBackUrl
167                 {
168                         get {
169                                 throw new NotImplementedException ();
170                         }
171                         set {
172                                 throw new NotImplementedException ();
173                         }
174                 }
175
176                 [Themeable (false)]
177                 [DefaultValue ("")]
178                 [WebSysDescription ("")]
179                 [WebCategory ("Behavior")]
180                 public virtual string ValidationGroup
181                 {
182                         get {
183                                 return ViewState.GetString ("ValidationGroup", "");
184                         }
185                         set {
186                                 ViewState ["ValidationGroup"] = value;
187                         }
188                 }
189 #endif          
190
191                 [Browsable(false)]
192                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
193 #if NET_2_0 && HAVE_CONTROL_ADAPTERS
194                 protected virtual new
195 #else           
196                 protected override
197 #endif
198                 HtmlTextWriterTag TagKey {
199                         get { return HtmlTextWriterTag.Input; }
200                 }
201
202 #if NET_2_0
203                 [MonoTODO]
204                 protected virtual string Text 
205                 {
206                         get {
207                                 throw new NotImplementedException ();
208                         }
209                         set {
210                                 throw new NotImplementedException ();
211                         }
212                 }
213 #endif          
214
215                 protected override void AddAttributesToRender (HtmlTextWriter writer)
216                 {
217                         if (Page != null)
218                                 Page.VerifyRenderingInServerForm (this);
219
220                         writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
221                         if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
222                                 ClientScriptManager csm = new ClientScriptManager (Page);
223                                 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
224                                 writer.AddAttribute ("language", "javascript");
225                         }
226                         base.AddAttributesToRender (writer);
227                 }
228
229 #if NET_2_0
230                 [MonoTODO]
231                 protected virtual PostBackOptions GetPostBackOptions ()
232                 {
233                         throw new NotImplementedException ();
234                 }
235 #endif          
236
237
238 #if NET_2_0
239                 [MonoTODO]
240                 protected virtual bool LoadPostData (string postDataKey, NameValueCollection psotCollection) 
241                 {
242                         throw new NotImplementedException ();
243                 }
244
245                 [MonoTODO]
246                 protected virtual void RaisePostDataChangedEvent ()
247                 {
248                         throw new NotImplementedException ();
249                 }
250                 
251                 [MonoTODO]
252                 protected virtual void RaisePostBackEvent (string eventArgument)
253                 {
254                         throw new NotImplementedException ();
255                 }
256 #endif
257
258                 bool IPostBackDataHandler.LoadPostData (string postDataKey,  NameValueCollection postCollection)
259                 {
260                         string x, y;
261
262                         x = postCollection [UniqueID + ".x"];
263                         y = postCollection [UniqueID + ".y"];
264
265                         if (x != null && y != null) {
266                                 pos_x = Int32.Parse(x);
267                                 pos_y = Int32.Parse(y);
268                                 Page.RegisterRequiresRaiseEvent (this);
269                         }
270
271                         return true;
272                 }
273
274
275                 void IPostBackDataHandler.RaisePostDataChangedEvent ()
276                 {
277
278                 }
279
280                 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
281                 {
282                         if (CausesValidation)
283 #if NET_2_0
284                                 Page.Validate (ValidationGroup);
285 #else
286                                 Page.Validate ();
287 #endif
288
289                         OnClick (new ImageClickEventArgs (pos_x, pos_y));
290                         OnCommand (new CommandEventArgs (CommandName, CommandArgument));
291                 }
292
293                 protected virtual void OnClick (ImageClickEventArgs e)
294                 {
295                         if (Events != null) {
296                                 EventHandler eh = (EventHandler) (Events [ClickEvent]);
297                                 if (eh != null)
298                                         eh (this, e);
299                         }
300                 }
301
302                 protected virtual void OnCommand (CommandEventArgs e)
303                 {
304                         if (Events != null) {
305                                 CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
306                                 if (eh != null)
307                                         eh (this, e);
308                         }
309
310                         RaiseBubbleEvent (this, e);
311                 }
312
313 #if NET_2_0
314                 protected internal
315 #else           
316                 protected
317 #endif          
318                 override void OnPreRender (EventArgs e)
319                 {
320                         if (Page != null)
321                                 Page.RegisterRequiresPostBack (this);
322                 }
323
324                 [WebSysDescription ("")]
325                 [WebCategory ("Action")]
326                 public event ImageClickEventHandler Click
327                 {
328                         add {
329                                 Events.AddHandler (ClickEvent, value);
330                         }
331                         remove {
332                                 Events.RemoveHandler (ClickEvent, value);
333                         }
334                 }
335
336                 [WebSysDescription ("")]
337                 [WebCategory ("Action")]
338                 public event CommandEventHandler Command
339                 {
340                         add {
341                                 Events.AddHandler (CommandEvent, value);
342                         }
343                         remove {
344                                 Events.RemoveHandler (CommandEvent, value);
345                         }
346                 }
347
348 #if NET_2_0
349                 [MonoTODO]
350                 string IButtonControl.Text 
351                 {
352                         get {
353                                 throw new NotImplementedException ();
354                         }
355                         set {
356                                 throw new NotImplementedException ();
357                         }
358                 }
359
360                 [MonoTODO]
361                 event EventHandler IButtonControl.Click
362                 {
363                         add {
364                                 throw new NotImplementedException ();
365                         }
366                         remove {
367                                 throw new NotImplementedException ();
368                         }
369                 }
370                 
371 #endif
372         }
373 }
374