Author: miguel
Date: 2007-06-13 19:26:27 -0400 (Wed, 13 Jun 2007)
New Revision: 79526
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/animation.cpp
trunk/moon/src/animation.h
trunk/moon/src/brush.cpp
trunk/moon/src/brush.h
trunk/moon/src/clock.cpp
trunk/moon/src/clock.h
trunk/moon/src/geometry.cpp
trunk/moon/src/geometry.h
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/transform.cpp
trunk/moon/src/transform.h
Log:
reapply this, this time setting the Add/Remove methods to
virtual, sorry about that
2007-06-13 Miguel de Icaza <[EMAIL PROTECTED]>
* runtime.h (Collection): Since it seems that everything we have
so far are collections of dependency objects, the code is now
simplified and will also take refs and remove refs on destruction.
The only reason to implement the Add/Remove methods is if you must
do something as a hook during add/remove
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/ChangeLog 2007-06-13 23:26:27 UTC (rev 79526)
@@ -7,6 +7,13 @@
2007-06-13 Miguel de Icaza <[EMAIL PROTECTED]>
+ * runtime.h (Collection): Since it seems that everything we have
+ so far are collections of dependency objects, the code is now
+ simplified and will also take refs and remove refs on destruction.
+
+ The only reason to implement the Add/Remove methods is if you must
+ do something as a hook during add/remove
+
* runtime.cpp (SetValue): Enable NULLs to be set on Dependency
Objects.
Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/animation.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -543,27 +543,21 @@
}
void
-KeyFrameCollection::Add (void *data)
+KeyFrameCollection::Add (DependencyObject *data)
{
- Value *value = (Value*)data;
- KeyFrame *kf = value->AsKeyFrame();
+ KeyFrame *kf = (KeyFrame *) data;
Collection::Add (kf);
- sorted_list = g_slist_insert_sorted (sorted_list, value->AsKeyFrame(),
(GCompareFunc)compare_keyframes);
- base_ref (kf);
+ sorted_list = g_slist_insert_sorted (sorted_list, kf,
(GCompareFunc)compare_keyframes);
}
void
-KeyFrameCollection::Remove (void *data)
+KeyFrameCollection::Remove (DependencyObject *data)
{
- Value *value = (Value*)data;
- KeyFrame *kf = value->AsKeyFrame();
+ KeyFrame *kf = (KeyFrame *) data;
Collection::Remove (kf);
-
sorted_list = g_slist_remove (sorted_list, kf);
- base_unref (kf); /* XXX i suppose we should only be doing this
- if we know kf was in the list, no? */
}
KeyFrame*
@@ -827,8 +821,7 @@
{
KeyFrameCollection *keyframes = GetValue
(DoubleAnimationUsingKeyFrames::KeyFramesProperty)->AsKeyFrameCollection ();
- Value fv = Value(frame);
- keyframes->Add (&fv);
+ keyframes->Add (frame);
}
void
@@ -949,8 +942,7 @@
void
ColorAnimationUsingKeyFrames::AddKeyFrame (ColorKeyFrame *frame)
{
- Value fv = Value(frame);
- key_frames->Add (&fv);
+ key_frames->Add (frame);
}
void
@@ -1080,8 +1072,7 @@
{
KeyFrameCollection *keyframes = GetValue
(PointAnimationUsingKeyFrames::KeyFramesProperty)->AsKeyFrameCollection ();
- Value fv = Value(frame);
- keyframes->Add (&fv);
+ keyframes->Add (frame);
}
void
Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/animation.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -263,8 +263,8 @@
public:
KeyFrameCollection () : sorted_list(NULL) {}
virtual Value::Kind GetObjectType() { return
Value::KEYFRAME_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *obj);
+ virtual void Remove (DependencyObject *obj);
KeyFrame *GetKeyFrameForTime (TimeSpan t, KeyFrame **previous_frame);
Modified: trunk/moon/src/brush.cpp
===================================================================
--- trunk/moon/src/brush.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/brush.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -633,21 +633,6 @@
// GradientStopCollection
//
-void
-GradientStopCollection::Add (void *data)
-{
- Value *value = (Value*) data;
- GradientStop *gradient_stop = value->AsGradientStop ();
- Collection::Add (gradient_stop);
-}
-
-void GradientStopCollection::Remove (void *data)
-{
- Value *value = (Value*) data;
- GradientStop *gradient_stop = value->AsGradientStop ();
- Collection::Remove (gradient_stop);
-}
-
GradientStopCollection*
gradient_stop_collection_new ()
{
Modified: trunk/moon/src/brush.h
===================================================================
--- trunk/moon/src/brush.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/brush.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -138,10 +138,6 @@
public:
GradientStopCollection () {}
virtual Value::Kind GetObjectType () { return
Value::GRADIENTSTOP_COLLECTION; }
-
- virtual void Add (void *data);
- virtual void Remove (void *data);
-
};
GradientStopCollection *gradient_stop_collection_new ();
Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/clock.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -447,22 +447,6 @@
return Duration::Automatic;
}
-/* timeline collection */
-
-void
-TimelineCollection::Add (void *data)
-{
- Value *value = (Value*)data;
- Collection::Add (value->AsTimeline());
-}
-
-void
-TimelineCollection::Remove (void *data)
-{
- Value *value = (Value*)data;
- Collection::Remove (value->AsTimeline());
-}
-
/* timeline group */
DependencyProperty* TimelineGroup::ChildrenProperty;
Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/clock.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -301,8 +301,6 @@
public:
TimelineCollection () {}
virtual Value::Kind GetObjectType() { return
Value::TIMELINE_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
};
Modified: trunk/moon/src/geometry.cpp
===================================================================
--- trunk/moon/src/geometry.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/geometry.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -145,26 +145,6 @@
}
//
-// GeometryCollection
-//
-
-void
-GeometryCollection::Add (void *data)
-{
- Value *value = (Value*) data;
- Geometry *geometry = value->AsGeometry ();
- Collection::Add (geometry);
-}
-
-void
-GeometryCollection::Remove (void *data)
-{
- Value *value = (Value*) data;
- Geometry *geometry = value->AsGeometry ();
- Collection::Remove (geometry);
-}
-
-//
// EllipseGeometry
//
@@ -357,26 +337,6 @@
}
//
-// PathFigureCollection
-//
-
-void
-PathFigureCollection::Add (void *data)
-{
- Value *value = (Value*) data;
- PathFigure *pf = value->AsPathFigure ();
- Collection::Add (pf);
-}
-
-void
-PathFigureCollection::Remove (void *data)
-{
- Value *value = (Value*) data;
- PathFigure *pf = value->AsPathFigure ();
- Collection::Remove (pf);
-}
-
-//
// RectangleGeometry
//
Modified: trunk/moon/src/geometry.h
===================================================================
--- trunk/moon/src/geometry.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/geometry.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -47,9 +47,6 @@
public:
GeometryCollection () {}
virtual Value::Kind GetObjectType () { return
Value::GEOMETRY_COLLECTION; }
-
- virtual void Add (void *data);
- virtual void Remove (void *data);
};
//
@@ -119,9 +116,6 @@
public:
PathFigureCollection () {}
virtual Value::Kind GetObjectType () { return
Value::PATHFIGURE_COLLECTION; }
-
- virtual void Add (void *data);
- virtual void Remove (void *data);
};
//
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/runtime.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -64,39 +64,55 @@
}
void
-Collection::Add (void *data)
+Collection::Add (DependencyObject *data)
{
list = g_slist_append (list, data);
+ base_ref (data);
+ data->SetParent (this);
}
void
-Collection::Remove (void *data)
+Collection::Remove (DependencyObject *data)
{
- list = g_slist_remove (list, data);
-}
+ GSList *l, *prev = NULL;
+ bool found = FALSE;
-void
-Collection::Add (DependencyObject *data)
-{
- Collection::Add ((void*) data);
- data->SetParent (this);
+ // Do this by hand, so we only unref if we find the object
+ for (GSList *l = list; l != NULL; l = l->next){
+ if (l->data == data){
+ found = TRUE;
+ if (prev){
+ prev->next = l->next;
+ } else
+ list = l->next;
+ g_slist_free_1 (l);
+ break;
+ }
+ prev = l;
+ }
+ data->SetParent (NULL);
+ if (found){
+ base_unref (data);
+ }
}
-void
-Collection::Remove (DependencyObject *data)
+Collection::~Collection ()
{
- Collection::Remove ((void*) data);
- data->SetParent (NULL);
+ GSList *sl;
+
+ for (sl = list; sl != NULL; sl = sl->next){
+ base_unref ((Base *) sl->data);
+ }
}
void
-collection_add (Collection *collection, void *data)
+collection_add (Collection *collection, DependencyObject *data)
{
collection->Add (data);
}
void
-collection_remove (Collection *collection, void *data)
+collection_remove (Collection *collection, DependencyObject *data)
{
collection->Remove (data);
}
@@ -519,6 +535,7 @@
for (GSList *l = triggers->list; l != NULL; l =
l->next){
DependencyObject *dob =
(DependencyObject *) l->data;
+ printf ("Unrefing a %d\n",
dob->GetObjectType ());
base_unref (dob);
}
base_unref (triggers);
@@ -707,16 +724,12 @@
}
void
-VisualCollection::Add (void *data)
+VisualCollection::Add (DependencyObject *data)
{
Panel *panel = (Panel *) closure;
- Value *v = (Value *) data;
- UIElement *item = v->AsUIElement();
+ UIElement *item = (UIElement *) data;
- base_ref (item);
-
- // Add the UIElement, not the Value
Collection::Add (item);
item->parent = panel;
@@ -726,26 +739,20 @@
}
void
-VisualCollection::Remove (void *data)
+VisualCollection::Remove (DependencyObject *data)
{
Panel *panel = (Panel *) closure;
- Value *v = (Value *) data;
- UIElement *item = v->AsUIElement();
+ UIElement *item = (UIElement *) data;
- Collection::Remove (item);
-
item_invalidate (item);
- base_unref (item);
-
+ Collection::Remove (item);
item_update_bounds (panel);
}
void
panel_child_add (Panel *panel, UIElement *child)
{
- Value v(child);
-
- collection_add (panel->children, &v);
+ collection_add (panel->children, child);
}
Panel::Panel ()
@@ -1277,6 +1284,7 @@
Value *current_value = (Value*)g_hash_table_lookup (current_values,
property->name);
if (current_value != NULL && current_value->k >=
Value::DEPENDENCY_OBJECT) {
+ printf ("Setting null: SetValue\n");
current_value->AsDependencyObject ()->SetParent (NULL);
}
if (value != NULL && value->k >= Value::DEPENDENCY_OBJECT) {
@@ -1727,12 +1735,11 @@
}
void
-TriggerCollection::Add (void *data)
+TriggerCollection::Add (DependencyObject *data)
{
FrameworkElement *fwe = (FrameworkElement *) closure;
- Value *v = (Value *) data;
- EventTrigger *trigger = v->AsEventTrigger ();
+ EventTrigger *trigger = (EventTrigger *) data;
Collection::Add (trigger);
@@ -1740,40 +1747,17 @@
}
void
-TriggerCollection::Remove (void *data)
+TriggerCollection::Remove (DependencyObject *data)
{
FrameworkElement *fwe = (FrameworkElement *) closure;
- Value *v = (Value *) data;
- EventTrigger *trigger = v->AsEventTrigger ();
+ EventTrigger *trigger = (EventTrigger *) data;
Collection::Remove (trigger);
trigger->RemoveTarget (fwe);
}
-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);
-}
-
VisualCollection *
visual_collection_new ()
{
@@ -1891,8 +1875,8 @@
void
event_trigger_action_add (EventTrigger *trigger, TriggerAction *action)
{
- Value v (action);
- trigger->actions->Add (&v);
+ printf ("Adding action\n");
+ trigger->actions->Add (action);
}
void
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/runtime.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -373,26 +373,26 @@
void *closure;
Collection () : list(NULL), closure(NULL) {}
+ ~Collection ();
Value::Kind GetObjectType () { return Value::COLLECTION; };
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
- protected:
- void Add (DependencyObject *data);
- void Remove (DependencyObject *data);
+ void Add (Value *v) { Add (v->AsDependencyObject ()); };
+ void Remove (Value *v) { Remove (v->AsDependencyObject ()); };
};
-void collection_add (Collection *collection, void *data);
-void collection_remove (Collection *collection, void *data);
+void collection_add (Collection *collection, DependencyObject *data);
+void collection_remove (Collection *collection, DependencyObject *data);
class VisualCollection : public Collection {
public:
VisualCollection () {}
virtual Value::Kind GetObjectType () { return Value::VISUAL_COLLECTION;
}
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
class TriggerCollection : public Collection {
@@ -400,17 +400,14 @@
TriggerCollection () {}
virtual Value::Kind GetObjectType () { return
Value::TRIGGER_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *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 ResourceCollection : public Collection {
@@ -418,8 +415,8 @@
ResourceCollection () {}
virtual Value::Kind GetObjectType () { return
Value::RESOURCE_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
@@ -428,8 +425,8 @@
StrokeCollection () {}
virtual Value::Kind GetObjectType () { return Value::STROKE_COLLECTION;
}
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
@@ -438,8 +435,8 @@
StylusPointCollection () {}
virtual Value::Kind GetObjectType () { return
Value::STYLUSPOINT_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
@@ -448,8 +445,8 @@
TimelineMarkerCollection () {}
virtual Value::Kind GetObjectType () { return
Value::TIMELINEMARKER_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
@@ -458,8 +455,8 @@
MediaAttributeCollection () {}
virtual Value::Kind GetObjectType () { return
Value::MEDIAATTRIBUTE_COLLECTION; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
@@ -468,8 +465,8 @@
Inlines () {}
virtual Value::Kind GetObjectType () { return Value::INLINES; }
- virtual void Add (void *data);
- virtual void Remove (void *data);
+ virtual void Add (DependencyObject *data);
+ virtual void Remove (DependencyObject *data);
};
Modified: trunk/moon/src/transform.cpp
===================================================================
--- trunk/moon/src/transform.cpp 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/transform.cpp 2007-06-13 23:26:27 UTC (rev 79526)
@@ -343,26 +343,6 @@
return (value ? value->AsMatrix() : NULL);
}
-
-
-void
-TransformCollection::Add (void *data)
-{
- Value *v = (Value *) data;
- Transform *transform = v->AsTransform ();
-
- Collection::Add (transform);
-}
-
-void
-TransformCollection::Remove (void *data)
-{
- Value *v = (Value *) data;
- Transform *transform = v->AsTransform ();
-
- Collection::Remove (transform);
-}
-
DependencyProperty* TransformGroup::ChildrenProperty;
TransformGroup::TransformGroup ()
Modified: trunk/moon/src/transform.h
===================================================================
--- trunk/moon/src/transform.h 2007-06-13 23:12:17 UTC (rev 79525)
+++ trunk/moon/src/transform.h 2007-06-13 23:26:27 UTC (rev 79526)
@@ -140,9 +140,6 @@
public:
TransformCollection () {}
virtual Value::Kind GetObjectType () { return
Value::TRANSFORM_COLLECTION; }
-
- virtual void Add (void *data);
- virtual void Remove (void *data);
};
class TransformGroup : public Transform {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches