Author: jackson
Date: 2007-06-06 04:02:20 -0400 (Wed, 06 Jun 2007)
New Revision: 78708
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/animation.cpp
trunk/moon/src/animation.h
trunk/moon/src/brush.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/shape.cpp
trunk/moon/src/transform.cpp
trunk/moon/src/transform.h
trunk/moon/src/xaml.cpp
Log:
* runtime.cpp/h: initialize xaml
- Add canvas C style constructor
- Make SolidColorBrush's Color public
* shape.cpp: Comment out the set_prop... stuff, this code won't
* be
used anymore, now that the xaml parser is using dependency
objects
to set properties.
* animation.cpp|h:
* transform.cpp|h: Add some C style constructors
* brush.cpp: Create colors from a string instead of solid
* brushes
* xaml.cpp: Add in a known element tree, and move property
* setting
into the xaml code, also added code for setting properties with
property element syntax
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/ChangeLog 2007-06-06 08:02:20 UTC (rev 78708)
@@ -1,3 +1,18 @@
+2007-06-06 Jackson Harper <[EMAIL PROTECTED]>
+
+ * runtime.cpp/h: initialize xaml
+ - Add canvas C style constructor
+ - Make SolidColorBrush's Color public
+ * shape.cpp: Comment out the set_prop... stuff, this code won't be
+ used anymore, now that the xaml parser is using dependency objects
+ to set properties.
+ * animation.cpp|h:
+ * transform.cpp|h: Add some C style constructors
+ * brush.cpp: Create colors from a string instead of solid brushes
+ * xaml.cpp: Add in a known element tree, and move property setting
+ into the xaml code, also added code for setting properties with
+ property element syntax
+
2007-06-05 Miguel de Icaza <[EMAIL PROTECTED]>
Add type checking on SetValue, RegisterProperty to avoid
Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/animation.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -315,6 +315,12 @@
}
}
+Storyboard *
+storyboard_new ()
+{
+ return new Storyboard ();
+}
+
void
storyboard_begin (Storyboard *sb)
{
@@ -386,6 +392,12 @@
{
}
+DoubleAnimation *
+double_animation_new ()
+{
+ return new DoubleAnimation ();
+}
+
void
double_animation_set_by (DoubleAnimation *da, double by)
{
Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/animation.h 2007-06-06 08:02:20 UTC (rev 78708)
@@ -109,6 +109,7 @@
static gboolean storyboard_tick (gpointer data);
};
+Storyboard *storyboard_new ();
void storyboard_begin (Storyboard *sb);
void storyboard_pause (Storyboard *sb);
void storyboard_resume (Storyboard *sb);
@@ -139,6 +140,8 @@
static DependencyProperty* ToProperty;
};
+DoubleAnimation * double_animation_new ();
+
void double_animation_set_by (DoubleAnimation *da, double by);
double double_animation_get_by (DoubleAnimation *da);
Modified: trunk/moon/src/brush.cpp
===================================================================
--- trunk/moon/src/brush.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/brush.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -55,9 +55,11 @@
/**
* see:
http://msdn2.microsoft.com/en-us/library/system.windows.media.solidcolorbrush.aspx
+ *
+ * If no color is found, Color.Transparent is returned.
*/
-SolidColorBrush *
-solid_brush_from_str (const char *name)
+Color
+color_from_str (const char *name)
{
if (!name)
return NULL;
@@ -97,10 +99,8 @@
break;
}
- return new SolidColorBrush (Color (strtol (r, NULL, 16) /
255.0F,
- strtol (g, NULL,
16) / 255.0F,
- strtol (b, NULL,
16) / 255.0F,
- strtol (a, NULL,
16) / 255.0F));
+ return Color (strtol (r, NULL, 16) / 255.0F, strtol (g, NULL,
16) / 255.0F,
+ strtol (b, NULL, 16) / 255.0F, strtol (a, NULL,
16) / 255.0F);
}
if (name [0] == 's' && name [1] == 'c' && name [2] == '#') {
@@ -109,9 +109,9 @@
for (int i = 0; named_colors [i].name; i++) {
if (!g_strcasecmp (named_colors [i].name, name)) {
- Color c = Color (named_colors [i].color);
- return new SolidColorBrush (c);
+ return Color (named_colors [i].color);
}
}
- return NULL;
+
+ return Color (0x00FFFFFF);
}
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/runtime.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -468,6 +468,12 @@
}
}
+Canvas *
+canvas_new ()
+{
+ return new Canvas ();
+}
+
Surface *
surface_new (int width, int height)
{
@@ -900,4 +906,5 @@
animation_init ();
shape_init ();
geometry_init ();
+ xaml_init ();
}
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/runtime.h 2007-06-06 08:02:20 UTC (rev 78708)
@@ -77,6 +77,10 @@
};
};
+
+Color color_from_str (const char *name);
+
+
//
// Collection: provides a collection that we can monitor for
// changes. We expose this collection in a few classes to
@@ -247,6 +251,7 @@
enum Type {
INVALID = 0,
UIELEMENT,
+ PANEL,
CANVAS,
TIMELINE,
ROTATETRANSFORM,
@@ -351,8 +356,9 @@
};
class SolidColorBrush : public Brush {
+
+ public:
Color color;
- public:
SolidColorBrush (Color c) { color = c; }
virtual void SetupBrush (cairo_t *cairo);
@@ -368,7 +374,6 @@
virtual void SetupBrush (cairo_t *cairo);
};
-SolidColorBrush *solid_brush_from_str (const char *name);
enum Stretch {
@@ -526,6 +531,9 @@
static DependencyProperty* LeftProperty;
};
+Canvas * canvas_new ();
+
+
//
// FrameworkElement class
//
@@ -616,6 +624,7 @@
void transform_init ();
void shape_init ();
void geometry_init ();
+void xaml_init ();
G_END_DECLS
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/shape.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -91,6 +91,7 @@
void
Shape::set_prop_from_str (const char *prop, const char *value)
{
+ /*
if (!g_strcasecmp ("fill", prop)) {
SolidColorBrush *fill = solid_brush_from_str (value);
if (fill)
@@ -101,6 +102,7 @@
shape_set_stroke (this, stroke);
} else
FrameworkElement::set_prop_from_str (prop, value);
+ */
}
void
Modified: trunk/moon/src/transform.cpp
===================================================================
--- trunk/moon/src/transform.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/transform.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -49,6 +49,12 @@
}
}
+RotateTransform *
+rotate_transform_new ()
+{
+ return new RotateTransform ();
+}
+
void
rotate_transform_set_angle (RotateTransform *t, double angle)
{
@@ -100,6 +106,12 @@
cairo_matrix_init_translate (value, x, y);
}
+TranslateTransform *
+translate_transform_new ()
+{
+ return new TranslateTransform ();
+}
+
void
translate_transform_set_x (TranslateTransform *t, double x)
{
@@ -151,6 +163,12 @@
}
}
+ScaleTransform *
+scale_transform_new ()
+{
+ return new ScaleTransform ();
+}
+
void
scale_transform_set_scale_x (ScaleTransform *t, double scaleX)
{
@@ -211,6 +229,11 @@
#endif
}
+MatrixTransform *
+matrix_transform_new ()
+{
+ return new MatrixTransform ();
+}
void
transform_init ()
Modified: trunk/moon/src/transform.h
===================================================================
--- trunk/moon/src/transform.h 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/transform.h 2007-06-06 08:02:20 UTC (rev 78708)
@@ -30,6 +30,8 @@
virtual void GetTransform (cairo_matrix_t *value);
};
+RotateTransform * rotate_transform_new ();
+
void rotate_transform_set_angle (RotateTransform *t, double angle);
double rotate_transform_get_angle (RotateTransform *t);
@@ -50,6 +52,7 @@
virtual void GetTransform (cairo_matrix_t *value);
};
+TranslateTransform *translate_transform_new ();
void translate_transform_set_x (TranslateTransform *t, double x);
double translate_transform_get_x (TranslateTransform *t);
@@ -70,6 +73,7 @@
virtual void GetTransform (cairo_matrix_t *value);
};
+ScaleTransform * scale_transform_new ();
void scale_transform_set_scale_x (ScaleTransform *t, double scaleX);
double scale_transform_get_scale_x (ScaleTransform *t);
@@ -95,6 +99,7 @@
virtual void GetTransform (cairo_matrix_t *value);
};
+MatrixTransform *matrix_transform_new ();
void matrix_transform_set_matrix (MatrixTransform *t, cairo_matrix_t
matrix);
cairo_matrix_t matrix_transform_get_matrix (MatrixTransform *t);
Modified: trunk/moon/src/xaml.cpp
===================================================================
--- trunk/moon/src/xaml.cpp 2007-06-06 06:41:24 UTC (rev 78707)
+++ trunk/moon/src/xaml.cpp 2007-06-06 08:02:20 UTC (rev 78708)
@@ -22,19 +22,33 @@
#include "runtime.h"
#include "shape.h"
+#include "animation.h"
+#include "geometry.h"
#define READ_BUFFER 1024
-GHashTable *element_table = NULL;
-void xaml_init_element_table ();
+GHashTable *element_map = NULL;
-class XamlElementInfo {
+class XamlElementInfo;
+class XamlElementInstance;
+class XamlParserInfo;
+
+typedef void* (*create_item_func) ();
+typedef XamlElementInstance *(*create_element_instance_func) (XamlParserInfo
*p, XamlElementInfo *i);
+typedef void (*add_child_func) (XamlParserInfo *p, XamlElementInstance
*parent, XamlElementInstance *child);
+typedef void (*set_property_func) (XamlParserInfo *p, XamlElementInstance
*item, XamlElementInstance *property, XamlElementInstance *value);
+typedef void (*set_attributes_func) (XamlParserInfo *p, XamlElementInstance
*item, const char **attr);
+
+
+class XamlElementInstance {
+
public:
const char *element_name;
const char *instance_name;
- XamlElementInfo *parent;
+ XamlElementInfo *info;
+ XamlElementInstance *parent;
GList *children;
enum ElementType {
@@ -45,10 +59,10 @@
};
int element_type;
- UIElement *item;
+ void *item;
- XamlElementInfo () : element_name (NULL), instance_name (NULL),
+ XamlElementInstance (XamlElementInfo *info) : info (info), element_name
(NULL), instance_name (NULL),
parent (NULL), children (NULL), element_type
(PANEL)
{
}
@@ -60,15 +74,13 @@
public:
XML_Parser parser;
- XamlElementInfo *top_element;
- XamlElementInfo *current_element;
+ XamlElementInstance *top_element;
+ XamlElementInstance *current_element;
GString *char_data_buffer;
int state;
-
-
XamlParserInfo (XML_Parser parser) : parser (parser), top_element
(NULL),
current_element (NULL),
char_data_buffer (NULL)
{
@@ -76,99 +88,113 @@
};
-typedef XamlElementInfo* (*create_element_func) (XamlParserInfo *info, const
char *, const char **);
+class XamlElementInfo {
+ public:
+ const char *name;
+ XamlElementInfo *parent;
+ DependencyObject::Type dependency_type;
+ create_item_func create_item;
+ create_element_instance_func create_element;
+ add_child_func add_child;
+ set_property_func set_property;
+ set_attributes_func set_attributes;
+
+ XamlElementInfo (const char *name, XamlElementInfo *parent,
DependencyObject::Type dependency_type) :
+ name (name), parent (parent), dependency_type (dependency_type),
+ create_item (NULL), create_element (NULL), add_child (NULL),
set_property (NULL), set_attributes (NULL)
+ {
+
+ }
+
+};
+
+
void
start_element_handler (void *data, const char *el, const char **attr)
{
- XamlElementInfo *item;
- XamlParserInfo *info = (XamlParserInfo *) data;
- create_element_func create_element = (create_element_func)
g_hash_table_lookup (element_table, el);
+ XamlParserInfo *p = (XamlParserInfo *) data;
+ XamlElementInfo *elem;
+ XamlElementInstance *inst;
- if (create_element) {
- item = create_element (info, el, attr);
+ elem = (XamlElementInfo *) g_hash_table_lookup (element_map, el);
- if (!info->top_element) {
- info->top_element = item;
- } else {
- item->parent = info->current_element;
- info->current_element->children = g_list_append
(info->current_element->children, item);
+ if (elem) {
- if (info->current_element->element_type &
XamlElementInfo::PANEL &&
- item->element_type <=
XamlElementInfo::PANEL) {
- panel_child_add ((Panel *)
info->current_element->item, item->item);
- }
+ inst = elem->create_element (p, elem);
+ elem->set_attributes (p, inst, attr);
+
+ if (!p->top_element) {
+ p->top_element = inst;
+ p->current_element = inst;
+ return;
}
- info->current_element = item;
- return;
- }
+ if (p->current_element && p->current_element->element_type ==
XamlElementInstance::ELEMENT) {
+ p->current_element->info->add_child (p,
p->current_element, inst);
+ }
- char *elem = g_strdup (el);
- char **ep = g_strsplit (el, ".", -1);
- if (ep [0] && ep [1]) {
+ } else {
- item = new XamlElementInfo ();
+ bool property = false;
+ for (int i = 0; el [i]; i++) {
+ if (el [i] != '.')
+ continue;
+ property = true;
+ break;
+ }
- item->element_name = g_strdup (elem);
- item->element_type = XamlElementInfo::PROPERTY;
+ if (property) {
+ inst = new XamlElementInstance (NULL);
+ inst->element_name = g_strdup (el);
+ inst->element_type = XamlElementInstance::PROPERTY;
+ } else {
+ inst = new XamlElementInstance (NULL);
+ inst->element_name = g_strdup (el);
+ inst->element_type = XamlElementInstance::UNKNOWN;
+ }
- item->parent = info->current_element;
- info->current_element->children = g_list_append
(info->current_element->children, item);
-
- info->current_element = item;
- return;
}
-// printf ("making an unknown item\n");
-// item = new XamlElementInfo ();
-// item->element_type = XamlElementInfo::UNKNOWN;
-// info->current_element = item;
+
+ inst->parent = p->current_element;
+ p->current_element->children = g_list_append
(p->current_element->children, inst);
+ p->current_element = inst;
}
-void end_element (XamlParserInfo *info, const char *el)
-{
- if (info->char_data_buffer && info->char_data_buffer->len) {
- /*
- * TODO: set content property
- - Make sure we aren't just white space
- info->current_element->set_content_prop
(info->char_data_buffer->str);
- */
-
- g_string_free (info->char_data_buffer, FALSE);
- info->char_data_buffer = NULL;
- }
- info->current_element = info->current_element->parent;
-}
-
-void end_property (XamlParserInfo *info, const char *el)
-{
- info->current_element = info->current_element->parent;
-}
-
-void end_unknown (XamlParserInfo *info, const char *el)
-{
-// info->current_element = info->current_element->parent;
-}
-
void
end_element_handler (void *data, const char *el)
{
XamlParserInfo *info = (XamlParserInfo *) data;
switch (info->current_element->element_type) {
- case XamlElementInfo::ELEMENT:
- end_element (info, el);
+ case XamlElementInstance::ELEMENT:
+ if (info->char_data_buffer && info->char_data_buffer->len) {
+ /*
+ * TODO: set content property
+ - Make sure we aren't just white space
+ info->current_element->set_content_prop
(info->char_data_buffer->str);
+ */
+
+ g_string_free (info->char_data_buffer, FALSE);
+ info->char_data_buffer = NULL;
+ }
break;
- case XamlElementInfo::PROPERTY:
- end_property (info, el);
+ case XamlElementInstance::PROPERTY:
+
+ GList *walk = info->current_element->children;
+ while (walk) {
+ XamlElementInstance *child = (XamlElementInstance *)
walk->data;
+ info->current_element->parent->info->set_property
(info, info->current_element->parent, info->current_element, child);
+ walk = walk->next;
+ }
+
break;
- case XamlElementInfo::UNKNOWN:
- end_unknown (info, el);
- break;
}
+
+ info->current_element = info->current_element->parent;
}
void
@@ -185,20 +211,20 @@
}
void
-free_recursive (XamlElementInfo *el)
+free_recursive (XamlElementInstance *el)
{
}
void
-print_tree (XamlElementInfo *el, int depth)
+print_tree (XamlElementInstance *el, int depth)
{
for (int i = 0; i < depth; i++)
printf ("\t");
printf ("%s (%d)\n", el->element_name, g_list_length (el->children));
for (GList *walk = el->children; walk != NULL; walk = walk->next) {
- XamlElementInfo *el = (XamlElementInfo *) walk->data;
+ XamlElementInstance *el = (XamlElementInstance *) walk->data;
print_tree (el, depth + 1);
}
}
@@ -240,9 +266,6 @@
XML_SetProcessingInstructionHandler (p, proc_handler);
*/
- if (!element_table)
- xaml_init_element_table ();
-
done = 0;
while (!done) {
len = fread (buffer, 1, READ_BUFFER, fp);
@@ -295,8 +318,6 @@
XML_SetProcessingInstructionHandler (p, proc_handler);
*/
- if (!element_table)
- xaml_init_element_table ();
if (!XML_Parse (p, xaml, strlen (xaml), TRUE)) {
#ifdef DEBUG_XAML
@@ -321,86 +342,252 @@
return NULL;
}
-XamlElementInfo *
-create_canvas_from_element (XamlParserInfo *info, const char *el, const char
**attr)
+
+
+XamlElementInstance *
+default_create_element_instance (XamlParserInfo *p, XamlElementInfo *i)
{
- Canvas *canvas = new Canvas ();
- XamlElementInfo *res = new XamlElementInfo ();
+ XamlElementInstance *inst = new XamlElementInstance (i);
- res->item = canvas;
- res->element_name = g_strdup (el);
- res->instance_name = NULL;
- res->element_type = XamlElementInfo::PANEL;
+ inst->element_name = i->name;
+ inst->element_type = XamlElementInstance::ELEMENT;
+ inst->item = i->create_item ();
- int count = XML_GetSpecifiedAttributeCount (info->parser);
- for (int i = 0; attr [i]; i += 2)
- canvas->set_prop_from_str (attr [i], attr [i + 1]);
+ return inst;
+}
+
+///
+/// Add Child funcs
+///
- return res;
+void
+nonpanel_add_child (XamlParserInfo *p, XamlElementInstance *parent,
XamlElementInstance *child)
+{
+ /// should we raise an error here????
+
}
-XamlElementInfo *
-create_rectangle_from_element (XamlParserInfo *info, const char *el, const
char **attr)
+void
+panel_add_child (XamlParserInfo *p, XamlElementInstance *parent,
XamlElementInstance *child)
{
- Rectangle *rectangle = new Rectangle ();
- XamlElementInfo *res = new XamlElementInfo ();
+ panel_child_add ((Panel *) parent->item, (UIElement *) child->item);
+}
- res->item = rectangle;
- res->element_name = g_strdup (el);
- res->instance_name = NULL;
- res->element_type = XamlElementInfo::ELEMENT;
- int count = XML_GetSpecifiedAttributeCount (info->parser);
- for (int i = 0; attr [i]; i += 2)
- rectangle->set_prop_from_str (attr [i], attr [i + 1]);
+///
+/// set property funcs
+///
- return res;
+void
+dependency_object_set_property (XamlParserInfo *p, XamlElementInstance *item,
XamlElementInstance *property, XamlElementInstance *value)
+{
+ char **prop_name = g_strsplit (property->element_name, ".", -1);
+
+ DependencyProperty *prop = NULL;
+ XamlElementInfo *walk = item->info;
+ while (walk) {
+ prop = DependencyObject::GetDependencyProperty
(walk->dependency_type, prop_name [1]);
+ if (prop)
+ break;
+ walk = walk->parent;
+ }
+
+ if (prop) {
+ /* need to create Values from void*'s */
+ }
+
+ g_strfreev (prop_name);
}
+void
+solid_color_brush_set_property (XamlParserInfo *p, XamlElementInstance *item,
XamlElementInstance *property, XamlElementInstance *value)
+{
+
+}
+
+///
+/// set attributes funcs
+///
+
+void
+default_set_attributes (XamlParserInfo *p, XamlElementInstance *item, const
char **attr)
+{
+
+}
+
+void
+dependency_object_set_attributes (XamlParserInfo *p, XamlElementInstance
*item, const char **attr)
+{
+ DependencyObject *dep = (DependencyObject *) item->item;
+
+ for (int i = 0; attr [i]; i++) {
+ DependencyProperty *prop = NULL;
+ XamlElementInfo *walk = item->info;
+ while (walk) {
+ prop = DependencyObject::GetDependencyProperty
(walk->dependency_type, (char *) attr [i]);
+ if (prop)
+ break;
+ walk = walk->parent;
+ }
+
+ if (prop) {
+ /// This should be replaced soon, just stuck it in here
for debugging
+ Value v;
+ switch (prop->value_type) {
+ case Value::BOOL:
+ v = Value ((bool) !g_strcasecmp ("true", attr
[i + 1]));
+ break;
+ case Value::DOUBLE:
+ v = Value ((double) strtod (attr [i + 1],
NULL));
+ break;
+ case Value::INT64:
+ v = Value ((gint64) strtol (attr [i + 1], NULL,
10));
+ break;
+ case Value::INT32:
+ v = Value ((int) strtol (attr [i + 1], NULL,
10));
+ break;
+ case Value::STRING:
+ v = Value (attr [i + 1]);
+ break;
+ default:
+ continue;
+ }
+ dep->SetValue (prop, v);
+ }
+ }
+}
+
+void
+solid_color_brush_set_attributes (XamlParserInfo *p, XamlElementInstance
*item, const char **attr)
+{
+ SolidColorBrush *brush = (SolidColorBrush *) item->item;
+
+ for (int i = 0; attr [i]; i++) {
+ if (!strcmp ("Color", attr [i])) {
+ brush->color = color_from_str (attr [i + 1]);
+ }
+ }
+}
+
+void *
+create_solid_color_brush ()
+{
+ return new SolidColorBrush (color_from_str ("Transparent"));
+}
+
+// We still use a name for ghost elements to make debugging easier
XamlElementInfo *
-create_line_from_element (XamlParserInfo *info, const char *el, const char
**attr)
+register_ghost_element (const char *name, XamlElementInfo *parent,
DependencyObject::Type dt)
{
- Line *line = line_new ();
- XamlElementInfo *res = new XamlElementInfo ();
+ return new XamlElementInfo (name, parent, dt);
+}
- res->item = line;
- res->element_name = g_strdup (el);
- res->instance_name = NULL;
- res->element_type = XamlElementInfo::ELEMENT;
+XamlElementInfo *
+register_dependency_object_element (const char *name, XamlElementInfo *parent,
DependencyObject::Type dt,
+ create_item_func create_item)
+{
+ XamlElementInfo *res = new XamlElementInfo (name, parent, dt);
- int count = XML_GetSpecifiedAttributeCount (info->parser);
- for (int i = 0; attr [i]; i += 2)
- line->set_prop_from_str (attr [i], attr [i + 1]);
+ res->create_item = create_item;
+ res->create_element = default_create_element_instance;
+ res->add_child = nonpanel_add_child;
+ res->set_property = dependency_object_set_property;
+ res->set_attributes = dependency_object_set_attributes;
+ g_hash_table_insert (element_map, (char *) name, GINT_TO_POINTER (res));
+
return res;
}
XamlElementInfo *
-create_ellipse_from_element (XamlParserInfo *info, const char *el, const char
**attr)
+register_element_full (const char *name, XamlElementInfo *parent,
DependencyObject::Type dt,
+ create_item_func create_item, create_element_instance_func
create_element, add_child_func add_child,
+ set_property_func set_property, set_attributes_func
set_attributes)
{
- Ellipse *ellipse = ellipse_new ();
- XamlElementInfo *res = new XamlElementInfo ();
+ XamlElementInfo *res = new XamlElementInfo (name, parent, dt);
- res->item = ellipse;
- res->element_name = g_strdup (el);
- res->instance_name = NULL;
- res->element_type = XamlElementInfo::ELEMENT;
+ res->create_item = create_item;
+ res->create_element = create_element;
+ res->add_child = add_child;
+ res->set_property = set_property;
+ res->set_attributes = set_attributes;
- int count = XML_GetSpecifiedAttributeCount (info->parser);
- for (int i = 0; attr [i]; i += 2)
- ellipse->set_prop_from_str (attr [i], attr [i + 1]);
+ g_hash_table_insert (element_map, (char *) name, GINT_TO_POINTER (res));
return res;
}
void
-xaml_init_element_table ()
+xaml_init ()
{
- element_table = g_hash_table_new (g_str_hash, g_str_equal);
+ element_map = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_insert (element_table, (char *) "Canvas", GINT_TO_POINTER
(create_canvas_from_element));
- g_hash_table_insert (element_table, (char *) "Rectangle",
GINT_TO_POINTER (create_rectangle_from_element));
- g_hash_table_insert (element_table, (char *) "Line", GINT_TO_POINTER
(create_line_from_element));
- g_hash_table_insert (element_table, (char *) "Ellipse", GINT_TO_POINTER
(create_ellipse_from_element));
+ //
+ // ui element ->
+ //
+ XamlElementInfo *ui = register_ghost_element ("UIElement", NULL,
DependencyObject::UIELEMENT);
+ XamlElementInfo *fw = register_ghost_element ("FrameworkElement", ui,
DependencyObject::FRAMEWORKELEMENT);
+ XamlElementInfo *shape = register_ghost_element ("Shape", fw,
DependencyObject::SHAPE);
+
+ ///
+ /// Shapes
+ ///
+
+ register_dependency_object_element ("Ellipse", shape,
DependencyObject::ELLIPSE, (create_item_func) ellipse_new);
+ register_dependency_object_element ("Line", shape,
DependencyObject::LINE, (create_item_func) line_new);
+ register_dependency_object_element ("Path", shape,
DependencyObject::PATH, (create_item_func) path_new);
+ register_dependency_object_element ("Polygon", shape,
DependencyObject::POLYGON, (create_item_func) polygon_new);
+ register_dependency_object_element ("Polyline", shape,
DependencyObject::POLYLINE, (create_item_func) polyline_new);
+ register_dependency_object_element ("Rectangle", shape,
DependencyObject::RECTANGLE, (create_item_func) rectangle_new);
+
+ ///
+ /// Geometry
+ ///
+
+ XamlElementInfo *geo = register_ghost_element ("Geometry", NULL,
DependencyObject::GEOMETRY);
+ register_dependency_object_element ("GeometryGroup", geo,
DependencyObject::GEOMETRYGROUP, (create_item_func) geometry_group_new);
+ register_dependency_object_element ("EllipseGeometry", geo,
DependencyObject::ELLIPSEGEOMETRY, (create_item_func) ellipse_geometry_new);
+// register_dependency_object_element ("CombinedGeometry", geo,
DependencyObject::COMBINEDGEOMETRY, (create_item_func) combined_geometry_new);
+ register_dependency_object_element ("LineGeometry", geo,
DependencyObject::LINEGEOMETRY, (create_item_func) line_geometry_new);
+ register_dependency_object_element ("PathGeometry", geo,
DependencyObject::PATHGEOMETRY, (create_item_func) path_geometry_new);
+ register_dependency_object_element ("RectangleGeometry", geo,
DependencyObject::RECTANGLEGEOMETRY, (create_item_func) rectangle_geometry_new);
+// register_dependency_object_element ("StreamGeometry", geo,
DependencyObject::STREAMGEOMETRY, (create_item_func) stream_geometry_new);
+
+
+ ///
+ /// Panels
+ ///
+
+ XamlElementInfo *panel = register_ghost_element ("Panel", fw,
DependencyObject::PANEL);
+ XamlElementInfo *canvas = register_dependency_object_element ("Canvas",
panel, DependencyObject::CANVAS, (create_item_func) canvas_new);
+ canvas->add_child = panel_add_child;
+
+
+ ///
+ /// Animation
+ ///
+
+ XamlElementInfo *tl = register_ghost_element ("Timeline", NULL,
DependencyObject::TIMELINE);
+ register_dependency_object_element ("DoubleAnimation", tl,
DependencyObject::DOUBLEANIMATION, (create_item_func) double_animation_new);
+ register_dependency_object_element ("StoryBoard", tl,
DependencyObject::STORYBOARD, (create_item_func) storyboard_new);
+
+
+ ///
+ /// Transforms
+ ///
+
+ register_dependency_object_element ("RotateTransform", NULL,
DependencyObject::ROTATETRANSFORM, (create_item_func) rotate_transform_new);
+ register_dependency_object_element ("ScaleTransform", NULL,
DependencyObject::SCALETRANSFORM, (create_item_func) scale_transform_new);
+ register_dependency_object_element ("TranslateTransform", NULL,
DependencyObject::TRANSLATETRANSFORM, (create_item_func)
translate_transform_new);
+ register_dependency_object_element ("MatrixTransform", NULL,
DependencyObject::MATRIXTRANSFORM, (create_item_func) matrix_transform_new);
+
+
+ ///
+ /// Brushes
+ ///
+
+ register_element_full ("SolidColorBrush", NULL,
DependencyObject::INVALID,
+ create_solid_color_brush,
default_create_element_instance, nonpanel_add_child,
+ solid_color_brush_set_property,
solid_color_brush_set_attributes);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches