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 float DEFAULT_CAPTION_POINT_SIZE = 8.0f; // todo This should be from the style sheet not fixed.
58 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
59 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
60 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
61 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
62 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
63 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
64 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
66 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
68 #ifdef DGETTEXT_ENABLED
70 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
71 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
72 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
73 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
74 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
75 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
79 #define POPUP_CUT_STRING "Cut"
80 #define POPUP_COPY_STRING "Copy"
81 #define POPUP_PASTE_STRING "Paste"
82 #define POPUP_SELECT_STRING "Select"
83 #define POPUP_SELECT_ALL_STRING "Select All"
84 #define POPUP_CLIPBOARD_STRING "Clipboard"
88 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
89 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
90 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
91 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
92 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
93 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
97 return Toolkit::TextSelectionPopup::New( Toolkit::TextSelectionPopup::NONE, NULL );
100 // Setup properties, signals and actions using the type-registry.
102 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
116 DALI_TYPE_REGISTRATION_END()
121 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
122 TextSelectionPopupCallbackInterface* callbackInterface )
124 // Create the implementation, temporarily owned by this handle on stack
125 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup( callbackInterface );
127 // Pass ownership to CustomActor handle
128 Dali::Toolkit::TextSelectionPopup handle( *impl );
130 impl->mEnabledButtons = buttonsToEnable;
131 // Second-phase init of the implementation
132 // This can only be done after the CustomActor connection has been made...
138 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
140 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
144 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
148 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
150 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
153 case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE:
155 impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
158 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
160 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
163 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
165 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
168 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
170 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
173 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
175 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
176 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
179 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
181 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
182 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
185 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
187 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
188 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
191 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
193 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
194 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
197 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
199 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
200 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
203 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
205 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
206 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
210 } // TextSelectionPopup
213 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
215 Property::Value value;
217 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
221 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
225 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
227 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
230 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
232 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
235 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
237 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
240 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
242 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
245 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
247 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
250 value = image.GetUrl();
254 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
256 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
259 value = image.GetUrl();
263 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
265 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
268 value = image.GetUrl();
272 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
274 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
277 value = image.GetUrl();
281 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
283 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
286 value = image.GetUrl();
290 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
292 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
295 value = image.GetUrl();
304 void TextSelectionPopup::RaiseAbove( Layer target )
308 mToolbar.RaiseAbove( target );
312 void TextSelectionPopup::OnInitialize()
317 void TextSelectionPopup::OnStageConnection( int depth )
319 // Call the Control::OnStageConnection() to set the depth of the background.
320 Control::OnStageConnection( depth );
322 // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components.
325 bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button )
327 if( mCallbackInterface )
329 mCallbackInterface->TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
335 bool TextSelectionPopup::OnCopyButtonPressed( Toolkit::Button button )
337 if( mCallbackInterface )
339 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::COPY );
345 bool TextSelectionPopup::OnPasteButtonPressed( Toolkit::Button button )
347 if( mCallbackInterface )
349 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::PASTE );
355 bool TextSelectionPopup::OnSelectButtonPressed( Toolkit::Button button )
357 if( mCallbackInterface )
359 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT );
365 bool TextSelectionPopup::OnSelectAllButtonPressed( Toolkit::Button button )
367 if( mCallbackInterface )
369 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::SELECT_ALL );
375 bool TextSelectionPopup::OnClipboardButtonPressed( Toolkit::Button button )
377 if( mCallbackInterface )
379 mCallbackInterface->TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::CLIPBOARD );
385 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
387 switch( settingToCustomise )
389 case POPUP_MAXIMUM_SIZE :
392 mMaxSize = dimension;
395 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
399 case POPUP_MINIMUM_SIZE :
402 mMinSize = dimension;
403 // Option can not be smaller than this if only one.
406 case OPTION_MAXIMUM_SIZE :
408 mOptionMaxSize = dimension;
409 // Option max size not currently currently supported
413 case OPTION_MINIMUM_SIZE :
415 mOptionMinSize = dimension;
416 // Option min size not currently currently supported
419 case OPTION_DIVIDER_SIZE :
421 mOptionDividerSize = dimension;
424 // Resize Dividers not currently supported
431 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
433 switch( settingToCustomise )
435 case POPUP_MAXIMUM_SIZE :
439 case POPUP_MINIMUM_SIZE :
443 case OPTION_MAXIMUM_SIZE :
445 return mOptionMaxSize;
447 case OPTION_MINIMUM_SIZE :
449 return mOptionMinSize;
451 case OPTION_DIVIDER_SIZE :
453 return mOptionDividerSize;
460 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
465 case Toolkit::TextSelectionPopup::CLIPBOARD:
467 mClipboardIconImage = image;
470 case Toolkit::TextSelectionPopup::CUT :
472 mCutIconImage = image;
475 case Toolkit::TextSelectionPopup::COPY :
477 mCopyIconImage = image;
480 case Toolkit::TextSelectionPopup::PASTE :
482 mPasteIconImage = image;
485 case Toolkit::TextSelectionPopup::SELECT :
487 mSelectIconImage = image;
490 case Toolkit::TextSelectionPopup::SELECT_ALL :
492 mSelectAllIconImage = image;
497 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
502 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
506 case Toolkit::TextSelectionPopup::CLIPBOARD :
508 return mClipboardIconImage;
511 case Toolkit::TextSelectionPopup::CUT :
513 return mCutIconImage;
516 case Toolkit::TextSelectionPopup::COPY :
518 return mCopyIconImage;
521 case Toolkit::TextSelectionPopup::PASTE :
523 return mPasteIconImage;
526 case Toolkit::TextSelectionPopup::SELECT :
528 return mSelectIconImage;
531 case Toolkit::TextSelectionPopup::SELECT_ALL :
533 return mSelectAllIconImage;
538 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
542 return Dali::Image();
545 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
547 mOrderListOfButtons.clear();
548 mOrderListOfButtons.reserve( 8u );
550 // Create button for each possible option using Option priority
551 if ( !mCutIconImage )
553 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
555 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
557 if ( !mCopyIconImage )
559 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
561 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
563 if ( !mPasteIconImage )
565 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
567 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
569 if ( !mSelectIconImage )
570 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
571 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
573 if ( !mSelectAllIconImage )
575 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
577 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
579 if ( !mClipboardIconImage )
581 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
583 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
585 // Sort the buttons according their priorities.
586 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
589 void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
591 const std::string& name = button.name;
592 const std::string& caption = button.caption;
593 Image iconImage = button.icon;
595 // 1. Create the backgrounds for the popup option both normal and pressed.
596 // Both containers will be added to a button.
598 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
599 optionContainer.SetFitHeight( 0 );
600 optionContainer.SetFitWidth( 0 );
602 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
603 optionPressedContainer.SetFitHeight( 0 );
604 optionPressedContainer.SetFitWidth( 0 );
605 optionPressedContainer.SetBackgroundColor( mPressedColor );
607 #ifdef DECORATOR_DEBUG
608 optionContainer.SetName("optionContainer");
609 optionPressedContainer.SetName("optionPressedContainer");
615 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
616 captionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
617 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
618 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, DEFAULT_CAPTION_POINT_SIZE );
619 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
621 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
622 pressedCaptionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
623 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
624 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, DEFAULT_CAPTION_POINT_SIZE );
625 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
628 padding.left = 24.0f;
629 padding.right = 24.0f;
631 padding.bottom = 14.0f;
632 captionTextLabel.SetPadding( padding );
633 pressedCaptionTextLabel.SetPadding( padding );
635 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
636 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
639 int depth = Self().GetHierarchyDepth();
640 // 3. Create the icons
643 ImageActor pressedIcon = ImageActor::New( iconImage );
644 ImageActor icon = ImageActor::New( iconImage );
645 icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
646 pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
648 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
649 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
650 icon.SetColor( mIconColor );
652 if ( showCaption & showIcons )
654 optionContainer.SetFitHeight( 1 );
655 optionContainer.SetFitWidth( 1 );
656 optionPressedContainer.SetFitHeight( 1 );
657 optionPressedContainer.SetFitWidth( 1 );
660 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
661 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
663 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
664 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
667 // 4. Create a option.
668 Toolkit::PushButton option = Toolkit::PushButton::New();
669 option.SetName( name );
670 option.SetAnimationTime( 0.0f );
671 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
675 case Toolkit::TextSelectionPopup::CUT:
677 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCutButtonPressed );
680 case Toolkit::TextSelectionPopup::COPY:
682 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnCopyButtonPressed );
685 case Toolkit::TextSelectionPopup::PASTE:
687 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnPasteButtonPressed );
690 case Toolkit::TextSelectionPopup::SELECT:
692 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectButtonPressed );
695 case Toolkit::TextSelectionPopup::SELECT_ALL:
697 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnSelectAllButtonPressed );
700 case Toolkit::TextSelectionPopup::CLIPBOARD:
702 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnClipboardButtonPressed );
705 case Toolkit::TextSelectionPopup::NONE:
712 // 5. Set the normal option image.
713 option.SetButtonImage( optionContainer );
715 // 6. Set the pressed option image
716 option.SetSelectedImage( optionPressedContainer );
718 // 7 Add option to tool bar
719 mToolbar.AddOption( option );
721 // 8. Add the divider
724 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
726 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
727 #ifdef DECORATOR_DEBUG
728 divider.SetName("Text's popup divider");
730 divider.SetSize( size );
731 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
732 divider.SetColor( mDividerColor );
733 divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
734 mToolbar.AddDivider( divider );
738 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
740 std::size_t numberOfOptions = 0u;
741 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
743 const ButtonRequirement& button( *it );
750 return numberOfOptions;
753 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
755 // Iterate list of buttons and add active ones to Toolbar
756 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
757 std::size_t numberOfOptionsAdded = 0u;
758 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
760 const ButtonRequirement& button( *it );
761 if ( button.enabled )
763 numberOfOptionsAdded++;
764 AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
769 void TextSelectionPopup::CreatePopup()
772 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
773 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
774 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
778 mToolbar = Toolkit::TextSelectionToolbar::New();
779 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
780 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
781 self.Add( mToolbar );
782 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
786 TextSelectionPopup::TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface )
787 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
791 mOptionDividerSize( Size( 2.0f, 0.0f) ),
792 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
793 mCallbackInterface( callbackInterface ),
794 mDividerColor( DEFAULT_POPUP_DIVIDER_COLOR ),
795 mIconColor( DEFAULT_OPTION_ICON ),
796 mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
797 mSelectOptionPriority( 1 ),
798 mSelectAllOptionPriority ( 2 ),
799 mCutOptionPriority ( 4 ),
800 mCopyOptionPriority ( 3 ),
801 mPasteOptionPriority ( 5 ),
802 mClipboardOptionPriority( 6 ),
804 mShowCaptions( true )
808 TextSelectionPopup::~TextSelectionPopup()
813 } // namespace Internal
815 } // namespace Toolkit