From 86202cf2dbd203142c38e55ed38429d9aa005f75 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 9 May 2014 19:07:47 +0100 Subject: [PATCH] (Control) Added more event-side properties Change-Id: Id513bccdba5f0c050cec7d2b73fdf104acb5cf05 Signed-off-by: Adeel Kazmi --- .../src/dali-toolkit/tct-dali-toolkit-core.h | 6 ++ .../src/dali-toolkit/utc-Dali-Control.cpp | 71 +++++++++++++ .../internal/controls/relayout-controller-impl.cpp | 5 +- .../public-api/controls/control-impl.cpp | 93 ++++++++++++++++- capi/dali-toolkit/public-api/controls/control.h | 5 + .../internal/builder/builder-control.cpp | 112 --------------------- .../dali-toolkit/internal/builder/builder-impl.cpp | 8 -- optional/dali-toolkit/internal/file.list | 1 - 8 files changed, 178 insertions(+), 123 deletions(-) delete mode 100644 optional/dali-toolkit/internal/builder/builder-control.cpp diff --git a/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.h b/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.h index b5383d3..6d81eb2 100644 --- a/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.h +++ b/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.h @@ -102,6 +102,9 @@ extern int UtcDaliControlTestParameters(void); extern int UtcDaliControlBackgroundColor(void); extern int UtcDaliControlBackgroundImage(void); extern int UtcDaliControlBackgroundProperties(void); +extern int UtcDaliControlSizePolicyProperties(void); +extern int UtcDaliControlSizeProperties(void); +extern int UtcDaliControlKeyProperties(void); extern int UtcDaliControlImplNew(void); extern int UtcDaliControlImplEnableGestureDetector(void); extern int UtcDaliControlImplDisableGestureDetector(void); @@ -337,6 +340,9 @@ testcase tc_array[] = { {"UtcDaliControlBackgroundColor", UtcDaliControlBackgroundColor, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, {"UtcDaliControlBackgroundImage", UtcDaliControlBackgroundImage, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, {"UtcDaliControlBackgroundProperties", UtcDaliControlBackgroundProperties, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, + {"UtcDaliControlSizePolicyProperties", UtcDaliControlSizePolicyProperties, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, + {"UtcDaliControlSizeProperties", UtcDaliControlSizeProperties, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, + {"UtcDaliControlKeyProperties", UtcDaliControlKeyProperties, utc_dali_toolkit_control_startup, utc_dali_toolkit_control_cleanup}, {"UtcDaliControlImplNew", UtcDaliControlImplNew, utc_dali_toolkit_control_impl_startup, utc_dali_toolkit_control_impl_cleanup}, {"UtcDaliControlImplEnableGestureDetector", UtcDaliControlImplEnableGestureDetector, utc_dali_toolkit_control_impl_startup, utc_dali_toolkit_control_impl_cleanup}, {"UtcDaliControlImplDisableGestureDetector", UtcDaliControlImplDisableGestureDetector, utc_dali_toolkit_control_impl_startup, utc_dali_toolkit_control_impl_cleanup}, diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 1de1d57..095879b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -434,3 +434,74 @@ int UtcDaliControlBackgroundProperties(void) END_TEST; } + +int UtcDaliControlSizePolicyProperties(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + + Control::SizePolicy widthPolicy( Control::Fixed ); + Control::SizePolicy heightPolicy( Control::Fixed ); + + control.GetSizePolicy( widthPolicy, heightPolicy ); + DALI_TEST_EQUALS( "FIXED", control.GetProperty( Control::PROPERTY_WIDTH_POLICY ).Get< std::string >(), TEST_LOCATION ); + DALI_TEST_EQUALS( "FIXED", control.GetProperty( Control::PROPERTY_HEIGHT_POLICY ).Get< std::string >(), TEST_LOCATION ); + + control.SetSizePolicy( Control::Flexible, Control::Range ); + DALI_TEST_EQUALS( "FLEXIBLE", control.GetProperty( Control::PROPERTY_WIDTH_POLICY ).Get< std::string >(), TEST_LOCATION ); + DALI_TEST_EQUALS( "RANGE", control.GetProperty( Control::PROPERTY_HEIGHT_POLICY ).Get< std::string >(), TEST_LOCATION ); + + control.SetProperty( Control::PROPERTY_WIDTH_POLICY, "MAXIMUM" ); + control.SetProperty( Control::PROPERTY_HEIGHT_POLICY, "MINIMUM" ); + control.GetSizePolicy( widthPolicy, heightPolicy ); + DALI_TEST_EQUALS( Control::Maximum, widthPolicy, TEST_LOCATION ); + DALI_TEST_EQUALS( Control::Minimum, heightPolicy, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlSizeProperties(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + + DALI_TEST_EQUALS( control.GetMinimumSize(), control.GetProperty( Control::PROPERTY_MINIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION ); + DALI_TEST_EQUALS( control.GetMaximumSize(), control.GetProperty( Control::PROPERTY_MAXIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION ); + + control.SetMinimumSize( Vector3( 100.0f, 200.0f, 300.0f ) ); + DALI_TEST_EQUALS( Vector3( 100.0f, 200.0f, 300.0f ), control.GetProperty( Control::PROPERTY_MINIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION ); + + + control.SetMaximumSize( Vector3( 200.0f, 250.0f, 800.0f ) ); + DALI_TEST_EQUALS( Vector3( 200.0f, 250.0f, 800.0f ), control.GetProperty( Control::PROPERTY_MAXIMUM_SIZE ).Get< Vector3 >(), TEST_LOCATION ); + + control.SetProperty( Control::PROPERTY_MINIMUM_SIZE, Vector3( 1.0f, 2.0f, 3.0f ) ); + control.SetProperty( Control::PROPERTY_MAXIMUM_SIZE, Vector3( 10.0f, 20.0f, 30.0f ) ); + DALI_TEST_EQUALS( control.GetMinimumSize(), Vector3( 1.0f, 2.0f, 3.0f ), TEST_LOCATION ); + DALI_TEST_EQUALS( control.GetMaximumSize(), Vector3( 10.0f, 20.0f, 30.0f ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlKeyProperties(void) +{ + ToolkitTestApplication application; + + Control control = Control::New(); + Stage::GetCurrent().Add( control ); + + DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.SetKeyInputFocus(); + DALI_TEST_EQUALS( true, control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.ClearKeyInputFocus(); + DALI_TEST_EQUALS( false, control.GetProperty( Control::PROPERTY_KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION ); + + control.SetProperty( Control::PROPERTY_KEY_INPUT_FOCUS, true ); + DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION ); + + END_TEST; +} diff --git a/base/dali-toolkit/internal/controls/relayout-controller-impl.cpp b/base/dali-toolkit/internal/controls/relayout-controller-impl.cpp index bdefe39..84b79d1 100644 --- a/base/dali-toolkit/internal/controls/relayout-controller-impl.cpp +++ b/base/dali-toolkit/internal/controls/relayout-controller-impl.cpp @@ -85,7 +85,10 @@ void PrintChildren( Actor actor, int level ) */ void PrintHierarchy() { - PrintChildren( Stage().GetCurrent().GetRootLayer(), 0 ); + if ( gLogFilter->IsEnabledFor( Debug::Verbose ) ) + { + PrintChildren( Stage().GetCurrent().GetRootLayer(), 0 ); + } } #define PRINT_HIERARCHY PrintHierarchy() diff --git a/base/dali-toolkit/public-api/controls/control-impl.cpp b/base/dali-toolkit/public-api/controls/control-impl.cpp index b2fb483..fe4429a 100644 --- a/base/dali-toolkit/public-api/controls/control-impl.cpp +++ b/base/dali-toolkit/public-api/controls/control-impl.cpp @@ -36,10 +36,25 @@ namespace Toolkit const Property::Index Control::PROPERTY_BACKGROUND_COLOR = ControlImpl::CONTROL_PROPERTY_START_INDEX; const Property::Index Control::PROPERTY_BACKGROUND = ControlImpl::CONTROL_PROPERTY_START_INDEX + 1; +const Property::Index Control::PROPERTY_WIDTH_POLICY = ControlImpl::CONTROL_PROPERTY_START_INDEX + 2; +const Property::Index Control::PROPERTY_HEIGHT_POLICY = ControlImpl::CONTROL_PROPERTY_START_INDEX + 3; +const Property::Index Control::PROPERTY_MINIMUM_SIZE = ControlImpl::CONTROL_PROPERTY_START_INDEX + 4; +const Property::Index Control::PROPERTY_MAXIMUM_SIZE = ControlImpl::CONTROL_PROPERTY_START_INDEX + 5; +const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS = ControlImpl::CONTROL_PROPERTY_START_INDEX + 6; namespace { +const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] = +{ + { "FIXED", Control::Fixed }, + { "MINIMUM", Control::Minimum }, + { "MAXIMUM", Control::Maximum }, + { "RANGE", Control::Range }, + { "FLEXIBLE", Control::Flexible }, +}; +const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] ); + #if defined(DEBUG_ENABLED) Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL"); #endif @@ -352,6 +367,43 @@ public: } break; } + + case Control::PROPERTY_WIDTH_POLICY: + { + controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ); + break; + } + + case Control::PROPERTY_HEIGHT_POLICY: + { + controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Control::SizePolicy >( value.Get< std::string >(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ); + break; + } + + case Control::PROPERTY_MINIMUM_SIZE: + { + controlImpl.SetMinimumSize( value.Get< Vector3 >() ); + break; + } + + case Control::PROPERTY_MAXIMUM_SIZE: + { + controlImpl.SetMaximumSize( value.Get< Vector3 >() ); + break; + } + + case Control::PROPERTY_KEY_INPUT_FOCUS: + { + if ( value.Get< bool >() ) + { + controlImpl.SetKeyInputFocus(); + } + else + { + controlImpl.ClearKeyInputFocus(); + } + break; + } } } } @@ -401,6 +453,35 @@ public: break; } + case Control::PROPERTY_WIDTH_POLICY: + { + value = std::string( Scripting::GetEnumerationName< Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) ); + break; + } + + case Control::PROPERTY_HEIGHT_POLICY: + { + value = std::string( Scripting::GetEnumerationName< Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) ); + break; + } + + case Control::PROPERTY_MINIMUM_SIZE: + { + value = controlImpl.mImpl->mMinimumSize; + break; + } + + case Control::PROPERTY_MAXIMUM_SIZE: + { + value = controlImpl.mImpl->mMaximumSize; + break; + } + + case Control::PROPERTY_KEY_INPUT_FOCUS: + { + value = controlImpl.HasKeyInputFocus(); + break; + } } } @@ -444,13 +525,23 @@ public: // Background Background* mBackground; ///< Only create the background if we use it - // Properties - need to be part of this class as ControlImpl::Impl is private + // Properties - these need to be members of ControlImpl::Impl as they need to functions within this class. static PropertyRegistration PROPERTY_1; static PropertyRegistration PROPERTY_2; + static PropertyRegistration PROPERTY_3; + static PropertyRegistration PROPERTY_4; + static PropertyRegistration PROPERTY_5; + static PropertyRegistration PROPERTY_6; + static PropertyRegistration PROPERTY_7; }; PropertyRegistration ControlImpl::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); PropertyRegistration ControlImpl::Impl::PROPERTY_2( CONTROL_TYPE, "background", Control::PROPERTY_BACKGROUND, Property::MAP, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); +PropertyRegistration ControlImpl::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy", Control::PROPERTY_WIDTH_POLICY, Property::STRING, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); +PropertyRegistration ControlImpl::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy", Control::PROPERTY_HEIGHT_POLICY, Property::STRING, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); +PropertyRegistration ControlImpl::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size", Control::PROPERTY_MINIMUM_SIZE, Property::VECTOR3, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); +PropertyRegistration ControlImpl::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size", Control::PROPERTY_MAXIMUM_SIZE, Property::VECTOR3, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); +PropertyRegistration ControlImpl::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus", Control::PROPERTY_KEY_INPUT_FOCUS, Property::BOOLEAN, &ControlImpl::Impl::SetProperty, &ControlImpl::Impl::GetProperty ); Control ControlImpl::New() { diff --git a/capi/dali-toolkit/public-api/controls/control.h b/capi/dali-toolkit/public-api/controls/control.h index 84096dc..26baa51 100644 --- a/capi/dali-toolkit/public-api/controls/control.h +++ b/capi/dali-toolkit/public-api/controls/control.h @@ -49,6 +49,11 @@ public: /** @{ */ static const Property::Index PROPERTY_BACKGROUND_COLOR; ///< name "background-color", @see SetBackgroundColor, type VECTOR4 static const Property::Index PROPERTY_BACKGROUND; ///< name "background", @see SetBackground, type MAP + static const Property::Index PROPERTY_WIDTH_POLICY; ///< name "width-policy", @see SetSizePolicy, type STRING + static const Property::Index PROPERTY_HEIGHT_POLICY; ///< name "height-policy", @see SetSizePolicy, type STRING + static const Property::Index PROPERTY_MINIMUM_SIZE; ///< name "minimum-size", @see SetMinimumSize, type VECTOR3 + static const Property::Index PROPERTY_MAXIMUM_SIZE; ///< name "maximum-size", @see SetMaximumSize, type VECTOR3 + static const Property::Index PROPERTY_KEY_INPUT_FOCUS; ///< name "key-input-focus", @see SetKeyInputFocus, type BOOLEAN /** @} */ /// @name Signals diff --git a/optional/dali-toolkit/internal/builder/builder-control.cpp b/optional/dali-toolkit/internal/builder/builder-control.cpp deleted file mode 100644 index 005fde9..0000000 --- a/optional/dali-toolkit/internal/builder/builder-control.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// - -// EXTERNAL INCLUDES -#include - -// INTERNAL INCLUDES -#include -#include -#include -#include - -namespace // unnamed namespace -{ - -using namespace Dali; -using namespace Dali::Toolkit; -using namespace Dali::Scripting; // SetIfEqual - -Control::SizePolicy GetSizePolicy( const std::string& value ) -{ - Control::SizePolicy v(Control::Flexible); - - bool set = \ - SetIfEqual(value, "FIXED", v, Control::Fixed ) || \ - SetIfEqual(value, "MINIMUM", v, Control::Minimum ) || \ - SetIfEqual(value, "MAXIMUM", v, Control::Maximum ) || \ - SetIfEqual(value, "RANGE", v, Control::Range ) || \ - SetIfEqual(value, "FLEXIBLE", v, Control::Flexible ); - - if( !set ) - { - DALI_ASSERT_ALWAYS( !"Unknown Color mode" ); - } - - return v; -} - -} // anon namespace - - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -/* - * Handles special case control configuration (anything thats not already a property) - * - */ -Dali::Toolkit::Control SetupControl( const TreeNode& child, Dali::Toolkit::Control& control ) -{ - DALI_ASSERT_ALWAYS( control && "Empty actor handle" ); - - Control::SizePolicy widthPolicy(Control::Flexible); - Control::SizePolicy heightPolicy(Control::Flexible); - - if( OptionalString v = IsString(child, "width-policy") ) - { - widthPolicy = GetSizePolicy(*v); - control.SetSizePolicy( widthPolicy, heightPolicy ); - } - - if( OptionalString v = IsString(child, "height-policy") ) - { - heightPolicy = GetSizePolicy(*v); - control.SetSizePolicy( widthPolicy, heightPolicy ); - } - - if( OptionalVector3 v = IsVector3(child, "minimum-size") ) - { - control.SetMinimumSize( *v ); - } - - if( OptionalVector3 v = IsVector3(child, "maximum-size") ) - { - control.SetMaximumSize( *v ); - } - - if( OptionalBoolean v = IsBoolean(child, "key-input-focus") ) - { - if( *v ) - { - control.SetKeyInputFocus(); - } - } - - return control; -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali diff --git a/optional/dali-toolkit/internal/builder/builder-impl.cpp b/optional/dali-toolkit/internal/builder/builder-impl.cpp index d16c64f..abf8b57 100644 --- a/optional/dali-toolkit/internal/builder/builder-impl.cpp +++ b/optional/dali-toolkit/internal/builder/builder-impl.cpp @@ -50,7 +50,6 @@ extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Prop extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor); extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor); extern Actor SetupActor( const TreeNode& node, Actor& actor ); -extern Control SetupControl( const TreeNode& node, Control& actor ); #if defined(DEBUG_ENABLED) Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT"); @@ -330,13 +329,6 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node, { SetupActor( node, actor ); - Control control = Control::DownCast(actor); - - if( control ) - { - SetupControl( node, control ); - } - // add signals SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor ); diff --git a/optional/dali-toolkit/internal/file.list b/optional/dali-toolkit/internal/file.list index 7e03624..5e214a4 100644 --- a/optional/dali-toolkit/internal/file.list +++ b/optional/dali-toolkit/internal/file.list @@ -6,7 +6,6 @@ toolkit_optional_src_files = \ $(toolkit_optional_src_dir)/builder/builder-set-property.cpp \ $(toolkit_optional_src_dir)/builder/builder-signals.cpp \ $(toolkit_optional_src_dir)/builder/builder-actor.cpp \ - $(toolkit_optional_src_dir)/builder/builder-control.cpp \ $(toolkit_optional_src_dir)/builder/json-parser-state.cpp \ $(toolkit_optional_src_dir)/builder/json-parser-impl.cpp \ $(toolkit_optional_src_dir)/builder/tree-node-manipulator.cpp \ -- 2.7.4