Update keyboard focus direction enum for Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / popup / popup-impl.cpp
index 69df006..719cfe9 100755 (executable)
 #include <dali-toolkit/internal/controls/popup/popup-impl.h>
 
 // EXTERNAL INCLUDES
+#include <cstring> // for strcmp
 #include <dali/public-api/adaptor-framework/key.h>
-#include <dali/public-api/adaptor-framework/physical-keyboard.h>
+#include <dali/devel-api/adaptor-framework/physical-keyboard.h>
 #include <dali/public-api/animation/constraints.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/events/key-event.h>
 #include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/devel-api/object/type-registry-helper.h>
 #include <dali/public-api/size-negotiation/relayout-container.h>
 #include <dali/integration-api/debug.h>
 
@@ -37,6 +38,7 @@
 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
+#include <dali-toolkit/internal/controls/buttons/button-impl.h>
 
 using namespace Dali;
 
@@ -60,8 +62,8 @@ BaseHandle Create()
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Popup, Toolkit::Control, Create )
 
-DALI_SIGNAL_REGISTRATION( Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
-DALI_SIGNAL_REGISTRATION( Popup, "hidden",          SIGNAL_HIDDEN          )
+DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "touched-outside", SIGNAL_TOUCHED_OUTSIDE )
+DALI_SIGNAL_REGISTRATION( Toolkit, Popup, "hidden",          SIGNAL_HIDDEN          )
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -121,14 +123,14 @@ void Popup::OnInitialize()
   Actor self = Self();
   self.SetSensitive(false);
   // Reisize to fit the height of children
-  self.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT );
+  self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
 
   // Create Layer
   mLayer = Layer::New();
   mLayer.SetName( "POPUP_LAYER" );
   mLayer.SetParentOrigin(ParentOrigin::CENTER);
   mLayer.SetAnchorPoint(AnchorPoint::CENTER);
-  mLayer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+  mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   mLayer.SetDrawMode( DrawMode::OVERLAY );
 
   // Any content after this point which is added to Self() will be reparented to
@@ -147,8 +149,8 @@ void Popup::OnInitialize()
   mPopupLayout.SetName( "POPUP_LAYOUT_TABLE" );
   mPopupLayout.SetParentOrigin(ParentOrigin::CENTER);
   mPopupLayout.SetAnchorPoint(AnchorPoint::CENTER);
-  mPopupLayout.SetResizePolicy( FILL_TO_PARENT, WIDTH );
-  mPopupLayout.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
+  mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+  mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
   mPopupLayout.SetFitHeight( 0 );   // Set row to fit
   mPopupLayout.SetFitHeight( 1 );   // Set row to fit
   self.Add( mPopupLayout );
@@ -171,12 +173,6 @@ void Popup::OnInitialize()
   SetAsKeyboardFocusGroup(true);
 }
 
-void Popup::MarkDirtyForRelayout()
-{
-  // Flag all the popup controls for relayout as it is about to be hidden and miss the main flagging pass
-  mLayer.RelayoutRequestTree();
-}
-
 void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue )
 {
   if( index == mPropertyTitle )
@@ -223,7 +219,7 @@ void Popup::SetBackgroundImage( Actor image )
   // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
   mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
 
-  mBackgroundImage.SetResizePolicy( SIZE_FIXED_OFFSET_FROM_PARENT, ALL_DIMENSIONS );
+  mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
   mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER );
   mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
 
@@ -250,7 +246,7 @@ void Popup::SetButtonAreaImage( Actor image )
   // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing.
   mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
 
-  mButtonAreaImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+  mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER );
   mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER );
 
@@ -262,41 +258,36 @@ void Popup::SetButtonAreaImage( Actor image )
 
 void Popup::SetTitle( const std::string& text )
 {
-  Toolkit::TextView titleActor = Toolkit::TextView::New();
-  titleActor.SetName( "POPUP_TITLE" );
-  titleActor.SetText( text );
-  titleActor.SetColor( Color::BLACK );
-  titleActor.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
-  titleActor.SetWidthExceedPolicy( Toolkit::TextView::Split );
-  titleActor.SetLineJustification( Toolkit::TextView::Center );
-
-  SetTitle( titleActor );
-}
-
-void Popup::SetTitle( Toolkit::TextView titleActor )
-{
   // Replaces the current title actor.
   if( mPopupLayout )
   {
     mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) );
   }
 
-  mTitle = titleActor;
+  mTitle = Toolkit::TextLabel::New( text );
+  mTitle.SetName( "POPUP_TITLE" );
+  mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+  mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
 
   if( mPopupLayout )
   {
     mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) );
-    mTitle.SetResizePolicy( FILL_TO_PARENT, WIDTH );
-    mTitle.SetResizePolicy( DIMENSION_DEPENDENCY, HEIGHT );
+    mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
     mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
   }
 
   RelayoutRequest();
 }
 
-Toolkit::TextView Popup::GetTitle() const
+std::string Popup::GetTitle() const
 {
-  return mTitle;
+  if( mTitle )
+  {
+    return mTitle.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
+  }
+
+  return std::string();
 }
 
 void Popup::CreateFooter()
@@ -306,8 +297,7 @@ void Popup::CreateFooter()
     // Adds bottom background
     mBottomBg = Actor::New();
     mBottomBg.SetName( "POPUP_BOTTOM_BG" );
-    mBottomBg.SetRelayoutEnabled( true );
-    mBottomBg.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+    mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
     mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height );   // Buttons
     mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) );
@@ -317,7 +307,7 @@ void Popup::CreateFooter()
 void Popup::AddButton( Toolkit::Button button )
 {
   mButtons.push_back( button );
-  button.SetResizePolicy( USE_ASSIGNED_SIZE, ALL_DIMENSIONS );    // Size will be assigned to it
+  button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );    // Size will be assigned to it
 
   // If this is the first button added
   if( mButtons.size() == 1 )
@@ -427,13 +417,13 @@ void Popup::CreateBacking()
   mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor );
   mBacking.SetName( "POPUP_BACKING" );
 
-  mBacking.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+  mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   mBacking.SetSensitive(true);
 
   mLayer.Add( mBacking );
   mBacking.SetOpacity(0.0f);
   mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
-  mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent);
+  mBacking.WheelEventSignal().Connect(this, &Popup::OnBackingWheelEvent);
 }
 
 void Popup::CreateDialog()
@@ -530,13 +520,13 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration
 
     if(mShowing)
     {
-      mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
-      mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) );
+      mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
+      mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(duration * 0.5f, duration * 0.5f) );
     }
     else
     {
-      mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
-      mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) );
+      mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
+      mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) );
     }
     mAnimation.Play();
     mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished);
@@ -621,9 +611,9 @@ bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event)
   return true;
 }
 
-bool Popup::OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event)
+bool Popup::OnBackingWheelEvent(Actor actor, const WheelEvent& event)
 {
-  // consume mouse wheel event in dimmed backing actor
+  // consume wheel event in dimmed backing actor
   return true;
 }
 
@@ -657,7 +647,7 @@ void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
   mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) );
 
   // Relayout All buttons
-  if ( !mButtons.empty() )
+  if( !mButtons.empty() )
   {
     // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well.
     Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ),
@@ -665,7 +655,7 @@ void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
 
     Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f );
 
-    for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end();
+    for( std::vector< Actor >::iterator iter = mButtons.begin(), endIter = mButtons.end();
           iter != endIter;
           ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width )
     {
@@ -686,29 +676,29 @@ void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
 
       button.SetPosition( buttonPosition );
 
-      button.PropagateRelayoutFlags();    // Reset relayout flags for relayout
-      container.Add( button, buttonSize );
+     //Todo: Use the size negotiation pass instead of SetSize directly
+     button.SetSize( buttonSize );
     }
   }
 }
 
-void Popup::OnSetResizePolicy( ResizePolicy policy, Dimension dimension )
+void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
 {
   if( mPopupLayout )
   {
-    if( policy == FIT_TO_CHILDREN )
+    if( policy == ResizePolicy::FIT_TO_CHILDREN )
     {
-      mPopupLayout.SetResizePolicy( USE_NATURAL_SIZE, dimension );
-      if( dimension & HEIGHT )
+      mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension );
+      if( dimension & Dimension::HEIGHT )
       {
         mPopupLayout.SetFitHeight( 1 );
       }
     }
     else
     {
-      mPopupLayout.SetResizePolicy( FILL_TO_PARENT, dimension );
+      mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension );
       // Make the content cell fill the whole of the available space
-      if( dimension & HEIGHT )
+      if( dimension & Dimension::HEIGHT )
       {
         mPopupLayout.SetRelativeHeight( 1, 1.0f );
       }
@@ -747,7 +737,7 @@ Vector3 Popup::GetNaturalSize()
     const float titleBuffer = 0.5f;
     titleNaturalSize.width += titleBuffer;
 
-    // As TextView GetNaturalSize does not take wrapping into account, limit the width
+    // As TextLabel GetNaturalSize does not take wrapping into account, limit the width
     // to that of the stage
     if( titleNaturalSize.width >= maxWidth)
     {
@@ -820,7 +810,7 @@ float Popup::GetWidthForHeight( float height )
   return GetNaturalSize().width;
 }
 
-Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
+Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
 {
   Actor nextFocusableActor( currentFocusedActor );
 
@@ -843,7 +833,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::C
   else
   {
     // Rebuild the focus chain because button or content can be added or removed dynamically
-    ActorContainer focusableActors;
+    std::vector< Actor > focusableActors;
     if( mContent && mContent.IsKeyboardFocusable() )
     {
       focusableActors.push_back(mContent);
@@ -857,13 +847,13 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::C
       }
     }
 
-    for ( ActorContainer::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
+    for( std::vector< Actor >::iterator iter = focusableActors.begin(), end = focusableActors.end(); iter != end; ++iter )
     {
       if ( currentFocusedActor == *iter )
       {
         switch ( direction )
         {
-          case Toolkit::Control::Left:
+          case Toolkit::Control::KeyboardFocus::LEFT:
           {
             if ( iter == focusableActors.begin() )
             {
@@ -875,7 +865,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::C
             }
             break;
           }
-          case Toolkit::Control::Right:
+          case Toolkit::Control::KeyboardFocus::RIGHT:
           {
             if ( iter == focusableActors.end() - 1 )
             {
@@ -888,7 +878,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::C
             break;
           }
 
-          case Toolkit::Control::Up:
+          case Toolkit::Control::KeyboardFocus::UP:
           {
             if ( *iter == mContent )
             {
@@ -915,7 +905,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::C
             break;
           }
 
-          case Toolkit::Control::Down:
+          case Toolkit::Control::KeyboardFocus::DOWN:
           {
             if ( mContent && mContent.IsKeyboardFocusable() )
             {