refactoring: Button, ImageButton and LinkButton are used insted internal DataControlB...
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / PagedDataSource.cs
index 6afb4687e4947f049db59c733a8241d968e4e198..d3cd36a46c7c5d1afc0622d2a2fb74cb3ccb294b 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Web.UI.WebControls {
        public sealed class PagedDataSource : ICollection, IEnumerable, ITypedList
        {
                int page_size, current_page_index, virtual_count;
-               bool allow_paging, allow_custom_paging;
+               bool allow_paging, allow_custom_paging, allow_server_paging;
                IEnumerable source;
                
                public PagedDataSource ()
@@ -46,7 +46,14 @@ namespace System.Web.UI.WebControls {
 
                public bool AllowCustomPaging {
                        get { return allow_custom_paging; }
-                       set { allow_custom_paging = value; }
+                       set { 
+                               allow_custom_paging = value; 
+#if NET_2_0
+                               // AllowCustomPaging and AllowServerPaging are mutually exclusive
+                               if (allow_custom_paging)
+                                       allow_server_paging = false;
+#endif
+                       }
                }
 
                public bool AllowPaging {
@@ -84,7 +91,11 @@ namespace System.Web.UI.WebControls {
                                if (source == null)
                                        return 0;
                                
-                               if (IsCustomPagingEnabled)
+                               if (IsCustomPagingEnabled 
+#if NET_2_0
+                                   || IsServerPagingEnabled
+#endif
+                               )
                                        return virtual_count;
 
                                if (source is ICollection)
@@ -96,7 +107,11 @@ namespace System.Web.UI.WebControls {
 
                public int FirstIndexInPage {
                        get {
-                               if (!IsPagingEnabled || IsCustomPagingEnabled || source == null)
+                               if (!IsPagingEnabled || IsCustomPagingEnabled || 
+#if NET_2_0
+                                   IsServerPagingEnabled || 
+#endif
+                                   source == null)
                                        return 0;
                                
                                return current_page_index * page_size;
@@ -107,6 +122,12 @@ namespace System.Web.UI.WebControls {
                        get { return IsPagingEnabled && allow_custom_paging; }
                }
 
+#if NET_2_0
+               public bool IsServerPagingEnabled {
+                       get { return IsPagingEnabled && allow_server_paging; }
+               }
+#endif
+
                public bool IsFirstPage {
                        get { 
                                if (!allow_paging)
@@ -141,10 +162,10 @@ namespace System.Web.UI.WebControls {
                        get {
                                if (source == null)
                                        return 0;
-
+                               
                                if (!IsPagingEnabled || DataSourceCount == 0 || page_size == 0)
                                        return 1;
-
+                               
                                return (DataSourceCount + page_size - 1) / page_size;
                        }
                }
@@ -163,40 +184,17 @@ namespace System.Web.UI.WebControls {
                        set { virtual_count = value; }
                }
 #if NET_2_0
-               [MonoTODO]
                public bool AllowServerPaging {
                        get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
-               }
-
-               [MonoTODO]
-               public DataSourceSelectArguments DataSourceSelectArguments {
-                       get {
-                               throw new NotImplementedException ();
+                               return allow_server_paging;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               allow_server_paging = value;
+                               // AllowCustomPaging and AllowServerPaging are mutually exclusive
+                               if (allow_server_paging)
+                                       allow_custom_paging = false;
                        }
                }
-               [MonoTODO]
-               public DataSourceView DataSourceView {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
-               }
-
-               [MonoTODO]
-               public void SetItemCountFromPageIndex (int highestPageIndex)
-               {
-                       throw new NotImplementedException ();
-               }
 #endif
 
                public void CopyTo (Array array, int index)
@@ -243,10 +241,81 @@ namespace System.Web.UI.WebControls {
                        return String.Empty; // as documented
                }
 
+#if TARGET_JVM
+               internal class ListEnum : IEnumerator
+               {
+                       int start;
+                       int end;
+                       int ind;
+                       IList list;
+
+                       internal ListEnum(IList list, int start, int end)
+                       {
+                               this.list = list;
+                               this.start = start;
+                               this.end = end;
+                               this.ind = start - 1;
+                       }
+
+                       public bool MoveNext()
+                       {
+                               ind++;
+                               return (ind < end);
+                       }
+
+                       public void Reset() { ind = start - 1; }
+                       public object Current { get { return list[ind]; }}
+               }
+
                private IEnumerator GetListEnum (IList list, int start, int end)
                {
                        if (!allow_paging)
                                end = list.Count;
+                       return new ListEnum(list, start, end);
+               }
+
+               internal class EnumeratorEnum : IEnumerator
+               {
+                       int start;
+                       int end;
+                       int ind;
+                       IEnumerator en;
+                       PagedDataSource parent;
+
+                       internal EnumeratorEnum(PagedDataSource parent, IEnumerator en, int start, int end)
+                       {
+                               this.parent = parent;
+                               this.en = en;
+                               this.start = start;
+                               this.end = end;
+                               this.ind = start - 1;
+                               for (int i = 0; i < start; i++)
+                                       en.MoveNext ();
+                       }
+
+                       public bool MoveNext()
+                       {
+                               ind++;
+                               return (!parent.allow_paging || ind < end) && en.MoveNext ();
+                       }
+
+                       public void Reset()
+                       {
+                               throw new NotSupportedException();
+                       }
+
+                       public object Current { get { return en.Current; }}
+               }
+
+               private IEnumerator GetEnumeratorEnum (IEnumerator e, int start, int end)
+               {
+                       return new EnumeratorEnum(this, e, start, end);
+               }
+#else
+               private IEnumerator GetListEnum (IList list, int start, int end)
+               {
+                       if (!AllowPaging)
+                               end = list.Count;
                        else if (start >= list.Count)
                                yield break;
                        
@@ -261,6 +330,7 @@ namespace System.Web.UI.WebControls {
                        for (int i = start; (!allow_paging || i < end) && e.MoveNext (); i++)
                                yield return e.Current;
                }
+#endif
        }
 }