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/default-controls/solid-color-actor.h>
24 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
27 #include <dali/public-api/images/nine-patch-image.h>
28 #include <dali/public-api/images/resource-image.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/vector4.h>
31 #include <dali/devel-api/object/type-registry-helper.h>
46 // todo Move this to adaptor??
47 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
49 const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.69f, 0.93f, 0.93f, 1.0f ) );
50 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
51 const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.12f, 0.56f, 1.0f, 1.0f ) );
53 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
54 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
55 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
56 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
57 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
58 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
59 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
61 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
63 #ifdef DGETTEXT_ENABLED
65 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
66 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
67 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
68 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
69 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
70 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
74 #define POPUP_CUT_STRING "Cut"
75 #define POPUP_COPY_STRING "Copy"
76 #define POPUP_PASTE_STRING "Paste"
77 #define POPUP_SELECT_STRING "Select"
78 #define POPUP_SELECT_ALL_STRING "Select All"
79 #define POPUP_CLIPBOARD_STRING "Clipboard"
83 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
84 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
85 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
86 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
87 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
88 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
92 return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL );
95 // Setup properties, signals and actions using the type-registry.
97 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
111 DALI_TYPE_REGISTRATION_END()
116 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
117 TextSelectionPopupCallbackInterface* callbackInterface )
119 // Create the implementation, temporarily owned by this handle on stack
120 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
122 // Pass ownership to CustomActor handle
123 Dali::Toolkit::TextSelectionPopup handle( *impl );
125 impl->mEnabledButtons = buttonsToEnable;
127 // Second-phase init of the implementation
128 // This can only be done after the CustomActor connection has been made...
134 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
136 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
140 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
144 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
146 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
149 case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE:
151 impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
154 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
156 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
159 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
161 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
164 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
166 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
169 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
171 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
172 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
175 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
177 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
178 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
181 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
183 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
184 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
187 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
189 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
190 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
193 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
195 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
196 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
199 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
201 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
202 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
206 } // TextSelectionPopup
209 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
211 Property::Value value;
213 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
217 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
221 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
223 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
226 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
228 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
231 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
233 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
236 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
238 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
241 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
243 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
246 value = image.GetUrl();
250 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
252 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
255 value = image.GetUrl();
259 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
261 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
264 value = image.GetUrl();
268 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
270 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
273 value = image.GetUrl();
277 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
279 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
282 value = image.GetUrl();
286 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
288 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
291 value = image.GetUrl();
300 void TextSelectionPopup::OnInitialize()
305 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
307 if( mCallbackInterface )
309 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
315 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
317 if( mCallbackInterface )
319 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
325 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
327 if( mCallbackInterface )
329 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
335 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
337 if( mCallbackInterface )
339 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
345 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
347 if( mCallbackInterface )
349 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
355 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
357 if( mCallbackInterface )
359 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
365 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
367 switch( settingToCustomise )
369 case POPUP_MAXIMUM_SIZE :
372 mMaxSize = dimension;
375 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
379 case POPUP_MINIMUM_SIZE :
382 mMinSize = dimension;
383 // Option can not be smaller than this if only one.
386 case OPTION_MAXIMUM_SIZE :
388 mOptionMaxSize = dimension;
389 // Option max size not currently currently supported
393 case OPTION_MINIMUM_SIZE :
395 mOptionMinSize = dimension;
396 // Option min size not currently currently supported
399 case OPTION_DIVIDER_SIZE :
401 mOptionDividerSize = dimension;
404 // Resize Dividers not currently supported
411 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
413 switch( settingToCustomise )
415 case POPUP_MAXIMUM_SIZE :
419 case POPUP_MINIMUM_SIZE :
423 case OPTION_MAXIMUM_SIZE :
425 return mOptionMaxSize;
427 case OPTION_MINIMUM_SIZE :
429 return mOptionMinSize;
431 case OPTION_DIVIDER_SIZE :
433 return mOptionDividerSize;
440 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
445 case Toolkit::TextSelectionPopup::CLIPBOARD:
447 mClipboardIconImage = image;
450 case Toolkit::TextSelectionPopup::CUT :
452 mCutIconImage = image;
455 case Toolkit::TextSelectionPopup::COPY :
457 mCopyIconImage = image;
460 case Toolkit::TextSelectionPopup::PASTE :
462 mPasteIconImage = image;
465 case Toolkit::TextSelectionPopup::SELECT :
467 mSelectIconImage = image;
470 case Toolkit::TextSelectionPopup::SELECT_ALL :
472 mSelectAllIconImage = image;
477 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
482 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
486 case Toolkit::TextSelectionPopup::CLIPBOARD :
488 return mClipboardIconImage;
491 case Toolkit::TextSelectionPopup::CUT :
493 return mCutIconImage;
496 case Toolkit::TextSelectionPopup::COPY :
498 return mCopyIconImage;
501 case Toolkit::TextSelectionPopup::PASTE :
503 return mPasteIconImage;
506 case Toolkit::TextSelectionPopup::SELECT :
508 return mSelectIconImage;
511 case Toolkit::TextSelectionPopup::SELECT_ALL :
513 return mSelectAllIconImage;
518 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
522 return Dali::Image();
525 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
527 mOrderListOfButtons.clear();
529 // Create button for each possible option using Option priority
530 if ( !mCutIconImage )
532 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
534 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
536 if ( !mCopyIconImage )
538 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
540 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
542 if ( !mPasteIconImage )
544 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
546 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
548 if ( !mSelectIconImage )
549 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
550 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
552 if ( !mSelectAllIconImage )
554 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
556 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
558 if ( !mClipboardIconImage )
560 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
562 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
564 // Sort the buttons according their priorities.
565 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
568 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
571 const std::string& name = button.name;
572 const std::string& caption = button.caption;
573 Image iconImage = button.icon;
575 // 1. Create the backgrounds for the popup option both normal and pressed.
576 // Both containers will be added to a button.
578 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
579 optionContainer.SetDrawMode( DrawMode::OVERLAY );
580 optionContainer.SetFitHeight( 0 );
581 optionContainer.SetFitWidth( 0 );
583 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
584 optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
585 optionPressedContainer.SetFitHeight( 0 );
586 optionPressedContainer.SetFitWidth( 0 );
587 optionPressedContainer.SetBackgroundColor( mPressedColor );
589 #ifdef DECORATOR_DEBUG
590 optionContainer.SetName("optionContainer");
591 optionPressedContainer.SetName("optionPressedContainer");
597 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
598 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
599 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
601 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
602 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
603 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
606 padding.left = 24.0f;
607 padding.right = 24.0f;
609 padding.bottom = 14.0f;
610 captionTextLabel.SetPadding( padding );
611 pressedCaptionTextLabel.SetPadding( padding );
613 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
614 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
617 // 3. Create the icons
620 ImageActor pressedIcon = ImageActor::New( iconImage );
621 ImageActor icon = ImageActor::New( iconImage );
623 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
624 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
625 icon.SetColor( mIconColor );
627 if ( showCaption & showIcons )
629 optionContainer.SetFitHeight( 1 );
630 optionContainer.SetFitWidth( 1 );
631 optionPressedContainer.SetFitHeight( 1 );
632 optionPressedContainer.SetFitWidth( 1 );
635 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
636 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
638 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
639 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
642 // 4. Create a option.
643 Toolkit::PushButton option = Toolkit::PushButton::New();
644 option.SetName( name );
645 option.SetAnimationTime( 0.0f );
646 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
650 case Toolkit::TextSelectionPopup::CUT:
652 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
655 case Toolkit::TextSelectionPopup::COPY:
657 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
660 case Toolkit::TextSelectionPopup::PASTE:
662 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
665 case Toolkit::TextSelectionPopup::SELECT:
667 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
670 case Toolkit::TextSelectionPopup::SELECT_ALL:
672 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
675 case Toolkit::TextSelectionPopup::CLIPBOARD:
677 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
680 case Toolkit::TextSelectionPopup::NONE:
687 // 5. Set the normal option image.
688 option.SetButtonImage( optionContainer );
690 // 6. Set the pressed option image
691 option.SetSelectedImage( optionPressedContainer );
693 // 7 Add option to tool bar
694 mToolbar.AddOption( option );
696 // 8. Add the divider
699 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
701 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
702 divider.SetSize( size );
703 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
704 divider.SetColor( mLineColor );
705 mToolbar.AddDivider( divider );
709 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
711 std::size_t numberOfOptions = 0u;
712 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
714 const ButtonRequirement& button( *it );
721 return numberOfOptions;
724 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
726 // Iterate list of buttons and add active ones to Toolbar
727 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
728 std::size_t numberOfOptionsAdded = 0u;
729 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
731 const ButtonRequirement& button( *it );
732 if ( button.enabled )
734 numberOfOptionsAdded++;
735 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
740 void TextSelectionPopup::CreatePopup()
743 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
744 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
745 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
749 mToolbar = Toolkit::TextSelectionToolbar::New();
750 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
751 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
752 self.Add( mToolbar );
753 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
757 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
758 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
762 mOptionDividerSize( Size( 2.0f, 0.0f) ),
763 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
764 mCallbackInterface( callbackInterface ),
765 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
766 mIconColor( DEFAULT_OPTION_ICON ),
767 mPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
768 mSelectOptionPriority( 1 ),
769 mSelectAllOptionPriority ( 2 ),
770 mCutOptionPriority ( 3 ),
771 mCopyOptionPriority ( 4 ),
772 mPasteOptionPriority ( 5 ),
773 mClipboardOptionPriority( 6 ),
775 mShowCaptions( true )
779 TextSelectionPopup::~TextSelectionPopup()
784 } // namespace Internal
786 } // namespace Toolkit