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/images/nine-patch-image.h>
29 #include <dali/public-api/images/resource-image.h>
30 #include <dali/public-api/math/vector2.h>
31 #include <dali/public-api/math/vector4.h>
32 #include <dali/devel-api/object/type-registry-helper.h>
47 // todo Move this to adaptor??
48 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
50 const std::string TEXT_SELECTION_POPUP_LABEL = "textselectionpopuplabel";
52 #ifdef DGETTEXT_ENABLED
54 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
55 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
56 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
57 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
58 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
59 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
63 #define POPUP_CUT_STRING "Cut"
64 #define POPUP_COPY_STRING "Copy"
65 #define POPUP_PASTE_STRING "Paste"
66 #define POPUP_SELECT_STRING "Select"
67 #define POPUP_SELECT_ALL_STRING "Select All"
68 #define POPUP_CLIPBOARD_STRING "Clipboard"
72 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
73 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
74 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
75 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
76 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
77 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
81 return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL );
84 // Setup properties, signals and actions using the type-registry.
86 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, DIVIDER_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, ICON_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, PRESSED_COLOR )
103 DALI_TYPE_REGISTRATION_END()
108 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
109 TextSelectionPopupCallbackInterface* callbackInterface )
111 // Create the implementation, temporarily owned by this handle on stack
112 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
114 // Pass ownership to CustomActor handle
115 Dali::Toolkit::TextSelectionPopup handle( *impl );
117 impl->mEnabledButtons = buttonsToEnable;
118 // Second-phase init of the implementation
119 // This can only be done after the CustomActor connection has been made...
125 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
127 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
131 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
135 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
137 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
140 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
142 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
145 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
147 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
150 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
152 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
155 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
157 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
158 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
161 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
163 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
164 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
167 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
169 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
170 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
173 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
175 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
176 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
179 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
181 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
182 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
185 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
187 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
188 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
191 case Toolkit::TextSelectionPopup::Property::DIVIDER_COLOR:
193 impl.mDividerColor = value.Get< Vector4 >();
196 case Toolkit::TextSelectionPopup::Property::ICON_COLOR:
198 impl.mIconColor = value.Get< Vector4 >();
201 case Toolkit::TextSelectionPopup::Property::PRESSED_COLOR:
203 impl.mPressedColor = value.Get< Vector4 >();
207 } // TextSelectionPopup
210 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
212 Property::Value value;
214 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
218 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
222 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
224 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
227 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
229 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
232 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
234 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
237 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
239 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
242 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
244 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
247 value = image.GetUrl();
251 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
253 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
256 value = image.GetUrl();
260 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
262 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
265 value = image.GetUrl();
269 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
271 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
274 value = image.GetUrl();
278 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
280 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
283 value = image.GetUrl();
287 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
289 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
292 value = image.GetUrl();
301 void TextSelectionPopup::RaiseAbove( Layer target )
305 mToolbar.RaiseAbove( target );
309 void TextSelectionPopup::ShowPopup()
311 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
314 void TextSelectionPopup::OnInitialize()
319 void TextSelectionPopup::OnStageConnection( int depth )
321 // Call the Control::OnStageConnection() to set the depth of the background.
322 Control::OnStageConnection( depth );
324 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
327 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
329 if( mCallbackInterface )
331 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
337 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
339 if( mCallbackInterface )
341 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
347 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
349 if( mCallbackInterface )
351 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
357 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
359 if( mCallbackInterface )
361 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
367 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
369 if( mCallbackInterface )
371 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
377 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
379 if( mCallbackInterface )
381 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
387 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
389 switch( settingToCustomise )
391 case POPUP_MAXIMUM_SIZE :
395 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, dimension );
399 case OPTION_MAXIMUM_SIZE :
401 mOptionMaxSize = dimension;
402 // Option max size not currently currently supported
405 case OPTION_MINIMUM_SIZE :
407 mOptionMinSize = dimension;
408 // Option min size not currently currently supported
411 case OPTION_DIVIDER_SIZE :
413 mOptionDividerSize = dimension;
416 // Resize Dividers not currently supported
423 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
425 switch( settingToCustomise )
427 case POPUP_MAXIMUM_SIZE :
429 return mToolbar.GetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE ).Get< Vector2 >();
431 case OPTION_MAXIMUM_SIZE :
433 return mOptionMaxSize;
435 case OPTION_MINIMUM_SIZE :
437 return mOptionMinSize;
439 case OPTION_DIVIDER_SIZE :
441 return mOptionDividerSize;
448 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
453 case Toolkit::TextSelectionPopup::CLIPBOARD:
455 mClipboardIconImage = image;
458 case Toolkit::TextSelectionPopup::CUT :
460 mCutIconImage = image;
463 case Toolkit::TextSelectionPopup::COPY :
465 mCopyIconImage = image;
468 case Toolkit::TextSelectionPopup::PASTE :
470 mPasteIconImage = image;
473 case Toolkit::TextSelectionPopup::SELECT :
475 mSelectIconImage = image;
478 case Toolkit::TextSelectionPopup::SELECT_ALL :
480 mSelectAllIconImage = image;
485 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
490 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
494 case Toolkit::TextSelectionPopup::CLIPBOARD :
496 return mClipboardIconImage;
499 case Toolkit::TextSelectionPopup::CUT :
501 return mCutIconImage;
504 case Toolkit::TextSelectionPopup::COPY :
506 return mCopyIconImage;
509 case Toolkit::TextSelectionPopup::PASTE :
511 return mPasteIconImage;
514 case Toolkit::TextSelectionPopup::SELECT :
516 return mSelectIconImage;
519 case Toolkit::TextSelectionPopup::SELECT_ALL :
521 return mSelectAllIconImage;
526 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
530 return Dali::Image();
533 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
535 mOrderListOfButtons.clear();
536 mOrderListOfButtons.reserve( 8u );
538 // Create button for each possible option using Option priority
539 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
540 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
541 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
542 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
543 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
544 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
546 // Sort the buttons according their priorities.
547 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
550 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
552 const std::string& name = button.name;
553 const std::string& caption = button.caption;
554 Image iconImage = button.icon;
556 // 1. Create the backgrounds for the popup option both normal and pressed.
557 // Both containers will be added to a button.
559 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
560 optionContainer.SetFitHeight( 0 );
561 optionContainer.SetFitWidth( 0 );
563 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
564 optionPressedContainer.SetFitHeight( 0 );
565 optionPressedContainer.SetFitWidth( 0 );
566 optionPressedContainer.SetBackgroundColor( mPressedColor );
568 #ifdef DECORATOR_DEBUG
569 optionContainer.SetName("optionContainer");
570 optionPressedContainer.SetName("optionPressedContainer");
576 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
577 captionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
578 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
579 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
581 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
582 pressedCaptionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
583 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
584 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
587 padding.left = 24.0f;
588 padding.right = 24.0f;
590 padding.bottom = 14.0f;
591 captionTextLabel.SetPadding( padding );
592 pressedCaptionTextLabel.SetPadding( padding );
594 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
595 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
598 int depth = Self().GetHierarchyDepth();
599 // 3. Create the icons
600 if ( showIcons && iconImage )
602 ImageActor pressedIcon = ImageActor::New( iconImage );
603 ImageActor icon = ImageActor::New( iconImage );
604 icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
605 pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
607 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
608 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
609 icon.SetColor( mIconColor );
611 if ( showCaption & showIcons )
613 optionContainer.SetFitHeight( 1 );
614 optionContainer.SetFitWidth( 1 );
615 optionPressedContainer.SetFitHeight( 1 );
616 optionPressedContainer.SetFitWidth( 1 );
619 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
620 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
622 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
623 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
626 // 4. Create a option.
627 Toolkit::PushButton option = Toolkit::PushButton::New();
628 option.SetName( name );
629 option.SetAnimationTime( 0.0f );
630 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
634 case Toolkit::TextSelectionPopup::CUT:
636 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
639 case Toolkit::TextSelectionPopup::COPY:
641 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
644 case Toolkit::TextSelectionPopup::PASTE:
646 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
649 case Toolkit::TextSelectionPopup::SELECT:
651 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
654 case Toolkit::TextSelectionPopup::SELECT_ALL:
656 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
659 case Toolkit::TextSelectionPopup::CLIPBOARD:
661 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
664 case Toolkit::TextSelectionPopup::NONE:
671 // 5. Set the normal option image.
672 option.SetButtonImage( optionContainer );
674 // 6. Set the pressed option image
675 option.SetSelectedImage( optionPressedContainer );
677 // 7 Add option to tool bar
678 mToolbar.AddOption( option );
680 // 8. Add the divider
683 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
685 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
686 #ifdef DECORATOR_DEBUG
687 divider.SetName("Text's popup divider");
689 divider.SetSize( size );
690 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
691 divider.SetColor( mDividerColor );
692 divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
693 mToolbar.AddDivider( divider );
697 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
699 std::size_t numberOfOptions = 0u;
700 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
702 const ButtonRequirement& button( *it );
709 return numberOfOptions;
712 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
714 // Iterate list of buttons and add active ones to Toolbar
715 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
716 std::size_t numberOfOptionsAdded = 0u;
717 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
719 const ButtonRequirement& button( *it );
720 if ( button.enabled )
722 numberOfOptionsAdded++;
723 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
728 void TextSelectionPopup::CreatePopup()
731 CreateOrderedListOfPopupOptions();
732 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
736 mToolbar = Toolkit::TextSelectionToolbar::New();
737 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
738 self.Add( mToolbar );
742 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
743 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
745 mOptionDividerSize(),
746 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
747 mCallbackInterface( callbackInterface ),
748 mDividerColor( Color::WHITE ),
749 mIconColor( Color::WHITE ),
750 mPressedColor( Color::WHITE ),
751 mSelectOptionPriority( 1 ),
752 mSelectAllOptionPriority ( 2 ),
753 mCutOptionPriority ( 4 ),
754 mCopyOptionPriority ( 3 ),
755 mPasteOptionPriority ( 5 ),
756 mClipboardOptionPriority( 6 ),
758 mShowCaptions( true )
762 TextSelectionPopup::~TextSelectionPopup()
767 } // namespace Internal
769 } // namespace Toolkit