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/public-api/controls/default-controls/solid-color-actor.h>
23 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
26 #include <dali/public-api/images/nine-patch-image.h>
27 #include <dali/public-api/images/resource-image.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/math/vector4.h>
30 #include <dali/devel-api/object/type-registry-helper.h>
45 // todo Move this to adaptor??
46 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
48 const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.69f, 0.93f, 0.93f, 1.0f ) );
49 const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
50 const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.5f, 1.0f, 1.0f, 1.0f ) );
52 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "selection-popup-bg#.png" );
53 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
54 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
55 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
56 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
57 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
58 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
60 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
62 #ifdef DGETTEXT_ENABLED
64 #define POPUP_CUT_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CUT")
65 #define POPUP_COPY_STRING GET_LOCALE_TEXT("IDS_COM_BODY_COPY")
66 #define POPUP_PASTE_STRING GET_LOCALE_TEXT("IDS_COM_BODY_PASTE")
67 #define POPUP_SELECT_STRING GET_LOCALE_TEXT("IDS_COM_SK_SELECT")
68 #define POPUP_SELECT_ALL_STRING GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL")
69 #define POPUP_CLIPBOARD_STRING GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD")
73 #define POPUP_CUT_STRING "Cut"
74 #define POPUP_COPY_STRING "Copy"
75 #define POPUP_PASTE_STRING "Paste"
76 #define POPUP_SELECT_STRING "Select"
77 #define POPUP_SELECT_ALL_STRING "Select All"
78 #define POPUP_CLIPBOARD_STRING "Clipboard"
82 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
83 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
84 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
85 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
86 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
87 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
91 return Toolkit::TextSelectionPopup::New();
94 // Setup properties, signals and actions using the type-registry.
96 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionPopup, Toolkit::Control, Create );
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-max-size", VECTOR2, POPUP_MAX_SIZE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-min-size", VECTOR2, POPUP_MIN_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-max-size", VECTOR2, OPTION_MAX_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-min-size", VECTOR2, OPTION_MIN_SIZE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "option-divider-size", VECTOR2, OPTION_DIVIDER_SIZE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-clipboard-button-image", STRING, POPUP_CLIPBOARD_BUTTON_ICON_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-cut-button-image", STRING, POPUP_CUT_BUTTON_ICON_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-copy-button-image", STRING, POPUP_COPY_BUTTON_ICON_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
110 DALI_TYPE_REGISTRATION_END()
114 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
116 // Create the implementation, temporarily owned by this handle on stack
117 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
119 // Pass ownership to CustomActor handle
120 Dali::Toolkit::TextSelectionPopup handle( *impl );
122 // Second-phase init of the implementation
123 // This can only be done after the CustomActor connection has been made...
129 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable )
131 // Create the implementation, temporarily owned by this handle on stack
132 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
134 // Pass ownership to CustomActor handle
135 Dali::Toolkit::TextSelectionPopup handle( *impl );
137 impl->mEnabledButtons = buttonsToEnable;
139 // Second-phase init of the implementation
140 // This can only be done after the CustomActor connection has been made...
145 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
151 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
155 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
157 impl.SetDimensionToCustomise( POPUP_MAXIMUM_SIZE, value.Get< Vector2 >() );
160 case Toolkit::TextSelectionPopup::Property::POPUP_MIN_SIZE:
162 impl.SetDimensionToCustomise( POPUP_MINIMUM_SIZE, value.Get< Vector2 >() );
165 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
167 impl.SetDimensionToCustomise( OPTION_MAXIMUM_SIZE, value.Get< Vector2 >() );
170 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
172 impl.SetDimensionToCustomise( OPTION_MINIMUM_SIZE, value.Get< Vector2>() );
175 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
177 impl.SetDimensionToCustomise( OPTION_DIVIDER_SIZE, value.Get< Vector2>() );
180 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
182 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
183 impl.SetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD, image );
186 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
188 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
189 impl.SetButtonImage( Toolkit::TextSelectionPopup::CUT, image );
192 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
194 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
195 impl.SetButtonImage( Toolkit::TextSelectionPopup::COPY, image );
198 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
200 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
201 impl.SetButtonImage( Toolkit::TextSelectionPopup::PASTE, image );
204 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
206 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
207 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT, image );
210 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
212 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
213 impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
217 } // TextSelectionPopup
220 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
222 Property::Value value;
224 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
228 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
232 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
234 value = impl.GetDimensionToCustomise( POPUP_MAXIMUM_SIZE );
237 case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
239 value = impl.GetDimensionToCustomise( OPTION_MAXIMUM_SIZE );
242 case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
244 value = impl.GetDimensionToCustomise( OPTION_MINIMUM_SIZE );
247 case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
249 value = impl.GetDimensionToCustomise( OPTION_DIVIDER_SIZE );
252 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
254 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CLIPBOARD ) );
257 value = image.GetUrl();
261 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
263 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::CUT ) );
266 value = image.GetUrl();
270 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
272 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::COPY ) );
275 value = image.GetUrl();
279 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
281 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::PASTE ) );
284 value = image.GetUrl();
288 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
290 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT ) );
293 value = image.GetUrl();
297 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
299 ResourceImage image = ResourceImage::DownCast( impl.GetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL ) );
302 value = image.GetUrl();
311 void TextSelectionPopup::OnInitialize()
316 bool TextSelectionPopup::OnButtonPressed( Toolkit::Button button )
321 void TextSelectionPopup::SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension )
323 switch( settingToCustomise )
325 case POPUP_MAXIMUM_SIZE :
328 mMaxSize = dimension;
331 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
335 case POPUP_MINIMUM_SIZE :
338 mMinSize = dimension;
339 // Option can not be smaller than this if only one.
342 case OPTION_MAXIMUM_SIZE :
344 mOptionMaxSize = dimension;
345 // Option max size not currently currently supported
349 case OPTION_MINIMUM_SIZE :
351 mOptionMinSize = dimension;
352 // Option min size not currently currently supported
355 case OPTION_DIVIDER_SIZE :
357 mOptionDividerSize = dimension;
360 // Resize Dividers not currently supported
367 Size TextSelectionPopup::GetDimensionToCustomise( const PopupCustomisations& settingToCustomise )
369 switch( settingToCustomise )
371 case POPUP_MAXIMUM_SIZE :
375 case POPUP_MINIMUM_SIZE :
379 case OPTION_MAXIMUM_SIZE :
381 return mOptionMaxSize;
383 case OPTION_MINIMUM_SIZE :
385 return mOptionMinSize;
387 case OPTION_DIVIDER_SIZE :
389 return mOptionDividerSize;
396 void TextSelectionPopup::SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image )
401 case Toolkit::TextSelectionPopup::CLIPBOARD:
403 mClipboardIconImage = image;
406 case Toolkit::TextSelectionPopup::CUT :
408 mCutIconImage = image;
411 case Toolkit::TextSelectionPopup::COPY :
413 mCopyIconImage = image;
416 case Toolkit::TextSelectionPopup::PASTE :
418 mPasteIconImage = image;
421 case Toolkit::TextSelectionPopup::SELECT :
423 mSelectIconImage = image;
426 case Toolkit::TextSelectionPopup::SELECT_ALL :
428 mSelectAllIconImage = image;
433 DALI_ASSERT_DEBUG( "TextSelectionPopup SetPopupImage Unknown Button" );
438 Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::Buttons button )
442 case Toolkit::TextSelectionPopup::CLIPBOARD :
444 return mClipboardIconImage;
447 case Toolkit::TextSelectionPopup::CUT :
449 return mCutIconImage;
452 case Toolkit::TextSelectionPopup::COPY :
454 return mCopyIconImage;
457 case Toolkit::TextSelectionPopup::PASTE :
459 return mPasteIconImage;
462 case Toolkit::TextSelectionPopup::SELECT :
464 return mSelectIconImage;
467 case Toolkit::TextSelectionPopup::SELECT_ALL :
469 return mSelectAllIconImage;
474 DALI_ASSERT_DEBUG( "TextSelectionPopup GetPopupImage Unknown Button" );
478 return Dali::Image();
481 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
483 mOrderListOfButtons.clear();
485 // Create button for each possible option using Option priority
486 if ( !mCutIconImage )
488 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
490 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CUT, mCutOptionPriority, OPTION_CUT, POPUP_CUT_STRING , mCutIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CUT) ) );
492 if ( !mCopyIconImage )
494 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
496 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::COPY, mCopyOptionPriority, OPTION_COPY, POPUP_COPY_STRING, mCopyIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::COPY) ) );
498 if ( !mPasteIconImage )
500 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
502 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::PASTE, mPasteOptionPriority, OPTION_PASTE, POPUP_PASTE_STRING, mPasteIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::PASTE) ) );
504 if ( !mSelectIconImage )
505 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
506 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT, mSelectOptionPriority, OPTION_SELECT_WORD, POPUP_SELECT_STRING, mSelectIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT) ) );
508 if ( !mSelectAllIconImage )
510 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
512 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::SELECT_ALL, mSelectAllOptionPriority, OPTION_SELECT_ALL, POPUP_SELECT_ALL_STRING, mSelectAllIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::SELECT_ALL) ) );
514 if ( !mClipboardIconImage )
516 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
518 mOrderListOfButtons.push_back( ButtonRequirement( Toolkit::TextSelectionPopup::CLIPBOARD, mClipboardOptionPriority, OPTION_CLIPBOARD, POPUP_CLIPBOARD_STRING, mClipboardIconImage, ( mEnabledButtons & Toolkit::TextSelectionPopup::CLIPBOARD) ) );
520 // Sort the buttons according their priorities.
521 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
524 void TextSelectionPopup::AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption )
526 // 1. Create the backgrounds for the popup option both normal and pressed.
527 // Both containers will be added to a button.
529 Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
530 optionContainer.SetDrawMode( DrawMode::OVERLAY );
531 optionContainer.SetFitHeight( 0 );
532 optionContainer.SetFitWidth( 0 );
534 Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
535 optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
536 optionPressedContainer.SetFitHeight( 0 );
537 optionPressedContainer.SetFitWidth( 0 );
538 optionPressedContainer.SetBackgroundColor(Color::RED); //todo member variable
540 #ifdef DECORATOR_DEBUG
541 optionContainer.SetName("optionContainer");
542 optionPressedContainer.SetName("optionPressedContainer");
548 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
549 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
550 captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
552 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
553 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
554 pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
557 padding.left = 24.0f;
558 padding.right = 24.0f;
560 padding.bottom = 14.0f;
561 captionTextLabel.SetPadding( padding );
562 pressedCaptionTextLabel.SetPadding( padding );
564 optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
565 optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
568 // 3. Create the icons
571 ImageActor pressedIcon = ImageActor::New( iconImage );
572 ImageActor icon = ImageActor::New( iconImage );
574 icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
575 pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
576 icon.SetColor( mIconColor );
577 pressedIcon.SetColor( mIconPressedColor );
579 if ( showCaption & showIcons )
581 optionContainer.SetFitHeight( 1 );
582 optionContainer.SetFitWidth( 1 );
583 optionPressedContainer.SetFitHeight( 1 );
584 optionPressedContainer.SetFitWidth( 1 );
587 optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
588 optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
590 icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
591 pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
594 // 4. Create a option.
595 Toolkit::PushButton option = Toolkit::PushButton::New();
596 option.SetName( name );
597 option.SetAnimationTime( 0.0f );
598 option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
599 option.ClickedSignal().Connect( this, &TextSelectionPopup::OnButtonPressed );
601 // 5. Set the normal option image.
602 option.SetButtonImage( optionContainer );
604 // 6. Set the pressed option image
605 option.SetSelectedImage( optionPressedContainer );
607 // 7 Add option to tool bar
608 mToolbar.AddOption( option );
610 // 8. Add the divider
613 const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
615 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
616 divider.SetSize( size );
617 divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
618 divider.SetColor( mLineColor );
619 mToolbar.AddDivider( divider );
623 std::size_t TextSelectionPopup::GetNumberOfEnabledOptions()
625 std::size_t numberOfOptions = 0u;
626 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
628 const ButtonRequirement& button( *it );
635 return numberOfOptions;
638 void TextSelectionPopup::AddPopupOptionsToToolbar( bool showIcons, bool showCaptions )
640 // Iterate list of buttons and add active ones to Toolbar
641 std::size_t numberOfOptionsRequired = GetNumberOfEnabledOptions();
642 std::size_t numberOfOptionsAdded = 0u;
643 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
645 const ButtonRequirement& button( *it );
646 if ( button.enabled )
648 numberOfOptionsAdded++;
649 AddOption( button.name, button.caption, button.icon, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
654 void TextSelectionPopup::CreatePopup()
657 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
658 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
659 SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) );
663 mToolbar = Toolkit::TextSelectionToolbar::New();
664 mToolbar.SetParentOrigin( ParentOrigin::CENTER );
665 mToolbar.SetProperty( Toolkit::TextSelectionToolbar::Property::MAX_SIZE, mMaxSize );
666 self.Add( mToolbar );
667 AddPopupOptionsToToolbar( mShowIcons, mShowCaptions );
671 TextSelectionPopup::TextSelectionPopup()
672 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
676 mOptionDividerSize( Size( 2.0f, 0.0f) ),
677 mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
678 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
679 mIconColor( DEFAULT_OPTION_ICON ),
680 mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
681 mSelectOptionPriority( 1 ),
682 mSelectAllOptionPriority ( 2 ),
683 mCutOptionPriority ( 3 ),
684 mCopyOptionPriority ( 4 ),
685 mPasteOptionPriority ( 5 ),
686 mClipboardOptionPriority( 6 ),
688 mShowCaptions( true )
692 TextSelectionPopup::~TextSelectionPopup()
697 } // namespace Internal
699 } // namespace Toolkit