ChangeLog: Updated.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableStyle.cs
index 0805738ac9e1fc5f5320e0d3f8ca56c29ed3fb3f..a1653a11928f558c0b48c0cdf60c732b31be625c 100644 (file)
@@ -1,17 +1,38 @@
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class:     TableStyle\r
- *\r
- * Author:  Gaurav Vaish\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
- * Implementation: yes\r
- * Status:  100%\r
- *\r
- * (C) Gaurav Vaish (2002)\r
- */\r
+//
+// System.Web.UI.WebControls.TableStyle.cs
+//
+// Authors:
+//   Gaurav Vaish (gvaish@iitk.ac.in)
+//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (C) Gaurav Vaish (2002)
+// (C) 2003 Andreas Nahr
+//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 \r
-using System;\r
+using System;
+using System.ComponentModel;\r
+using System.Globalization;\r
 using System.Web;\r
 using System.Web.UI;\r
 \r
@@ -32,7 +53,9 @@ namespace System.Web.UI.WebControls
                public TableStyle(StateBag bag): base(bag)\r
                {\r
                }\r
-\r
+
+               [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
+               [WebSysDescription ("An Url specifying the background image for the table.")]\r
                public virtual string BackImageUrl\r
                {\r
                        get\r
@@ -44,12 +67,14 @@ namespace System.Web.UI.WebControls
                        set\r
                        {\r
                                if(value == null)\r
-                                       throw new ArgumentNullException("BackImageUrl");\r
+                                       throw new ArgumentNullException("value");\r
                                ViewState["BackImageUrl"] = value;\r
                                Set(IMAGE_URL);\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
+               [WebSysDescription ("The space left around the borders within a cell.")]\r
                public virtual int CellPadding\r
                {\r
                        get\r
@@ -61,12 +86,14 @@ namespace System.Web.UI.WebControls
                        set\r
                        {\r
                                if(value < -1)\r
-                                       throw new ArgumentOutOfRangeException("CellPadding");\r
+                                       throw new ArgumentOutOfRangeException("value", "CellPadding value has to be -1 for 'not set' or a value >= 0");\r
                                ViewState["CellPadding"] = value;\r
                                Set(CELL_PADD);\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
+               [WebSysDescription ("The space left between cells.")]\r
                public virtual int CellSpacing\r
                {\r
                        get\r
@@ -78,41 +105,45 @@ namespace System.Web.UI.WebControls
                        set\r
                        {\r
                                if(value < -1)\r
-                                       throw new ArgumentOutOfRangeException("CellSpacing");\r
+                                       throw new ArgumentOutOfRangeException("value"," CellSpacing value has to be -1 for 'not set' or a value >= 0");\r
                                ViewState["CellSpacing"] = value;\r
                                Set(CELL_SPAC);\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (typeof (GridLines), "None"), Bindable (true), WebCategory ("Appearance")]
+               [WebSysDescription ("The type of grid that a table uses.")]\r
                public virtual GridLines GridLines\r
                {\r
                        get\r
                        {\r
                                if(IsSet(GRID_LINE))\r
-                                       return (string)(ViewState["GridLines"]);\r
-                               return GridLines.Both;\r
+                                       return (GridLines)(ViewState["GridLines"]);\r
+                               return GridLines.None;\r
                        }\r
                        set\r
                        {\r
                                if(!Enum.IsDefined(typeof(GridLines), value))\r
-                                       throw new ArgumentException();\r
+                                       throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");\r
                                ViewState["GridLines"] = value;\r
                                Set(GRID_LINE);\r
                        }\r
                }\r
-\r
+
+               [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
+               [WebSysDescription ("The horizonal alignment of the table.")]\r
                public virtual HorizontalAlign HorizontalAlign\r
                {\r
                        get\r
                        {\r
                                if(IsSet(HOR_ALIGN))\r
-                                       return (string)(ViewState["HorizontalAlign"]);\r
+                                       return (HorizontalAlign)(ViewState["HorizontalAlign"]);\r
                                return HorizontalAlign.NotSet;\r
                        }\r
                        set\r
                        {\r
                                if(!Enum.IsDefined(typeof(HorizontalAlign), value))\r
-                                       throw new ArgumentException();\r
+                                       throw new ArgumentOutOfRangeException("value"," Gridlines value has to be a valid enumeration member");\r
                                ViewState["HorizontalAlign"] = value;\r
                                Set(HOR_ALIGN);\r
                        }\r
@@ -123,11 +154,14 @@ namespace System.Web.UI.WebControls
                        base.AddAttributesToRender(writer, owner);\r
                        if(BackImageUrl.Length > 0)\r
                        {\r
-                               writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + ResolveUrl(BackImageUrl) + ")");\r
+                               writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + owner.ResolveUrl(BackImageUrl) + ")");\r
                        }\r
                        if(CellSpacing >= 0)\r
                        {\r
                                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, CellSpacing.ToString(NumberFormatInfo.InvariantInfo));\r
+                               if(CellSpacing == 0)
+                                       writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse");
+                               
                        }\r
                        if(CellPadding >= 0)\r
                        {\r
@@ -137,73 +171,79 @@ namespace System.Web.UI.WebControls
                        {\r
                                writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(HorizontalAlign), HorizontalAlign, "G"));\r
                        }\r
-                       string gd = "";\r
+                       string gd = null;
                        switch(GridLines)\r
                        {\r
-                               case GridLines.None:       gd = "";\r
-                                                          break;\r
-                               case GridLines.Horizontal: gd = "cols";\r
+                               case GridLines.None:       break;
+                               case GridLines.Horizontal: gd = "rows";\r
                                                           break;\r
-                               case GridLines.Vertical:   gd = "rows";\r
+                               case GridLines.Vertical:   gd = "cols";\r
                                                           break;\r
                                case GridLines.Both:       gd = "all";\r
                                                           break;\r
-                       }\r
-                       writer.AddAttribute(HtmlTextWriterAttribute.Rules, gd);\r
-               }\r
-\r
-               public override void CopyFrom(Style s)\r
-               {\r
-                       if(s != null && s is TableStyle && !s.IsEmpty)\r
-                       {\r
-                               base.CopyFrom(s);\r
-                               TableStyle from = (TableStyle)s;\r
-                               if(from.IsSet(HOR_ALIGN))\r
-                               {\r
-                                       HorizontalAlign = from.HorizontalAlign;\r
-                               }\r
-                               if(from.IsSet(IMAGE_URL))\r
-                               {\r
-                                       BackImageUrl = from.BackImageUrl;\r
-                               }\r
-                               if(from.IsSet(CELL_PADD))\r
-                               {\r
-                                       CellPadding = from.CellPadding;\r
-                               }\r
-                               if(from.IsSet(CELL_SPAC))\r
-                               {\r
-                                       CellSpacing = from.CellSpacing;\r
-                               }\r
-                               if(from.IsSet(GRID_LINE))\r
-                               {\r
-                                       GridLines = from.GridLines;\r
-                               }\r
-                       }\r
-               }\r
-\r
+                       }
+
+                       if (gd != null)
+                               writer.AddAttribute(HtmlTextWriterAttribute.Rules, gd);
+               }
+
+               public override void CopyFrom(Style s)
+               {
+                       if (s == null || s.IsEmpty)
+                               return;
+
+                       base.CopyFrom (s);
+                       TableStyle from = s as TableStyle;
+                       if (from == null)
+                               return;
+
+                       if (from.IsSet (HOR_ALIGN))
+                               HorizontalAlign = from.HorizontalAlign;
+
+                       if (from.IsSet (IMAGE_URL))
+                               BackImageUrl = from.BackImageUrl;
+
+                       if (from.IsSet (CELL_PADD))
+                               CellPadding = from.CellPadding;
+
+                       if (from.IsSet (CELL_SPAC))
+                               CellSpacing = from.CellSpacing;
+
+                       if (from.IsSet (GRID_LINE))
+                               GridLines = from.GridLines;
+               }
+
                public override void MergeWith(Style s)\r
                {\r
-                       if(s != null && s is TableStyle && !s.IsEmpty)\r
+                       if(s != null && !s.IsEmpty)\r
                        {\r
+                               if (IsEmpty) {
+                                       CopyFrom (s);
+                                       return;
+                               }
                                base.MergeWith(s);\r
+
+                               if (!(s is TableStyle))
+                                       return;
+                               
                                TableStyle with = (TableStyle)s;\r
-                               if(with.IsSet(HOR_ALIGN) && IsSet(HOR_ALIGN))\r
+                               if(with.IsSet(HOR_ALIGN) && !IsSet(HOR_ALIGN))\r
                                {\r
                                        HorizontalAlign = with.HorizontalAlign;\r
                                }\r
-                               if(with.IsSet(IMAGE_URL) && IsSet(IMAGE_URL))\r
+                               if(with.IsSet(IMAGE_URL) && !IsSet(IMAGE_URL))\r
                                {\r
                                        BackImageUrl = with.BackImageUrl;\r
                                }\r
-                               if(with.IsSet(CELL_PADD) && IsSet(CELLL_PADD))\r
+                               if(with.IsSet(CELL_PADD) && !IsSet(CELL_PADD))\r
                                {\r
                                        CellPadding = with.CellPadding;\r
                                }\r
-                               if(with.IsSet(CELL_SPAC) && IsSet(CELL_SPAC))\r
+                               if(with.IsSet(CELL_SPAC) && !IsSet(CELL_SPAC))\r
                                {\r
                                        CellSpacing = with.CellSpacing;\r
                                }\r
-                               if(with.IsSet(GRID_LINE) && IsSet(GRID_LINE))\r
+                               if(with.IsSet(GRID_LINE) && !IsSet(GRID_LINE))\r
                                {\r
                                        GridLines = with.GridLines;\r
                                }\r