2 * Copyright (c) 2015 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>
22 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
23 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
24 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
25 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/images/nine-patch-image.h>
30 #include <dali/public-api/images/resource-image.h>
31 #include <dali/public-api/math/vector2.h>
32 #include <dali/public-api/math/vector4.h>
33 #include <dali/devel-api/object/type-registry-helper.h>
49 // todo Move this to adaptor??
50 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
52 const std::string TEXT_SELECTION_POPUP_LABEL( "textselectionpopuplabel" );
53 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
55 #ifdef DGETTEXT_ENABLED
57 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
58 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
59 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
60 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
61 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
62 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
66 #define POPUP_CUT_STRING "Cut"
67 #define POPUP_COPY_STRING "Copy"
68 #define POPUP_PASTE_STRING "Paste"
69 #define POPUP_SELECT_STRING "Select"
70 #define POPUP_SELECT_ALL_STRING "Select All"
71 #define POPUP_CLIPBOARD_STRING "Clipboard"
75 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
76 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
77 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
78 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
79 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
80 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
84 return Toolkit::TextSelectionPopup::New( NULL );
87 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, POPUP_DIVIDER_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, POPUP_ICON_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, POPUP_PRESSED_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-image", STRING, POPUP_PRESSED_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-fade-in-duration", FLOAT, POPUP_FADE_IN_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-fade-out-duration", FLOAT, POPUP_FADE_OUT_DURATION )
109 DALI_TYPE_REGISTRATION_END()
114 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
116 // Create the implementation, temporarily owned by this handle on stack
117 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
119 // Pass ownership to CustomActor handle
120 Dali::Toolkit::TextSelectionPopup handle( *impl );
122 // Second-phase init of the implementation
123 // This can only be done after the CustomActor connection has been made...
129 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
131 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
135 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
139 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
141 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
144 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
146 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
149 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
151 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
154 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
156 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
159 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
161 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
162 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
165 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
167 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
168 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
171 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
173 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
174 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
177 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
179 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
180 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
183 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
185 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
186 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
189 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
191 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
192 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
195 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
197 impl.mDividerColor = value.Get< Vector4 >();
200 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
202 impl.mIconColor = value.Get< Vector4 >();
205 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
207 impl.mPressedColor = value.Get< Vector4 >();
210 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
212 impl.SetPressedImage( value.Get< std::string >() );
215 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
217 impl.mFadeInDuration = value.Get < float >();
220 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
222 impl.mFadeOutDuration = value.Get < float >();
226 } // TextSelectionPopup
229 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
231 Property::Value value;
233 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
237 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
241 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
243 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
246 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
248 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
251 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
253 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
256 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
258 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
261 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
263 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
266 value = image.GetUrl();
270 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
272 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
275 value = image.GetUrl();
279 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
281 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
284 value = image.GetUrl();
288 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
290 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
293 value = image.GetUrl();
297 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
299 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
302 value = image.GetUrl();
306 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
308 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
311 value = image.GetUrl();
315 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
317 value = impl.GetPressedImage();
320 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
322 value = impl.mFadeInDuration;
325 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
327 value = impl.mFadeOutDuration;
335 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
337 mEnabledButtons = buttonsToEnable;
338 mButtonsChanged = true;
341 void TextSelectionPopup::RaiseAbove( Layer target )
345 mToolbar.RaiseAbove( target );
349 void TextSelectionPopup::ShowPopup()
351 if ( !mPopupShowing || mButtonsChanged )
354 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
356 Animation animation = Animation::New( mFadeInDuration );
357 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
359 mPopupShowing = true;
363 void TextSelectionPopup::HidePopup()
367 mPopupShowing = false;
369 Animation animation = Animation::New( mFadeOutDuration );
370 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
371 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
376 void TextSelectionPopup::OnInitialize()
379 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
380 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
383 void TextSelectionPopup::OnStageConnection( int depth )
385 // Call the Control::OnStageConnection() to set the depth of the background.
386 Control::OnStageConnection( depth );
388 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
391 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
394 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
396 UnparentAndReset( self ); // Popup needs to be shown so do not unparent
400 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
402 if( mCallbackInterface )
404 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
410 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
412 if( mCallbackInterface )
414 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
420 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
422 if( mCallbackInterface )
424 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
430 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
432 if( mCallbackInterface )
434 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
440 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
442 if( mCallbackInterface )
444 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
450 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
452 if( mCallbackInterface )
454 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
460 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
462 switch( settingToCustomise )
464 case POPUP_MAXIMUM_SIZE :
466 mPopupMaxSize = dimension;
469 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
473 case OPTION_MAXIMUM_SIZE :
475 mOptionMaxSize = dimension;
476 // Option max size not currently currently supported
479 case OPTION_MINIMUM_SIZE :
481 mOptionMinSize = dimension;
482 // Option min size not currently currently supported
485 case OPTION_DIVIDER_SIZE :
487 mOptionDividerSize = dimension;
490 // Resize Dividers not currently supported
497 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
499 switch( settingToCustomise )
501 case POPUP_MAXIMUM_SIZE :
505 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
509 return mPopupMaxSize;
512 case OPTION_MAXIMUM_SIZE :
514 return mOptionMaxSize;
516 case OPTION_MINIMUM_SIZE :
518 return mOptionMinSize;
520 case OPTION_DIVIDER_SIZE :
522 return mOptionDividerSize;
529 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
534 case Toolkit::TextSelectionPopup::CLIPBOARD:
536 mClipboardIconImage = image;
539 case Toolkit::TextSelectionPopup::CUT :
541 mCutIconImage = image;
544 case Toolkit::TextSelectionPopup::COPY :
546 mCopyIconImage = image;
549 case Toolkit::TextSelectionPopup::PASTE :
551 mPasteIconImage = image;
554 case Toolkit::TextSelectionPopup::SELECT :
556 mSelectIconImage = image;
559 case Toolkit::TextSelectionPopup::SELECT_ALL :
561 mSelectAllIconImage = image;
566 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
571 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
575 case Toolkit::TextSelectionPopup::CLIPBOARD :
577 return mClipboardIconImage;
580 case Toolkit::TextSelectionPopup::CUT :
582 return mCutIconImage;
585 case Toolkit::TextSelectionPopup::COPY :
587 return mCopyIconImage;
590 case Toolkit::TextSelectionPopup::PASTE :
592 return mPasteIconImage;
595 case Toolkit::TextSelectionPopup::SELECT :
597 return mSelectIconImage;
600 case Toolkit::TextSelectionPopup::SELECT_ALL :
602 return mSelectAllIconImage;
607 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
611 return Dali::Image();
614 void TextSelectionPopup::SetPressedImage( const std::string& filename )
616 mPressedImage = filename;
619 std::string TextSelectionPopup::GetPressedImage() const
621 return mPressedImage;
624 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
626 mOrderListOfButtons.clear();
627 mOrderListOfButtons.reserve( 8u );
629 // Create button for each possible option using Option priority
630 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
631 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
632 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
633 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
634 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
635 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
637 // Sort the buttons according their priorities.
638 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
641 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
643 // 1. Create a option.
644 Toolkit::PushButton option = Toolkit::PushButton::New();
645 option.SetName( button.name );
646 option.SetAnimationTime( 0.0f );
647 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
651 case Toolkit::TextSelectionPopup::CUT:
653 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
656 case Toolkit::TextSelectionPopup::COPY:
658 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
661 case Toolkit::TextSelectionPopup::PASTE:
663 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
666 case Toolkit::TextSelectionPopup::SELECT:
668 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
671 case Toolkit::TextSelectionPopup::SELECT_ALL:
673 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
676 case Toolkit::TextSelectionPopup::CLIPBOARD:
678 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
681 case Toolkit::TextSelectionPopup::NONE:
688 // 2. Set the options contents.
691 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
692 option.SetLabelText( button.caption );
696 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
697 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
699 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
700 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
701 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
704 // 3. Set the normal option image (blank / Transparent).
705 option.SetUnselectedImage( "" );
707 // 4. Set the pressed option image.
708 // The image can be blank, the color can be used regardless.
709 option.SetSelectedImage( mPressedImage );
710 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
712 // 5 Add option to tool bar
713 mToolbar.AddOption( option );
715 // 6. Add the divider
718 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
720 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
721 #ifdef DECORATOR_DEBUG
722 divider.SetName("Text's popup divider");
724 divider.SetSize( size );
725 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
726 divider.SetColor( mDividerColor );
727 divider.SetSortModifier( DECORATION_DEPTH_INDEX );
728 mToolbar.AddDivider( divider );
732 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
734 std::size_t numberOfOptions = 0u;
735 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
737 const ButtonRequirement& button( *it );
744 return numberOfOptions;
747 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
749 CreateOrderedListOfPopupOptions();
751 mButtonsChanged = false;
752 UnparentAndReset( mToolbar);
757 mToolbar = Toolkit::TextSelectionToolbar::New();
758 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
760 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
762 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
763 #ifdef DECORATOR_DEBUG
764 mToolbar.SetName("TextSelectionToolbar");
766 self.Add( mToolbar );
769 // Iterate list of buttons and add active ones to Toolbar
770 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
771 std::size_t numberOfOptionsAdded = 0u;
772 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
774 const ButtonRequirement& button( *it );
775 if ( button.enabled )
777 numberOfOptionsAdded++;
778 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
783 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
784 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
789 mOptionDividerSize(),
790 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
791 mCallbackInterface( callbackInterface ),
792 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
793 mDividerColor( Color::WHITE ),
794 mIconColor( Color::WHITE ),
795 mSelectOptionPriority( 1 ),
796 mSelectAllOptionPriority ( 2 ),
797 mCutOptionPriority ( 4 ),
798 mCopyOptionPriority ( 3 ),
799 mPasteOptionPriority ( 5 ),
800 mClipboardOptionPriority( 6 ),
801 mFadeInDuration(0.0f),
802 mFadeOutDuration(0.0f),
804 mShowCaptions( true ),
805 mPopupShowing( false ),
806 mButtonsChanged( false )
810 TextSelectionPopup::~TextSelectionPopup()
815 } // namespace Internal
817 } // namespace Toolkit