2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/object/property-map.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
37 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
38 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
39 #include <dali-toolkit/internal/helpers/color-conversion.h>
40 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
54 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
56 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
57 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
59 #if defined(DEBUG_ENABLED)
60 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
63 #ifdef DGETTEXT_ENABLED
65 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
66 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
67 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
68 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
69 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
70 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
74 #define POPUP_CUT_STRING "Cut"
75 #define POPUP_COPY_STRING "Copy"
76 #define POPUP_PASTE_STRING "Paste"
77 #define POPUP_SELECT_STRING "Select"
78 #define POPUP_SELECT_ALL_STRING "Select All"
79 #define POPUP_CLIPBOARD_STRING "Clipboard"
83 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
84 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
85 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
86 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
87 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
88 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
92 return Toolkit::TextSelectionPopup::New( NULL );
95 // Setup properties, signals and actions using the type-registry.
97 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
118 DALI_TYPE_REGISTRATION_END()
123 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
125 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
127 // Create the implementation, temporarily owned by this handle on stack
128 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
130 // Pass ownership to CustomActor handle
131 Dali::Toolkit::TextSelectionPopup handle( *impl );
133 // Second-phase init of the implementation
134 // This can only be done after the CustomActor connection has been made...
140 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
142 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
146 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
150 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
152 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
155 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
157 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
160 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
162 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
165 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
167 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
170 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
172 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
173 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
176 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
178 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
179 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
182 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
184 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
185 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
188 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
190 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
191 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
194 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
196 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
197 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
200 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
202 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
203 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
206 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
208 impl.mDividerColor = value.Get< Vector4 >();
211 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
213 impl.mIconColor = value.Get< Vector4 >();
216 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
218 impl.mPressedColor = value.Get< Vector4 >();
221 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
223 impl.SetPressedImage( value.Get< std::string >() );
226 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
228 impl.mFadeInDuration = value.Get < float >();
231 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
233 impl.mFadeOutDuration = value.Get < float >();
236 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
238 Property::Map map = value.Get<Property::Map>();
239 impl.CreateBackgroundBorder( map );
243 } // TextSelectionPopup
246 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
248 Property::Value value;
250 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
254 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
258 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
260 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
263 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
265 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
268 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
270 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
273 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
275 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
278 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
280 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
283 value = image.GetUrl();
287 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
289 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
292 value = image.GetUrl();
296 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
298 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
301 value = image.GetUrl();
305 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
307 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
310 value = image.GetUrl();
314 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
316 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
319 value = image.GetUrl();
323 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
325 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
328 value = image.GetUrl();
332 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
334 value = impl.GetPressedImage();
337 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
339 value = impl.mFadeInDuration;
342 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
344 value = impl.mFadeOutDuration;
347 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
350 Toolkit::Visual::Base visual = impl.GetVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
353 visual.CreatePropertyMap( map );
363 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
365 mEnabledButtons = buttonsToEnable;
366 mButtonsChanged = true;
369 void TextSelectionPopup::RaiseAbove( Layer target )
373 mToolbar.RaiseAbove( target );
377 void TextSelectionPopup::ShowPopup()
379 if( ( !mPopupShowing || mButtonsChanged ) &&
380 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
383 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
385 Animation animation = Animation::New( mFadeInDuration );
386 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
388 mPopupShowing = true;
392 void TextSelectionPopup::HidePopup()
396 mPopupShowing = false;
398 Animation animation = Animation::New( mFadeOutDuration );
399 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
400 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
405 void TextSelectionPopup::OnInitialize()
407 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
409 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
410 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
412 // The Popup Control background is a nine-patch image. We clip against this so the
413 // contents are correctly clipped against the edges of the nine-patch.
414 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
417 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
420 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
422 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
423 UnparentAndReset( mToolbar );
427 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
429 if( mCallbackInterface )
431 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
437 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
439 if( mCallbackInterface )
441 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
447 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
449 if( mCallbackInterface )
451 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
457 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
459 if( mCallbackInterface )
461 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
467 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
469 if( mCallbackInterface )
471 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
477 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
479 if( mCallbackInterface )
481 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
487 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
489 switch( settingToCustomise )
491 case POPUP_MAXIMUM_SIZE :
493 mPopupMaxSize = dimension;
496 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
500 case OPTION_MAXIMUM_SIZE :
502 mOptionMaxSize = dimension;
503 // Option max size not currently currently supported
506 case OPTION_MINIMUM_SIZE :
508 mOptionMinSize = dimension;
509 // Option min size not currently currently supported
512 case OPTION_DIVIDER_SIZE :
514 mOptionDividerSize = dimension;
517 // Resize Dividers not currently supported
524 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
526 switch( settingToCustomise )
528 case POPUP_MAXIMUM_SIZE :
532 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
536 return mPopupMaxSize;
539 case OPTION_MAXIMUM_SIZE :
541 return mOptionMaxSize;
543 case OPTION_MINIMUM_SIZE :
545 return mOptionMinSize;
547 case OPTION_DIVIDER_SIZE :
549 return mOptionDividerSize;
556 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
561 case Toolkit::TextSelectionPopup::CLIPBOARD:
563 mClipboardIconImage = image;
566 case Toolkit::TextSelectionPopup::CUT :
568 mCutIconImage = image;
571 case Toolkit::TextSelectionPopup::COPY :
573 mCopyIconImage = image;
576 case Toolkit::TextSelectionPopup::PASTE :
578 mPasteIconImage = image;
581 case Toolkit::TextSelectionPopup::SELECT :
583 mSelectIconImage = image;
586 case Toolkit::TextSelectionPopup::SELECT_ALL :
588 mSelectAllIconImage = image;
593 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
598 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
602 case Toolkit::TextSelectionPopup::CLIPBOARD :
604 return mClipboardIconImage;
607 case Toolkit::TextSelectionPopup::CUT :
609 return mCutIconImage;
612 case Toolkit::TextSelectionPopup::COPY :
614 return mCopyIconImage;
617 case Toolkit::TextSelectionPopup::PASTE :
619 return mPasteIconImage;
622 case Toolkit::TextSelectionPopup::SELECT :
624 return mSelectIconImage;
627 case Toolkit::TextSelectionPopup::SELECT_ALL :
629 return mSelectAllIconImage;
634 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
638 return Dali::Image();
641 void TextSelectionPopup::SetPressedImage( const std::string& filename )
643 mPressedImage = filename;
646 std::string TextSelectionPopup::GetPressedImage() const
648 return mPressedImage;
651 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
653 mOrderListOfButtons.clear();
654 mOrderListOfButtons.reserve( 8u );
656 // Create button for each possible option using Option priority
657 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
658 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
659 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
660 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
661 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
662 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
664 // Sort the buttons according their priorities.
665 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
668 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
670 // 1. Create a option.
671 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
673 Toolkit::PushButton option = Toolkit::PushButton::New();
674 option.SetName( button.name );
675 option.SetAnimationTime( 0.0f );
676 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
680 case Toolkit::TextSelectionPopup::CUT:
682 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
685 case Toolkit::TextSelectionPopup::COPY:
687 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
690 case Toolkit::TextSelectionPopup::PASTE:
692 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
695 case Toolkit::TextSelectionPopup::SELECT:
697 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
700 case Toolkit::TextSelectionPopup::SELECT_ALL:
702 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
705 case Toolkit::TextSelectionPopup::CLIPBOARD:
707 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
710 case Toolkit::TextSelectionPopup::NONE:
717 // 2. Set the options contents.
720 // PushButton layout properties.
721 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
724 Property::Map buttonLabelProperties;
725 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
726 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
730 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
731 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
733 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
734 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
735 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
738 // 3. Set the normal option image (blank / Transparent).
739 option.SetUnselectedImage( "" );
741 // 4. Set the pressed option image.
742 // The image can be blank, the color can be used regardless.
743 option.SetSelectedImage( mPressedImage );
744 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
745 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
747 // 5 Add option to tool bar
748 mToolbar.AddOption( option );
750 // 6. Add the divider
753 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
755 Toolkit::Control divider = Toolkit::Control::New();
756 #ifdef DECORATOR_DEBUG
757 divider.SetName("Text's popup divider");
759 divider.SetSize( size );
760 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
761 divider.SetBackgroundColor( mDividerColor );
762 mToolbar.AddDivider( divider );
766 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
768 std::size_t numberOfOptions = 0u;
769 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
771 const ButtonRequirement& button( *it );
778 return numberOfOptions;
781 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
783 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
785 CreateOrderedListOfPopupOptions();
787 mButtonsChanged = false;
788 UnparentAndReset( mToolbar);
793 mToolbar = Toolkit::TextSelectionToolbar::New();
794 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
796 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
798 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
799 #ifdef DECORATOR_DEBUG
800 mToolbar.SetName("TextSelectionToolbar");
802 self.Add( mToolbar );
805 // Iterate list of buttons and add active ones to Toolbar
806 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
807 std::size_t numberOfOptionsAdded = 0u;
808 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
810 const ButtonRequirement& button( *it );
811 if ( button.enabled )
813 numberOfOptionsAdded++;
814 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
819 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
821 // Removes previous image if necessary
822 UnregisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
824 if( ! propertyMap.Empty() )
826 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
830 RegisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual );
831 visual.SetDepthIndex( DepthIndex::CONTENT );
836 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
837 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
842 mOptionDividerSize(),
843 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
844 mCallbackInterface( callbackInterface ),
845 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
846 mDividerColor( Color::WHITE ),
847 mIconColor( Color::WHITE ),
848 mSelectOptionPriority( 1 ),
849 mSelectAllOptionPriority ( 2 ),
850 mCutOptionPriority ( 4 ),
851 mCopyOptionPriority ( 3 ),
852 mPasteOptionPriority ( 5 ),
853 mClipboardOptionPriority( 6 ),
854 mFadeInDuration(0.0f),
855 mFadeOutDuration(0.0f),
857 mShowCaptions( true ),
858 mPopupShowing( false ),
859 mButtonsChanged( false )
863 TextSelectionPopup::~TextSelectionPopup()
868 } // namespace Internal
870 } // namespace Toolkit