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>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-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>
49 // todo Move this to adaptor??
50 #define GET_LOCALE_TEXT(string) dgettext("dali-toolkit", string)
52 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "textselectionpopupbutton" );
53 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
59 #ifdef DGETTEXT_ENABLED
61 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
62 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
63 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
64 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
65 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
66 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
70 #define POPUP_CUT_STRING "Cut"
71 #define POPUP_COPY_STRING "Copy"
72 #define POPUP_PASTE_STRING "Paste"
73 #define POPUP_SELECT_STRING "Select"
74 #define POPUP_SELECT_ALL_STRING "Select All"
75 #define POPUP_CLIPBOARD_STRING "Clipboard"
79 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
80 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
81 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
82 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
83 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
84 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
88 return Toolkit::TextSelectionPopup::New( NULL );
91 // Setup properties, signals and actions using the type-registry.
93 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
113 DALI_TYPE_REGISTRATION_END()
118 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
120 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
122 // Create the implementation, temporarily owned by this handle on stack
123 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
125 // Pass ownership to CustomActor handle
126 Dali::Toolkit::TextSelectionPopup handle( *impl );
128 // Second-phase init of the implementation
129 // This can only be done after the CustomActor connection has been made...
135 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
137 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
141 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
145 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
147 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
150 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
152 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
155 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
157 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
160 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
162 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
165 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
167 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
168 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
171 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
173 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
174 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
177 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
179 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
180 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
183 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
185 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
186 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
189 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
191 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
192 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
195 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
197 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
198 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
201 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
203 impl.mDividerColor = value.Get< Vector4 >();
206 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
208 impl.mIconColor = value.Get< Vector4 >();
211 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
213 impl.mPressedColor = value.Get< Vector4 >();
216 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
218 impl.SetPressedImage( value.Get< std::string >() );
221 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
223 impl.mFadeInDuration = value.Get < float >();
226 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
228 impl.mFadeOutDuration = value.Get < float >();
232 } // TextSelectionPopup
235 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
237 Property::Value value;
239 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
243 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
247 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
249 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
252 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
254 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
257 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
259 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
262 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
264 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
267 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
269 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
272 value = image.GetUrl();
276 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
278 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
281 value = image.GetUrl();
285 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
287 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
290 value = image.GetUrl();
294 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
296 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
299 value = image.GetUrl();
303 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
305 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
308 value = image.GetUrl();
312 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
314 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
317 value = image.GetUrl();
321 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
323 value = impl.GetPressedImage();
326 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
328 value = impl.mFadeInDuration;
331 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
333 value = impl.mFadeOutDuration;
341 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
343 mEnabledButtons = buttonsToEnable;
344 mButtonsChanged = true;
347 void TextSelectionPopup::RaiseAbove( Layer target )
351 mToolbar.RaiseAbove( target );
355 void TextSelectionPopup::ShowPopup()
357 if( ( !mPopupShowing || mButtonsChanged ) &&
358 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
361 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
363 Animation animation = Animation::New( mFadeInDuration );
364 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
366 mPopupShowing = true;
370 void TextSelectionPopup::HidePopup()
374 mPopupShowing = false;
376 Animation animation = Animation::New( mFadeOutDuration );
377 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
378 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
383 void TextSelectionPopup::OnInitialize()
385 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
387 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
388 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
391 void TextSelectionPopup::OnStageConnection( int depth )
393 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnStageConnection\n" );
394 // Call the Control::OnStageConnection() to set the depth of the background.
395 Control::OnStageConnection( depth );
397 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
400 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
403 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
405 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
406 UnparentAndReset( mToolbar );
410 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
412 if( mCallbackInterface )
414 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
420 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
422 if( mCallbackInterface )
424 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
430 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
432 if( mCallbackInterface )
434 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
440 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
442 if( mCallbackInterface )
444 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
450 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
452 if( mCallbackInterface )
454 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
460 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
462 if( mCallbackInterface )
464 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
470 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
472 switch( settingToCustomise )
474 case POPUP_MAXIMUM_SIZE :
476 mPopupMaxSize = dimension;
479 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
483 case OPTION_MAXIMUM_SIZE :
485 mOptionMaxSize = dimension;
486 // Option max size not currently currently supported
489 case OPTION_MINIMUM_SIZE :
491 mOptionMinSize = dimension;
492 // Option min size not currently currently supported
495 case OPTION_DIVIDER_SIZE :
497 mOptionDividerSize = dimension;
500 // Resize Dividers not currently supported
507 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
509 switch( settingToCustomise )
511 case POPUP_MAXIMUM_SIZE :
515 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
519 return mPopupMaxSize;
522 case OPTION_MAXIMUM_SIZE :
524 return mOptionMaxSize;
526 case OPTION_MINIMUM_SIZE :
528 return mOptionMinSize;
530 case OPTION_DIVIDER_SIZE :
532 return mOptionDividerSize;
539 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
544 case Toolkit::TextSelectionPopup::CLIPBOARD:
546 mClipboardIconImage = image;
549 case Toolkit::TextSelectionPopup::CUT :
551 mCutIconImage = image;
554 case Toolkit::TextSelectionPopup::COPY :
556 mCopyIconImage = image;
559 case Toolkit::TextSelectionPopup::PASTE :
561 mPasteIconImage = image;
564 case Toolkit::TextSelectionPopup::SELECT :
566 mSelectIconImage = image;
569 case Toolkit::TextSelectionPopup::SELECT_ALL :
571 mSelectAllIconImage = image;
576 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
581 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
585 case Toolkit::TextSelectionPopup::CLIPBOARD :
587 return mClipboardIconImage;
590 case Toolkit::TextSelectionPopup::CUT :
592 return mCutIconImage;
595 case Toolkit::TextSelectionPopup::COPY :
597 return mCopyIconImage;
600 case Toolkit::TextSelectionPopup::PASTE :
602 return mPasteIconImage;
605 case Toolkit::TextSelectionPopup::SELECT :
607 return mSelectIconImage;
610 case Toolkit::TextSelectionPopup::SELECT_ALL :
612 return mSelectAllIconImage;
617 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
621 return Dali::Image();
624 void TextSelectionPopup::SetPressedImage( const std::string& filename )
626 mPressedImage = filename;
629 std::string TextSelectionPopup::GetPressedImage() const
631 return mPressedImage;
634 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
636 mOrderListOfButtons.clear();
637 mOrderListOfButtons.reserve( 8u );
639 // Create button for each possible option using Option priority
640 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
641 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
642 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
643 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
644 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
645 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, 0 != ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
647 // Sort the buttons according their priorities.
648 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
651 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
653 // 1. Create a option.
654 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
656 Toolkit::PushButton option = Toolkit::PushButton::New();
657 option.SetName( button.name );
658 option.SetAnimationTime( 0.0f );
659 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
663 case Toolkit::TextSelectionPopup::CUT:
665 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
668 case Toolkit::TextSelectionPopup::COPY:
670 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
673 case Toolkit::TextSelectionPopup::PASTE:
675 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
678 case Toolkit::TextSelectionPopup::SELECT:
680 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
683 case Toolkit::TextSelectionPopup::SELECT_ALL:
685 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
688 case Toolkit::TextSelectionPopup::CLIPBOARD:
690 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
693 case Toolkit::TextSelectionPopup::NONE:
700 // 2. Set the options contents.
703 // PushButton layout properties.
704 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
707 Property::Map buttonLabelProperties;
708 buttonLabelProperties.Insert( "text", button.caption );
709 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
713 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
716 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
717 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
718 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
721 // 3. Set the normal option image (blank / Transparent).
722 option.SetUnselectedImage( "" );
724 // 4. Set the pressed option image.
725 // The image can be blank, the color can be used regardless.
726 option.SetSelectedImage( mPressedImage );
727 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
728 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
730 // 5 Add option to tool bar
731 mToolbar.AddOption( option );
733 // 6. Add the divider
736 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
738 Toolkit::Control divider = Toolkit::Control::New();
739 #ifdef DECORATOR_DEBUG
740 divider.SetName("Text's popup divider");
742 divider.SetSize( size );
743 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
744 divider.SetBackgroundColor( mDividerColor );
745 mToolbar.AddDivider( divider );
749 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
751 std::size_t numberOfOptions = 0u;
752 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
754 const ButtonRequirement& button( *it );
761 return numberOfOptions;
764 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
766 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
768 CreateOrderedListOfPopupOptions();
770 mButtonsChanged = false;
771 UnparentAndReset( mToolbar);
776 mToolbar = Toolkit::TextSelectionToolbar::New();
777 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
779 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
781 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
782 #ifdef DECORATOR_DEBUG
783 mToolbar.SetName("TextSelectionToolbar");
785 self.Add( mToolbar );
788 // Iterate list of buttons and add active ones to Toolbar
789 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
790 std::size_t numberOfOptionsAdded = 0u;
791 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
793 const ButtonRequirement& button( *it );
794 if ( button.enabled )
796 numberOfOptionsAdded++;
797 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
802 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
803 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
808 mOptionDividerSize(),
809 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
810 mCallbackInterface( callbackInterface ),
811 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
812 mDividerColor( Color::WHITE ),
813 mIconColor( Color::WHITE ),
814 mSelectOptionPriority( 1 ),
815 mSelectAllOptionPriority ( 2 ),
816 mCutOptionPriority ( 4 ),
817 mCopyOptionPriority ( 3 ),
818 mPasteOptionPriority ( 5 ),
819 mClipboardOptionPriority( 6 ),
820 mFadeInDuration(0.0f),
821 mFadeOutDuration(0.0f),
823 mShowCaptions( true ),
824 mPopupShowing( false ),
825 mButtonsChanged( false )
829 TextSelectionPopup::~TextSelectionPopup()
834 } // namespace Internal
836 } // namespace Toolkit