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/buttons/push-button.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>
33 // todo Move this to adaptor??
34 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
47 const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
48 const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
49 const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 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( 1.0f, 1.0f, 1.0f, 1.0f ) );
52 const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
53 const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
55 const std::string DEFAULT_POPUP_BACKGROUND_IMAGE( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
56 const std::string OPTION_ICON_CLIPBOARD( DALI_IMAGE_DIR "copy_paste_icon_clipboard.png" );
57 const std::string OPTION_ICON_COPY( DALI_IMAGE_DIR "copy_paste_icon_copy.png" );
58 const std::string OPTION_ICON_CUT( DALI_IMAGE_DIR "copy_paste_icon_cut.png" );
59 const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" );
60 const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" );
61 const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" );
63 const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 470.0f, 120.0f ); ///< The maximum size of the popup.
65 const float OPTION_TEXT_LINE_HEIGHT( 32.0f ); ///< The line height of the text.
66 const Dali::Vector2 OPTION_ICON_SIZE( 0.f, 0.f ); ///< The size of the icon.
67 const float OPTION_GAP_ICON_TEXT( 6.f ); ///< The gap between the icon and the text
68 const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon.
69 const float OPTION_MAX_WIDTH( DEFAULT_POPUP_MAX_SIZE.width / 6 ); ///< The maximum width of the option (currently set to the max)
70 const float OPTION_MIN_WIDTH( 86.0f ); ///< The minimum width of the option.
72 const float POPUP_DIVIDER_WIDTH( 1.f ); ///< The size of the divider.
74 const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail.
75 const float POPUP_TAIL_Y_OFFSET( 5.f ); ///< The y offset of the tail (when its position is on the bottom).
76 const float POPUP_TAIL_TOP_Y_OFFSET( 3.f ); ///< The y offset of the tail (when its position is on the top).
78 const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
79 const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
81 const char* const OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
82 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
83 const char* const OPTION_CUT("option-cut"); // "Cut" popup option.
84 const char* const OPTION_COPY("option-copy"); // "Copy" popup option.
85 const char* const OPTION_PASTE("option-paste"); // "Paste" popup option.
86 const char* const OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
90 //// Comparison function for ButtonRequirement Priority
91 //bool TextSelectionPopup::PriorityCompare( ButtonRequirement const& a, ButtonRequirement const& b )
93 // return a.priority < b.priority;
97 Dali::Toolkit::TextSelectionPopup TextSelectionPopup::New()
99 // Create the implementation, temporarily owned by this handle on stack
100 IntrusivePtr< TextSelectionPopup > impl = new TextSelectionPopup();
102 // Pass ownership to CustomActor handle
103 Dali::Toolkit::TextSelectionPopup handle( *impl );
105 // Second-phase init of the implementation
106 // This can only be done after the CustomActor connection has been made...
112 void TextSelectionPopup::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
114 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
118 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
122 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
124 impl.SetPopupMaxSize( value.Get< Vector2 >() );
127 case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
129 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
130 impl.SetPopupImage( POPUP_BACKGROUND, image );
133 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
135 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
136 impl.SetPopupImage( POPUP_CLIPBOARD_BUTTON, image );
139 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
141 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
142 impl.SetPopupImage( POPUP_CUT_BUTTON_ICON, image );
145 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
147 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
148 impl.SetPopupImage( POPUP_COPY_BUTTON_ICON, image );
151 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
153 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
154 impl.SetPopupImage( POPUP_PASTE_BUTTON_ICON, image );
157 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
159 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
160 impl.SetPopupImage( POPUP_SELECT_BUTTON_ICON, image );
163 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
165 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
166 impl.SetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON, image );
170 } // TextSelectionPopup
173 Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::Index index )
175 Property::Value value;
177 Toolkit::TextSelectionPopup selectionPopup = Toolkit::TextSelectionPopup::DownCast( Dali::BaseHandle( object ) );
181 TextSelectionPopup& impl( GetImpl( selectionPopup ) );
185 case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
187 value = impl.GetPopupMaxSize();
190 case Toolkit::TextSelectionPopup::Property::POPUP_BACKGROUND_IMAGE:
192 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_BACKGROUND ) );
195 value = image.GetUrl();
199 case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
201 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CLIPBOARD_BUTTON ) );
204 value = image.GetUrl();
208 case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
210 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_CUT_BUTTON_ICON ) );
213 value = image.GetUrl();
217 case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
219 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_COPY_BUTTON_ICON ) );
222 value = image.GetUrl();
226 case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
228 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_PASTE_BUTTON_ICON ) );
231 value = image.GetUrl();
235 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
237 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_BUTTON_ICON ) );
240 value = image.GetUrl();
244 case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
246 ResourceImage image = ResourceImage::DownCast( impl.GetPopupImage( POPUP_SELECT_ALL_BUTTON_ICON ) );
249 value = image.GetUrl();
258 void TextSelectionPopup::OnInitialize()
263 void TextSelectionPopup::OnRelayout( const Vector2& size, RelayoutContainer& container )
268 void TextSelectionPopup::SetPopupMaxSize( const Size& maxSize )
273 const Dali::Vector2& TextSelectionPopup::GetPopupMaxSize() const
278 void TextSelectionPopup::SetPopupImage( PopupParts part, Dali::Image image )
282 case POPUP_BACKGROUND :
284 mBackgroundImage = image;
287 case POPUP_CLIPBOARD_BUTTON :
289 mClipboardIconImage = image;
292 case POPUP_CUT_BUTTON_ICON :
294 mCutIconImage = image;
297 case POPUP_COPY_BUTTON_ICON :
299 mCopyIconImage = image;
302 case POPUP_PASTE_BUTTON_ICON :
304 mPasteIconImage = image;
307 case POPUP_SELECT_BUTTON_ICON :
309 mSelectIconImage = image;
312 case POPUP_SELECT_ALL_BUTTON_ICON :
314 mSelectAllIconImage = image;
321 Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part )
325 case POPUP_BACKGROUND :
327 return mBackgroundImage;
330 case POPUP_CLIPBOARD_BUTTON :
332 return mClipboardIconImage;
335 case POPUP_CUT_BUTTON_ICON :
337 return mCutIconImage;
340 case POPUP_COPY_BUTTON_ICON :
342 return mCopyIconImage;
345 case POPUP_PASTE_BUTTON_ICON :
347 return mPasteIconImage;
350 case POPUP_SELECT_BUTTON_ICON :
352 return mSelectIconImage;
355 case POPUP_SELECT_ALL_BUTTON_ICON :
357 return mSelectAllIconImage;
362 DALI_ASSERT_DEBUG( "Unknown Popup Part" );
366 return Dali::Image();
369 void TextSelectionPopup::CreateOrderedListOfPopupOptions()
371 mOrderListOfButtons.clear();
373 // Create button for each possible option using Option priority
374 if ( !mCutIconImage )
376 mCutIconImage = ResourceImage::New( OPTION_ICON_CUT );
378 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), mCutIconImage, true ) );
380 if ( !mCopyIconImage )
382 mCopyIconImage = ResourceImage::New( OPTION_ICON_COPY );
384 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), mCopyIconImage, true ) );
386 if ( !mPasteIconImage )
388 mPasteIconImage = ResourceImage::New( OPTION_ICON_PASTE );
390 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), mPasteIconImage, true ) );
392 if ( !mSelectIconImage )
393 mSelectIconImage = ResourceImage::New( OPTION_ICON_SELECT );
394 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), mSelectIconImage, true ) );
396 if ( !mSelectAllIconImage )
398 mSelectAllIconImage = ResourceImage::New( OPTION_ICON_SELECT_ALL );
400 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), mSelectAllIconImage, true ) );
402 if ( !mClipboardIconImage )
404 mClipboardIconImage = ResourceImage::New( OPTION_ICON_CLIPBOARD );
406 mOrderListOfButtons.push_back( ButtonRequirement( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), mClipboardIconImage, true ) );
408 // Sort the buttons according their priorities.
409 std::sort( mOrderListOfButtons.begin(), mOrderListOfButtons.end(), TextSelectionPopup::ButtonPriorityCompare() );
412 void TextSelectionPopup::CreateBackground()
414 if ( !mBackgroundImage )
416 mBackgroundImage = ResourceImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE );
419 NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( mBackgroundImage );
420 if( backgroundImageNinePatch )
422 const Size ninePatchImageSize = Size( static_cast<float>( mBackgroundImage.GetWidth() ), static_cast<float>( mBackgroundImage.GetHeight() ) );
423 Rect<int> childRect = backgroundImageNinePatch.GetChildRectangle();
425 // -1u because of the cropping.
426 mNinePatchMargins.x = childRect.x - 1u;
427 mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u;
428 mNinePatchMargins.z = childRect.y - 1u;
429 mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u;
432 SetBackgroundImage( mBackgroundImage );
433 SetBackgroundColor( mBackgroundColor );
436 void TextSelectionPopup::AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons )
438 // 1. Create the backgrounds for the popup option both normal and pressed.
439 // Both containers will be added to a button.
440 Actor optionContainer = Actor::New();
441 optionContainer.SetRelayoutEnabled( true );
442 optionContainer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
443 optionContainer.SetDrawMode( DrawMode::OVERLAY );
444 optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
446 ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
447 optionPressedContainer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
448 optionPressedContainer.SetDrawMode( DrawMode::OVERLAY );
449 optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
452 Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
453 captionTextLabel.SetResizePolicy( FIXED, ALL_DIMENSIONS );
454 captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
455 // optionContainer.Add( captionTextLabel ); Temporary removed.
457 Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
458 pressedCaptionTextLabel.SetResizePolicy( FIXED, ALL_DIMENSIONS );
459 pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
460 // optionPressedContainer.Add( pressedCaptionTextLabel ); Temporary removed.
462 // Calculates the icon/text position.
463 float iconTextOffsetY = 0.0f;
467 // 3. Create the icons
468 ImageActor pressedIcon = ImageActor::New( iconImage );
469 ImageActor icon = ImageActor::New( iconImage );
471 optionContainer.Add( icon );
472 optionPressedContainer.Add( pressedIcon );
474 iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) );
476 icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
477 icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
478 icon.SetY( iconTextOffsetY );
480 pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER );
481 pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
482 pressedIcon.SetY( iconTextOffsetY );
484 // Layout icon + gap + text
485 captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
486 pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
487 pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
488 captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
489 pressedCaptionTextLabel.SetY( -iconTextOffsetY );
490 captionTextLabel.SetY( -iconTextOffsetY );
494 // Centre option text
495 captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
496 captionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
497 pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
498 pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER );
501 // Calculate the size of the text.
502 Vector3 textSize = captionTextLabel.GetNaturalSize();
503 textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH );
505 // Set the size to the text. Text will be ellipsized if exceeds the max width.
506 captionTextLabel.SetSize( textSize.GetVectorXY() );
507 pressedCaptionTextLabel.SetSize( textSize.GetVectorXY() );
509 // 4. Calculate the size of option.
511 // The width is the max size of the text or the icon plus the margins clamped between the option min and max size.
512 // The height is the whole popup height minus the ninepatch margins.
513 const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ),
514 DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w );
516 optionContainer.SetSize( optionSize );
517 optionPressedContainer.SetSize( optionSize );
519 // 5. Create a option.
520 Toolkit::PushButton option = Toolkit::PushButton::New();
521 option.SetResizePolicy( FIXED, ALL_DIMENSIONS );
522 option.SetSize( optionSize );
523 option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
524 option.SetX( mContentSize.width );
525 option.SetName( name );
526 option.SetAnimationTime( 0.0f );
527 //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
529 parent.Add( option );
531 // 6. Set the normal option image.
532 option.SetButtonImage( optionContainer );
534 // 7. Set the pressed option image
535 option.SetSelectedImage( optionPressedContainer );
537 // 8. Update the content size.
538 mContentSize.width += optionSize.width;
539 mContentSize.height = std::max ( optionSize.height, mContentSize.height );
541 // 9. Add the divider
544 const Size size( POPUP_DIVIDER_WIDTH, mContentSize.height );
546 ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE );
547 divider.SetResizePolicy( FIXED, ALL_DIMENSIONS );
548 divider.SetSize( size );
549 divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
550 divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
551 divider.SetPosition( mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f );
552 parent.Add( divider );
556 void TextSelectionPopup::SetUpPopup( Size& size )
560 // Create Layer and Stencil.
561 mStencilLayer = Layer::New();
562 ImageActor stencil = CreateSolidColorActor( Color::RED );
563 stencil.SetDrawMode( DrawMode::STENCIL );
564 stencil.SetVisible( true );
565 Actor scrollview = Actor::New(); //todo make a scrollview
566 stencil.SetRelayoutEnabled( true );
568 self.SetResizePolicy( FIXED, ALL_DIMENSIONS );
569 self.SetSize( mRequiredPopUpSize ); // control matches stencil size
571 mStencilLayer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
572 mStencilLayer.SetSize( size ); // matches stencil size
574 stencil.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
575 scrollview.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
576 mButtons.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
578 mStencilLayer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
579 scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT);
580 mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT );
582 mStencilLayer.SetPosition( mNinePatchMargins.x, mNinePatchMargins.y );
584 self.Add( mStencilLayer );
585 mStencilLayer.Add( stencil );
586 mStencilLayer.Add( scrollview );
587 scrollview.Add( mButtons );
590 void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons )
592 mShowIcons = showIcons;
594 mContentSize = Vector2::ZERO;
596 mButtons = Actor::New();
597 mButtons.SetRelayoutEnabled( true );
599 // Add the options into the buttons container.
601 // 1. Determine how many buttons are active and should be added to container.
602 std::size_t numberOfOptions = 0u;
603 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
605 const ButtonRequirement& button( *it );
612 // 2. Iterate list of buttons and add active ones.
613 std::size_t optionsAdded = 0u;
614 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
616 const ButtonRequirement& button( *it );
617 if ( button.enabled )
620 AddOption( mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mShowIcons );
624 // Calculate the size of the whole popup which may not be all visible.
625 mRequiredPopUpSize = Size( std::min( mMaxSize.width, mContentSize.width + mNinePatchMargins.x + mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE.height );
627 // Size of the contents within the popup
628 mVisiblePopUpSize = Size( mRequiredPopUpSize.width - mNinePatchMargins.x - mNinePatchMargins.y, mRequiredPopUpSize.height - mNinePatchMargins.z - mNinePatchMargins.w );
631 void TextSelectionPopup::CreatePopup()
633 if ( !mStencilLayer )
635 CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown
637 AddPopupOptions( true, true );
638 SetUpPopup( mVisiblePopUpSize );
641 mStencilLayer.RaiseToTop();
644 TextSelectionPopup::TextSelectionPopup()
645 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
646 mMaxSize ( DEFAULT_POPUP_MAX_SIZE ),
647 mVisiblePopUpSize( DEFAULT_POPUP_MAX_SIZE ),
648 mRequiredPopUpSize( DEFAULT_POPUP_MAX_SIZE ),
649 mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
650 mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
651 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
652 mIconColor( DEFAULT_OPTION_ICON ),
653 mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
654 mTextColor( DEFAULT_OPTION_TEXT ),
655 mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
656 mSelectOptionPriority( 1 ),
657 mSelectAllOptionPriority ( 2 ),
658 mCutOptionPriority ( 3 ),
659 mCopyOptionPriority ( 4 ),
660 mPasteOptionPriority ( 5 ),
661 mClipboardOptionPriority( 6 ),
666 TextSelectionPopup::~TextSelectionPopup()
671 } // namespace Internal
673 } // namespace Toolkit