Author: gonzalo
Date: 2005-09-28 04:05:58 -0400 (Wed, 28 Sep 2005)
New Revision: 50931
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
trunk/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
trunk/mcs/class/System.Web/System.Web_test.dll.sources
Log:
2005-09-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* System.Web_test.dll.sources: add new test.
* System.Web.UI/AttributeCollection.cs: avoid code duplication and
don't add "style" to the bag, or it will overwrite the settings made
by CssStyleCollection.
* System.Web.UI/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.
* System.Web.UI.WebControls/Style.cs: avoid unnecesary creation of a
CssStyleCollection and instead write the style attributes directly to
the HtmlTextWriter.
* System.Web.UI.WebControls/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.
* System.Web.UI.WebControls/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.
Modified: trunk/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -62,14 +62,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);
}
}
@@ -80,11 +73,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: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2005-09-28 08:00:26 UTC
(rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2005-09-28 08:05:58 UTC
(rev 50931)
@@ -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: trunk/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -39,24 +39,22 @@
[AspNetHostingPermission (SecurityAction.LinkDemand, Level =
AspNetHostingPermissionLevel.Minimal)]
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)
@@ -82,21 +80,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;
}
@@ -112,11 +118,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
@@ -129,18 +137,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] {
@@ -152,19 +160,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: trunk/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -788,7 +788,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: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2005-09-28 08:05:58 UTC (rev 50931)
@@ -1,3 +1,22 @@
+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-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * DataGrid.cs: handle null data sources. Fixed the contions that make
+ the table to be added to the Controls collection.
+
2005-09-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Calendar.cs: TrackViewState should be called upon creation, not on
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -400,7 +400,7 @@
CssStyleCollection style = Attributes.CssStyle;
w.AddAttribute (HtmlTextWriterAttribute.Style,
- style.BagToString ());
+ style.Value);
w.RenderBeginTag (HtmlTextWriterTag.Span);
control_style = true;
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -3,6 +3,7 @@
//
// Authors:
// Jackson Harper ([EMAIL PROTECTED])
+// Gonzalo Paniagua Javier ([EMAIL PROTECTED])
//
// (C) 2005 Novell, Inc (http://www.novell.com)
//
@@ -474,8 +475,8 @@
Type ds_type = data_source.GetType ();
PropertyInfo pinfo = ds_type.GetProperty ("Item",
item_args);
if (pinfo == null) {
- IEnumerator items = data_source.GetEnumerator
();
- if (items.MoveNext ()) {
+ IEnumerator items = (data_source.DataSource !=
null) ? data_source.GetEnumerator () : null;
+ if (items != null && items.MoveNext ()) {
object data = items.Current;
if (data is ICustomTypeDescriptor)
props =
TypeDescriptor.GetProperties (data);
@@ -848,6 +849,12 @@
pds.VirtualCount = VirtualItemCount;
CreateRenderColumns (paged_data_source, useDataSource);
+ if (useDataSource) {
+ if (DataSource != null)
+ Controls.Add (RenderTable);
+ } else {
+ Controls.Add (RenderTable);
+ }
if (pds.IsPagingEnabled)
CreateItem (-1, -1, ListItemType.Pager, false,
null, pds);
@@ -865,22 +872,23 @@
// replaced when creating bound columns
enumerator = data_enumerator;
skip_first = true;
+ } else if (pds.DataSource != null) {
+ enumerator = pds.GetEnumerator ();
} else {
- enumerator = pds.GetEnumerator ();
+ enumerator = null;
}
int index = 0;
bool first = true;
string key = null;
- while (skip_first || enumerator.MoveNext ()) {
+ while (enumerator != null && (skip_first ||
enumerator.MoveNext ())) {
// MS does not render <table blah></table> on
empty datasource.
if (first) {
- Controls.Add (RenderTable);
first = false;
key = DataKeyField;
+ skip_first = false;
}
object data = enumerator.Current;
- skip_first = false;
// This will throw if the DataKeyField is not
there. As on MS, this
// will not be hit on an empty datasource.
// The values stored here can be used in events
so that you can
@@ -933,11 +941,12 @@
protected override void PrepareControlHierarchy ()
{
- if (render_table == null)
- return;
+ if (!HasControls () || Controls.Count == 0)
+ return; // No one called
CreateControlHierarchy() with DataSource != null
- render_table.CopyBaseAttributes (this);
- render_table.ApplyStyle (ControlStyle);
+ Table rt = render_table;
+ rt.CopyBaseAttributes (this);
+ rt.ApplyStyle (ControlStyle);
bool top_pager = true;
Style alt = null;
@@ -949,7 +958,7 @@
alt = item_style;
}
- foreach (DataGridItem item in render_table.Rows) {
+ foreach (DataGridItem item in rt.Rows) {
switch (item.ItemType) {
case ListItemType.Item:
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
2005-09-28 08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
2005-09-28 08:05:58 UTC (rev 50931)
@@ -394,12 +394,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;
Modified: trunk/mcs/class/System.Web/System.Web_test.dll.sources
===================================================================
--- trunk/mcs/class/System.Web/System.Web_test.dll.sources 2005-09-28
08:00:26 UTC (rev 50930)
+++ trunk/mcs/class/System.Web/System.Web_test.dll.sources 2005-09-28
08:05:58 UTC (rev 50931)
@@ -19,6 +19,7 @@
System.Web.Security/MembershipUserCollectionTest.cs
System.Web.Security/RolePrincipalTest.cs
System.Web.Security/RolesTest.cs
+System.Web.UI/AttributeCollectionTest.cs
System.Web.UI/CleanHtmlTextWriter.cs
System.Web.UI/ControlTest.cs
System.Web.UI/DataBindingCollectionTest.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches