process relative URL to the image.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputImage.cs
index 9fa15e5b848a8de0ebe8a830a796103b77e2333a..09917b7e20b7aaed2f3092f2307aa77408e5378d 100644 (file)
 // TODO: getting the .x and .y in LoadData doesn't work with mozilla
 //
 
-using System;
 using System.Globalization;
 using System.Collections.Specialized;
 using System.ComponentModel;
+using System.Security.Permissions;
 
 namespace System.Web.UI.HtmlControls {
+
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       // attributes
        [DefaultEvent("ServerClick")]
+#if NET_2_0
+       [SupportsEventValidation]
+#endif
        public class HtmlInputImage : HtmlInputControl, IPostBackDataHandler,
                      IPostBackEventHandler {
 
@@ -92,6 +100,9 @@ namespace System.Web.UI.HtmlControls {
                [WebSysDescription("")]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [WebCategory("Appearance")]
+#if NET_2_0
+               [UrlProperty]
+#endif
                public string Src {
                        get { return GetAtt ("src"); }
                        set { SetAtt ("src", value); }
@@ -121,69 +132,94 @@ namespace System.Web.UI.HtmlControls {
                        }
                }
 
+               bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
+               {
+                       string x = postCollection [UniqueID + ".x"];
+                       string y = postCollection [UniqueID + ".y"];
+
+                       if (x != null && x.Length != 0 &&
+                                       y != null && y.Length != 0) {
+                               clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
+                               clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
+                               Page.RegisterRequiresRaiseEvent (this);
+                               return true;
+                       }
+
+                       return false;
+               }
+
+               
+               void RaisePostBackEventInternal (string eventArgument)
+               {
+                       if (CausesValidation)
+#if NET_2_0
+                               Page.Validate (ValidationGroup);
+#else
+                               Page.Validate ();
+#endif
+                       OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
+               }
+
+               void RaisePostDataChangedEventInternal ()
+               {
+                       /* no events to raise */
+               }
+
 #if NET_2_0
-               [MonoTODO]
                [DefaultValue ("")]
-               public string ValidationGroup
+               public virtual string ValidationGroup
                {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetString ("ValidationGroup", "");
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["ValidationGroup"] = value;
                        }
                }
 
-               [MonoTODO]
                protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
-                       throw new NotImplementedException ();
+                       return LoadPostDataInternal (postDataKey, postCollection);
                }
 
-               [MonoTODO]
                protected virtual void RaisePostBackEvent (string eventArgument)
                {
-                       throw new NotImplementedException ();
+                       RaisePostBackEventInternal (eventArgument);
                }
 
-               [MonoTODO]
                protected virtual void RaisePostDataChangedEvent ()
                {
-                       throw new NotImplementedException ();
+                       RaisePostDataChangedEventInternal ();
                }
 #endif         
 
                bool IPostBackDataHandler.LoadPostData (string postDataKey,
                                NameValueCollection postCollection)
                {
-                       string x = postCollection [UniqueID + ".x"];
-                       string y = postCollection [UniqueID + ".y"];
-
-                       if (x != null && x.Length != 0 &&
-                                       y != null && y.Length != 0) {
-                               clicked_x = Int32.Parse (x, CultureInfo.InvariantCulture);
-                               clicked_y = Int32.Parse (y, CultureInfo.InvariantCulture);
-                               Page.RegisterRequiresRaiseEvent (this);
-                               return true;
-                       }
-
-                       return false;
+#if NET_2_0
+                       return LoadPostData (postDataKey, postCollection);
+#else
+                       return LoadPostDataInternal (postDataKey, postCollection);
+#endif
                }
 
                
                void IPostBackDataHandler.RaisePostDataChangedEvent ()
                {
+#if NET_2_0
+                       RaisePostDataChangedEvent();
+#else
+                       RaisePostDataChangedEventInternal ();
+#endif
                }
                                
                void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
                {
-                       if (CausesValidation)
 #if NET_2_0
-                               Page.Validate (ValidationGroup);
+                       RaisePostBackEvent (eventArgument);
 #else
-                               Page.Validate ();
+                       RaisePostBackEventInternal (eventArgument);
 #endif
-                       OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
                }
 
 #if NET_2_0
@@ -194,30 +230,43 @@ namespace System.Web.UI.HtmlControls {
                override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender (e);
-                       if (Page != null)
+
+                       if (Page != null) {
                                Page.RegisterRequiresPostBack (this);
+                       }
                }
 
                protected virtual void OnServerClick (ImageClickEventArgs e)
                {
-                       EventHandler handler = Events [ServerClickEvent] as EventHandler;
+                       ImageClickEventHandler handler = Events [ServerClickEvent] as ImageClickEventHandler;
                        if (handler != null)
                                handler (this, e);
                }
 
                protected override void RenderAttributes (HtmlTextWriter writer)
                {
+#if NET_2_0
+                       if (Page != null)
+                               Page.ClientScript.RegisterForEventValidation (this.UniqueID);
+                       
+                       if (CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup)) {
+                               ClientScriptManager csm = Page.ClientScript;
+                               Attributes ["onclick"] += csm.GetClientValidationEvent (ValidationGroup);
+                       }
+#else          
                        if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
                                ClientScriptManager csm = new ClientScriptManager (Page);
                                writer.WriteAttribute ("onclick", csm.GetClientValidationEvent ());
                        }
+#endif         
 
+                       PreProcessRelativeReference (writer,"src");
                        base.RenderAttributes (writer);
                }
 
                private void SetAtt (string name, string value)
                {
-                       if (value == null)
+                       if ((value == null) || (value.Length == 0))
                                Attributes.Remove (name);
                        else
                                Attributes [name] = value;