Author: jackson
Date: 2007-06-20 23:42:45 -0400 (Wed, 20 Jun 2007)
New Revision: 80398

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
   trunk/moon/src/xaml.cpp
Log:

                * xaml.cpp: Set namecopes earlier, and make sure to copy
                * the
        namescope when we recreate a class using x:Class.
        - When we use x:Class reparse the element's attributes, so it
          can
        hook up to events and set properties.
        * runtime.cpp|h: When the Name property is set, register it with
        the proper NameScope.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-21 03:38:40 UTC (rev 80397)
+++ trunk/moon/src/ChangeLog    2007-06-21 03:42:45 UTC (rev 80398)
@@ -1,3 +1,12 @@
+2007-06-20  Jackson Harper  <[EMAIL PROTECTED]>
+
+       * xaml.cpp: Set namecopes earlier, and make sure to copy the
+       namescope when we recreate a class using x:Class.
+       - When we use x:Class reparse the element's attributes, so it can
+       hook up to events and set properties.
+       * runtime.cpp|h: When the Name property is set, register it with
+       the proper NameScope.
+       
 2007-06-20  Chris Toshok  <[EMAIL PROTECTED]>
 
        * runtime.cpp, runtime.h: add rudimentary Visibility support.  we

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-21 03:38:40 UTC (rev 80397)
+++ trunk/moon/src/runtime.cpp  2007-06-21 03:42:45 UTC (rev 80398)
@@ -839,7 +839,6 @@
        Collection::Add (item);
        emit_loaded_events (item);
 
-       
        VisualUpdate (data);
 }
 
@@ -2519,7 +2518,6 @@
        DependencyObject *obj = (DependencyObject *) value;
        NameScope *scope = (NameScope *) data;
 
-       printf ("MERGING:  %s, %p\n", name, obj);
        scope->RegisterName (name, obj);
 }
 
@@ -2880,6 +2878,17 @@
 DependencyProperty* DependencyObject::NameProperty;
 
 void
+DependencyObject::OnPropertyChanged (DependencyProperty *property)
+{
+       if (NameProperty == property) {
+               NameScope *scope = FindNameScope ();
+               Value *v = GetValue (NameProperty);
+               if (scope && v)
+                       scope->RegisterName (v->AsString (), this);
+       }
+}
+
+void
 dependency_object_init(void)
 {
        DependencyObject::NameProperty = DependencyObject::Register 
(Type::DEPENDENCY_OBJECT, "Name", Type::STRING);

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-21 03:38:40 UTC (rev 80397)
+++ trunk/moon/src/runtime.h    2007-06-21 03:42:45 UTC (rev 80398)
@@ -258,7 +258,7 @@
        EventObject *events;
        static GHashTable *properties;
 
-       virtual void OnPropertyChanged (DependencyProperty *property) { }
+       virtual void OnPropertyChanged (DependencyProperty *property);
        virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyProperty *subprop) { }
 
        //

Modified: trunk/moon/src/xaml.cpp
===================================================================
--- trunk/moon/src/xaml.cpp     2007-06-21 03:38:40 UTC (rev 80397)
+++ trunk/moon/src/xaml.cpp     2007-06-21 03:42:45 UTC (rev 80398)
@@ -179,7 +179,7 @@
        XamlNamespace () : name (NULL) { }
        
        virtual XamlElementInfo* FindElement (XamlParserInfo *p, const char 
*el) = 0;
-       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value) = 0;
+       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value, bool *reparse) = 0;
 };
 
 class DefaultNamespace : public XamlNamespace {
@@ -194,7 +194,7 @@
                return (XamlElementInfo *) g_hash_table_lookup (element_map, 
el);
        }
 
-       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value)
+       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value, bool *reparse)
        {
                // We don't have to do anything, since the default framework 
covers us
        }
@@ -212,23 +212,34 @@
                return NULL;
        }
 
-       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value)
+       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value, bool *reparse)
        {
+               *reparse = false;
+
                if (!strcmp ("Name", attr)) {
                        p->namescope->RegisterName (value, (DependencyObject *) 
item->item);
                        return;
                }
 
                if (!strcmp ("Class", attr)) {
-                       delete item->item;
+                       DependencyObject *old = item->item;
+                       
                        item->item = NULL;
-
                        DependencyObject *dob = p->custom_element_callback 
(value, NULL);
-                       if (!dob)
+                       if (!dob) {
                                parser_error (p, item->element_name, attr,
                                                g_strdup_printf ("Unable to 
resolve x:Class type '%s'\n", value));
+                               return;
+                       }
 
+                       // Special case the namescope for now, since attached 
properties aren't copied
+                       NameScope *ns = NameScope::GetNameScope (old);
+                       if (ns)
+                               NameScope::SetNameScope (dob, ns);
                        item->item = dob;
+
+                       delete old;
+                       *reparse = true;
                        return;
                }
        }
@@ -278,9 +289,8 @@
                return info;
        }
 
-       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value)
+       virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value, bool *reparse)
        {
-               printf ("Setting custom attribute:  %p\n", item->item);
                p->custom_attribute_callback (item->item, attr, value);
        }
 };
@@ -336,6 +346,20 @@
        XML_StopParser (p->parser, FALSE);
 }
 
+DependencyObject *
+get_parent (XamlElementInstance *inst)
+{
+       XamlElementInstance *walk = inst;
+
+       while (walk) {
+               if (walk->element_type == XamlElementInstance::ELEMENT)
+                       return walk->item;
+               walk = walk->parent;
+       }
+
+       return NULL;
+}
+
 void
 start_element (void *data, const char *el, const char **attr)
 {
@@ -346,23 +370,34 @@
        elem = p->current_namespace->FindElement (p, el);
 
        if (elem) {
+               bool set_top = false;
+
                inst = elem->create_element (p, elem);
 
                if (!inst || !inst->item)
                        return;
 
+               if (!p->top_element) {
+                       set_top = true;
+
+                       p->top_element = inst;
+                       p->current_element = inst;
+                       NameScope::SetNameScope (inst->item, p->namescope);
+               } else {
+                       DependencyObject *parent = get_parent 
(p->current_element);
+                       if (parent) {
+                               inst->item->SetParent (parent);
+                       }
+               }
+
                elem->set_attributes (p, inst, attr);
 
                // Setting the attributes can kill the item
                if (!inst->item)
                        return;
 
-               if (!p->top_element) {
-                       p->top_element = inst;
-                       p->current_element = inst;
-                       NameScope::SetNameScope (inst->item, p->namescope);
+               if (set_top)
                        return;
-               }
 
                if (p->current_element && p->current_element->element_type != 
XamlElementInstance::UNKNOWN) {
 
@@ -371,6 +406,7 @@
                        else
                                g_warning ("attempt to set property of 
unimplemented type: %s\n", p->current_element->element_name);
                }
+
        } else {
                bool property = false;
                for (int i = 0; el [i]; i++) {
@@ -1881,7 +1917,12 @@
 void
 dependency_object_set_attributes (XamlParserInfo *p, XamlElementInstance 
*item, const char **attr)
 {
+       int skip_attribute = -1;
        for (int i = 0; attr [i]; i += 2) {
+
+               if (i == skip_attribute)
+                       continue;
+
                // Setting attributes like x:Class can change item->item, so we
                // need to make sure we have an up to date pointer
                DependencyObject *dep = (DependencyObject *) item->item;
@@ -1894,7 +1935,8 @@
                                return parser_error (p, item->element_name, 
attr [i],
                                                g_strdup_printf ("Could not 
find namespace %s", attr_name [0]));
 
-                       ns->SetAttribute (p, item, attr_name [1], attr [i + 1]);
+                       bool reparse = false;
+                       ns->SetAttribute (p, item, attr_name [1], attr [i + 1], 
&reparse);
 
                        g_strfreev (attr_name);
 
@@ -1902,6 +1944,10 @@
                        if (p->error_args)
                                return;
 
+                       if (reparse) {
+                               skip_attribute = i;
+                               i = 0;
+                       }
                        continue;
                }
 

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

Reply via email to