Explorar el Código

In System.Web.UI:
2006-03-02 Chris Toshok <[email protected]>

* Control.cs (ApplyStyleSheetTheme): remove the exception, and add
a MonoTODO.

* Page.cs (Theme): implement setter/getter.
(StyleSheetTheme): same.

* PageParser.cs (ProcessMainAttributes): parse the Theme and
StyleSheetTheme attributes.

In System.Web.UI.WebControls:
2006-03-02 Chris Toshok <[email protected]>

* WebControl.cs (SkinID): implement setter/getter, and have them
just chain up to base.SkinID.

In System.Web.Compilation:
2006-03-02 Chris Toshok <[email protected]>

* TemplateControlCompiler.cs (InitMethod): emit an assignment for
SkinID just after the creation of our object, and right after that
call "_ctrl.ApplyStyleSheetSkin (page)".
(CreateAssignStatementsFromAttributes): split out the majority of
this code to CreateAssignStatementFromAttribute, and change this
method to simply a loop over the attribute keys. In the 2.0 case,
skip the SkinID property, since that's handled explicitly in
InitMethod.

* PageCompiler.cs (AddStatementsToInitMethod): emit assignments
for Theme and StyleSheetTheme.


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

Chris Toshok hace 20 años
padre
commit
9cd26e2c03

+ 14 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,17 @@
+2006-03-02  Chris Toshok  <[email protected]>
+
+	* TemplateControlCompiler.cs (InitMethod): emit an assignment for
+	SkinID just after the creation of our object, and right after that
+	call "_ctrl.ApplyStyleSheetSkin (page)".
+	(CreateAssignStatementsFromAttributes): split out the majority of
+	this code to CreateAssignStatementFromAttribute, and change this
+	method to simply a loop over the attribute keys.  In the 2.0 case,
+	skip the SkinID property, since that's handled explicitly in
+	InitMethod.
+
+	* PageCompiler.cs (AddStatementsToInitMethod): emit assignments
+	for Theme and StyleSheetTheme.
+
 2006-02-23  Chris Toshok  <[email protected]>
 
 	* TemplateControlCompiler.cs (AddContentTemplateInvocation): track

+ 6 - 0
mcs/class/System.Web/System.Web.Compilation/PageCompiler.cs

@@ -108,6 +108,12 @@ namespace System.Web.Compilation
 
 			if (pageParser.MasterPageFile != null)
 				method.Statements.Add (CreatePropertyAssign (ctrlVar, "MasterPageFile", pageParser.MasterPageFile));
+
+			if (pageParser.Theme != null)
+				method.Statements.Add (CreatePropertyAssign (ctrlVar, "Theme", pageParser.Theme));
+
+			if (pageParser.StyleSheetTheme != null)
+				method.Statements.Add (CreatePropertyAssign (ctrlVar, "StyleSheetTheme", pageParser.StyleSheetTheme));
 #endif
 		}
 

+ 94 - 64
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -190,6 +190,8 @@ namespace System.Web.Compilation
 				if (typeof (Control).IsAssignableFrom (type))
 					method.ReturnType = new CodeTypeReference (typeof (Control));
 
+				// _ctrl = new $controlType ($parameters);
+				//
 				CodeObjectCreateExpression newExpr = new CodeObjectCreateExpression (type);
 
 				object [] atts = type.GetCustomAttributes (typeof (ConstructorNeedsTagAttribute), true);
@@ -208,6 +210,8 @@ namespace System.Web.Compilation
 				assign.Right = newExpr;
 				method.Statements.Add (assign);
 				
+				// this.$builderID = _ctrl;
+				//
 				CodeFieldReferenceExpression builderID = new CodeFieldReferenceExpression ();
 				builderID.TargetObject = thisRef;
 				builderID.FieldName = builder.ID;
@@ -223,8 +227,32 @@ namespace System.Web.Compilation
 					initAsControl.Parameters.Add (new CodePropertyReferenceExpression (thisRef, "Page"));
 					method.Statements.Add (initAsControl);
 				}
+
+#if NET_2_0
+				// _ctrl.SkinID = $value
+				// _ctrl.ApplyStyleSheetSkin (this);
+				//
+				// the SkinID assignment needs to come
+				// before the call to
+				// ApplyStyleSheetSkin, for obvious
+				// reasons.  We skip SkinID in
+				// CreateAssignStatementsFromAttributes
+				// below.
+				// 
+				if (builder.attribs != null) {
+					string skinid = builder.attribs ["skinid"] as string;
+					if (skinid != null)
+						CreateAssignStatementFromAttribute (builder, "skinid");
+				}
+				if (typeof (WebControl).IsAssignableFrom (type)) {
+					CodeMethodInvokeExpression applyStyleSheetSkin = new CodeMethodInvokeExpression (ctrlVar, "ApplyStyleSheetSkin");
+					applyStyleSheetSkin.Parameters.Add (thisRef);
+					method.Statements.Add (applyStyleSheetSkin);
+				}
+#endif
+
 #if NET_2_0
-				if (typeof (System.Web.UI.WebControls.ContentPlaceHolder).IsAssignableFrom (type)) {
+				if (typeof (ContentPlaceHolder).IsAssignableFrom (type)) {
 					CodePropertyReferenceExpression prop = new CodePropertyReferenceExpression (thisRef, "ContentPlaceHolders");
 					CodeMethodInvokeExpression addPlaceholder = new CodeMethodInvokeExpression (prop, "Add");
 					addPlaceholder.Parameters.Add (ctrlVar);
@@ -520,6 +548,66 @@ namespace System.Web.Compilation
 			method.Statements.Add (attach);
 		}
 		
+		void CreateAssignStatementFromAttribute (ControlBuilder builder, string id)
+		{
+			EventInfo [] ev_info = null;
+			Type type = builder.ControlType;
+
+			string attvalue = builder.attribs [id] as string;
+			if (id.Length > 2 && id.Substring (0, 2).ToUpper () == "ON"){
+				if (ev_info == null)
+					ev_info = type.GetEvents ();
+
+				string id_as_event = id.Substring (2);
+				foreach (EventInfo ev in ev_info){
+					if (InvariantCompareNoCase (ev.Name, id_as_event)){
+						AddEventAssign (builder.method,
+								ev.Name,
+								ev.EventHandlerType,
+								attvalue);
+						
+						return;
+					}
+				}
+
+			}
+
+			int hyphen = id.IndexOf ('-');
+			string alt_id = id;
+			if (hyphen != -1)
+				alt_id = id.Substring (0, hyphen);
+
+			MemberInfo fop = GetFieldOrProperty (type, alt_id);
+			if (fop != null) {
+				if (ProcessPropertiesAndFields (builder, fop, id, attvalue, null))
+					return;
+			}
+
+			if (!typeof (IAttributeAccessor).IsAssignableFrom (type))
+				throw new ParseException (builder.location, "Unrecognized attribute: " + id);
+
+			string val;
+			CodeMemberMethod method = builder.method;
+			bool databound = IsDataBound (attvalue);
+			if (databound) {
+				val = attvalue.Substring (3);
+				val = val.Substring (0, val.Length - 2);
+				CreateDBAttributeMethod (builder, id, val);
+			} else {
+				CodeCastExpression cast;
+				CodeMethodReferenceExpression methodExpr;
+				CodeMethodInvokeExpression expr;
+
+				cast = new CodeCastExpression (typeof (IAttributeAccessor), ctrlVar);
+				methodExpr = new CodeMethodReferenceExpression (cast, "SetAttribute");
+				expr = new CodeMethodInvokeExpression (methodExpr);
+				expr.Parameters.Add (new CodePrimitiveExpression (id));
+				expr.Parameters.Add (new CodePrimitiveExpression (attvalue));
+				method.Statements.Add (expr);
+			}
+
+		}
+
 		void CreateAssignStatementsFromAttributes (ControlBuilder builder)
 		{
 			this.dataBoundAtts = 0;
@@ -527,75 +615,17 @@ namespace System.Web.Compilation
 			if (atts == null || atts.Count == 0)
 				return;
 
-			EventInfo [] ev_info = null;
-			bool is_processed = false;
-			Type type = builder.ControlType;
-
 			foreach (string id in atts.Keys) {
 				if (InvariantCompareNoCase (id, "runat"))
 					continue;
 
-				is_processed = false;
-				string attvalue = atts [id] as string;
-				if (id.Length > 2 && id.Substring (0, 2).ToUpper () == "ON"){
-					if (ev_info == null)
-						ev_info = type.GetEvents ();
-
-					string id_as_event = id.Substring (2);
-					foreach (EventInfo ev in ev_info){
-						if (InvariantCompareNoCase (ev.Name, id_as_event)){
-							AddEventAssign (builder.method,
-									ev.Name,
-									ev.EventHandlerType,
-									attvalue);
-
-							is_processed = true;
-							break;
-						}
-					}
-
-					if (is_processed)
-						continue;
-				} 
-
-				int hyphen = id.IndexOf ('-');
-				string alt_id = id;
-				if (hyphen != -1)
-					alt_id = id.Substring (0, hyphen);
-
-				MemberInfo fop = GetFieldOrProperty (type, alt_id);
-				if (fop != null) {
-					is_processed = ProcessPropertiesAndFields (builder, fop, id, attvalue, null);
-					if (is_processed)
-						continue;
-				}
-
-				if (is_processed)
+#if NET_2_0
+				/* we skip SkinID here as it's assigned in BuildControlTree */
+				if (InvariantCompareNoCase (id, "skinid"))
 					continue;
+#endif
+				CreateAssignStatementFromAttribute (builder, id);
 
-				if (!typeof (IAttributeAccessor).IsAssignableFrom (type))
-					throw new ParseException (builder.location, "Unrecognized attribute: " + id);
-
-
-				CodeMemberMethod method = builder.method;
-				string val = (string) atts [id];
-				bool databound = IsDataBound (val);
-				if (databound) {
-					val = val.Substring (3);
-					val = val.Substring (0, val.Length - 2);
-					CreateDBAttributeMethod (builder, id, val);
-				} else {
-					CodeCastExpression cast;
-					CodeMethodReferenceExpression methodExpr;
-					CodeMethodInvokeExpression expr;
-
-					cast = new CodeCastExpression (typeof (IAttributeAccessor), ctrlVar);
-					methodExpr = new CodeMethodReferenceExpression (cast, "SetAttribute");
-					expr = new CodeMethodInvokeExpression (methodExpr);
-					expr.Parameters.Add (new CodePrimitiveExpression (id));
-					expr.Parameters.Add (new CodePrimitiveExpression ((string) atts [id]));
-					method.Statements.Add (expr);
-				}
 			}
 		}
 

+ 5 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,8 @@
+2006-03-02  Chris Toshok  <[email protected]>
+
+	* WebControl.cs (SkinID): implement setter/getter, and have them
+	just chain up to base.SkinID.
+
 2006-02-27  Chris Toshok  <[email protected]>
 
 	* SqlDataSource.cs: track change to DataSourceControl's protected

+ 2 - 6
mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs

@@ -327,12 +327,8 @@ namespace System.Web.UI.WebControls {
 		[MonoTODO]
 		public virtual new string SkinID
 		{
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				throw new NotImplementedException ();
-			}
+			get { return base.SkinID; }
+			set { base.SkinID = value; }
 		}
 #endif		
 		

+ 11 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,14 @@
+2006-03-02  Chris Toshok  <[email protected]>
+
+	* Control.cs (ApplyStyleSheetTheme): remove the exception, and add
+	a MonoTODO.
+
+	* Page.cs (Theme): implement setter/getter.
+	(StyleSheetTheme): same.
+	
+	* PageParser.cs (ProcessMainAttributes): parse the Theme and
+	StyleSheetTheme attributes.
+
 2006-02-27  Chris Toshok  <[email protected]>
 
 	* TemplateControl.cs: corcompare work.

+ 1 - 1
mcs/class/System.Web/System.Web.UI/Control.cs

@@ -591,10 +591,10 @@ namespace System.Web.UI
                 }
 
 #if NET_2_0
+		[MonoTODO]
 		[EditorBrowsable (EditorBrowsableState.Advanced)]
 		public virtual void ApplyStyleSheetSkin (Page page)
 		{
-			throw new NotImplementedException ();
 		}
 #endif		
 

+ 6 - 6
mcs/class/System.Web/System.Web.UI/Page.cs

@@ -128,6 +128,8 @@ public class Page : TemplateControl, IHttpHandler
 	HtmlForm _form;
 
 	string _title;
+	string _theme;
+	string _styleSheetTheme;
 #endif
 
 	#region Constructor
@@ -454,21 +456,19 @@ public class Page : TemplateControl, IHttpHandler
 	}
 
 #if NET_2_0
-	[MonoTODO]
 	[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 	[Filterable (false)]
 	[Browsable (false)]
 	public virtual string StyleSheetTheme {
-		get { throw new NotImplementedException (); }
-		set { throw new NotImplementedException (); }
+		get { return _styleSheetTheme; }
+		set { _styleSheetTheme = value; }
 	}
 
-	[MonoTODO]
 	[Browsable (false)]
 	[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 	public virtual string Theme {
-		get { throw new NotImplementedException (); }
-		set { throw new NotImplementedException (); }
+		get { return _theme; }
+		set { _theme = value; }
 	}
 #endif
 

+ 13 - 0
mcs/class/System.Web/System.Web.UI/PageParser.cs

@@ -64,6 +64,8 @@ namespace System.Web.UI
 		string masterPage;
 		Type masterType;
 		string title;
+		string theme;
+		string styleSheetTheme;
 #endif
 
 		public PageParser ()
@@ -281,6 +283,9 @@ namespace System.Web.UI
 				MasterPageParser.GetCompiledMasterType (masterPage, MapPath (masterPage), HttpContext.Current);
 
 			title = GetString(atts, "Title", null);
+
+			theme = GetString (atts, "Theme", null);
+			styleSheetTheme = GetString (atts, "StyleSheetTheme", null);
 #endif
 			// Ignored by now
 			GetString (atts, "EnableViewStateMac", null);
@@ -401,6 +406,14 @@ namespace System.Web.UI
 		}
 
 #if NET_2_0
+		internal string Theme {
+			get { return theme; }
+		}
+
+		internal string StyleSheetTheme {
+			get { return styleSheetTheme; }
+		}
+
 		internal string MasterPageFile {
 			get { return masterPage; }
 		}