[dali_1.2.22] Merge branch 'devel/master'
[platform/core/uifw/dali-demo.git] / examples / popup / popup-example.cpp
index ea2e89a..a2427ea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * 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.
@@ -18,7 +18,9 @@
 #include "shared/view.h"
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/controls/popup/popup.h>
+#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
 
 using namespace Dali;
 
@@ -33,15 +35,15 @@ struct ButtonItem
 namespace
 {
 
-const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "background-gradient.jpg";
-const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png";
+const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
+const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
 
 const char* const TOOLBAR_TITLE = "Popup";
 
-const char* CONTEXT_DISABLED_ICON_IMAGE = DALI_IMAGE_DIR "icon-scroll-view-carousel.png";
-const char* CONTEXT_ENABLED_ICON_IMAGE = DALI_IMAGE_DIR "icon-scroll-view-spiral.png";
-const char* ANIMATION_FADE_ICON_IMAGE = DALI_IMAGE_DIR "icon-effects-off.png";
-const char* ANIMATION_ZOOM_ICON_IMAGE = DALI_IMAGE_DIR "icon-effects-on.png";
+const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png";
+const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png";
+const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png";
+const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png";
 
 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
@@ -54,17 +56,18 @@ const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTE
 const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS";
 const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID";
 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
+const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE";
 
 // Names to give Popup PushButton controls.
-const char* const POPUP_CONTROL_OK_NAME = "control-ok";
-const char* const POPUP_CONTROL_CANCEL_NAME = "control-cancel";
+const char* const POPUP_CONTROL_OK_NAME = "controlOk";
+const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
 
 const char* const CONTENT_TEXT = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
-const char* const IMAGE1 = DALI_IMAGE_DIR "gallery-medium-5.jpg";
-const char* const IMAGE2 = DALI_IMAGE_DIR "background-magnifier.jpg";
+const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg";
+const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg";
 
 // Control area image.
-const char*   DEFAULT_CONTROL_AREA_IMAGE_PATH = DALI_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
+const char*   DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
 
 const ButtonItem POPUP_BUTTON_ITEMS[] = {
     { POPUP_BUTTON_COMPLEX_ID,                     "Complex" },
@@ -77,11 +80,13 @@ const ButtonItem POPUP_BUTTON_ITEMS[] = {
     { POPUP_BUTTON_CONTENT_TEXT_ID,                "Content Text" },
     { POPUP_BUTTON_CONTENT_IMAGE_ID,               "Content Image" },
     { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID,          "Title + Content" },
-    { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" }
+    { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" },
+    { POPUP_BUTTON_CUSTOM_STYLE,                   "Custom Styled Popup" }
 };
 
 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
 
+const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name
 }  // anonymous namespace
 
 
@@ -111,8 +116,12 @@ public:
     // The Init signal is received once (only) during the Application lifetime
     Stage stage = Stage::GetCurrent();
 
-    // Respond to key events
-    stage.KeyEventSignal().Connect(this, &PopupExample::OnKeyEvent);
+    // Respond to key events if not handled
+    Toolkit::KeyInputFocusManager keyInputFocusManager = Toolkit::KeyInputFocusManager::Get();
+    if( keyInputFocusManager )
+    {
+      keyInputFocusManager.UnhandledKeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
+    }
 
     // Creates a default view with a default tool bar.
     // The view is added to the stage.
@@ -132,17 +141,17 @@ public:
 
     // Create animation button.
     mAnimationButton = Toolkit::PushButton::New();
-    mAnimationButton.SetUnselectedImage( ANIMATION_FADE_ICON_IMAGE );
-    mAnimationButton.SetSelectedImage( ANIMATION_ZOOM_ICON_IMAGE );
-    mAnimationButton.SetTogglableButton( true );
+    mAnimationButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE );
+    mAnimationButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE );
+    mAnimationButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
     mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
     mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
 
     // Create context button.
     mContextButton = Toolkit::PushButton::New();
-    mContextButton.SetUnselectedImage( CONTEXT_DISABLED_ICON_IMAGE );
-    mContextButton.SetSelectedImage( CONTEXT_ENABLED_ICON_IMAGE );
-    mContextButton.SetTogglableButton( true );
+    mContextButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE );
+    mContextButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE );
+    mContextButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
     mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
     mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
 
@@ -168,13 +177,13 @@ public:
 
   bool OnContextClicked( Toolkit::Button button )
   {
-    mContextual = button.IsSelected();
+    mContextual = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>();
     return true;
   }
 
   bool OnAnimationClicked( Toolkit::Button button )
   {
-    mAnimationFade = !button.IsSelected();
+    mAnimationFade = ! ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() );
     return true;
   }
 
@@ -352,11 +361,11 @@ public:
     {
       // Start with a control area image.
       Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
-      footer.SetName( "control-area-image" );
+      footer.SetName( "controlAreaImage" );
       // Set up the container's layout.
       footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
       footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
-      footer.SetSize( 0.0f, 80.0f );
+      footer.SetSize( 0.0f, 130.0f );
       footer.SetAnchorPoint( AnchorPoint::CENTER );
       footer.SetParentOrigin( ParentOrigin::CENTER );
 
@@ -407,7 +416,7 @@ public:
   Actor CreateTitle( std::string title )
   {
     Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
-    titleActor.SetName( "title-actor" );
+    titleActor.SetName( "titleActor" );
     titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
     titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
     titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
@@ -419,7 +428,7 @@ public:
   {
     Toolkit::PushButton okayButton = Toolkit::PushButton::New();
     okayButton.SetName( POPUP_CONTROL_OK_NAME );
-    okayButton.SetLabelText( "OK!" );
+    okayButton.SetProperty( Toolkit::Button::Property::LABEL, "OK!" );
 
     okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
 
@@ -430,7 +439,7 @@ public:
   {
     Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
     cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
-    cancelButton.SetLabelText( "Cancel" );
+    cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" );
 
     cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
 
@@ -471,7 +480,7 @@ public:
     else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
     {
       // Create a toast popup via the type registry (as it is a named-type).
-      TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "popup-toast" );
+      TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
       if( typeInfo )
       {
         BaseHandle baseHandle = typeInfo.CreateInstance();
@@ -646,6 +655,21 @@ public:
 
       SetupPopup( mPopup, button );
     }
+    else if( button.GetName() == POPUP_BUTTON_CUSTOM_STYLE )
+    {
+      mPopup = CreateConfirmationPopup( 2 );
+
+      Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" );
+      titleActor.SetName( "titleActor" );
+      titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED );
+      titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+      titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+      mPopup.SetTitle( titleActor );
+
+      SetupPopup( mPopup, button );
+
+      mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME );
+    }
 
     return true;
   }
@@ -684,7 +708,7 @@ public: // From ItemFactory
   {
     Toolkit::PushButton popupButton = Toolkit::PushButton::New();
     popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
-    popupButton.SetLabelText( POPUP_BUTTON_ITEMS[ itemId ].text );
+    popupButton.SetProperty( Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[ itemId ].text );
     popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
 
     popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
@@ -707,11 +731,6 @@ private:
   bool                mContextual;                 ///< True if currently using the contextual popup mode.
   bool                mAnimationFade;              ///< True if currently using the fade animation.
 
-  ResourceImage       mContextButtonDisabledImage; ///< The disabled context button icon.
-  ResourceImage       mContextButtonEnabledImage;  ///< The enabled context button icon.
-  ResourceImage       mAnimationButtonZoomImage;   ///< The zoom animation button icon.
-  ResourceImage       mAnimationButtonFadeImage;   ///< The fade animation button icon.
-
   Toolkit::Popup      mPopup;                       ///< The current example popup.
 
   Toolkit::ItemView   mItemView;                    ///< ItemView to hold test images
@@ -726,9 +745,9 @@ void RunTest( Application& application )
 }
 
 // Entry point for Linux & SLP applications
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
 {
-  Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
+  Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
 
   RunTest( application );