New tests.
[mono.git] / mcs / class / System.Web / System.Web.UI.Adapters / PageAdapter.cs
index 5497df3a203f659849c2de1bb4e91b8ac90df3d5..a86a98f71be152bb9696bbfb9439e7195a5fcdf2 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //     Dick Porter  <dick@ximian.com>
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,7 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.Collections;
@@ -40,90 +39,102 @@ namespace System.Web.UI.Adapters
                {
                }
 
-               [MonoTODO]
-               public virtual StringCollection CacheVaryByHeaders 
+               internal PageAdapter (Page p) : base (p)
                {
-                       get {
-                               throw new NotImplementedException ();
-                       }
                }
 
-               [MonoTODO]
-               public virtual StringCollection CacheVaryByParams 
-               {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+               public virtual StringCollection CacheVaryByHeaders {
+                       get { return null; }
+               }
+
+               public virtual StringCollection CacheVaryByParams {
+                       get { return null; }
                }
                
-               [MonoTODO]
                protected string ClientState 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return Page.GetSavedViewState ();
                        }
                }
                
-               [MonoTODO]
                public virtual NameValueCollection DeterminePostBackMode ()
                {
-                       throw new NotImplementedException ();
+                       return Page.DeterminePostBackMode ();
                }
 
-               [MonoTODO]
                public virtual ICollection GetRadioButtonsByGroup (string groupName)
                {
-                       throw new NotImplementedException ();
+                       if (radio_button_group == null)
+                               return new ArrayList();
+                       ArrayList radioButtons = (ArrayList) radio_button_group [groupName];
+                       if (radioButtons == null)
+                               return new ArrayList();
+                       return radioButtons;
                }
 
-               [MonoTODO]
                public virtual PageStatePersister GetStatePersister ()
                {
-                       throw new NotImplementedException ();
+                       return new HiddenFieldPageStatePersister ((Page)Control);
                }
 
-               [MonoTODO]
                public virtual void RegisterRadioButton (RadioButton radioButton)
                {
-                       throw new NotImplementedException ();
+                       if (radio_button_group == null)
+                               radio_button_group = new ListDictionary();
+                       ArrayList radioButtons = (ArrayList) radio_button_group [radioButton.GroupName];
+                       if (radioButtons == null)
+                               radio_button_group [radioButton.GroupName] = radioButtons = new ArrayList();
+                       if (!radioButtons.Contains(radioButton))
+                               radioButtons.Add(radioButton);
                }
 
-               [MonoTODO]
                public virtual void RenderBeginHyperlink (HtmlTextWriter w,
                                                          string targetUrl,
                                                          bool encodeUrl,
                                                          string softKeyLabel)
                {
-                       throw new NotImplementedException ();
+                       InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, null);
                }
 
-               [MonoTODO]
                public virtual void RenderBeginHyperlink (HtmlTextWriter w,
                                                          string targetUrl,
                                                          bool encodeUrl,
                                                          string softKeyLabel,
                                                          string accessKey)
                {
-                       throw new NotImplementedException ();
+                       if (accessKey != null && accessKey.Length > 1)
+                               throw new ArgumentOutOfRangeException("accessKey");
+                       InternalRenderBeginHyperlink (w, targetUrl, encodeUrl, softKeyLabel, accessKey);
                }
                
-               [MonoTODO]
+               void InternalRenderBeginHyperlink (HtmlTextWriter w,
+                                                  string targetUrl,
+                                                  bool encodeUrl,
+                                                  string softKeyLabel,
+                                                  string accessKey)
+               {
+                       w.AddAttribute (HtmlTextWriterAttribute.Href, targetUrl, encodeUrl);
+                       if (accessKey != null)
+                               w.AddAttribute (HtmlTextWriterAttribute.Accesskey, accessKey);
+                       w.RenderBeginTag (HtmlTextWriterTag.A);
+               }
+               
+               
                public virtual void RenderEndHyperlink (HtmlTextWriter w)
                {
-                       throw new NotImplementedException ();
+                       w.RenderEndTag();
                }
 
-               [MonoTODO]
                public virtual void RenderPostBackEvent (HtmlTextWriter w,
                                                         string target,
                                                         string argument,
                                                         string softKeyLabel,
                                                         string text)
                {
-                       throw new NotImplementedException ();
+                       RenderPostBackEvent (w, target, argument, softKeyLabel, text, Page.Request.FilePath, null, true);
                }
 
-               [MonoTODO]
                public virtual void RenderPostBackEvent (HtmlTextWriter w,
                                                         string target,
                                                         string argument,
@@ -132,10 +143,9 @@ namespace System.Web.UI.Adapters
                                                         string postUrl,
                                                         string accessKey)
                {
-                       throw new NotImplementedException ();
+                       RenderPostBackEvent (w, target, argument, softKeyLabel, text, postUrl, accessKey, true);
                }
 
-               [MonoTODO]
                protected void RenderPostBackEvent (HtmlTextWriter w,
                                                    string target,
                                                    string argument,
@@ -145,20 +155,24 @@ namespace System.Web.UI.Adapters
                                                    string accessKey,
                                                    bool encode)
                {
-                       throw new NotImplementedException ();
+                       string url = String.Format ("{0}?__VIEWSTATE={1}&__EVENTTARGET={2}&__EVENTARGUMENT={3}&__PREVIOUSPAGE={4}",
+                               postUrl, HttpUtility.UrlEncode (Page.GetSavedViewState ()), target, argument, Page.Request.FilePath);
+                       RenderBeginHyperlink (w, url, encode, softKeyLabel, accessKey);
+                       w.Write(text);
+                       RenderEndHyperlink(w);
                }
 
-               [MonoTODO]
                public virtual string TransformText (string text) 
                {
-                       throw new NotImplementedException ();
+                       return text;
                }
                
-               [MonoTODO]
                protected internal virtual string GetPostBackFormReference (string formID)
                {
-                       throw new NotImplementedException ();
+                       return String.Format("document.forms['{0}']", formID);
                }
+               
+               ListDictionary radio_button_group;
        }
 }
-#endif
+