Merge changes I75f2d974,Ib8d53cf7 into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 15 Feb 2017 17:17:36 +0000 (09:17 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 15 Feb 2017 17:17:37 +0000 (09:17 -0800)
* changes:
  Updating Builder and Control to handle styled States
  Reordered builder implementation ahead of rework

17 files changed:
automated-tests/src/dali-toolkit-styling/theme2.json [new file with mode: 0644]
automated-tests/src/dali-toolkit-styling/theme3.json [new file with mode: 0644]
automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h
automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp
dali-toolkit/devel-api/builder/tree-node.cpp
dali-toolkit/devel-api/controls/control-devel.h
dali-toolkit/internal/builder/builder-impl.cpp
dali-toolkit/internal/builder/builder-impl.h
dali-toolkit/internal/builder/dictionary.h [new file with mode: 0644]
dali-toolkit/internal/builder/style.cpp [new file with mode: 0644]
dali-toolkit/internal/builder/style.h [new file with mode: 0644]
dali-toolkit/internal/file.list
dali-toolkit/internal/styling/style-manager-impl.cpp
dali-toolkit/internal/styling/style-manager-impl.h
dali-toolkit/public-api/controls/control-impl.cpp

diff --git a/automated-tests/src/dali-toolkit-styling/theme2.json b/automated-tests/src/dali-toolkit-styling/theme2.json
new file mode 100644 (file)
index 0000000..8ca44cd
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "styles":
+  {
+    "testbutton":
+    {
+      "backgroundColor":[1.0,1.0,0.0,1.0]
+    }
+  }
+}
diff --git a/automated-tests/src/dali-toolkit-styling/theme3.json b/automated-tests/src/dali-toolkit-styling/theme3.json
new file mode 100644 (file)
index 0000000..68a292e
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "styles":
+  {
+    "testbutton":
+    {
+      "backgroundColor":[1.0,1.0,0.0,1.0]
+// Deliberate Error: trailing comma
+    },
+  },
+}
index 8d93d9c..6fe0fde 100644 (file)
@@ -1,4 +1,4 @@
-/*
+ /*
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,9 @@
 #include <test-button.h>
 #include <test-animation-data.h>
 #include <toolkit-style-monitor.h>
+#include <dummy-control.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -33,6 +36,10 @@ namespace
 {
 const char* defaultTheme =
 "{\n"
+"  \"constants\":\n"
+"  {\n"
+"    \"CONFIG_SCRIPT_LOG_LEVEL\":\"NoLogging\"\n"
+"  },\n"
 "  \"styles\":\n"
 "  {\n"
 "    \"textlabel\":\n"
@@ -146,6 +153,223 @@ const char* defaultTheme =
 "      \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n"
 "      \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n"
 "      \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n"
+"    },\n"
+"    \"ComplexControl\":\n"
+"    {\n"
+"      \"states\":\n"
+"      {\n"
+"        \"NORMAL\":\n"
+"        {\n"
+"          \"states\":\n"
+"          {\n"
+"            \"SELECTED\":\n"
+"            {\n"
+"              \"visuals\":\n"
+"              {\n"
+"                \"foregroundVisual\":\n"
+"                {\n"
+"                  \"visualType\":\"GRADIENT\",\n"
+"                  \"startPosition\": [-1, -1],\n"
+"                  \"endPosition\": [1, 1],\n"
+"                  \"spreadMethod\": \"REPEAT\",\n"
+"                  \"stopOffset\": [0.2, 0.8],\n"
+"                  \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n"
+"                }\n"
+"              }\n"
+"            },\n"
+"            \"UNSELECTED\":\n"
+"            {\n"
+"              \"visuals\":\n"
+"              {\n"
+"                \"foregroundVisual\":\n"
+"                {\n"
+"                  \"visualType\":\"COLOR\",\n"
+"                  \"mixColor\": [ 1,0,0,1]\n"
+"                }\n"
+"              }\n"
+"            }\n"
+"          },\n"
+"          \"transitions\":\n"
+"          {\n"
+"            \"visualName\":\"*\",\n"
+"            \"effect\":\"CROSSFADE\",\n"
+"            \"animator\":\n"
+"            {\n"
+"              \"alphaFunction\":\"EASE_IN_OUT\",\n"
+"              \"duration\":0.3\n"
+"            }\n"
+"          }\n"
+"        },\n"
+"        \"FOCUSED\":\n"
+"        {\n"
+"          \"visuals\":\n"
+"          {\n"
+"            \"foregroundVisual\":\n"
+"            {\n"
+"              \"visualType\":\"GRADIENT\",\n"
+"              \"startPosition\": [-1, -1],\n"
+"              \"endPosition\": [1, 1],\n"
+"              \"spreadMethod\": \"REPEAT\",\n"
+"              \"stopOffset\": [0.3, 0.9],\n"
+"              \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n"
+"            },\n"
+"            \"focusVisual\":\n"
+"            {\n"
+"              \"visualType\":\"IMAGE\",\n"
+"              \"url\": \"focus.png\"\n"
+"            }\n"
+"          },\n"
+"          \"entryTransition\":\n"
+"          {\n"
+"            \"target\":\"focusVisual\",\n"
+"            \"property\":\"mixColor\",\n"
+"            \"initialValue\":[0,0,0,0],\n"
+"            \"targetValue\":[1,1,1,1],\n"
+"            \"animator\":\n"
+"            {\n"
+"              \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
+"              \"timePeriod\": \n"
+"              {\n"
+"                \"duration\":0.5,\n"
+"                \"delay\":0\n"
+"              }\n"
+"            }\n"
+"          },\n"
+"          \"exitTransition\":\n"
+"          {\n"
+"            \"target\":\"focusVisual\",\n"
+"            \"property\":\"mixColor\",\n"
+"            \"initialValue\":[1,1,1,1],\n"
+"            \"targetValue\":[0,0,0,0],\n"
+"            \"animator\":\n"
+"            {\n"
+"              \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
+"              \"timePeriod\": \n"
+"              {\n"
+"                \"duration\":0.5,\n"
+"                \"delay\":0\n"
+"              }\n"
+"            }\n"
+"          }\n"
+"        },\n"
+"        \"DISABLED\":\n"
+"        {\n"
+"          \"visuals\":\n"
+"          {\n"
+"            \"foregroundVisual\":\n"
+"            {\n"
+"              \"visualType\":\"COLOR\",\n"
+"              \"mixColor\": [1,0,0,1]\n"
+"            }\n"
+"          }\n"
+"        }\n"
+"      },\n"
+"      \"transitions\":\n"
+"      [\n"
+"        {\n"
+"          \"effect\":\"CROSSFADE\",\n"
+"          \"animator\":\n"
+"          {\n"
+"            \"alphaFunction\":\"EASE_IN_OUT\",\n"
+"            \"duration\":0.3\n"
+"          }\n"
+"        }\n"
+"      ]\n"
+"    },\n"
+"    \"BasicControl\":\n"
+"    {\n"
+"      \"states\":\n"
+"      {\n"
+"        \"NORMAL\":\n"
+"        {\n"
+"          \"visuals\":\n"
+"          {\n"
+"            \"foregroundVisual\":\n"
+"            {\n"
+"              \"visualType\":\"GRADIENT\",\n"
+"              \"startPosition\": [-1, -1],\n"
+"              \"endPosition\": [1, 1],\n"
+"              \"spreadMethod\": \"REPEAT\",\n"
+"              \"stopOffset\": [0.2, 0.8],\n"
+"              \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n"
+"            }\n"
+"          }\n"
+"        },\n"
+"        \"FOCUSED\":\n"
+"        {\n"
+"          \"visuals\":\n"
+"          {\n"
+"            \"foregroundVisual\":\n"
+"            {\n"
+"              \"visualType\":\"GRADIENT\",\n"
+"              \"startPosition\": [-1, -1],\n"
+"              \"endPosition\": [1, 1],\n"
+"              \"spreadMethod\": \"REPEAT\",\n"
+"              \"stopOffset\": [0.3, 0.9],\n"
+"              \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n"
+"            },\n"
+"            \"focusVisual\":\n"
+"            {\n"
+"              \"visualType\":\"IMAGE\",\n"
+"              \"url\": \"focus.png\"\n"
+"            }\n"
+"          },\n"
+"          \"entryTransition\":\n"
+"          {\n"
+"            \"target\":\"focusVisual\",\n"
+"            \"property\":\"mixColor\",\n"
+"            \"initialValue\":[0,0,0,0],\n"
+"            \"targetValue\":[1,1,1,1],\n"
+"            \"animator\":\n"
+"            {\n"
+"              \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
+"              \"timePeriod\": \n"
+"              {\n"
+"                \"duration\":0.5,\n"
+"                \"delay\":0\n"
+"              }\n"
+"            }\n"
+"          },\n"
+"          \"exitTransition\":\n"
+"          {\n"
+"            \"target\":\"focusVisual\",\n"
+"            \"property\":\"mixColor\",\n"
+"            \"initialValue\":[1,1,1,1],\n"
+"            \"targetValue\":[0,0,0,0],\n"
+"            \"animator\":\n"
+"            {\n"
+"              \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n"
+"              \"timePeriod\": \n"
+"              {\n"
+"                \"duration\":0.5,\n"
+"                \"delay\":0\n"
+"              }\n"
+"            }\n"
+"          }\n"
+"        },\n"
+"        \"DISABLED\":\n"
+"        {\n"
+"          \"visuals\":\n"
+"          {\n"
+"            \"foregroundVisual\":\n"
+"            {\n"
+"              \"visualType\":\"COLOR\",\n"
+"              \"mixColor\": [1,0,0,1]\n"
+"            }\n"
+"          }\n"
+"        }\n"
+"      },\n"
+"      \"transitions\":\n"
+"      [\n"
+"        {\n"
+"          \"effect\":\"CROSSFADE\",\n"
+"          \"animator\":\n"
+"          {\n"
+"            \"alphaFunction\":\"EASE_IN_OUT\",\n"
+"            \"duration\":0.3\n"
+"          }\n"
+"        }\n"
+"      ]\n"
 "    }\n"
 "  }\n"
 "}\n";
@@ -154,6 +378,7 @@ const char* defaultTheme =
 
 
 
+
 void dali_style_manager_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -258,6 +483,10 @@ int UtcDaliStyleManagerApplyTheme(void)
 
   const char* json1 =
     "{\n"
+    "  \"constants\":\n"
+    "  {\n"
+    "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Verbose\"\n"
+    "  },\n"
     "  \"styles\":\n"
     "  {\n"
     "    \"testbutton\":\n"
@@ -362,6 +591,10 @@ int UtcDaliStyleManagerApplyDefaultTheme(void)
 
   const char* defaultTheme =
     "{\n"
+    "  \"constants\":\n"
+    "  {\n"
+    "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"Concise\"\n"
+    "  },\n"
     "  \"styles\":\n"
     "  {\n"
     "    \"testbutton\":\n"
@@ -505,6 +738,10 @@ int UtcDaliStyleManagerApplyStyle(void)
 
   const char* json1 =
     "{\n"
+    "  \"constants\":\n"
+    "  {\n"
+    "    \"CONFIG_SCRIPT_LOG_LEVEL\":\"General\"\n"
+    "  },\n"
     "  \"styles\":\n"
     "  {\n"
     "    \"testbutton\":\n"
@@ -574,6 +811,107 @@ int UtcDaliStyleManagerApplyStyle(void)
 }
 
 
+int UtcDaliStyleManagerIncludeStyleP(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works" );
+
+  const char* json1 =
+    "{\n"
+    "  \"includes\":\n"
+    "  [\n"
+    "     \"src/dali-toolkit-styling/theme2.json\"\n"
+    "  ],\n"
+    "  \"styles\":\n"
+    "  {\n"
+    "    \"testbutton\":\n"
+    "    {\n"
+    "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
+    "    }\n"
+    "  }\n"
+    "}\n";
+
+  // Add 2 buttons
+  Test::TestButton testButton = Test::TestButton::New();
+  Test::TestButton testButton2 = Test::TestButton::New();
+  Stage::GetCurrent().Add( testButton );
+  Stage::GetCurrent().Add( testButton2 );
+  StyleChangedSignalChecker styleChangedSignalHandler;
+  StyleManager styleManager = StyleManager::Get();
+
+  styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+
+  tet_infoline("Apply the style");
+
+  std::string themeFile("ThemeOne");
+  Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
+
+  styleManager.ApplyTheme(themeFile);
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  Property::Value themedBgColor( testButton.GetProperty(Test::TestButton::Property::BACKGROUND_COLOR) );
+  Property::Value themedFgColor( testButton.GetProperty(Test::TestButton::Property::FOREGROUND_COLOR) );
+
+  DALI_TEST_EQUALS( themedBgColor, Property::Value(Color::YELLOW), 0.001, TEST_LOCATION );
+  DALI_TEST_EQUALS( themedFgColor, Property::Value(Color::BLUE), 0.001, TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+int UtcDaliStyleManagerIncludeStyleN(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline( "UtcDaliStyleManagerIncludeStyle - test that style sheet inclusion works, but included stylesheet is bad json" );
+
+  const char* json1 =
+    "{\n"
+    "  \"includes\":\n"
+    "  [\n"
+    "     \"src/dali-toolkit-styling/theme3.json\"\n"
+    "  ],\n"
+    "  \"styles\":\n"
+    "  {\n"
+    "    \"testbutton\":\n"
+    "    {\n"
+    "      \"foregroundColor\":[0.0,0.0,1.0,1.0]\n"
+    "    }\n"
+    "  }\n"
+    "}\n";
+
+  // Add 2 buttons
+  Test::TestButton testButton = Test::TestButton::New();
+  Test::TestButton testButton2 = Test::TestButton::New();
+  Stage::GetCurrent().Add( testButton );
+  Stage::GetCurrent().Add( testButton2 );
+  StyleChangedSignalChecker styleChangedSignalHandler;
+  StyleManager styleManager = StyleManager::Get();
+
+  styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+
+  tet_infoline("Apply the style");
+
+  std::string themeFile("ThemeOne");
+  Test::StyleMonitor::SetThemeFileOutput(themeFile, json1);
+
+  try
+  {
+    styleManager.ApplyTheme(themeFile);
+  }
+  catch( Dali::DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "!\"Cannot parse JSON\"", TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+
 int UtcDaliStyleManagerStyleChangedSignalFontFamily(void)
 {
   tet_infoline("Test that the StyleChange signal is fired when the font family is altered" );
@@ -860,3 +1198,85 @@ int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void)
 
   END_TEST;
 }
+
+
+int UtcDaliStyleManagerVisualTransitionParsing(void)
+{
+  tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
+  Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
+                                          defaultTheme );
+
+  ToolkitTestApplication application;
+
+  StyleChangedSignalChecker styleChangedSignalHandler;
+  Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
+  StyleManager styleManager = StyleManager::Get();
+
+  DummyControl actor = DummyControl::New(true);
+  actor.SetStyleName("BasicControl");
+  Stage::GetCurrent().Add(actor);
+
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
+  Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
+
+  actor.SetProperty( DevelControl::Property::STATE, DevelControl::FOCUSED );
+
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), true, TEST_LOCATION);
+
+  Visual::Base visual2 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
+  DALI_TEST_CHECK( visual1 != visual2 );
+
+  actor.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
+
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
+
+  Visual::Base visual3 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
+  Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL);
+  DALI_TEST_CHECK( !focusVisual );
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION);
+
+  DALI_TEST_CHECK( visual1 != visual3 );
+  DALI_TEST_CHECK( visual2 != visual3 );
+
+  END_TEST;
+}
+
+
+int UtcDaliStyleManagerVisualTransitionParsing02(void)
+{
+  tet_infoline("Instantiate dummy control and test state/visual/transition capture" );
+  Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json",
+                                          defaultTheme );
+
+  ToolkitTestApplication application;
+
+  StyleChangedSignalChecker styleChangedSignalHandler;
+  Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get();
+  StyleManager styleManager = StyleManager::Get();
+
+  DummyControl actor = DummyControl::New(true);
+  actor.SetProperty(DevelControl::Property::STATE, "FOCUSED");
+
+  actor.SetStyleName("ComplexControl");
+  Stage::GetCurrent().Add(actor);
+
+  Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
+
+  DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION);
+  Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL);
+  DALI_TEST_CHECK( visual1 );
+  Property::Map map;
+  visual1.CreatePropertyMap( map );
+  Property::Value* value = map.Find( Visual::Property::TYPE );
+  DALI_TEST_CHECK( value );
+
+  int visualType;
+  value->Get( visualType );
+
+  DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::GRADIENT, TEST_LOCATION );
+
+  END_TEST;
+}
index f6fb4bf..979e56a 100644 (file)
@@ -74,6 +74,12 @@ Dali::PropertyRegistration dummyControlVisualProperty01(
 Dali::PropertyRegistration dummyControlVisualProperty02(
   typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL2, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
 
+Dali::PropertyRegistration dummyControlVisualProperty03(
+  typeRegistration, "foregroundVisual", Dali::Toolkit::DummyControl::Property::FOREGROUND_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
+
+Dali::PropertyRegistration dummyControlVisualProperty04(
+  typeRegistration, "focusVisual", Dali::Toolkit::DummyControl::Property::FOCUS_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
+
 }
 
 DummyControl DummyControlImpl::New()
@@ -144,6 +150,26 @@ Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& tra
 
 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
 {
+  Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
+  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
+
+  switch(index)
+  {
+    case Toolkit::DummyControl::Property::TEST_VISUAL:
+    case Toolkit::DummyControl::Property::TEST_VISUAL2:
+    case Toolkit::DummyControl::Property::FOREGROUND_VISUAL:
+    case Toolkit::DummyControl::Property::FOCUS_VISUAL:
+    {
+      Property::Map* map = value.GetMap();
+      if( map != NULL )
+      {
+        VisualFactory visualFactory = VisualFactory::Get();
+        Visual::Base visual = visualFactory.CreateVisual(*map);
+        dummyImpl.RegisterVisual(index, visual);
+      }
+      break;
+    }
+  }
 }
 
 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
index f27f296..75d3efe 100644 (file)
@@ -46,7 +46,9 @@ public:
     enum Type
     {
       TEST_VISUAL = PROPERTY_START_INDEX,
-      TEST_VISUAL2
+      TEST_VISUAL2,
+      FOREGROUND_VISUAL,
+      FOCUS_VISUAL
     };
   };
 
@@ -89,7 +91,7 @@ public:
   void RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled );
   void UnregisterVisual( Property::Index index );
   void EnableVisual( Property::Index index, bool enabled );
-  bool IsVisualEnabled( Property::Index indepx );
+  bool IsVisualEnabled( Property::Index index );
 
   Toolkit::Visual::Base GetVisual( Property::Index index );
   Animation CreateTransition( const Toolkit::TransitionData& transition );
index cb84952..60f4a1b 100644 (file)
@@ -276,7 +276,7 @@ int UtcDaliBuilderAnimationP(void)
         "    \"name\": \"greeting\","
         "    \"type\": \"TextLabel\","
         "    \"text\": \"Touch me\","
-        "    \"styles\": [\"basicText\"],"
+        "    \"inherit\": [\"basicText\"],"
         "    \"position\": [0, -120, 0],"
         "    \"size\": [200, 200, 1],"
         "    \"orientation\": [0, 0, 30],"
@@ -400,7 +400,7 @@ int UtcDaliBuilderAnimationN(void)
         "    \"name\": \"greeting\","
         "    \"type\": \"TextLabel\","
         "    \"text\": \"Touch me\","
-        "    \"styles\": [\"basicText\"],"
+        "    \"inherit\": [\"basicText\"],"
         "    \"position\": [0, -120, 0],"
         "    \"size\": [200, 200, 1],"
         "    \"orientation\": [0, 0, 30],"
index 6b0f6b3..3d9eed7 100644 (file)
@@ -23,7 +23,8 @@
 #include "dali-toolkit/devel-api/builder/tree-node.h"
 #include "dali-toolkit/internal/builder/tree-node-manipulator.h"
 
-namespace
+
+namespace Dali
 {
 
 bool CaseInsensitiveCharacterCompare( unsigned char a, unsigned char b )
@@ -45,12 +46,6 @@ bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b )
   return result;
 }
 
-} // anonymous namespace
-
-
-namespace Dali
-{
-
 namespace Toolkit
 {
 
index 71071db..306ce2d 100644 (file)
@@ -30,6 +30,13 @@ namespace Toolkit
 namespace DevelControl
 {
 
+enum State
+{
+  NORMAL,
+  FOCUSED,
+  DISABLED
+};
+
 namespace Property
 {
 
@@ -53,6 +60,22 @@ enum
    * @see Toolkit::Tooltip
    */
   TOOLTIP = BACKGROUND + 1,
+
+  /**
+   * @brief The current state of the control.
+   * @details Name "state", type DevelControl::State ( Property::INTEGER ) or Property::STRING
+   *
+   * @see DevelControl::State
+   */
+  STATE = BACKGROUND + 2,
+
+  /**
+   * @brief The current sub state of the control.
+   * @details Name "subState", type Property::INTEGER or Property::STRING. The enumeration used is dependent on the derived control.
+   *
+   * @see DevelControl::State
+   */
+  SUB_STATE = BACKGROUND + 3
 };
 
 } // namespace Property
index a7fabdf..9b6daa0 100644 (file)
 #include <sys/stat.h>
 #include <sstream>
 
-#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/object/property-array.h>
 #include <dali/public-api/object/type-info.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/object/property-array.h>
-#include <dali/public-api/actors/layer.h>
-#include <dali/public-api/actors/camera-actor.h>
-#include <dali/devel-api/scripting/scripting.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/signals/functor-delegate.h>
+#include <dali/devel-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/devel-api/builder/json-parser.h>
 
-#include <dali-toolkit/internal/builder/builder-get-is.inl.h>
-#include <dali-toolkit/internal/builder/builder-filesystem.h>
 #include <dali-toolkit/internal/builder/builder-declarations.h>
+#include <dali-toolkit/internal/builder/builder-filesystem.h>
+#include <dali-toolkit/internal/builder/builder-get-is.inl.h>
+#include <dali-toolkit/internal/builder/builder-impl-debug.h>
 #include <dali-toolkit/internal/builder/builder-set-property.h>
 #include <dali-toolkit/internal/builder/replacement.h>
 #include <dali-toolkit/internal/builder/tree-node-manipulator.h>
 
-#include <dali-toolkit/internal/builder/builder-impl-debug.h>
-
 namespace Dali
 {
 
@@ -56,9 +56,12 @@ namespace Internal
 class Replacement;
 
 extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot, Builder* const builder );
+
 extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
+
 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
 
+
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gFilterScript  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
 #endif
@@ -68,14 +71,20 @@ namespace
 
 #define TOKEN_STRING(x) #x
 
-const std::string KEYNAME_STYLES    = "styles";
-const std::string KEYNAME_TYPE      = "type";
-const std::string KEYNAME_ACTORS    = "actors";
-const std::string KEYNAME_SIGNALS   = "signals";
-const std::string KEYNAME_NAME      = "name";
-const std::string KEYNAME_TEMPLATES = "templates";
-const std::string KEYNAME_INCLUDES  = "includes";
-const std::string KEYNAME_MAPPINGS  = "mappings";
+const std::string KEYNAME_ACTORS           = "actors";
+const std::string KEYNAME_ENTRY_TRANSITION = "entryTransition";
+const std::string KEYNAME_EXIT_TRANSITION  = "exitTransition";
+const std::string KEYNAME_INCLUDES         = "includes";
+const std::string KEYNAME_INHERIT          = "inherit";
+const std::string KEYNAME_MAPPINGS         = "mappings";
+const std::string KEYNAME_NAME             = "name";
+const std::string KEYNAME_SIGNALS          = "signals";
+const std::string KEYNAME_STATES           = "states";
+const std::string KEYNAME_STYLES           = "styles";
+const std::string KEYNAME_TEMPLATES        = "templates";
+const std::string KEYNAME_TRANSITIONS      = "transitions";
+const std::string KEYNAME_TYPE             = "type";
+const std::string KEYNAME_VISUALS          = "visuals";
 
 const std::string PROPERTIES = "properties";
 const std::string ANIMATABLE_PROPERTIES = "animatableProperties";
@@ -121,7 +130,12 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style,
         {
           styleList.push_back( &(*node) );
 
-          if( OptionalChild subStyle = IsChild( *node, KEYNAME_STYLES ) )
+          OptionalChild subStyle = IsChild( *node, KEYNAME_INHERIT );
+          if( ! subStyle )
+          {
+            subStyle = IsChild( *node, KEYNAME_STYLES );
+          }
+          if( subStyle )
           {
             CollectAllStyles( stylesCollection, *subStyle, styleList );
           }
@@ -134,379 +148,256 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style,
 
 } // namespace anon
 
-/*
- * Sets the handle properties found in the tree node
- */
-void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
+
+Builder::Builder()
+: mSlotDelegate( this )
 {
-  if( handle )
-  {
+  mParser = Dali::Toolkit::JsonParser::New();
 
-    for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
-    {
-      const TreeNode::KeyNodePair& keyChild = *iter;
+  Property::Map defaultDirs;
+  defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]       = DALI_IMAGE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ]       = DALI_SOUND_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ]       = DALI_STYLE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR;
 
-      std::string key( keyChild.first );
+  AddConstants( defaultDirs );
+}
 
-      // ignore special fields; type,actors,signals,styles
-      if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES || key == KEYNAME_MAPPINGS )
-      {
-        continue;
-      }
+void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
+{
+  // parser to get constants and includes only
+  Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
+
+  if( !parser.Parse( data ) )
+  {
+    DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
+                      parser.GetErrorLineNumber(),
+                      parser.GetErrorColumn(),
+                      parser.GetErrorDescription().c_str() );
 
-      Handle propertyObject( handle );
+    DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+  }
+  else
+  {
+    // load constant map (allows the user to override the constants in the json after loading)
+    LoadConstants( *parser.GetRoot(), mReplacementMap );
 
-      Dali::Property::Index index = propertyObject.GetPropertyIndex( key );
+    // merge includes
+    if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
+    {
+      Replacement replacer( mReplacementMap );
 
-      if( Property::INVALID_INDEX != index )
+      for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
       {
-        Property::Type type = propertyObject.GetPropertyType(index);
-        Property::Value value;
-        bool mapped = false;
+        OptionalString filename = replacer.IsString( (*iter).second );
 
-        // if node.value is a mapping, get the property value from the "mappings" table
-        if( keyChild.second.GetType() == TreeNode::STRING )
-        {
-          std::string mappingKey;
-          if( GetMappingKey(keyChild.second.GetString(), mappingKey) )
-          {
-            OptionalChild mappingRoot = IsChild( mParser.GetRoot(), KEYNAME_MAPPINGS );
-            mapped = GetPropertyMap( *mappingRoot, mappingKey.c_str(), type, value );
-          }
-        }
-        if( ! mapped )
-        {
-          mapped = DeterminePropertyFromNode( keyChild.second, type, value, constant );
-          if( ! mapped )
-          {
-            // Just determine the property from the node and if it's valid, let the property object handle it
-            DeterminePropertyFromNode( keyChild.second, value, constant );
-            mapped = ( value.GetType() != Property::NONE );
-          }
-        }
-        if( mapped )
+        if( filename )
         {
-          DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
-
-          propertyObject.SetProperty( index, value );
+#if defined(DEBUG_ENABLED)
+          DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
+#endif
+          LoadFromString( GetFileContents(*filename) );
         }
       }
-      else
-      {
-        DALI_LOG_ERROR("Key '%s' not found.\n", key.c_str());
-      }
+    }
 
-      // Add custom properties
-      SetCustomProperties(node, handle, constant, PROPERTIES, Property::READ_WRITE);
-      SetCustomProperties(node, handle, constant, ANIMATABLE_PROPERTIES, Property::ANIMATABLE);
+    if( !mParser.Parse( data ) )
+    {
+      DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
+                        mParser.GetErrorLineNumber(),
+                        mParser.GetErrorColumn(),
+                        mParser.GetErrorDescription().c_str() );
 
-    } // for property nodes
-  }
-  else
-  {
-    DALI_SCRIPT_WARNING("Style applied to empty handle\n");
+      DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+    }
   }
+
+  DUMP_PARSE_TREE(parser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
+  DUMP_TEST_MAPPINGS(parser);
+
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
 }
 
-void Builder::SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant,
-                          const std::string& childName, Property::AccessMode accessMode )
+void Builder::AddConstants( const Property::Map& map )
 {
-  // Add custom properties
-  if( OptionalChild customPropertiesChild = IsChild(node, childName) )
-  {
-    const TreeNode& customPropertiesNode = *customPropertiesChild;
-    const TreeConstIter endIter = customPropertiesNode.CEnd();
-    for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
-    {
-      const TreeNode::KeyNodePair& keyChild = *iter;
-      std::string key( keyChild.first );
+  mReplacementMap.Merge( map );
+}
 
-      Property::Value value;
-      DeterminePropertyFromNode( keyChild.second, value, constant );
-      // Register/Set property.
-      handle.RegisterProperty( key, value, accessMode );
-    }
-  }
+void Builder::AddConstant( const std::string& key, const Property::Value& value )
+{
+  mReplacementMap[key] = value;
 }
 
-// Set properties from node on handle.
-void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
-                               Dali::Handle& handle, const Replacement& constant )
+const Property::Map& Builder::GetConstants() const
 {
-  if( Actor actor = Actor::DownCast(handle) )
-  {
-    SetProperties( node, actor, constant );
+  return mReplacementMap;
+}
 
-    if( actor )
-    {
-      // add signals
-      SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
-      SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
-   }
+const Property::Value& Builder::GetConstant( const std::string& key ) const
+{
+  Property::Value* match = mReplacementMap.Find( key );
+  if( match )
+  {
+    return (*match);
   }
   else
   {
-    SetProperties( node, handle, constant );
+    static Property::Value invalid;
+    return invalid;
   }
 }
 
-// Appling by style helper
-// use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
-void Builder::ApplyStylesByActor(  const TreeNode& root, const TreeNode& node,
-                                   Dali::Handle& handle, const Replacement& constant )
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
 {
-  if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
-  {
-    if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
-    {
-      // in a style the actor subtree properties referenced by actor name
-      for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
-      {
-        Dali::Actor foundActor;
-
-        if( (*iter).first )
-        {
-          foundActor = actor.FindChildByName( (*iter).first );
-        }
-
-        if( !foundActor )
-        {
-          // debug log cannot find searched for actor
-#if defined(DEBUG_ENABLED)
-          DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
-#endif
-        }
-        else
-        {
-#if defined(DEBUG_ENABLED)
-          DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
-#endif
-          ApplyProperties( root, (*iter).second, foundActor, constant );
-        }
-      }
-    }
-  }
+  Replacement replacement(map, mReplacementMap);
+  return CreateAnimation( animationName, replacement, sourceActor);
 }
 
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
+{
+  Replacement replacement(map, mReplacementMap);
+  return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
+}
 
-void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
-                                       Dali::Handle& handle, const Replacement& constant )
+Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
 {
-  OptionalChild styles = IsChild(root, KEYNAME_STYLES);
-  OptionalChild style  = IsChild(node, KEYNAME_STYLES);
+  Replacement replacement( mReplacementMap );
 
-  if( styles && style )
-  {
-    TreeNodeList additionalStyles;
+  return CreateAnimation( animationName, replacement, sourceActor );
+}
 
-    CollectAllStyles( *styles, *style, additionalStyles );
+Animation Builder::CreateAnimation( const std::string& animationName )
+{
+  Replacement replacement( mReplacementMap );
 
-#if defined(DEBUG_ENABLED)
-    for(TreeNode::ConstIterator iter = (*style).CBegin(); iter != (*style).CEnd(); ++iter)
-    {
-      if( OptionalString styleName = IsString( (*iter).second ) )
-      {
-        DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
-      }
-    }
-#endif
+  return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
+}
 
-    // a style may have other styles, which has other styles etc so we apply in reverse by convention.
-    for(TreeNodeList::reverse_iterator iter = additionalStyles.rbegin(); iter != additionalStyles.rend(); ++iter)
-    {
-      ApplyProperties( root, *(*iter), handle, constant );
+BaseHandle Builder::Create( const std::string& templateName )
+{
+  Replacement replacement( mReplacementMap );
+  return Create( templateName, replacement );
+}
 
-      ApplyStylesByActor( root, *(*iter), handle, constant );
-    }
-  }
+BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
+{
+  Replacement replacement( map, mReplacementMap );
+  return Create( templateName, replacement );
+}
+
+BaseHandle Builder::CreateFromJson( const std::string& json )
+{
+  BaseHandle ret;
 
-  // applying given node last
-  ApplyProperties( root, node, handle, constant );
+  // merge in new template, hoping no one else has one named '@temp@'
+  std::string newTemplate =
+    std::string("{\"templates\":{\"@temp@\":") +                      \
+    json +                                                            \
+    std::string("}}");
 
-  ApplyStylesByActor( root, node, handle, constant );
+  if( mParser.Parse(newTemplate) )
+  {
+    Replacement replacement( mReplacementMap );
+    ret = Create( "@temp@", replacement );
+  }
 
+  return ret;
 }
 
-
-/*
- * Create a dali type from a node.
- * If parent given and an actor type was created then add it to the parent and
- * recursively add nodes children.
- */
-BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
-                              Actor parent, const Replacement& replacements )
+bool Builder::ApplyFromJson(  Handle& handle, const std::string& json )
 {
-  BaseHandle baseHandle;
-  TypeInfo typeInfo;
-  const TreeNode* templateNode = NULL;
-
-  if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
-  {
-    typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
+  bool ret = false;
 
-    if( !typeInfo )
-    {
-      // a template name is also allowed inplace of the type name
-      OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
-
-      if( templates )
-      {
-        if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
-        {
-          templateNode = &(*isTemplate);
-
-          if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
-          {
-            typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
-          }
-        }
-      }
-    }
-  }
+  // merge new style, hoping no one else has one named '@temp@'
+  std::string newStyle =
+    std::string("{\"styles\":{\"@temp@\":") +                           \
+    json +                                                              \
+    std::string("}}");
 
-  if(!typeInfo)
+  if( mParser.Parse(newStyle) )
   {
-    DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
+    Replacement replacement( mReplacementMap );
+    ret = ApplyStyle( "@temp@", handle, replacement );
   }
-  else
-  {
-    baseHandle       = typeInfo.CreateInstance();
-    Handle handle    = Handle::DownCast(baseHandle);
-    Actor actor      = Actor::DownCast(handle);
-
-    if(handle)
-    {
-
-      DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
-
-#if defined(DEBUG_ENABLED)
-      if(handle)
-      {
-        DALI_SCRIPT_VERBOSE("  Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
-        DALI_SCRIPT_VERBOSE("  Is Handle Property Count=%d\n", handle.GetPropertyCount());
-      }
-
-      if(actor)
-      {
-        DALI_SCRIPT_VERBOSE("  Is Actor id=%d\n", actor.GetId());
-      }
-
-      Toolkit::Control control  = Toolkit::Control::DownCast(handle);
-      if(control)
-      {
-        DALI_SCRIPT_VERBOSE("  Is Control id=%d\n", actor.GetId());
-      }
-#endif // DEBUG_ENABLED
 
-      if( templateNode )
-      {
-        ApplyProperties( root, *templateNode, handle, replacements );
+  return ret;
+}
 
-        if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
-        {
-          for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
-          {
-            DoCreate( root, (*iter).second, actor, replacements );
-          }
-        }
-      }
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
+{
+  Replacement replacer( mReplacementMap );
+  return ApplyStyle( styleName, handle, replacer );
+}
 
-      if( actor )
-      {
-        // add children of all the styles
-        if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
-        {
-          for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
-          {
-            DoCreate( root, (*iter).second, actor, replacements );
-          }
-        }
+bool Builder::LookupStyleName( const std::string& styleName )
+{
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-        // apply style on top as they need the children to exist
-        ApplyAllStyleProperties( root, node, actor, replacements );
+  OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
+  OptionalChild style  = IsChildIgnoreCase( *styles, styleName );
 
-        // then add to parent
-        if( parent )
-        {
-          parent.Add( actor );
-        }
-      }
-      else
-      {
-        ApplyProperties( root, node, handle, replacements );
-      }
-    }
-    else
-    {
-      DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
-    }
+  if( styles && style )
+  {
+    return true;
   }
-
-  return baseHandle;
+  return false;
 }
 
-void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
+const StylePtr Builder::GetStyle( const std::string& styleName )
 {
-  const Stage& stage = Stage::GetCurrent();
-  Layer root  = stage.GetRootLayer();
+  const StylePtr* style = mStyles.FindCaseInsensitiveC( styleName );
 
-  if( OptionalString s = constant.IsString( IsChild(node, "sourceActor") ) )
+  if( style==NULL )
   {
-    Actor actor = root.FindChildByName(*s);
-    if(actor)
-    {
-      task.SetSourceActor( actor );
-    }
-    else
-    {
-      DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
-    }
+    return StylePtr(NULL);
   }
-
-  if( OptionalString s = constant.IsString( IsChild(node, "cameraActor") ) )
+  else
   {
-    CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
-    if(actor)
-    {
-      task.SetCameraActor( actor );
-    }
-    else
-    {
-      DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
-    }
+    return *style;
   }
+}
 
-  if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) )
-  {
-    FrameBufferImage fb = GetFrameBufferImage( *s, constant );
-    if(fb)
-    {
-      task.SetTargetFrameBuffer( fb );
-    }
-    else
-    {
-      DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
-    }
-  }
+void Builder::AddActors( Actor toActor )
+{
+  // 'stage' is the default/by convention section to add from
+  AddActors( "stage", toActor );
+}
 
-  if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
+void Builder::AddActors( const std::string &sectionName, Actor toActor )
+{
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+  Property::Map overrideMap;
+  Replacement replacements(overrideMap, mReplacementMap);
+
+  OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
+
+  if( add )
   {
-    if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
-    {
-      task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
-    }
-    else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
+    for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
     {
-      task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
+      // empty actor adds directly to the stage
+      BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
+      Actor actor = Actor::DownCast(baseHandle);
+      if(actor)
+      {
+        toActor.Add( actor );
+      }
     }
-    else
+
+    // if were adding the 'stage' section then also check for a render task called stage
+    // to add automatically
+    if( "stage" == sectionName )
     {
-      DALI_SCRIPT_WARNING("todo");
+      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") )
+      {
+        if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
+        {
+          CreateRenderTask( "stage" );
+        }
+      }
     }
   }
-
-  // other setup is via the property system
-  SetProperties( node, task, constant );
 }
 
 void Builder::CreateRenderTask( const std::string &name )
@@ -741,6 +632,7 @@ PathConstrainer Builder::GetPathConstrainer( const std::string& name )
   return ret;
 }
 
+
 bool Builder::IsPathConstrainer( const std::string& name )
 {
   size_t count( mPathConstrainerLut.size() );
@@ -877,60 +769,67 @@ void Builder::EmitQuitSignal()
   mQuitSignal.Emit();
 }
 
-void Builder::AddActors( Actor toActor )
+Builder::~Builder()
 {
-  // 'stage' is the default/by convention section to add from
-  AddActors( "stage", toActor );
 }
 
-void Builder::AddActors( const std::string &sectionName, Actor toActor )
+void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
 {
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
-
-  Property::Map overrideMap;
-  Replacement replacements(overrideMap, mReplacementMap);
-
-  OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
+  Replacement replacer(intoMap);
 
-  if( add )
+  if( OptionalChild constants = IsChild(root, "constants") )
   {
-    for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )
-    {
-      // empty actor adds directly to the stage
-      BaseHandle baseHandle = DoCreate( *mParser.GetRoot(), (*iter).second, Actor(), replacements );
-      Actor actor = Actor::DownCast(baseHandle);
-      if(actor)
-      {
-        toActor.Add( actor );
-      }
-    }
-
-    // if were adding the 'stage' section then also check for a render task called stage
-    // to add automatically
-    if( "stage" == sectionName )
+    for(TreeNode::ConstIterator iter = (*constants).CBegin();
+        iter != (*constants).CEnd(); ++iter)
     {
-      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") )
+      Dali::Property::Value property;
+      if( (*iter).second.GetName() )
       {
-        if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
-        {
-          CreateRenderTask( "stage" );
-        }
+#if defined(DEBUG_ENABLED)
+        DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
+#endif
+        DeterminePropertyFromNode( (*iter).second, property, replacer );
+        intoMap[ (*iter).second.GetName() ] = property;
       }
     }
   }
-}
-
-Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
-{
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
-
-  Animation anim;
 
-  if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
+#if defined(DEBUG_ENABLED)
+  Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" );
+  if( iter && iter->GetType() == Property::STRING )
   {
-    if( OptionalChild animation = IsChild(*animations, animationName) )
+    std::string logLevel( iter->Get< std::string >() );
+    if( logLevel == "NoLogging" )
     {
-      anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor, this );
+      gFilterScript->SetLogLevel( Integration::Log::NoLogging );
+    }
+    else if( logLevel == "Concise" )
+    {
+      gFilterScript->SetLogLevel( Integration::Log::Concise );
+    }
+    else if( logLevel == "General" )
+    {
+      gFilterScript->SetLogLevel( Integration::Log::General );
+    }
+    else if( logLevel == "Verbose" )
+    {
+      gFilterScript->SetLogLevel( Integration::Log::Verbose );
+    }
+  }
+#endif
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor )
+{
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+  Animation anim;
+
+  if( OptionalChild animations = IsChild(*mParser.GetRoot(), "animations") )
+  {
+    if( OptionalChild animation = IsChild(*animations, animationName) )
+    {
+      anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor, this );
     }
     else
     {
@@ -945,412 +844,737 @@ Animation Builder::CreateAnimation( const std::string& animationName, const Repl
   return anim;
 }
 
-Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
+BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
 {
-  Replacement replacement(map, mReplacementMap);
-  return CreateAnimation( animationName, replacement, sourceActor);
-}
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
-{
-  Replacement replacement(map, mReplacementMap);
-  return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
-}
+  BaseHandle baseHandle;
 
-Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
-{
-  Replacement replacement( mReplacementMap );
+  OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
 
-  return CreateAnimation( animationName, replacement, sourceActor );
-}
+  if( !templates )
+  {
+    DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
+  }
+  else
+  {
+    OptionalChild childTemplate = IsChild(*templates, templateName);
+    if(!childTemplate)
+    {
+      DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
+    }
+    else
+    {
+      OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
 
-Animation Builder::CreateAnimation( const std::string& animationName )
-{
-  Replacement replacement( mReplacementMap );
+      if(!type)
+      {
+        DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
+      }
+      else
+      {
+        baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
+      }
+    }
+  }
 
-  return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
+  return baseHandle;
 }
 
-bool Builder::ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& child )
+/*
+ * Create a dali type from a node.
+ * If parent given and an actor type was created then add it to the parent and
+ * recursively add nodes children.
+ */
+BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
+                              Actor parent, const Replacement& replacements )
 {
-  bool result = false;
+  BaseHandle baseHandle;
+  TypeInfo typeInfo;
+  const TreeNode* templateNode = NULL;
 
-  switch( child.GetType() )
+  if( OptionalString typeName = IsString(node, KEYNAME_TYPE) )
   {
-    case Property::STRING:
+    typeInfo = TypeRegistry::Get().GetTypeInfo( *typeName );
+
+    if( !typeInfo )
     {
-      std::string value;
-      if( child.Get( value ) )
+      // a template name is also allowed inplace of the type name
+      OptionalChild templates = IsChild( root, KEYNAME_TEMPLATES);
+
+      if( templates )
       {
-        std::string key;
-        if( GetMappingKey( value, key ) )
+        if( OptionalChild isTemplate = IsChild( *templates, *typeName ) )
         {
-          // Check key for cycles:
-          result=true;
-          for( KeyStack::iterator iter = keyStack.begin() ; iter != keyStack.end(); ++iter )
-          {
-            if( key.compare(*iter) == 0 )
-            {
-              // key is already in stack; stop.
-              DALI_LOG_WARNING("Detected cycle in stylesheet mapping table:%s\n", key.c_str());
-              child = Property::Value("");
-              result=false;
-              break;
-            }
-          }
+          templateNode = &(*isTemplate);
 
-          if( result )
+          if( OptionalString templateTypeName = IsString(*templateNode, KEYNAME_TYPE) )
           {
-            // The following call will overwrite the child with the value
-            // from the mapping.
-            RecursePropertyMap( mappingRoot, keyStack, key.c_str(), Property::NONE, child );
-            result = true;
+            typeInfo = TypeRegistry::Get().GetTypeInfo( *templateTypeName );
           }
         }
       }
-      break;
     }
+  }
 
-    case Property::MAP:
+  if(!typeInfo)
+  {
+    DALI_SCRIPT_WARNING("Cannot create Dali type from node '%s'\n", node.GetName());
+  }
+  else
+  {
+    baseHandle       = typeInfo.CreateInstance();
+    Handle handle    = Handle::DownCast(baseHandle);
+    Actor actor      = Actor::DownCast(handle);
+
+    if(handle)
     {
-      Property::Map* map = child.GetMap();
-      if( map )
+
+      DALI_SCRIPT_VERBOSE("Create:%s\n", typeInfo.GetName().c_str());
+
+#if defined(DEBUG_ENABLED)
+      if(handle)
       {
-        for( Property::Map::SizeType i=0; i < map->Count(); ++i )
-        {
-          Property::Value& child = map->GetValue(i);
-          ConvertChildValue(mappingRoot, keyStack, child);
-        }
+        DALI_SCRIPT_VERBOSE("  Is Handle Object=%d\n", (long*)handle.GetObjectPtr());
+        DALI_SCRIPT_VERBOSE("  Is Handle Property Count=%d\n", handle.GetPropertyCount());
       }
-      break;
-    }
 
-    case Property::ARRAY:
-    {
-      Property::Array* array = child.GetArray();
-      if( array )
+      if(actor)
       {
-        for( Property::Array::SizeType i=0; i < array->Count(); ++i )
-        {
-          Property::Value& child = array->GetElementAt(i);
-          ConvertChildValue(mappingRoot, keyStack, child);
-        }
+        DALI_SCRIPT_VERBOSE("  Is Actor id=%d\n", actor.GetId());
       }
-      break;
-    }
-
-    default:
-      // Ignore other types.
-      break;
-  }
 
-  return result;
-}
+      Toolkit::Control control  = Toolkit::Control::DownCast(handle);
+      if(control)
+      {
+        DALI_SCRIPT_VERBOSE("  Is Control id=%d\n", actor.GetId());
+      }
+#endif // DEBUG_ENABLED
 
-bool Builder::RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value )
-{
-  Replacement replacer( mReplacementMap );
-  bool result = false;
+      if( templateNode )
+      {
+        ApplyProperties( root, *templateNode, handle, replacements );
 
-  keyStack.push_back( theKey );
+        if( OptionalChild actors = IsChild( *templateNode, KEYNAME_ACTORS ) )
+        {
+          for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
+          {
+            DoCreate( root, (*iter).second, actor, replacements );
+          }
+        }
+      }
 
-  for( TreeNode::ConstIterator iter = mappingRoot.CBegin(); iter != mappingRoot.CEnd(); ++iter )
-  {
-    std::string aKey( (*iter).first );
-    if( aKey.compare( theKey ) == 0 )
-    {
-      if( propertyType == Property::NONE )
+      if( actor )
       {
-        DeterminePropertyFromNode( (*iter).second, value, replacer );
-        result = true;
+        // add children of all the styles
+        if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
+        {
+          for( TreeConstIter iter = (*actors).CBegin(); iter != (*actors).CEnd(); ++iter )
+          {
+            DoCreate( root, (*iter).second, actor, replacements );
+          }
+        }
+
+        // apply style on top as they need the children to exist
+        ApplyAllStyleProperties( root, node, actor, replacements );
+
+        // then add to parent
+        if( parent )
+        {
+          parent.Add( actor );
+        }
       }
       else
       {
-        result = DeterminePropertyFromNode( (*iter).second, propertyType, value, replacer );
-      }
-
-      if( result )
-      {
-        ConvertChildValue(mappingRoot, keyStack, value);
+        ApplyProperties( root, node, handle, replacements );
       }
-      break;
+    }
+    else
+    {
+      DALI_SCRIPT_WARNING("Cannot create handle from type '%s'\n", typeInfo.GetName().c_str());
     }
   }
-  keyStack.pop_back();
-
-  return result;
-}
-
 
-bool Builder::GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value )
-{
-  KeyStack keyStack;
-  return RecursePropertyMap( mappingRoot, keyStack, theKey, propertyType, value );
+  return baseHandle;
 }
 
-
-void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
+void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
 {
-  // parser to get constants and includes only
-  Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
+  const Stage& stage = Stage::GetCurrent();
+  Layer root  = stage.GetRootLayer();
 
-  if( !parser.Parse( data ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "sourceActor") ) )
   {
-    DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
-                      parser.GetErrorLineNumber(),
-                      parser.GetErrorColumn(),
-                      parser.GetErrorDescription().c_str() );
-
-    DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+    Actor actor = root.FindChildByName(*s);
+    if(actor)
+    {
+      task.SetSourceActor( actor );
+    }
+    else
+    {
+      DALI_SCRIPT_WARNING("Cannot find source actor on stage for render task called '%s'\n", (*s).c_str() );
+    }
   }
-  else
-  {
-    // load constant map (allows the user to override the constants in the json after loading)
-    LoadConstants( *parser.GetRoot(), mReplacementMap );
 
-    // merge includes
-    if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
+  if( OptionalString s = constant.IsString( IsChild(node, "cameraActor") ) )
+  {
+    CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
+    if(actor)
     {
-      Replacement replacer( mReplacementMap );
-
-      for(TreeNode::ConstIterator iter = (*includes).CBegin(); iter != (*includes).CEnd(); ++iter)
-      {
-        OptionalString filename = replacer.IsString( (*iter).second );
-
-        if( filename )
-        {
-#if defined(DEBUG_ENABLED)
-          DALI_SCRIPT_VERBOSE("Loading Include '%s'\n", (*filename).c_str());
-#endif
-          LoadFromString( GetFileContents(*filename) );
-        }
-      }
+      task.SetCameraActor( actor );
     }
-
-    if( !mParser.Parse( data ) )
+    else
     {
-      DALI_LOG_WARNING( "JSON Parse Error:%d:%d:'%s'\n",
-                        mParser.GetErrorLineNumber(),
-                        mParser.GetErrorColumn(),
-                        mParser.GetErrorDescription().c_str() );
+      DALI_SCRIPT_WARNING("Cannot find camera actor on stage for render task called '%s'\n", (*s).c_str() );
+    }
+  }
 
-      DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
+  if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) )
+  {
+    FrameBufferImage fb = GetFrameBufferImage( *s, constant );
+    if(fb)
+    {
+      task.SetTargetFrameBuffer( fb );
+    }
+    else
+    {
+      DALI_SCRIPT_WARNING("Cannot find target frame buffer '%s'\n", (*s).c_str() );
     }
   }
 
-  DUMP_PARSE_TREE(parser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
-  DUMP_TEST_MAPPINGS(parser);
+  if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
+  {
+    if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
+    {
+      task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
+    }
+    else if("FULLSCREEN_FRAMEBUFFER_FUNCTION" == *s)
+    {
+      task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
+    }
+    else
+    {
+      DALI_SCRIPT_WARNING("todo");
+    }
+  }
 
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
+  // other setup is via the property system
+  SetProperties( node, task, constant );
 }
 
-void Builder::AddConstants( const Property::Map& map )
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
 {
-  mReplacementMap.Merge( map );
-}
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-void Builder::AddConstant( const std::string& key, const Property::Value& value )
-{
-  mReplacementMap[key] = value;
-}
+  OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
 
-const Property::Map& Builder::GetConstants() const
-{
-  return mReplacementMap;
-}
+  std::string styleNameLower(styleName);
+  OptionalChild style  = IsChildIgnoreCase( *styles, styleNameLower );
 
-const Property::Value& Builder::GetConstant( const std::string& key ) const
-{
-  Property::Value* match = mReplacementMap.Find( key );
-  if( match )
+  if( styles && style )
   {
-    return (*match);
+    ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
+    return true;
   }
   else
   {
-    static Property::Value invalid;
-    return invalid;
+    return false;
   }
 }
 
-void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
+void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
+                                       Dali::Handle& handle, const Replacement& constant )
 {
-  Replacement replacer(intoMap);
+  const char* styleName = node.GetName();
 
-  if( OptionalChild constants = IsChild(root, "constants") )
+  StylePtr style = Style::New();
+
+  StylePtr* matchedStyle = NULL;
+  if( styleName )
   {
-    for(TreeNode::ConstIterator iter = (*constants).CBegin();
-        iter != (*constants).CEnd(); ++iter)
+    matchedStyle = mStyles.FindCaseInsensitive( styleName );
+    if( ! matchedStyle )
     {
-      Dali::Property::Value property;
-      if( (*iter).second.GetName() )
+      OptionalChild styleNodes = IsChild(root, KEYNAME_STYLES);
+      OptionalChild inheritFromNode = IsChild(node, KEYNAME_INHERIT);
+      if( !inheritFromNode )
+      {
+        inheritFromNode = IsChild( node, KEYNAME_STYLES );
+      }
+
+      if( styleNodes )
       {
+        if( inheritFromNode )
+        {
+          TreeNodeList additionalStyleNodes;
+
+          CollectAllStyles( *styleNodes, *inheritFromNode, additionalStyleNodes );
+
 #if defined(DEBUG_ENABLED)
-        DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
+          for(TreeNode::ConstIterator iter = (*inheritFromNode).CBegin(); iter != (*inheritFromNode).CEnd(); ++iter)
+          {
+            if( OptionalString styleName = IsString( (*iter).second ) )
+            {
+              DALI_SCRIPT_VERBOSE("Style Applied '%s'\n", (*styleName).c_str());
+            }
+          }
 #endif
-        DeterminePropertyFromNode( (*iter).second, property, replacer );
-        intoMap[ (*iter).second.GetName() ] = property;
+
+          // a style may have other styles, which has other styles etc so we apply in reverse by convention.
+          for(TreeNodeList::reverse_iterator iter = additionalStyleNodes.rbegin(); iter != additionalStyleNodes.rend(); ++iter)
+          {
+            RecordStyle( style, *(*iter), handle, constant );
+            ApplySignals( root, *(*iter), handle );
+            ApplyStylesByActor( root, *(*iter), handle, constant );
+          }
+        }
+
+        RecordStyle( style, node, handle, constant );
+        mStyles.Add( styleName, style ); // shallow copy
+        matchedStyle = &style;
       }
     }
   }
 
-#if defined(DEBUG_ENABLED)
-  Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" );
-  if( iter && iter->GetType() == Property::STRING )
+  if( matchedStyle )
   {
-    std::string logLevel( iter->Get< std::string >() );
-    if( logLevel == "NoLogging" )
+    StylePtr style( *matchedStyle );
+    style->ApplyVisualsAndPropertiesRecursively( handle ); // (recurses through states)
+  }
+  else // If there were no styles, instead set properties
+  {
+    SetProperties( node, handle, constant );
+  }
+  ApplySignals( root, node, handle );
+  ApplyStylesByActor( root, node, handle, constant );
+}
+
+void Builder::RecordStyle( StylePtr           style,
+                           const TreeNode&    node,
+                           Dali::Handle&      handle,
+                           const Replacement& replacements )
+{
+  // With repeated calls, accumulate inherited states, visuals and properties
+  // but override any with same name
+
+  for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
+  {
+    const TreeNode::KeyNodePair& keyValue = *iter;
+    std::string key( keyValue.first );
+    if( key == KEYNAME_STATES )
     {
-      gFilterScript->SetLogLevel( Integration::Log::NoLogging );
+      const TreeNode& states = keyValue.second;
+      if( states.GetType() != TreeNode::OBJECT )
+      {
+        DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", key.c_str() );
+        continue;
+      }
+
+      for( TreeNode::ConstIterator iter = states.CBegin(); iter != states.CEnd(); ++iter )
+      {
+        const TreeNode& stateNode = (*iter).second;
+        const char* stateName = stateNode.GetName();
+        if( stateNode.GetType() != TreeNode::OBJECT )
+        {
+          DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", stateName );
+          continue;
+        }
+
+        StylePtr* stylePtr = style->subStates.FindCaseInsensitive( stateName );
+        if( stylePtr )
+        {
+          StylePtr style(*stylePtr);
+          RecordStyle( style, stateNode, handle, replacements );
+        }
+        else
+        {
+          StylePtr subState = Style::New();
+          RecordStyle( subState, stateNode, handle, replacements );
+          style->subStates.Add( stateName, subState );
+        }
+      }
     }
-    else if( logLevel == "Concise" )
+    else if( key == KEYNAME_VISUALS )
     {
-      gFilterScript->SetLogLevel( Integration::Log::Concise );
+      for( TreeNode::ConstIterator iter = keyValue.second.CBegin(); iter != keyValue.second.CEnd(); ++iter )
+      {
+        // Each key in this table should be a property name matching a visual.
+        const TreeNode::KeyNodePair& visual = *iter;
+        Dali::Property::Value property(Property::MAP);
+        if( DeterminePropertyFromNode( visual.second, Property::MAP, property, replacements ) )
+        {
+          Property::Map* mapPtr = style->visuals.FindCaseInsensitive( visual.first );
+          if( mapPtr )
+          {
+            // Override existing visuals
+            mapPtr->Clear();
+            mapPtr->Merge(*property.GetMap());
+          }
+          else
+          {
+            style->visuals.Add(visual.first, *property.GetMap());
+          }
+        }
+      }
     }
-    else if( logLevel == "General" )
+    else if( key == KEYNAME_ENTRY_TRANSITION )
     {
-      gFilterScript->SetLogLevel( Integration::Log::General );
+      Dali::Property::Value property(Property::MAP);
+      if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) )
+      {
+        style->entryTransition = Toolkit::TransitionData::New( *property.GetMap() );
+      }
     }
-    else if( logLevel == "Verbose" )
+    else if( key == KEYNAME_EXIT_TRANSITION )
     {
-      gFilterScript->SetLogLevel( Integration::Log::Verbose );
+      Dali::Property::Value property(Property::MAP);
+      if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) )
+      {
+        style->exitTransition = Toolkit::TransitionData::New( *property.GetMap() );
+      }
+    }
+    else if( key == KEYNAME_TRANSITIONS )
+    {
+      //@todo add new transitions to style.transitions
+      //      override existing transitions. A transition matches on target & property name
+      const TreeNode& node = keyValue.second;
+      if( node.GetType() == TreeNode::ARRAY )
+      {
+        Dali::Property::Value property(Property::ARRAY);
+        if( DeterminePropertyFromNode( node, Property::ARRAY, property, replacements ) )
+        {
+          style->transitions = *property.GetArray();
+        }
+      }
+      else if( node.GetType() == TreeNode::OBJECT )
+      {
+        Dali::Property::Value property(Property::MAP);
+        if( DeterminePropertyFromNode( node, Property::MAP, property, replacements ) )
+        {
+          Property::Array propertyArray;
+          propertyArray.Add( property );
+          style->transitions = propertyArray;
+        }
+      }
+      else
+      {
+        DALI_LOG_WARNING( "RecordState() Node \"%s\" is not a JSON array or object\n", key.c_str() );
+      }
+    }
+    else if( key == KEYNAME_TYPE ||
+             key == KEYNAME_ACTORS ||
+             key == KEYNAME_SIGNALS ||
+             key == KEYNAME_STYLES ||
+             key == KEYNAME_MAPPINGS ||
+             key == KEYNAME_INHERIT )
+    {
+      continue;
+    }
+    else // It's a property
+    {
+      Property::Index index;
+      Property::Value value;
+      if( MapToTargetProperty( handle, key, keyValue.second, replacements, index, value ) )
+      {
+        Property::Value* existingValuePtr = style->properties.Find( index );
+        if( existingValuePtr != NULL )
+        {
+          *existingValuePtr = value; // Overwrite existing property.
+        }
+        else
+        {
+          style->properties.Add( index, value );
+        }
+      }
     }
   }
-#endif
+}
 
+// Set properties from node on handle.
+void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
+                               Dali::Handle& handle, const Replacement& constant )
+{
+  SetProperties( node, handle, constant );
+  ApplySignals( root, node, handle );
 }
 
-bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
+void Builder::ApplySignals(const TreeNode& root, const TreeNode& node, Dali::Handle& handle )
 {
-  Replacement replacer( mReplacementMap );
-  return ApplyStyle( styleName, handle, replacer );
+  Actor actor = Actor::DownCast(handle);
+  if( actor )
+  {
+    // add signals
+    SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
+    SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
+  }
 }
 
-bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
+
+// Appling by style helper
+// use FindChildByName() to apply properties referenced in KEYNAME_ACTORS in the node
+void Builder::ApplyStylesByActor(  const TreeNode& root, const TreeNode& node,
+                                   Dali::Handle& handle, const Replacement& constant )
 {
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+  if( Dali::Actor actor = Dali::Actor::DownCast( handle ) )
+  {
+    if( const TreeNode* actors = node.GetChild( KEYNAME_ACTORS ) )
+    {
+      // in a style the actor subtree properties referenced by actor name
+      for( TreeConstIter iter = actors->CBegin(); iter != actors->CEnd(); ++iter )
+      {
+        Dali::Actor foundActor;
 
-  OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
+        if( (*iter).first )
+        {
+          foundActor = actor.FindChildByName( (*iter).first );
+        }
 
-  std::string styleNameLower(styleName);
-  OptionalChild style  = IsChildIgnoreCase( *styles, styleNameLower );
+        if( !foundActor )
+        {
+          DALI_SCRIPT_VERBOSE("Cannot find actor in style application '%s'\n", (*iter).first);
+        }
+        else
+        {
+          DALI_SCRIPT_VERBOSE("Styles applied to actor '%s'\n", (*iter).first);
+          ApplyProperties( root, (*iter).second, foundActor, constant );
+        }
+      }
+    }
+  }
+}
 
-  if( styles && style )
+/*
+ * Sets the handle properties found in the tree node
+ */
+void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant )
+{
+  if( handle )
   {
-    ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
-    return true;
+    for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
+    {
+      const TreeNode::KeyNodePair& keyChild = *iter;
+
+      std::string key( keyChild.first );
+
+      // ignore special fields;
+      if( key == KEYNAME_TYPE ||
+          key == KEYNAME_ACTORS ||
+          key == KEYNAME_SIGNALS ||
+          key == KEYNAME_STYLES ||
+          key == KEYNAME_MAPPINGS ||
+          key == KEYNAME_INHERIT ||
+          key == KEYNAME_STATES ||
+          key == KEYNAME_VISUALS ||
+          key == KEYNAME_ENTRY_TRANSITION ||
+          key == KEYNAME_EXIT_TRANSITION ||
+          key == KEYNAME_TRANSITIONS )
+      {
+        continue;
+      }
+
+      Property::Index index;
+      Property::Value value;
+
+      bool mapped = MapToTargetProperty( handle, key, keyChild.second, constant, index, value );
+      if( mapped )
+      {
+        DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
+
+        handle.SetProperty( index, value );
+      }
+
+      // Add custom properties
+      SetCustomProperties(node, handle, constant, PROPERTIES, Property::READ_WRITE);
+      SetCustomProperties(node, handle, constant, ANIMATABLE_PROPERTIES, Property::ANIMATABLE);
+
+    } // for property nodes
   }
   else
   {
-    return false;
+    DALI_SCRIPT_WARNING("Style applied to empty handle\n");
   }
 }
 
-BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
+bool Builder::MapToTargetProperty(
+  Handle&            propertyObject,
+  const std::string& key,
+  const TreeNode&    node,
+  const Replacement& constant,
+  Property::Index&   index,
+  Property::Value&   value )
 {
-  Replacement replacement( map, mReplacementMap );
-  return Create( templateName, replacement );
+  bool mapped = false;
+
+  index = propertyObject.GetPropertyIndex( key );
+  if( Property::INVALID_INDEX != index )
+  {
+    Property::Type type = propertyObject.GetPropertyType(index);
+
+    // if node.value is a mapping, get the property value from the "mappings" table
+    if( node.GetType() == TreeNode::STRING )
+    {
+      std::string mappingKey;
+      if( GetMappingKey( node.GetString(), mappingKey) )
+      {
+        OptionalChild mappingRoot = IsChild( mParser.GetRoot(), KEYNAME_MAPPINGS );
+        mapped = GetPropertyMap( *mappingRoot, mappingKey.c_str(), type, value );
+      }
+    }
+    if( ! mapped )
+    {
+      mapped = DeterminePropertyFromNode( node, type, value, constant );
+      if( ! mapped )
+      {
+        // Just determine the property from the node and if it's valid, let the property object handle it
+        DeterminePropertyFromNode( node, value, constant );
+        mapped = ( value.GetType() != Property::NONE );
+      }
+    }
+  }
+  else
+  {
+    DALI_LOG_ERROR("Key '%s' not found.\n", key.c_str());
+  }
+  return mapped;
 }
 
-BaseHandle Builder::Create( const std::string& templateName, const Replacement& constant )
+bool Builder::GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value )
 {
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+  KeyStack keyStack;
+  return RecursePropertyMap( mappingRoot, keyStack, theKey, propertyType, value );
+}
 
-  BaseHandle baseHandle;
+bool Builder::RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value )
+{
+  Replacement replacer( mReplacementMap );
+  bool result = false;
 
-  OptionalChild templates = IsChild(*mParser.GetRoot(), KEYNAME_TEMPLATES);
+  keyStack.push_back( theKey );
 
-  if( !templates )
-  {
-    DALI_SCRIPT_WARNING("No template section found to CreateFromTemplate\n");
-  }
-  else
+  for( TreeNode::ConstIterator iter = mappingRoot.CBegin(); iter != mappingRoot.CEnd(); ++iter )
   {
-    OptionalChild childTemplate = IsChild(*templates, templateName);
-    if(!childTemplate)
-    {
-      DALI_SCRIPT_WARNING("Template '%s' does not exist in template section\n", templateName.c_str());
-    }
-    else
+    std::string aKey( (*iter).first );
+    if( aKey.compare( theKey ) == 0 )
     {
-      OptionalString type = constant.IsString( IsChild(*childTemplate, KEYNAME_TYPE) );
-
-      if(!type)
+      if( propertyType == Property::NONE )
       {
-        DALI_SCRIPT_WARNING("Cannot create template '%s' as template section is missing 'type'\n", templateName.c_str());
+        DeterminePropertyFromNode( (*iter).second, value, replacer );
+        result = true;
       }
       else
       {
-        baseHandle = DoCreate( *mParser.GetRoot(), *childTemplate, Actor(), constant );
+        result = DeterminePropertyFromNode( (*iter).second, propertyType, value, replacer );
+      }
+
+      if( result )
+      {
+        ConvertChildValue(mappingRoot, keyStack, value);
       }
+      break;
     }
   }
+  keyStack.pop_back();
 
-  return baseHandle;
+  return result;
 }
 
-BaseHandle Builder::CreateFromJson( const std::string& json )
+bool Builder::ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& child )
 {
-  BaseHandle ret;
-
-  // merge in new template, hoping no one else has one named '@temp@'
-  std::string newTemplate =
-    std::string("{\"templates\":{\"@temp@\":") +                      \
-    json +                                                            \
-    std::string("}}");
+  bool result = false;
 
-  if( mParser.Parse(newTemplate) )
+  switch( child.GetType() )
   {
-    Replacement replacement( mReplacementMap );
-    ret = Create( "@temp@", replacement );
-  }
+    case Property::STRING:
+    {
+      std::string value;
+      if( child.Get( value ) )
+      {
+        std::string key;
+        if( GetMappingKey( value, key ) )
+        {
+          // Check key for cycles:
+          result=true;
+          for( KeyStack::iterator iter = keyStack.begin() ; iter != keyStack.end(); ++iter )
+          {
+            if( key.compare(*iter) == 0 )
+            {
+              // key is already in stack; stop.
+              DALI_LOG_WARNING("Detected cycle in stylesheet mapping table:%s\n", key.c_str());
+              child = Property::Value("");
+              result=false;
+              break;
+            }
+          }
 
-  return ret;
-}
+          if( result )
+          {
+            // The following call will overwrite the child with the value
+            // from the mapping.
+            RecursePropertyMap( mappingRoot, keyStack, key.c_str(), Property::NONE, child );
+            result = true;
+          }
+        }
+      }
+      break;
+    }
 
-bool Builder::ApplyFromJson(  Handle& handle, const std::string& json )
-{
-  bool ret = false;
+    case Property::MAP:
+    {
+      Property::Map* map = child.GetMap();
+      if( map )
+      {
+        for( Property::Map::SizeType i=0; i < map->Count(); ++i )
+        {
+          Property::Value& child = map->GetValue(i);
+          ConvertChildValue(mappingRoot, keyStack, child);
+        }
+      }
+      break;
+    }
 
-  // merge new style, hoping no one else has one named '@temp@'
-  std::string newStyle =
-    std::string("{\"styles\":{\"@temp@\":") +                           \
-    json +                                                              \
-    std::string("}}");
+    case Property::ARRAY:
+    {
+      Property::Array* array = child.GetArray();
+      if( array )
+      {
+        for( Property::Array::SizeType i=0; i < array->Count(); ++i )
+        {
+          Property::Value& child = array->GetElementAt(i);
+          ConvertChildValue(mappingRoot, keyStack, child);
+        }
+      }
+      break;
+    }
 
-  if( mParser.Parse(newStyle) )
-  {
-    Replacement replacement( mReplacementMap );
-    ret = ApplyStyle( "@temp@", handle, replacement );
+    default:
+      // Ignore other types.
+      break;
   }
 
-  return ret;
-}
-
-
-BaseHandle Builder::Create( const std::string& templateName )
-{
-  Replacement replacement( mReplacementMap );
-  return Create( templateName, replacement );
+  return result;
 }
 
-Builder::Builder()
-: mSlotDelegate( this )
+void Builder::SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant,
+                          const std::string& childName, Property::AccessMode accessMode )
 {
-  mParser = Dali::Toolkit::JsonParser::New();
-
-  Property::Map defaultDirs;
-  defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]       = DALI_IMAGE_DIR;
-  defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ]       = DALI_SOUND_DIR;
-  defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ]       = DALI_STYLE_DIR;
-  defaultDirs[ TOKEN_STRING(DALI_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR;
+  // Add custom properties
+  if( OptionalChild customPropertiesChild = IsChild(node, childName) )
+  {
+    const TreeNode& customPropertiesNode = *customPropertiesChild;
+    const TreeConstIter endIter = customPropertiesNode.CEnd();
+    for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
+    {
+      const TreeNode::KeyNodePair& keyChild = *iter;
+      std::string key( keyChild.first );
+      Property::Value value;
+      DeterminePropertyFromNode( keyChild.second, value, constant );
 
-  AddConstants( defaultDirs );
+      // Register/Set property.
+      handle.RegisterProperty( key, value, accessMode );
+    }
+  }
 }
 
-Builder::~Builder()
-{
-}
 
 } // namespace Internal
 
index 4c018aa..b6db52d 100644 (file)
@@ -34,6 +34,7 @@
 #include <dali-toolkit/devel-api/builder/json-parser.h>
 #include <dali-toolkit/devel-api/builder/builder.h>
 #include <dali-toolkit/internal/builder/builder-declarations.h>
+#include <dali-toolkit/internal/builder/style.h>
 
 // Warning messages usually displayed
 #define DALI_SCRIPT_WARNING(format, args...) \
@@ -149,6 +150,24 @@ public:
   bool ApplyStyle( const std::string& styleName, Handle& handle );
 
   /**
+   * Lookup the stylename in builder. If it's found in the parse tree,
+   * then return true.
+   * @param[in] styleName The style name to search for
+   * @return true if the stylename exists
+   */
+  bool LookupStyleName( const std::string& styleName );
+
+  /**
+   * Lookup the stylename in the recorded Styles - if it exists,
+   * performs a shallow copy to the passed in style and returns true.
+   * Otherwise it returns false.
+
+   * @param[in] styleName The stylename to search for
+   * @return A const pointer to the style object
+   */
+  const StylePtr GetStyle( const std::string& styleName );
+
+  /**
    * @copydoc Toolkit::Builder::AddActors
    */
   void AddActors( Actor toActor );
@@ -214,99 +233,151 @@ public:
    */
   void EmitQuitSignal();
 
+
 protected:
 
   virtual ~Builder();
 
 private:
-  // Undefined
-  Builder(const Builder&);
-  Builder& operator=(const Builder& rhs);
-
-  void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
-
-  void SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant, const std::string& childName, Property::AccessMode accessMode );
-
-private:
-  Toolkit::JsonParser mParser;
-
-  typedef std::map<const std::string, FrameBufferImage> ImageLut;
-  ImageLut mFrameBufferImageLut;
-
-  typedef std::map<const std::string, Path> PathLut;
-  PathLut mPathLut;
-
-  typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
-  typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
-  PathConstrainerLut mPathConstrainerLut;
-
+  typedef std::vector<const char*> KeyStack;
+  typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
   typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
   typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
-  LinearConstrainerLut mLinearConstrainerLut;
-
-  SlotDelegate<Builder> mSlotDelegate;
-
-  Property::Map mReplacementMap;
-
-  typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
-  MappingsLut mCompleteMappings;
+  typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
+  typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
+  typedef std::map<const std::string, Path> PathLut;
+  typedef std::map<const std::string, FrameBufferImage> ImageLut;
 
-  BaseHandle Create( const std::string& templateName, const Replacement& constant );
+private:
+  // Undefined
+  Builder(const Builder&);
 
-  BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
+  // Undefined
+  Builder& operator=(const Builder& rhs);
 
   void LoadConstants( const TreeNode& root, Property::Map& intoMap );
 
-  void LoadIncludes( const std::string& data );
-
-  bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
-
-  Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
-
-  typedef std::vector<const char*> KeyStack;
+  Animation CreateAnimation( const std::string& animationName,
+                             const Replacement& replacement,
+                             Dali::Actor        sourceActor );
+
+  BaseHandle Create( const std::string& templateName,
+                     const Replacement& constant );
+
+  BaseHandle DoCreate( const TreeNode&    root,
+                       const TreeNode&    node,
+                       Actor              parent,
+                       const Replacement& replacements );
+
+  void SetupTask( RenderTask&              task,
+                  const Toolkit::TreeNode& node,
+                  const Replacement&       replacement );
+
+  bool ApplyStyle( const std::string& styleName,
+                   Handle&            handle,
+                   const Replacement& replacement);
+
+  void ApplyAllStyleProperties( const TreeNode&    root,
+                                const TreeNode&    node,
+                                Dali::Handle&      handle,
+                                const Replacement& constant );
+
+  void RecordStyles( const char*        styleName,
+                     const TreeNode&    node,
+                     Dali::Handle&      handle,
+                     const Replacement& replacements );
+
+  void RecordStyle( StylePtr           style,
+                    const TreeNode&    node,
+                    Dali::Handle&      handle,
+                    const Replacement& replacements );
+
+  void ApplyProperties( const TreeNode&    root,
+                        const TreeNode&    node,
+                        Dali::Handle&      handle,
+                        const Replacement& constant );
+
+  void ApplySignals( const TreeNode& root,
+                     const TreeNode& node,
+                     Dali::Handle& handle );
+
+  void ApplyStylesByActor( const TreeNode&    root,
+                           const TreeNode&    node,
+                           Dali::Handle&      handle,
+                           const Replacement& constant );
+
+  void SetProperties( const TreeNode&    node,
+                      Handle&            handle,
+                      const Replacement& constant );
+
+  bool MapToTargetProperty( Handle&            propertyObject,
+                            const std::string& key,
+                            const TreeNode&    node,
+                            const Replacement& constant,
+                            Property::Index&   index,
+                            Property::Value&   value );
 
   /**
-   * Tests if the value is a string delimited by <>. If it is, then it attempts to
-   * change the value to the mapping from a matching key in the mappings table.
+   * Find the key in the mapping table, if it's present, then generate
+   * a property value for it (of the given type if available),
+   * recursing as necessary, and stopping if any cycles are detected.
+   *
    * @param[in] mappingRoot The JSON node containing the mappings
-   * @param[in,out] keyStack the stack of visited keys
+   * @param[in] theKey The key to search for
+   * @param[in] propertyType The property type if known, or NONE
    * @param[in,out] value The string value to test and write back to.
-   * @return true if the value was converted, false otherwise.
    */
-  bool ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& value );
+  bool GetPropertyMap( const TreeNode&  mappingRoot,
+                       const char*      theKey,
+                       Property::Type   propertyType,
+                       Property::Value& value );
+
+  void SetCustomProperties( const TreeNode&      node,
+                            Handle&              handle,
+                            const Replacement&   constant,
+                            const std::string&   childName,
+                            Property::AccessMode accessMode );
 
   /**
-   * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
-   * are detected.
+   * Find the key in the mapping table, if it's present, then generate
+   * a property value for it (of the given type if available),
+   * recursing as necessary, and stopping if any cycles are detected.
+   *
    * @param[in] mappingRoot The JSON node containing the mappings
    * @param[in] theKey The key to search for
    * @param[in,out] keyStack the stack of visited keys
    * @param[in] propertyType The property type if known, or NONE
    * @param[in,out] value The string value to test and write back to.
    */
-  bool RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value );
+  bool RecursePropertyMap( const TreeNode&  mappingRoot,
+                           KeyStack&        keyStack,
+                           const char*      theKey,
+                           Property::Type   propertyType,
+                           Property::Value& value );
+
 
   /**
-   * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
-   * are detected.
+   * Tests if the value is a string delimited by <>. If it is, then it attempts to
+   * change the value to the mapping from a matching key in the mappings table.
    * @param[in] mappingRoot The JSON node containing the mappings
-   * @param[in] theKey The key to search for
-   * @param[in] propertyType The property type if known, or NONE
+   * @param[in,out] keyStack the stack of visited keys
    * @param[in,out] value The string value to test and write back to.
+   * @return true if the value was converted, false otherwise.
    */
-  bool GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value );
-
-  void ApplyProperties( const TreeNode& root, const TreeNode& node,
-                        Dali::Handle& handle, const Replacement& constant );
-
-  void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
-                           Dali::Handle& handle, const Replacement& constant );
-
-  void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
-                                Dali::Handle& handle, const Replacement& constant );
-
-  void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
+  bool ConvertChildValue( const TreeNode& mappingRoot,
+                          KeyStack& keyStack,
+                          Property::Value& value );
 
+private:
+  Toolkit::JsonParser                 mParser;
+  ImageLut                            mFrameBufferImageLut;
+  PathLut                             mPathLut;
+  PathConstrainerLut                  mPathConstrainerLut;
+  LinearConstrainerLut                mLinearConstrainerLut;
+  SlotDelegate<Builder>               mSlotDelegate;
+  Property::Map                       mReplacementMap;
+  MappingsLut                         mCompleteMappings;
+  Dictionary<StylePtr>                mStyles; // State based styles
   Toolkit::Builder::BuilderSignalType mQuitSignal;
 };
 
diff --git a/dali-toolkit/internal/builder/dictionary.h b/dali-toolkit/internal/builder/dictionary.h
new file mode 100644 (file)
index 0000000..22d2afe
--- /dev/null
@@ -0,0 +1,235 @@
+#ifndef DALI_TOOLKIT_INTERNAL_BUILDER_DICTIONARY_H
+#define DALI_TOOLKIT_INTERNAL_BUILDER_DICTIONARY_H
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/public-api/common/vector-wrapper.h>
+#include <algorithm>
+
+namespace Dali
+{
+extern bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b );
+
+namespace Toolkit
+{
+namespace Internal
+{
+
+/**
+ * The Dictionary template class enables a means of storing key-value
+ * pairs where the keys are strings and the value can be a complex
+ * type.
+ *
+ * It enables lookup of keys via case-insensitive match.
+ */
+template<typename EntryType>
+class Dictionary
+{
+private:
+  /**
+   * Element is a key-value pair
+   */
+  struct Element
+  {
+    std::string key;
+    EntryType entry;
+    Element( const std::string&name, EntryType entry )
+    : key( name ),
+      entry( entry )
+    {
+    }
+  };
+  typedef std::vector<Element> Elements;
+  Elements container;
+
+public:
+  /**
+   * Only allow const iteration over the dictionary
+   */
+  typedef typename Elements::const_iterator iterator;
+
+
+  /**
+   * Constructor
+   */
+  Dictionary<EntryType>()
+  {
+  }
+
+  /**
+   * Add a key value pair to the dictionary.
+   * If the entry does not already exist, add it to the dictionary
+   * using a shallow copy
+   */
+  bool Add( const std::string& name, const EntryType& entry )
+  {
+    for( typename Elements::iterator iter = container.begin(); iter != container.end(); ++iter )
+    {
+      if( iter->key == name )
+      {
+        return false;
+      }
+    }
+    container.push_back( Element(name, entry) );
+    return true;
+  }
+
+  /**
+   * Add a key-value pair to the dictionary
+   * If the entry does not already exist, add it to the dictionary
+   * (shallow copy)
+   */
+  bool Add( const char* name, const EntryType& entry )
+  {
+    bool result=false;
+    if( name != NULL )
+    {
+      std::string theName(name);
+      result=Add(theName, entry);
+    }
+    return result;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key, and
+   * return a pointer to it, or NULL.
+   */
+  EntryType* Find( const std::string& key ) const
+  {
+    EntryType* result=NULL;
+
+    if( ! key.empty() )
+    {
+      for( typename Elements::iterator iter = container.begin(); iter != container.end(); ++iter )
+      {
+        if( iter->key == key )
+        {
+          result = &(iter->entry);
+          break;
+        }
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key, and
+   * return a pointer to it, or NULL
+   */
+  EntryType* Find( const char* key ) const
+  {
+    if( key != NULL )
+    {
+      std::string theKey(key);
+      return Find(theKey);
+    }
+    return NULL;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key using a case
+   * insensitive search, and return a const pointer to it, or NULL
+   */
+  const EntryType* FindCaseInsensitiveC( const std::string& key ) const
+  {
+    if( ! key.empty() )
+    {
+      for( typename Elements::const_iterator iter = container.begin(); iter != container.end(); ++iter )
+      {
+        if( Dali::CaseInsensitiveStringCompare(iter->key, key ))
+        {
+          const EntryType* result = &(iter->entry);
+          return result;
+        }
+      }
+    }
+    return NULL;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key using a case
+   * insensitive search, and return a non-const pointer to it, or NULL
+   */
+  EntryType* FindCaseInsensitive( const std::string& key ) const
+  {
+    EntryType* result = NULL;
+    if( ! key.empty() )
+    {
+      for( typename Elements::const_iterator iter = container.begin(); iter != container.end(); ++iter )
+      {
+        if( Dali::CaseInsensitiveStringCompare(iter->key, key ))
+        {
+          // Const cast because of const_iterator. const_iterator because, STL.
+          result = const_cast<EntryType*>(&(iter->entry));
+        }
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key using a case
+   * insensitive search, and return a const pointer to it, or NULL
+   */
+  const EntryType* FindCaseInsensitiveC( const char* key ) const
+  {
+    if( key != NULL )
+    {
+      std::string theKey(key);
+      return FindCaseInsensitiveC( theKey );
+    }
+    return NULL;
+  }
+
+  /**
+   * Find the element in the dictionary pointed at by key using a case
+   * insensitive search, and return a non-const pointer to it, or NULL
+   */
+  EntryType* FindCaseInsensitive( const char* key ) const
+  {
+    if( key != NULL )
+    {
+      std::string theKey(key);
+      return FindCaseInsensitive( theKey );
+    }
+    return NULL;
+  }
+
+  /**
+   * Return an iterator pointing at the first entry in the dictionary
+   */
+  typename Elements::const_iterator Begin() const
+  {
+    return container.begin();
+  }
+
+  /**
+   * Return an iterator pointing past the last entry in the dictionary
+   */
+  typename Elements::const_iterator End() const
+  {
+    return container.end();
+  }
+};
+
+
+
+}//Internal
+}//Toolkit
+}//Dali
+
+#endif // DALI_TOOLKIT_INTERNAL_BUILDER_DICTIONARY_H
diff --git a/dali-toolkit/internal/builder/style.cpp b/dali-toolkit/internal/builder/style.cpp
new file mode 100644 (file)
index 0000000..eaf59dc
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/public-api/object/handle.h>
+#include <dali-toolkit/public-api/controls/control.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/internal/builder/style.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+StylePtr Style::New()
+{
+  StylePtr stylePtr( new Style() );
+  return stylePtr;
+}
+
+void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const
+{
+  ApplyVisuals( handle );
+  ApplyProperties( handle );
+
+  Toolkit::Control control = Toolkit::Control::DownCast(handle);
+  if( control )
+  {
+    Property::Value value = control.GetProperty(DevelControl::Property::STATE);
+    std::string stateName;
+    if( value.Get( stateName ) )
+    {
+      // Look up state in states table:
+      const StylePtr* stylePtr = subStates.FindCaseInsensitiveC( stateName );
+      if( stylePtr )
+      {
+        const StylePtr statePtr(*stylePtr);
+
+        // We have a state match.
+        statePtr->ApplyVisuals( handle );
+        statePtr->ApplyProperties( handle );
+
+        // Apply substate visuals
+        Property::Value value = control.GetProperty(DevelControl::Property::SUB_STATE);
+        std::string subStateName;
+        if( value.Get( subStateName ) && ! subStateName.empty() )
+        {
+          const StylePtr* stylePtr = statePtr->subStates.FindCaseInsensitiveC( subStateName );
+          if( stylePtr )
+          {
+            const StylePtr subStatePtr(*stylePtr);
+            // We have a sub-state match.
+            subStatePtr->ApplyVisuals( handle );
+            subStatePtr->ApplyProperties( handle );
+          }
+        }
+      }
+    }
+  }
+}
+
+void Style::ApplyVisuals( Handle handle ) const
+{
+  for( Dictionary<Property::Map>::iterator iter = visuals.Begin(); iter != visuals.End() ; ++iter )
+  {
+    const std::string& visualName = (*iter).key;
+    const Property::Map& map = (*iter).entry;
+    Dali::Property::Index index = handle.GetPropertyIndex( visualName );
+    if( index != Property::INVALID_INDEX )
+    {
+      const Property::Value value(const_cast<Property::Map&>(map));
+      handle.SetProperty( index, value );
+    }
+  }
+}
+
+void Style::ApplyProperties( Handle handle ) const
+{
+  for( Property::Map::SizeType i=0; i<properties.Count(); ++i )
+  {
+    KeyValuePair keyValue = properties.GetKeyValue( i );
+    if( keyValue.first.type == Property::Key::INDEX )
+    {
+      handle.SetProperty( keyValue.first.indexKey, keyValue.second );
+    }
+  }
+}
+
+Style::Style()
+{
+}
+
+Style::~Style()
+{
+}
+
+
+} // Internal
+} // Toolkit
+} // Dali
diff --git a/dali-toolkit/internal/builder/style.h b/dali-toolkit/internal/builder/style.h
new file mode 100644 (file)
index 0000000..2fb4e83
--- /dev/null
@@ -0,0 +1,112 @@
+#ifndef DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H
+#define DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/public-api/object/ref-object.h>
+#include <dali-toolkit/devel-api/visual-factory/transition-data.h>
+#include <dali-toolkit/internal/builder/dictionary.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+class Style;
+typedef IntrusivePtr<Style> StylePtr;
+
+/**
+ * This class encapsulates the style information for a given styled
+ * control.  It is generated only when a control instance looks up
+ * it's style information for the first time, and then stored by
+ * Builder.
+ *
+ * It contains the visual, property and transition definitions for the
+ * main control and for each state and sub-state within the control.
+ *
+ * It has methods to enable the base control to apply visuals and
+ * properties per state.
+ */
+class Style : public RefObject
+{
+public:
+  static StylePtr New();
+
+public:
+  /**
+   * Apply the visuals and properties for the current state/substate
+   * of the handle to the control pointed at by handle. Recurses
+   * through sub-states.
+   *
+   * @param[in] handle The handle to apply the visuals to
+   */
+  void ApplyVisualsAndPropertiesRecursively( Handle handle ) const;
+
+
+private:
+  /**
+   * Apply the visuals of the style to the control pointed at by
+   * handle.
+   *
+   * @param[in] handle The handle to apply the visuals to
+   */
+  void ApplyVisuals( Handle handle ) const;
+
+  /**
+   * Apply the properties of the style to the control pointed at by
+   * handle.
+   *
+   * @param[in] handle The handle to apply the properties to
+   */
+  void ApplyProperties( Handle handle ) const;
+
+protected:
+  /**
+   * @brief Default constructor.
+   */
+  Style();
+
+  /**
+   * @brief virtual destructor.
+   */
+  virtual ~Style();
+
+private:
+  // Not implemented
+  DALI_INTERNAL Style( const Style& rhs );
+
+  // Not implemented
+  DALI_INTERNAL Style& operator=(const Style& rhs);
+
+public:
+  // Everything must be shallow-copiable.
+  Dictionary<StylePtr> subStates; // Each named style maps to a state.
+  Dictionary<Property::Map> visuals;
+  Property::Map properties;
+  Property::Array transitions;
+  Toolkit::TransitionData entryTransition;
+  Toolkit::TransitionData exitTransition;
+};
+
+} // Internal
+} // Toolkit
+} // Dali
+
+
+#endif //DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H
index 2fcc669..6ec0d0c 100755 (executable)
@@ -8,6 +8,7 @@ toolkit_src_files = \
    $(toolkit_src_dir)/builder/builder-signals.cpp \
    $(toolkit_src_dir)/builder/json-parser-state.cpp \
    $(toolkit_src_dir)/builder/json-parser-impl.cpp \
+   $(toolkit_src_dir)/builder/style.cpp \
    $(toolkit_src_dir)/builder/tree-node-manipulator.cpp \
    $(toolkit_src_dir)/builder/replacement.cpp \
    $(toolkit_src_dir)/visuals/visual-base-impl.cpp \
index d1fa388..b38d23b 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali/public-api/adaptor-framework/application.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/internal/builder/builder-impl.h>
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/styling/style-manager.h>
@@ -291,7 +292,7 @@ bool StyleManager::LoadJSON( Toolkit::Builder builder, const std::string& jsonFi
   }
 }
 
-void StyleManager::CollectQualifiers( StringList& qualifiersOut )
+static void CollectQualifiers( std::vector<std::string>& qualifiersOut )
 {
   // Append the relevant qualifier for orientation
   int orientation = 0; // Get the orientation from the system
@@ -313,11 +314,24 @@ void StyleManager::CollectQualifiers( StringList& qualifiersOut )
   }
 }
 
-void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut )
+/**
+ * @brief Construct a qualified style name out of qualifiers
+ *
+ * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
+ *
+ * @param[in] styleName The root name of the style
+ * @param[in] qualifiers List of qualifier names
+ * @param[out] qualifiedStyleOut The qualified style name
+ */
+static void BuildQualifiedStyleName(
+  const std::string& styleName,
+  const std::vector<std::string>& qualifiers,
+  std::string& qualifiedStyleOut )
 {
   qualifiedStyleOut.append( styleName );
 
-  for( StringList::const_iterator it = qualifiers.begin(), itEnd = qualifiers.end(); it != itEnd; ++it )
+  for( std::vector<std::string>::const_iterator it = qualifiers.begin(),
+         itEnd = qualifiers.end(); it != itEnd; ++it )
   {
     const std::string& str = *it;
 
@@ -326,9 +340,9 @@ void StyleManager::BuildQualifiedStyleName( const std::string& styleName, const
   }
 }
 
-void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control )
+static bool GetStyleNameForControl( Toolkit::Builder builder, Toolkit::Control control, std::string& styleName)
 {
-  std::string styleName = control.GetStyleName();
+  styleName = control.GetStyleName();
 
   if( styleName.empty() )
   {
@@ -336,22 +350,43 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro
   }
 
   // Apply the style after choosing the correct actual style (e.g. landscape or portrait)
-  StringList qualifiers;
+  std::vector<std::string> qualifiers;
   CollectQualifiers( qualifiers );
 
-  while( true )
+  bool found = 0;
+  std::string qualifiedStyleName;
+  do
   {
-    std::string qualifiedStyleName;
+    qualifiedStyleName.clear();
     BuildQualifiedStyleName( styleName, qualifiers, qualifiedStyleName );
 
     // Break if style found or we have tried the root style name (qualifiers is empty)
-    if( builder.ApplyStyle( qualifiedStyleName, control ) || qualifiers.size() == 0 )
+    if( GetImpl(builder).LookupStyleName( qualifiedStyleName ) )
+    {
+      found = true;
+      break;
+    }
+    if( qualifiers.size() == 0 )
     {
       break;
     }
-
     // Remove the last qualifier in an attempt to find a style that is valid
     qualifiers.pop_back();
+  } while (!found);
+
+  if(found)
+  {
+    styleName = qualifiedStyleName;
+  }
+  return found;
+}
+
+void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control control )
+{
+  std::string styleName = control.GetStyleName();
+  if( GetStyleNameForControl( builder, control, styleName ) )
+  {
+    builder.ApplyStyle( styleName, control );
   }
 
   if( mDefaultFontSize >= 0 )
@@ -363,6 +398,21 @@ void StyleManager::ApplyStyle( Toolkit::Builder builder, Toolkit::Control contro
   }
 }
 
+const StylePtr StyleManager::GetRecordedStyle( Toolkit::Control control )
+{
+  if( mThemeBuilder )
+  {
+    std::string styleName = control.GetStyleName();
+
+    if( GetStyleNameForControl( mThemeBuilder, control, styleName ) )
+    {
+      const StylePtr style = GetImpl(mThemeBuilder).GetStyle( styleName );
+      return style;
+    }
+  }
+  return StylePtr(NULL);
+}
+
 Toolkit::Builder StyleManager::FindCachedBuilder( const std::string& key )
 {
   BuilderMap::iterator builderIt = mBuilderCache.find( key );
index f0c217c..aa514ea 100644 (file)
@@ -29,6 +29,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/styling/style-manager.h>
 #include <dali-toolkit/devel-api/builder/builder.h>
+#include <dali-toolkit/internal/builder/style.h>
 
 namespace Dali
 {
@@ -67,7 +68,7 @@ protected:
 
 public: // Public API
 
-/**
+  /**
    * @copydoc Toolkit::StyleManager::ApplyTheme
    */
   void ApplyTheme( const std::string& themeFile );
@@ -111,6 +112,13 @@ public: // Public API
    */
   void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
 
+  /**
+   * Get the state/style information for the given control
+   * @param[in] control The control to get state information for
+   * @return The style information (or empty ptr if not found)
+   */
+  const StylePtr GetRecordedStyle( Toolkit::Control control );
+
 public:
   // SIGNALS
 
@@ -164,24 +172,6 @@ private:
   bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
 
   /**
-   * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
-   *
-   * @param[in,out] qualifiersOut The list to populate with qualifiers
-   */
-  void CollectQualifiers( StringList& qualifiersOut );
-
-  /**
-   * @brief Construct a qualified style name out of qualifiers
-   *
-   * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
-   *
-   * @param[in] styleName The root name of the style
-   * @param[in] qualifiers List of qualifier names
-   * @param[out] qualifiedStyleOut The qualified style name
-   */
-  void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
-
-  /**
    * @brief Apply a style to the control using the given builder
    *
    * @param[in] builder The builder to apply the style from
index c94ebb1..5d3248e 100644 (file)
@@ -217,6 +217,12 @@ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra
   return connected;
 }
 
+const Scripting::StringEnum ControlStateTable[] = {
+  { "NORMAL",   Toolkit::DevelControl::NORMAL   },
+  { "FOCUSED",  Toolkit::DevelControl::FOCUSED  },
+  { "DISABLED", Toolkit::DevelControl::DISABLED },
+}; const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] );
+
 // Setup signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
 
@@ -246,6 +252,8 @@ public:
   // Construction & Destruction
   Impl(Control& controlImpl)
   : mControlImpl( controlImpl ),
+    mState( Toolkit::DevelControl::NORMAL ),
+    mSubState(""),
     mStyleName(""),
     mBackgroundColor(Color::TRANSPARENT),
     mStartingPinchScale( NULL ),
@@ -312,6 +320,27 @@ public:
           break;
         }
 
+        case Toolkit::DevelControl::Property::STATE:
+        {
+          Toolkit::DevelControl::State state( DevelControl::NORMAL );
+
+          if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( value, ControlStateTable, ControlStateTableCount, state ) )
+          {
+            controlImpl.mImpl->SetState( state );
+          }
+        }
+        break;
+
+        case Toolkit::DevelControl::Property::SUB_STATE:
+        {
+          std::string subState;
+          if( value.Get( subState ) )
+          {
+            controlImpl.mImpl->SetSubState( subState );
+          }
+        }
+        break;
+
         case Toolkit::Control::Property::BACKGROUND_COLOR:
         {
           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
@@ -411,6 +440,12 @@ public:
           break;
         }
 
+        case Toolkit::DevelControl::Property::STATE:
+        {
+          value = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( controlImpl.mImpl->mState, ControlStateTable, ControlStateTableCount );
+          break;
+        }
+
         case Toolkit::Control::Property::BACKGROUND_COLOR:
         {
           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
@@ -467,9 +502,48 @@ public:
     return value;
   }
 
+  void SetState( DevelControl::State state )
+  {
+    if( mState != state )
+    {
+      mState = state;
+
+      // Trigger state change and transitions
+      // Apply new style, if stylemanager is available
+      Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+      if( styleManager )
+      {
+        const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) );
+        if( stylePtr )
+        {
+          for( int i=mVisuals.Count()-1; i >= 0; i-- )
+          {
+            mControlImpl.UnregisterVisual( mVisuals[i]->index );
+          }
+
+          Dali::CustomActor handle( mControlImpl.GetOwner() );
+          stylePtr->ApplyVisualsAndPropertiesRecursively( handle );
+        }
+      }
+    }
+  }
+
+  void SetSubState( const std::string& state )
+  {
+    if( mSubState != state )
+    {
+      mSubState = state;
+      // Trigger transitions
+
+    }
+  }
+
   // Data
 
   Control& mControlImpl;
+  DevelControl::State mState;
+  std::string mSubState;
+
   RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
   std::string mStyleName;
   Vector4 mBackgroundColor;                       ///< The color of the background visual
@@ -498,6 +572,8 @@ public:
   static const PropertyRegistration PROPERTY_4;
   static const PropertyRegistration PROPERTY_5;
   static const PropertyRegistration PROPERTY_6;
+  static const PropertyRegistration PROPERTY_7;
+  static const PropertyRegistration PROPERTY_8;
 };
 
 // Properties registered without macro to use specific member variables.
@@ -507,6 +583,8 @@ const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgro
 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",   Toolkit::Control::Property::KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",      Toolkit::Control::Property::BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip",         Toolkit::DevelControl::Property::TOOLTIP,     Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state",           Toolkit::DevelControl::Property::STATE,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState",        Toolkit::DevelControl::Property::SUB_STATE,   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 
 Toolkit::Control Control::New()
 {