Make sure at least one position change event is emitted after
[dcpomatic.git] / src / lib / dkdm_wrapper.cc
index 316a0581ee058418291a164345b19b702fff9ae6..76f9217aac4a64d3b6f589aa20290511a66ddad4 100644 (file)
@@ -71,10 +71,19 @@ DKDMGroup::as_xml (xmlpp::Element* node) const
 }
 
 void
-DKDMGroup::add (shared_ptr<DKDMBase> child)
+DKDMGroup::add (shared_ptr<DKDMBase> child, shared_ptr<DKDM> previous)
 {
        DCPOMATIC_ASSERT (child);
-       _children.push_back (child);
+       if (previous) {
+               list<shared_ptr<DKDMBase> >::iterator i = find (_children.begin(), _children.end(), previous);
+               if (i != _children.end ()) {
+                       ++i;
+               }
+               _children.insert (i, child);
+       } else {
+               _children.push_back (child);
+       }
+       child->set_parent (dynamic_pointer_cast<DKDMGroup> (shared_from_this ()));
 }
 
 void
@@ -83,6 +92,7 @@ DKDMGroup::remove (shared_ptr<DKDMBase> child)
        for (list<shared_ptr<DKDMBase> >::iterator i = _children.begin(); i != _children.end(); ++i) {
                if (*i == child) {
                        _children.erase (i);
+                       child->set_parent (shared_ptr<DKDMGroup> ());
                        return;
                }
                shared_ptr<DKDMGroup> g = dynamic_pointer_cast<DKDMGroup> (*i);