Custom property owning objects
[platform/core/uifw/dali-core.git] / dali / internal / event / object / custom-object-internal.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/object/custom-object-internal.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/event/common/stage-impl.h>
22 #include <dali/internal/update/common/animatable-property.h>
23 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/internal/update/common/property-owner-messages.h>
25 #include <dali/internal/update/manager/update-manager.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27
28 using Dali::Internal::SceneGraph::PropertyOwner;
29 using Dali::Internal::SceneGraph::PropertyBase;
30 using Dali::Internal::SceneGraph::UpdateManager;
31 using Dali::Internal::SceneGraph::AnimatableProperty;
32
33 namespace
34 {
35 const std::string INVALID_PROPERTY_NAME;
36 }
37
38 namespace Dali
39 {
40
41 namespace Internal
42 {
43
44 CustomObject* CustomObject::New()
45 {
46   return new CustomObject();
47 }
48
49 bool CustomObject::IsSceneObjectRemovable() const
50 {
51   return false;
52 }
53
54 const SceneGraph::PropertyOwner* CustomObject::GetSceneObject() const
55 {
56   return mUpdateObject;
57 }
58
59 const PropertyBase* CustomObject::GetSceneObjectAnimatableProperty( Property::Index index ) const
60 {
61   const PropertyBase* property( NULL );
62
63   CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index );
64
65   DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "index is invalid" );
66
67   property = dynamic_cast<const PropertyBase*>( entry->second.GetSceneGraphProperty() );
68
69   return property;
70 }
71
72 const PropertyInputImpl* CustomObject::GetSceneObjectInputProperty( Property::Index index ) const
73 {
74   return GetSceneObjectAnimatableProperty( index );
75 }
76
77 unsigned int CustomObject::GetDefaultPropertyCount() const
78 {
79   return 0u;
80 }
81
82 void CustomObject::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
83 {
84 }
85
86 const std::string& CustomObject::GetDefaultPropertyName( Property::Index index ) const
87 {
88   return INVALID_PROPERTY_NAME;
89 }
90
91 Property::Index CustomObject::GetDefaultPropertyIndex(const std::string& name) const
92 {
93   return Property::INVALID_INDEX;
94 }
95
96 bool CustomObject::IsDefaultPropertyWritable(Property::Index index) const
97 {
98   return false;
99 }
100
101 bool CustomObject::IsDefaultPropertyAnimatable(Property::Index index) const
102 {
103   return false;
104 }
105
106 Property::Type CustomObject::GetDefaultPropertyType(Property::Index index) const
107 {
108   return Property::NONE;
109 }
110
111 void CustomObject::SetDefaultProperty( Property::Index index, const Property::Value& property )
112 {
113   // do nothing
114 }
115
116 Property::Value CustomObject::GetDefaultProperty(Property::Index index) const
117 {
118   return Property::Value();
119 }
120
121 void CustomObject::InstallSceneObjectProperty( PropertyBase& newProperty, const std::string& name, unsigned int index )
122 {
123   if( NULL != mUpdateObject )
124   {
125     // mUpdateObject is being used in a separate thread; queue a message to add the property
126     InstallCustomPropertyMessage( Stage::GetCurrent()->GetUpdateInterface(), *mUpdateObject, newProperty ); // Message takes ownership
127   }
128 }
129
130 CustomObject::~CustomObject()
131 {
132   // Guard to allow handle destruction after Core has been destroyed
133   if( Stage::IsInstalled() )
134   {
135     if( NULL != mUpdateObject )
136     {
137       RemoveObjectMessage( Stage::GetCurrent()->GetUpdateManager(), mUpdateObject );
138       mUpdateObject = NULL; // object is about to be destroyed
139     }
140   }
141 }
142
143 CustomObject::CustomObject()
144 {
145   PropertyOwner* updateObject = PropertyOwner::New();
146
147   // Pass ownership to the update-thread
148   AddObjectMessage( Stage::GetCurrent()->GetUpdateManager(), updateObject );
149
150   // Keep as const since this should only be modified from update-thread
151   mUpdateObject = updateObject;
152 }
153
154 } // namespace Internal
155
156 } // namespace Dali