Author: jackson
Date: 2007-11-20 11:29:44 -0500 (Tue, 20 Nov 2007)
New Revision: 89990
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/xaml.cpp
trunk/moon/src/xaml.h
Log:
* xaml.cpp: Add new function to create a value from a string
without having the Kind available (you still need to have the
type
in string form).
- SetAttribute now ensures that the attribute was set properly
- If the object we are trying to set an attribute on is a
managed
object and there is no DependencyProperty for the attribute, we
try setting the attribute on the object.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-11-20 16:25:27 UTC (rev 89989)
+++ trunk/moon/src/ChangeLog 2007-11-20 16:29:44 UTC (rev 89990)
@@ -1,3 +1,13 @@
+2007-11-20 Jackson Harper <[EMAIL PROTECTED]>
+
+ * xaml.cpp: Add new function to create a value from a string
+ without having the Kind available (you still need to have the type
+ in string form).
+ - SetAttribute now ensures that the attribute was set properly
+ - If the object we are trying to set an attribute on is a managed
+ object and there is no DependencyProperty for the attribute, we
+ try setting the attribute on the object.
+
2007-11-20 Sebastien Pouliot <[EMAIL PROTECTED]>
* uielement.cpp: Ensure the default value for VisibilityProperty
@@ -32,6 +42,12 @@
2007-11-15 Jackson Harper <[EMAIL PROTECTED]>
+ * Makefile.am:
+ * parsertest.cpp: Some tests I use for checking the parsing
+ functions.
+
+2007-11-15 Jackson Harper <[EMAIL PROTECTED]>
+
* color.h: Add equality operators.
2007-11-15 Jackson Harper <[EMAIL PROTECTED]>
Modified: trunk/moon/src/xaml.cpp
===================================================================
--- trunk/moon/src/xaml.cpp 2007-11-20 16:25:27 UTC (rev 89989)
+++ trunk/moon/src/xaml.cpp 2007-11-20 16:29:44 UTC (rev 89990)
@@ -237,7 +237,7 @@
virtual ~XamlNamespace () { }
virtual XamlElementInfo* FindElement (XamlParserInfo *p, const char
*el) = 0;
- virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse) = 0;
+ virtual bool SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse) = 0;
};
class DefaultNamespace : public XamlNamespace {
@@ -254,9 +254,9 @@
return (XamlElementInfo *) g_hash_table_lookup (element_map,
el);
}
- virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse)
+ virtual bool 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
+ return false;
}
};
@@ -274,7 +274,7 @@
return (XamlElementInfo *) g_hash_table_lookup (element_map,
el);
}
- virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse)
+ virtual bool SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse)
{
*reparse = false;
@@ -286,15 +286,18 @@
//
// if (p->namescope->FindName (value)) {
// parser_error (p,
p->current_element->element_name, "x:Name", 2028, g_strdup_printf ("The name
already exists in the tree: %s.", value));
- // return;
+ // return false;
// }
//
p->namescope->RegisterName (value, (DependencyObject *)
item->item);
item->item->SetValue (DependencyObject::NameProperty,
Value (value));
- if (p->loader)
+ if (p->loader) {
p->loader->SetNameAttribute (item->item, value);
- return;
+ return true;
+ }
+
+ return false;
}
if (!strcmp ("Class", attr)) {
@@ -311,7 +314,7 @@
if (!dob) {
parser_error (p, item->element_name, attr, -1,
g_strdup_printf ("Unable to
resolve x:Class type '%s'\n", value));
- return;
+ return false;
}
// Special case the namescope for now, since attached
properties aren't copied
@@ -323,8 +326,10 @@
p->AddCreatedElement (item->item);
*reparse = true;
- return;
+ return true;
}
+
+ return false;
}
};
@@ -375,10 +380,11 @@
return info;
}
- virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse)
+ virtual bool SetAttribute (XamlParserInfo *p, XamlElementInstance
*item, const char *attr, const char *value, bool *reparse)
{
if (p->loader)
- p->loader->SetAttribute (item->item, attr, value);
+ return p->loader->SetAttribute (item->item, attr,
value);
+ return false;
}
};
@@ -434,14 +440,13 @@
return NULL;
}
-void
+bool
XamlLoader::SetAttribute (void* target, const char* name, const char* value)
{
- if (callbacks.set_custom_attribute) {
- callbacks.set_custom_attribute (target, name, value);
- return;
- }
- //printf ("XamlLoader::SetAttribute (%p, %s, %s)\n", target, name,
value);
+ if (callbacks.set_custom_attribute)
+ return callbacks.set_custom_attribute (target, name, value);
+
+ return false;
}
void
@@ -2318,8 +2323,19 @@
return (int) strtol (str, NULL, 10);
}
-// Will return an INVALID value if there are any errors
Value *
+value_from_str_with_typename (const char *type_name, const char *prop_name,
const char *str)
+{
+ Type *t = Type::Find (type_name);
+ if (!t)
+ return NULL;
+
+ return value_from_str (t->type, prop_name, str);
+}
+
+
+// Will return NULL if there are any errors
+Value *
value_from_str (Type::Kind type, const char *prop_name, const char *str)
{
Value *v;
@@ -2772,7 +2788,6 @@
}
-// TODO: Merge more of this code with the above function
void
dependency_object_set_attributes (XamlParserInfo *p, XamlElementInstance
*item, const char **attr)
{
@@ -2861,6 +2876,14 @@
dep->SetValue (prop, v);
item->MarkPropertyAsSet (prop->name);
} else {
+
+ // This might be a property of a managed object
+ if (p->loader && p->loader->SetAttribute (item->item,
attr [i], attr [i + 1])) {
+ if (atchname)
+ g_free (atchname);
+ continue;
+ }
+
if (dependency_object_hookup_event (p, item, pname,
attr [i + 1]))
parser_error (p, item->element_name, attr [i],
2012, g_strdup_printf ("Unknown attribute %s on element %s.",
attr [i],
p->current_element->element_name));
Modified: trunk/moon/src/xaml.h
===================================================================
--- trunk/moon/src/xaml.h 2007-11-20 16:25:27 UTC (rev 89989)
+++ trunk/moon/src/xaml.h 2007-11-20 16:29:44 UTC (rev 89990)
@@ -21,7 +21,7 @@
struct XamlLoaderCallbacks;
typedef DependencyObject *xaml_load_managed_object_callback (const char*
asm_name, const char* asm_path, const char* name, const char* type_name);
-typedef void xaml_set_custom_attribute_callback (void *target, const char
*name, const char *value);
+typedef bool xaml_set_custom_attribute_callback (void *target, const char
*name, const char *value);
typedef bool xaml_hookup_event_callback (void *target, const char *ename,
const char *evalue);
typedef void xaml_insert_mapping_callback (const char* key, const char*
value);
typedef const char* xaml_get_mapping_callback (const char* key);
@@ -34,6 +34,9 @@
DependencyObject *xaml_create_from_str (XamlLoader* loader, const char
*xaml, bool create_namescope, Type::Kind *element_type);
bool xaml_set_property_from_str (DependencyObject *obj,
DependencyProperty *prop, const char *value);
+Value* value_from_str_with_typename (const char *type_name, const char
*prop_name, const char *str);
+Value* value_from_str (Type::Kind type, const char *prop_name, const char
*str);
+
void xaml_loader_set_callbacks (XamlLoader* loader, XamlLoaderCallbacks
callbacks);
void xaml_init (void);
@@ -116,7 +119,7 @@
virtual bool LoadVM ();
virtual DependencyObject* CreateManagedObject (const char* xmlns, const
char* name);
virtual DependencyObject* CreateManagedObject (const char* asm_name,
const char* asm_path, const char* name, const char* type_name);
- virtual void SetAttribute (void* target, const char* name, const char*
value);
+ virtual bool SetAttribute (void* target, const char* name, const char*
value);
virtual void SetNameAttribute (void* target, const char* name);
virtual bool HookupEvent (void* target, const char* name, const char*
value);
virtual void InsertMapping (const char* key, const char* value);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches