// XXX this was (mostly, except for the type check) c&p from DependencyObjectCollection void ResourceDictionary::OnIsAttachedChanged (bool attached) { Collection::OnIsAttachedChanged (attached); Value *value; for (guint i = 0; i < array->len; i++) { value = (Value *) array->pdata[i]; if (value->Is (GetDeployment (), Type::DEPENDENCY_OBJECT)) { DependencyObject *obj = value->AsDependencyObject (); if (obj) obj->SetIsAttached (attached); } } }
// XXX this was (mostly, except for the type check) c&p from DependencyObjectCollection void ResourceDictionary::RemovedFromCollection (Value *value, bool is_value_safe) { if (is_value_safe & value->Is (GetDeployment (), Type::DEPENDENCY_OBJECT)) { DependencyObject *obj = value->AsDependencyObject (); if (obj) { obj->RemovePropertyChangeListener (this); obj->RemoveParent (this, NULL); obj->SetIsAttached (false); } } Collection::RemovedFromCollection (value, is_value_safe); if (is_value_safe && value->Is (GetDeployment (), Type::DEPENDENCY_OBJECT)) { if (!from_resource_dictionary_api && value->AsDependencyObject()) { g_hash_table_foreach_remove (hash, remove_from_hash_by_value, value->AsDependencyObject ()); // FIXME we need to EmitChanged something here so the managed RD can remain in sync } } }
// XXX this was (mostly, except for the type check) c&p from DependencyObjectCollection bool ResourceDictionary::AddedToCollection (Value *value, MoonError *error) { DependencyObject *obj = NULL; bool rv = false; if (value->Is(GetDeployment (), Type::DEPENDENCY_OBJECT)) { obj = value->AsDependencyObject (); // Call SetSurface() /before/ setting the logical parent // because Storyboard::SetSurface() needs to be able to // distinguish between the two cases. if (obj->GetParent () && !can_be_added_twice (GetDeployment (), value)) { MoonError::FillIn (error, MoonError::INVALID_OPERATION, g_strdup_printf ("Element is already a child of another element. %s", GetTypeName ())); return false; } obj->AddParent (this, error); if (error->number) return false; obj->SetIsAttached (IsAttached ()); obj->AddPropertyChangeListener (this); if (!from_resource_dictionary_api) { const char *key = obj->GetName(); if (!key) { MoonError::FillIn (error, MoonError::ARGUMENT_NULL, "key was null"); goto cleanup; } if (ContainsKey (key)) { MoonError::FillIn (error, MoonError::ARGUMENT, "An item with the same key has already been added"); goto cleanup; } } } rv = Collection::AddedToCollection (value, error); if (rv && !from_resource_dictionary_api && obj != NULL) { const char *key = obj->GetName(); Value *obj_value = new Value (obj); g_hash_table_insert (hash, g_strdup (key), obj_value); obj_value->Weaken (GetDeployment ()); EmitChanged (CollectionChangedActionAdd, obj_value, NULL, key); } cleanup: if (!rv) { if (obj) { /* If we set the parent, but the object wasn't added to the collection, make sure we clear the parent */ printf ("ResourceDictionary::AddedToCollection (): not added, clearing parent from %p\n", obj); obj->RemoveParent (this, NULL); } } return rv; }