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 Dali::Vector4 DEFAULT_POPUP_DIVIDER_COLOR( Dali::Vector4( 0.23f, 0.72f, 0.8f, 0.11f ) );
51 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
52 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 0.11f ) );
54 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
55 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
56 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
57 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
58 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
59 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
60 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
62 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
64 #ifdef DGETTEXT_ENABLED
66 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
67 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
68 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
69 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
70 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
71 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
75 #define POPUP_CUT_STRING "Cut"
76 #define POPUP_COPY_STRING "Copy"
77 #define POPUP_PASTE_STRING "Paste"
78 #define POPUP_SELECT_STRING "Select"
79 #define POPUP_SELECT_ALL_STRING "Select All"
80 #define POPUP_CLIPBOARD_STRING "Clipboard"
84 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
85 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
86 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
87 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
88 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
89 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
93 return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL );
96 // Setup properties, signals and actions using the type-registry.
98 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
112 DALI_TYPE_REGISTRATION_END()
117 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
118 TextSelectionPopupCallbackInterface* callbackInterface )
120 // Create the implementation, temporarily owned by this handle on stack
121 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
123 // Pass ownership to CustomActor handle
124 Dali::Toolkit::TextSelectionPopup handle( *impl );
126 impl->mEnabledButtons = buttonsToEnable;
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::POPUP_MIN_SIZE:
152 impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
155 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
157 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
160 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
162 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
165 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
167 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
170 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
172 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
173 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
176 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
178 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
179 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
182 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
184 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
185 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
188 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
190 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
191 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
194 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
196 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
197 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
200 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
202 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
203 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
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::OnInitialize()
314 void TextSelectionPopup::OnStageConnection( int depth )
316 // Call the Control::OnStageConnection() to set the depth of the background.
317 Control::OnStageConnection( depth );
319 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
322 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
324 if( mCallbackInterface )
326 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
332 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
334 if( mCallbackInterface )
336 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
342 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
344 if( mCallbackInterface )
346 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
352 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
354 if( mCallbackInterface )
356 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
362 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
364 if( mCallbackInterface )
366 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
372 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
374 if( mCallbackInterface )
376 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
382 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
384 switch( settingToCustomise )
386 case POPUP_MAXIMUM_SIZE :
389 mMaxSize = dimension;
392 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
396 case POPUP_MINIMUM_SIZE :
399 mMinSize = dimension;
400 // Option can not be smaller than this if only one.
403 case OPTION_MAXIMUM_SIZE :
405 mOptionMaxSize = dimension;
406 // Option max size not currently currently supported
410 case OPTION_MINIMUM_SIZE :
412 mOptionMinSize = dimension;
413 // Option min size not currently currently supported
416 case OPTION_DIVIDER_SIZE :
418 mOptionDividerSize = dimension;
421 // Resize Dividers not currently supported
428 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
430 switch( settingToCustomise )
432 case POPUP_MAXIMUM_SIZE :
436 case POPUP_MINIMUM_SIZE :
440 case OPTION_MAXIMUM_SIZE :
442 return mOptionMaxSize;
444 case OPTION_MINIMUM_SIZE :
446 return mOptionMinSize;
448 case OPTION_DIVIDER_SIZE :
450 return mOptionDividerSize;
457 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
462 case Toolkit::TextSelectionPopup::CLIPBOARD:
464 mClipboardIconImage = image;
467 case Toolkit::TextSelectionPopup::CUT :
469 mCutIconImage = image;
472 case Toolkit::TextSelectionPopup::COPY :
474 mCopyIconImage = image;
477 case Toolkit::TextSelectionPopup::PASTE :
479 mPasteIconImage = image;
482 case Toolkit::TextSelectionPopup::SELECT :
484 mSelectIconImage = image;
487 case Toolkit::TextSelectionPopup::SELECT_ALL :
489 mSelectAllIconImage = image;
494 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
499 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
503 case Toolkit::TextSelectionPopup::CLIPBOARD :
505 return mClipboardIconImage;
508 case Toolkit::TextSelectionPopup::CUT :
510 return mCutIconImage;
513 case Toolkit::TextSelectionPopup::COPY :
515 return mCopyIconImage;
518 case Toolkit::TextSelectionPopup::PASTE :
520 return mPasteIconImage;
523 case Toolkit::TextSelectionPopup::SELECT :
525 return mSelectIconImage;
528 case Toolkit::TextSelectionPopup::SELECT_ALL :
530 return mSelectAllIconImage;
535 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
539 return Dali::Image();
542 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
544 mOrderListOfButtons.clear();
545 mOrderListOfButtons.reserve( 8u );
547 // Create button for each possible option using Option priority
548 if ( !mCutIconImage )
550 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
552 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
554 if ( !mCopyIconImage )
556 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
558 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
560 if ( !mPasteIconImage )
562 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
564 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
566 if ( !mSelectIconImage )
567 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
568 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
570 if ( !mSelectAllIconImage )
572 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
574 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
576 if ( !mClipboardIconImage )
578 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
580 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
582 // Sort the buttons according their priorities.
583 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
586 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
588 const std::string& name = button.name;
589 const std::string& caption = button.caption;
590 Image iconImage = button.icon;
592 // 1. Create the backgrounds for the popup option both normal and pressed.
593 // Both containers will be added to a button.
595 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
596 optionContainer.SetFitHeight( 0 );
597 optionContainer.SetFitWidth( 0 );
599 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
600 optionPressedContainer.SetFitHeight( 0 );
601 optionPressedContainer.SetFitWidth( 0 );
602 optionPressedContainer.SetBackgroundColor( mPressedColor );
604 #ifdef DECORATOR_DEBUG
605 optionContainer.SetName("optionContainer");
606 optionPressedContainer.SetName("optionPressedContainer");
612 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
613 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
614 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
616 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
617 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
618 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
621 padding.left = 24.0f;
622 padding.right = 24.0f;
624 padding.bottom = 14.0f;
625 captionTextLabel.SetPadding( padding );
626 pressedCaptionTextLabel.SetPadding( padding );
628 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
629 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
632 int depth = Self().GetHierarchyDepth();
633 // 3. Create the icons
636 ImageActor pressedIcon = ImageActor::New( iconImage );
637 ImageActor icon = ImageActor::New( iconImage );
638 icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
639 pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
641 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
642 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
643 icon.SetColor( mIconColor );
645 if ( showCaption & showIcons )
647 optionContainer.SetFitHeight( 1 );
648 optionContainer.SetFitWidth( 1 );
649 optionPressedContainer.SetFitHeight( 1 );
650 optionPressedContainer.SetFitWidth( 1 );
653 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
654 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
656 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
657 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
660 // 4. Create a option.
661 Toolkit::PushButton option = Toolkit::PushButton::New();
662 option.SetName( name );
663 option.SetAnimationTime( 0.0f );
664 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
668 case Toolkit::TextSelectionPopup::CUT:
670 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
673 case Toolkit::TextSelectionPopup::COPY:
675 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
678 case Toolkit::TextSelectionPopup::PASTE:
680 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
683 case Toolkit::TextSelectionPopup::SELECT:
685 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
688 case Toolkit::TextSelectionPopup::SELECT_ALL:
690 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
693 case Toolkit::TextSelectionPopup::CLIPBOARD:
695 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
698 case Toolkit::TextSelectionPopup::NONE:
705 // 5. Set the normal option image.
706 option.SetButtonImage( optionContainer );
708 // 6. Set the pressed option image
709 option.SetSelectedImage( optionPressedContainer );
711 // 7 Add option to tool bar
712 mToolbar.AddOption( option );
714 // 8. Add the divider
717 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
719 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
720 #ifdef DECORATOR_DEBUG
721 divider.SetName("Text's popup divider");
723 divider.SetSize( size );
724 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
725 divider.SetColor( mDividerColor );
726 divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
727 mToolbar.AddDivider( divider );
731 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
733 std::size_t numberOfOptions = 0u;
734 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
736 const ButtonRequirement& button( *it );
743 return numberOfOptions;
746 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
748 // Iterate list of buttons and add active ones to Toolbar
749 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
750 std::size_t numberOfOptionsAdded = 0u;
751 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
753 const ButtonRequirement& button( *it );
754 if ( button.enabled )
756 numberOfOptionsAdded++;
757 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
762 void TextSelectionPopup::CreatePopup()
765 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
766 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
767 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
771 mToolbar = Toolkit::TextSelectionToolbar::New();
772 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
773 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
774 self.Add( mToolbar );
775 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
779 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
780 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
784 mOptionDividerSize( Size( 2.0f, 0.0f) ),
785 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
786 mCallbackInterface( callbackInterface ),
787 mDividerColor( DEFAULT_POPUP_DIVIDER_COLOR ),
788 mIconColor( DEFAULT_OPTION_ICON ),
789 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
790 mSelectOptionPriority( 1 ),
791 mSelectAllOptionPriority ( 2 ),
792 mCutOptionPriority ( 4 ),
793 mCopyOptionPriority ( 3 ),
794 mPasteOptionPriority ( 5 ),
795 mClipboardOptionPriority( 6 ),
797 mShowCaptions( true )
801 TextSelectionPopup::~TextSelectionPopup()
806 } // namespace Internal
808 } // namespace Toolkit