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_LINE_COLOR( Dali::Vector4( 0.69f, 0.93f, 0.93f, 1.0f ) );
51 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
52 const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.12f, 0.56f, 1.0f, 1.0f ) );
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::OnInitialize()
306 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
308 if( mCallbackInterface )
310 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
316 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
318 if( mCallbackInterface )
320 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
326 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
328 if( mCallbackInterface )
330 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
336 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
338 if( mCallbackInterface )
340 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
346 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
348 if( mCallbackInterface )
350 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
356 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
358 if( mCallbackInterface )
360 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
366 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
368 switch( settingToCustomise )
370 case POPUP_MAXIMUM_SIZE :
373 mMaxSize = dimension;
376 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
380 case POPUP_MINIMUM_SIZE :
383 mMinSize = dimension;
384 // Option can not be smaller than this if only one.
387 case OPTION_MAXIMUM_SIZE :
389 mOptionMaxSize = dimension;
390 // Option max size not currently currently supported
394 case OPTION_MINIMUM_SIZE :
396 mOptionMinSize = dimension;
397 // Option min size not currently currently supported
400 case OPTION_DIVIDER_SIZE :
402 mOptionDividerSize = dimension;
405 // Resize Dividers not currently supported
412 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
414 switch( settingToCustomise )
416 case POPUP_MAXIMUM_SIZE :
420 case POPUP_MINIMUM_SIZE :
424 case OPTION_MAXIMUM_SIZE :
426 return mOptionMaxSize;
428 case OPTION_MINIMUM_SIZE :
430 return mOptionMinSize;
432 case OPTION_DIVIDER_SIZE :
434 return mOptionDividerSize;
441 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
446 case Toolkit::TextSelectionPopup::CLIPBOARD:
448 mClipboardIconImage = image;
451 case Toolkit::TextSelectionPopup::CUT :
453 mCutIconImage = image;
456 case Toolkit::TextSelectionPopup::COPY :
458 mCopyIconImage = image;
461 case Toolkit::TextSelectionPopup::PASTE :
463 mPasteIconImage = image;
466 case Toolkit::TextSelectionPopup::SELECT :
468 mSelectIconImage = image;
471 case Toolkit::TextSelectionPopup::SELECT_ALL :
473 mSelectAllIconImage = image;
478 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
483 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
487 case Toolkit::TextSelectionPopup::CLIPBOARD :
489 return mClipboardIconImage;
492 case Toolkit::TextSelectionPopup::CUT :
494 return mCutIconImage;
497 case Toolkit::TextSelectionPopup::COPY :
499 return mCopyIconImage;
502 case Toolkit::TextSelectionPopup::PASTE :
504 return mPasteIconImage;
507 case Toolkit::TextSelectionPopup::SELECT :
509 return mSelectIconImage;
512 case Toolkit::TextSelectionPopup::SELECT_ALL :
514 return mSelectAllIconImage;
519 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
523 return Dali::Image();
526 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
528 mOrderListOfButtons.clear();
530 // Create button for each possible option using Option priority
531 if ( !mCutIconImage )
533 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
535 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
537 if ( !mCopyIconImage )
539 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
541 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
543 if ( !mPasteIconImage )
545 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
547 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
549 if ( !mSelectIconImage )
550 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
551 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
553 if ( !mSelectAllIconImage )
555 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
557 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
559 if ( !mClipboardIconImage )
561 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
563 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
565 // Sort the buttons according their priorities.
566 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
569 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
572 const std::string& name = button.name;
573 const std::string& caption = button.caption;
574 Image iconImage = button.icon;
576 // 1. Create the backgrounds for the popup option both normal and pressed.
577 // Both containers will be added to a button.
579 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
580 optionContainer.SetFitHeight( 0 );
581 optionContainer.SetFitWidth( 0 );
583 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
584 optionPressedContainer.SetFitHeight( 0 );
585 optionPressedContainer.SetFitWidth( 0 );
586 optionPressedContainer.SetBackgroundColor( mPressedColor );
588 #ifdef DECORATOR_DEBUG
589 optionContainer.SetName("optionContainer");
590 optionPressedContainer.SetName("optionPressedContainer");
596 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
597 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
598 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
600 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
601 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
602 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
605 padding.left = 24.0f;
606 padding.right = 24.0f;
608 padding.bottom = 14.0f;
609 captionTextLabel.SetPadding( padding );
610 pressedCaptionTextLabel.SetPadding( padding );
612 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
613 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
616 // 3. Create the icons
619 ImageActor pressedIcon = ImageActor::New( iconImage );
620 ImageActor icon = ImageActor::New( iconImage );
621 icon.SetSortModifier( DECORATION_DEPTH_INDEX - 1 );
622 pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX - 1 );
624 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
625 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
626 icon.SetColor( mIconColor );
628 if ( showCaption & showIcons )
630 optionContainer.SetFitHeight( 1 );
631 optionContainer.SetFitWidth( 1 );
632 optionPressedContainer.SetFitHeight( 1 );
633 optionPressedContainer.SetFitWidth( 1 );
636 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
637 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
639 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
640 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
643 // 4. Create a option.
644 Toolkit::PushButton option = Toolkit::PushButton::New();
645 option.SetName( name );
646 option.SetAnimationTime( 0.0f );
647 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
651 case Toolkit::TextSelectionPopup::CUT:
653 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
656 case Toolkit::TextSelectionPopup::COPY:
658 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
661 case Toolkit::TextSelectionPopup::PASTE:
663 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
666 case Toolkit::TextSelectionPopup::SELECT:
668 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
671 case Toolkit::TextSelectionPopup::SELECT_ALL:
673 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
676 case Toolkit::TextSelectionPopup::CLIPBOARD:
678 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
681 case Toolkit::TextSelectionPopup::NONE:
688 // 5. Set the normal option image.
689 option.SetButtonImage( optionContainer );
691 // 6. Set the pressed option image
692 option.SetSelectedImage( optionPressedContainer );
694 // 7 Add option to tool bar
695 mToolbar.AddOption( option );
697 // 8. Add the divider
700 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
702 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
703 divider.SetSize( size );
704 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
705 divider.SetColor( mLineColor );
706 mToolbar.AddDivider( divider );
710 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
712 std::size_t numberOfOptions = 0u;
713 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
715 const ButtonRequirement& button( *it );
722 return numberOfOptions;
725 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
727 // Iterate list of buttons and add active ones to Toolbar
728 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
729 std::size_t numberOfOptionsAdded = 0u;
730 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
732 const ButtonRequirement& button( *it );
733 if ( button.enabled )
735 numberOfOptionsAdded++;
736 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
741 void TextSelectionPopup::CreatePopup()
744 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
745 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
746 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
750 mToolbar = Toolkit::TextSelectionToolbar::New();
751 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
752 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
753 self.Add( mToolbar );
754 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
758 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
759 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
763 mOptionDividerSize( Size( 2.0f, 0.0f) ),
764 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
765 mCallbackInterface( callbackInterface ),
766 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
767 mIconColor( DEFAULT_OPTION_ICON ),
768 mPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
769 mSelectOptionPriority( 1 ),
770 mSelectAllOptionPriority ( 2 ),
771 mCutOptionPriority ( 4 ),
772 mCopyOptionPriority ( 3 ),
773 mPasteOptionPriority ( 5 ),
774 mClipboardOptionPriority( 6 ),
776 mShowCaptions( true )
780 TextSelectionPopup::~TextSelectionPopup()
785 } // namespace Internal
787 } // namespace Toolkit