f5963f6f95bf91de1713800e17ffea916f2c1a06
[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 Dali
35 {
36
37 namespace Internal
38 {
39
40 CustomObject* CustomObject::New()
41 {
42   return new CustomObject();
43 }
44
45 bool CustomObject::IsSceneObjectRemovable() const
46 {
47   return false;
48 }
49
50 const SceneGraph::PropertyOwner* CustomObject::GetSceneObject() const
51 {
52   return mUpdateObject;
53 }
54
55 const PropertyBase* CustomObject::GetSceneObjectAnimatableProperty( Property::Index index ) const
56 {
57   CustomProperty* custom = FindCustomProperty( index );
58   DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
59   return custom->GetSceneGraphProperty();
60 }
61
62 const PropertyInputImpl* CustomObject::GetSceneObjectInputProperty( Property::Index index ) const
63 {
64   return GetSceneObjectAnimatableProperty( index );
65 }
66
67 unsigned int CustomObject::GetDefaultPropertyCount() const
68 {
69   return 0u;
70 }
71
72 void CustomObject::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
73 {
74 }
75
76 const char* CustomObject::GetDefaultPropertyName( Property::Index index ) const
77 {
78   return NULL;
79 }
80
81 Property::Index CustomObject::GetDefaultPropertyIndex(const std::string& name) const
82 {
83   return Property::INVALID_INDEX;
84 }
85
86 bool CustomObject::IsDefaultPropertyWritable(Property::Index index) const
87 {
88   return false;
89 }
90
91 bool CustomObject::IsDefaultPropertyAnimatable(Property::Index index) const
92 {
93   return false;
94 }
95
96 bool CustomObject::IsDefaultPropertyAConstraintInput( Property::Index index ) const
97 {
98   return false;
99 }
100
101 Property::Type CustomObject::GetDefaultPropertyType(Property::Index index) const
102 {
103   return Property::NONE;
104 }
105
106 void CustomObject::SetDefaultProperty( Property::Index index, const Property::Value& property )
107 {
108   // do nothing
109 }
110
111 Property::Value CustomObject::GetDefaultProperty(Property::Index index) const
112 {
113   return Property::Value();
114 }
115
116 void CustomObject::InstallSceneObjectProperty( PropertyBase& newProperty, const std::string& name, unsigned int index )
117 {
118   if( NULL != mUpdateObject )
119   {
120     // mUpdateObject is being used in a separate thread; queue a message to add the property
121     InstallCustomPropertyMessage( Stage::GetCurrent()->GetUpdateInterface(), *mUpdateObject, newProperty ); // Message takes ownership
122   }
123 }
124
125 CustomObject::~CustomObject()
126 {
127   // Guard to allow handle destruction after Core has been destroyed
128   if( Stage::IsInstalled() )
129   {
130     if( NULL != mUpdateObject )
131     {
132       RemoveObjectMessage( Stage::GetCurrent()->GetUpdateManager(), mUpdateObject );
133       mUpdateObject = NULL; // object is about to be destroyed
134     }
135   }
136 }
137
138 CustomObject::CustomObject()
139 {
140   PropertyOwner* updateObject = PropertyOwner::New();
141
142   // Pass ownership to the update-thread
143   AddObjectMessage( Stage::GetCurrent()->GetUpdateManager(), updateObject );
144
145   // Keep as const since this should only be modified from update-thread
146   mUpdateObject = updateObject;
147 }
148
149 } // namespace Internal
150
151 } // namespace Dali