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>
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/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
37 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
38 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
51 // todo Move this to adaptor??
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.
90 return Toolkit::TextSelectionPopup::New( NULL );
93 // Setup properties, signals and actions using the type-registry.
95 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
115 DALI_TYPE_REGISTRATION_END()
120 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
122 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
124 // Create the implementation, temporarily owned by this handle on stack
125 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
127 // Pass ownership to CustomActor handle
128 Dali::Toolkit::TextSelectionPopup handle( *impl );
130 // Second-phase init of the implementation
131 // This can only be done after the CustomActor connection has been made...
137 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
139 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
143 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
147 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
149 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
152 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
154 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
157 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
159 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
162 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
164 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
167 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
169 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
170 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
173 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
175 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
176 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
179 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
181 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
182 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
185 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
187 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
188 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
191 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
193 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
194 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
197 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
199 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
200 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
203 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
205 impl.mDividerColor = value.Get< Vector4 >();
208 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
210 impl.mIconColor = value.Get< Vector4 >();
213 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
215 impl.mPressedColor = value.Get< Vector4 >();
218 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
220 impl.SetPressedImage( value.Get< std::string >() );
223 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
225 impl.mFadeInDuration = value.Get < float >();
228 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
230 impl.mFadeOutDuration = value.Get < float >();
234 } // TextSelectionPopup
237 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
239 Property::Value value;
241 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
245 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
249 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
251 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
254 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
256 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
259 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
261 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
264 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
266 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
269 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
271 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
274 value = image.GetUrl();
278 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
280 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
283 value = image.GetUrl();
287 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
289 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
292 value = image.GetUrl();
296 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
298 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
301 value = image.GetUrl();
305 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
307 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
310 value = image.GetUrl();
314 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
316 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
319 value = image.GetUrl();
323 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
325 value = impl.GetPressedImage();
328 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
330 value = impl.mFadeInDuration;
333 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
335 value = impl.mFadeOutDuration;
343 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
345 mEnabledButtons = buttonsToEnable;
346 mButtonsChanged = true;
349 void TextSelectionPopup::RaiseAbove( Layer target )
353 mToolbar.RaiseAbove( target );
357 void TextSelectionPopup::ShowPopup()
359 if( ( !mPopupShowing || mButtonsChanged ) &&
360 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
363 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
365 Animation animation = Animation::New( mFadeInDuration );
366 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
368 mPopupShowing = true;
372 void TextSelectionPopup::HidePopup()
376 mPopupShowing = false;
378 Animation animation = Animation::New( mFadeOutDuration );
379 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
380 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
385 void TextSelectionPopup::OnInitialize()
387 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
389 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
390 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
392 // The Popup Control background is a nine-patch image. We clip against this so the
393 // contents are correctly clipped against the edges of the nine-patch.
394 self.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
397 void TextSelectionPopup::OnStageConnection( int depth )
399 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnStageConnection\n" );
400 // Call the Control::OnStageConnection() to set the depth of the background.
401 Control::OnStageConnection( depth );
403 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
406 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
409 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
411 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
412 UnparentAndReset( mToolbar );
416 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
418 if( mCallbackInterface )
420 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
426 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
428 if( mCallbackInterface )
430 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
436 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
438 if( mCallbackInterface )
440 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
446 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
448 if( mCallbackInterface )
450 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
456 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
458 if( mCallbackInterface )
460 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
466 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
468 if( mCallbackInterface )
470 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
476 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
478 switch( settingToCustomise )
480 case POPUP_MAXIMUM_SIZE :
482 mPopupMaxSize = dimension;
485 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
489 case OPTION_MAXIMUM_SIZE :
491 mOptionMaxSize = dimension;
492 // Option max size not currently currently supported
495 case OPTION_MINIMUM_SIZE :
497 mOptionMinSize = dimension;
498 // Option min size not currently currently supported
501 case OPTION_DIVIDER_SIZE :
503 mOptionDividerSize = dimension;
506 // Resize Dividers not currently supported
513 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
515 switch( settingToCustomise )
517 case POPUP_MAXIMUM_SIZE :
521 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
525 return mPopupMaxSize;
528 case OPTION_MAXIMUM_SIZE :
530 return mOptionMaxSize;
532 case OPTION_MINIMUM_SIZE :
534 return mOptionMinSize;
536 case OPTION_DIVIDER_SIZE :
538 return mOptionDividerSize;
545 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
550 case Toolkit::TextSelectionPopup::CLIPBOARD:
552 mClipboardIconImage = image;
555 case Toolkit::TextSelectionPopup::CUT :
557 mCutIconImage = image;
560 case Toolkit::TextSelectionPopup::COPY :
562 mCopyIconImage = image;
565 case Toolkit::TextSelectionPopup::PASTE :
567 mPasteIconImage = image;
570 case Toolkit::TextSelectionPopup::SELECT :
572 mSelectIconImage = image;
575 case Toolkit::TextSelectionPopup::SELECT_ALL :
577 mSelectAllIconImage = image;
582 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
587 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
591 case Toolkit::TextSelectionPopup::CLIPBOARD :
593 return mClipboardIconImage;
596 case Toolkit::TextSelectionPopup::CUT :
598 return mCutIconImage;
601 case Toolkit::TextSelectionPopup::COPY :
603 return mCopyIconImage;
606 case Toolkit::TextSelectionPopup::PASTE :
608 return mPasteIconImage;
611 case Toolkit::TextSelectionPopup::SELECT :
613 return mSelectIconImage;
616 case Toolkit::TextSelectionPopup::SELECT_ALL :
618 return mSelectAllIconImage;
623 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
627 return Dali::Image();
630 void TextSelectionPopup::SetPressedImage( const std::string& filename )
632 mPressedImage = filename;
635 std::string TextSelectionPopup::GetPressedImage() const
637 return mPressedImage;
640 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
642 mOrderListOfButtons.clear();
643 mOrderListOfButtons.reserve( 8u );
645 // Create button for each possible option using Option priority
646 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
647 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
648 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
649 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
650 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
651 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
653 // Sort the buttons according their priorities.
654 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
657 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
659 // 1. Create a option.
660 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
662 Toolkit::PushButton option = Toolkit::PushButton::New();
663 option.SetName( button.name );
664 option.SetAnimationTime( 0.0f );
665 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
669 case Toolkit::TextSelectionPopup::CUT:
671 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
674 case Toolkit::TextSelectionPopup::COPY:
676 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
679 case Toolkit::TextSelectionPopup::PASTE:
681 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
684 case Toolkit::TextSelectionPopup::SELECT:
686 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
689 case Toolkit::TextSelectionPopup::SELECT_ALL:
691 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
694 case Toolkit::TextSelectionPopup::CLIPBOARD:
696 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
699 case Toolkit::TextSelectionPopup::NONE:
706 // 2. Set the options contents.
709 // PushButton layout properties.
710 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
713 Property::Map buttonLabelProperties;
714 buttonLabelProperties.Insert( Toolkit::TextVisual::Property::TEXT, button.caption );
715 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
719 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
720 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
722 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
723 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
724 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
727 // 3. Set the normal option image (blank / Transparent).
728 option.SetUnselectedImage( "" );
730 // 4. Set the pressed option image.
731 // The image can be blank, the color can be used regardless.
732 option.SetSelectedImage( mPressedImage );
733 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
734 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
736 // 5 Add option to tool bar
737 mToolbar.AddOption( option );
739 // 6. Add the divider
742 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
744 Toolkit::Control divider = Toolkit::Control::New();
745 #ifdef DECORATOR_DEBUG
746 divider.SetName("Text's popup divider");
748 divider.SetSize( size );
749 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
750 divider.SetBackgroundColor( mDividerColor );
751 mToolbar.AddDivider( divider );
755 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
757 std::size_t numberOfOptions = 0u;
758 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
760 const ButtonRequirement& button( *it );
767 return numberOfOptions;
770 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
772 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
774 CreateOrderedListOfPopupOptions();
776 mButtonsChanged = false;
777 UnparentAndReset( mToolbar);
782 mToolbar = Toolkit::TextSelectionToolbar::New();
783 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
785 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
787 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
788 #ifdef DECORATOR_DEBUG
789 mToolbar.SetName("TextSelectionToolbar");
791 self.Add( mToolbar );
794 // Iterate list of buttons and add active ones to Toolbar
795 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
796 std::size_t numberOfOptionsAdded = 0u;
797 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
799 const ButtonRequirement& button( *it );
800 if ( button.enabled )
802 numberOfOptionsAdded++;
803 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
808 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
809 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
814 mOptionDividerSize(),
815 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
816 mCallbackInterface( callbackInterface ),
817 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
818 mDividerColor( Color::WHITE ),
819 mIconColor( Color::WHITE ),
820 mSelectOptionPriority( 1 ),
821 mSelectAllOptionPriority ( 2 ),
822 mCutOptionPriority ( 4 ),
823 mCopyOptionPriority ( 3 ),
824 mPasteOptionPriority ( 5 ),
825 mClipboardOptionPriority( 6 ),
826 mFadeInDuration(0.0f),
827 mFadeOutDuration(0.0f),
829 mShowCaptions( true ),
830 mPopupShowing( false ),
831 mButtonsChanged( false )
835 TextSelectionPopup::~TextSelectionPopup()
840 } // namespace Internal
842 } // namespace Toolkit