void NameScope::ObjectDestroyedEvent (EventObject *sender, EventArgs *args, gpointer closure) { NameScope *ns = (NameScope*)closure; // XXX this method worries me.. using GetName like this. DependencyObject *depobj = (DependencyObject*)sender; const char *name = depobj->GetName (); if (name != NULL) { g_hash_table_remove (ns->names, name); } else { g_hash_table_foreach_remove (ns->names, remove_object_from_namescope, depobj); } }
// 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; }