Author: toshok
Date: 2008-02-06 00:26:20 -0500 (Wed, 06 Feb 2008)
New Revision: 94993

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/collection.cpp
   trunk/moon/src/collection.h
   trunk/moon/src/type.cpp
   trunk/moon/src/type.cpp.in
   trunk/moon/src/type.h
   trunk/moon/src/type.h.in
Log:
2008-02-05  Chris Toshok  <[EMAIL PROTECTED]>

        * collection.cpp (Collection::EmitChanged): new method.  Emit the
        Changed event and then call closure->OnCollectionChanged.

        * collection.h (class Collection): add ChangeEventArgs struct, and
        an EmitChanged method declaration.

        * type.h.in, type.cpp.in (Type::~Type): no need to free all the
        events explicitly.
        (Type::HideEvent): remove the event name from the hash so it's
        inaccessible from javascript.
        (Type::RegisterEvent): use g_hash_table_new_full so we can specify
        a destroy function for keys instead of doing the _foreach in the dtor.
        (types_init_manually): add the #if 0 here instead of type.cpp.  oops.
        (types_init_register_events): register a Changed event for
        Collections.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/ChangeLog    2008-02-06 05:26:20 UTC (rev 94993)
@@ -1,3 +1,20 @@
+2008-02-05  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * collection.h (class Collection): add ChangeEventArgs struct, and
+       an EmitChanged method declaration.
+
+       * type.h.in, type.cpp.in (Type::~Type): no need to free all the
+       events explicitly.
+       (Type::HideEvent): remove the event name from the hash so it's
+       inaccessible from javascript.
+       (Type::RegisterEvent): use g_hash_table_new_full so we can specify
+       a destroy function for keys instead of doing the _foreach in the
+       dtor.
+       (types_init_manually): add the #if 0 here instead of type.cpp.
+       oops.
+       (types_init_register_events): register a Changed event for
+       Collections.
+
 2008-02-05  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * downloader.cpp (Downloader::ll_downloader_get_response_file):

Modified: trunk/moon/src/collection.cpp
===================================================================
--- trunk/moon/src/collection.cpp       2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/collection.cpp       2008-02-06 05:26:20 UTC (rev 94993)
@@ -44,7 +44,6 @@
        return cn->obj == (DependencyObject *) data;
 }
 
-
 Collection::Collection ()
 {
        list = new List ();
@@ -63,6 +62,19 @@
        delete list;
 }
 
+void
+Collection::EmitChanged (CollectionChangeType type, DependencyObject *obj, 
DependencyProperty *prop)
+{
+       Collection::ChangeEventArgs args;
+       args.type = type;
+       args.obj = obj;
+       args.prop = prop;
+       Emit (ChangedEvent, &args);
+
+       if (closure)
+               closure->OnCollectionChanged (this, type, obj, prop);
+}
+
 bool
 Collection::Add (DependencyObject *data)
 {
@@ -94,7 +106,7 @@
                        }
                }
 
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemAdded, data, NULL);
+               EmitChanged (CollectionChangeTypeItemAdded, data, NULL);
        }
 
        return true;
@@ -122,7 +134,7 @@
                                con_ns->MergeTemporaryScope (ns);
                }
 
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemAdded, data, NULL);
+               EmitChanged (CollectionChangeTypeItemAdded, data, NULL);
        }
 
        return true;
@@ -131,11 +143,9 @@
 void
 Collection::OnSubPropertyChanged (DependencyProperty *prop, DependencyObject 
*obj, DependencyProperty *subprop)
 {
-       if (closure) {
-               /* unfortunately OnSubPropertyChanged doesn't give us
-                  enough info to fill in the obj parameter here */
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemChanged, obj, subprop);
-       }
+       /* unfortunately OnSubPropertyChanged doesn't give us
+          enough info to fill in the obj parameter here */
+       EmitChanged (CollectionChangeTypeItemChanged, obj, subprop);
 }
 
 DependencyObject *
@@ -154,8 +164,8 @@
        old->obj->Detach (NULL, this);
        
        if (closure) {
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemRemoved, old->obj, NULL);
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemAdded, data, NULL);
+               EmitChanged (CollectionChangeTypeItemRemoved, old->obj, NULL);
+               EmitChanged (CollectionChangeTypeItemAdded, data, NULL);
        }
 
        DependencyObject *obj = old->obj;
@@ -193,7 +203,7 @@
                                con_ns->UnmergeTemporaryScope (ns);
                }
 
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemRemoved, data, NULL);
+               EmitChanged (CollectionChangeTypeItemRemoved, data, NULL);
        }
        
        delete n;
@@ -222,7 +232,7 @@
                                con_ns->UnmergeTemporaryScope (ns);
                }
 
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeItemRemoved, n->obj, NULL);
+               EmitChanged (CollectionChangeTypeItemRemoved, n->obj, NULL);
        }
        
        delete n;
@@ -248,16 +258,22 @@
 
        list->Clear (true);
 
-       if (closure)
-               closure->OnCollectionChanged (this, 
CollectionChangeTypeChanged, NULL, NULL);
+       EmitChanged (CollectionChangeTypeChanged, NULL, NULL);
 }
 
 DependencyProperty *Collection::CountProperty;
 
+int Collection::ChangedEvent = -1;
+
 void
 collection_init (void)
 {
        Collection::CountProperty = DependencyObject::Register 
(Type::COLLECTION, "Count", Type::INT32);
+
+       Type *t = Type::Find (Type::COLLECTION);
+       Collection::ChangedEvent = t->LookupEvent 
("__moonlight_CollectionChanged");
+       // make this event inaccessible to javascript.
+       t->HideEvent ("__moonlight_CollectionChanged");
 }
 
 bool

Modified: trunk/moon/src/collection.h
===================================================================
--- trunk/moon/src/collection.h 2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/collection.h 2008-02-06 05:26:20 UTC (rev 94993)
@@ -22,6 +22,12 @@
 //
 class Collection : public DependencyObject {
  public:
+       struct ChangeEventArgs {
+               CollectionChangeType type;
+               DependencyObject *obj;
+               DependencyProperty *prop;
+       };
+
        class Node : public List::Node {
        public:
                DependencyObject *obj, *parent;
@@ -54,7 +60,12 @@
        
        virtual void OnSubPropertyChanged (DependencyProperty *prop, 
DependencyObject *obj, DependencyProperty *subprop);
 
+       void EmitChanged (CollectionChangeType type, DependencyObject *obj, 
DependencyProperty *prop);
+
        static DependencyProperty *CountProperty;
+
+       // Events you can AddHandler to
+       static int ChangedEvent;
 };
 
 bool CollectionNodeFinder (List::Node *n, void *data);

Modified: trunk/moon/src/type.cpp
===================================================================
--- trunk/moon/src/type.cpp     2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/type.cpp     2008-02-06 05:26:20 UTC (rev 94993)
@@ -64,10 +64,8 @@
 
 Type::~Type()
 {
-       if (event_name_hash) {
-               g_hash_table_foreach (event_name_hash, (GHFunc)g_free, NULL);
+       if (event_name_hash)
                g_hash_table_destroy (event_name_hash);
-       }
 
        event_name_hash = NULL;
 
@@ -75,10 +73,19 @@
 }
 
 void
+Type::HideEvent (const char *event_name)
+{
+       if (event_name_hash)
+               g_hash_table_remove (event_name_hash, event_name);
+}
+
+void
 Type::RegisterEvent (const char *event_name)
 {
        if (event_name_hash == NULL)
-               event_name_hash = g_hash_table_new (strcase_hash, 
strcase_equal);
+               event_name_hash = g_hash_table_new_full (strcase_hash, 
strcase_equal,
+                                                        (GDestroyNotify)g_free,
+                                                        NULL);
 
        g_hash_table_insert (event_name_hash, g_strdup (event_name), 
GINT_TO_POINTER (local_event_count++));
 }
@@ -88,10 +95,10 @@
 {
        gpointer key, value;
        if (event_name_hash &&
-                        g_hash_table_lookup_extended (event_name_hash,
-                                       event_name,
-                                       &key,
-                                       &value)) {
+           g_hash_table_lookup_extended (event_name_hash,
+                                         event_name,
+                                         &key,
+                                         &value)) {
 
                return GPOINTER_TO_INT (value) + GetEventBase();
        }
@@ -382,6 +389,9 @@
        t->RegisterEvent ("Invalidated");
        t->RegisterEvent ("GotFocus");
        t->RegisterEvent ("LostFocus");
+
+       t = Type::Find(Type::COLLECTION);
+       t->RegisterEvent ("__moonlight_CollectionChanged");
 }
 
 //

Modified: trunk/moon/src/type.cpp.in
===================================================================
--- trunk/moon/src/type.cpp.in  2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/type.cpp.in  2008-02-06 05:26:20 UTC (rev 94993)
@@ -59,10 +59,8 @@
 
 Type::~Type()
 {
-       if (event_name_hash) {
-               g_hash_table_foreach (event_name_hash, (GHFunc)g_free, NULL);
+       if (event_name_hash)
                g_hash_table_destroy (event_name_hash);
-       }
 
        event_name_hash = NULL;
 
@@ -70,10 +68,19 @@
 }
 
 void
+Type::HideEvent (const char *event_name)
+{
+       if (event_name_hash)
+               g_hash_table_remove (event_name_hash, event_name);
+}
+
+void
 Type::RegisterEvent (const char *event_name)
 {
        if (event_name_hash == NULL)
-               event_name_hash = g_hash_table_new (strcase_hash, 
strcase_equal);
+               event_name_hash = g_hash_table_new_full (strcase_hash, 
strcase_equal,
+                                                        (GDestroyNotify)g_free,
+                                                        NULL);
 
        g_hash_table_insert (event_name_hash, g_strdup (event_name), 
GINT_TO_POINTER (local_event_count++));
 }
@@ -83,10 +90,10 @@
 {
        gpointer key, value;
        if (event_name_hash &&
-                        g_hash_table_lookup_extended (event_name_hash,
-                                       event_name,
-                                       &key,
-                                       &value)) {
+           g_hash_table_lookup_extended (event_name_hash,
+                                         event_name,
+                                         &key,
+                                         &value)) {
 
                return GPOINTER_TO_INT (value) + GetEventBase();
        }
@@ -300,7 +307,7 @@
        Type::RegisterType ("SystemTimeSource", Type::SYSTEMTIMESOURCE, 
Type::TIMESOURCE);
        Type::RegisterType ("TimeManager", Type::TIMEMANAGER, 
Type::EVENTOBJECT);
        Type::RegisterType ("Surface", Type::SURFACE, Type::EVENTOBJECT);
-#if DEBUG
+#if 0 && DEBUG
        for (int i = 1; i < Type::LASTTYPE; i++) {
                if (Type::types [i] != NULL)
                        continue;
@@ -377,6 +384,9 @@
        t->RegisterEvent ("Invalidated");
        t->RegisterEvent ("GotFocus");
        t->RegisterEvent ("LostFocus");
+
+       t = Type::Find(Type::COLLECTION);
+       t->RegisterEvent ("__moonlight_CollectionChanged");
 }
 
 //

Modified: trunk/moon/src/type.h
===================================================================
--- trunk/moon/src/type.h       2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/type.h       2008-02-06 05:26:20 UTC (rev 94993)
@@ -187,6 +187,7 @@
        char *name;
        bool value_type;
 
+       void HideEvent (const char *event_name);
        void RegisterEvent (const char *event_name);
        int LookupEvent (const char *event_name);
        int GetEventCount ();

Modified: trunk/moon/src/type.h.in
===================================================================
--- trunk/moon/src/type.h.in    2008-02-06 05:17:55 UTC (rev 94992)
+++ trunk/moon/src/type.h.in    2008-02-06 05:26:20 UTC (rev 94993)
@@ -68,6 +68,7 @@
        char *name;
        bool value_type;
 
+       void HideEvent (const char *event_name);
        void RegisterEvent (const char *event_name);
        int LookupEvent (const char *event_name);
        int GetEventCount ();

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

Reply via email to