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/public-api/object/property-map.h>
34 #include <dali/devel-api/object/type-registry-helper.h>
50 // todo Move this to adaptor??
51 #define GET_LOCALE_TEXT(string) dgettext("elementary", 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 #ifdef DGETTEXT_ENABLED
58 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
59 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
60 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
61 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
62 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
63 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
67 #define POPUP_CUT_STRING "Cut"
68 #define POPUP_COPY_STRING "Copy"
69 #define POPUP_PASTE_STRING "Paste"
70 #define POPUP_SELECT_STRING "Select"
71 #define POPUP_SELECT_ALL_STRING "Select All"
72 #define POPUP_CLIPBOARD_STRING "Clipboard"
76 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
77 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
78 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
79 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
80 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
81 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
85 return Toolkit::TextSelectionPopup::New( NULL );
88 // Setup properties, signals and actions using the type-registry.
90 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, POPUP_DIVIDER_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, POPUP_ICON_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, POPUP_PRESSED_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-image", STRING, POPUP_PRESSED_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-fade-in-duration", FLOAT, POPUP_FADE_IN_DURATION )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-fade-out-duration", FLOAT, POPUP_FADE_OUT_DURATION )
110 DALI_TYPE_REGISTRATION_END()
115 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
117 // Create the implementation, temporarily owned by this handle on stack
118 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
120 // Pass ownership to CustomActor handle
121 Dali::Toolkit::TextSelectionPopup handle( *impl );
123 // Second-phase init of the implementation
124 // This can only be done after the CustomActor connection has been made...
130 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
132 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
136 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
140 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
142 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
145 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
147 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
150 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
152 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
155 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
157 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
160 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
162 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
163 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
166 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
168 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
169 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
172 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
174 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
175 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
178 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
180 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
181 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
184 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
186 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
187 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
190 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
192 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
193 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
196 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
198 impl.mDividerColor = value.Get< Vector4 >();
201 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
203 impl.mIconColor = value.Get< Vector4 >();
206 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
208 impl.mPressedColor = value.Get< Vector4 >();
211 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
213 impl.SetPressedImage( value.Get< std::string >() );
216 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
218 impl.mFadeInDuration = value.Get < float >();
221 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
223 impl.mFadeOutDuration = value.Get < float >();
227 } // TextSelectionPopup
230 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
232 Property::Value value;
234 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
238 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
242 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
244 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
247 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
249 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
252 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
254 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
257 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
259 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
262 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
264 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
267 value = image.GetUrl();
271 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
273 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
276 value = image.GetUrl();
280 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
282 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
285 value = image.GetUrl();
289 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
291 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
294 value = image.GetUrl();
298 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
300 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
303 value = image.GetUrl();
307 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
309 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
312 value = image.GetUrl();
316 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
318 value = impl.GetPressedImage();
321 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
323 value = impl.mFadeInDuration;
326 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
328 value = impl.mFadeOutDuration;
336 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
338 mEnabledButtons = buttonsToEnable;
339 mButtonsChanged = true;
342 void TextSelectionPopup::RaiseAbove( Layer target )
346 mToolbar.RaiseAbove( target );
350 void TextSelectionPopup::ShowPopup()
352 if ( !mPopupShowing || mButtonsChanged )
355 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
357 Animation animation = Animation::New( mFadeInDuration );
358 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
360 mPopupShowing = true;
364 void TextSelectionPopup::HidePopup()
368 mPopupShowing = false;
370 Animation animation = Animation::New( mFadeOutDuration );
371 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
372 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
377 void TextSelectionPopup::OnInitialize()
380 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
381 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
384 void TextSelectionPopup::OnStageConnection( int depth )
386 // Call the Control::OnStageConnection() to set the depth of the background.
387 Control::OnStageConnection( depth );
389 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
392 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
395 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
397 UnparentAndReset( self ); // Popup needs to be shown so do not unparent
401 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
403 if( mCallbackInterface )
405 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
411 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
413 if( mCallbackInterface )
415 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
421 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
423 if( mCallbackInterface )
425 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
431 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
433 if( mCallbackInterface )
435 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
441 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
443 if( mCallbackInterface )
445 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
451 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
453 if( mCallbackInterface )
455 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
461 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
463 switch( settingToCustomise )
465 case POPUP_MAXIMUM_SIZE :
467 mPopupMaxSize = dimension;
470 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
474 case OPTION_MAXIMUM_SIZE :
476 mOptionMaxSize = dimension;
477 // Option max size not currently currently supported
480 case OPTION_MINIMUM_SIZE :
482 mOptionMinSize = dimension;
483 // Option min size not currently currently supported
486 case OPTION_DIVIDER_SIZE :
488 mOptionDividerSize = dimension;
491 // Resize Dividers not currently supported
498 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
500 switch( settingToCustomise )
502 case POPUP_MAXIMUM_SIZE :
506 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
510 return mPopupMaxSize;
513 case OPTION_MAXIMUM_SIZE :
515 return mOptionMaxSize;
517 case OPTION_MINIMUM_SIZE :
519 return mOptionMinSize;
521 case OPTION_DIVIDER_SIZE :
523 return mOptionDividerSize;
530 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
535 case Toolkit::TextSelectionPopup::CLIPBOARD:
537 mClipboardIconImage = image;
540 case Toolkit::TextSelectionPopup::CUT :
542 mCutIconImage = image;
545 case Toolkit::TextSelectionPopup::COPY :
547 mCopyIconImage = image;
550 case Toolkit::TextSelectionPopup::PASTE :
552 mPasteIconImage = image;
555 case Toolkit::TextSelectionPopup::SELECT :
557 mSelectIconImage = image;
560 case Toolkit::TextSelectionPopup::SELECT_ALL :
562 mSelectAllIconImage = image;
567 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
572 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
576 case Toolkit::TextSelectionPopup::CLIPBOARD :
578 return mClipboardIconImage;
581 case Toolkit::TextSelectionPopup::CUT :
583 return mCutIconImage;
586 case Toolkit::TextSelectionPopup::COPY :
588 return mCopyIconImage;
591 case Toolkit::TextSelectionPopup::PASTE :
593 return mPasteIconImage;
596 case Toolkit::TextSelectionPopup::SELECT :
598 return mSelectIconImage;
601 case Toolkit::TextSelectionPopup::SELECT_ALL :
603 return mSelectAllIconImage;
608 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
612 return Dali::Image();
615 void TextSelectionPopup::SetPressedImage( const std::string& filename )
617 mPressedImage = filename;
620 std::string TextSelectionPopup::GetPressedImage() const
622 return mPressedImage;
625 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
627 mOrderListOfButtons.clear();
628 mOrderListOfButtons.reserve( 8u );
630 // Create button for each possible option using Option priority
631 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
632 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
633 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
634 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
635 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
636 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
638 // Sort the buttons according their priorities.
639 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
642 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
644 // 1. Create a option.
645 Toolkit::PushButton option = Toolkit::PushButton::New();
646 option.SetName( button.name );
647 option.SetAnimationTime( 0.0f );
648 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
652 case Toolkit::TextSelectionPopup::CUT:
654 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
657 case Toolkit::TextSelectionPopup::COPY:
659 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
662 case Toolkit::TextSelectionPopup::PASTE:
664 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
667 case Toolkit::TextSelectionPopup::SELECT:
669 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
672 case Toolkit::TextSelectionPopup::SELECT_ALL:
674 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
677 case Toolkit::TextSelectionPopup::CLIPBOARD:
679 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
682 case Toolkit::TextSelectionPopup::NONE:
689 // 2. Set the options contents.
692 // PushButton layout properties.
693 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
696 Property::Map buttonLabelProperties;
697 buttonLabelProperties.Insert( "text", button.caption );
698 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
702 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
703 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
705 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
706 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
707 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
710 // 3. Set the normal option image (blank / Transparent).
711 option.SetUnselectedImage( "" );
713 // 4. Set the pressed option image.
714 // The image can be blank, the color can be used regardless.
715 option.SetSelectedImage( mPressedImage );
716 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
717 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
719 // 5 Add option to tool bar
720 mToolbar.AddOption( option );
722 // 6. Add the divider
725 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
727 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
728 #ifdef DECORATOR_DEBUG
729 divider.SetName("Text's popup divider");
731 divider.SetSize( size );
732 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
733 divider.SetColor( mDividerColor );
734 divider.SetSortModifier( DECORATION_DEPTH_INDEX );
735 mToolbar.AddDivider( divider );
739 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
741 std::size_t numberOfOptions = 0u;
742 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
744 const ButtonRequirement& button( *it );
751 return numberOfOptions;
754 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
756 CreateOrderedListOfPopupOptions();
758 mButtonsChanged = false;
759 UnparentAndReset( mToolbar);
764 mToolbar = Toolkit::TextSelectionToolbar::New();
765 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
767 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
769 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
770 #ifdef DECORATOR_DEBUG
771 mToolbar.SetName("TextSelectionToolbar");
773 self.Add( mToolbar );
776 // Iterate list of buttons and add active ones to Toolbar
777 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
778 std::size_t numberOfOptionsAdded = 0u;
779 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
781 const ButtonRequirement& button( *it );
782 if ( button.enabled )
784 numberOfOptionsAdded++;
785 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
790 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
791 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
796 mOptionDividerSize(),
797 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
798 mCallbackInterface( callbackInterface ),
799 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
800 mDividerColor( Color::WHITE ),
801 mIconColor( Color::WHITE ),
802 mSelectOptionPriority( 1 ),
803 mSelectAllOptionPriority ( 2 ),
804 mCutOptionPriority ( 4 ),
805 mCopyOptionPriority ( 3 ),
806 mPasteOptionPriority ( 5 ),
807 mClipboardOptionPriority( 6 ),
808 mFadeInDuration(0.0f),
809 mFadeOutDuration(0.0f),
811 mShowCaptions( true ),
812 mPopupShowing( false ),
813 mButtonsChanged( false )
817 TextSelectionPopup::~TextSelectionPopup()
822 } // namespace Internal
824 } // namespace Toolkit