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>
57 #if defined(__GLIBC__)
58 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
61 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
62 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
68 #ifdef DGETTEXT_ENABLED
70 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
71 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
72 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
73 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
74 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
75 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
79 #define POPUP_CUT_STRING "Cut"
80 #define POPUP_COPY_STRING "Copy"
81 #define POPUP_PASTE_STRING "Paste"
82 #define POPUP_SELECT_STRING "Select"
83 #define POPUP_SELECT_ALL_STRING "Select All"
84 #define POPUP_CLIPBOARD_STRING "Clipboard"
88 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
89 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
90 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
91 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
92 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
93 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
95 const std::string IDS_LTR( "IDS_LTR" );
96 const std::string RTL_DIRECTION( "RTL" );
100 return Toolkit::TextSelectionPopup::New( NULL );
103 // Setup properties, signals and actions using the type-registry.
105 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
126 DALI_TYPE_REGISTRATION_END()
131 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
133 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
135 // Create the implementation, temporarily owned by this handle on stack
136 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
138 // Pass ownership to CustomActor handle
139 Dali::Toolkit::TextSelectionPopup handle( *impl );
141 // Second-phase init of the implementation
142 // This can only be done after the CustomActor connection has been made...
148 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
150 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
154 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
158 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
160 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
163 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
165 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
168 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
170 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
173 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
175 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
178 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
180 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, value.Get< std::string >() );
183 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
185 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, value.Get< std::string >() );
188 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
190 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, value.Get< std::string >() );
193 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
195 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, value.Get< std::string >() );
198 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
200 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, value.Get< std::string >() );
203 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
205 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, value.Get< std::string >() );
208 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
210 impl.mDividerColor = value.Get< Vector4 >();
213 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
215 impl.mIconColor = value.Get< Vector4 >();
218 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
220 impl.mPressedColor = value.Get< Vector4 >();
223 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
225 impl.SetPressedImage( value.Get< std::string >() );
228 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
230 impl.mFadeInDuration = value.Get < float >();
233 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
235 impl.mFadeOutDuration = value.Get < float >();
238 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
240 Property::Map map = value.Get<Property::Map>();
241 impl.CreateBackgroundBorder( map );
245 } // TextSelectionPopup
248 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
250 Property::Value value;
252 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
256 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
260 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
262 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
265 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
267 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
270 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
272 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
275 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
277 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
280 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
282 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD );
285 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
287 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT );
290 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
292 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY );
295 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
297 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE );
300 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
302 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT );
305 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
307 value = impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL );
310 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
312 value = impl.GetPressedImage();
315 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
317 value = impl.mFadeInDuration;
320 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
322 value = impl.mFadeOutDuration;
325 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
328 Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
331 visual.CreatePropertyMap( map );
341 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
343 mEnabledButtons = buttonsToEnable;
344 mButtonsChanged = true;
347 void TextSelectionPopup::RaiseAbove( Layer target )
351 mToolbar.RaiseAbove( target );
355 void TextSelectionPopup::ShowPopup()
357 if( ( !mPopupShowing || mButtonsChanged ) &&
358 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
361 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
363 Animation animation = Animation::New( mFadeInDuration );
364 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
366 mPopupShowing = true;
370 void TextSelectionPopup::HidePopup()
374 mPopupShowing = false;
376 Animation animation = Animation::New( mFadeOutDuration );
377 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
378 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
383 void TextSelectionPopup::OnInitialize()
385 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
387 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
388 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
391 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
394 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
396 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
397 UnparentAndReset( mToolbar );
401 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
403 if( mCallbackInterface )
405 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
411 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
413 if( mCallbackInterface )
415 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
421 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
423 if( mCallbackInterface )
425 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
431 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
433 if( mCallbackInterface )
435 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
441 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
443 if( mCallbackInterface )
445 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
451 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
453 if( mCallbackInterface )
455 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
461 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
463 switch( settingToCustomise )
465 case POPUP_MAXIMUM_SIZE :
467 mPopupMaxSize = dimension;
470 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
474 case OPTION_MAXIMUM_SIZE :
476 mOptionMaxSize = dimension;
477 // Option max size not currently currently supported
480 case OPTION_MINIMUM_SIZE :
482 mOptionMinSize = dimension;
483 // Option min size not currently currently supported
486 case OPTION_DIVIDER_SIZE :
488 mOptionDividerSize = dimension;
491 // Resize Dividers not currently supported
498 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise ) const
500 switch( settingToCustomise )
502 case POPUP_MAXIMUM_SIZE :
506 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
510 return mPopupMaxSize;
513 case OPTION_MAXIMUM_SIZE :
515 return mOptionMaxSize;
517 case OPTION_MINIMUM_SIZE :
519 return mOptionMinSize;
521 case OPTION_DIVIDER_SIZE :
523 return mOptionDividerSize;
530 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, const std::string& image )
534 case Toolkit::TextSelectionPopup::CLIPBOARD:
536 mClipboardIconImage = image;
539 case Toolkit::TextSelectionPopup::CUT :
541 mCutIconImage = image;
544 case Toolkit::TextSelectionPopup::COPY :
546 mCopyIconImage = image;
549 case Toolkit::TextSelectionPopup::PASTE :
551 mPasteIconImage = image;
554 case Toolkit::TextSelectionPopup::SELECT :
556 mSelectIconImage = image;
559 case Toolkit::TextSelectionPopup::SELECT_ALL :
561 mSelectAllIconImage = image;
566 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
571 const std::string& TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button ) const
575 case Toolkit::TextSelectionPopup::CLIPBOARD:
577 return mClipboardIconImage;
580 case Toolkit::TextSelectionPopup::CUT:
582 return mCutIconImage;
585 case Toolkit::TextSelectionPopup::COPY:
587 return mCopyIconImage;
590 case Toolkit::TextSelectionPopup::PASTE:
592 return mPasteIconImage;
595 case Toolkit::TextSelectionPopup::SELECT:
597 return mSelectIconImage;
600 case Toolkit::TextSelectionPopup::SELECT_ALL:
602 return mSelectAllIconImage;
605 case Toolkit::TextSelectionPopup::NONE:
611 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
612 static std::string empty;
616 void TextSelectionPopup::SetPressedImage( const std::string& filename )
618 mPressedImage = filename;
621 std::string TextSelectionPopup::GetPressedImage() const
623 return mPressedImage;
626 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
628 mOrderListOfButtons.clear();
629 mOrderListOfButtons.reserve( 8u );
631 // Create button for each possible option using Option priority
632 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
633 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
634 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
635 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
636 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
637 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
639 // Sort the buttons according their priorities.
640 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
643 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
645 // 1. Create a option.
646 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
648 Toolkit::PushButton option = Toolkit::PushButton::New();
649 option.SetProperty( Dali::Actor::Property::NAME, button.name );
650 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
654 case Toolkit::TextSelectionPopup::CUT:
656 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
659 case Toolkit::TextSelectionPopup::COPY:
661 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
664 case Toolkit::TextSelectionPopup::PASTE:
666 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
669 case Toolkit::TextSelectionPopup::SELECT:
671 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
674 case Toolkit::TextSelectionPopup::SELECT_ALL:
676 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
679 case Toolkit::TextSelectionPopup::CLIPBOARD:
681 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
684 case Toolkit::TextSelectionPopup::NONE:
691 // 2. Set the options contents.
694 // PushButton layout properties.
695 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
698 Property::Map buttonLabelProperties;
699 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
700 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
704 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
705 option.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM" );
707 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
708 //option.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, button.icon );
709 //option.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, button.icon );
712 // 3. Set the normal option image (blank / Transparent).
713 option.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
715 // 4. Set the pressed option image.
716 Property::Value selectedBackgroundValue( mPressedImage );
717 if( mPressedImage.empty() )
719 // The image can be blank, the color can be used in that case.
720 selectedBackgroundValue = Property::Value{ { Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR },
721 { Toolkit::ColorVisual::Property::MIX_COLOR, mPressedColor } };
723 option.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, selectedBackgroundValue );
724 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
726 // 5 Add option to tool bar
727 mToolbar.AddOption( option );
729 // 6. Add the divider
732 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
734 Toolkit::Control divider = Toolkit::Control::New();
735 #ifdef DECORATOR_DEBUG
736 divider.SetProperty( Dali::Actor::Property::NAME,"Text's popup divider");
738 divider.SetProperty( Actor::Property::SIZE, size );
739 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
740 divider.SetBackgroundColor( mDividerColor );
741 mToolbar.AddDivider( divider );
745 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions() const
747 std::size_t numberOfOptions = 0u;
748 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
750 const ButtonRequirement& button( *it );
757 return numberOfOptions;
760 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
762 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
764 CreateOrderedListOfPopupOptions();
766 mButtonsChanged = false;
767 UnparentAndReset( mToolbar);
772 mToolbar = Toolkit::TextSelectionToolbar::New();
773 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
775 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
777 mToolbar.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
778 #ifdef DECORATOR_DEBUG
779 mToolbar.SetProperty( Dali::Actor::Property::NAME,"TextSelectionToolbar");
781 self.Add( mToolbar );
784 // Whether to mirror the list of buttons (for right to left languages)
786 #if defined(__GLIBC__)
787 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
790 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
794 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
799 // Iterate list of buttons and add active ones to Toolbar
800 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
801 std::size_t numberOfOptionsAdded = 0u;
802 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
804 const ButtonRequirement& button( *it );
805 if ( button.enabled )
807 numberOfOptionsAdded++;
808 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
814 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
818 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
820 // Removes previous image if necessary
821 DevelControl::UnregisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
823 if( ! propertyMap.Empty() )
825 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
829 DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT );
834 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
835 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
840 mOptionDividerSize(),
841 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
842 mCallbackInterface( callbackInterface ),
843 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
844 mDividerColor( Color::WHITE ),
845 mIconColor( Color::WHITE ),
846 mSelectOptionPriority( 1 ),
847 mSelectAllOptionPriority ( 2 ),
848 mCutOptionPriority ( 4 ),
849 mCopyOptionPriority ( 3 ),
850 mPasteOptionPriority ( 5 ),
851 mClipboardOptionPriority( 6 ),
852 mFadeInDuration(0.0f),
853 mFadeOutDuration(0.0f),
855 mShowCaptions( true ),
856 mPopupShowing( false ),
857 mButtonsChanged( false )
861 TextSelectionPopup::~TextSelectionPopup()
866 } // namespace Internal
868 } // namespace Toolkit