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/text-controls/text-selection-popup-callback-interface.h>
39 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
40 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
41 #include <dali-toolkit/public-api/visuals/visual-properties.h>
42 #include <dali-toolkit/internal/helpers/color-conversion.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
56 #if defined(__GLIBC__)
57 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
60 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
61 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
67 #ifdef DGETTEXT_ENABLED
69 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
70 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
71 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
72 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
73 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
74 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
78 #define POPUP_CUT_STRING "Cut"
79 #define POPUP_COPY_STRING "Copy"
80 #define POPUP_PASTE_STRING "Paste"
81 #define POPUP_SELECT_STRING "Select"
82 #define POPUP_SELECT_ALL_STRING "Select All"
83 #define POPUP_CLIPBOARD_STRING "Clipboard"
87 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
88 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
89 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
90 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
91 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
92 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
94 const std::string IDS_LTR( "IDS_LTR" );
95 const std::string RTL_DIRECTION( "RTL" );
99 return Toolkit::TextSelectionPopup::New( NULL );
102 // Setup properties, signals and actions using the type-registry.
104 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
125 DALI_TYPE_REGISTRATION_END()
130 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
132 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
134 // Create the implementation, temporarily owned by this handle on stack
135 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
137 // Pass ownership to CustomActor handle
138 Dali::Toolkit::TextSelectionPopup handle( *impl );
140 // Second-phase init of the implementation
141 // This can only be done after the CustomActor connection has been made...
147 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
149 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
153 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
157 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
159 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
162 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
164 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
167 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
169 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
172 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
174 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
177 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
179 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, value.Get< std::string >() );
182 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
184 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, value.Get< std::string >() );
187 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
189 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, value.Get< std::string >() );
192 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
194 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, value.Get< std::string >() );
197 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
199 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, value.Get< std::string >() );
202 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
204 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, value.Get< std::string >() );
207 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
209 impl.mDividerColor = value.Get< Vector4 >();
212 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
214 impl.mIconColor = value.Get< Vector4 >();
217 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
219 impl.mPressedColor = value.Get< Vector4 >();
222 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
224 impl.SetPressedImage( value.Get< std::string >() );
227 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
229 impl.mFadeInDuration = value.Get < float >();
232 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
234 impl.mFadeOutDuration = value.Get < float >();
237 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
239 Property::Map map = value.Get<Property::Map>();
240 impl.CreateBackgroundBorder( map );
244 } // TextSelectionPopup
247 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
249 Property::Value value;
251 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
255 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
259 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
261 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
264 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
266 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
269 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
271 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
274 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
276 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
279 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
281 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD );
284 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
286 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT );
289 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
291 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY );
294 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
296 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE );
299 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
301 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT );
304 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
306 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL );
309 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
311 value = impl.GetPressedImage();
314 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
316 value = impl.mFadeInDuration;
319 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
321 value = impl.mFadeOutDuration;
324 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
327 Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
330 visual.CreatePropertyMap( map );
340 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
342 mEnabledButtons = buttonsToEnable;
343 mButtonsChanged = true;
346 void TextSelectionPopup::RaiseAbove( Layer target )
350 mToolbar.RaiseAbove( target );
354 void TextSelectionPopup::ShowPopup()
356 if( ( !mPopupShowing || mButtonsChanged ) &&
357 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
360 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
362 Animation animation = Animation::New( mFadeInDuration );
363 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
365 mPopupShowing = true;
369 void TextSelectionPopup::HidePopup()
373 mPopupShowing = false;
375 Animation animation = Animation::New( mFadeOutDuration );
376 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
377 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
382 void TextSelectionPopup::OnInitialize()
384 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
386 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
387 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
390 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
393 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
395 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
396 UnparentAndReset( mToolbar );
400 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
402 if( mCallbackInterface )
404 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
410 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
412 if( mCallbackInterface )
414 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
420 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
422 if( mCallbackInterface )
424 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
430 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
432 if( mCallbackInterface )
434 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
440 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
442 if( mCallbackInterface )
444 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
450 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
452 if( mCallbackInterface )
454 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
460 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
462 switch( settingToCustomise )
464 case POPUP_MAXIMUM_SIZE :
466 mPopupMaxSize = dimension;
469 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
473 case OPTION_MAXIMUM_SIZE :
475 mOptionMaxSize = dimension;
476 // Option max size not currently currently supported
479 case OPTION_MINIMUM_SIZE :
481 mOptionMinSize = dimension;
482 // Option min size not currently currently supported
485 case OPTION_DIVIDER_SIZE :
487 mOptionDividerSize = dimension;
490 // Resize Dividers not currently supported
497 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
499 switch( settingToCustomise )
501 case POPUP_MAXIMUM_SIZE :
505 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
509 return mPopupMaxSize;
512 case OPTION_MAXIMUM_SIZE :
514 return mOptionMaxSize;
516 case OPTION_MINIMUM_SIZE :
518 return mOptionMinSize;
520 case OPTION_DIVIDER_SIZE :
522 return mOptionDividerSize;
529 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, const std::string& image )
533 case Toolkit::TextSelectionPopup::CLIPBOARD:
535 mClipboardIconImage = image;
538 case Toolkit::TextSelectionPopup::CUT :
540 mCutIconImage = image;
543 case Toolkit::TextSelectionPopup::COPY :
545 mCopyIconImage = image;
548 case Toolkit::TextSelectionPopup::PASTE :
550 mPasteIconImage = image;
553 case Toolkit::TextSelectionPopup::SELECT :
555 mSelectIconImage = image;
558 case Toolkit::TextSelectionPopup::SELECT_ALL :
560 mSelectAllIconImage = image;
565 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
570 std::string TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
572 std::string buttonImageUrl;
575 case Toolkit::TextSelectionPopup::CLIPBOARD :
577 buttonImageUrl = mClipboardIconImage;
580 case Toolkit::TextSelectionPopup::CUT :
582 buttonImageUrl = mCutIconImage;
585 case Toolkit::TextSelectionPopup::COPY :
587 buttonImageUrl = mCopyIconImage;
590 case Toolkit::TextSelectionPopup::PASTE :
592 buttonImageUrl = mPasteIconImage;
595 case Toolkit::TextSelectionPopup::SELECT :
597 buttonImageUrl = mSelectIconImage;
600 case Toolkit::TextSelectionPopup::SELECT_ALL :
602 buttonImageUrl = mSelectAllIconImage;
607 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
611 return buttonImageUrl;
614 void TextSelectionPopup::SetPressedImage( const std::string& filename )
616 mPressedImage = filename;
619 std::string TextSelectionPopup::GetPressedImage() const
621 return mPressedImage;
624 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
626 mOrderListOfButtons.clear();
627 mOrderListOfButtons.reserve( 8u );
629 // Create button for each possible option using Option priority
630 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
631 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
632 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
633 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
634 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
635 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
637 // Sort the buttons according their priorities.
638 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
641 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
643 // 1. Create a option.
644 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
646 Toolkit::PushButton option = Toolkit::PushButton::New();
647 option.SetProperty( Dali::Actor::Property::NAME, button.name );
648 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
652 case Toolkit::TextSelectionPopup::CUT:
654 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
657 case Toolkit::TextSelectionPopup::COPY:
659 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
662 case Toolkit::TextSelectionPopup::PASTE:
664 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
667 case Toolkit::TextSelectionPopup::SELECT:
669 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
672 case Toolkit::TextSelectionPopup::SELECT_ALL:
674 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
677 case Toolkit::TextSelectionPopup::CLIPBOARD:
679 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
682 case Toolkit::TextSelectionPopup::NONE:
689 // 2. Set the options contents.
692 // PushButton layout properties.
693 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
696 Property::Map buttonLabelProperties;
697 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
698 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
702 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
703 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
705 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
706 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
707 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
710 // 3. Set the normal option image (blank / Transparent).
711 option.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
713 // 4. Set the pressed option image.
714 Property::Value selectedBackgroundValue( mPressedImage );
715 if( mPressedImage.empty() )
717 // The image can be blank, the color can be used in that case.
718 selectedBackgroundValue = Property::Value{ { Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR },
719 { Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor } };
721 option.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue );
722 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
724 // 5 Add option to tool bar
725 mToolbar.AddOption( option );
727 // 6. Add the divider
730 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
732 Toolkit::Control divider = Toolkit::Control::New();
733 #ifdef DECORATOR_DEBUG
734 divider.SetProperty( Dali::Actor::Property::NAME,"Text's popup divider");
736 divider.SetProperty( Actor::Property::SIZE, size );
737 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
738 divider.SetBackgroundColor( mDividerColor );
739 mToolbar.AddDivider( divider );
743 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
745 std::size_t numberOfOptions = 0u;
746 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
748 const ButtonRequirement& button( *it );
755 return numberOfOptions;
758 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
760 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
762 CreateOrderedListOfPopupOptions();
764 mButtonsChanged = false;
765 UnparentAndReset( mToolbar);
770 mToolbar = Toolkit::TextSelectionToolbar::New();
771 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
773 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
775 mToolbar.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
776 #ifdef DECORATOR_DEBUG
777 mToolbar.SetProperty( Dali::Actor::Property::NAME,"TextSelectionToolbar");
779 self.Add( mToolbar );
782 // Whether to mirror the list of buttons (for right to left languages)
784 #if defined(__GLIBC__)
785 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
788 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
792 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
797 // Iterate list of buttons and add active ones to Toolbar
798 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
799 std::size_t numberOfOptionsAdded = 0u;
800 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
802 const ButtonRequirement& button( *it );
803 if ( button.enabled )
805 numberOfOptionsAdded++;
806 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
812 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
816 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
818 // Removes previous image if necessary
819 DevelControl::UnregisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
821 if( ! propertyMap.Empty() )
823 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
827 DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT );
832 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
833 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
838 mOptionDividerSize(),
839 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
840 mCallbackInterface( callbackInterface ),
841 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
842 mDividerColor( Color::WHITE ),
843 mIconColor( Color::WHITE ),
844 mSelectOptionPriority( 1 ),
845 mSelectAllOptionPriority ( 2 ),
846 mCutOptionPriority ( 4 ),
847 mCopyOptionPriority ( 3 ),
848 mPasteOptionPriority ( 5 ),
849 mClipboardOptionPriority( 6 ),
850 mFadeInDuration(0.0f),
851 mFadeOutDuration(0.0f),
853 mShowCaptions( true ),
854 mPopupShowing( false ),
855 mButtonsChanged( false )
859 TextSelectionPopup::~TextSelectionPopup()
864 } // namespace Internal
866 } // namespace Toolkit