Text - UNDERLINE, SHADOW, INPUT_UNDERLINE and INPUT_SHADOW properties refactor.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / text / text-visual.cpp
index e9278f9..c597e27 100644 (file)
@@ -25,6 +25,7 @@
 // INTERNAL HEADER
 #include <dali-toolkit/public-api/text/rendering-backend.h>
 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
 #include <dali-toolkit/internal/text/text-view.h>
@@ -154,18 +155,11 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS
   return geometry;
 }
 
-} // namespace
+} // unnamed namespace
 
-TextVisual::TextVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
-  mController( Text::Controller::New() ),
-  mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
-  mHasBeenStaged( false )
-{
-}
-
-TextVisual::~TextVisual()
+TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache )
 {
+  return new TextVisual( factoryCache );
 }
 
 void TextVisual::SetTextControlInterface( Text::ControlInterface* controlInterface )
@@ -207,7 +201,7 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const
   Property::Value value;
 
   map.Clear();
-  map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
+  map.Insert( Toolkit::VisualProperty::TYPE, Toolkit::Visual::TEXT );
 
   map.Insert( Toolkit::TextVisual::Property::RENDERING_BACKEND, mRenderingBackend );
 
@@ -254,10 +248,20 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const
   map.Insert( Toolkit::TextVisual::Property::BATCHING_ENABLED, false ); // TODO
 }
 
-void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
+TextVisual::TextVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache ),
+  mController( Text::Controller::New() ),
+  mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
+  mHasBeenStaged( false )
 {
-  mSelf = actor;
+}
 
+TextVisual::~TextVisual()
+{
+}
+
+void TextVisual::DoSetProperties( const Property::Map& propertyMap )
+{
   for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index )
   {
     const KeyValuePair& keyValue = propertyMap.GetKeyValue( index );
@@ -266,7 +270,7 @@ void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
     {
       case Property::Key::INDEX:
       {
-        if( Toolkit::Visual::Property::TYPE != keyValue.first.indexKey ) // Toolkit::Visual::Property::TYPE is not a TextVisual's property.
+        if( Toolkit::VisualProperty::TYPE != keyValue.first.indexKey ) // Toolkit::VisualProperty::TYPE is not a TextVisual's property.
         {
           DoSetProperty( keyValue.first.indexKey, keyValue.second );
         }
@@ -550,7 +554,7 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert
     case Toolkit::TextVisual::Property::UNDERLINE:
     {
       // TODO : This switch can be removed when the deprecated SHADOW_OFFSET and SHADOW_COLOR properties are finally removed.
-      //        Only the code for the STRING case should be kept.
+      //        Only the code for the MAP case should be kept.
       switch( propertyValue.GetType() )
       {
         case Property::VECTOR4:
@@ -583,7 +587,7 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert
           }
           break;
         }
-        case Property::STRING:
+        case Property::MAP:
         {
           const bool update = SetUnderlineProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
           if( update )
@@ -604,7 +608,7 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert
     case Toolkit::TextVisual::Property::SHADOW:
     {
       // TODO : This switch can be removed when the deprecated SHADOW_OFFSET and SHADOW_COLOR properties are finally removed.
-      //        Only the code for the STRING case should be kept.
+      //        Only the code for the MAP case should be kept.
       switch( propertyValue.GetType() )
       {
         case Property::VECTOR2:
@@ -627,7 +631,7 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert
           }
           break;
         }
-        case Property::STRING:
+        case Property::MAP:
         {
           const bool update = SetShadowProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
           if( update )
@@ -807,6 +811,13 @@ Dali::Property::Value TextVisual::DoGetProperty( Dali::Property::Index index )
 
 void TextVisual::RenderText()
 {
+  Actor self = mSelf.GetHandle();
+  if( !self )
+  {
+    // Nothing to do if the handle is not initialized.
+    return;
+  }
+
   Actor renderableActor;
 
   if( mRenderer )
@@ -823,7 +834,7 @@ void TextVisual::RenderText()
       const Vector2& scrollOffset = mController->GetScrollPosition();
       renderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
 
-      mSelf.Add( renderableActor );
+      self.Add( renderableActor );
     }
     mRenderableActor = renderableActor;
 
@@ -844,6 +855,13 @@ void TextVisual::StopTextAutoScrolling()
 
 void TextVisual::SetUpAutoScrolling()
 {
+  Actor self = mSelf.GetHandle();
+  if( !self )
+  {
+    // Nothing to do if the handle is not initialized.
+    return;
+  }
+
   const Text::ScrollerData* const data = mController->GetAutoScrollData();
 
   if( NULL != data )
@@ -857,8 +875,8 @@ void TextVisual::SetUpAutoScrolling()
     mTextScroller->StartScrolling( mRenderableActor,
                                    *data );
 
-    mSelf.Add( mTextScroller->GetScrollingText() );
-    mSelf.Add( mTextScroller->GetSourceCamera() );
+    self.Add( mTextScroller->GetScrollingText() );
+    self.Add( mTextScroller->GetSourceCamera() );
   }
 }