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/text-controls/text-selection-popup-callback-interface.h>
39 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
40 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
41 #include <dali-toolkit/internal/helpers/color-conversion.h>
42 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
56 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
58 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
59 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
61 #if defined(DEBUG_ENABLED)
62 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
65 #ifdef DGETTEXT_ENABLED
67 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
68 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
69 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
70 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
71 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
72 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
76 #define POPUP_CUT_STRING "Cut"
77 #define POPUP_COPY_STRING "Copy"
78 #define POPUP_PASTE_STRING "Paste"
79 #define POPUP_SELECT_STRING "Select"
80 #define POPUP_SELECT_ALL_STRING "Select All"
81 #define POPUP_CLIPBOARD_STRING "Clipboard"
85 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
86 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
87 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
88 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
89 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
90 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
92 const std::string IDS_LTR( "IDS_LTR" );
93 const std::string RTL_DIRECTION( "RTL" );
97 return Toolkit::TextSelectionPopup::New( NULL );
100 // Setup properties, signals and actions using the type-registry.
102 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "backgroundBorder", MAP, BACKGROUND_BORDER )
123 DALI_TYPE_REGISTRATION_END()
128 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
130 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
132 // Create the implementation, temporarily owned by this handle on stack
133 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
135 // Pass ownership to CustomActor handle
136 Dali::Toolkit::TextSelectionPopup handle( *impl );
138 // Second-phase init of the implementation
139 // This can only be done after the CustomActor connection has been made...
145 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
151 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
155 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
157 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
160 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
162 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
165 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
167 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
170 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
172 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
175 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
177 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
178 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
181 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
183 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
184 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
187 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
189 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
190 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
193 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
195 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
196 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
199 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
201 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
202 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
205 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
207 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
208 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
211 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
213 impl.mDividerColor = value.Get< Vector4 >();
216 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
218 impl.mIconColor = value.Get< Vector4 >();
221 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
223 impl.mPressedColor = value.Get< Vector4 >();
226 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
228 impl.SetPressedImage( value.Get< std::string >() );
231 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
233 impl.mFadeInDuration = value.Get < float >();
236 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
238 impl.mFadeOutDuration = value.Get < float >();
241 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
243 Property::Map map = value.Get<Property::Map>();
244 impl.CreateBackgroundBorder( map );
248 } // TextSelectionPopup
251 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
253 Property::Value value;
255 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
259 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
263 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
265 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
268 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
270 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
273 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
275 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
278 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
280 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
283 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
285 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
288 value = image.GetUrl();
292 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
294 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
297 value = image.GetUrl();
301 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
303 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
306 value = image.GetUrl();
310 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
312 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
315 value = image.GetUrl();
319 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
321 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
324 value = image.GetUrl();
328 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
330 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
333 value = image.GetUrl();
337 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
339 value = impl.GetPressedImage();
342 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
344 value = impl.mFadeInDuration;
347 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
349 value = impl.mFadeOutDuration;
352 case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
355 Toolkit::Visual::Base visual = impl.GetVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
358 visual.CreatePropertyMap( map );
368 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
370 mEnabledButtons = buttonsToEnable;
371 mButtonsChanged = true;
374 void TextSelectionPopup::RaiseAbove( Layer target )
378 mToolbar.RaiseAbove( target );
382 void TextSelectionPopup::ShowPopup()
384 if( ( !mPopupShowing || mButtonsChanged ) &&
385 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
388 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
390 Animation animation = Animation::New( mFadeInDuration );
391 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
393 mPopupShowing = true;
397 void TextSelectionPopup::HidePopup()
401 mPopupShowing = false;
403 Animation animation = Animation::New( mFadeOutDuration );
404 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
405 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
410 void TextSelectionPopup::OnInitialize()
412 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
414 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
415 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
417 // The Popup Control background is a nine-patch image. We clip against this so the
418 // contents are correctly clipped against the edges of the nine-patch.
419 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
422 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
425 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
427 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
428 UnparentAndReset( mToolbar );
432 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
434 if( mCallbackInterface )
436 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
442 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
444 if( mCallbackInterface )
446 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
452 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
454 if( mCallbackInterface )
456 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
462 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
464 if( mCallbackInterface )
466 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
472 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
474 if( mCallbackInterface )
476 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
482 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
484 if( mCallbackInterface )
486 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
492 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
494 switch( settingToCustomise )
496 case POPUP_MAXIMUM_SIZE :
498 mPopupMaxSize = dimension;
501 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
505 case OPTION_MAXIMUM_SIZE :
507 mOptionMaxSize = dimension;
508 // Option max size not currently currently supported
511 case OPTION_MINIMUM_SIZE :
513 mOptionMinSize = dimension;
514 // Option min size not currently currently supported
517 case OPTION_DIVIDER_SIZE :
519 mOptionDividerSize = dimension;
522 // Resize Dividers not currently supported
529 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
531 switch( settingToCustomise )
533 case POPUP_MAXIMUM_SIZE :
537 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
541 return mPopupMaxSize;
544 case OPTION_MAXIMUM_SIZE :
546 return mOptionMaxSize;
548 case OPTION_MINIMUM_SIZE :
550 return mOptionMinSize;
552 case OPTION_DIVIDER_SIZE :
554 return mOptionDividerSize;
561 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
566 case Toolkit::TextSelectionPopup::CLIPBOARD:
568 mClipboardIconImage = image;
571 case Toolkit::TextSelectionPopup::CUT :
573 mCutIconImage = image;
576 case Toolkit::TextSelectionPopup::COPY :
578 mCopyIconImage = image;
581 case Toolkit::TextSelectionPopup::PASTE :
583 mPasteIconImage = image;
586 case Toolkit::TextSelectionPopup::SELECT :
588 mSelectIconImage = image;
591 case Toolkit::TextSelectionPopup::SELECT_ALL :
593 mSelectAllIconImage = image;
598 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
603 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
607 case Toolkit::TextSelectionPopup::CLIPBOARD :
609 return mClipboardIconImage;
612 case Toolkit::TextSelectionPopup::CUT :
614 return mCutIconImage;
617 case Toolkit::TextSelectionPopup::COPY :
619 return mCopyIconImage;
622 case Toolkit::TextSelectionPopup::PASTE :
624 return mPasteIconImage;
627 case Toolkit::TextSelectionPopup::SELECT :
629 return mSelectIconImage;
632 case Toolkit::TextSelectionPopup::SELECT_ALL :
634 return mSelectAllIconImage;
639 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
643 return Dali::Image();
646 void TextSelectionPopup::SetPressedImage( const std::string& filename )
648 mPressedImage = filename;
651 std::string TextSelectionPopup::GetPressedImage() const
653 return mPressedImage;
656 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
658 mOrderListOfButtons.clear();
659 mOrderListOfButtons.reserve( 8u );
661 // Create button for each possible option using Option priority
662 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
663 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
664 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
665 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
666 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
667 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
669 // Sort the buttons according their priorities.
670 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
673 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
675 // 1. Create a option.
676 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
678 Toolkit::PushButton option = Toolkit::PushButton::New();
679 option.SetName( button.name );
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( Toolkit::TextVisual::Property::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.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, "" );
745 // 4. Set the pressed option image.
746 // The image can be blank, the color can be used regardless.
747 option.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, 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 UnregisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER );
846 if( ! propertyMap.Empty() )
848 Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
852 RegisterVisual( Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER, visual );
853 visual.SetDepthIndex( 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