New tests.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputImage.cs
index 864c358250ec8b06598d1078d70ded7d8374bae6..d73f34fb05c23553aa6a675c99129f747960a8d0 100644 (file)
@@ -24,7 +24,7 @@
 // Authors:
 //     Jackson Harper (jackson@ximian.com)
 //
-// (C) 2005 Novell, Inc.
+// (C) 2005-2010 Novell, Inc.
 
 
 //
@@ -35,24 +35,22 @@ using System.Globalization;
 using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Security.Permissions;
+using System.Web.Util;
 
-namespace System.Web.UI.HtmlControls {
-
+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 {
-
-               private static readonly object ServerClickEvent = new object ();
+       public class HtmlInputImage : HtmlInputControl, IPostBackDataHandler, IPostBackEventHandler 
+       {
+               static readonly object ServerClickEvent = new object ();
 
-               private int clicked_x;
-               private int clicked_y;
+               int clicked_x;
+               int clicked_y;
 
                public HtmlInputImage () : base ("image")
                {
@@ -61,12 +59,7 @@ namespace System.Web.UI.HtmlControls {
                [DefaultValue(true)]
                [WebSysDescription("")]
                [WebCategory("Behavior")]
-#if NET_2_0
-               public virtual
-#else
-               public
-#endif         
-               bool CausesValidation {
+               public virtual bool CausesValidation {
                        get {
                                return ViewState.GetBool ("CausesValidation", true);
                        }
@@ -86,9 +79,7 @@ namespace System.Web.UI.HtmlControls {
 
                [DefaultValue("")]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
-#if NET_2_0
                [Localizable (true)]
-#endif         
                [WebSysDescription("")]
                [WebCategory("Appearance")]
                public string Alt {
@@ -100,19 +91,13 @@ 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); }
                }
 
-#if NET_2_0
                [DefaultValue("-1")]
-#else          
-               [DefaultValue("")]
-#endif         
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
                [WebCategory("Appearance")]
@@ -121,14 +106,14 @@ namespace System.Web.UI.HtmlControls {
                                string border = Attributes ["border"];
                                if (border == null)
                                        return -1;
-                               return Int32.Parse (border, CultureInfo.InvariantCulture);
+                               return Int32.Parse (border, Helpers.InvariantCulture);
                        }
                        set {
                                if (value == -1) {
                                        Attributes.Remove ("border");
                                        return;
                                }
-                               Attributes ["border"] = value.ToString (CultureInfo.InvariantCulture);
+                               Attributes ["border"] = value.ToString (Helpers.InvariantCulture);
                        }
                }
 
@@ -139,8 +124,8 @@ namespace System.Web.UI.HtmlControls {
 
                        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);
+                               clicked_x = Int32.Parse (x, Helpers.InvariantCulture);
+                               clicked_y = Int32.Parse (y, Helpers.InvariantCulture);
                                Page.RegisterRequiresRaiseEvent (this);
                                return true;
                        }
@@ -152,11 +137,8 @@ namespace System.Web.UI.HtmlControls {
                void RaisePostBackEventInternal (string eventArgument)
                {
                        if (CausesValidation)
-#if NET_2_0
                                Page.Validate (ValidationGroup);
-#else
-                               Page.Validate ();
-#endif
+
                        OnServerClick (new ImageClickEventArgs (clicked_x, clicked_y));
                }
 
@@ -165,7 +147,6 @@ namespace System.Web.UI.HtmlControls {
                        /* no events to raise */
                }
 
-#if NET_2_0
                [DefaultValue ("")]
                public virtual string ValidationGroup
                {
@@ -189,78 +170,59 @@ namespace System.Web.UI.HtmlControls {
 
                protected virtual void RaisePostDataChangedEvent ()
                {
+                       ValidateEvent (UniqueID, String.Empty);
                        RaisePostDataChangedEventInternal ();
                }
-#endif         
 
-               bool IPostBackDataHandler.LoadPostData (string postDataKey,
-                               NameValueCollection postCollection)
+               bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
-#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 NET_2_0
                        RaisePostBackEvent (eventArgument);
-#else
-                       RaisePostBackEventInternal (eventArgument);
-#endif
                }
 
-#if NET_2_0
-               protected internal
-#else          
-               protected
-#endif         
-               override void OnPreRender (EventArgs e)
+               protected internal override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender (e);
 
-                       if (Page != null) {
-                               Page.RegisterRequiresPostBack (this);
+                       Page page = Page;
+                       if (page != null && !Disabled) {
+                               page.RegisterRequiresPostBack (this);
+                               page.RegisterEnabledControl (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 (CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup)) {
-                               ClientScriptManager csm = Page.ClientScript;
+                       Page page = Page;
+                       if (page != null)
+                               page.ClientScript.RegisterForEventValidation (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)
+               void SetAtt (string name, string value)
                {
                        if ((value == null) || (value.Length == 0))
                                Attributes.Remove (name);
@@ -268,7 +230,7 @@ namespace System.Web.UI.HtmlControls {
                                Attributes [name] = value;
                }
 
-               private string GetAtt (string name)
+               string GetAtt (string name)
                {
                        string res = Attributes [name];
                        if (res == null)
@@ -284,4 +246,3 @@ namespace System.Web.UI.HtmlControls {
                }
        }
 }
-