Revert "Revert "Renamed KeyEvent enum values to comply with coding standards.""
[platform/core/uifw/dali-demo.git] / examples / popup / popup-example.cpp
index 9f6d308..15475b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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,6 +19,7 @@
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/popup/popup.h>
+#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
 
 using namespace Dali;
 
@@ -112,13 +113,13 @@ public:
   void Create( Application& application )
   {
     // The Init signal is received once (only) during the Application lifetime
-    Stage stage = Stage::GetCurrent();
+    Window window = application.GetWindow();
 
     // Respond to key events if not handled
-    stage.KeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
+    window.KeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
 
     // Creates a default view with a default tool bar.
-    // The view is added to the stage.
+    // The view is added to the window.
     mContentLayer = DemoHelper::CreateView( application,
                                             mView,
                                             mToolBar,
@@ -156,15 +157,15 @@ public:
     mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
     // Use a grid layout for tests
-    Vector2 stageSize = stage.GetSize();
+    Vector2 windowSize = window.GetSize();
     Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
     Vector3 itemSize;
-    gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
-    itemSize.height = stageSize.y / 10;
+    gridLayout->GetItemSize( 0, Vector3( windowSize ), itemSize );
+    itemSize.height = windowSize.y / 10;
     gridLayout->SetItemSize( itemSize );
     mItemView.AddLayout( *gridLayout );
 
-    mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
+    mItemView.ActivateLayout( 0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f );
 
     mContentLayer.Add( mItemView );
   }
@@ -194,27 +195,27 @@ public:
    */
   void SetupContextualResizePolicy( Toolkit::Popup& popup )
   {
-    Vector2 stageSize = Stage::GetCurrent().GetSize();
+    Vector2 windowSize = mApplication.GetWindow().GetSize();
     // Some defaults when creating a new fixed size.
     // This is NOT a Vector2 so we can modify each dimension in a for-loop.
-    float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
+    float newSize[ Dimension::DIMENSION_COUNT ] = { windowSize.x * 0.75f, windowSize.y * 0.75f };
     bool modifySize = false;
 
     // Loop through each of two dimensions to process them.
     for( unsigned int dimension = 0; dimension < 2; ++dimension )
     {
-      float stageDimensionSize, sizeModeFactor;
+      float windowDimensionSize, sizeModeFactor;
       Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
 
       // Setup information related to the current dimension we are processing.
       if( policyDimension == Dimension::WIDTH )
       {
-        stageDimensionSize = stageSize.x;
+        windowDimensionSize = windowSize.x;
         sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).x;
       }
       else
       {
-        stageDimensionSize = stageSize.y;
+        windowDimensionSize = windowSize.y;
         sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).y;
       }
 
@@ -246,7 +247,7 @@ public:
         case ResizePolicy::FILL_TO_PARENT:
         {
           newPolicy = ResizePolicy::FIXED;
-          newSize[ dimension ] = stageDimensionSize;
+          newSize[ dimension ] = windowDimensionSize;
           modifyPolicy = true;
           break;
         }
@@ -254,7 +255,7 @@ public:
         case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
         {
           newPolicy = ResizePolicy::FIXED;
-          newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
+          newSize[ dimension ] = windowDimensionSize * sizeModeFactor;
           modifyPolicy = true;
           break;
         }
@@ -262,7 +263,7 @@ public:
         case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
         {
           newPolicy = ResizePolicy::FIXED;
-          newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
+          newSize[ dimension ] = windowDimensionSize + sizeModeFactor;
           modifyPolicy = true;
           break;
         }
@@ -279,7 +280,7 @@ public:
     if( modifySize )
     {
       // The size is set once at the end.
-      popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
+      popup.SetProperty( Actor::Property::SIZE, Vector2( newSize[ 0 ], newSize[ 1 ] ) );
     }
   }
 
@@ -305,7 +306,7 @@ public:
     }
     else
     {
-      Stage::GetCurrent().Add( popup );
+      mApplication.GetWindow().Add( popup );
     }
 
     mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
@@ -330,14 +331,14 @@ public:
 
   Toolkit::Popup CreatePopup()
   {
-    Stage stage = Stage::GetCurrent();
-    const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
+    Window window = mApplication.GetWindow();
+    const float POPUP_WIDTH_DP = window.GetSize().GetWidth() * 0.75f;
 
     Toolkit::Popup popup = Toolkit::Popup::New();
     popup.SetProperty( Dali::Actor::Property::NAME, "popup" );
     popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    popup.SetSize( POPUP_WIDTH_DP, 0.0f );
+    popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) );
     popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
 
     popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
@@ -359,7 +360,7 @@ public:
       // Set up the container's layout.
       footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
       footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
-      footer.SetSize( 0.0f, 130.0f );
+      footer.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 130.0f ) );
       footer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
       footer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
 
@@ -483,7 +484,7 @@ public:
           mPopup = Toolkit::Popup::DownCast( baseHandle );
           mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
 
-          Stage::GetCurrent().Add( mPopup );
+          mApplication.GetWindow().Add( mPopup );
           mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
         }
       }
@@ -565,7 +566,7 @@ public:
       mPopup.Add( text );
 
       // Fix the popup's size.
-      mPopup.SetSize( 240.0f, 400.0f );
+      mPopup.SetProperty( Actor::Property::SIZE, Vector2( 240.0f, 400.0f ) );
       mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
 
       SetupPopup( mPopup, button );
@@ -632,7 +633,7 @@ public:
         root.SetProperty( Actor::Property::PADDING, Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
 
         Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
-        checkBox.SetSize( 48, 48 );
+        checkBox.SetProperty( Actor::Property::SIZE, Vector2( 48, 48 ) );
         root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
 
         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
@@ -670,7 +671,7 @@ public:
 
   void OnKeyEvent( const KeyEvent& event )
   {
-    if( event.state == KeyEvent::Down )
+    if( event.GetState() == KeyEvent::DOWN )
     {
       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
       {