Author: jackson
Date: 2007-06-19 11:40:04 -0400 (Tue, 19 Jun 2007)
New Revision: 80180
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/runtime.h
trunk/moon/src/xaml.cpp
Log:
* xaml.cpp\runtime.h: Add a public function for setting
properties, from strings. Basically a copy and paste of my
set_attributes code. Eventually I should be able to merge the
two, but they use different name lookup mechanisms right now.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-19 15:39:53 UTC (rev 80179)
+++ trunk/moon/src/ChangeLog 2007-06-19 15:40:04 UTC (rev 80180)
@@ -1,3 +1,10 @@
+2007-06-19 Jackson Harper <[EMAIL PROTECTED]>
+
+ * xaml.cpp\runtime.h: Add a public function for setting
+ properties, from strings. Basically a copy and paste of my
+ set_attributes code. Eventually I should be able to merge the
+ two, but they use different name lookup mechanisms right now.
+
2007-06-19 Jeffrey Stedfast <[EMAIL PROTECTED]>
* animation.cpp (Remove): Remove the KeyFrame from the sorted list
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-19 15:39:53 UTC (rev 80179)
+++ trunk/moon/src/runtime.h 2007-06-19 15:40:04 UTC (rev 80180)
@@ -946,6 +946,7 @@
xaml_set_custom_attribute_callback *sca, Type::Kind
*element_type);
UIElement *xaml_create_from_str (const char *xaml, bool create_namescope,
xaml_create_custom_element_callback *cecb,
xaml_set_custom_attribute_callback *sca, Type::Kind
*element_type);
+void xaml_set_property_from_str (DependencyObject *obj, const char
*prop, const char *value);
void runtime_init (void);
Modified: trunk/moon/src/xaml.cpp
===================================================================
--- trunk/moon/src/xaml.cpp 2007-06-19 15:39:53 UTC (rev 80179)
+++ trunk/moon/src/xaml.cpp 2007-06-19 15:40:04 UTC (rev 80180)
@@ -1484,6 +1484,106 @@
///
void
+xaml_set_property_from_str (DependencyObject *obj, const char *pname, const
char *value)
+{
+ DependencyProperty *prop = DependencyObject::GetDependencyProperty
(obj->GetObjectType (), (char *) pname);
+
+ if (!prop) {
+ printf ("can not find property: %s\n", prop);
+ return;
+ }
+
+ switch (prop->value_type & Value::VALUE_TYPEMASK) {
+ case Value::BOOL:
+ obj->SetValue (prop, Value ((bool) !g_strcasecmp ("true",
value)));
+ break;
+ case Value::DOUBLE:
+ obj->SetValue (prop, Value ((double) strtod (value, NULL)));
+ break;
+ case Value::INT64:
+ obj->SetValue (prop, Value ((gint64) strtol (value, NULL, 10)));
+ break;
+ case Value::INT32:
+ {
+ // Maybe we should try an [0] != '-' && !isdigit before looking
up the enum?
+ int val;
+ enum_map_t *emu = (enum_map_t *) g_hash_table_lookup (enum_map,
value);
+
+ if (emu)
+ val = enum_from_str (emu, value);
+ else
+ val = (int) strtol (value, NULL, 10);
+ obj->SetValue (prop, Value (val));
+ break;
+ }
+ case Value::STRING:
+ obj->SetValue (prop, Value (value));
+ break;
+ case Value::COLOR:
+ obj->SetValue (prop, Value (*color_from_str (value)));
+ break;
+ case Value::REPEATBEHAVIOR:
+ obj->SetValue (prop, Value (repeat_behavior_from_str (value)));
+ break;
+ case Value::DURATION:
+ obj->SetValue (prop, Value (duration_from_str (value)));
+ break;
+ case Value::KEYTIME:
+ obj->SetValue (prop, Value (KeyTime (timespan_from_str
(value))));
+ break;
+ case Value::KEYSPLINE:
+ obj->SetValue (prop, Value (key_spline_from_str (value)));
+ break;
+ case Value::BRUSH:
+ case Value::SOLIDCOLORBRUSH:
+ {
+ // Only solid color brushes can be specified using attribute
syntax
+ SolidColorBrush *scb = solid_color_brush_new ();
+ Color *c = color_from_str (value);
+ solid_color_brush_set_color (scb, c); // copies c
+ delete c;
+ obj->SetValue (prop, Value (scb));
+ break;
+ }
+ case Value::POINT:
+ obj->SetValue (prop, Value (point_from_str (value)));
+ break;
+ case Value::RECT:
+ obj->SetValue (prop, Value (rect_from_str (value)));
+ break;
+ case Value::DOUBLE_ARRAY:
+ {
+ int count = 0;
+ double *doubles = double_array_from_str (value, &count);
+ obj->SetValue (prop, Value (doubles, count));
+ break;
+ }
+ case Value::POINT_ARRAY:
+ {
+ int count = 0;
+ Point *points = point_array_from_str (value, &count);
+ obj->SetValue (prop, Value (points, count));
+ break;
+ }
+
+ case Value::MATRIX:
+ obj->SetValue (prop, matrix_value_from_str (value));
+ break;
+ case Value::GEOMETRY:
+ {
+ char *data = g_strdup (value);
+ obj->SetValue (prop, geometry_from_str (data));
+ g_free (data);
+ break;
+ }
+ default:
+ printf ("could not find value type for: %s to '%s' %d\n", prop,
value, prop->value_type);
+ break;
+ }
+}
+
+// TODO: Merge more of this code with the above function
+void
dependency_object_set_attributes (XamlParserInfo *p, XamlElementInstance
*item, const char **attr)
{
for (int i = 0; attr [i]; i += 2) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches