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 const Dali::Vector4 DEFAULT_POPUP_DIVIDER_COLOR( Dali::Vector4( 0.23f, 0.72f, 0.8f, 0.11f ) );
53 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
54 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 0.11f ) );
56 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
57 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
58 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
59 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
60 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
61 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
62 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
64 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
66 #ifdef DGETTEXT_ENABLED
68 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
69 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
70 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
71 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
72 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
73 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
77 #define POPUP_CUT_STRING "Cut"
78 #define POPUP_COPY_STRING "Copy"
79 #define POPUP_PASTE_STRING "Paste"
80 #define POPUP_SELECT_STRING "Select"
81 #define POPUP_SELECT_ALL_STRING "Select All"
82 #define POPUP_CLIPBOARD_STRING "Clipboard"
86 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
87 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
88 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
89 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
90 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
91 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
95 return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL );
98 // Setup properties, signals and actions using the type-registry.
100 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
114 DALI_TYPE_REGISTRATION_END()
119 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
120 TextSelectionPopupCallbackInterface* callbackInterface )
122 // Create the implementation, temporarily owned by this handle on stack
123 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
125 // Pass ownership to CustomActor handle
126 Dali::Toolkit::TextSelectionPopup handle( *impl );
128 impl->mEnabledButtons = buttonsToEnable;
129 // Second-phase init of the implementation
130 // This can only be done after the CustomActor connection has been made...
136 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
138 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
142 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
146 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
148 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
151 case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE:
153 impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
156 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
158 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
161 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
163 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
166 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
168 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
171 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
173 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
174 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
177 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
179 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
180 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
183 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
185 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
186 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
189 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
191 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
192 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
195 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
197 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
198 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
201 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
203 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
204 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
208 } // TextSelectionPopup
211 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
213 Property::Value value;
215 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
219 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
223 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
225 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
228 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
230 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
233 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
235 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
238 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
240 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
243 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
245 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
248 value = image.GetUrl();
252 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
254 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
257 value = image.GetUrl();
261 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
263 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
266 value = image.GetUrl();
270 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
272 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
275 value = image.GetUrl();
279 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
281 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
284 value = image.GetUrl();
288 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
290 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
293 value = image.GetUrl();
302 void TextSelectionPopup::RaiseAbove( Layer target )
306 mToolbar.RaiseAbove( target );
310 void TextSelectionPopup::OnInitialize()
315 void TextSelectionPopup::OnStageConnection( int depth )
317 // Call the Control::OnStageConnection() to set the depth of the background.
318 Control::OnStageConnection( depth );
320 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
323 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
325 if( mCallbackInterface )
327 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
333 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
335 if( mCallbackInterface )
337 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
343 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
345 if( mCallbackInterface )
347 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
353 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
355 if( mCallbackInterface )
357 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
363 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
365 if( mCallbackInterface )
367 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
373 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
375 if( mCallbackInterface )
377 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
383 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
385 switch( settingToCustomise )
387 case POPUP_MAXIMUM_SIZE :
390 mMaxSize = dimension;
393 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
397 case POPUP_MINIMUM_SIZE :
400 mMinSize = dimension;
401 // Option can not be smaller than this if only one.
404 case OPTION_MAXIMUM_SIZE :
406 mOptionMaxSize = dimension;
407 // Option max size not currently currently supported
411 case OPTION_MINIMUM_SIZE :
413 mOptionMinSize = dimension;
414 // Option min size not currently currently supported
417 case OPTION_DIVIDER_SIZE :
419 mOptionDividerSize = dimension;
422 // Resize Dividers not currently supported
429 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
431 switch( settingToCustomise )
433 case POPUP_MAXIMUM_SIZE :
437 case POPUP_MINIMUM_SIZE :
441 case OPTION_MAXIMUM_SIZE :
443 return mOptionMaxSize;
445 case OPTION_MINIMUM_SIZE :
447 return mOptionMinSize;
449 case OPTION_DIVIDER_SIZE :
451 return mOptionDividerSize;
458 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
463 case Toolkit::TextSelectionPopup::CLIPBOARD:
465 mClipboardIconImage = image;
468 case Toolkit::TextSelectionPopup::CUT :
470 mCutIconImage = image;
473 case Toolkit::TextSelectionPopup::COPY :
475 mCopyIconImage = image;
478 case Toolkit::TextSelectionPopup::PASTE :
480 mPasteIconImage = image;
483 case Toolkit::TextSelectionPopup::SELECT :
485 mSelectIconImage = image;
488 case Toolkit::TextSelectionPopup::SELECT_ALL :
490 mSelectAllIconImage = image;
495 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
500 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
504 case Toolkit::TextSelectionPopup::CLIPBOARD :
506 return mClipboardIconImage;
509 case Toolkit::TextSelectionPopup::CUT :
511 return mCutIconImage;
514 case Toolkit::TextSelectionPopup::COPY :
516 return mCopyIconImage;
519 case Toolkit::TextSelectionPopup::PASTE :
521 return mPasteIconImage;
524 case Toolkit::TextSelectionPopup::SELECT :
526 return mSelectIconImage;
529 case Toolkit::TextSelectionPopup::SELECT_ALL :
531 return mSelectAllIconImage;
536 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
540 return Dali::Image();
543 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
545 mOrderListOfButtons.clear();
546 mOrderListOfButtons.reserve( 8u );
548 // Create button for each possible option using Option priority
549 if ( !mCutIconImage )
551 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
553 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
555 if ( !mCopyIconImage )
557 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
559 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
561 if ( !mPasteIconImage )
563 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
565 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
567 if ( !mSelectIconImage )
568 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
569 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
571 if ( !mSelectAllIconImage )
573 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
575 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
577 if ( !mClipboardIconImage )
579 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
581 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
583 // Sort the buttons according their priorities.
584 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
587 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
589 const std::string& name = button.name;
590 const std::string& caption = button.caption;
591 Image iconImage = button.icon;
593 // 1. Create the backgrounds for the popup option both normal and pressed.
594 // Both containers will be added to a button.
596 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
597 optionContainer.SetFitHeight( 0 );
598 optionContainer.SetFitWidth( 0 );
600 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
601 optionPressedContainer.SetFitHeight( 0 );
602 optionPressedContainer.SetFitWidth( 0 );
603 optionPressedContainer.SetBackgroundColor( mPressedColor );
605 #ifdef DECORATOR_DEBUG
606 optionContainer.SetName("optionContainer");
607 optionPressedContainer.SetName("optionPressedContainer");
613 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
614 captionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
615 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
616 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
618 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
619 pressedCaptionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
620 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
621 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
624 padding.left = 24.0f;
625 padding.right = 24.0f;
627 padding.bottom = 14.0f;
628 captionTextLabel.SetPadding( padding );
629 pressedCaptionTextLabel.SetPadding( padding );
631 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
632 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
635 int depth = Self().GetHierarchyDepth();
636 // 3. Create the icons
639 ImageActor pressedIcon = ImageActor::New( iconImage );
640 ImageActor icon = ImageActor::New( iconImage );
641 icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
642 pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
644 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
645 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
646 icon.SetColor( mIconColor );
648 if ( showCaption & showIcons )
650 optionContainer.SetFitHeight( 1 );
651 optionContainer.SetFitWidth( 1 );
652 optionPressedContainer.SetFitHeight( 1 );
653 optionPressedContainer.SetFitWidth( 1 );
656 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
657 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
659 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
660 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
663 // 4. Create a option.
664 Toolkit::PushButton option = Toolkit::PushButton::New();
665 option.SetName( name );
666 option.SetAnimationTime( 0.0f );
667 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
671 case Toolkit::TextSelectionPopup::CUT:
673 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
676 case Toolkit::TextSelectionPopup::COPY:
678 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
681 case Toolkit::TextSelectionPopup::PASTE:
683 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
686 case Toolkit::TextSelectionPopup::SELECT:
688 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
691 case Toolkit::TextSelectionPopup::SELECT_ALL:
693 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
696 case Toolkit::TextSelectionPopup::CLIPBOARD:
698 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
701 case Toolkit::TextSelectionPopup::NONE:
708 // 5. Set the normal option image.
709 option.SetButtonImage( optionContainer );
711 // 6. Set the pressed option image
712 option.SetSelectedImage( optionPressedContainer );
714 // 7 Add option to tool bar
715 mToolbar.AddOption( option );
717 // 8. Add the divider
720 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
722 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
723 #ifdef DECORATOR_DEBUG
724 divider.SetName("Text's popup divider");
726 divider.SetSize( size );
727 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
728 divider.SetColor( mDividerColor );
729 divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
730 mToolbar.AddDivider( divider );
734 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
736 std::size_t numberOfOptions = 0u;
737 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
739 const ButtonRequirement& button( *it );
746 return numberOfOptions;
749 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
751 // Iterate list of buttons and add active ones to Toolbar
752 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
753 std::size_t numberOfOptionsAdded = 0u;
754 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
756 const ButtonRequirement& button( *it );
757 if ( button.enabled )
759 numberOfOptionsAdded++;
760 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
765 void TextSelectionPopup::CreatePopup()
768 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
769 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
770 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
774 mToolbar = Toolkit::TextSelectionToolbar::New();
775 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
776 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
777 self.Add( mToolbar );
778 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
782 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
783 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
787 mOptionDividerSize( Size( 2.0f, 0.0f) ),
788 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
789 mCallbackInterface( callbackInterface ),
790 mDividerColor( DEFAULT_POPUP_DIVIDER_COLOR ),
791 mIconColor( DEFAULT_OPTION_ICON ),
792 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
793 mSelectOptionPriority( 1 ),
794 mSelectAllOptionPriority ( 2 ),
795 mCutOptionPriority ( 4 ),
796 mCopyOptionPriority ( 3 ),
797 mPasteOptionPriority ( 5 ),
798 mClipboardOptionPriority( 6 ),
800 mShowCaptions( true )
804 TextSelectionPopup::~TextSelectionPopup()
809 } // namespace Internal
811 } // namespace Toolkit