Author: gonzalo
Date: 2005-09-28 04:09:31 -0400 (Wed, 28 Sep 2005)
New Revision: 50932
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/ChangeLog
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
Log:
from head
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
===================================================================
---
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
2005-09-28 08:05:58 UTC (rev 50931)
+++
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
2005-09-28 08:09:31 UTC (rev 50932)
@@ -61,14 +61,7 @@
get { return bag [key] as string; }
set {
- if (0 == String.Compare (key, "style", true,
CultureInfo.InvariantCulture)) {
- CssStyle.Clear();
- if (value != null) {
- CssStyle.FillStyle (value);
- }
- key = "style"; // Needs to be always
lowercase
- }
- bag.Add (key, value);
+ Add (key, value);
}
}
@@ -79,11 +72,8 @@
public void Add (string key, string value)
{
if (0 == String.Compare (key, "style", true,
CultureInfo.InvariantCulture)) {
- CssStyle.Clear();
- if (value != null) {
- CssStyle.FillStyle (value);
- }
- key = "style"; // Needs to be always lowercase
+ CssStyle.Value = value;
+ return;
}
bag.Add (key, value);
}
Modified: branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/ChangeLog
2005-09-28 08:05:58 UTC (rev 50931)
+++ branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/ChangeLog
2005-09-28 08:09:31 UTC (rev 50932)
@@ -1,5 +1,17 @@
2005-09-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+ * AttributeCollection.cs: avoid code duplication and
+ don't add "style" to the bag, or it will overwrite the settings made
+ by CssStyleCollection.
+
+ * CssStyleCollection.cs: make it throw where MS throws.
+ Minimize the number of times we create the "style" string and take
+ care of updating it for the AttributeCollection. FillStyle and
+ BagToString are now private. One should use the 2.0 (internal in <2.0)
+ Value property.
+
+2005-09-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
* Control.cs: fix HasChildViewStates.
2005-09-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
===================================================================
---
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
2005-09-28 08:05:58 UTC (rev 50931)
+++
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
2005-09-28 08:09:31 UTC (rev 50932)
@@ -36,24 +36,22 @@
public sealed class CssStyleCollection
{
- private StateBag bag;
- private StateBag style;
+ StateBag bag;
+ StateBag style;
+ string last_string;
- internal CssStyleCollection ()
- {
- style = new StateBag ();
- }
-
internal CssStyleCollection (StateBag bag)
{
this.bag = bag;
- style = new StateBag ();
- string st_string = bag ["style"] as string;
- if (st_string != null)
- FillStyle (st_string);
+ if (bag != null) {
+ last_string = (string) bag ["style"];
+ style = new StateBag ();
+ if (last_string != null)
+ FillStyle (last_string);
+ }
}
- internal void FillStyle (string s)
+ void FillStyle (string s)
{
int mark = s.IndexOf (':');
if (mark == -1)
@@ -79,21 +77,29 @@
FillStyle (fullValue.Substring (mark + 1));
}
- internal string BagToString ()
+ string BagToString ()
{
- HtmlTextWriter writer = new HtmlTextWriter (new
StringWriter ());
- foreach (string k in style.Keys)
- writer.WriteStyleAttribute ((k as string),
(style [k] as string));
- return writer.InnerWriter.ToString ();
+ if (last_string != null)
+ return last_string;
+
+ StringBuilder sb = new StringBuilder ();
+ foreach (string key in Keys)
+ sb.AppendFormat ("{0}: {1};", key, style [key]);
+
+ last_string = sb.ToString ();
+ return last_string;
}
-
+
public int Count
{
- get { return style.Count; }
+ get {
+ if (bag == null)
+ throw new NullReferenceException ();
+ return style.Count;
+ }
}
- public string this [string key]
- {
+ public string this [string key] {
get {
return style [key] as string;
}
@@ -109,11 +115,13 @@
public void Add (string key, string value)
{
+ if (style == null)
+ style = new StateBag ();
style [key] = value;
- if (bag != null)
- bag ["style"] = BagToString ();
+ last_string = null;
+ bag ["style"] = BagToString ();
}
-
+
#if NET_2_0
public
#else
@@ -126,18 +134,18 @@
public void Clear ()
{
- if (bag != null)
- bag.Remove ("style");
- style.Clear ();
+ if (style != null)
+ style.Clear ();
+ last_string = null;
+ bag.Remove ("style");
}
public void Remove (string key)
{
- if (style [key] != null) {
+ if (style != null)
style.Remove (key);
- if (bag != null)
- bag ["style"] = BagToString ();
- }
+ last_string = null;
+ bag ["style"] = BagToString ();
}
#if NET_2_0
public string this [HtmlTextWriterStyle key] {
@@ -149,19 +157,27 @@
}
}
- public string Value {
- get { return BagToString (); }
- set {
- Clear ();
- FillStyle (value);
- }
- }
-
public void Remove (HtmlTextWriterStyle key)
{
Remove (HtmlTextWriter.StaticGetStyleName (key));
}
+
+ public
+#else
+ internal
#endif
+ string Value {
+ get { return BagToString (); }
+ set {
+ if (style != null)
+ style = new StateBag ();
+ style.Clear ();
+ last_string = value;
+ bag ["style"] = value;
+ if (value != null)
+ FillStyle (value);
+ }
+ }
}
}
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
===================================================================
---
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
2005-09-28 08:05:58 UTC (rev 50931)
+++
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
2005-09-28 08:09:31 UTC (rev 50932)
@@ -782,7 +782,10 @@
Table table = new Table ();
table.CellSpacing = CellSpacing;
table.CellPadding = CellPadding;
- table.ControlStyle.CopyFrom (ControlStyle);
+ if (ControlStyleCreated)
+ table.ControlStyle.CopyFrom (ControlStyle);
+ table.CopyBaseAttributes (this);
+ table.ID = ID;
if (ShowGridLines)
table.GridLines = GridLines.Both;
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
---
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2005-09-28 08:05:58 UTC (rev 50931)
+++
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2005-09-28 08:09:31 UTC (rev 50932)
@@ -1,8 +1,17 @@
2005-09-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+ * Style.cs: avoid unnecesary creation of a CssStyleCollection and
+ instead write the style attributes directly to the HtmlTextWriter.
+
+ * CheckBox.cs: adapted to new API.
+
* DataGrid.cs: handle null data sources. Fixed the contions that make
the table to be added to the Controls collection.
+ * Calendar.cs: the table needed an ID and the attributes from the
+ parent. Also don't create the ControlStyleCollection if it has not
+ already been created.
+
2005-09-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Calendar.cs: TrackViewState should be called upon creation, not on
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
===================================================================
---
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
2005-09-28 08:05:58 UTC (rev 50931)
+++
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
2005-09-28 08:09:31 UTC (rev 50932)
@@ -395,7 +395,7 @@
CssStyleCollection style = Attributes.CssStyle;
w.AddAttribute (HtmlTextWriterAttribute.Style,
- style.BagToString ());
+ style.Value);
w.RenderBeginTag (HtmlTextWriterTag.Span);
control_style = true;
Modified:
branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
===================================================================
--- branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
2005-09-28 08:05:58 UTC (rev 50931)
+++ branches/mono-1-1-9/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
2005-09-28 08:09:31 UTC (rev 50932)
@@ -365,12 +365,93 @@
writer.AddAttribute
(HtmlTextWriterAttribute.Class, s);
}
- CssStyleCollection attributes = new CssStyleCollection
();
- FillStyleAttributes (attributes);
- foreach (string attr in attributes.Keys)
- writer.AddStyleAttribute (attr, attributes
[attr]);
+ WriteStyleAttributes (writer);
}
-
+
+ void WriteStyleAttributes (HtmlTextWriter writer)
+ {
+ string s;
+ Color color;
+ BorderStyle bs;
+ Unit u;
+
+ if ((styles & Styles.BackColor) != 0) {
+ color = (Color)viewstate["BackColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderColor) != 0) {
+ color = (Color)viewstate["BorderColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderStyle) != 0) {
+ bs = (BorderStyle)viewstate["BorderStyle"];
+ if (bs != BorderStyle.NotSet)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.BorderStyle, bs.ToString());
+ }
+
+ if ((styles & Styles.BorderWidth) != 0) {
+ u = (Unit)viewstate["BorderWidth"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.BorderWidth, u.ToString());
+ }
+
+ if ((styles & Styles.ForeColor) != 0) {
+ color = (Color)viewstate["ForeColor"];
+ if (!color.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.Height) != 0) {
+ u = (Unit)viewstate["Height"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.Height, u.ToString());
+ }
+
+ if ((styles & Styles.Width) != 0) {
+ u = (Unit)viewstate["Width"];
+ if (!u.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.Width, u.ToString());
+ }
+
+ if (fontinfo != null) {
+ // Fonts are a bit weird
+ if (fontinfo.Name != string.Empty) {
+ s = fontinfo.Names[0];
+ for (int i = 1; i <
fontinfo.Names.Length; i++)
+ s += "," + fontinfo.Names[i];
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.FontFamily, s);
+ }
+
+ if (fontinfo.Bold)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.FontWeight, "bold");
+
+ if (fontinfo.Italic)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.FontStyle, "italic");
+
+ if (!fontinfo.Size.IsEmpty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
+
+ // These styles are munged into a attribute
decoration
+ s = string.Empty;
+
+ if (fontinfo.Overline)
+ s += "overline ";
+
+ if (fontinfo.Strikeout)
+ s += "line-through ";
+
+ if (fontinfo.Underline)
+ s += "underline ";
+
+ if (s != string.Empty)
+ writer.AddStyleAttribute
(HtmlTextWriterStyle.TextDecoration, s);
+ }
+ }
+
void FillStyleAttributes (CssStyleCollection attributes)
{
string s;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches