2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/object/property-map.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
35 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
38 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
39 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
40 #include <dali-toolkit/internal/helpers/color-conversion.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
55 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
57 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
58 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
60 #if defined(DEBUG_ENABLED)
61 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
64 #ifdef DGETTEXT_ENABLED
66 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
67 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
68 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
69 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
70 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
71 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
75 #define POPUP_CUT_STRING "Cut"
76 #define POPUP_COPY_STRING "Copy"
77 #define POPUP_PASTE_STRING "Paste"
78 #define POPUP_SELECT_STRING "Select"
79 #define POPUP_SELECT_ALL_STRING "Select All"
80 #define POPUP_CLIPBOARD_STRING "Clipboard"
84 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
85 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
86 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
87 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
88 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
89 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
93 return Toolkit::TextSelectionPopup::New( NULL );
96 // Setup properties, signals and actions using the type-registry.
98 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
119 DALI_TYPE_REGISTRATION_END()
124 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
126 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
128 // Create the implementation, temporarily owned by this handle on stack
129 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
131 // Pass ownership to CustomActor handle
132 Dali::Toolkit::TextSelectionPopup handle( *impl );
134 // Second-phase init of the implementation
135 // This can only be done after the CustomActor connection has been made...
141 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
143 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
147 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
151 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
153 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
156 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
158 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
161 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
163 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
166 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
168 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
171 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
173 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
174 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
177 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
179 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
180 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
183 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
185 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
186 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
189 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
191 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
192 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
195 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
197 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
198 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
201 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
203 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
204 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
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 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
284 value = image.GetUrl();
288 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
290 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
293 value = image.GetUrl();
297 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
299 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
302 value = image.GetUrl();
306 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
308 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
311 value = image.GetUrl();
315 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
317 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
320 value = image.GetUrl();
324 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
326 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
329 value = image.GetUrl();
333 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
335 value = impl.GetPressedImage();
338 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
340 value = impl.mFadeInDuration;
343 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
345 value = impl.mFadeOutDuration;
348 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
351 Toolkit::Visual::Base visual = impl.GetVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
354 visual.CreatePropertyMap( map );
364 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
366 mEnabledButtons = buttonsToEnable;
367 mButtonsChanged = true;
370 void TextSelectionPopup::RaiseAbove( Layer target )
374 mToolbar.RaiseAbove( target );
378 void TextSelectionPopup::ShowPopup()
380 if( ( !mPopupShowing || mButtonsChanged ) &&
381 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
384 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
386 Animation animation = Animation::New( mFadeInDuration );
387 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
389 mPopupShowing = true;
393 void TextSelectionPopup::HidePopup()
397 mPopupShowing = false;
399 Animation animation = Animation::New( mFadeOutDuration );
400 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
401 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
406 void TextSelectionPopup::OnInitialize()
408 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
410 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
411 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
413 // The Popup Control background is a nine-patch image. We clip against this so the
414 // contents are correctly clipped against the edges of the nine-patch.
415 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
418 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
421 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
423 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
424 UnparentAndReset( mToolbar );
428 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
430 if( mCallbackInterface )
432 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
438 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
440 if( mCallbackInterface )
442 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
448 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
450 if( mCallbackInterface )
452 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
458 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
460 if( mCallbackInterface )
462 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
468 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
470 if( mCallbackInterface )
472 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
478 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
480 if( mCallbackInterface )
482 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
488 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
490 switch( settingToCustomise )
492 case POPUP_MAXIMUM_SIZE :
494 mPopupMaxSize = dimension;
497 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
501 case OPTION_MAXIMUM_SIZE :
503 mOptionMaxSize = dimension;
504 // Option max size not currently currently supported
507 case OPTION_MINIMUM_SIZE :
509 mOptionMinSize = dimension;
510 // Option min size not currently currently supported
513 case OPTION_DIVIDER_SIZE :
515 mOptionDividerSize = dimension;
518 // Resize Dividers not currently supported
525 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
527 switch( settingToCustomise )
529 case POPUP_MAXIMUM_SIZE :
533 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
537 return mPopupMaxSize;
540 case OPTION_MAXIMUM_SIZE :
542 return mOptionMaxSize;
544 case OPTION_MINIMUM_SIZE :
546 return mOptionMinSize;
548 case OPTION_DIVIDER_SIZE :
550 return mOptionDividerSize;
557 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
562 case Toolkit::TextSelectionPopup::CLIPBOARD:
564 mClipboardIconImage = image;
567 case Toolkit::TextSelectionPopup::CUT :
569 mCutIconImage = image;
572 case Toolkit::TextSelectionPopup::COPY :
574 mCopyIconImage = image;
577 case Toolkit::TextSelectionPopup::PASTE :
579 mPasteIconImage = image;
582 case Toolkit::TextSelectionPopup::SELECT :
584 mSelectIconImage = image;
587 case Toolkit::TextSelectionPopup::SELECT_ALL :
589 mSelectAllIconImage = image;
594 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
599 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
603 case Toolkit::TextSelectionPopup::CLIPBOARD :
605 return mClipboardIconImage;
608 case Toolkit::TextSelectionPopup::CUT :
610 return mCutIconImage;
613 case Toolkit::TextSelectionPopup::COPY :
615 return mCopyIconImage;
618 case Toolkit::TextSelectionPopup::PASTE :
620 return mPasteIconImage;
623 case Toolkit::TextSelectionPopup::SELECT :
625 return mSelectIconImage;
628 case Toolkit::TextSelectionPopup::SELECT_ALL :
630 return mSelectAllIconImage;
635 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
639 return Dali::Image();
642 void TextSelectionPopup::SetPressedImage( const std::string& filename )
644 mPressedImage = filename;
647 std::string TextSelectionPopup::GetPressedImage() const
649 return mPressedImage;
652 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
654 mOrderListOfButtons.clear();
655 mOrderListOfButtons.reserve( 8u );
657 // Create button for each possible option using Option priority
658 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
659 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
660 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
661 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
662 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
663 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
665 // Sort the buttons according their priorities.
666 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
669 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
671 // 1. Create a option.
672 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
674 Toolkit::PushButton option = Toolkit::PushButton::New();
675 option.SetName( button.name );
676 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
680 case Toolkit::TextSelectionPopup::CUT:
682 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
685 case Toolkit::TextSelectionPopup::COPY:
687 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
690 case Toolkit::TextSelectionPopup::PASTE:
692 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
695 case Toolkit::TextSelectionPopup::SELECT:
697 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
700 case Toolkit::TextSelectionPopup::SELECT_ALL:
702 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
705 case Toolkit::TextSelectionPopup::CLIPBOARD:
707 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
710 case Toolkit::TextSelectionPopup::NONE:
717 // 2. Set the options contents.
720 // PushButton layout properties.
721 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
724 Property::Map buttonLabelProperties;
725 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
726 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
730 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
731 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
733 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
734 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
735 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
738 // 3. Set the normal option image (blank / Transparent).
739 option.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
741 // 4. Set the pressed option image.
742 // The image can be blank, the color can be used regardless.
743 option.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, mPressedImage );
744 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
745 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
747 // 5 Add option to tool bar
748 mToolbar.AddOption( option );
750 // 6. Add the divider
753 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
755 Toolkit::Control divider = Toolkit::Control::New();
756 #ifdef DECORATOR_DEBUG
757 divider.SetName("Text's popup divider");
759 divider.SetSize( size );
760 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
761 divider.SetBackgroundColor( mDividerColor );
762 mToolbar.AddDivider( divider );
766 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
768 std::size_t numberOfOptions = 0u;
769 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
771 const ButtonRequirement& button( *it );
778 return numberOfOptions;
781 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
783 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
785 CreateOrderedListOfPopupOptions();
787 mButtonsChanged = false;
788 UnparentAndReset( mToolbar);
793 mToolbar = Toolkit::TextSelectionToolbar::New();
794 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
796 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
798 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
799 #ifdef DECORATOR_DEBUG
800 mToolbar.SetName("TextSelectionToolbar");
802 self.Add( mToolbar );
805 // Iterate list of buttons and add active ones to Toolbar
806 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
807 std::size_t numberOfOptionsAdded = 0u;
808 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
810 const ButtonRequirement& button( *it );
811 if ( button.enabled )
813 numberOfOptionsAdded++;
814 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
819 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
821 // Removes previous image if necessary
822 UnregisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
824 if( ! propertyMap.Empty() )
826 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
830 RegisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual );
831 visual.SetDepthIndex( DepthIndex::CONTENT );
836 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
837 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
842 mOptionDividerSize(),
843 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
844 mCallbackInterface( callbackInterface ),
845 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
846 mDividerColor( Color::WHITE ),
847 mIconColor( Color::WHITE ),
848 mSelectOptionPriority( 1 ),
849 mSelectAllOptionPriority ( 2 ),
850 mCutOptionPriority ( 4 ),
851 mCopyOptionPriority ( 3 ),
852 mPasteOptionPriority ( 5 ),
853 mClipboardOptionPriority( 6 ),
854 mFadeInDuration(0.0f),
855 mFadeOutDuration(0.0f),
857 mShowCaptions( true ),
858 mPopupShowing( false ),
859 mButtonsChanged( false )
863 TextSelectionPopup::~TextSelectionPopup()
868 } // namespace Internal
870 } // namespace Toolkit