Initialise Controller's DefaultFont description to that of the Platform default font
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
index 065d0f9..1c31449 100644 (file)
 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/object/type-registry.h>
 #include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/devel-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/text/rendering-backend.h>
-#include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
+#include <dali-toolkit/internal/text/text-view.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
 
 using Dali::Toolkit::Text::LayoutEngine;
@@ -50,6 +49,10 @@ namespace
 namespace
 {
 
+#if defined(DEBUG_ENABLED)
+  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
+#endif
+
 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
 {
   { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
@@ -144,24 +147,17 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
         {
           const std::string fontFamily = value.Get< std::string >();
 
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
           if( impl.mController->GetDefaultFontFamily() != fontFamily )
           {
-            impl.mController->SetDefaultFontFamily( fontFamily );
+            impl.mController->SetDefaultFontFamily( fontFamily, true );
           }
         }
         break;
       }
       case Toolkit::TextLabel::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          const std::string fontStyle = value.Get< std::string >();
-
-          if( impl.mController->GetDefaultFontStyle() != fontStyle )
-          {
-            impl.mController->SetDefaultFontStyle( fontStyle );
-          }
-        }
+        SetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextLabel::Property::POINT_SIZE:
@@ -336,10 +332,7 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::TextLabel::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          value = impl.mController->GetDefaultFontStyle();
-        }
+        GetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextLabel::Property::POINT_SIZE:
@@ -458,7 +451,37 @@ void TextLabel::OnInitialize()
 
 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
 {
-  GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
+
+  switch ( change )
+  {
+    case StyleChange::DEFAULT_FONT_CHANGE:
+    {
+      // Property system did not set the font so should update it.
+      std::string newFont = styleManager.GetDefaultFontFamily();
+      DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
+      mController->UpdateAfterFontChange( newFont );
+      break;
+    }
+
+    case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
+    {
+      DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
+
+      if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
+      {
+        // Property system did not set the PointSize so should update it.
+        // todo instruct text-controller to update model
+      }
+      break;
+    }
+    case StyleChange::THEME_CHANGE:
+    {
+      GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+      break;
+    }
+  }
 }
 
 Vector3 TextLabel::GetNaturalSize()
@@ -491,10 +514,11 @@ void TextLabel::RequestTextRelayout()
 
 void TextLabel::RenderText()
 {
+  Actor self = Self();
   Actor renderableActor;
   if( mRenderer )
   {
-    renderableActor = mRenderer->Render( mController->GetView(), mDepth );
+    renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
   }
 
   if( renderableActor != mRenderableActor )
@@ -506,7 +530,7 @@ void TextLabel::RenderText()
       const Vector2& alignmentOffset = mController->GetAlignmentOffset();
       renderableActor.SetPosition( alignmentOffset.x, alignmentOffset.y );
 
-      Self().Add( renderableActor );
+      self.Add( renderableActor );
     }
     mRenderableActor = renderableActor;
   }
@@ -531,7 +555,10 @@ void TextLabel::AddDecoration( Actor& actor, bool needsClipping )
 
 void TextLabel::OnStageConnection( int depth )
 {
-  mDepth = depth;
+  // Call the Control::OnStageConnection() to set the depth of the background.
+  Control::OnStageConnection( depth );
+
+  // The depth of the text renderer is set in the RenderText() called from OnRelayout().
 }
 
 void TextLabel::TextChanged()
@@ -547,7 +574,6 @@ void TextLabel::MaxLengthReached()
 TextLabel::TextLabel()
 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
-  mDepth( 0 ),
   mHasBeenStaged( false )
 {
 }