X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftool-bar%2Ftool-bar-impl.cpp;h=a0cd9e43493a9995254ed47367ea69ca108f4c96;hp=0bcfe26cf27ee841814ab895f51681089ce1eddf;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=de3afc02ae1077be95857285b2228bfadf3cabd7 diff --git a/dali-toolkit/internal/controls/tool-bar/tool-bar-impl.cpp b/dali-toolkit/internal/controls/tool-bar/tool-bar-impl.cpp index 0bcfe26..a0cd9e4 100644 --- a/dali-toolkit/internal/controls/tool-bar/tool-bar-impl.cpp +++ b/dali-toolkit/internal/controls/tool-bar/tool-bar-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -19,46 +19,41 @@ #include "tool-bar-impl.h" // EXTERNAL INCLUDES -#include #include -#include #include +#include // INTERNAL INCLUDES -#include -#include +#include +#include namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - BaseHandle Create() { return Toolkit::ToolBar::New(); } -DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ToolBar, Toolkit::Control, Create ) +DALI_TYPE_REGISTRATION_BEGIN(Toolkit::ToolBar, Toolkit::Control, Create) DALI_TYPE_REGISTRATION_END() -const float DEFAULT_RELATIVE_SIZE( 0.1f ); -const Toolkit::Alignment::Type DEFAULT_ALIGNMENT( Toolkit::Alignment::HorizontalLeft ); +const float DEFAULT_RELATIVE_SIZE(0.1f); +const Toolkit::Alignment::Type DEFAULT_ALIGNMENT(Toolkit::Alignment::HORIZONTAL_LEFT); } // namespace Toolkit::ToolBar ToolBar::New() { // Create the implementation, temporarily owned on stack - IntrusivePtr< ToolBar > internalToolBar = new ToolBar(); + IntrusivePtr internalToolBar = new ToolBar(); - // Pass ownership to Toolkit::View - Toolkit::ToolBar toolBar( *internalToolBar ); + // Pass ownership to Toolkit::Toolbar + Toolkit::ToolBar toolBar(*internalToolBar); // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... @@ -67,32 +62,13 @@ Toolkit::ToolBar ToolBar::New() return toolBar; } -void ToolBar::SetBackground( Actor background ) -{ - Lock lock( mInitializing ); - - // ToolBar image - background.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); - background.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); - background.SetSize( Vector2( mToolBarSize.width, mToolBarSize.height ) ); - - RenderableActor renderableActor = RenderableActor::DownCast( background ); - if ( renderableActor ) - { - renderableActor.SetSortModifier( 1.f ); - } - - Self().Add( background ); - mBackground = background; -} - -void ToolBar::AddControl( Actor control, float relativeSize, Toolkit::Alignment::Type alignment, const Toolkit::Alignment::Padding& padding ) +void ToolBar::AddControl(Actor control, float relativeSize, Toolkit::Alignment::Type alignment, const Toolkit::Alignment::Padding& padding) { // Work out index and update bases and offsets for further insertions. unsigned int index = 0; - switch( alignment ) + switch(alignment) { - case Toolkit::Alignment::HorizontalLeft: + case Toolkit::Alignment::HORIZONTAL_LEFT: { index = mLeftOffset; ++mLeftOffset; @@ -100,14 +76,14 @@ void ToolBar::AddControl( Actor control, float relativeSize, Toolkit::Alignment: ++mRightBase; break; } - case Toolkit::Alignment::HorizontalCenter: + case Toolkit::Alignment::HORIZONTAL_CENTER: { index = mCenterBase + mCenterOffset; ++mCenterOffset; ++mRightBase; break; } - case Toolkit::Alignment::HorizontalRight: + case Toolkit::Alignment::HORIZONTAL_RIGHT: { index = mRightBase - mRightOffset; ++mRightBase; @@ -116,23 +92,23 @@ void ToolBar::AddControl( Actor control, float relativeSize, Toolkit::Alignment: } default: { - DALI_ASSERT_ALWAYS( false ); + DALI_ASSERT_ALWAYS(false); } } // Create a new column for the new control. - mLayout.InsertColumn( index ); + mLayout.InsertColumn(index); // Create an alignment container where to place the control. - Toolkit::Alignment alignmentContainer = Toolkit::Alignment::New( alignment ); - alignmentContainer.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - alignmentContainer.SetPadding( padding ); - alignmentContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - alignmentContainer.Add( control ); + Toolkit::Alignment alignmentContainer = Toolkit::Alignment::New(alignment); + alignmentContainer.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + alignmentContainer.SetPadding(padding); + alignmentContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + alignmentContainer.Add(control); // Insert the control in the table view. - mLayout.AddChild( alignmentContainer, Toolkit::TableView::CellPosition( 0, index ) ); - mLayout.SetRelativeWidth( index, relativeSize ); + mLayout.AddChild(alignmentContainer, Toolkit::TableView::CellPosition(0, index)); + mLayout.SetRelativeWidth(index, relativeSize); // Relate control and alignmentContainer in order to allow removing controls. mControls[control] = alignmentContainer; @@ -141,35 +117,35 @@ void ToolBar::AddControl( Actor control, float relativeSize, Toolkit::Alignment: mAccumulatedRelativeSpace += relativeSize; // Update spaces between left, center and right groups of controls. - switch( alignment ) + switch(alignment) { - case Toolkit::Alignment::HorizontalLeft: + case Toolkit::Alignment::HORIZONTAL_LEFT: { mLeftRelativeSpace -= relativeSize; - if ( mLeftRelativeSpace < 0.f ) + if(mLeftRelativeSpace < 0.f) { mLeftRelativeSpace = 0.f; } break; } - case Toolkit::Alignment::HorizontalCenter: + case Toolkit::Alignment::HORIZONTAL_CENTER: { mLeftRelativeSpace -= 0.5f * relativeSize; - if ( mLeftRelativeSpace < 0.f ) + if(mLeftRelativeSpace < 0.f) { mLeftRelativeSpace = 0.f; } mRightRelativeSpace -= 0.5f * relativeSize; - if ( mRightRelativeSpace < 0.f ) + if(mRightRelativeSpace < 0.f) { mRightRelativeSpace = 0.f; } break; } - case Toolkit::Alignment::HorizontalRight: + case Toolkit::Alignment::HORIZONTAL_RIGHT: { mRightRelativeSpace -= relativeSize; - if ( mRightRelativeSpace < 0.f ) + if(mRightRelativeSpace < 0.f) { mRightRelativeSpace = 0.f; } @@ -177,78 +153,78 @@ void ToolBar::AddControl( Actor control, float relativeSize, Toolkit::Alignment: } default: { - DALI_ASSERT_ALWAYS( false ); + DALI_ASSERT_ALWAYS(false); } } - mLayout.SetRelativeWidth( mLeftOffset, mLeftRelativeSpace ); - mLayout.SetRelativeWidth( mCenterBase + mCenterOffset, mRightRelativeSpace ); + mLayout.SetRelativeWidth(mLeftOffset, mLeftRelativeSpace); + mLayout.SetRelativeWidth(mCenterBase + mCenterOffset, mRightRelativeSpace); } -void ToolBar::RemoveControl( Actor control ) +void ToolBar::RemoveControl(Actor control) { Toolkit::TableView::CellPosition position; // Find the alignment where the control is placed. - std::map::iterator it = mControls.find( control ); + std::map::iterator it = mControls.find(control); - if( ( it != mControls.end() ) && ( mLayout.FindChildPosition( it->second, position ) ) ) + if((it != mControls.end()) && (mLayout.FindChildPosition(it->second, position))) { // Update accumulated relative space. - mAccumulatedRelativeSpace -= mLayout.GetRelativeWidth( position.columnIndex ); + mAccumulatedRelativeSpace -= mLayout.GetRelativeWidth(position.columnIndex); // Update spaces between left, center and right groups of controls. - if( 1.0 > mAccumulatedRelativeSpace ) + if(1.0 > mAccumulatedRelativeSpace) { - Toolkit::Alignment::Type alignment = Toolkit::Alignment::HorizontalLeft; - if( position.columnIndex < mLeftOffset ) + Toolkit::Alignment::Type alignment = Toolkit::Alignment::HORIZONTAL_LEFT; + if(position.columnIndex < mLeftOffset) { - alignment = Toolkit::Alignment::HorizontalLeft; + alignment = Toolkit::Alignment::HORIZONTAL_LEFT; } - else if( ( position.columnIndex > mLeftOffset ) && ( position.columnIndex < mCenterBase + mCenterOffset ) ) + else if((position.columnIndex > mLeftOffset) && (position.columnIndex < mCenterBase + mCenterOffset)) { - alignment = Toolkit::Alignment::HorizontalCenter; + alignment = Toolkit::Alignment::HORIZONTAL_CENTER; } - else if( position.columnIndex > mCenterBase + mCenterOffset ) + else if(position.columnIndex > mCenterBase + mCenterOffset) { - alignment = Toolkit::Alignment::HorizontalRight; + alignment = Toolkit::Alignment::HORIZONTAL_RIGHT; } else { - DALI_ASSERT_ALWAYS( false ); + DALI_ASSERT_ALWAYS(false); } - float relativeSize = mLayout.GetRelativeWidth( position.columnIndex ); + float relativeSize = mLayout.GetRelativeWidth(position.columnIndex); - switch( alignment ) + switch(alignment) { - case Toolkit::Alignment::HorizontalLeft: + case Toolkit::Alignment::HORIZONTAL_LEFT: { mLeftRelativeSpace += relativeSize; - if ( mLeftRelativeSpace < 0.f ) + if(mLeftRelativeSpace < 0.f) { mLeftRelativeSpace = 0.f; } break; } - case Toolkit::Alignment::HorizontalCenter: + case Toolkit::Alignment::HORIZONTAL_CENTER: { mLeftRelativeSpace += 0.5f * relativeSize; - if ( mLeftRelativeSpace < 0.f ) + if(mLeftRelativeSpace < 0.f) { mLeftRelativeSpace = 0.f; } mRightRelativeSpace += 0.5f * relativeSize; - if ( mRightRelativeSpace < 0.f ) + if(mRightRelativeSpace < 0.f) { mRightRelativeSpace = 0.f; } break; } - case Toolkit::Alignment::HorizontalRight: + case Toolkit::Alignment::HORIZONTAL_RIGHT: { mRightRelativeSpace += relativeSize; - if ( mRightRelativeSpace < 0.f ) + if(mRightRelativeSpace < 0.f) { mRightRelativeSpace = 0.f; } @@ -256,31 +232,31 @@ void ToolBar::RemoveControl( Actor control ) } default: { - DALI_ASSERT_ALWAYS( false ); + DALI_ASSERT_ALWAYS(false); } } - mLayout.SetRelativeWidth( mLeftOffset, mLeftRelativeSpace ); - mLayout.SetRelativeWidth( mCenterBase + mCenterOffset, mRightRelativeSpace ); + mLayout.SetRelativeWidth(mLeftOffset, mLeftRelativeSpace); + mLayout.SetRelativeWidth(mCenterBase + mCenterOffset, mRightRelativeSpace); } // Remove alignment as parent of control. - it->second.Remove( control ); + it->second.Remove(control); // Remove the relationship between control and alignment. - mControls.erase( it ); + mControls.erase(it); // Remove column from tableview. - mLayout.DeleteColumn( position.columnIndex ); + mLayout.DeleteColumn(position.columnIndex); // Update bases and offsets. - if( position.columnIndex < mCenterBase ) + if(position.columnIndex < mCenterBase) { // Control is on the left side. Decrease left offset and center and right bases. --mLeftOffset; --mCenterBase; --mRightBase; } - else if( position.columnIndex < mCenterBase + mCenterOffset ) + else if(position.columnIndex < mCenterBase + mCenterOffset) { // Control is on the center side. Decrease center offset and right base. --mCenterOffset; @@ -296,17 +272,17 @@ void ToolBar::RemoveControl( Actor control ) } ToolBar::ToolBar() -: Control( CONTROL_BEHAVIOUR_NONE ), +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mLayout(), - mLeftOffset( 0 ), - mCenterBase( 1 ), - mCenterOffset( 0 ), - mRightBase( 2 ), - mRightOffset( 0 ), - mLeftRelativeSpace( 0.5f ), - mRightRelativeSpace( 0.5f ), - mAccumulatedRelativeSpace( 0.f ), - mInitializing( false ), + mLeftOffset(0), + mCenterBase(1), + mCenterOffset(0), + mRightBase(2), + mRightOffset(0), + mLeftRelativeSpace(0.5f), + mRightRelativeSpace(0.5f), + mAccumulatedRelativeSpace(0.f), + mInitializing(false), mControls() { } @@ -317,49 +293,50 @@ ToolBar::~ToolBar() void ToolBar::OnInitialize() { - Lock lock( mInitializing ); + Lock lock(mInitializing); // Layout - mLayout = Toolkit::TableView::New( 1, 1 ); - mLayout.SetName( "TOOLBAR_LAYOUT" ); - mLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mLayout.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); + mLayout = Toolkit::TableView::New(1, 1); + mLayout.SetProperty(Dali::Actor::Property::NAME, "TOOLBAR_LAYOUT"); + mLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - Self().Add( mLayout ); + Self().Add(mLayout); // Add two default actors to create spaces between controls grouped on the left, center and right. - Actor leftSpace = Actor::New(); + Actor leftSpace = Actor::New(); Actor rightSpace = Actor::New(); - mLayout.AddChild( leftSpace, Toolkit::TableView::CellPosition( 0, 0 ) ); - mLayout.AddChild( rightSpace, Toolkit::TableView::CellPosition( 0, 1 ) ); - mLayout.SetRelativeWidth( 0, mLeftRelativeSpace ); - mLayout.SetRelativeWidth( 1, mRightRelativeSpace ); + mLayout.AddChild(leftSpace, Toolkit::TableView::CellPosition(0, 0)); + mLayout.AddChild(rightSpace, Toolkit::TableView::CellPosition(0, 1)); + mLayout.SetRelativeWidth(0, mLeftRelativeSpace); + mLayout.SetRelativeWidth(1, mRightRelativeSpace); + + DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) { + return std::unique_ptr( + new Control::Impl::AccessibleImpl(actor, Dali::Accessibility::Role::TOOL_BAR)); + }); } -void ToolBar::OnControlChildAdd(Actor& child) +void ToolBar::OnChildAdd(Actor& child) { - if( !mInitializing ) + if(!mInitializing) { // An actor is being added through the Actor's API. // Remove child from tool bar actor and insert it in table view with some 'default' values - if ( child && child.GetParent() ) + if(child && child.GetParent()) { - child.GetParent().Remove( child ); + child.GetParent().Remove(child); } - AddControl( child, DEFAULT_RELATIVE_SIZE, DEFAULT_ALIGNMENT, Toolkit::ToolBar::DEFAULT_PADDING ); + AddControl(child, DEFAULT_RELATIVE_SIZE, DEFAULT_ALIGNMENT, Toolkit::ToolBar::DEFAULT_PADDING); } - // No OnControlChildRemove method required because Actors are added to the mLayout table view, so if an + // No OnChildRemove method required because Actors are added to the mLayout table view, so if an // actor is removed using the Actor::RemoveChild method it will not remove anything because the // actor is in mLayout not in Self(). -} -void ToolBar::OnControlSizeSet( const Vector3& targetSize ) -{ - mToolBarSize = targetSize; - mBackground.SetSize( Vector2( mToolBarSize.width, mToolBarSize.height ) ); + Control::OnChildAdd(child); } } // namespace Internal