2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 #include <dali/internal/event/common/property-notification-impl.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/math/radian.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/common/property-notification-manager.h>
26 #include <dali/internal/event/common/proxy-object.h>
27 #include <dali/internal/event/common/stage-impl.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/common/scene-graph-property-notification.h>
30 #include <dali/internal/event/common/thread-local-storage.h>
34 using Dali::Internal::SceneGraph::UpdateManager;
42 PropertyNotificationPtr PropertyNotification::New(Property& target,
43 const Dali::PropertyCondition& condition)
45 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
47 UpdateManager& updateManager = tls.GetUpdateManager();
49 PropertyNotificationManager& propertyNotificationManager = Stage::GetCurrent()->GetPropertyNotificationManager();
51 PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
52 propertyNotificationManager,
56 return propertyNotification;
59 PropertyNotification::PropertyNotification(UpdateManager& updateManager,
60 PropertyNotificationManager& propertyNotificationManager,
62 const Dali::PropertyCondition& condition)
63 : mUpdateManager(updateManager),
64 mPropertyNotification(NULL),
65 mPropertyNotificationManager(propertyNotificationManager),
66 mProxyPropertyIndex(target.propertyIndex),
67 mCondition(condition),
68 mNotifyMode(Dali::PropertyNotification::NotifyOnTrue),
71 // Set condition arguments (as simple vector of floats)
72 PropertyCondition::ArgumentContainer arguments = GetImplementation(condition).arguments;
73 PropertyCondition::ArgumentConstIter iter = arguments.begin();
75 while( iter != arguments.end() )
77 const Property::Value& value = *iter;
79 value.Get(floatValue);
81 mRawConditionArgs.PushBack( floatValue );
85 // Observe target proxy and create/destroy notification scene object accordingly.
86 mProxy = dynamic_cast<ProxyObject*>( &GetImplementation(target.object) );
88 // Check if target scene-object already present, and if so create our notification
92 const SceneGraph::PropertyOwner* object = mProxy->GetSceneObject();
100 // Connect to the property notification manager
101 mPropertyNotificationManager.PropertyNotificationCreated( *this );
104 PropertyNotification::~PropertyNotification()
108 // Guard to disallow use of PropertyNotificationManager after Core has been destroyed
109 if ( Stage::IsInstalled() )
111 // Disconnect from the property notification manager
112 mPropertyNotificationManager.PropertyNotificationDestroyed( *this );
116 Dali::PropertyNotifySignalV2& PropertyNotification::NotifySignal()
118 return mNotifySignal;
121 void PropertyNotification::EmitSignalNotify()
123 Dali::PropertyNotification source(this);
125 mNotifySignal.Emit( source );
128 void PropertyNotification::Enable()
133 void PropertyNotification::Disable()
135 // Guard to allow handle destruction after Core has been destroyed
136 if ( Stage::IsInstalled() )
138 // Stop scene-graph from monitoring the target's properties.
139 DestroySceneObject();
143 void PropertyNotification::SetNotifyResult( bool result )
145 mNotifyResult = result;
148 const Dali::PropertyCondition& PropertyNotification::GetCondition() const
153 Dali::Handle PropertyNotification::GetTarget() const
155 Dali::Handle handle(mProxy);
160 Property::Index PropertyNotification::GetTargetProperty() const
162 return mProxyPropertyIndex;
165 void PropertyNotification::SetNotifyMode( NotifyMode mode )
168 PropertyNotificationSetNotifyModeMessage( mUpdateManager, mPropertyNotification, mode );
171 PropertyNotification::NotifyMode PropertyNotification::GetNotifyMode()
176 bool PropertyNotification::GetNotifyResult() const
178 return mNotifyResult;
181 bool PropertyNotification::CompareSceneObject( const SceneGraph::PropertyNotification* sceneObject )
183 return sceneObject && sceneObject == mPropertyNotification;
186 void PropertyNotification::CreateSceneObject()
188 DALI_ASSERT_DEBUG( mPropertyNotification == NULL );
190 Property::Type propertyType = mProxy->GetPropertyType(mProxyPropertyIndex);
192 // Create a new PropertyNotification, temporarily owned
193 SceneGraph::PropertyNotification* propertyNotification = SceneGraph::PropertyNotification::New( *mProxy,
196 GetImplementation(mCondition).type,
199 // Keep a const pointer to the PropertyNotification.
200 mPropertyNotification = propertyNotification;
202 // Transfer scene object ownership to the update manager through a message
203 AddPropertyNotificationMessage( mUpdateManager, propertyNotification );
206 void PropertyNotification::DestroySceneObject()
208 if ( mPropertyNotification != NULL )
210 // Remove PropertyNotification using a message to the update manager
211 RemovePropertyNotificationMessage( mUpdateManager, *mPropertyNotification );
212 mPropertyNotification = NULL;
216 } // namespace Internal