Author: zoltan
Date: 2007-09-22 11:11:02 -0400 (Sat, 22 Sep 2007)
New Revision: 86208

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/xaml.cpp
   trunk/moon/src/xaml.h
Log:
2007-09-22  Zoltan Varga  <[EMAIL PROTECTED]>

        * xaml.h xaml.cpp: Add support for parsing x:Code elements and passing 
them to
        managed code.


Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-09-22 14:40:59 UTC (rev 86207)
+++ trunk/moon/src/ChangeLog    2007-09-22 15:11:02 UTC (rev 86208)
@@ -1,3 +1,8 @@
+2007-09-22  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * xaml.h xaml.cpp: Add support for parsing x:Code elements and passing 
them to
+       managed code.
+
 2007-09-21  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * mplayer.cpp (audio_play): Slightly optimized the volume

Modified: trunk/moon/src/xaml.cpp
===================================================================
--- trunk/moon/src/xaml.cpp     2007-09-22 14:40:59 UTC (rev 86207)
+++ trunk/moon/src/xaml.cpp     2007-09-22 15:11:02 UTC (rev 86208)
@@ -64,8 +64,9 @@
 void  custom_add_child (XamlParserInfo *p, XamlElementInstance *parent, 
XamlElementInstance *child);
 void  custom_set_property (XamlParserInfo *p, XamlElementInstance *item, 
XamlElementInstance *property, XamlElementInstance *value);
 
+XamlElementInstance *create_x_code_directive_element (XamlParserInfo *p, 
XamlElementInfo *i);
+void process_x_code_directive (XamlParserInfo *p, const char **attr);
 
-
 class XamlElementInstance : public List::Node {
  public:
        const char *element_name;
@@ -79,6 +80,7 @@
        enum ElementType {
                ELEMENT,
                PROPERTY,
+               X_CODE_DIRECTIVE,
                UNKNOWN
        };
 
@@ -241,13 +243,13 @@
  public:
        GHashTable *element_map;
 
-       XNamespace () { }
+       XNamespace (GHashTable *element_map) : element_map (element_map) { }
 
        virtual ~XNamespace () { }
 
        virtual XamlElementInfo* FindElement (XamlParserInfo *p, const char *el)
        {
-               return NULL;
+               return (XamlElementInfo *) g_hash_table_lookup (element_map, 
el);
        }
 
        virtual void SetAttribute (XamlParserInfo *p, XamlElementInstance 
*item, const char *attr, const char *value, bool *reparse)
@@ -487,6 +489,13 @@
                return NULL;
 }
 
+void
+XamlLoader::LoadCode (const char *source, const char *type)
+{
+       if (callbacks.load_code)
+               return callbacks.load_code (source, type);
+}
+
 XamlLoader::XamlLoader (const char* filename, const char* str, Surface* 
surface)
 {
        this->filename = g_strdup (filename);
@@ -594,6 +603,35 @@
 
 }
 
+XamlElementInstance *
+create_x_code_directive_element (XamlParserInfo *p, XamlElementInfo *i)
+{
+       XamlElementInstance *inst = new XamlElementInstance (i);
+       inst->element_type = XamlElementInstance::X_CODE_DIRECTIVE;
+
+       return inst;
+}
+
+void
+process_x_code_directive (XamlParserInfo *p, const char **attr)
+{
+       const char *source = NULL;
+       const char *type = NULL;
+       int i;
+
+       i = 0;
+       while (attr [i]) {
+               if (!strcmp (attr [i], "Source"))
+                       source = attr [i + 1];
+               else if (!strcmp (attr [i], "Type"))
+                       type = attr [i + 1];
+               i += 2;
+       }
+
+       if (p->loader)
+               p->loader->LoadCode (source, type);
+}
+
 bool
 is_instance_of (XamlElementInstance *item, Type::Kind kind)
 {
@@ -655,9 +693,19 @@
 
                inst = elem->create_element (p, elem);
 
-               if (!inst || !inst->item)
+               if (!inst)
                        return;
 
+               if (inst->element_type == 
XamlElementInstance::X_CODE_DIRECTIVE) {
+                       process_x_code_directive (p, attr);
+                       inst->parent = p->current_element;
+                       p->current_element = inst;
+                       return;
+               }
+
+               if (!inst->item)
+                       return;
+
                if (!p->top_element) {
                        set_top = true;
 
@@ -812,7 +860,7 @@
        case XamlElementInstance::ELEMENT:
                flush_char_data (info);
                break;
-       case XamlElementInstance::PROPERTY:
+       case XamlElementInstance::PROPERTY: {
                List::Node *walk = info->current_element->children->First ();
                while (walk) {
                        XamlElementInstance *child = (XamlElementInstance *) 
walk;
@@ -826,6 +874,10 @@
                }
                break;
        }
+       case XamlElementInstance::X_CODE_DIRECTIVE:
+               /* Nothing to do */
+               break;
+       }
 
        info->current_element = info->current_element->parent;
 }
@@ -2584,10 +2636,23 @@
        return res;
 }
 
+XamlElementInfo *
+register_x_code_element (GHashTable *table)
+{
+       XamlElementInfo *res = new XamlElementInfo ("Code", NULL, 
Type::INVALID);
+
+       res->create_element = create_x_code_directive_element;
+
+       g_hash_table_insert (table, (char *) "Code", res);
+
+       return res;
+}
+
 void
 xaml_init (void)
 {
        GHashTable *dem = g_hash_table_new (g_str_hash, g_str_equal); // 
default element map
+       GHashTable *x_dem = g_hash_table_new (g_str_hash, g_str_equal); // x 
element map
        enum_map = g_hash_table_new (g_str_hash, g_str_equal);
 
        XamlElementInfo *col = register_ghost_element ("Collection", NULL, 
Type::COLLECTION);
@@ -2800,12 +2865,17 @@
        rdoe (dem, "InkPresenter", canvas, Type::INKPRESENTER, 
(create_item_func) ink_presenter_new);
        rdoe (dem, "StrokeCollection", col, Type::STROKE_COLLECTION, 
(create_item_func) stroke_collection_new);
        rdoe (dem, "StylusPointCollection", col, Type::STYLUSPOINT_COLLECTION, 
(create_item_func) stylus_point_collection_new);
+
+       //
+       // Code
+       //
+       // FIXME: Make this v1.1 only
+       register_x_code_element (x_dem);
        
 #undef rdoe
        
        default_namespace = new DefaultNamespace (dem);
-       x_namespace = new XNamespace ();
-
+       x_namespace = new XNamespace (x_dem);
        
        ///
        /// ENUMS

Modified: trunk/moon/src/xaml.h
===================================================================
--- trunk/moon/src/xaml.h       2007-09-22 14:40:59 UTC (rev 86207)
+++ trunk/moon/src/xaml.h       2007-09-22 15:11:02 UTC (rev 86208)
@@ -24,6 +24,7 @@
 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);
+typedef void xaml_load_code_callback (const char *source, const char *type);
 
 G_BEGIN_DECLS
 
@@ -50,11 +51,12 @@
        xaml_hookup_event_callback *hookup_event;
        xaml_get_mapping_callback *get_mapping;
        xaml_insert_mapping_callback *insert_mapping;
-       
+       xaml_load_code_callback *load_code;
+
        XamlLoaderCallbacks () :
                load_managed_object (NULL), set_custom_attribute (NULL),
                hookup_event (NULL), get_mapping (NULL),
-               insert_mapping (NULL)
+               insert_mapping (NULL), load_code (NULL)
        {
        }
 };
@@ -114,6 +116,7 @@
        virtual bool HookupEvent (void* target, const char* name, const char* 
value);
        virtual void InsertMapping (const char* key, const char* value);
        const char* GetMapping (const char* key);
+       void LoadCode (const char *source, const char *type);
        
        char* GetFilename () { return filename; }
        char* GetString () { return str; }

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

Reply via email to