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/devel-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
35 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
50 // todo Move this to adaptor??
51 #define GET_LOCALE_TEXT(string) dgettext("sys_string", string)
53 const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "textselectionpopupbutton" );
54 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
60 #ifdef DGETTEXT_ENABLED
62 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
63 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
64 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
65 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
66 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
67 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
71 #define POPUP_CUT_STRING "Cut"
72 #define POPUP_COPY_STRING "Copy"
73 #define POPUP_PASTE_STRING "Paste"
74 #define POPUP_SELECT_STRING "Select"
75 #define POPUP_SELECT_ALL_STRING "Select All"
76 #define POPUP_CLIPBOARD_STRING "Clipboard"
80 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
81 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
82 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
83 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
84 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
85 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
89 return Toolkit::TextSelectionPopup::New( NULL );
92 // Setup properties, signals and actions using the type-registry.
94 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMaxSize", VECTOR2, POPUP_MAX_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupMinSize", VECTOR2, POPUP_MIN_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMaxSize", VECTOR2, OPTION_MAX_SIZE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionMinSize", VECTOR2, OPTION_MIN_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "optionDividerSize", VECTOR2, OPTION_DIVIDER_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupClipboardButtonImage", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCutButtonImage", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupCopyButtonImage", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPasteButtonImage", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectButtonImage", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupSelectAllButtonImage", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupDividerColor", VECTOR4, POPUP_DIVIDER_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupIconColor", VECTOR4, POPUP_ICON_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedColor", VECTOR4, POPUP_PRESSED_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupPressedImage", STRING, POPUP_PRESSED_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeInDuration", FLOAT, POPUP_FADE_IN_DURATION )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popupFadeOutDuration", FLOAT, POPUP_FADE_OUT_DURATION )
114 DALI_TYPE_REGISTRATION_END()
119 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( TextSelectionPopupCallbackInterface* callbackInterface )
121 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextSelectionPopup::New\n" );
123 // Create the implementation, temporarily owned by this handle on stack
124 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
126 // Pass ownership to CustomActor handle
127 Dali::Toolkit::TextSelectionPopup handle( *impl );
129 // Second-phase init of the implementation
130 // This can only be done after the CustomActor connection has been made...
136 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
138 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
142 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
146 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
148 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
151 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
153 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
156 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
158 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
161 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
163 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
166 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
168 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
169 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
172 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
174 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
175 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
178 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
180 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
181 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
184 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
186 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
187 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
190 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
192 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
193 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
196 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
198 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
199 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
202 case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
204 impl.mDividerColor = value.Get< Vector4 >();
207 case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
209 impl.mIconColor = value.Get< Vector4 >();
212 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
214 impl.mPressedColor = value.Get< Vector4 >();
217 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
219 impl.SetPressedImage( value.Get< std::string >() );
222 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
224 impl.mFadeInDuration = value.Get < float >();
227 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
229 impl.mFadeOutDuration = value.Get < float >();
233 } // TextSelectionPopup
236 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
238 Property::Value value;
240 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
244 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
248 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
250 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
253 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
255 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
258 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
260 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
263 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
265 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
268 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
270 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
273 value = image.GetUrl();
277 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
279 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
282 value = image.GetUrl();
286 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
288 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
291 value = image.GetUrl();
295 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
297 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
300 value = image.GetUrl();
304 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
306 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
309 value = image.GetUrl();
313 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
315 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
318 value = image.GetUrl();
322 case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
324 value = impl.GetPressedImage();
327 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
329 value = impl.mFadeInDuration;
332 case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
334 value = impl.mFadeOutDuration;
342 void TextSelectionPopup::EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
344 mEnabledButtons = buttonsToEnable;
345 mButtonsChanged = true;
348 void TextSelectionPopup::RaiseAbove( Layer target )
352 mToolbar.RaiseAbove( target );
356 void TextSelectionPopup::ShowPopup()
358 if( ( !mPopupShowing || mButtonsChanged ) &&
359 ( Toolkit::TextSelectionPopup::NONE != mEnabledButtons ) )
362 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
364 Animation animation = Animation::New( mFadeInDuration );
365 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 1.0f );
367 mPopupShowing = true;
371 void TextSelectionPopup::HidePopup()
375 mPopupShowing = false;
377 Animation animation = Animation::New( mFadeOutDuration );
378 animation.AnimateTo( Property(self, Actor::Property::COLOR_ALPHA), 0.0f );
379 animation.FinishedSignal().Connect( this, &TextSelectionPopup::HideAnimationFinished );
384 void TextSelectionPopup::OnInitialize()
386 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnInitialize\n" );
388 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
389 self.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
392 void TextSelectionPopup::OnStageConnection( int depth )
394 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::OnStageConnection\n" );
395 // Call the Control::OnStageConnection() to set the depth of the background.
396 Control::OnStageConnection( depth );
398 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
401 void TextSelectionPopup::HideAnimationFinished( Animation& animation )
404 if ( !mPopupShowing ) // During the Hide/Fade animation there could be a call to Show the Popup again, mPopupShowing will be true in this case.
406 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::HideAnimationFinished\n" );
407 UnparentAndReset( mToolbar );
411 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
413 if( mCallbackInterface )
415 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
421 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
423 if( mCallbackInterface )
425 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
431 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
433 if( mCallbackInterface )
435 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
441 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
443 if( mCallbackInterface )
445 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
451 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
453 if( mCallbackInterface )
455 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
461 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
463 if( mCallbackInterface )
465 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
471 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
473 switch( settingToCustomise )
475 case POPUP_MAXIMUM_SIZE :
477 mPopupMaxSize = dimension;
480 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
484 case OPTION_MAXIMUM_SIZE :
486 mOptionMaxSize = dimension;
487 // Option max size not currently currently supported
490 case OPTION_MINIMUM_SIZE :
492 mOptionMinSize = dimension;
493 // Option min size not currently currently supported
496 case OPTION_DIVIDER_SIZE :
498 mOptionDividerSize = dimension;
501 // Resize Dividers not currently supported
508 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
510 switch( settingToCustomise )
512 case POPUP_MAXIMUM_SIZE :
516 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
520 return mPopupMaxSize;
523 case OPTION_MAXIMUM_SIZE :
525 return mOptionMaxSize;
527 case OPTION_MINIMUM_SIZE :
529 return mOptionMinSize;
531 case OPTION_DIVIDER_SIZE :
533 return mOptionDividerSize;
540 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
545 case Toolkit::TextSelectionPopup::CLIPBOARD:
547 mClipboardIconImage = image;
550 case Toolkit::TextSelectionPopup::CUT :
552 mCutIconImage = image;
555 case Toolkit::TextSelectionPopup::COPY :
557 mCopyIconImage = image;
560 case Toolkit::TextSelectionPopup::PASTE :
562 mPasteIconImage = image;
565 case Toolkit::TextSelectionPopup::SELECT :
567 mSelectIconImage = image;
570 case Toolkit::TextSelectionPopup::SELECT_ALL :
572 mSelectAllIconImage = image;
577 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
582 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
586 case Toolkit::TextSelectionPopup::CLIPBOARD :
588 return mClipboardIconImage;
591 case Toolkit::TextSelectionPopup::CUT :
593 return mCutIconImage;
596 case Toolkit::TextSelectionPopup::COPY :
598 return mCopyIconImage;
601 case Toolkit::TextSelectionPopup::PASTE :
603 return mPasteIconImage;
606 case Toolkit::TextSelectionPopup::SELECT :
608 return mSelectIconImage;
611 case Toolkit::TextSelectionPopup::SELECT_ALL :
613 return mSelectAllIconImage;
618 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
622 return Dali::Image();
625 void TextSelectionPopup::SetPressedImage( const std::string& filename )
627 mPressedImage = filename;
630 std::string TextSelectionPopup::GetPressedImage() const
632 return mPressedImage;
635 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
637 mOrderListOfButtons.clear();
638 mOrderListOfButtons.reserve( 8u );
640 // Create button for each possible option using Option priority
641 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
642 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
643 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
644 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
645 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
646 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
648 // Sort the buttons according their priorities.
649 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
652 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
654 // 1. Create a option.
655 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddOption\n" );
657 Toolkit::PushButton option = Toolkit::PushButton::New();
658 option.SetName( button.name );
659 option.SetAnimationTime( 0.0f );
660 option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
664 case Toolkit::TextSelectionPopup::CUT:
666 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
669 case Toolkit::TextSelectionPopup::COPY:
671 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
674 case Toolkit::TextSelectionPopup::PASTE:
676 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
679 case Toolkit::TextSelectionPopup::SELECT:
681 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
684 case Toolkit::TextSelectionPopup::SELECT_ALL:
686 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
689 case Toolkit::TextSelectionPopup::CLIPBOARD:
691 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
694 case Toolkit::TextSelectionPopup::NONE:
701 // 2. Set the options contents.
704 // PushButton layout properties.
705 option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
708 Property::Map buttonLabelProperties;
709 buttonLabelProperties.Insert( "text", button.caption );
710 option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
714 option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
715 option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
717 // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
718 //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
719 //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
722 // 3. Set the normal option image (blank / Transparent).
723 option.SetUnselectedImage( "" );
725 // 4. Set the pressed option image.
726 // The image can be blank, the color can be used regardless.
727 option.SetSelectedImage( mPressedImage );
728 option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
729 option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
731 // 5 Add option to tool bar
732 mToolbar.AddOption( option );
734 // 6. Add the divider
737 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
739 Toolkit::Control divider = Toolkit::Control::New();
740 #ifdef DECORATOR_DEBUG
741 divider.SetName("Text's popup divider");
743 divider.SetSize( size );
744 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
745 divider.SetBackgroundColor( mDividerColor );
746 mToolbar.AddDivider( divider );
750 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
752 std::size_t numberOfOptions = 0u;
753 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
755 const ButtonRequirement& button( *it );
762 return numberOfOptions;
765 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
767 DALI_LOG_INFO( gLogFilter, Debug::General, "TextSelectionPopup::AddPopupOptionsToToolbar\n" );
769 CreateOrderedListOfPopupOptions();
771 mButtonsChanged = false;
772 UnparentAndReset( mToolbar);
777 mToolbar = Toolkit::TextSelectionToolbar::New();
778 if ( mPopupMaxSize != Vector2::ZERO ) // If PopupMaxSize property set then apply to Toolbar. Toolbar currently is not retriving this from json
780 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mPopupMaxSize );
782 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
783 #ifdef DECORATOR_DEBUG
784 mToolbar.SetName("TextSelectionToolbar");
786 self.Add( mToolbar );
789 // Iterate list of buttons and add active ones to Toolbar
790 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
791 std::size_t numberOfOptionsAdded = 0u;
792 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
794 const ButtonRequirement& button( *it );
795 if ( button.enabled )
797 numberOfOptionsAdded++;
798 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
803 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
804 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
809 mOptionDividerSize(),
810 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
811 mCallbackInterface( callbackInterface ),
812 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
813 mDividerColor( Color::WHITE ),
814 mIconColor( Color::WHITE ),
815 mSelectOptionPriority( 1 ),
816 mSelectAllOptionPriority ( 2 ),
817 mCutOptionPriority ( 4 ),
818 mCopyOptionPriority ( 3 ),
819 mPasteOptionPriority ( 5 ),
820 mClipboardOptionPriority( 6 ),
821 mFadeInDuration(0.0f),
822 mFadeOutDuration(0.0f),
824 mShowCaptions( true ),
825 mPopupShowing( false ),
826 mButtonsChanged( false )
830 TextSelectionPopup::~TextSelectionPopup()
835 } // namespace Internal
837 } // namespace Toolkit