Author: iainmc
Date: 2005-07-03 08:57:28 -0400 (Sun, 03 Jul 2005)
New Revision: 46889

Modified:
   trunk/mcs/class/PresentationFramework/ChangeLog
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
   trunk/mcs/tools/xamlc/ChangeLog
   trunk/mcs/tools/xamlc/demo/Makefile
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
   trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
   trunk/mcs/tools/xamlc/demo/test.xaml
Log:
2005-07-03  Iain McCoy  <[EMAIL PROTECTED]>
        * demo/Makefile: made more useful - just do "make run" and it should
        all happen
        * demo/test.xaml: added Code section, which I think should make this
        thing a complete, if small, program
        * demo/TestVocab/*: some small bugfixes, with a little bit of
        craziness to work around the slightly bogus stuff in DependencyObject
        at the moment.

        * Mono.Windows.Serialization/XamlParser.cs: added support for Code
        elements, provide fully qualified name of type to attach to, skip
        xmns: attributes when processing,
        * Mono.Windows.Serialization/XamlWriter.cs: added WriteCode member,
        ordered methods by type of thing dealt with
        * Mono.Windows.Serialization/CodeWriter.cs: added support for Code
        elements, call empty constructor for objects, call TypeConverter
        almost correctly.



Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-03 09:31:25 UTC 
(rev 46888)
+++ trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-03 12:57:28 UTC 
(rev 46889)
@@ -1,5 +1,16 @@
 2005-07-03  Iain McCoy  <[EMAIL PROTECTED]>
 
+       * Mono.Windows.Serialization/XamlParser.cs: added support for Code
+       elements, provide fully qualified name of type to attach to, skip
+       xmns: attributes when processing, 
+       * Mono.Windows.Serialization/XamlWriter.cs: added WriteCode member,
+       ordered methods by type of thing dealt with
+       * Mono.Windows.Serialization/CodeWriter.cs: added support for Code
+       elements, call empty constructor for objects, call TypeConverter
+       almost correctly.
+
+2005-07-03  Iain McCoy  <[EMAIL PROTECTED]>
+
        * Mono.Windows.Serialization/CodeWriter.cs: use CodeDom to do code
        generation
        * Mono.Windows.Serialization/CodeWriter.cs:

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-03 09:31:25 UTC (rev 46888)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-03 12:57:28 UTC (rev 46889)
@@ -40,6 +40,7 @@
                int tempIndex = 0;
 
                CodeCompileUnit code;
+               CodeTypeDeclaration type;
                CodeConstructor constructor;
                
                // pushes: the code writer
@@ -65,7 +66,7 @@
                        CodeNamespace ns = new CodeNamespace(clrNamespace);
                        ((CodeCompileUnit)objects[0]).Namespaces.Add(ns);
 
-                       CodeTypeDeclaration type = new 
CodeTypeDeclaration(className);
+                       type = new CodeTypeDeclaration(className);
                        type.BaseTypes.Add(new CodeTypeReference(parent));
                        constructor = new CodeConstructor();
                        type.Members.Add(constructor);
@@ -93,7 +94,9 @@
                        }
 
                        CodeVariableDeclarationStatement declaration = 
-                                       new 
CodeVariableDeclarationStatement(type, varName);
+                                       new 
CodeVariableDeclarationStatement(type, 
+                                                       varName,
+                                                       new 
CodeObjectCreateExpression(type));
                        CodeVariableReferenceExpression varRef = new 
CodeVariableReferenceExpression(varName);
                        CodeMethodInvokeExpression addChild = new 
CodeMethodInvokeExpression(
                                        (CodeExpression)objects[objects.Count - 
1],
@@ -119,8 +122,8 @@
                //   the property, and a reference to an object
                public void CreateAttachedProperty(string attachedTo, string 
propertyName, string typeName)
                {
-                       // need to:
                        Type t = Type.GetType(typeName);
+                       Type typeAttachedTo = Type.GetType(attachedTo);
 
                        string name = "temp";
                        if (tempIndex != 0)
@@ -130,7 +133,7 @@
 
 
                        CodeMethodInvokeExpression call = new 
CodeMethodInvokeExpression(
-                                       new 
CodeVariableReferenceExpression(attachedTo),
+                                       new 
CodeTypeReferenceExpression(typeAttachedTo),
                                        "Set" + propertyName,
                                        (CodeExpression)objects[objects.Count - 
1],
                                        new 
CodeVariableReferenceExpression(name));
@@ -169,10 +172,12 @@
                        CodeExpression expr = new CodePrimitiveExpression(text);
                        if (converter != null) {
                                Type t = Type.GetType(converter);
-                               expr = new CodeMethodInvokeExpression(
-                                               new 
CodeTypeReferenceExpression(t),
-                                               "ConvertFromString",
-                                               expr);
+                               expr = new CodeCastExpression(
+                                               new 
CodeTypeReference(typeof(int)),
+                                               new CodeMethodInvokeExpression(
+                                                               new 
CodeObjectCreateExpression(t),
+                                                               
"ConvertFromString",
+                                                               expr));
                        }
                        CodeAssignStatement assignment = new 
CodeAssignStatement(
                                        (CodeExpression)objects[objects.Count - 
1],
@@ -197,5 +202,10 @@
                        generator.GenerateCodeFromCompileUnit(code, writer, 
null);
                        writer.Close();
                }
+
+               public void CreateCode(string code)
+               {
+                       type.Members.Add(new CodeSnippetTypeMember(code));
+               }
        }
 }

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-03 09:31:25 UTC (rev 46888)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-03 12:57:28 UTC (rev 46889)
@@ -41,7 +41,10 @@
                private XmlReader reader;
                private XamlWriter writer;
 
-               private enum CurrentType { Object, Property, AttachedProperty }
+               private enum CurrentType { Object, 
+                       Property, 
+                       AttachedProperty,
+                       Code }
 
                private class ParserState {
                        public object obj;
@@ -60,6 +63,18 @@
                public void Parse()
                {
                        while (reader.Read()) {
+                               if (currentState != null &&
+                                               currentState.type == 
CurrentType.Code)
+                               {
+                                       if (reader.NodeType == 
XmlNodeType.EndElement &&
+                                                       reader.LocalName == 
"Code" && 
+                                                       reader.NamespaceURI == 
XAML_NAMESPACE) {
+                                               parseEndElement();
+                                       } else {
+                                               currentState.obj = 
(string)currentState.obj + reader.Value;
+                                       }
+                                       continue;
+                               }
                                switch (reader.NodeType) {
                                case XmlNodeType.ProcessingInstruction:
                                        parsePI();
@@ -92,6 +107,10 @@
 
                void parseElement()
                {
+                       if (reader.LocalName == "Code" && reader.NamespaceURI 
== XAML_NAMESPACE) {
+                               parseCodeElement();
+                               return;
+                       }
                        // This element must be an object if:
                        //  - It's a direct child of a property element
                        //  - It's a direct child of an IAddChild element
@@ -129,6 +148,14 @@
                        return false;
                }
 
+               void parseCodeElement()
+               {
+                       oldStates.Add(currentState);
+                       currentState = new ParserState();
+                       currentState.type = CurrentType.Code;
+                       currentState.obj = "";
+               }
+
                void parseText()
                {
                        if (currentState.type == CurrentType.Object) {
@@ -160,7 +187,6 @@
                                        fromType.Name == "String")
                                return null;
                        string converterName = "System.ComponentModel." + 
fromType.Name + "Converter,System.dll";
-                       Console.WriteLine("YY '"+converterName + "'");
                        Type converter = assembly.GetType(converterName);
                        return converter.AssemblyQualifiedName;
                        // TODO: catch NullReferenceException and do something
@@ -179,11 +205,10 @@
                                // TODO: exception
                        }
 
-                       ParserState newState = new ParserState();
-                       newState.type = CurrentType.Property;
-                       newState.obj = prop;
                        oldStates.Add(currentState);
-                       currentState = newState;
+                       currentState = new ParserState();
+                       currentState.type = CurrentType.Property;
+                       currentState.obj = prop;
 
                        writer.CreateProperty(propertyName);
 
@@ -201,7 +226,8 @@
                        DependencyProperty dp;
                        Type currentType = (Type)currentState.obj;
                        if 
(!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
-                                       throw new Exception("Attached 
properties can only be set on DependencyObjects (not " + currentType.Name + 
")");
+                                       throw new Exception("Attached 
properties can only be set on "+
+                                                       "DependencyObjects (not 
" + currentType.Name + ")");
                        foreach (ParserState state in oldStates) {
                                if (state.type == CurrentType.Object &&
                                                ((Type)state.obj).Name == 
attachedTo) {
@@ -221,7 +247,9 @@
                        currentState.obj = dp;
                        currentState.type = CurrentType.AttachedProperty;
 
-                       writer.CreateAttachedProperty(attachedTo, propertyName, 
dp.PropertyType.AssemblyQualifiedName);
+                       
writer.CreateAttachedProperty(typeAttachedTo.AssemblyQualifiedName, 
+                                       propertyName, 
+                                       dp.PropertyType.AssemblyQualifiedName);
                }
 
                void parseObjectElement()
@@ -241,8 +269,10 @@
                        
                        if (reader.MoveToFirstAttribute()) {
                                do {
-                                       if 
(reader.LocalName.StartsWith("xmlns"))
+                                       if (reader.Name.StartsWith("xmlns"))
                                                continue;
+                                       if (reader.NamespaceURI == 
XAML_NAMESPACE)
+                                               continue;
                                        if (reader.LocalName.IndexOf(".") < 0)
                                                parseLocalPropertyAttribute();
                                        else
@@ -280,6 +310,8 @@
 
                void parseEndElement()
                {
+                       if (currentState.type == CurrentType.Code)
+                               writer.CreateCode((string)currentState.obj);
                        if (currentState.type == CurrentType.Object)
                                writer.EndObject();
                        else if (currentState.type == CurrentType.Property)

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-03 09:31:25 UTC (rev 46888)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-03 12:57:28 UTC (rev 46889)
@@ -29,15 +29,21 @@
 namespace Mono.Windows.Serialization {
        public interface XamlWriter {
                void CreateTopLevel(string parentName, string className);
+
                void CreateObject(string typeName);
+               void CreateElementText(string text);
+               void EndObject();
+
                void CreateProperty(string propertyName);
-               void CreateElementText(string text);
                void CreatePropertyText(string text, string converter);
+               void EndProperty();
+               
                void CreateAttachedProperty(string attachedTo, string 
propertyName, string typeName);
                void CreateAttachedPropertyText(string text, string converter);
-               void EndObject();
-               void EndProperty();
                void EndAttachedProperty();
+
+               void CreateCode(string code);
+
                void Finish();
        }
 }

Modified: trunk/mcs/tools/xamlc/ChangeLog
===================================================================
--- trunk/mcs/tools/xamlc/ChangeLog     2005-07-03 09:31:25 UTC (rev 46888)
+++ trunk/mcs/tools/xamlc/ChangeLog     2005-07-03 12:57:28 UTC (rev 46889)
@@ -1,3 +1,12 @@
+2005-07-03  Iain McCoy  <[EMAIL PROTECTED]>
+       * demo/Makefile: made more useful - just do "make run" and it should
+       all happen
+       * demo/test.xaml: added Code section, which I think should make this
+       thing a complete, if small, program
+       * demo/TestVocab/*: some small bugfixes, with a little bit of
+       craziness to work around the slightly bogus stuff in DependencyObject
+       at the moment.
+
 2005-07-02  Iain McCoy  <[EMAIL PROTECTED]>
 
        * whole folder: first emphatically work-in-progress version of xaml

Modified: trunk/mcs/tools/xamlc/demo/Makefile
===================================================================
--- trunk/mcs/tools/xamlc/demo/Makefile 2005-07-03 09:31:25 UTC (rev 46888)
+++ trunk/mcs/tools/xamlc/demo/Makefile 2005-07-03 12:57:28 UTC (rev 46889)
@@ -3,11 +3,14 @@
 
 SOURCES=TestVocab/ConsoleApp.cs TestVocab/ConsoleWriter.cs 
TestVocab/IConsoleAction.cs
 
-all-local: TestVocab.dll test.xaml.out
+run:
+       make TestVocab.dll
+       MONO_PATH="." $(RUNTIME) --debug ../xamlc.exe -o:test.xaml.out.cs 
test.xaml
+       $(CSCOMPILE) -r:TestVocab.dll -o test.exe test.xaml.out.cs
+       $(RUNTIME) --debug test.exe
 
+all-local: TestVocab.dll
+
 TestVocab.dll: $(SOURCES)
        $(CSCOMPILE) -r:PresentationFramework.dll -r:WindowsBase.dll 
-out:TestVocab.dll -target:library $(SOURCES)
 
-test.xaml.out:
-       make TestVocab.dll
-       MONO_PATH="." $(RUNTIME) ../xamlc.exe -o:test.xaml.out test.xaml

Modified: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs  2005-07-03 09:31:25 UTC 
(rev 46888)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs  2005-07-03 12:57:28 UTC 
(rev 46889)
@@ -5,7 +5,7 @@
 
 namespace Xaml.TestVocab.Console {
        public class ConsoleApp : IAddChild {
-               private ArrayList actions;
+               private ArrayList actions = new ArrayList();
                public void AddText(string Text)
                {
                        actions.Add(new ConsoleWriter(Text));
@@ -36,7 +36,8 @@
                }
                public static int GetRepetitions(DependencyObject d)
                {
-                       return (int)d.GetValue(RepetitionsProperty);
+                       object v = d.GetValue(RepetitionsProperty);
+                       return (v == null ? 1 : (int)v);
                }
        }
 }

Modified: trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
===================================================================
--- trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs       2005-07-03 
09:31:25 UTC (rev 46888)
+++ trunk/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs       2005-07-03 
12:57:28 UTC (rev 46889)
@@ -1,9 +1,16 @@
+using System;
 using System.Windows;
+using System.Windows.Serialization;
 
 namespace Xaml.TestVocab.Console {
-       public class ConsoleWriter : DependencyObject {
+       public class ConsoleWriter : DependencyObject, IAddChild, 
IConsoleAction {
                string text;
 
+               public ConsoleWriter()
+               {
+                       text = "";
+               }
+               
                public ConsoleWriter(string text)
                {
                        this.text = text;
@@ -14,6 +21,16 @@
                        set { text = value; }
                }
 
+               public void AddText(string text)
+               {
+                       this.text += text;
+               }
+
+               public void AddChild(Object o)
+               {
+                       throw new NotImplementedException();
+               }
+
                
                public void Run()
                {

Modified: trunk/mcs/tools/xamlc/demo/test.xaml
===================================================================
--- trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-03 09:31:25 UTC (rev 
46888)
+++ trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-03 12:57:28 UTC (rev 
46889)
@@ -1,10 +1,19 @@
 <?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab" 
XmlNamespace="console" ?>
 
-<ConsoleApp xmlns="console">
+<ConsoleApp xmlns="console" 
+               xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"; 
+               x:Class="DemoConsoleApp">
        <ConsoleWriter>IT BEGINS!</ConsoleWriter>
        <ConsoleWriter Text="Hello World" />
        <ConsoleWriter>
                <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions>
                <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
        </ConsoleWriter>
+       <x:Code><![CDATA[
+               public static void Main(string[] args)
+               {
+                       Xaml.TestVocab.Console.ConsoleApp c = new 
DemoConsoleApp();
+                       c.Run();
+               }
+       ]]></x:Code>
 </ConsoleApp>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to