(Button/PushButton) Registering properties using the type-registry.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.cpp
index bd74b57..9c1c340 100644 (file)
@@ -29,13 +29,13 @@ namespace Dali
 namespace Toolkit
 {
 
-namespace Internal
-{
+const Property::Index Button::PROPERTY_DIMMED( Internal::Button::BUTTON_PROPERTY_START_INDEX );
 
 namespace Internal
 {
 
-using namespace Dali;
+namespace
+{
 
 BaseHandle Create()
 {
@@ -47,7 +47,9 @@ TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Cont
 
 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
 
-}
+PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
+
+} // unnamed namespace
 
 Button::Button()
 : ControlImpl( true ),
@@ -196,15 +198,14 @@ void Button::OnInitialize()
     mPainter->Initialize( handle );
   }
 
+  Actor self = Self();
+
   mTapDetector = TapGestureDetector::New();
-  mTapDetector.Attach(Self());
+  mTapDetector.Attach( self );
   mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
 
   OnButtonInitialize();
 
-  Actor self = Self();
-  mPropertyDimmed = self.RegisterProperty( PROPERTY_DIMMED, false, Property::READ_WRITE );
-
   self.SetKeyboardFocusable( true );
 }
 
@@ -217,14 +218,6 @@ void Button::OnControlSizeSet(const Vector3& targetSize)
   }
 }
 
-void Button::OnPropertySet( Property::Index index, Property::Value propertyValue )
-{
-  if( index == mPropertyDimmed )
-  {
-    SetDimmed(propertyValue.Get<bool>());
-  }
-}
-
 void Button::OnTap(Actor actor, TapGesture tap)
 {
   // Do nothing.
@@ -239,6 +232,28 @@ void Button::OnStageDisconnection()
   }
 }
 
+void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+  Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
+
+  if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) )
+  {
+    GetImplementation( button ).SetDimmed( value.Get<bool>() );
+  }
+}
+
+Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
+{
+  Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
+
+  if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) )
+  {
+    return Property::Value( GetImplementation( button ).mDimmed );
+  }
+
+  return Property::Value();
+}
+
 } // namespace Internal
 
 } // namespace Toolkit