2 * Copyright (c) 2020 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>
22 #if defined(__GLIBC__)
27 #include <dali/public-api/animation/animation.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/math/vector4.h>
30 #include <dali/public-api/object/property-map.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
38 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
40 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
41 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
42 #include <dali-toolkit/public-api/visuals/visual-properties.h>
43 #include <dali-toolkit/internal/helpers/color-conversion.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
45 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
58 #if defined(__GLIBC__)
59 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
62 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
63 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
69 #ifdef DGETTEXT_ENABLED
71 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
72 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
73 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
74 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
75 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
76 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
80 #define POPUP_CUT_STRING "Cut"
81 #define POPUP_COPY_STRING "Copy"
82 #define POPUP_PASTE_STRING "Paste"
83 #define POPUP_SELECT_STRING "Select"
84 #define POPUP_SELECT_ALL_STRING "Select All"
85 #define POPUP_CLIPBOARD_STRING "Clipboard"
89 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
90 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
91 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
92 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
93 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
94 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
96 const std::string IDS_LTR( "IDS_LTR" );
97 const std::string RTL_DIRECTION( "RTL" );
101 return Toolkit::TextSelectionPopup::New( NULL );
104 // Setup properties, signals and actions using the type-registry.
106 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
127 DALI_TYPE_REGISTRATION_END()
132 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
134 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
136 // Create the implementation, temporarily owned by this handle on stack
137 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
139 // Pass ownership to CustomActor handle
140 Dali::Toolkit::TextSelectionPopup handle( *impl );
142 // Second-phase init of the implementation
143 // This can only be done after the CustomActor connection has been made...
149 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
151 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
155 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
159 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
161 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
164 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
166 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
169 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
171 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
174 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
176 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
179 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
181 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, value.Get< std::string >() );
184 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
186 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, value.Get< std::string >() );
189 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
191 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, value.Get< std::string >() );
194 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
196 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, value.Get< std::string >() );
199 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
201 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, value.Get< std::string >() );
204 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
206 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, value.Get< std::string >() );
209 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
211 impl.mDividerColor = value.Get< Vector4 >();
214 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
216 impl.mIconColor = value.Get< Vector4 >();
219 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
221 impl.mPressedColor = value.Get< Vector4 >();
224 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
226 impl.SetPressedImage( value.Get< std::string >() );
229 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
231 impl.mFadeInDuration = value.Get < float >();
234 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
236 impl.mFadeOutDuration = value.Get < float >();
239 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
241 Property::Map map = value.Get<Property::Map>();
242 impl.CreateBackgroundBorder( map );
246 } // TextSelectionPopup
249 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
251 Property::Value value;
253 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
257 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
261 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
263 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
266 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
268 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
271 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
273 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
276 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
278 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
281 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
283 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD );
286 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
288 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT );
291 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
293 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY );
296 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
298 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE );
301 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
303 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT );
306 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
308 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL );
311 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
313 value = impl.GetPressedImage();
316 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
318 value = impl.mFadeInDuration;
321 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
323 value = impl.mFadeOutDuration;
326 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
329 Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
332 visual.CreatePropertyMap( map );
342 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
344 mEnabledButtons = buttonsToEnable;
345 mButtonsChanged = true;
348 void TextSelectionPopup::RaiseAbove( Actor target )
352 mToolbar.RaiseAbove( target );
356 void TextSelectionPopup::ShowPopup()
358 if( ( !mPopupShowing || mButtonsChanged ) &&
359 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
362 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
364 Animation animation = Animation::New( mFadeInDuration );
365 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
367 mPopupShowing = true;
371 void TextSelectionPopup::HidePopup()
375 mPopupShowing = false;
377 Animation animation = Animation::New( mFadeOutDuration );
378 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
379 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
384 void TextSelectionPopup::OnInitialize()
386 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
388 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
389 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
392 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
395 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
397 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
398 UnparentAndReset( mToolbar );
402 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
404 if( mCallbackInterface )
406 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
412 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
414 if( mCallbackInterface )
416 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
422 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
424 if( mCallbackInterface )
426 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
432 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
434 if( mCallbackInterface )
436 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
442 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
444 if( mCallbackInterface )
446 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
452 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
454 if( mCallbackInterface )
456 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
462 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
464 switch( settingToCustomise )
466 case POPUP_MAXIMUM_SIZE :
468 mPopupMaxSize = dimension;
471 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
475 case OPTION_MAXIMUM_SIZE :
477 mOptionMaxSize = dimension;
478 // Option max size not currently currently supported
481 case OPTION_MINIMUM_SIZE :
483 mOptionMinSize = dimension;
484 // Option min size not currently currently supported
487 case OPTION_DIVIDER_SIZE :
489 mOptionDividerSize = dimension;
492 // Resize Dividers not currently supported
499 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise ) const
501 switch( settingToCustomise )
503 case POPUP_MAXIMUM_SIZE :
507 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
511 return mPopupMaxSize;
514 case OPTION_MAXIMUM_SIZE :
516 return mOptionMaxSize;
518 case OPTION_MINIMUM_SIZE :
520 return mOptionMinSize;
522 case OPTION_DIVIDER_SIZE :
524 return mOptionDividerSize;
531 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, const std::string& image )
535 case Toolkit::TextSelectionPopup::CLIPBOARD:
537 mClipboardIconImage = image;
540 case Toolkit::TextSelectionPopup::CUT :
542 mCutIconImage = image;
545 case Toolkit::TextSelectionPopup::COPY :
547 mCopyIconImage = image;
550 case Toolkit::TextSelectionPopup::PASTE :
552 mPasteIconImage = image;
555 case Toolkit::TextSelectionPopup::SELECT :
557 mSelectIconImage = image;
560 case Toolkit::TextSelectionPopup::SELECT_ALL :
562 mSelectAllIconImage = image;
567 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
572 const std::string& TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button ) const
576 case Toolkit::TextSelectionPopup::CLIPBOARD:
578 return mClipboardIconImage;
581 case Toolkit::TextSelectionPopup::CUT:
583 return mCutIconImage;
586 case Toolkit::TextSelectionPopup::COPY:
588 return mCopyIconImage;
591 case Toolkit::TextSelectionPopup::PASTE:
593 return mPasteIconImage;
596 case Toolkit::TextSelectionPopup::SELECT:
598 return mSelectIconImage;
601 case Toolkit::TextSelectionPopup::SELECT_ALL:
603 return mSelectAllIconImage;
606 case Toolkit::TextSelectionPopup::NONE:
612 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
613 static std::string empty;
617 void TextSelectionPopup::SetPressedImage( const std::string& filename )
619 mPressedImage = filename;
622 std::string TextSelectionPopup::GetPressedImage() const
624 return mPressedImage;
627 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
629 mOrderListOfButtons.clear();
630 mOrderListOfButtons.reserve( 8u );
632 // Create button for each possible option using Option priority
633 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
634 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
635 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
636 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
637 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
638 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
640 // Sort the buttons according their priorities.
641 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
644 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
646 // 1. Create a option.
647 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
649 Toolkit::PushButton option = Toolkit::PushButton::New();
650 option.SetProperty( Dali::Actor::Property::NAME, button.name );
651 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
655 case Toolkit::TextSelectionPopup::CUT:
657 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
660 case Toolkit::TextSelectionPopup::COPY:
662 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
665 case Toolkit::TextSelectionPopup::PASTE:
667 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
670 case Toolkit::TextSelectionPopup::SELECT:
672 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
675 case Toolkit::TextSelectionPopup::SELECT_ALL:
677 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
680 case Toolkit::TextSelectionPopup::CLIPBOARD:
682 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
685 case Toolkit::TextSelectionPopup::NONE:
692 // 2. Set the options contents.
695 // PushButton layout properties.
696 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
699 Property::Map buttonLabelProperties;
700 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
701 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
705 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
706 option.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM" );
708 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
709 //option.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
710 //option.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
713 // 3. Set the normal option image (blank / Transparent).
714 option.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
716 // 4. Set the pressed option image.
717 Property::Value selectedBackgroundValue( mPressedImage );
718 if( mPressedImage.empty() )
720 // The image can be blank, the color can be used in that case.
721 selectedBackgroundValue = Property::Value{ { Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR },
722 { Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor } };
724 option.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue );
725 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
727 // 5 Add option to tool bar
728 mToolbar.AddOption( option );
730 // 6. Add the divider
733 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
735 Toolkit::Control divider = Toolkit::Control::New();
736 #ifdef DECORATOR_DEBUG
737 divider.SetProperty( Dali::Actor::Property::NAME,"Text's popup divider");
739 divider.SetProperty( Actor::Property::SIZE, size );
740 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
741 divider.SetBackgroundColor( mDividerColor );
742 mToolbar.AddDivider( divider );
746 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
748 std::size_t numberOfOptions = 0u;
749 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
751 const ButtonRequirement& button( *it );
758 return numberOfOptions;
761 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
763 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
765 CreateOrderedListOfPopupOptions();
767 mButtonsChanged = false;
768 UnparentAndReset( mToolbar);
773 mToolbar = Toolkit::TextSelectionToolbar::New();
774 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
776 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
778 mToolbar.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
779 #ifdef DECORATOR_DEBUG
780 mToolbar.SetProperty( Dali::Actor::Property::NAME,"TextSelectionToolbar");
782 self.Add( mToolbar );
785 // Whether to mirror the list of buttons (for right to left languages)
787 #if defined(__GLIBC__)
788 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
791 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
795 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
800 // Iterate list of buttons and add active ones to Toolbar
801 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
802 std::size_t numberOfOptionsAdded = 0u;
803 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
805 const ButtonRequirement& button( *it );
806 if ( button.enabled )
808 numberOfOptionsAdded++;
809 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
815 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
819 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
821 // Removes previous image if necessary
822 DevelControl::UnregisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
824 if( ! propertyMap.Empty() )
826 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
830 DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT );
835 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
836 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
841 mOptionDividerSize(),
842 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
843 mCallbackInterface( callbackInterface ),
844 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
845 mDividerColor( Color::WHITE ),
846 mIconColor( Color::WHITE ),
847 mSelectOptionPriority( 1 ),
848 mSelectAllOptionPriority ( 2 ),
849 mCutOptionPriority ( 4 ),
850 mCopyOptionPriority ( 3 ),
851 mPasteOptionPriority ( 5 ),
852 mClipboardOptionPriority( 6 ),
853 mFadeInDuration(0.0f),
854 mFadeOutDuration(0.0f),
856 mShowCaptions( true ),
857 mPopupShowing( false ),
858 mButtonsChanged( false )
860 DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
861 return std::unique_ptr< Dali::Accessibility::Accessible >(
862 new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::DIALOG, true ) );
866 TextSelectionPopup::~TextSelectionPopup()
871 } // namespace Internal
873 } // namespace Toolkit