Adding TextSelectionPopup control 06/36806/12
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 20 Mar 2015 11:02:15 +0000 (11:02 +0000)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 24 Mar 2015 10:52:09 +0000 (03:52 -0700)
Change-Id: Ibfeb0f1f212c76aa9963a6a1c81849daa1baa3ac
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
12 files changed:
dali-toolkit/images/popup_bubble_bg.#.png
dali-toolkit/images/popup_bubble_bg_ef.#.png [deleted file]
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp [new file with mode: 0644]
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h [new file with mode: 0644]
dali-toolkit/internal/file.list
dali-toolkit/internal/text/decorator/text-decorator.cpp
dali-toolkit/internal/text/decorator/text-decorator.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/public-api/controls/text-controls/text-selection-popup.cpp [new file with mode: 0644]
dali-toolkit/public-api/controls/text-controls/text-selection-popup.h [new file with mode: 0644]
dali-toolkit/public-api/file.list

index 202ecec..43106f3 100644 (file)
Binary files a/dali-toolkit/images/popup_bubble_bg.#.png and b/dali-toolkit/images/popup_bubble_bg.#.png differ
diff --git a/dali-toolkit/images/popup_bubble_bg_ef.#.png b/dali-toolkit/images/popup_bubble_bg_ef.#.png
deleted file mode 100644 (file)
index 462c9db..0000000
Binary files a/dali-toolkit/images/popup_bubble_bg_ef.#.png and /dev/null differ
index 5cd3308..71a4c5f 100644 (file)
@@ -86,7 +86,6 @@ DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-duration",   FLOAT,     CUR
 DALI_PROPERTY_REGISTRATION( TextField, "grab-handle-image",       STRING,    GRAB_HANDLE_IMAGE       )
 DALI_PROPERTY_REGISTRATION( TextField, "decoration bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
 DALI_PROPERTY_REGISTRATION( TextField, "alignment",               STRING,    ALIGNMENT               )
-
 DALI_TYPE_REGISTRATION_END()
 
 } // namespace
@@ -262,8 +261,8 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
         }
         break;
       }
-    }
-  }
+    } // switch
+  } // textfield
 }
 
 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
@@ -363,7 +362,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
-    }
+    } //switch
   }
 
   return value;
diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp
new file mode 100644 (file)
index 0000000..e117e22
--- /dev/null
@@ -0,0 +1,667 @@
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/buttons/push-button.h>
+#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/nine-patch-image.h>
+#include <dali/public-api/images/resource-image.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/vector4.h>
+#include <libintl.h>
+
+// todo Move this to adaptor??
+#define GET_LOCALE_TEXT(string) dgettext("elementary", string)
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
+const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
+const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+
+const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
+const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
+const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
+const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
+const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
+const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
+const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
+
+const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 470.0f, 120.0f ); ///< The maximum size of the popup.
+
+const float OPTION_TEXT_LINE_HEIGHT( 32.0f );     ///< The line height of the text.
+const Dali::Vector2 OPTION_ICON_SIZE( 0.f, 0.f );       ///< The size of the icon.
+const float OPTION_GAP_ICON_TEXT( 6.f );          ///< The gap between the icon and the text
+const float OPTION_MARGIN_WIDTH( 10.f );          ///< The margin between the right or lefts edge and the text or icon.
+const float OPTION_MAX_WIDTH( DEFAULT_POPUP_MAX_SIZE.width / 6 ); ///< The maximum width of the option (currently set to the max)
+const float OPTION_MIN_WIDTH( 86.0f );           ///< The minimum width of the option.
+
+const float POPUP_DIVIDER_WIDTH( 1.f );        ///< The size of the divider.
+
+const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail.
+const float POPUP_TAIL_Y_OFFSET( 5.f );        ///< The y offset of the tail (when its position is on the bottom).
+const float POPUP_TAIL_TOP_Y_OFFSET( 3.f );    ///< The y offset of the tail (when its position is on the top).
+
+const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
+const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
+
+const char* const OPTION_SELECT_WORD = "option-select_word";                       // "Select Word" popup option.
+const char* const OPTION_SELECT_ALL("option-select_all");                          // "Select All" popup option.
+const char* const OPTION_CUT("option-cut");                                        // "Cut" popup option.
+const char* const OPTION_COPY("option-copy");                                      // "Copy" popup option.
+const char* const OPTION_PASTE("option-paste");                                    // "Paste" popup option.
+const char* const OPTION_CLIPBOARD("option-clipboard");                            // "Clipboard" popup option.
+
+} // namespace
+
+//// Comparison function for ButtonRequirement Priority
+//bool TextSelectionPopup::PriorityCompare( ButtonRequirement const& a, ButtonRequirement const& b )
+//{
+//  return a.priority < b.priority;
+//}
+
+
+Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
+{
+  // Create the implementation, temporarily owned by this handle on stack
+  IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
+
+  // Pass ownership to CustomActor handle
+  Dali::Toolkit::TextSelectionPopup handle( *impl );
+
+  // Second-phase init of the implementation
+  // This can only be done after the CustomActor connection has been made...
+  impl->Initialize();
+
+  return handle;
+}
+
+void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+  Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
+
+  if( selectionPopup )
+  {
+    TextSelectionPopup& impl( GetImpl( selectionPopup ) );
+
+    switch( index )
+    {
+      case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+      {
+       impl.SetPopupMaxSize( value.Get< Vector2 >() );
+       break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_BACKGROUND, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_CLIPBOARD_BUTTON, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_CUT_BUTTON_ICON, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_COPY_BUTTON_ICON, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_PASTE_BUTTON_ICON, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_SELECT_BUTTON_ICON, image );
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::New( value.Get< std::string >() );
+        impl.SetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON, image );
+        break;
+      }
+    } // switch
+  } // TextSelectionPopup
+}
+
+Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
+{
+  Property::Value value;
+
+  Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
+
+  if( selectionPopup )
+  {
+    TextSelectionPopup& impl( GetImpl( selectionPopup ) );
+
+    switch( index )
+    {
+      case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+      {
+        value = impl.GetPopupMaxSize();
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_BACKGROUND ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CLIPBOARD_BUTTON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CUT_BUTTON_ICON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_COPY_BUTTON_ICON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_PASTE_BUTTON_ICON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_BUTTON_ICON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+      {
+        ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON ) );
+        if( image )
+        {
+          value = image.GetUrl();
+        }
+        break;
+      }
+    } // switch
+  }
+  return value;
+}
+
+void TextSelectionPopup::OnInitialize()
+{
+  CreatePopup();
+}
+
+void TextSelectionPopup::OnRelayout( const Vector2& size, ActorSizeContainer& container )
+{
+
+}
+
+void TextSelectionPopup::SetPopupMaxSize( const Size& maxSize )
+{
+  mMaxSize = maxSize;
+}
+
+const Dali::Vector2& TextSelectionPopup::GetPopupMaxSize() const
+{
+  return mMaxSize;
+}
+
+void TextSelectionPopup::SetPopupImage( PopupParts part, Dali::Image image )
+{
+   switch ( part )
+   {
+   case POPUP_BACKGROUND :
+   {
+     mBackgroundImage = image;
+   }
+   break;
+   case POPUP_CLIPBOARD_BUTTON :
+   {
+     mClipboardIconImage  = image;
+   }
+   break;
+   case POPUP_CUT_BUTTON_ICON :
+   {
+     mCutIconImage = image;
+   }
+   break;
+   case POPUP_COPY_BUTTON_ICON :
+   {
+     mCopyIconImage = image;
+   }
+   break;
+   case POPUP_PASTE_BUTTON_ICON :
+   {
+     mPasteIconImage = image;
+   }
+   break;
+   case POPUP_SELECT_BUTTON_ICON :
+   {
+     mSelectIconImage = image;
+   }
+   break;
+   case POPUP_SELECT_ALL_BUTTON_ICON :
+   {
+     mSelectAllIconImage = image;
+   }
+   break;
+
+   } // switch
+}
+
+Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part )
+{
+  switch ( part )
+  {
+  case POPUP_BACKGROUND :
+  {
+    return mBackgroundImage;
+  }
+  break;
+  case POPUP_CLIPBOARD_BUTTON :
+  {
+    return mClipboardIconImage;
+  }
+  break;
+  case POPUP_CUT_BUTTON_ICON :
+  {
+    return mCutIconImage;
+  }
+  break;
+  case POPUP_COPY_BUTTON_ICON :
+  {
+    return mCopyIconImage;
+  }
+  break;
+  case POPUP_PASTE_BUTTON_ICON :
+  {
+    return mPasteIconImage;
+  }
+  break;
+  case POPUP_SELECT_BUTTON_ICON :
+  {
+    return mSelectIconImage;
+  }
+  break;
+  case POPUP_SELECT_ALL_BUTTON_ICON :
+  {
+    return mSelectAllIconImage;
+  }
+  break;
+  default :
+  {
+    DALI_ASSERT_DEBUG( "Unknown Popup Part" );
+  }
+  } // switch
+
+  return Dali::Image();
+}
+
+ void TextSelectionPopup::CreateOrderedListOfPopupOptions()
+ {
+   mOrderListOfButtons.clear();
+
+   // Create button for each possible option using Option priority
+   if ( !mCutIconImage )
+   {
+     mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
+   }
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), mCutIconImage, true ) );
+
+   if ( !mCopyIconImage )
+   {
+     mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
+   }
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), mCopyIconImage, true ) );
+
+   if ( !mPasteIconImage )
+   {
+     mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
+   }
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), mPasteIconImage, true ) );
+
+   if ( !mSelectIconImage )
+   mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), mSelectIconImage, true ) );
+
+   if ( !mSelectAllIconImage )
+   {
+    mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
+   }
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), mSelectAllIconImage, true ) );
+
+   if ( !mClipboardIconImage )
+   {
+     mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
+   }
+   mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), mClipboardIconImage, true ) );
+
+   // Sort the buttons according their priorities.
+   std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
+ }
+
+ void TextSelectionPopup::CreateBackground()
+ {
+   if ( !mBackgroundImage )
+   {
+     mBackgroundImage = ResourceImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE );
+   }
+
+   NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( mBackgroundImage );
+   if( backgroundImageNinePatch )
+   {
+     const Size ninePatchImageSize = Size( static_cast<float>( mBackgroundImage.GetWidth() ), static_cast<float>( mBackgroundImage.GetHeight() ) );
+     Rect<int> childRect = backgroundImageNinePatch.GetChildRectangle();
+
+     // -1u because of the cropping.
+     mNinePatchMargins.x = childRect.x - 1u;
+     mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u;
+     mNinePatchMargins.z = childRect.y - 1u;
+     mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u;
+   }
+
+   SetBackground ( mBackgroundImage );
+   SetBackgroundColor ( mBackgroundColor );
+ }
+
+ void TextSelectionPopup::AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons )
+ {
+   // 1. Create the backgrounds for the popup option both normal and pressed.
+   // Both containers will be added to a button.
+   Actor optionContainer = Actor::New();
+   optionContainer.SetDrawMode( DrawMode::OVERLAY );
+   //optionContainer.SetParentOrigin( ParentOrigin::CENTER );
+   optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+   ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
+   optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
+   //optionPressedContainer.SetParentOrigin( ParentOrigin::CENTER );
+   optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+   // 2. Add text.
+   Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
+   captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
+   optionContainer.Add( captionTextLabel );
+
+   Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
+   pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
+   optionPressedContainer.Add( pressedCaptionTextLabel );
+
+   // Calculates the icon/text position.
+   float iconTextOffsetY = 0.0f;
+
+   if ( showIcons )
+   {
+     // 3. Create the icons
+     ImageActor pressedIcon = ImageActor::New(  iconImage );
+     ImageActor icon = ImageActor::New(  iconImage );
+
+     optionContainer.Add( icon );
+     optionPressedContainer.Add( pressedIcon );
+
+     iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) );
+
+     icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
+     icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+     icon.SetY( iconTextOffsetY );
+
+     pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER );
+     pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+     pressedIcon.SetY( iconTextOffsetY );
+
+     // Layout icon + gap + text
+     captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+     pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+     pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+     captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+     pressedCaptionTextLabel.SetY( -iconTextOffsetY );
+     captionTextLabel.SetY( -iconTextOffsetY );
+   }
+   else
+   {
+     // Centre option text
+     captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+     captionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
+     pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
+     pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
+   }
+
+   // Calculate the size of the text.
+   Vector3 textSize = captionTextLabel.GetNaturalSize();
+   textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH );
+
+   // Set the size to the text. Text will be ellipsized if exceeds the max width.
+   captionTextLabel.SetSize( textSize );
+   pressedCaptionTextLabel.SetSize( textSize );
+
+   // 4. Calculate the size of option.
+
+   // The width is the max size of the text or the icon plus the margins clamped between the option min and max size.
+   // The height is the whole popup height minus the ninepatch margins.
+   const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ),
+                             DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w );
+
+   optionContainer.SetSize( optionSize );
+   optionPressedContainer.SetSize( optionSize );
+
+   // 5. Create a option.
+   Toolkit::PushButton option = Toolkit::PushButton::New();
+   option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
+   option.SetSize( optionSize );
+   option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+   option.SetX( mContentSize.width );
+   option.SetName( name );
+   option.SetAnimationTime( 0.0f );
+   //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
+
+   parent.Add( option );
+
+   // 6. Set the normal option image.
+   option.SetButtonImage( optionContainer );
+
+   // 7. Set the pressed option image
+   option.SetSelectedImage( optionPressedContainer );
+
+   // 8. Update the content size.
+   mContentSize.width += optionSize.width;
+   mContentSize.height = std::max ( optionSize.height, mContentSize.height );
+
+   // 9. Add the divider
+   if( !finalOption )
+   {
+     const Size size( POPUP_DIVIDER_WIDTH, mContentSize.height );
+
+     ImageActor divider =  Toolkit::CreateSolidColorActor( Color::WHITE );
+     divider.SetSize (size);
+     divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
+     divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+     divider.SetPosition( mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f );
+     parent.Add( divider );
+   }
+ }
+
+ void TextSelectionPopup::SetUpPopup( Size& size )
+ {
+   Actor self = Self();
+
+   // Create Layer and Stencil.
+   mStencilLayer = Layer::New();
+   ImageActor stencil = CreateSolidColorActor( Color::RED );
+   stencil.SetDrawMode( DrawMode::STENCIL );
+   stencil.SetVisible( true );
+   Actor scrollview = Actor::New(); //todo make a scrollview
+
+   //todo Use Size negotiation
+   //self.SetSize( size ); // control matches stencil size
+   self.SetSize( mRequiredPopUpSize ); // control matches stencil size
+   mStencilLayer.SetSize( size ); // matches stencil size
+   stencil.SetSize( size );
+   scrollview.SetSize( size );
+   mButtons.SetSize( size );
+
+   mStencilLayer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+   scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+   mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+   mStencilLayer.SetPosition( mNinePatchMargins.x,  mNinePatchMargins.y );
+
+   self.Add( mStencilLayer );
+   mStencilLayer.Add( stencil );
+   mStencilLayer.Add( scrollview );
+   scrollview.Add( mButtons );
+ }
+
+ void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons )
+ {
+   mShowIcons = showIcons;
+
+   mContentSize = Vector2::ZERO;
+
+   mButtons = Actor::New();
+
+   // Add the options into the buttons container.
+
+   // 1. Determine how many buttons are active and should be added to container.
+   std::size_t numberOfOptions = 0u;
+   for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
+   {
+     const ButtonRequirement& button( *it );
+     if( button.enabled )
+     {
+       ++numberOfOptions;
+     }
+   }
+
+   // 2. Iterate list of buttons and add active ones.
+   std::size_t optionsAdded = 0u;
+   for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
+   {
+     const ButtonRequirement& button( *it );
+     if ( button.enabled )
+     {
+       ++optionsAdded;
+       AddOption( mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mShowIcons );
+     }
+   }
+
+   // Calculate the size of the whole popup which may not be all visible.
+   mRequiredPopUpSize = Size( std::min( mMaxSize.width, mContentSize.width + mNinePatchMargins.x + mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE.height );
+
+   // Size of the contents within the popup
+   mVisiblePopUpSize = Size( mRequiredPopUpSize.width - mNinePatchMargins.x - mNinePatchMargins.y, mRequiredPopUpSize.height - mNinePatchMargins.z - mNinePatchMargins.w );
+ }
+
+ void TextSelectionPopup::CreatePopup()
+ {
+   if ( !mStencilLayer )
+   {
+     CreateOrderedListOfPopupOptions();  //todo Currently causes all options to be shown
+     CreateBackground();
+     AddPopupOptions( true, true );
+     SetUpPopup( mVisiblePopUpSize );
+   }
+
+   mStencilLayer.RaiseToTop();
+ }
+
+TextSelectionPopup::TextSelectionPopup()
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
+  mMaxSize ( DEFAULT_POPUP_MAX_SIZE ),
+  mVisiblePopUpSize( DEFAULT_POPUP_MAX_SIZE ),
+  mRequiredPopUpSize( DEFAULT_POPUP_MAX_SIZE ),
+  mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
+  mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
+  mLineColor( DEFAULT_POPUP_LINE_COLOR ),
+  mIconColor( DEFAULT_OPTION_ICON ),
+  mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
+  mTextColor( DEFAULT_OPTION_TEXT ),
+  mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
+  mSelectOptionPriority( 1 ),
+  mSelectAllOptionPriority ( 2 ),
+  mCutOptionPriority ( 3 ),
+  mCopyOptionPriority ( 4 ),
+  mPasteOptionPriority ( 5 ),
+  mClipboardOptionPriority( 6 ),
+  mShowIcons( true )
+{
+}
+
+TextSelectionPopup::~TextSelectionPopup()
+{
+}
+
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h
new file mode 100644 (file)
index 0000000..2650c57
--- /dev/null
@@ -0,0 +1,306 @@
+#ifndef __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
+#define __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
+
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-selection-popup.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/actors/layer.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+enum PopupParts
+{
+  POPUP_BACKGROUND,
+  POPUP_CLIPBOARD_BUTTON,
+  POPUP_CUT_BUTTON_ICON,
+  POPUP_COPY_BUTTON_ICON,
+  POPUP_PASTE_BUTTON_ICON,
+  POPUP_SELECT_BUTTON_ICON,
+  POPUP_SELECT_ALL_BUTTON_ICON,
+};
+
+} // namespace
+
+class TextSelectionPopup : public Control
+{
+public:
+
+  enum Buttons
+  {
+    ButtonsCut,
+    ButtonsCopy,
+    ButtonsPaste,
+    ButtonsSelect,
+    ButtonsSelectAll,
+    ButtonsClipboard,
+    ButtonsEnumEnd
+  };
+
+  struct ButtonRequirement
+  {
+    ButtonRequirement()
+    : id( ButtonsEnumEnd ),
+      priority( 0u ),
+      name(),
+      caption(),
+      icon(),
+      enabled( false )
+    {}
+
+    ButtonRequirement( Buttons buttonId,
+                       std::size_t buttonPriority,
+                       const std::string& buttonName,
+                       const std::string& buttonCaption,
+                       Dali::Image& buttonIcon,
+                       bool buttonEnabled )
+    : id( buttonId ),
+      priority( buttonPriority ),
+      name( buttonName ),
+      caption( buttonCaption ),
+      icon( buttonIcon ),
+      enabled( buttonEnabled )
+    {}
+
+    Buttons id;
+    std::size_t priority;
+    std::string name;
+    std::string caption;
+    Dali::Image icon;
+    bool enabled;
+  };
+
+  struct ButtonPriorityCompare
+  {
+      bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
+        return lhs.priority < rhs.priority;
+      }
+  };
+
+//  static inline bool ButtonPriorityCompare( ButtonRequirement a, ButtonRequirement b )
+//  {
+//    return a.priority < b.priority ? true : false;
+//  }
+
+  /**
+   * @copydoc Dali::Toollkit::TextSelectionPopup::New()
+   */
+  static Toolkit::TextSelectionPopup New();
+
+  // Properties
+
+  /**
+   * @brief Called when a property of an object of this type is set.
+   *
+   * @param[in] object The object whose property is set.
+   * @param[in] index The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+
+  /**
+   * @brief Called to retrieve a property of an object of this type.
+   *
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty( BaseObject* object, Property::Index index );
+
+  void CreatePopup();
+
+  void DestroyPopup();
+
+private: // From Control
+
+  /**
+   * @copydoc Control::OnInitialize()
+   */
+ virtual void OnInitialize();
+
+//  /**
+//   * @copydoc Control::GetNaturalSize()
+//   */
+//  virtual Vector3 GetNaturalSize();
+//
+//  /**
+//   * @copydoc Control::GetHeightForWidth()
+//   */
+//  virtual float GetHeightForWidth( float width );
+
+  /**
+   * @copydoc Control::OnInitialize()
+   */
+  virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
+//
+//  /**
+//   * Received for single & double taps
+//   */
+//  virtual void OnTap( const TapGesture& tap );
+//
+//  /**
+//   * @copydoc Text::ControlInterface::RequestTextRelayout()
+//   */
+//  virtual void RequestTextRelayout();
+
+  /**
+   * Set max size of Popup
+   * @param[in] maxSize Size (Vector2)
+   */
+  void SetPopupMaxSize( const Size& maxSize );
+
+  /**
+   * Get Max size of Popup
+   * @return Vector2 the max size of the Popup
+   */
+  const Dali::Vector2& GetPopupMaxSize() const;
+
+  /**
+   * @brief Sets the image for the given part of the Popup.
+   *
+   * @param[in] part  The part of the pop from the Enum PopupParts
+   * @param[in] image The image to use.
+   */
+ void SetPopupImage( PopupParts part, Dali::Image image );
+
+  /**
+   * @brief Retrieves the image of the given part used by the popup
+   *
+   * @param[in] part The part of the popup
+   * @return The image used for that part.
+   */
+  Dali::Image GetPopupImage( PopupParts part );
+
+  void CreateOrderedListOfPopupOptions();
+
+  void CreateBackground();
+
+  void AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons );
+
+  void SetUpPopup( Size& size );
+
+  void AddPopupOptions( bool createTail, bool showIcons );
+
+private: // Implementation
+
+  /**
+   * Construct a new TextField.
+   */
+  TextSelectionPopup();
+
+  /**
+   * A reference counted object may only be deleted by calling Unreference()
+   */
+  virtual ~TextSelectionPopup();
+
+private:
+
+  // Undefined copy constructor and assignment operators
+  TextSelectionPopup(const TextSelectionPopup&);
+  TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
+
+private: // Data
+
+  Actor mButtons;                                     // Actor which holds all the buttons, sensitivity can be set oActor buttons via this actor
+  Layer mStencilLayer;                                // Layer to enable clipping when buttons exceed popup
+
+  // Images to be used by the Popup
+  Image mBackgroundImage;
+  Image mCutIconImage;
+  Image mCopyIconImage;
+  Image mPasteIconImage;
+  Image mClipboardIconImage;
+  Image mSelectIconImage;
+  Image mSelectAllIconImage;
+
+  ImageActor mBackground;                             // The background popup panel
+  ImageActor mTail;                                   // The tail for the popup
+  ImageActor mTailEffect;   //todo remove                          // the tail effect
+  ImageActor mTailLine;     //todo remove                          // The border/outline around the tail
+
+  Size mMaxSize;                                      // Max size of the Popup
+  Size mVisiblePopUpSize;                             // Visible Size of popup excluding content that needs scrolling.
+  Size mRequiredPopUpSize;                            // Total size of popup including any invisible margin
+
+  Vector4 mNinePatchMargins;                          // Margins between the edge of the cropped image and the nine patch rect (left, right, top, bottom).
+
+  Size mContentSize;                                  // Size of Content (i.e. Buttons)
+  //Animation mAnimation;                               // Popup Hide/Show animation.
+
+  std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
+
+  Vector4 mBackgroundColor;             // Color of the background of the text input popup
+  Vector4 mBackgroundPressedColor;      // Color of the option background.
+  Vector4 mLineColor;                   // Color of the line around the text input popup
+  Vector4 mIconColor;                   // Color of the popup icon.
+  Vector4 mIconPressedColor;            // Color of the popup icon when pressed.
+  Vector4 mTextColor;                   // Color of the popup text.
+  Vector4 mTextPressedColor;            // Color of the popup text when pressed.
+
+  // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
+  std::size_t mSelectOptionPriority;    // Position of Select Button
+  std::size_t mSelectAllOptionPriority; // Position of Select All button
+  std::size_t mCutOptionPriority;       // Position of Cut button
+  std::size_t mCopyOptionPriority;      // Position of Copy button
+  std::size_t mPasteOptionPriority;     // Position of Paste button
+  std::size_t mClipboardOptionPriority; // Position of Clipboard button
+
+  bool mShowIcons; // Flag to show icons
+
+};
+
+} // namespace Internal
+
+// Helpers for public-api forwarding methods
+
+inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
+{
+  DALI_ASSERT_ALWAYS( textSelectionPopup );
+
+  Dali::RefObject& handle = textSelectionPopup.GetImplementation();
+
+  return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
+}
+
+inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
+{
+  DALI_ASSERT_ALWAYS( textSelectionPopup );
+
+  const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
+
+  return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
index 4a27e26..5c38d49 100644 (file)
@@ -63,6 +63,7 @@ toolkit_src_files = \
    $(toolkit_src_dir)/controls/table-view/table-view-impl.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-field-impl.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-label-impl.cpp \
+   $(toolkit_src_dir)/controls/text-controls/text-selection-popup-impl.cpp \
    $(toolkit_src_dir)/controls/tool-bar/tool-bar-impl.cpp \
    $(toolkit_src_dir)/controls/view/view-impl.cpp \
    $(toolkit_src_dir)/focus-manager/focus-manager-impl.cpp \
index 4cff454..3ec0aa1 100644 (file)
 #include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector4.h>
-#include <dali/public-api/images/nine-patch-image.h>
+//#include <dali/public-api/images/nine-patch-image.h>
 #include <dali/public-api/signals/connection-tracker.h>
-#include <libintl.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
-#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-selection-popup.h>
 
 #ifdef DEBUG_ENABLED
 #define DECORATOR_DEBUG
 #endif
 
-// todo Move this to adaptor??
-#define GET_LOCALE_TEXT(string) dgettext("elementary", string)
-
 // Local Data
 namespace
 {
@@ -66,100 +62,6 @@ const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
 const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
 const std::size_t MILLISECONDS = 1000;
 
-const std::string POPUP_BACKGROUND( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
-const std::string POPUP_BACKGROUND_EFFECT( DALI_IMAGE_DIR "popup_bubble_bg_ef.#.png" );
-const std::string POPUP_BACKGROUND_LINE( DALI_IMAGE_DIR "popup_bubble_bg_line.#.png" );
-
-const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
-const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
-const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) );
-const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
-const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
-const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
-const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
-
-const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
-const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
-const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
-const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
-const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
-const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
-
-const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 470.0f, 120.0f ); ///< The maximum size of the popup.
-
-const float OPTION_TEXT_LINE_HEIGHT( 32.0f );     ///< The line height of the text.
-const Dali::Vector2 OPTION_ICON_SIZE( 0.f, 0.f );       ///< The size of the icon.
-const float OPTION_GAP_ICON_TEXT( 6.f );          ///< The gap between the icon and the text
-const float OPTION_MARGIN_WIDTH( 10.f );          ///< The margin between the right or lefts edge and the text or icon.
-const float OPTION_MAX_WIDTH( DEFAULT_POPUP_MAX_SIZE.width / 6 ); ///< The maximum width of the option (currently set to the max)
-const float OPTION_MIN_WIDTH( 86.0f );           ///< The minimum width of the option.
-
-const float POPUP_DIVIDER_WIDTH( 1.f );        ///< The size of the divider.
-
-const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail.
-const float POPUP_TAIL_Y_OFFSET( 5.f );        ///< The y offset of the tail (when its position is on the bottom).
-const float POPUP_TAIL_TOP_Y_OFFSET( 3.f );    ///< The y offset of the tail (when its position is on the top).
-
-const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
-const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
-
-const char* const OPTION_SELECT_WORD = "option-select_word";                       // "Select Word" popup option.
-const char* const OPTION_SELECT_ALL("option-select_all");                          // "Select All" popup option.
-const char* const OPTION_CUT("option-cut");                                        // "Cut" popup option.
-const char* const OPTION_COPY("option-copy");                                      // "Copy" popup option.
-const char* const OPTION_PASTE("option-paste");                                    // "Paste" popup option.
-const char* const OPTION_CLIPBOARD("option-clipboard");                            // "Clipboard" popup option.
-
-enum Buttons
-{
-  ButtonsCut,
-  ButtonsCopy,
-  ButtonsPaste,
-  ButtonsSelect,
-  ButtonsSelectAll,
-  ButtonsClipboard,
-  ButtonsEnumEnd
-};
-
-struct ButtonRequirement
-{
-  ButtonRequirement()
-  : id( ButtonsEnumEnd ),
-    priority( 0u ),
-    name(),
-    caption(),
-    icon(),
-    enabled( false )
-  {}
-
-  ButtonRequirement( Buttons buttonId,
-                     std::size_t buttonPriority,
-                     const std::string& buttonName,
-                     const std::string& buttonCaption,
-                     Dali::ResourceImage buttonIcon,
-                     bool buttonEnabled )
-  : id( buttonId ),
-    priority( buttonPriority ),
-    name( buttonName ),
-    caption( buttonCaption ),
-    icon( buttonIcon ),
-    enabled( buttonEnabled )
-  {}
-
-  Buttons id;
-  std::size_t priority;
-  std::string name;
-  std::string caption;
-  Dali::ResourceImage icon;
-  bool enabled;
-};
-
-// Comparison function for ButtonRequirement Priority
-bool PriorityCompare( ButtonRequirement const& a, ButtonRequirement const& b)
-{
-  return a.priority < b.priority;
-}
-
 } // end of namespace
 
 namespace Dali
@@ -212,61 +114,6 @@ struct Decorator::Impl : public ConnectionTracker
     Image releasedImage;
   };
 
-  struct PopupImpl
-  {
-    PopupImpl()
-    : mVisiblePopUpSize( Vector2( 100.0f, 100.0f ) ),
-      mRequiredPopUpSize( Vector2( 100.0f, 100.0f ) ),
-      mMaxWidth( DEFAULT_POPUP_MAX_SIZE.width ),
-      mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
-      mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
-      mLineColor( DEFAULT_POPUP_LINE_COLOR ),
-      mIconColor( DEFAULT_OPTION_ICON ),
-      mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
-      mTextColor( DEFAULT_OPTION_TEXT ),
-      mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED )
-      {
-      }
-
-      Actor mRoot;                                        // The actor which all popup content is added to (i.e. panel and buttons)
-      Actor mButtons;                                     // Actor which holds all the buttons, sensitivity can be set oActor buttons via this actor
-      Layer mStencilLayer;                                // Layer to enable clipping when buttons exceed popup
-      ImageActor mBackground;                             // The background popup panel
-      ImageActor mTail;                                   // The tail for the popup
-      ImageActor mTailEffect;                             // the tail effect
-      ImageActor mTailLine;                               // The border/outline around the tail
-
-      Size mVisiblePopUpSize;                             // Visible Size of popup excluding content that needs scrolling.
-      Size mRequiredPopUpSize;                            // Total size of popup including any invisible margin
-      float mMaxWidth;                                    // Max width of the Popup
-
-      Vector4 mNinePatchMargins;                          // Margins between the edge of the cropped image and the nine patch rect (left, right, top, bottom).
-
-      Size mContentSize;                                  // Size of Content (i.e. Buttons)
-      //Animation mAnimation;                               // Popup Hide/Show animation.
-
-      std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
-
-      Vector4 mBackgroundColor;             // Color of the background of the text input popup
-      Vector4 mBackgroundPressedColor;      // Color of the option background.
-      Vector4 mLineColor;                   // Color of the line around the text input popup
-      Vector4 mIconColor;                   // Color of the popup icon.
-      Vector4 mIconPressedColor;            // Color of the popup icon when pressed.
-      Vector4 mTextColor;                   // Color of the popup text.
-      Vector4 mTextPressedColor;            // Color of the popup text when pressed.
-
-      // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
-      std::size_t mSelectOptionPriority;    // Position of Select Button
-      std::size_t mSelectAllOptionPriority; // Position of Select All button
-      std::size_t mCutOptionPriority;       // Position of Cut button
-      std::size_t mCopyOptionPriority;      // Position of Copy button
-      std::size_t mPasteOptionPriority;     // Position of Paste button
-      std::size_t mClipboardOptionPriority; // Position of Clipboard button
-
-      bool mShowIcons; // Flag to show icons
-  };
-
-
   Impl( Dali::Toolkit::Internal::Control& parent, Observer& observer )
   : mTextControlParent(parent),
     mObserver(observer),
@@ -347,12 +194,19 @@ struct Decorator::Impl : public ConnectionTracker
 
     if ( mActiveCopyPastePopup )
     {
-      CreatePopup();
-      mCopyPastePopup.mRoot.SetPosition( Vector3( 180.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle postions to be used
+      if ( !mCopyPastePopup )
+      {
+        mCopyPastePopup = TextSelectionPopup::New();
+        mActiveLayer.Add ( mCopyPastePopup );
+      }
+      mCopyPastePopup.SetPosition( Vector3( 200.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle positions to be used
     }
     else
     {
-      DestroyPopup();
+     if ( mCopyPastePopup )
+     {
+       UnparentAndReset( mCopyPastePopup );
+     }
     }
   }
 
@@ -607,290 +461,6 @@ struct Decorator::Impl : public ConnectionTracker
     return false;
   }
 
-  /**
-   * Popup
-   */
-
-  void CreateOrderedListOfPopupOptions()
-  {
-    mCopyPastePopup.mOrderListOfButtons.clear();
-
-    // Create button for each possible option using Option priority
-    ResourceImage cutIcon = ResourceImage::New( OPTION_ICON_CUT );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCopyPastePopup.mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, true ) );
-
-    ResourceImage copyIcon = ResourceImage::New( OPTION_ICON_COPY );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyPastePopup.mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, true ) );
-
-    ResourceImage pasteIcon = ResourceImage::New( OPTION_ICON_PASTE );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mCopyPastePopup.mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, true ) );
-
-    ResourceImage selectIcon = ResourceImage::New( OPTION_ICON_SELECT );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mCopyPastePopup.mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, true ) );
-
-    ResourceImage selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mCopyPastePopup.mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, true ) );
-
-    ResourceImage clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD );
-    mCopyPastePopup.mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mCopyPastePopup.mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, true ) );
-
-    // Sort the buttons according their priorities.
-    std::sort( mCopyPastePopup.mOrderListOfButtons.begin(), mCopyPastePopup.mOrderListOfButtons.end(), PriorityCompare );
-  }
-
-  void CreateBackground( PopupImpl& popup )
-  {
-    // Create background-panel if not already created (required if we have at least one option)
-    if ( !popup.mBackground )
-    {
-      ResourceImage bgImg = ResourceImage::New( POPUP_BACKGROUND );
-      popup.mBackground = ImageActor::New( bgImg );
-      popup.mBackground.SetColor( popup.mBackgroundColor );
-      popup.mBackground.SetParentOrigin( ParentOrigin::CENTER );
-
-      NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( bgImg );
-      if( backgroundImageNinePatch )
-      {
-        const Size ninePatchImageSize = Size( static_cast<float>( bgImg.GetWidth() ), static_cast<float>( bgImg.GetHeight() ) );
-        Rect<int> childRect = backgroundImageNinePatch.GetChildRectangle();
-
-        // -1u because of the cropping.
-        popup.mNinePatchMargins.x = childRect.x - 1u;
-        popup.mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u;
-        popup.mNinePatchMargins.z = childRect.y - 1u;
-        popup.mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u;
-      }
-
-      ResourceImage::Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT );
-      ImageActor backgroundEffect = ImageActor::New( bgEffectImg );
-      backgroundEffect.SetParentOrigin( ParentOrigin::CENTER );
-
-      ResourceImage::Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE );
-      ImageActor backgroundLine = ImageActor::New( bgLine );
-      backgroundLine.SetParentOrigin( ParentOrigin::CENTER );
-      backgroundLine.SetColor( popup.mLineColor );
-
-      popup.mBackground.Add( backgroundEffect );
-      popup.mBackground.Add( backgroundLine );
-    }
-  }
-
-  void AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons )
-  {
-    // 1. Create the backgrounds for the popup option both normal and pressed.
-    // Both containers will be added to a button.
-    Actor optionContainer = Actor::New();
-    optionContainer.SetDrawMode( DrawMode::OVERLAY );
-    //optionContainer.SetParentOrigin( ParentOrigin::CENTER );
-    optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
-    ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mCopyPastePopup.mBackgroundPressedColor );
-    optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
-    //optionPressedContainer.SetParentOrigin( ParentOrigin::CENTER );
-    optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
-    // 2. Add text.
-    Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
-    captionTextLabel.SetProperty( TextLabel::Property::TEXT, caption );
-    optionContainer.Add( captionTextLabel );
-
-    Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
-    pressedCaptionTextLabel.SetProperty( TextLabel::Property::TEXT, caption );
-    optionPressedContainer.Add( pressedCaptionTextLabel );
-
-    // Calculates the icon/text position.
-    float iconTextOffsetY = 0.0f;
-
-    if ( showIcons )
-    {
-      // 3. Create the icons
-      ImageActor pressedIcon = ImageActor::New(  iconImage );
-      ImageActor icon = ImageActor::New(  iconImage );
-
-      optionContainer.Add( icon );
-      optionPressedContainer.Add( pressedIcon );
-
-      iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) );
-
-      icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
-      icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-      icon.SetY( iconTextOffsetY );
-
-      pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER );
-      pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-      pressedIcon.SetY( iconTextOffsetY );
-
-      // Layout icon + gap + text
-      captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-      pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-      pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-      captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-      pressedCaptionTextLabel.SetY( -iconTextOffsetY );
-      captionTextLabel.SetY( -iconTextOffsetY );
-    }
-    else
-    {
-      // Centre option text
-      captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
-      captionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
-      pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
-      pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
-    }
-
-    // Calculate the size of the text.
-    Vector3 textSize = captionTextLabel.GetNaturalSize();
-    textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH );
-
-    // Set the size to the text. Text will be ellipsized if exceeds the max width.
-    captionTextLabel.SetSize( textSize );
-    pressedCaptionTextLabel.SetSize( textSize );
-
-    // 4. Calculate the size of option.
-
-    // The width is the max size of the text or the icon plus the margins clamped between the option min and max size.
-    // The height is the whole popup height minus the ninepatch margins.
-    const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ),
-                              DEFAULT_POPUP_MAX_SIZE.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w );
-
-    optionContainer.SetSize( optionSize );
-    optionPressedContainer.SetSize( optionSize );
-
-    // 5. Create a option.
-    Toolkit::PushButton option = Toolkit::PushButton::New();
-    option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
-    option.SetSize( optionSize );
-    option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    option.SetX( mCopyPastePopup.mContentSize.width );
-    option.SetName( name );
-    option.SetAnimationTime( 0.0f );
-    //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
-
-    parent.Add( option );
-
-    // 6. Set the normal option image.
-    option.SetButtonImage( optionContainer );
-
-    // 7. Set the pressed option image
-    option.SetSelectedImage( optionPressedContainer );
-
-    // 8. Update the content size.
-    mCopyPastePopup.mContentSize.width += optionSize.width;
-    mCopyPastePopup.mContentSize.height = std::max ( optionSize.height, mCopyPastePopup.mContentSize.height );
-
-    // 9. Add the divider
-    if( !finalOption )
-    {
-      const Size size( POPUP_DIVIDER_WIDTH, mCopyPastePopup.mContentSize.height );
-
-      ImageActor divider =  Toolkit::CreateSolidColorActor( Color::WHITE );
-      divider.SetSize (size);
-      divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
-      divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      divider.SetPosition( mCopyPastePopup.mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f );
-      parent.Add( divider );
-    }
-  }
-
-  void SetUpPopup( Actor& popupRootActor, Size& size )
-  {
-    // Create Layer and Stencil.
-    popupRootActor = Actor::New();
-    mCopyPastePopup.mStencilLayer = Layer::New();
-    ImageActor stencil = CreateSolidColorActor( Color::RED );
-    stencil.SetDrawMode( DrawMode::STENCIL );
-    stencil.SetVisible( true );
-    Actor scrollview = Actor::New();
-
-    //todo Use Size negotiation
-    mCopyPastePopup.mStencilLayer.SetSize( size ); // matches stencil size
-    popupRootActor.SetSize( size ); // matches stencil size
-    stencil.SetSize( size );
-    scrollview.SetSize( size );
-    mCopyPastePopup.mButtons.SetSize( size );
-
-    mCopyPastePopup.mStencilLayer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
-    scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT);
-    mCopyPastePopup.mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
-    mActiveLayer.Add( mCopyPastePopup.mRoot );
-    popupRootActor.Add( mCopyPastePopup.mBackground );
-    popupRootActor.Add( mCopyPastePopup.mStencilLayer );
-    mCopyPastePopup.mStencilLayer.Add( stencil );
-    mCopyPastePopup.mStencilLayer.Add( scrollview );
-    scrollview.Add( mCopyPastePopup.mButtons );
-  }
-
-  void AddPopupOptions( bool createTail, bool showIcons )
-  {
-    mCopyPastePopup.mShowIcons = showIcons;
-
-    mCopyPastePopup.mContentSize = Vector2::ZERO;
-
-    mCopyPastePopup.mButtons = Actor::New();
-
-    // Add the options into the buttons container.
-
-    // 1. Determine how many buttons are active and should be added to container.
-    std::size_t numberOfOptions = 0u;
-    for( std::vector<ButtonRequirement>::const_iterator it = mCopyPastePopup.mOrderListOfButtons.begin(), endIt = mCopyPastePopup.mOrderListOfButtons.end(); ( it != endIt ); ++it )
-    {
-      const ButtonRequirement& button( *it );
-      if( button.enabled )
-      {
-        ++numberOfOptions;
-      }
-    }
-
-    // 2. Iterate list of buttons and add active ones.
-    std::size_t optionsAdded = 0u;
-    for( std::vector<ButtonRequirement>::const_iterator it = mCopyPastePopup.mOrderListOfButtons.begin(), endIt = mCopyPastePopup.mOrderListOfButtons.end(); ( it != endIt ); ++it )
-    {
-      const ButtonRequirement& button( *it );
-      if ( button.enabled )
-      {
-        ++optionsAdded;
-        AddOption( mCopyPastePopup.mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mCopyPastePopup.mShowIcons );
-      }
-    }
-
-    // Calculate the size of the whole popup which may not be all visible.
-    mCopyPastePopup.mRequiredPopUpSize = Size( std::min( mCopyPastePopup.mMaxWidth, mCopyPastePopup.mContentSize.width + mCopyPastePopup.mNinePatchMargins.x + mCopyPastePopup.mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE. height );
-
-    // Set the size of the background, background line and background effect.
-    mCopyPastePopup.mBackground.SetSize( mCopyPastePopup.mRequiredPopUpSize);
-    for( std::size_t index = 0u, childCount = mCopyPastePopup.mBackground.GetChildCount(); index < childCount; ++index )
-    {
-      mCopyPastePopup.mBackground.GetChildAt( index ).SetSize( mCopyPastePopup.mRequiredPopUpSize );
-    }
-
-    // Size of the contents within the popup
-    mCopyPastePopup.mVisiblePopUpSize = Size( mCopyPastePopup.mRequiredPopUpSize.width - mCopyPastePopup.mNinePatchMargins.x - mCopyPastePopup.mNinePatchMargins.y, mCopyPastePopup.mRequiredPopUpSize.height - mCopyPastePopup.mNinePatchMargins.z - mCopyPastePopup.mNinePatchMargins.w );
-
-  }
-
-  void CreatePopup()
-  {
-    if ( !mCopyPastePopup.mRoot )
-    {
-      mActiveCopyPastePopup = true;
-      CreateOrderedListOfPopupOptions();  //todo Currently causes all options to be shown
-      CreateBackground( mCopyPastePopup );
-      AddPopupOptions( true, true );
-      SetUpPopup( mCopyPastePopup.mRoot, mCopyPastePopup.mVisiblePopUpSize );
-    }
-
-    mCopyPastePopup.mStencilLayer.RaiseToTop();
-  }
-
-  void DestroyPopup()
-  {
-    if ( mCopyPastePopup.mRoot )
-    {
-      mActiveCopyPastePopup = false;
-      UnparentAndReset( mCopyPastePopup.mButtons );
-      UnparentAndReset( mCopyPastePopup.mRoot );
-    }
-  }
 
   Internal::Control& mTextControlParent;
   Observer& mObserver;
@@ -919,7 +489,7 @@ struct Decorator::Impl : public ConnectionTracker
 
   SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
 
-  PopupImpl mCopyPastePopup;
+  TextSelectionPopup mCopyPastePopup;
 
   Image mCursorImage;
   Image mGrabHandleImage;
@@ -1102,20 +672,14 @@ Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState st
   return mImpl->mSelectionHandle[handle].releasedImage;
 }
 
-void Decorator::ShowPopup()
+void Decorator::SetPopupActive( bool active )
 {
-  if ( !mImpl->mCopyPastePopup.mRoot )
-  {
-    mImpl->CreatePopup();
-  }
+  mImpl->mActiveCopyPastePopup = active;
 }
 
-void Decorator::HidePopup()
+bool Decorator::IsPopupActive() const
 {
-  if ( mImpl->mCopyPastePopup.mRoot )
-  {
-    mImpl->DestroyPopup();
-  }
+  return mImpl->mActiveCopyPastePopup ;
 }
 
 Decorator::~Decorator()
index 9ea86c6..b7b793f 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/public-api/common/intrusive-ptr.h>
 #include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/math/rect.h>
+#include <dali/public-api/math/vector2.h>
 
 namespace Dali
 {
@@ -341,14 +342,18 @@ public:
   Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
 
   /**
-   * @brief Show the Copy and Paste Popup
+   * @brief Set the Selection Popup to show or hide via the active flaf
+   * @param[in] active true to show, false to hide
    */
-  void ShowPopup();
+  void SetPopupActive( bool active );
 
   /**
-   * @brief Hide the Copy and Paste Popup
+   * @brief Query whether the Selection Popup is active.
+   *
+   * @return True if the Selection Popup should be active.
    */
-  void HidePopup();
+  bool IsPopupActive() const;
+
 
 protected:
 
index 04093a4..e3c9ca3 100644 (file)
@@ -109,7 +109,8 @@ struct Controller::TextInput
   {
     INACTIVE,
     SELECTING,
-    EDITING
+    EDITING,
+    EDITING_WITH_POPUP
   };
 
   TextInput( LogicalModelPtr logicalModel,
@@ -123,8 +124,8 @@ struct Controller::TextInput
     mSecondaryCursorPosition( 0u ),
     mDecoratorUpdated( false ),
     mCursorBlinkEnabled( true ),
-    mGrabHandleEnabled( false ),
-    mGrabHandlePopupEnabled( false ),
+    mGrabHandleEnabled( true ),
+    mGrabHandlePopupEnabled( true ),
     mSelectionEnabled( false ),
     mHorizontalScrollingEnabled( true ),
     mVerticalScrollingEnabled( false ),
@@ -323,13 +324,16 @@ struct Controller::TextInput
       GetClosestCursorPosition( mPrimaryCursorPosition, xPosition, yPosition, height );
 
       mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height );
-      mDecorator->HidePopup();
+      //mDecorator->HidePopup();
+      ChangeState ( EDITING );
       mDecoratorUpdated = true;
     }
     else if ( mGrabHandlePopupEnabled &&
               GRAB_HANDLE_RELEASED == state )
     {
-      mDecorator->ShowPopup();
+      //mDecorator->ShowPopup();
+      ChangeState ( EDITING_WITH_POPUP );
+      mDecoratorUpdated = true;
     }
   }
 
@@ -345,7 +349,7 @@ struct Controller::TextInput
         mDecorator->StopCursorBlink();
         mDecorator->SetGrabHandleActive( false );
         mDecorator->SetSelectionActive( false );
-        mDecorator->HidePopup();
+        mDecorator->SetPopupActive( false );
         mDecoratorUpdated = true;
       }
       else if ( SELECTING == mState )
@@ -367,6 +371,28 @@ struct Controller::TextInput
         {
           mDecorator->SetGrabHandleActive( true );
         }
+        if( mGrabHandlePopupEnabled )
+        {
+          mDecorator->SetPopupActive( false );
+        }
+        mDecorator->SetSelectionActive( false );
+        mDecoratorUpdated = true;
+      }
+      else if( EDITING_WITH_POPUP == mState )
+      {
+        mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+        if( mCursorBlinkEnabled )
+        {
+          mDecorator->StartCursorBlink();
+        }
+        if( mGrabHandleEnabled )
+        {
+          mDecorator->SetGrabHandleActive( true );
+        }
+        if( mGrabHandlePopupEnabled )
+        {
+          mDecorator->SetPopupActive( true );
+        }
         mDecorator->SetSelectionActive( false );
         mDecoratorUpdated = true;
       }
@@ -1582,6 +1608,8 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
       mImpl->mModifyEvents.push_back( event );
     }
 
+    mImpl->mTextInput->ChangeState( TextInput::EDITING ); // todo Confirm this is the best place to change the state of
+
     RequestRelayout();
   }
 
diff --git a/dali-toolkit/public-api/controls/text-controls/text-selection-popup.cpp b/dali-toolkit/public-api/controls/text-controls/text-selection-popup.cpp
new file mode 100644 (file)
index 0000000..4c55375
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/public-api/controls/text-controls/text-selection-popup.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
+
+using namespace Dali;
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+TextSelectionPopup TextSelectionPopup::New()
+{
+  return Internal::TextSelectionPopup::New();
+}
+
+TextSelectionPopup::TextSelectionPopup()
+{
+}
+
+TextSelectionPopup::TextSelectionPopup( const TextSelectionPopup& handle )
+: Control( handle )
+{
+}
+
+TextSelectionPopup& TextSelectionPopup::operator=( const TextSelectionPopup& handle )
+{
+  if( &handle != this )
+  {
+    Control::operator=( handle );
+  }
+  return *this;
+}
+
+TextSelectionPopup::~TextSelectionPopup()
+{
+}
+
+TextSelectionPopup TextSelectionPopup::DownCast( BaseHandle handle )
+{
+  return Control::DownCast<TextSelectionPopup, Internal::TextSelectionPopup>(handle);
+}
+
+TextSelectionPopup::TextSelectionPopup( Internal::TextSelectionPopup& implementation )
+: Control(implementation)
+{
+}
+
+TextSelectionPopup::TextSelectionPopup( Dali::Internal::CustomActor* internal )
+: Control( internal )
+{
+  VerifyCustomActorPointer<Internal::TextSelectionPopup>( internal );
+}
+
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/public-api/controls/text-controls/text-selection-popup.h b/dali-toolkit/public-api/controls/text-controls/text-selection-popup.h
new file mode 100644 (file)
index 0000000..2243f2d
--- /dev/null
@@ -0,0 +1,143 @@
+#ifndef __DALI_TOOLKIT_TEXT_SELECTION_POPUP_H__
+#define __DALI_TOOLKIT_TEXT_SELECTION_POPUP_H__
+
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/control.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal DALI_INTERNAL
+{
+class TextSelectionPopup;
+}
+
+/**
+ * @brief A control which provides a Popup with a number of buttons
+ *
+ * The style of the pop can be set through style sheets, this includes the images for the buttons
+ * A Show and Hide API is provided.
+ *
+ * If the buttons exceed the size constraints of the popup then it will offer scrolling.
+ *
+ *
+ */
+class DALI_IMPORT_API TextSelectionPopup : public Control
+{
+public:
+
+  /**
+   * @brief The start and end property ranges for this control.
+   */
+  enum PropertyRange
+  {
+    PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
+    PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices
+  };
+
+  /**
+   * @brief An enumeration of properties belonging to the TextLabel class.
+   */
+  struct Property
+  {
+    enum
+    {
+
+      POPUP_MAX_SIZE,                           ///< name "popup-max-size",                The max size the Popup can be,                  type VECTOR2
+      POPUP_BACKGROUND_IMAGE,                   ///< name "popup-background-image",        The image to display for popup background       type STRING
+      POPUP_CLIPBOARD_BUTTON_ICON_IMAGE,        ///< name "popup-clipboard-button-image",  The image to use as the popup clipboard icon,   type STRING
+      POPUP_CUT_BUTTON_ICON_IMAGE,              ///< name "popup-cut-button-image",        The image to use as the popup cut icon,         type STRING
+      POPUP_COPY_BUTTON_ICON_IMAGE,             ///< name "popup-copy-button-image",       The image to use as the popup copy icon,        type STRING
+      POPUP_PASTE_BUTTON_ICON_IMAGE,            ///< name "popup-paste-button-image",      The image to use as the popup paste icon,       type STRING
+      POPUP_SELECT_BUTTON_ICON_IMAGE,           ///< name "popup-select-button-image",     The image to use as the popup select icon,      type STRING
+      POPUP_SELECT_ALL_BUTTON_ICON_IMAGE,       ///< name "popup-select-all-button-image", The image to use as the popup select all icon,  type STRING
+    };
+  };
+
+  /**
+   * Create the TextSelectionPopup control.
+   * @return A handle to the TextSelectionPopup control.
+   */
+  static TextSelectionPopup New();
+
+  /**
+   * @brief Creates an empty handle.
+   */
+  TextSelectionPopup();
+
+  /**
+   * @brief Copy constructor.
+   *
+   * @param[in] handle The handle to copy from.
+   */
+  TextSelectionPopup( const TextSelectionPopup& handle );
+
+  /**
+   * @brief Assignment operator.
+   *
+   * @param[in] handle The handle to copy from.
+   * @return A reference to this.
+   */
+  TextSelectionPopup& operator=( const TextSelectionPopup& handle );
+
+  /**
+   * @brief Destructor
+   *
+   * This is non-virtual since derived Handle types must not contain data or virtual methods.
+   */
+  ~TextSelectionPopup();
+
+  /**
+   * @brief Downcast a handle to TextSelectionPopup.
+   *
+   * If the BaseHandle points is a TextSelectionPopup the downcast returns a valid handle.
+   * If not the returned handle is left empty.
+   *
+   * @param[in] handle Handle to an object
+   * @return handle to a TextSelectionPopup or an empty handle
+   */
+  static TextSelectionPopup DownCast( BaseHandle handle );
+
+public: // Not intended for application developers
+
+  /**
+   * @brief Creates a handle using the Toolkit::Internal implementation.
+   *
+   * @param[in] implementation The Control implementation.
+   */
+  DALI_INTERNAL TextSelectionPopup( Internal::TextSelectionPopup& implementation );
+
+  /**
+   * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
+   *
+   * @param[in]  internal  A pointer to the internal CustomActor.
+   */
+  explicit DALI_INTERNAL TextSelectionPopup( Dali::Internal::CustomActor* internal );
+
+}; // Class TextSelectionPopup
+
+} // namespace Toolkit
+
+} // namepsace Dali
+
+#endif // __DALI_TOOLKIT_TEXT_SELECTION_POPUP_H__
index cf45789..41c390a 100755 (executable)
@@ -50,6 +50,7 @@ public_api_src_files = \
   $(public_api_src_dir)/controls/table-view/table-view.cpp \
   $(public_api_src_dir)/controls/text-controls/text-label.cpp \
   $(public_api_src_dir)/controls/text-controls/text-field.cpp \
+  $(public_api_src_dir)/controls/text-controls/text-selection-popup.cpp \
   $(public_api_src_dir)/controls/tool-bar/tool-bar.cpp \
   $(public_api_src_dir)/controls/bloom-view/bloom-view.cpp \
   $(public_api_src_dir)/controls/cluster/cluster-style.cpp \
@@ -204,7 +205,8 @@ public_api_table_view_header_files = \
 
 public_api_text_controls_header_files = \
   $(public_api_src_dir)/controls/text-controls/text-label.h \
-  $(public_api_src_dir)/controls/text-controls/text-field.h
+  $(public_api_src_dir)/controls/text-controls/text-field.h \
+  $(public_api_src_dir)/controls/text-controls/text-selection-popup.h
 
 public_api_tool_bar_header_files = \
   $(public_api_src_dir)/controls/tool-bar/tool-bar.h