Author: jackson
Date: 2007-06-09 09:26:27 -0400 (Sat, 09 Jun 2007)
New Revision: 79043

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
   trunk/moon/src/value.h
Log:

        * value.h:
        * runtime.cpp|h: Use the new collection classes for triggers and
        actions. These are unsettable, so don't register them as
        DependencyProperties.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-09 13:03:20 UTC (rev 79042)
+++ trunk/moon/src/ChangeLog    2007-06-09 13:26:27 UTC (rev 79043)
@@ -1,3 +1,10 @@
+2007-06-09  Jackson Harper  <[EMAIL PROTECTED]>
+
+       * value.h:
+       * runtime.cpp|h: Use the new collection classes for triggers and
+       actions. These are unsettable, so don't register them as
+       DependencyProperties.
+
 2007-06-08  Everaldo Canuto  <[EMAIL PROTECTED]>
 
        * runtime.cpp: In surface_destroy check for toplevel before unref

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-09 13:03:20 UTC (rev 79042)
+++ trunk/moon/src/runtime.cpp  2007-06-09 13:26:27 UTC (rev 79043)
@@ -400,6 +400,8 @@
 
 AS_DEP_SUBCLASS_IMPL(COLLECTION, Collection)
 AS_DEP_SUBCLASS_IMPL(VISUAL_COLLECTION, VisualCollection)
+AS_DEP_SUBCLASS_IMPL(TRIGGER_COLLECTION, TriggerCollection)
+AS_DEP_SUBCLASS_IMPL(TRIGGERACTION_COLLECTION, TriggerActionCollection)
 
 
 
@@ -533,13 +535,16 @@
        item->SetValue (UIElement::RenderTransformProperty, Value(transform));
 }
 
+FrameworkElement::FrameworkElement ()
+{
+       triggers = new TriggerCollection ();
+}
+
 void 
 framework_element_trigger_add (FrameworkElement *element, EventTrigger 
*trigger)
 {
-       EventTrigger *action = (EventTrigger *) trigger;
-
-       trigger->SetTarget (element);
-       collection_add (&element->triggers, trigger);
+       Value v (trigger);
+       element->triggers->Add (&v);
 }
 
 double
@@ -1341,14 +1346,58 @@
 }
 
 void
-EventTrigger::AddAction (TriggerAction *action)
+TriggerCollection::Add (void *data)
 {
-       g_assert (action);
+       FrameworkElement *fwe = (FrameworkElement *) closure;
+       
+       Value *v = (Value *) data;
+       EventTrigger *trigger = v->AsEventTrigger ();
 
-       actions = g_slist_append (actions, action);
+       Collection::Add (trigger);
+
+       trigger->SetTarget (fwe);
 }
 
 void
+TriggerCollection::Remove (void *data)
+{
+       FrameworkElement *fwe = (FrameworkElement *) closure;
+       
+       Value *v = (Value *) data;
+       EventTrigger *trigger = v->AsEventTrigger ();
+
+       Collection::Remove (trigger);
+}
+
+void
+TriggerActionCollection::Add (void *data)
+{
+       EventTrigger *trigger = (EventTrigger *) closure;
+       
+       Value *v = (Value *) data;
+       TriggerAction *action = v->AsTriggerAction ();
+
+       Collection::Add (action);
+}
+
+void
+TriggerActionCollection::Remove (void *data)
+{
+       EventTrigger *trigger = (EventTrigger *) closure;
+       
+       Value *v = (Value *) data;
+       TriggerAction *action = v->AsTriggerAction ();
+
+       Collection::Remove (action);
+}
+
+
+EventTrigger::EventTrigger () : routed_event (NULL)
+{
+       actions = new TriggerActionCollection ();
+}
+
+void
 EventTrigger::SetTarget (DependencyObject *target)
 {
        g_assert (target);
@@ -1357,6 +1406,14 @@
        target->events->AddHandler ("Loaded", (EventHandler) 
event_trigger_fire_actions, this);
 }
 
+void
+EventTrigger::RemoveTarget (DependencyObject *target)
+{
+       g_assert (target);
+
+       target->events->RemoveHandler ("Loaded", (EventHandler) 
event_trigger_fire_actions, this);
+}
+
 EventTrigger *
 event_trigger_new ()
 {
@@ -1366,10 +1423,8 @@
 void
 event_trigger_action_add (EventTrigger *trigger, TriggerAction *action)
 {
-       g_return_if_fail (trigger);
-       g_return_if_fail (action);
-
-       trigger->AddAction (action);
+       Value v (action);
+       trigger->actions->Add (&v);
 }
 
 void
@@ -1377,7 +1432,7 @@
 {
        g_assert (trigger);
 
-       for (GSList *walk = trigger->actions; walk != NULL; walk = walk->next) {
+       for (GSList *walk = trigger->actions->list; walk != NULL; walk = 
walk->next) {
                TriggerAction *action = (TriggerAction *) walk->data;
                action->Fire ();
        }

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-09 13:03:20 UTC (rev 79042)
+++ trunk/moon/src/runtime.h    2007-06-09 13:26:27 UTC (rev 79043)
@@ -332,6 +332,24 @@
        virtual void Remove (void *data);
 };
 
+class TriggerCollection : public Collection {
+ public:
+       TriggerCollection () {}
+       virtual Value::Kind GetObjectType () { return 
Value::TRIGGER_COLLECTION; }
+
+       virtual void Add    (void *data);
+       virtual void Remove (void *data);
+};
+
+class TriggerActionCollection : public Collection {
+ public:
+       TriggerActionCollection () {}
+       virtual Value::Kind GetObjectType () { return 
Value::TRIGGERACTION_COLLECTION; }
+
+       virtual void Add    (void *data);
+       virtual void Remove (void *data);
+};
+
 class Brush : public DependencyObject {
  public:
        static DependencyProperty* OpacityProperty;
@@ -416,7 +434,7 @@
        TriggerAction () { };
 
        Value::Kind GetObjectType () { return Value::TRIGGERACTION; };
-       virtual void Fire () = 0;
+       virtual void Fire () = 0;
 };
 
 
@@ -424,17 +442,14 @@
 
  public:
        char *routed_event;
-       GSList *actions;
+       TriggerActionCollection *actions;
 
-       EventTrigger () : routed_event (NULL), actions (NULL)
-       {
-       }
+       EventTrigger ();
 
        Value::Kind GetObjectType () { return Value::EVENTTRIGGER; };
 
-       void AddAction (TriggerAction *action);
-
        void SetTarget (DependencyObject *target);
+       void RemoveTarget (DependencyObject *target);
 };
 
 EventTrigger  *event_trigger_new ();
@@ -549,9 +564,9 @@
        static DependencyProperty* HeightProperty;
        static DependencyProperty* WidthProperty;
 
-       Collection triggers;
+       TriggerCollection *triggers;
 
-       FrameworkElement () {} 
+       FrameworkElement ();
 };
 
 double framework_element_get_height    (FrameworkElement *framework_element);

Modified: trunk/moon/src/value.h
===================================================================
--- trunk/moon/src/value.h      2007-06-09 13:03:20 UTC (rev 79042)
+++ trunk/moon/src/value.h      2007-06-09 13:26:27 UTC (rev 79043)
@@ -74,6 +74,8 @@
 
 class Collection;
 class VisualCollection;
+class TriggerCollection;
+class TriggerActionCollection;
 
 struct Value {
 public:
@@ -294,6 +296,8 @@
 
        Collection*                   AsCollection ();
        VisualCollection*             AsVisualCollection ();
+       TriggerCollection*            AsTriggerCollection ();
+       TriggerActionCollection*      AsTriggerActionCollection ();
 
   
        Kind k;

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

Reply via email to