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>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali/public-api/images/resource-image.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/buttons/button-devel.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
40 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
41 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
42 #include <dali-toolkit/internal/helpers/color-conversion.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
57 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
59 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
60 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
66 #ifdef DGETTEXT_ENABLED
68 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
69 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
70 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
71 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
72 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
73 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
77 #define POPUP_CUT_STRING "Cut"
78 #define POPUP_COPY_STRING "Copy"
79 #define POPUP_PASTE_STRING "Paste"
80 #define POPUP_SELECT_STRING "Select"
81 #define POPUP_SELECT_ALL_STRING "Select All"
82 #define POPUP_CLIPBOARD_STRING "Clipboard"
86 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
87 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
88 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
89 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
90 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
91 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
93 const std::string IDS_LTR( "IDS_LTR" );
94 const std::string RTL_DIRECTION( "RTL" );
98 return Toolkit::TextSelectionPopup::New( NULL );
101 // Setup properties, signals and actions using the type-registry.
103 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
124 DALI_TYPE_REGISTRATION_END()
129 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
131 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
133 // Create the implementation, temporarily owned by this handle on stack
134 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
136 // Pass ownership to CustomActor handle
137 Dali::Toolkit::TextSelectionPopup handle( *impl );
139 // Second-phase init of the implementation
140 // This can only be done after the CustomActor connection has been made...
146 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
148 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
152 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
156 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
158 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
161 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
163 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
166 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
168 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
171 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
173 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
176 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
178 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
179 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
182 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
184 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
185 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
188 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
190 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
191 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
194 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
196 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
197 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
200 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
202 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
203 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
206 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
208 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
209 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
212 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
214 impl.mDividerColor = value.Get< Vector4 >();
217 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
219 impl.mIconColor = value.Get< Vector4 >();
222 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
224 impl.mPressedColor = value.Get< Vector4 >();
227 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
229 impl.SetPressedImage( value.Get< std::string >() );
232 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
234 impl.mFadeInDuration = value.Get < float >();
237 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
239 impl.mFadeOutDuration = value.Get < float >();
242 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
244 Property::Map map = value.Get<Property::Map>();
245 impl.CreateBackgroundBorder( map );
249 } // TextSelectionPopup
252 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
254 Property::Value value;
256 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
260 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
264 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
266 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
269 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
271 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
274 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
276 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
279 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
281 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
284 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
286 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
289 value = image.GetUrl();
293 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
295 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
298 value = image.GetUrl();
302 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
304 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
307 value = image.GetUrl();
311 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
313 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
316 value = image.GetUrl();
320 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
322 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
325 value = image.GetUrl();
329 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
331 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
334 value = image.GetUrl();
338 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
340 value = impl.GetPressedImage();
343 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
345 value = impl.mFadeInDuration;
348 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
350 value = impl.mFadeOutDuration;
353 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
356 Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
359 visual.CreatePropertyMap( map );
369 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
371 mEnabledButtons = buttonsToEnable;
372 mButtonsChanged = true;
375 void TextSelectionPopup::RaiseAbove( Layer target )
379 mToolbar.RaiseAbove( target );
383 void TextSelectionPopup::ShowPopup()
385 if( ( !mPopupShowing || mButtonsChanged ) &&
386 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
389 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
391 Animation animation = Animation::New( mFadeInDuration );
392 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
394 mPopupShowing = true;
398 void TextSelectionPopup::HidePopup()
402 mPopupShowing = false;
404 Animation animation = Animation::New( mFadeOutDuration );
405 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
406 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
411 void TextSelectionPopup::OnInitialize()
413 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
415 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
416 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
418 // The Popup Control background is a nine-patch image. We clip against this so the
419 // contents are correctly clipped against the edges of the nine-patch.
420 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
423 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
426 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
428 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
429 UnparentAndReset( mToolbar );
433 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
435 if( mCallbackInterface )
437 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
443 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
445 if( mCallbackInterface )
447 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
453 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
455 if( mCallbackInterface )
457 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
463 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
465 if( mCallbackInterface )
467 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
473 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
475 if( mCallbackInterface )
477 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
483 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
485 if( mCallbackInterface )
487 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
493 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
495 switch( settingToCustomise )
497 case POPUP_MAXIMUM_SIZE :
499 mPopupMaxSize = dimension;
502 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
506 case OPTION_MAXIMUM_SIZE :
508 mOptionMaxSize = dimension;
509 // Option max size not currently currently supported
512 case OPTION_MINIMUM_SIZE :
514 mOptionMinSize = dimension;
515 // Option min size not currently currently supported
518 case OPTION_DIVIDER_SIZE :
520 mOptionDividerSize = dimension;
523 // Resize Dividers not currently supported
530 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
532 switch( settingToCustomise )
534 case POPUP_MAXIMUM_SIZE :
538 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
542 return mPopupMaxSize;
545 case OPTION_MAXIMUM_SIZE :
547 return mOptionMaxSize;
549 case OPTION_MINIMUM_SIZE :
551 return mOptionMinSize;
553 case OPTION_DIVIDER_SIZE :
555 return mOptionDividerSize;
562 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
567 case Toolkit::TextSelectionPopup::CLIPBOARD:
569 mClipboardIconImage = image;
572 case Toolkit::TextSelectionPopup::CUT :
574 mCutIconImage = image;
577 case Toolkit::TextSelectionPopup::COPY :
579 mCopyIconImage = image;
582 case Toolkit::TextSelectionPopup::PASTE :
584 mPasteIconImage = image;
587 case Toolkit::TextSelectionPopup::SELECT :
589 mSelectIconImage = image;
592 case Toolkit::TextSelectionPopup::SELECT_ALL :
594 mSelectAllIconImage = image;
599 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
604 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
608 case Toolkit::TextSelectionPopup::CLIPBOARD :
610 return mClipboardIconImage;
613 case Toolkit::TextSelectionPopup::CUT :
615 return mCutIconImage;
618 case Toolkit::TextSelectionPopup::COPY :
620 return mCopyIconImage;
623 case Toolkit::TextSelectionPopup::PASTE :
625 return mPasteIconImage;
628 case Toolkit::TextSelectionPopup::SELECT :
630 return mSelectIconImage;
633 case Toolkit::TextSelectionPopup::SELECT_ALL :
635 return mSelectAllIconImage;
640 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
644 return Dali::Image();
647 void TextSelectionPopup::SetPressedImage( const std::string& filename )
649 mPressedImage = filename;
652 std::string TextSelectionPopup::GetPressedImage() const
654 return mPressedImage;
657 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
659 mOrderListOfButtons.clear();
660 mOrderListOfButtons.reserve( 8u );
662 // Create button for each possible option using Option priority
663 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
664 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
665 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
666 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
667 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
668 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
670 // Sort the buttons according their priorities.
671 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
674 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
676 // 1. Create a option.
677 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
679 Toolkit::PushButton option = Toolkit::PushButton::New();
680 option.SetName( button.name );
681 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
685 case Toolkit::TextSelectionPopup::CUT:
687 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
690 case Toolkit::TextSelectionPopup::COPY:
692 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
695 case Toolkit::TextSelectionPopup::PASTE:
697 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
700 case Toolkit::TextSelectionPopup::SELECT:
702 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
705 case Toolkit::TextSelectionPopup::SELECT_ALL:
707 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
710 case Toolkit::TextSelectionPopup::CLIPBOARD:
712 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
715 case Toolkit::TextSelectionPopup::NONE:
722 // 2. Set the options contents.
725 // PushButton layout properties.
726 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
729 Property::Map buttonLabelProperties;
730 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
731 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
735 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
736 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
738 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
739 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
740 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
743 // 3. Set the normal option image (blank / Transparent).
744 option.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
746 // 4. Set the pressed option image.
747 // The image can be blank, the color can be used regardless.
748 option.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, mPressedImage );
749 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
750 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
752 // 5 Add option to tool bar
753 mToolbar.AddOption( option );
755 // 6. Add the divider
758 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
760 Toolkit::Control divider = Toolkit::Control::New();
761 #ifdef DECORATOR_DEBUG
762 divider.SetName("Text's popup divider");
764 divider.SetSize( size );
765 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
766 divider.SetBackgroundColor( mDividerColor );
767 mToolbar.AddDivider( divider );
771 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
773 std::size_t numberOfOptions = 0u;
774 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
776 const ButtonRequirement& button( *it );
783 return numberOfOptions;
786 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
788 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
790 CreateOrderedListOfPopupOptions();
792 mButtonsChanged = false;
793 UnparentAndReset( mToolbar);
798 mToolbar = Toolkit::TextSelectionToolbar::New();
799 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
801 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
803 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
804 #ifdef DECORATOR_DEBUG
805 mToolbar.SetName("TextSelectionToolbar");
807 self.Add( mToolbar );
810 // Whether to mirror the list of buttons (for right to left languages)
812 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
815 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
819 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
823 // Iterate list of buttons and add active ones to Toolbar
824 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
825 std::size_t numberOfOptionsAdded = 0u;
826 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
828 const ButtonRequirement& button( *it );
829 if ( button.enabled )
831 numberOfOptionsAdded++;
832 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
838 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
842 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
844 // Removes previous image if necessary
845 DevelControl::UnregisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
847 if( ! propertyMap.Empty() )
849 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
853 DevelControl::RegisterVisual( *this, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual, DepthIndex::CONTENT );
858 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
859 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
864 mOptionDividerSize(),
865 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
866 mCallbackInterface( callbackInterface ),
867 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
868 mDividerColor( Color::WHITE ),
869 mIconColor( Color::WHITE ),
870 mSelectOptionPriority( 1 ),
871 mSelectAllOptionPriority ( 2 ),
872 mCutOptionPriority ( 4 ),
873 mCopyOptionPriority ( 3 ),
874 mPasteOptionPriority ( 5 ),
875 mClipboardOptionPriority( 6 ),
876 mFadeInDuration(0.0f),
877 mFadeOutDuration(0.0f),
879 mShowCaptions( true ),
880 mPopupShowing( false ),
881 mButtonsChanged( false )
885 TextSelectionPopup::~TextSelectionPopup()
890 } // namespace Internal
892 } // namespace Toolkit