2 * Copyright (c) 2014 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.
20 #include <dali/public-api/animation/constraints.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/images/resource-image.h>
25 #include <dali-toolkit/internal/controls/text-input/text-input-popup-impl.h>
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
31 #define GET_LOCALE_TEXT(string) dgettext("sys_string", string)
35 const Vector2 DEFAULT_POPUP_INDICATOR_OFFSET(0.0f, 60.0f);
37 // 1. For selection: should be above top of highlighted selection, or below bottom of highlighted selection + end handle.
38 // 2. For cursor: should be above top of cursor, or below bottom of cursor + grab handle.
41 * Image resource paths
43 const std::string POPUP_BACKGROUND( DALI_IMAGE_DIR "popup_bubble_bg.#.png" );
44 const std::string POPUP_BACKGROUND_EFFECT( DALI_IMAGE_DIR "popup_bubble_bg_ef.#.png" );
45 const std::string POPUP_BACKGROUND_LINE( DALI_IMAGE_DIR "popup_bubble_bg_line.#.png" );
47 const std::string POPUP_TAIL_BOTTOM( DALI_IMAGE_DIR "popup_bubble_tail_bottom.png" );
48 const std::string POPUP_TAIL_BOTTOM_EFFECT( DALI_IMAGE_DIR "popup_bubble_tail_bottom_ef.png" );
49 const std::string POPUP_TAIL_BOTTOM_LINE( DALI_IMAGE_DIR "popup_bubble_tail_bottom_line.png" );
50 const std::string POPUP_TAIL_TOP( DALI_IMAGE_DIR "popup_bubble_tail_top.png" );
51 const std::string POPUP_TAIL_TOP_EFFECT( DALI_IMAGE_DIR "popup_bubble_tail_top_ef.png" );
52 const std::string POPUP_TAIL_TOP_LINE( DALI_IMAGE_DIR "popup_bubble_tail_top_line.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" );
62 * Constant values for building the GUI
64 const Vector4 POPUP_MARGIN( 14.0f, 14.0f, 14.0f, 14.0f ); ///< Margin around the popup visible background Image.
65 const Vector4 POPUP_BORDER( 2.0f, 2.0f, 2.0f, 2.0f ); ///< The Border of the popup.
66 const Vector2 POPUP_MIN_SIZE( 0.0f, 126.0f ); ///< The minimum size of the popup.
67 const Vector2 POPUP_MAX_SIZE( 720.0f, 126.0f ); ///< The maximum size of the popup.
68 const float POPUP_TAIL_Y_OFFSET( -2.25f ); ///< The y offset of the tail.
69 const Vector2 POPUP_TAIL_SIZE( 36.0f, 36.0f ); ///< The size of the tail.
70 const Vector2 POPUP_DIVIDER_SIZE( 1.0f, 126.0f ); ///< The size of the divider.
72 const Vector4 OPTION_PADDING( 16.0f, 16.0f, 24.0f, 19.0f ); ///< The padding within the option to position icon and text away from the border. The order is left, right, top and bottom
73 const Vector2 OPTION_MAX_SIZE( 220.0f, 126.0f ); ///< The maximum size of the option.
74 const Vector2 OPTION_MIN_SIZE( 128.0f, 126.0f ); ///< The minimum size of the option.
75 const Vector2 OPTION_ICON_SIZE( 45.0f, 45.0f ); ///< The size of the icon.
76 const Vector2 OPTION_TEXT_MIN_SIZE( 128.0f, 30.0f ); ///< The minimum size of the text.
77 const float OPTION_GAP_ICON_TEXT( 8.0f ); ///< The gap between the icon and the text
79 const float HIDE_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup hide animation in seconds.
80 const float SHOW_POPUP_ANIMATION_DURATION( 0.2f ); ///< Duration of popup show animation in seconds.
85 const Vector4 DEFAULT_POPUP_BACKGROUND( Vector4( .20f, 0.29f, 0.44f, 1.0f ) );
86 const Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) );
87 const Vector4 DEFAULT_POPUP_LINE_COLOR( Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) );
88 const Vector4 DEFAULT_OPTION_ICON( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
89 const Vector4 DEFAULT_OPTION_ICON_PRESSED( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
90 const Vector4 DEFAULT_OPTION_TEXT( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
91 const Vector4 DEFAULT_OPTION_TEXT_PRESSED( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
93 } // unnamed namespace
104 const char* const TextInputPopup::SIGNAL_PRESSED = "pressed";
105 const char* const TextInputPopup::SIGNAL_HIDE_FINISHED = "hide-finished";
106 const char* const TextInputPopup::SIGNAL_SHOW_FINISHED = "show-finished";
108 const char* const TextInputPopup::OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
109 const char* const TextInputPopup::OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
110 const char* const TextInputPopup::OPTION_CUT("option-cut"); // "Cut" popup option.
111 const char* const TextInputPopup::OPTION_COPY("option-copy"); // "Copy" popup option.
112 const char* const TextInputPopup::OPTION_PASTE("option-paste"); // "Paste" popup option.
113 const char* const TextInputPopup::OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
115 TextInputPopup::TextInputPopup()
116 : mState(StateHidden),
117 mRoot( Layer::New() ),
120 mPopupTailXPosition( 0.0f ),
122 mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
123 mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
124 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
125 mIconColor( DEFAULT_OPTION_ICON ),
126 mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
127 mTextColor( DEFAULT_OPTION_TEXT ),
128 mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
129 mSelectOptionPriority(1),
130 mSelectAllOptionPriority(2),
131 mCutOptionPriority(3),
132 mCopyOptionPriority(4),
133 mPasteOptionPriority(5),
134 mClipboardOptionPriority(6),
136 mHideFinishedSignal(),
137 mShowFinishedSignal()
139 mRoot.SetParentOrigin( ParentOrigin::TOP_LEFT );
140 mRoot.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
143 void TextInputPopup::AddToParent( Actor parent )
145 Actor existingParent = mRoot.GetParent();
147 if ( !existingParent )
153 void TextInputPopup::RemoveFromParent()
155 Actor parent = mRoot.GetParent();
159 parent.Remove( mRoot );
163 void TextInputPopup::CreateLayer( const Vector2& size )
165 mLayer = Layer::New();
166 mLayer.SetParentOrigin(ParentOrigin::CENTER);
167 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
168 mLayer.SetSize( size ); // matches stencil size
169 mLayer.SetName("popup-mLayer");
172 void TextInputPopup::CreateStencil( const Vector2& size )
174 mStencil = CreateSolidColorActor( Color::BLUE );
175 mStencil.SetParentOrigin( ParentOrigin::CENTER );
176 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
177 mStencil.SetDrawMode( DrawMode::STENCIL );
178 mStencil.SetVisible( true );
179 mStencil.SetName( "popup-stencil" );
180 mStencil.SetSize( size );
183 void TextInputPopup::OnScrollStarted( const Vector3& position )
185 mButtons.SetSensitive( false );
188 void TextInputPopup::OnScrollCompleted( const Vector3& position )
190 mButtons.SetSensitive( true );
193 void TextInputPopup::CreateScrollView()
195 mScrollView = Toolkit::ScrollView::New();
196 mScrollView.SetName("popup-scroll-view");
197 mScrollView.SetAnchorPoint( AnchorPoint::CENTER );
198 mScrollView.SetParentOrigin( ParentOrigin::CENTER );
199 mScrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) );
200 mScrollView.SetAxisAutoLock( true );
201 mScrollView.ScrollStartedSignal().Connect( this, &TextInputPopup::OnScrollStarted );
202 mScrollView.ScrollCompletedSignal().Connect( this, &TextInputPopup::OnScrollCompleted );
205 void TextInputPopup::UpdateScrollViewRulerAndSize( const Vector2& visibleSize )
207 mScrollView.SetSize( visibleSize.x, visibleSize.y );
209 RulerPtr rulerX = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
210 RulerPtr rulerY = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
212 rulerX->SetDomain( RulerDomain( 0, mContentSize.width, true ) );
213 mScrollView.SetRulerX(rulerX);
214 mScrollView.SetRulerY(rulerY);
218 void TextInputPopup::Clear()
222 UnparentAndReset( mTail );
223 UnparentAndReset( mStencil );
224 UnparentAndReset( mBackground );
225 UnparentAndReset( mButtons );
226 UnparentAndReset( mScrollView );
227 mDividerContainer.clear();
229 mState = StateHidden;
233 ImageActor TextInputPopup::CreateOptionIcon( Image iconImage, const Vector4& color )
235 ImageActor icon = ImageActor::New( iconImage );
236 icon.SetSize( OPTION_ICON_SIZE );
237 icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
238 icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
239 icon.SetColor( color );
240 icon.SetY( OPTION_PADDING.z - POPUP_BORDER.y );
244 Toolkit::TextView TextInputPopup::CreateOptionCaption( const std::string& caption, const Vector4& color )
247 style.SetTextColor( color );
249 PointSize pointSize( Font::PixelsToPoints( OPTION_TEXT_MIN_SIZE.y ) );
250 style.SetFontPointSize( pointSize );
252 MarkupProcessor::StyledTextArray styledCaption;
253 styledCaption.push_back( MarkupProcessor::StyledText( Text( caption ), style ) );
255 Toolkit::TextView textView = Toolkit::TextView::New( styledCaption );
256 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
257 textView.SetWidthExceedPolicy( Toolkit::TextView::EllipsizeEnd );
258 textView.SetHeightExceedPolicy( Toolkit::TextView::EllipsizeEnd );
259 textView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
260 textView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
261 textView.SetY( -OPTION_PADDING.w + POPUP_BORDER.w );
263 MarkupProcessor::StyledTextArray styledCaptionEllipsize;
264 MarkupProcessor::SetTextStyle( Text("..."), styledCaptionEllipsize, style );
265 textView.SetEllipsizeText( styledCaptionEllipsize );
267 const float textWidth = textView.GetWidthForHeight( OPTION_TEXT_MIN_SIZE.y );
268 textView.SetSize( textWidth, OPTION_TEXT_MIN_SIZE.y );
273 void TextInputPopup::CreateBackground()
275 // Create background-panel if not already created (required if we have at least one option)
278 Image bgImg = ResourceImage::New( POPUP_BACKGROUND );
279 mBackground = ImageActor::New( bgImg );
280 mBackground.SetAnchorPoint( AnchorPoint::CENTER );
281 mBackground.SetParentOrigin( ParentOrigin::CENTER );
282 mBackground.SetName( "text-input-popup-background" );
283 mBackground.SetColor( mBackgroundColor );
285 Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT );
286 mBackgroundEffect = ImageActor::New( bgEffectImg );
287 mBackgroundEffect.SetAnchorPoint( AnchorPoint::CENTER );
288 mBackgroundEffect.SetParentOrigin( ParentOrigin::CENTER );
289 mBackgroundEffect.SetName( "text-input-popup-background-effect" );
290 mBackgroundEffect.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
291 mBackgroundEffect.SetZ( 1.0f );
292 mBackground.Add( mBackgroundEffect );
294 Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE );
295 mBackgroundLine = ImageActor::New( bgLine );
296 mBackgroundLine.SetAnchorPoint( AnchorPoint::CENTER);
297 mBackgroundLine.SetParentOrigin( ParentOrigin::CENTER );
298 mBackgroundLine.SetName( "text-input-popup-background-effect" );
299 mBackgroundLine.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
300 mBackgroundLine.SetColor( mLineColor );
301 mBackgroundLine.SetZ( 0.1f );
302 mBackgroundEffect.Add( mBackgroundLine );
308 void TextInputPopup::CreateTail()
312 Image tail = ResourceImage::New( POPUP_TAIL_BOTTOM );
313 mTail = ImageActor::New( tail );
314 mTail.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
315 mTail.SetAnchorPoint( AnchorPoint::TOP_CENTER );
316 mTail.SetName( "text-input-popup-tail" );
317 mTail.SetPosition( 0.0f, POPUP_TAIL_Y_OFFSET - POPUP_BORDER.w, 1.2f );
318 mTail.SetColor( mBackgroundColor );
320 Image tailEffect = ResourceImage::New( POPUP_TAIL_BOTTOM_EFFECT );
321 mTailEffect = ImageActor::New( tailEffect );
322 mTailEffect.SetParentOrigin( ParentOrigin::CENTER );
323 mTailEffect.SetAnchorPoint( AnchorPoint::CENTER );
324 mTailEffect.SetName( "text-input-popup-tail-effect" );
325 mTailEffect.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
326 mTailEffect.SetZ( 0.1f );
327 mTail.Add( mTailEffect );
329 Image tailLine = ResourceImage::New( POPUP_TAIL_BOTTOM_LINE );
330 mTailLine = ImageActor::New( tailLine );
331 mTailLine.SetParentOrigin( ParentOrigin::CENTER );
332 mTailLine.SetAnchorPoint( AnchorPoint::CENTER );
333 mTailLine.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
334 mTailLine.SetName( "text-input-popup-tail-line" );
335 mTailLine.SetColor( mLineColor );
336 mTailLine.SetZ( 0.1f );
337 mTailEffect.Add( mTailLine );
341 ImageActor TextInputPopup::CreateDivider()
343 ImageActor divider = Toolkit::CreateSolidColorActor( mLineColor );
344 divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
345 divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
346 divider.SetSize( POPUP_DIVIDER_SIZE.width , mContentSize.height );
347 divider.SetPosition( mContentSize.width - POPUP_DIVIDER_SIZE.width, 0.0f );
349 // Keep track of all the dividers. As their height's need to be updated to the max of all
350 // buttons currently added.
351 mDividerContainer.push_back( divider );
356 ImageActor TextInputPopup::CreatePressedBackground( const Vector2& requiredSize )
358 ImageActor pressedBg = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
359 pressedBg.SetDrawMode( DrawMode::OVERLAY );
360 pressedBg.SetParentOrigin( ParentOrigin::CENTER );
361 pressedBg.SetAnchorPoint( AnchorPoint::CENTER );
362 pressedBg.SetSize( requiredSize );
366 TextInputPopup::ButtonRequirement TextInputPopup::CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
367 const std::string& name, const std::string& caption, Image iconImage, bool enabled )
369 TextInputPopup::ButtonRequirement currentButton;
370 currentButton.buttonId = buttonId;
371 currentButton.orderOfPriority = orderOfPriority;
372 currentButton.name = name;
373 currentButton.caption = caption;
374 currentButton.iconImage = iconImage;
375 currentButton.enabled = enabled;
377 return currentButton;
380 void TextInputPopup::CreateOrderedListOfOptions()
382 mOrderListOfButtons.clear();
384 for ( std::size_t index= 0; index < ButtonsEnumEnd; index++ )
386 TextInputPopup::ButtonRequirement currentButton;
388 // Create button for each possible option using Option priority
393 Image cutIcon = ResourceImage::New( OPTION_ICON_CUT );
394 currentButton = CreateRequiredButton( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, false );
399 Image copyIcon = ResourceImage::New( OPTION_ICON_COPY );
400 currentButton = CreateRequiredButton( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, false );
405 Image pasteIcon = ResourceImage::New( OPTION_ICON_PASTE );
406 currentButton = CreateRequiredButton( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, false );
411 Image selectIcon = ResourceImage::New( OPTION_ICON_SELECT );
412 currentButton = CreateRequiredButton( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, false );
415 case ButtonsSelectAll:
417 Image selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL );
418 currentButton = CreateRequiredButton( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, false );
421 case ButtonsClipboard:
423 Image clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD );
424 currentButton = CreateRequiredButton( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, false );
431 // Insert button in list of buttons in order of priority setting.
432 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
434 const ButtonRequirement& button( *it );
435 if ( currentButton.orderOfPriority < button.orderOfPriority )
437 if ( currentButton.orderOfPriority != 0 ) // If order priority 0 then do not add button as not required.
439 mOrderListOfButtons.insert( it, currentButton );
447 mOrderListOfButtons.push_back( currentButton );
452 Vector2 TextInputPopup::GetConstrainedTextSize( const Vector2& textSize )
454 return Vector2( std::min( textSize.width, OPTION_MAX_SIZE.width - OPTION_PADDING.x - OPTION_PADDING.y ), textSize.height );
457 void TextInputPopup::AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption)
459 // 1. Create container for text and icon when not pressed.
460 Actor optionContainer = Actor::New();
461 optionContainer.SetParentOrigin( ParentOrigin::TOP_LEFT );
462 optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
465 Toolkit::TextView captionTextView = CreateOptionCaption( caption, mTextColor );
466 optionContainer.Add( captionTextView );
469 ImageActor icon = CreateOptionIcon( iconImage, mIconColor );
470 optionContainer.Add( icon );
472 // 4. Calculate the size of option.
473 const Vector2 textSize = Vector2( captionTextView.GetNaturalSize() );
474 captionTextView.SetSize( GetConstrainedTextSize( textSize ) );
477 const Vector2 optionSize( std::max( textSize.x, OPTION_ICON_SIZE.x ) + OPTION_PADDING.x + OPTION_PADDING.z,
478 OPTION_PADDING.z + OPTION_ICON_SIZE.y + OPTION_GAP_ICON_TEXT + textSize.y + OPTION_MAX_SIZE.y );
481 Vector2 constrainedOptionSize = Min( Max( optionSize, OPTION_MIN_SIZE ), OPTION_MAX_SIZE );
483 constrainedOptionSize.height = constrainedOptionSize.height - POPUP_BORDER.y - POPUP_BORDER.z;
485 // 5. Create a option.
486 Toolkit::PushButton option = Toolkit::PushButton::New();
487 option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
488 option.SetParentOrigin( ParentOrigin::TOP_LEFT );
489 option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
490 option.SetSize( constrainedOptionSize );
491 option.SetX( mContentSize.x );
492 option.SetName( name );
493 option.SetAnimationTime( 0.0f );
494 option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
495 mButtons.Add( option );
497 // 6. Set the normal option image.
498 option.SetButtonImage( optionContainer );
500 // 7. Update the content size.
501 mContentSize.x += constrainedOptionSize.x;
502 mContentSize.y = std::max ( constrainedOptionSize.y, mContentSize.y );
504 // 8. Create the pressed container.
505 Actor optionPressedContainer = Actor::New();
507 // 9. Add option pressed background.
508 Vector2 optionPressedBackgroundSize( constrainedOptionSize.x - POPUP_BORDER.x, mContentSize.y - POPUP_BORDER.y - POPUP_BORDER.w );
509 ImageActor optionPressedBackground = CreatePressedBackground( optionPressedBackgroundSize );
510 optionPressedContainer.Add( optionPressedBackground );
512 // 10. Add pressed text
513 Toolkit::TextView pressedCaptionTextView = CreateOptionCaption( caption, mTextPressedColor );
514 pressedCaptionTextView.SetSize( GetConstrainedTextSize( Vector2( pressedCaptionTextView.GetNaturalSize() ) ) );
515 optionPressedBackground.Add( pressedCaptionTextView );
517 // 11. Add pressed icon
518 ImageActor pressedIcon = CreateOptionIcon( iconImage, mIconPressedColor );
519 optionPressedBackground.Add( pressedIcon );
521 // 12. Set the pressed option image
522 option.SetSelectedImage( optionPressedContainer );
524 // 13. Add the divider
527 ImageActor divider = CreateDivider();
528 mButtons.Add( divider );
532 void TextInputPopup::Hide(bool animate)
544 mAnimation = Animation::New( HIDE_POPUP_ANIMATION_DURATION );
545 mAnimation.AnimateTo( Property(mRoot, Actor::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut );
546 mAnimation.AnimateTo( Property(mRoot, Actor::COLOR_ALPHA), 0.0f, AlphaFunctions::EaseOut );
549 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnHideFinished );
550 mState = StateHiding;
554 mRoot.SetProperty(Actor::SCALE, Vector3::ZERO);
555 mRoot.SetProperty(Actor::COLOR_ALPHA, 0.0f);
556 mState = StateHidden;
561 void TextInputPopup::Show( Actor target, bool animate )
565 mRoot.SetSensitive( true );
575 AddToParent( target );
580 mAnimation = Animation::New( SHOW_POPUP_ANIMATION_DURATION );
581 mAnimation.AnimateTo( Property(mRoot, Actor::SCALE), Vector3::ONE, AlphaFunctions::EaseOut );
582 mAnimation.AnimateTo( Property(mRoot, Actor::COLOR_ALPHA), 1.0f, AlphaFunctions::EaseOut );
585 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnShowFinished );
586 mState = StateShowing;
590 mRoot.SetProperty(Actor::SCALE, Vector3::ONE);
591 mRoot.SetProperty(Actor::COLOR_ALPHA, 1.0f);
597 TextInputPopup::State TextInputPopup::GetState(void) const
602 Actor TextInputPopup::GetRootActor() const
609 void TextInputPopup::SetCutPastePopupColor( const Vector4& color )
611 mBackgroundColor = color;
614 const Vector4& TextInputPopup::GetCutPastePopupColor() const
616 return mBackgroundColor;
619 void TextInputPopup::SetCutPastePopupPressedColor( const Vector4& color )
621 mBackgroundPressedColor = color;
624 const Vector4& TextInputPopup::GetCutPastePopupPressedColor() const
626 return mBackgroundPressedColor;
629 void TextInputPopup::SetCutPastePopupBorderColor( const Vector4& color )
634 const Vector4& TextInputPopup::GetCutPastePopupBorderColor() const
639 void TextInputPopup::SetCutPastePopupIconColor( const Vector4& color )
644 const Vector4& TextInputPopup::GetCutPastePopupIconColor() const
649 void TextInputPopup::SetCutPastePopupIconPressedColor( const Vector4& color )
651 mIconPressedColor = color;
654 const Vector4& TextInputPopup::GetCutPastePopupIconPressedColor()
656 return mIconPressedColor;
659 void TextInputPopup::SetCutPastePopupTextColor( const Vector4& color )
664 const Vector4& TextInputPopup::GetCutPastePopupTextColor()
669 void TextInputPopup::SetCutPastePopupTextPressedColor( const Vector4& color )
671 mTextPressedColor = color;
674 const Vector4& TextInputPopup::GetCutPastePopupTextPressedColor()
676 return mTextPressedColor;
679 void TextInputPopup::TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable )
681 bool match ( false );
682 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
684 ButtonRequirement& button( *it );
685 if ( requiredButton == button.buttonId )
687 button.enabled = enable;
693 void TextInputPopup::SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority )
699 mCutOptionPriority = priority;
704 mCopyOptionPriority = priority;
709 mPasteOptionPriority = priority;
714 mSelectOptionPriority = priority;
717 case ButtonsSelectAll:
719 mSelectAllOptionPriority = priority;
722 case ButtonsClipboard:
724 mClipboardOptionPriority = priority;
729 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
733 CreateOrderedListOfOptions(); // Update list of options as priority changed.
736 unsigned int TextInputPopup::GetButtonPriorityPosition( TextInputPopup::Buttons button ) const
738 unsigned int priority = 0;
744 priority = mCutOptionPriority;
749 priority = mCopyOptionPriority;
754 priority = mPasteOptionPriority;
759 priority = mSelectOptionPriority;
762 case ButtonsSelectAll:
764 priority = mSelectAllOptionPriority;
767 case ButtonsClipboard:
769 priority = mClipboardOptionPriority;
774 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
782 void TextInputPopup::AddPopupOptions()
784 mContentSize = Vector2( POPUP_MIN_SIZE.width, ( POPUP_BORDER.y + POPUP_BORDER.z ) );
786 // 1. Create the background.
789 // 2. Create the tail.
792 // 3. Create the scroll view and Actor to hold buttons.
795 // Clear previous buttons
798 UnparentAndReset( mButtons );
801 mButtons = Actor::New();
802 mButtons.SetParentOrigin( ParentOrigin::CENTER );
803 mButtons.SetAnchorPoint( AnchorPoint::CENTER );
805 // 4. Create the options and add into the scroll view.
806 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
808 const ButtonRequirement& button( *it );
809 if ( button.enabled )
811 AddOption( button.name, button.caption, button.iconImage, it != ( endIt - 1 ) ? false : true );
815 // 5. Calculate size of content and of popup including borders
816 const Vector2 popupSize = Vector2( std::min ( ( POPUP_BORDER.x + mContentSize.width + POPUP_BORDER.z ), POPUP_MAX_SIZE.width ) , POPUP_BORDER.y + mContentSize.height + POPUP_BORDER.w );
818 mVisiblePopUpSize = Vector3( popupSize.width - POPUP_BORDER.x - POPUP_BORDER.z , mContentSize.height, 1.0f);
820 mBackground.SetSize( popupSize.x + 28 - POPUP_BORDER.x - POPUP_BORDER.z, popupSize.y + 28 - POPUP_BORDER.y - POPUP_BORDER.w );
821 mButtons.SetSize( mVisiblePopUpSize.GetVectorXY() );
823 // 6. Set the scroll view ruler.
824 UpdateScrollViewRulerAndSize( mVisiblePopUpSize.GetVectorXY() );
827 const Vector2 stencilSize = Vector2( mVisiblePopUpSize.GetVectorXY() );
829 CreateLayer( stencilSize );
830 CreateStencil( stencilSize );
832 mScrollView.Add ( mButtons );
833 mLayer.Add( mScrollView);
834 mLayer.Add( mStencil);
836 mRoot.Add( mBackground );
839 // 8. Set the root size.
840 mRoot.SetSize( popupSize ); // Make Root Actor reflect the size of its content
843 const Vector3& TextInputPopup::GetVisibileSize() const
845 return mVisiblePopUpSize;
848 void TextInputPopup::SetTailPosition( const Vector3& position, bool yAxisFlip )
850 mPopupTailXPosition = std::max( position.x, POPUP_TAIL_SIZE.width*0.5f - mVisiblePopUpSize.width*0.5f + POPUP_BORDER.x );
852 std::min( mPopupTailXPosition, mVisiblePopUpSize.width*0.5f - POPUP_BORDER.x - POPUP_TAIL_SIZE.width*0.5f );
854 mTail.SetX( mPopupTailXPosition );
858 Image tail = ResourceImage::New( POPUP_TAIL_TOP );
859 Image tailEffect = ResourceImage::New( POPUP_TAIL_TOP_EFFECT );
860 Image tailLine = ResourceImage::New( POPUP_TAIL_TOP_LINE );
862 mTail.SetImage( tail );
863 mTailEffect.SetImage( tailEffect );
864 mTailLine.SetImage( tailLine );
866 mTail.SetParentOrigin( ParentOrigin::TOP_CENTER );
867 mTail.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
868 mTail.SetY( POPUP_BORDER.y - POPUP_TAIL_Y_OFFSET );
872 bool TextInputPopup::OnButtonPressed( Toolkit::Button button )
874 mPressedSignal.Emit( button );
878 void TextInputPopup::OnHideFinished(Animation& source)
880 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnHideFinished );
882 mState = StateHidden;
883 mHideFinishedSignal.Emit( *this );
886 void TextInputPopup::OnShowFinished(Animation& source)
888 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnShowFinished );
890 mShowFinishedSignal.Emit( *this );
893 TextInputPopup::PressedSignalType& TextInputPopup::PressedSignal()
895 return mPressedSignal;
898 TextInputPopup::HideFinishedSignalType& TextInputPopup::HideFinishedSignal()
900 return mHideFinishedSignal;
903 TextInputPopup::ShowFinishedSignalType& TextInputPopup::ShowFinishedSignal()
905 return mShowFinishedSignal;
908 } // namespace Internal
910 } // namespace Toolkit