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>
50 // todo Move this to adaptor??
51 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
53 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "TextSelectionPopupButton" );
54 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
60 #ifdef DGETTEXT_ENABLED
62 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
63 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
64 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
65 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
66 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
67 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
71 #define POPUP_CUT_STRING "Cut"
72 #define POPUP_COPY_STRING "Copy"
73 #define POPUP_PASTE_STRING "Paste"
74 #define POPUP_SELECT_STRING "Select"
75 #define POPUP_SELECT_ALL_STRING "Select All"
76 #define POPUP_CLIPBOARD_STRING "Clipboard"
80 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
81 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
82 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
83 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
84 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
85 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
87 const std::string IDS_LTR( "IDS_LTR" );
88 const std::string RTL_DIRECTION( "RTL" );
92 return Toolkit::TextSelectionPopup::New( NULL );
95 // Setup properties, signals and actions using the type-registry.
97 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
117 DALI_TYPE_REGISTRATION_END()
122 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
124 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
126 // Create the implementation, temporarily owned by this handle on stack
127 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
129 // Pass ownership to CustomActor handle
130 Dali::Toolkit::TextSelectionPopup handle( *impl );
132 // Second-phase init of the implementation
133 // This can only be done after the CustomActor connection has been made...
139 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
141 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
145 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
149 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
151 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
154 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
156 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
159 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
161 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
164 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
166 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
169 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
171 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
172 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
175 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
177 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
178 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
181 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
183 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
184 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
187 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
189 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
190 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
193 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
195 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
196 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
199 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
201 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
202 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
205 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
207 impl.mDividerColor = value.Get< Vector4 >();
210 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
212 impl.mIconColor = value.Get< Vector4 >();
215 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
217 impl.mPressedColor = value.Get< Vector4 >();
220 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
222 impl.SetPressedImage( value.Get< std::string >() );
225 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
227 impl.mFadeInDuration = value.Get < float >();
230 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
232 impl.mFadeOutDuration = value.Get < float >();
236 } // TextSelectionPopup
239 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
241 Property::Value value;
243 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
247 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
251 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
253 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
256 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
258 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
261 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
263 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
266 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
268 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
271 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
273 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
276 value = image.GetUrl();
280 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
282 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
285 value = image.GetUrl();
289 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
291 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
294 value = image.GetUrl();
298 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
300 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
303 value = image.GetUrl();
307 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
309 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
312 value = image.GetUrl();
316 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
318 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
321 value = image.GetUrl();
325 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
327 value = impl.GetPressedImage();
330 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
332 value = impl.mFadeInDuration;
335 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
337 value = impl.mFadeOutDuration;
345 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
347 mEnabledButtons = buttonsToEnable;
348 mButtonsChanged = true;
351 void TextSelectionPopup::RaiseAbove( Layer target )
355 mToolbar.RaiseAbove( target );
359 void TextSelectionPopup::ShowPopup()
361 if( ( !mPopupShowing || mButtonsChanged ) &&
362 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
365 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
367 Animation animation = Animation::New( mFadeInDuration );
368 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
370 mPopupShowing = true;
374 void TextSelectionPopup::HidePopup()
378 mPopupShowing = false;
380 Animation animation = Animation::New( mFadeOutDuration );
381 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
382 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
387 void TextSelectionPopup::OnInitialize()
389 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
391 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
392 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
394 // The Popup Control background is a nine-patch image. We clip against this so the
395 // contents are correctly clipped against the edges of the nine-patch.
396 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
399 void TextSelectionPopup::OnStageConnection( int depth )
401 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnStageConnection\n" );
402 // Call the Control::OnStageConnection() to set the depth of the background.
403 Control::OnStageConnection( depth );
405 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
408 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
411 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
413 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
414 UnparentAndReset( mToolbar );
418 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
420 if( mCallbackInterface )
422 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
428 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
430 if( mCallbackInterface )
432 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
438 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
440 if( mCallbackInterface )
442 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
448 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
450 if( mCallbackInterface )
452 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
458 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
460 if( mCallbackInterface )
462 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
468 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
470 if( mCallbackInterface )
472 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
478 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
480 switch( settingToCustomise )
482 case POPUP_MAXIMUM_SIZE :
484 mPopupMaxSize = dimension;
487 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
491 case OPTION_MAXIMUM_SIZE :
493 mOptionMaxSize = dimension;
494 // Option max size not currently currently supported
497 case OPTION_MINIMUM_SIZE :
499 mOptionMinSize = dimension;
500 // Option min size not currently currently supported
503 case OPTION_DIVIDER_SIZE :
505 mOptionDividerSize = dimension;
508 // Resize Dividers not currently supported
515 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
517 switch( settingToCustomise )
519 case POPUP_MAXIMUM_SIZE :
523 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
527 return mPopupMaxSize;
530 case OPTION_MAXIMUM_SIZE :
532 return mOptionMaxSize;
534 case OPTION_MINIMUM_SIZE :
536 return mOptionMinSize;
538 case OPTION_DIVIDER_SIZE :
540 return mOptionDividerSize;
547 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
552 case Toolkit::TextSelectionPopup::CLIPBOARD:
554 mClipboardIconImage = image;
557 case Toolkit::TextSelectionPopup::CUT :
559 mCutIconImage = image;
562 case Toolkit::TextSelectionPopup::COPY :
564 mCopyIconImage = image;
567 case Toolkit::TextSelectionPopup::PASTE :
569 mPasteIconImage = image;
572 case Toolkit::TextSelectionPopup::SELECT :
574 mSelectIconImage = image;
577 case Toolkit::TextSelectionPopup::SELECT_ALL :
579 mSelectAllIconImage = image;
584 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
589 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
593 case Toolkit::TextSelectionPopup::CLIPBOARD :
595 return mClipboardIconImage;
598 case Toolkit::TextSelectionPopup::CUT :
600 return mCutIconImage;
603 case Toolkit::TextSelectionPopup::COPY :
605 return mCopyIconImage;
608 case Toolkit::TextSelectionPopup::PASTE :
610 return mPasteIconImage;
613 case Toolkit::TextSelectionPopup::SELECT :
615 return mSelectIconImage;
618 case Toolkit::TextSelectionPopup::SELECT_ALL :
620 return mSelectAllIconImage;
625 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
629 return Dali::Image();
632 void TextSelectionPopup::SetPressedImage( const std::string& filename )
634 mPressedImage = filename;
637 std::string TextSelectionPopup::GetPressedImage() const
639 return mPressedImage;
642 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
644 mOrderListOfButtons.clear();
645 mOrderListOfButtons.reserve( 8u );
647 // Create button for each possible option using Option priority
648 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
649 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
650 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
651 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
652 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
653 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
655 // Sort the buttons according their priorities.
656 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
659 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
661 // 1. Create a option.
662 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
664 Toolkit::PushButton option = Toolkit::PushButton::New();
665 option.SetName( button.name );
666 option.SetAnimationTime( 0.0f );
667 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
671 case Toolkit::TextSelectionPopup::CUT:
673 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
676 case Toolkit::TextSelectionPopup::COPY:
678 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
681 case Toolkit::TextSelectionPopup::PASTE:
683 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
686 case Toolkit::TextSelectionPopup::SELECT:
688 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
691 case Toolkit::TextSelectionPopup::SELECT_ALL:
693 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
696 case Toolkit::TextSelectionPopup::CLIPBOARD:
698 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
701 case Toolkit::TextSelectionPopup::NONE:
708 // 2. Set the options contents.
711 // PushButton layout properties.
712 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
715 Property::Map buttonLabelProperties;
716 buttonLabelProperties.Insert( "text", button.caption );
717 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
721 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
722 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
724 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
725 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
726 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
729 // 3. Set the normal option image (blank / Transparent).
730 option.SetUnselectedImage( "" );
732 // 4. Set the pressed option image.
733 // The image can be blank, the color can be used regardless.
734 option.SetSelectedImage( mPressedImage );
735 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
736 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
738 // 5 Add option to tool bar
739 mToolbar.AddOption( option );
741 // 6. Add the divider
744 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
746 Toolkit::Control divider = Toolkit::Control::New();
747 #ifdef DECORATOR_DEBUG
748 divider.SetName("Text's popup divider");
750 divider.SetSize( size );
751 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
752 divider.SetBackgroundColor( mDividerColor );
753 mToolbar.AddDivider( divider );
757 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
759 std::size_t numberOfOptions = 0u;
760 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
762 const ButtonRequirement& button( *it );
769 return numberOfOptions;
772 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
774 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
776 CreateOrderedListOfPopupOptions();
778 mButtonsChanged = false;
779 UnparentAndReset( mToolbar);
784 mToolbar = Toolkit::TextSelectionToolbar::New();
785 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
787 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
789 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
790 #ifdef DECORATOR_DEBUG
791 mToolbar.SetName("TextSelectionToolbar");
793 self.Add( mToolbar );
796 // Whether to mirror the list of buttons (for right to left languages)
798 char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
801 mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
805 std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
809 // Iterate list of buttons and add active ones to Toolbar
810 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
811 std::size_t numberOfOptionsAdded = 0u;
812 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
814 const ButtonRequirement& button( *it );
815 if ( button.enabled )
817 numberOfOptionsAdded++;
818 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
824 mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
828 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
829 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
834 mOptionDividerSize(),
835 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
836 mCallbackInterface( callbackInterface ),
837 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
838 mDividerColor( Color::WHITE ),
839 mIconColor( Color::WHITE ),
840 mSelectOptionPriority( 1 ),
841 mSelectAllOptionPriority ( 2 ),
842 mCutOptionPriority ( 4 ),
843 mCopyOptionPriority ( 3 ),
844 mPasteOptionPriority ( 5 ),
845 mClipboardOptionPriority( 6 ),
846 mFadeInDuration(0.0f),
847 mFadeOutDuration(0.0f),
849 mShowCaptions( true ),
850 mPopupShowing( false ),
851 mButtonsChanged( false )
855 TextSelectionPopup::~TextSelectionPopup()
860 } // namespace Internal
862 } // namespace Toolkit