2003-01-26 Gaurav Vaish <gvaish_mono AT lycos.com>
authorGaurav Vaish <gvaish@mono-cvs.ximian.com>
Mon, 27 Jan 2003 16:01:03 +0000 (16:01 -0000)
committerGaurav Vaish <gvaish@mono-cvs.ximian.com>
Mon, 27 Jan 2003 16:01:03 +0000 (16:01 -0000)
* Form.cs                : HasActiveHandler()       - Stubbed.
* List.cs                : Initial implementation.
* ItemPager.cs,
* Image.cs,
* Link.cs,
* ListDataBindEventArgs.cs,
* ListDataBindEventHandler.cs,
* ListCommandEventArgs.cs,
* ListCommandEventHandler.cs,
* LoadItemsEventArgs.cs,
* LoadItemsEventHandler.cs
                         : Completed.
* MobilePage.cs          : ActivePage { get; set; } - Stubbed.
                         : GetForm(string)          - Stubbed.
* PagedControl.cs        : Initial implementation.

svn path=/trunk/mcs/; revision=10950

14 files changed:
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ChangeLog
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Form.cs
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Image.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ItemPager.cs
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Link.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/List.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventArgs.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventHandler.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventArgs.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventHandler.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventArgs.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventHandler.cs [new file with mode: 0644]
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/MobilePage.cs
mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/PagedControl.cs [new file with mode: 0644]

index f9b043252728d5791f78e0d9ab2a2f3d977999ae..aceb5a137686d791cf75adaaa732bf6f59c14aaf 100644 (file)
@@ -1,4 +1,22 @@
 
+2003-01-26     Gaurav Vaish <gvaish_mono AT lycos.com>
+
+       * Form.cs                : HasActiveHandler()       - Stubbed.
+       * List.cs                : Initial implementation.
+       * ItemPager.cs,
+       * Image.cs,
+       * Link.cs,
+       * ListDataBindEventArgs.cs,
+       * ListDataBindEventHandler.cs,
+       * ListCommandEventArgs.cs,
+       * ListCommandEventHandler.cs,
+       * LoadItemsEventArgs.cs,
+       * LoadItemsEventHandler.cs
+                                : Completed.
+       * MobilePage.cs          : ActivePage { get; set; } - Stubbed.
+                                : GetForm(string)          - Stubbed.
+       * PagedControl.cs        : Initial implementation.
+
 2003-01-25     Gaurav Vaish <gvaish_mono AT lycos.com>
 
        * ControlPager.cs        : Completed.
index 8577ebbb19a9ac847924d58e2c5b6396452cee32..208c20916cb4ff3ce584d16b321c8a4de5e59a45 100644 (file)
@@ -48,5 +48,10 @@ namespace System.Web.UI.MobileControls
                                throw new NotImplementedException();
                        }
                }
+
+               public bool HasActiveHandler()
+               {
+                       throw new NotImplementedException();
+               }
        }
 }
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Image.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Image.cs
new file mode 100644 (file)
index 0000000..9ced2e1
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : Image
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System;
+using System.Web.UI;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public class Image : MobileControl, IPostBackEventHandler
+       {
+               public Image()
+               {
+               }
+
+               void IPostBackEventHandler.RaisePostBackEvent(string argument)
+               {
+                       MobilePage.ActiveForm = MobilePage.GetForm(argument);
+               }
+
+               public string AlternateText
+               {
+                       get
+                       {
+                               object o = ViewState["AlternateText"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["AlternateText"] = value;
+                       }
+               }
+
+               public string ImageUrl
+               {
+                       get
+                       {
+                               object o = ViewState["ImageUrl"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["ImageUrl"] = value;
+                       }
+               }
+
+               public string NavigateUrl
+               {
+                       get
+                       {
+                               object o = ViewState["NavigateUrl"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["NavigateUrl"] = value;
+                       }
+               }
+
+               public string SoftkeyLabel
+               {
+                       get
+                       {
+                               object o = ViewState["SoftkeyLabel"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["SoftkeyLabel"] = value;
+                       }
+               }
+       }
+}
index f689ce03d74ef39423bfee940e06e46947a293ab..4b1dd7025bdd16da6451314f2f4c339a6ce596fd 100644 (file)
@@ -33,11 +33,119 @@ namespace System.Web.UI.MobileControls
                        this.control = control;
                        if(itemsPerPage > 0)
                        {
-                               throw new NotImplementedException();
+                               if(itemCount < itemsPerPage)
+                               {
+                                       firstPageItemCount = itemCount;
+                                       firstPage = pager.GetPage(itemWeight * itemCount);
+                                       lastPage  = firstPage;
+                               } else
+                               {
+                                       int ppic = (itemCount - 1)/itemsPerPage + 1;
+                                       firstPageItemCount = itemsPerPage;
+                                       fullPageItemCount  = itemsPerPage;
+                                       lastPageItemCount = ppic - (ppic - 1)*itemsPerPage;
+                                       firstPage = pager.GetPage(itemsPerPage * itemWeight);
+                                       pager.PageCount += (ppic - 1);
+                                       if(ppic > 1)
+                                       {
+                                               pager.RemainingWeight = pager.PageWeight
+                                                                       - (itemsPerPage * itemWeight);
+                                               lastPage = firstPage + ppic - 1;
+                                       }
+                               }
                        } else
                        {
-                               throw new NotImplementedException();
+                               int totalWt = itemWeight * itemCount;
+                               if(totalWt <= pager.RemainingWeight)
+                               {
+                                       firstPageItemCount = itemCount;
+                                       firstPage = pager.GetPage(totalWt);
+                                       lastPage  = firstPage;
+                               } else
+                               {
+                                       firstPageItemCount = pager.RemainingWeight / itemWeight;
+                                       int rem = itemCount - firstPageItemCount;
+                                       fullPageItemCount  = Math.Max(itemWeight, pager.PageWeight);
+                                       int pages = rem / fullPageItemCount;
+                                       lastPageItemCount = rem % fullPageItemCount;
+                                       firstPage = pager.PageCount;
+                                       pager.PageCount += 1;
+                                       pager.RemainingWeight = pager.PageWeight;
+                                       pager.PageCount += pages;
+                                       pager.RemainingWeight -= lastPageItemCount * itemWeight;
+                                       if(firstPageItemCount == 0)
+                                       {
+                                               firstPage += 1;
+                                               firstPageItemCount = Math.Min(fullPageItemCount,
+                                                                             itemCount);
+                                       }
+                                       if(lastPageItemCount == 0)
+                                       {
+                                               pager.PageCount -= 1;
+                                               lastPageItemCount = Math.Min(fullPageItemCount,
+                                                                            itemCount);
+                                               pager.RemainingWeight = 0;
+                                       }
+                                       lastPage = pager.PageCount;
+                               }
+                               control.FirstPage = firstPage;
+                               control.LastPage  = lastPage;
                        }
                }
+
+               public int ItemCount
+               {
+                       get
+                       {
+                               return GetItemCount();
+                       }
+               }
+
+               public int ItemIndex
+               {
+                       get
+                       {
+                               return GetItemIndex();
+                       }
+               }
+
+               private int GetItemCount()
+               {
+                       int cp = control.Form.CurrentPage;
+                       int retVal;
+                       if(cp >= firstPage && cp <= lastPage)
+                       {
+                               if(cp == firstPage)
+                                       retVal = firstPageItemCount;
+                               else if(cp == lastPage)
+                                       retVal = lastPageItemCount;
+                               else
+                                       retVal = fullPageItemCount;
+                       } else
+                       {
+                               retVal = -1;
+                       }
+                       return retVal;
+               }
+
+               private int GetItemIndex()
+               {
+                       int cp = control.Form.CurrentPage;
+                       int retVal;
+                       if(cp >= firstPage && cp <= lastPage)
+                       {
+                               if(cp == firstPage)
+                                       retVal = 0;
+                               else
+                               {
+                                       retVal = (cp - firstPage - 1)* fullPageItemCount
+                                                + firstPageItemCount;
+                               }
+                       } else
+                       {
+                               retVal = -1;
+                       }
+                       return retVal;
+               }
        }
 }
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Link.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/Link.cs
new file mode 100644 (file)
index 0000000..ec02deb
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : Link
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System;
+using System.Collections;
+using System.Web.UI;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public class Link : MobileControl, IPostBackEventHandler
+       {
+               public Link()
+               {
+               }
+
+               void IPostBackEventHandler.RaisePostBackEvent(string argument)
+               {
+                       MobilePage.ActiveForm = MobilePage.GetForm(argument);
+               }
+
+               public override void AddLinkedForms(IList linkedForms)
+               {
+                       string url = NavigateUrl;
+                       string pref = Constants.FormIDPrefix;
+                       if(url.StartsWith(pref))
+                       {
+                               url = url.Substring(pref.Length);
+                               Form toAdd = ResolveFormReference(url);
+                               if(toAdd != null && !toAdd.HasActiveHandler())
+                                       linkedForms.Add(toAdd);
+                       }
+               }
+
+               public string NavigateUrl
+               {
+                       get
+                       {
+                               object o = ViewState["NavigateUrl"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["NavigateUrl"] = value;
+                       }
+               }
+
+               public string SoftkeyLabel
+               {
+                       get
+                       {
+                               object o = ViewState["SoftkeyLabel"];
+                               if(o != null)
+                                       return (string)o;
+                               return String.Empty;
+                       }
+                       set
+                       {
+                               ViewState["SoftkeyLabel"] = value;
+                       }
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/List.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/List.cs
new file mode 100644 (file)
index 0000000..1d7cdc8
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : List
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System.Web.UI;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public class List : PagedControl//, INamingContainer, IListControl,
+//                         ITemplateable, IPostBackEventHandler
+       {
+               public List()
+               {
+               }
+
+               protected override int InternalItemCount
+               {
+                       get
+                       {
+                               throw new NotImplementedException();
+                       }
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventArgs.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventArgs.cs
new file mode 100644 (file)
index 0000000..d2b0d2d
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : ListCommandEventArgs
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System.Web.UI.WebControls;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public class ListCommandEventArgs : CommandEventArgs
+       {
+               protected static readonly string DefaultCommand = "Default";
+
+               private object cmdSource;
+               private MobileListItem listItem;
+
+               public ListCommandEventArgs(MobileListItem item,
+                                           object commandSource)
+                                           :base(DefaultCommand, commandSource)
+               {
+                       this.listItem  = item;
+                       this.cmdSource = commandSource;
+               }
+
+               public ListCommandEventArgs(MobileListItem item,
+                       object commandSource, CommandEventArgs originalArgs)
+                       : base(originalArgs)
+               {
+                       this.cmdSource = commandSource;
+                       this.listItem  = item;
+               }
+
+               public object CommandSource
+               {
+                       get
+                       {
+                               return this.cmdSource;
+                       }
+               }
+
+               public MobileListItem ListItem
+               {
+                       get
+                       {
+                               return this.listItem;
+                       }
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventHandler.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListCommandEventHandler.cs
new file mode 100644 (file)
index 0000000..ad3e735
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : ListCommandEventHandler
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+namespace System.Web.UI.MobileControls
+{
+       public delegate void ListCommandEventHandler(object sender,
+                                                    ListCommandEventArgs e);
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventArgs.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventArgs.cs
new file mode 100644 (file)
index 0000000..2714f44
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : ListDataBindEventArgs
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public class ListDataBindEventArgs : EventArgs
+       {
+               private MobileListItem item;
+               private object         dataItem;
+
+               public ListDataBindEventArgs(MobileListItem item, object dataItem)
+               {
+                       this.item     = item;
+                       this.dataItem = dataItem;
+               }
+
+               public object DataItem
+               {
+                       get
+                       {
+                               return dataItem;
+                       }
+               }
+
+               public MobileListItem ListItem
+               {
+                       get
+                       {
+                               return item;
+                       }
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventHandler.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/ListDataBindEventHandler.cs
new file mode 100644 (file)
index 0000000..567463b
--- /dev/null
@@ -0,0 +1,18 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : ListDataBindEventHandler
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public delegate void ListDataBindEventHandler(object sender,
+                                                     ListDataBindEventArgs e);
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventArgs.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventArgs.cs
new file mode 100644 (file)
index 0000000..0c94d70
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : LoadItemsEventArgs
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+namespace System.Web.UI.MobileControls
+{
+       public class LoadItemsEventArgs : EventArgs
+       {
+               private int index;
+               private int count;
+
+               public LoadItemsEventArgs(int index, int count)
+               {
+                       this.index = index;
+                       this.count = count;
+               }
+
+               public int ItemCount
+               {
+                       get
+                       {
+                               return count;
+                       }
+               }
+
+               public int ItemIndex
+               {
+                       get
+                       {
+                               return index;
+                       }
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventHandler.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/LoadItemsEventHandler.cs
new file mode 100644 (file)
index 0000000..11caf55
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : LoadItemsEventHandler
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+namespace System.Web.UI.MobileControls
+{
+       public delegate void LoadItemsEventHandler(object sender,
+                                                LoadItemsEventArgs e);
+}
index 1f20c7b53f6bcb85dc7ae90e66328527c239402b..e2d4997c43117611f6708d68cc5bb16eeed0e62b 100644 (file)
@@ -23,5 +23,22 @@ namespace System.Web.UI.MobileControls
                {
                        throw new NotImplementedException();
                }
+
+               public Form ActiveForm
+               {
+                       get
+                       {
+                               throw new NotImplementedException();
+                       }
+                       set
+                       {
+                               throw new NotImplementedException();
+                       }
+               }
+
+               public Form GetForm(string id)
+               {
+                       throw new NotImplementedException();
+               }
        }
 }
diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/PagedControl.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls/PagedControl.cs
new file mode 100644 (file)
index 0000000..2dbdd8a
--- /dev/null
@@ -0,0 +1,103 @@
+/**
+ * Project   : Mono
+ * Namespace : System.Web.UI.MobileControls
+ * Class     : PagedControl
+ * Author    : Gaurav Vaish
+ *
+ * Copyright : 2003 with Gaurav Vaish, and with
+ *             Ximian Inc
+ */
+
+using System.Web.UI;
+using System.Web.Mobile;
+
+namespace System.Web.UI.MobileControls
+{
+       public abstract class PagedControl : MobileControl
+       {
+               private static readonly object LoadItemsEvent    = new object();
+               private static readonly object ItemDataBindEvent = new object();
+               private static readonly object ItemCommandEvent  = new object();
+
+               private int itemCount = 0;
+               private ItemPager itemPager;
+               private bool pagingCharsChanged = false;
+
+               protected PagedControl()
+               {
+               }
+
+               public event LoadItemsEventHandler LoadItems
+               {
+                       add
+                       {
+                               Events.AddHandler(LoadItemsEvent, value);
+                       }
+                       remove
+                       {
+                               Events.RemoveHandler(LoadItemsEvent, value);
+                       }
+               }
+
+               private void OnLoadItems()
+               {
+                       OnLoadItems(new LoadItemsEventArgs(PagerItemIndex, PagerItemCount));
+               }
+
+               private int PagerItemIndex
+               {
+                       get
+                       {
+                               return (itemPager == null ? 0 : itemPager.ItemIndex);
+                       }
+               }
+
+               private int PagerItemCount
+               {
+                       get
+                       {
+                               return (itemPager == null ? InternalItemCount :
+                                           itemPager.ItemCount);
+                       }
+               }
+
+               protected abstract int InternalItemCount { get; }
+
+               protected virtual void OnLoadItems(LoadItemsEventArgs e)
+               {
+                       LoadItemsEventHandler lieh = (LoadItemsEventHandler)(Events[LoadItemsEvent]);
+                       if(lieh != null)
+                               lieh(this, e);
+               }
+
+               protected override bool OnBubbleEvent(object sender, EventArgs e)
+               {
+                       if(e is ListCommandEventArgs)
+                       {
+                               OnItemCommand((ListCommandEventArgs)e);
+                               return true;
+                       }
+                       return false;
+               }
+
+               protected override void OnDataBinding(EventArgs e)
+               {
+                       base.OnDataBinding(e);
+                       throw new NotImplementedException();
+               }
+
+               protected void OnItemDataBind(ListDataBindEventArgs e)
+               {
+                       ListDataBindEventHandler ldbeh = (ListDataBindEventHandler)(Events[ItemDataBindEvent]);
+                       if(ldbeh != null)
+                               ldbeh(this, e);
+               }
+
+               protected virtual void OnItemCommand(ListCommandEventArgs e)
+               {
+                       ListCommandEventHandler lceh = (ListCommandEventHandler)(Events[ItemCommandEvent]);
+                       if(lceh != null)
+                               lceh(this, e);
+               }
+       }
+}