License conversion from Flora to Apache 2.0
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 // CLASS HEADER
19 #include <dali/internal/event/object/custom-object-internal.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/stage-impl.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/property-owner-messages.h>
26 #include <dali/internal/update/manager/update-manager.h>
27 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28
29 using Dali::Internal::SceneGraph::PropertyOwner;
30 using Dali::Internal::SceneGraph::PropertyBase;
31 using Dali::Internal::SceneGraph::UpdateManager;
32 using Dali::Internal::SceneGraph::AnimatableProperty;
33
34 namespace
35 {
36 const std::string INVALID_PROPERTY_NAME;
37 }
38
39 namespace Dali
40 {
41
42 namespace Internal
43 {
44
45 CustomObject* CustomObject::New()
46 {
47   return new CustomObject();
48 }
49
50 bool CustomObject::IsSceneObjectRemovable() const
51 {
52   return false;
53 }
54
55 const SceneGraph::PropertyOwner* CustomObject::GetSceneObject() const
56 {
57   return mUpdateObject;
58 }
59
60 const PropertyBase* CustomObject::GetSceneObjectAnimatableProperty( Property::Index index ) const
61 {
62   const PropertyBase* property( NULL );
63
64   CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index );
65
66   DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "index is invalid" );
67
68   property = dynamic_cast<const PropertyBase*>( entry->second.GetSceneGraphProperty() );
69
70   return property;
71 }
72
73 const PropertyInputImpl* CustomObject::GetSceneObjectInputProperty( Property::Index index ) const
74 {
75   return GetSceneObjectAnimatableProperty( index );
76 }
77
78 unsigned int CustomObject::GetDefaultPropertyCount() const
79 {
80   return 0u;
81 }
82
83 void CustomObject::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
84 {
85 }
86
87 const std::string& CustomObject::GetDefaultPropertyName( Property::Index index ) const
88 {
89   return INVALID_PROPERTY_NAME;
90 }
91
92 Property::Index CustomObject::GetDefaultPropertyIndex(const std::string& name) const
93 {
94   return Property::INVALID_INDEX;
95 }
96
97 bool CustomObject::IsDefaultPropertyWritable(Property::Index index) const
98 {
99   return false;
100 }
101
102 bool CustomObject::IsDefaultPropertyAnimatable(Property::Index index) const
103 {
104   return false;
105 }
106
107 bool CustomObject::IsDefaultPropertyAConstraintInput( Property::Index index ) const
108 {
109   return false;
110 }
111
112 Property::Type CustomObject::GetDefaultPropertyType(Property::Index index) const
113 {
114   return Property::NONE;
115 }
116
117 void CustomObject::SetDefaultProperty( Property::Index index, const Property::Value& property )
118 {
119   // do nothing
120 }
121
122 Property::Value CustomObject::GetDefaultProperty(Property::Index index) const
123 {
124   return Property::Value();
125 }
126
127 void CustomObject::InstallSceneObjectProperty( PropertyBase& newProperty, const std::string& name, unsigned int index )
128 {
129   if( NULL != mUpdateObject )
130   {
131     // mUpdateObject is being used in a separate thread; queue a message to add the property
132     InstallCustomPropertyMessage( Stage::GetCurrent()->GetUpdateInterface(), *mUpdateObject, newProperty ); // Message takes ownership
133   }
134 }
135
136 CustomObject::~CustomObject()
137 {
138   // Guard to allow handle destruction after Core has been destroyed
139   if( Stage::IsInstalled() )
140   {
141     if( NULL != mUpdateObject )
142     {
143       RemoveObjectMessage( Stage::GetCurrent()->GetUpdateManager(), mUpdateObject );
144       mUpdateObject = NULL; // object is about to be destroyed
145     }
146   }
147 }
148
149 CustomObject::CustomObject()
150 {
151   PropertyOwner* updateObject = PropertyOwner::New();
152
153   // Pass ownership to the update-thread
154   AddObjectMessage( Stage::GetCurrent()->GetUpdateManager(), updateObject );
155
156   // Keep as const since this should only be modified from update-thread
157   mUpdateObject = updateObject;
158 }
159
160 } // namespace Internal
161
162 } // namespace Dali