2 * Copyright (c) 2016 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/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
38 #include <dali-toolkit/internal/helpers/color-conversion.h>
52 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
54 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
55 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
61 #ifdef DGETTEXT_ENABLED
63 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
64 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
65 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
66 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
67 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
68 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
72 #define POPUP_CUT_STRING "Cut"
73 #define POPUP_COPY_STRING "Copy"
74 #define POPUP_PASTE_STRING "Paste"
75 #define POPUP_SELECT_STRING "Select"
76 #define POPUP_SELECT_ALL_STRING "Select All"
77 #define POPUP_CLIPBOARD_STRING "Clipboard"
81 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
82 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
83 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
84 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
85 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
86 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
88 const std::string IDS_LTR( "IDS_LTR" );
89 const std::string RTL_DIRECTION( "RTL" );
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:
350 value = impl.mBackgroundBorderProperties;
358 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
360 mEnabledButtons = buttonsToEnable;
361 mButtonsChanged = true;
364 void TextSelectionPopup::RaiseAbove( Layer target )
368 mToolbar.RaiseAbove( target );
372 void TextSelectionPopup::ShowPopup()
374 if( ( !mPopupShowing || mButtonsChanged ) &&
375 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
378 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
380 Animation animation = Animation::New( mFadeInDuration );
381 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
383 mPopupShowing = true;
387 void TextSelectionPopup::HidePopup()
391 mPopupShowing = false;
393 Animation animation = Animation::New( mFadeOutDuration );
394 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
395 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
400 void TextSelectionPopup::OnInitialize()
402 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
404 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
405 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
407 // The Popup Control background is a nine-patch image. We clip against this so the
408 // contents are correctly clipped against the edges of the nine-patch.
409 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
412 void TextSelectionPopup::OnStageConnection( int depth )
414 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnStageConnection\n" );
415 // Call the Control::OnStageConnection() to set the depth of the background.
416 Control::OnStageConnection( depth );
418 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
421 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
424 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
426 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
427 UnparentAndReset( mToolbar );
431 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
433 if( mCallbackInterface )
435 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
441 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
443 if( mCallbackInterface )
445 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
451 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
453 if( mCallbackInterface )
455 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
461 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
463 if( mCallbackInterface )
465 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
471 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
473 if( mCallbackInterface )
475 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
481 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
483 if( mCallbackInterface )
485 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
491 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
493 switch( settingToCustomise )
495 case POPUP_MAXIMUM_SIZE :
497 mPopupMaxSize = dimension;
500 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
504 case OPTION_MAXIMUM_SIZE :
506 mOptionMaxSize = dimension;
507 // Option max size not currently currently supported
510 case OPTION_MINIMUM_SIZE :
512 mOptionMinSize = dimension;
513 // Option min size not currently currently supported
516 case OPTION_DIVIDER_SIZE :
518 mOptionDividerSize = dimension;
521 // Resize Dividers not currently supported
528 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
530 switch( settingToCustomise )
532 case POPUP_MAXIMUM_SIZE :
536 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
540 return mPopupMaxSize;
543 case OPTION_MAXIMUM_SIZE :
545 return mOptionMaxSize;
547 case OPTION_MINIMUM_SIZE :
549 return mOptionMinSize;
551 case OPTION_DIVIDER_SIZE :
553 return mOptionDividerSize;
560 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
565 case Toolkit::TextSelectionPopup::CLIPBOARD:
567 mClipboardIconImage = image;
570 case Toolkit::TextSelectionPopup::CUT :
572 mCutIconImage = image;
575 case Toolkit::TextSelectionPopup::COPY :
577 mCopyIconImage = image;
580 case Toolkit::TextSelectionPopup::PASTE :
582 mPasteIconImage = image;
585 case Toolkit::TextSelectionPopup::SELECT :
587 mSelectIconImage = image;
590 case Toolkit::TextSelectionPopup::SELECT_ALL :
592 mSelectAllIconImage = image;
597 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
602 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
606 case Toolkit::TextSelectionPopup::CLIPBOARD :
608 return mClipboardIconImage;
611 case Toolkit::TextSelectionPopup::CUT :
613 return mCutIconImage;
616 case Toolkit::TextSelectionPopup::COPY :
618 return mCopyIconImage;
621 case Toolkit::TextSelectionPopup::PASTE :
623 return mPasteIconImage;
626 case Toolkit::TextSelectionPopup::SELECT :
628 return mSelectIconImage;
631 case Toolkit::TextSelectionPopup::SELECT_ALL :
633 return mSelectAllIconImage;
638 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
642 return Dali::Image();
645 void TextSelectionPopup::SetPressedImage( const std::string& filename )
647 mPressedImage = filename;
650 std::string TextSelectionPopup::GetPressedImage() const
652 return mPressedImage;
655 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
657 mOrderListOfButtons.clear();
658 mOrderListOfButtons.reserve( 8u );
660 // Create button for each possible option using Option priority
661 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
662 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
663 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
664 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
665 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
666 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
668 // Sort the buttons according their priorities.
669 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
672 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
674 // 1. Create a option.
675 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
677 Toolkit::PushButton option = Toolkit::PushButton::New();
678 option.SetName( button.name );
679 option.SetAnimationTime( 0.0f );
680 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
684 case Toolkit::TextSelectionPopup::CUT:
686 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
689 case Toolkit::TextSelectionPopup::COPY:
691 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
694 case Toolkit::TextSelectionPopup::PASTE:
696 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
699 case Toolkit::TextSelectionPopup::SELECT:
701 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
704 case Toolkit::TextSelectionPopup::SELECT_ALL:
706 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
709 case Toolkit::TextSelectionPopup::CLIPBOARD:
711 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
714 case Toolkit::TextSelectionPopup::NONE:
721 // 2. Set the options contents.
724 // PushButton layout properties.
725 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
728 Property::Map buttonLabelProperties;
729 buttonLabelProperties.Insert( "text", button.caption );
730 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
734 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
735 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
737 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
738 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
739 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
742 // 3. Set the normal option image (blank / Transparent).
743 option.SetUnselectedImage( "" );
745 // 4. Set the pressed option image.
746 // The image can be blank, the color can be used regardless.
747 option.SetSelectedImage( mPressedImage );
748 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
749 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
751 // 5 Add option to tool bar
752 mToolbar.AddOption( option );
754 // 6. Add the divider
757 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
759 Toolkit::Control divider = Toolkit::Control::New();
760 #ifdef DECORATOR_DEBUG
761 divider.SetName("Text's popup divider");
763 divider.SetSize( size );
764 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
765 divider.SetBackgroundColor( mDividerColor );
766 mToolbar.AddDivider( divider );
770 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
772 std::size_t numberOfOptions = 0u;
773 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
775 const ButtonRequirement& button( *it );
782 return numberOfOptions;
785 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
787 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
789 CreateOrderedListOfPopupOptions();
791 mButtonsChanged = false;
792 UnparentAndReset( mToolbar);
797 mToolbar = Toolkit::TextSelectionToolbar::New();
798 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
800 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
802 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
803 #ifdef DECORATOR_DEBUG
804 mToolbar.SetName("TextSelectionToolbar");
806 self.Add( mToolbar );
809 // Whether to mirror the list of buttons (for right to left languages)
811 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
814 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
818 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
822 // Iterate list of buttons and add active ones to Toolbar
823 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
824 std::size_t numberOfOptionsAdded = 0u;
825 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
827 const ButtonRequirement& button( *it );
828 if ( button.enabled )
830 numberOfOptionsAdded++;
831 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
837 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
841 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
843 // Removes previous image if necessary
844 UnparentAndReset( mBackgroundBorder );
846 mBackgroundBorderProperties = propertyMap;
848 if( ! propertyMap.Empty() )
850 mBackgroundBorder = Dali::Toolkit::ImageView::New();
851 mBackgroundBorder.SetProperty( Dali::Toolkit::ImageView::Property::IMAGE, propertyMap );
852 mBackgroundBorder.SetParentOrigin( ParentOrigin::CENTER );
853 mBackgroundBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
855 Property::Value* colorValue = propertyMap.Find( "borderColor" );
859 if( ConvertPropertyToColor( *colorValue, color ) )
861 mBackgroundBorder.SetColor( color );
865 Self().Add( mBackgroundBorder );
869 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
870 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
875 mOptionDividerSize(),
876 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
877 mCallbackInterface( callbackInterface ),
878 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
879 mDividerColor( Color::WHITE ),
880 mIconColor( Color::WHITE ),
881 mSelectOptionPriority( 1 ),
882 mSelectAllOptionPriority ( 2 ),
883 mCutOptionPriority ( 4 ),
884 mCopyOptionPriority ( 3 ),
885 mPasteOptionPriority ( 5 ),
886 mClipboardOptionPriority( 6 ),
887 mFadeInDuration(0.0f),
888 mFadeOutDuration(0.0f),
890 mShowCaptions( true ),
891 mPopupShowing( false ),
892 mButtonsChanged( false )
896 TextSelectionPopup::~TextSelectionPopup()
901 } // namespace Internal
903 } // namespace Toolkit