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/public-api/images/resource-image.h>
22 #include <dali/integration-api/debug.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 char* const POPUP_BACKGROUND = DALI_IMAGE_DIR "popup_bubble_bg.#.png";
44 const char* const POPUP_BACKGROUND_EFFECT = DALI_IMAGE_DIR "popup_bubble_bg_ef.#.png";
45 const char* const POPUP_BACKGROUND_LINE = DALI_IMAGE_DIR "popup_bubble_bg_line.#.png";
47 const char* const POPUP_TAIL_BOTTOM = DALI_IMAGE_DIR "popup_bubble_tail_bottom.png";
48 const char* const POPUP_TAIL_BOTTOM_EFFECT = DALI_IMAGE_DIR "popup_bubble_tail_bottom_ef.png";
49 const char* const POPUP_TAIL_BOTTOM_LINE = DALI_IMAGE_DIR "popup_bubble_tail_bottom_line.png";
50 const char* const POPUP_TAIL_TOP = DALI_IMAGE_DIR "popup_bubble_tail_top.png";
51 const char* const POPUP_TAIL_TOP_EFFECT = DALI_IMAGE_DIR "popup_bubble_tail_top_ef.png";
52 const char* const POPUP_TAIL_TOP_LINE = DALI_IMAGE_DIR "popup_bubble_tail_top_line.png";
54 const char* const OPTION_ICON_CLIPBOARD = DALI_IMAGE_DIR "copy_paste_icon_clipboard.png";
55 const char* const OPTION_ICON_COPY = DALI_IMAGE_DIR "copy_paste_icon_copy.png";
56 const char* const OPTION_ICON_CUT = DALI_IMAGE_DIR "copy_paste_icon_cut.png";
57 const char* const OPTION_ICON_PASTE = DALI_IMAGE_DIR "copy_paste_icon_paste.png";
58 const char* const OPTION_ICON_SELECT = DALI_IMAGE_DIR "copy_paste_icon_select.png";
59 const char* const 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
109 const char* const SIGNAL_PRESSED = "pressed";
110 const char* const SIGNAL_HIDE_FINISHED = "hide-finished";
111 const char* const SIGNAL_SHOW_FINISHED = "show-finished";
115 const char* const TextInputPopup::OPTION_SELECT_WORD = "option-select_word"; // "Select Word" popup option.
116 const char* const TextInputPopup::OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
117 const char* const TextInputPopup::OPTION_CUT("option-cut"); // "Cut" popup option.
118 const char* const TextInputPopup::OPTION_COPY("option-copy"); // "Copy" popup option.
119 const char* const TextInputPopup::OPTION_PASTE("option-paste"); // "Paste" popup option.
120 const char* const TextInputPopup::OPTION_CLIPBOARD("option-clipboard"); // "Clipboard" popup option.
122 TextInputPopup::TextInputPopup()
123 : mState(StateHidden),
124 mRoot( Layer::New() ),
127 mPopupTailXPosition( 0.0f ),
129 mBackgroundColor( DEFAULT_POPUP_BACKGROUND ),
130 mBackgroundPressedColor( DEFAULT_POPUP_BACKGROUND_PRESSED ),
131 mLineColor( DEFAULT_POPUP_LINE_COLOR ),
132 mIconColor( DEFAULT_OPTION_ICON ),
133 mIconPressedColor( DEFAULT_OPTION_ICON_PRESSED ),
134 mTextColor( DEFAULT_OPTION_TEXT ),
135 mTextPressedColor( DEFAULT_OPTION_TEXT_PRESSED ),
136 mSelectOptionPriority(1),
137 mSelectAllOptionPriority(2),
138 mCutOptionPriority(3),
139 mCopyOptionPriority(4),
140 mPasteOptionPriority(5),
141 mClipboardOptionPriority(6),
143 mHideFinishedSignal(),
144 mShowFinishedSignal()
146 mRoot.SetParentOrigin( ParentOrigin::TOP_LEFT );
147 mRoot.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
150 void TextInputPopup::AddToParent( Actor parent )
152 Actor existingParent = mRoot.GetParent();
154 if ( !existingParent )
160 void TextInputPopup::RemoveFromParent()
162 Actor parent = mRoot.GetParent();
166 parent.Remove( mRoot );
170 void TextInputPopup::CreateLayer( const Vector2& size )
172 mLayer = Layer::New();
173 mLayer.SetParentOrigin(ParentOrigin::CENTER);
174 mLayer.SetAnchorPoint(AnchorPoint::CENTER);
175 mLayer.SetSize( size ); // matches stencil size
176 mLayer.SetName("popup-mLayer");
179 void TextInputPopup::CreateStencil( const Vector2& size )
181 mStencil = CreateSolidColorActor( Color::BLUE );
182 mStencil.SetParentOrigin( ParentOrigin::CENTER );
183 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
184 mStencil.SetDrawMode( DrawMode::STENCIL );
185 mStencil.SetVisible( true );
186 mStencil.SetName( "popup-stencil" );
187 mStencil.SetSize( size );
190 void TextInputPopup::OnScrollStarted( const Vector3& position )
192 mButtons.SetSensitive( false );
195 void TextInputPopup::OnScrollCompleted( const Vector3& position )
197 mButtons.SetSensitive( true );
200 void TextInputPopup::CreateScrollView()
202 mScrollView = Toolkit::ScrollView::New();
203 mScrollView.SetName("popup-scroll-view");
204 mScrollView.SetAnchorPoint( AnchorPoint::CENTER );
205 mScrollView.SetParentOrigin( ParentOrigin::CENTER );
206 mScrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) );
207 mScrollView.SetAxisAutoLock( true );
208 mScrollView.ScrollStartedSignal().Connect( this, &TextInputPopup::OnScrollStarted );
209 mScrollView.ScrollCompletedSignal().Connect( this, &TextInputPopup::OnScrollCompleted );
212 void TextInputPopup::UpdateScrollViewRulerAndSize( const Vector2& visibleSize )
214 mScrollView.SetSize( visibleSize.x, visibleSize.y );
216 RulerPtr rulerX = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
217 RulerPtr rulerY = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
219 rulerX->SetDomain( RulerDomain( 0, mContentSize.width, true ) );
220 mScrollView.SetRulerX(rulerX);
221 mScrollView.SetRulerY(rulerY);
225 void TextInputPopup::Clear()
229 UnparentAndReset( mTail );
230 UnparentAndReset( mStencil );
231 UnparentAndReset( mBackground );
232 UnparentAndReset( mButtons );
233 UnparentAndReset( mScrollView );
234 mDividerContainer.clear();
236 mState = StateHidden;
240 ImageActor TextInputPopup::CreateOptionIcon( Image iconImage, const Vector4& color )
242 ImageActor icon = ImageActor::New( iconImage );
243 icon.SetSize( OPTION_ICON_SIZE );
244 icon.SetParentOrigin( ParentOrigin::TOP_CENTER );
245 icon.SetAnchorPoint( AnchorPoint::TOP_CENTER );
246 icon.SetColor( color );
247 icon.SetY( OPTION_PADDING.z - POPUP_BORDER.y );
251 Toolkit::TextView TextInputPopup::CreateOptionCaption( const std::string& caption, const Vector4& color )
254 style.SetTextColor( color );
256 PointSize pointSize( Font::PixelsToPoints( OPTION_TEXT_MIN_SIZE.y ) );
257 style.SetFontPointSize( pointSize );
259 MarkupProcessor::StyledTextArray styledCaption;
260 styledCaption.push_back( MarkupProcessor::StyledText( Text( caption ), style ) );
262 Toolkit::TextView textView = Toolkit::TextView::New( styledCaption );
263 textView.SetWidthExceedPolicy( Toolkit::TextView::EllipsizeEnd );
264 textView.SetHeightExceedPolicy( Toolkit::TextView::EllipsizeEnd );
265 textView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
266 textView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
267 textView.SetY( -OPTION_PADDING.w + POPUP_BORDER.w );
269 MarkupProcessor::StyledTextArray styledCaptionEllipsize;
270 MarkupProcessor::SetTextStyle( Text("..."), styledCaptionEllipsize, style );
271 textView.SetEllipsizeText( styledCaptionEllipsize );
273 const float textWidth = textView.GetWidthForHeight( OPTION_TEXT_MIN_SIZE.y );
274 textView.SetSize( textWidth, OPTION_TEXT_MIN_SIZE.y );
279 void TextInputPopup::CreateBackground()
281 // Create background-panel if not already created (required if we have at least one option)
284 Image bgImg = ResourceImage::New( POPUP_BACKGROUND );
285 mBackground = ImageActor::New( bgImg );
286 mBackground.SetAnchorPoint( AnchorPoint::CENTER );
287 mBackground.SetParentOrigin( ParentOrigin::CENTER );
288 mBackground.SetName( "text-input-popup-background" );
289 mBackground.SetColor( mBackgroundColor );
291 Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT );
292 mBackgroundEffect = ImageActor::New( bgEffectImg );
293 mBackgroundEffect.SetAnchorPoint( AnchorPoint::CENTER );
294 mBackgroundEffect.SetParentOrigin( ParentOrigin::CENTER );
295 mBackgroundEffect.SetName( "text-input-popup-background-effect" );
296 mBackgroundEffect.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
297 mBackgroundEffect.SetZ( 1.0f );
298 mBackground.Add( mBackgroundEffect );
300 Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE );
301 mBackgroundLine = ImageActor::New( bgLine );
302 mBackgroundLine.SetAnchorPoint( AnchorPoint::CENTER);
303 mBackgroundLine.SetParentOrigin( ParentOrigin::CENTER );
304 mBackgroundLine.SetName( "text-input-popup-background-effect" );
305 mBackgroundLine.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
306 mBackgroundLine.SetColor( mLineColor );
307 mBackgroundLine.SetZ( 0.1f );
308 mBackgroundEffect.Add( mBackgroundLine );
314 void TextInputPopup::CreateTail()
318 Image tail = ResourceImage::New( POPUP_TAIL_BOTTOM );
319 mTail = ImageActor::New( tail );
320 mTail.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
321 mTail.SetAnchorPoint( AnchorPoint::TOP_CENTER );
322 mTail.SetName( "text-input-popup-tail" );
323 mTail.SetPosition( 0.0f, POPUP_TAIL_Y_OFFSET - POPUP_BORDER.w, 1.2f );
324 mTail.SetColor( mBackgroundColor );
326 Image tailEffect = ResourceImage::New( POPUP_TAIL_BOTTOM_EFFECT );
327 mTailEffect = ImageActor::New( tailEffect );
328 mTailEffect.SetParentOrigin( ParentOrigin::CENTER );
329 mTailEffect.SetAnchorPoint( AnchorPoint::CENTER );
330 mTailEffect.SetName( "text-input-popup-tail-effect" );
331 mTailEffect.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
332 mTailEffect.SetZ( 0.1f );
333 mTail.Add( mTailEffect );
335 Image tailLine = ResourceImage::New( POPUP_TAIL_BOTTOM_LINE );
336 mTailLine = ImageActor::New( tailLine );
337 mTailLine.SetParentOrigin( ParentOrigin::CENTER );
338 mTailLine.SetAnchorPoint( AnchorPoint::CENTER );
339 mTailLine.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
340 mTailLine.SetName( "text-input-popup-tail-line" );
341 mTailLine.SetColor( mLineColor );
342 mTailLine.SetZ( 0.1f );
343 mTailEffect.Add( mTailLine );
347 ImageActor TextInputPopup::CreateDivider()
349 ImageActor divider = Toolkit::CreateSolidColorActor( mLineColor );
350 divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
351 divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
352 divider.SetSize( POPUP_DIVIDER_SIZE.width , mContentSize.height );
353 divider.SetPosition( mContentSize.width - POPUP_DIVIDER_SIZE.width, 0.0f );
355 // Keep track of all the dividers. As their height's need to be updated to the max of all
356 // buttons currently added.
357 mDividerContainer.push_back( divider );
362 ImageActor TextInputPopup::CreatePressedBackground( const Vector2& requiredSize )
364 ImageActor pressedBg = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
365 pressedBg.SetDrawMode( DrawMode::OVERLAY );
366 pressedBg.SetParentOrigin( ParentOrigin::CENTER );
367 pressedBg.SetAnchorPoint( AnchorPoint::CENTER );
368 pressedBg.SetSize( requiredSize );
372 TextInputPopup::ButtonRequirement TextInputPopup::CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
373 const std::string& name, const std::string& caption, Image iconImage, bool enabled )
375 TextInputPopup::ButtonRequirement currentButton;
376 currentButton.buttonId = buttonId;
377 currentButton.orderOfPriority = orderOfPriority;
378 currentButton.name = name;
379 currentButton.caption = caption;
380 currentButton.iconImage = iconImage;
381 currentButton.enabled = enabled;
383 return currentButton;
386 void TextInputPopup::CreateOrderedListOfOptions()
388 mOrderListOfButtons.clear();
390 for ( std::size_t index= 0; index < ButtonsEnumEnd; index++ )
392 TextInputPopup::ButtonRequirement currentButton;
394 // Create button for each possible option using Option priority
399 Image cutIcon = ResourceImage::New( OPTION_ICON_CUT );
400 currentButton = CreateRequiredButton( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, false );
405 Image copyIcon = ResourceImage::New( OPTION_ICON_COPY );
406 currentButton = CreateRequiredButton( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, false );
411 Image pasteIcon = ResourceImage::New( OPTION_ICON_PASTE );
412 currentButton = CreateRequiredButton( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, false );
417 Image selectIcon = ResourceImage::New( OPTION_ICON_SELECT );
418 currentButton = CreateRequiredButton( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, false );
421 case ButtonsSelectAll:
423 Image selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL );
424 currentButton = CreateRequiredButton( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, false );
427 case ButtonsClipboard:
429 Image clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD );
430 currentButton = CreateRequiredButton( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, false );
437 // Insert button in list of buttons in order of priority setting.
438 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
440 const ButtonRequirement& button( *it );
441 if ( currentButton.orderOfPriority < button.orderOfPriority )
443 if ( currentButton.orderOfPriority != 0 ) // If order priority 0 then do not add button as not required.
445 mOrderListOfButtons.insert( it, currentButton );
453 mOrderListOfButtons.push_back( currentButton );
458 Vector2 TextInputPopup::GetConstrainedTextSize( const Vector2& textSize )
460 return Vector2( std::min( textSize.width, OPTION_MAX_SIZE.width - OPTION_PADDING.x - OPTION_PADDING.y ), textSize.height );
463 void TextInputPopup::AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption)
465 // 1. Create container for text and icon when not pressed.
466 Actor optionContainer = Actor::New();
467 optionContainer.SetParentOrigin( ParentOrigin::TOP_LEFT );
468 optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
471 Toolkit::TextView captionTextView = CreateOptionCaption( caption, mTextColor );
472 optionContainer.Add( captionTextView );
475 ImageActor icon = CreateOptionIcon( iconImage, mIconColor );
476 optionContainer.Add( icon );
478 // 4. Calculate the size of option.
479 const Vector2 textSize = Vector2( captionTextView.GetNaturalSize() );
480 captionTextView.SetSize( GetConstrainedTextSize( textSize ) );
483 const Vector2 optionSize( std::max( textSize.x, OPTION_ICON_SIZE.x ) + OPTION_PADDING.x + OPTION_PADDING.z,
484 OPTION_PADDING.z + OPTION_ICON_SIZE.y + OPTION_GAP_ICON_TEXT + textSize.y + OPTION_MAX_SIZE.y );
487 Vector2 constrainedOptionSize = Min( Max( optionSize, OPTION_MIN_SIZE ), OPTION_MAX_SIZE );
489 constrainedOptionSize.height = constrainedOptionSize.height - POPUP_BORDER.y - POPUP_BORDER.z;
491 // 5. Create a option.
492 Toolkit::PushButton option = Toolkit::PushButton::New();
493 option.SetParentOrigin( ParentOrigin::TOP_LEFT );
494 option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
495 option.SetSize( constrainedOptionSize );
496 option.SetX( mContentSize.x );
497 option.SetName( name );
498 option.SetAnimationTime( 0.0f );
499 option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
500 mButtons.Add( option );
502 // 6. Set the normal option image.
503 option.SetButtonImage( optionContainer );
505 // 7. Update the content size.
506 mContentSize.x += constrainedOptionSize.x;
507 mContentSize.y = std::max ( constrainedOptionSize.y, mContentSize.y );
509 // 8. Create the pressed container.
510 Actor optionPressedContainer = Actor::New();
512 // 9. Add option pressed background.
513 Vector2 optionPressedBackgroundSize( constrainedOptionSize.x - POPUP_BORDER.x, mContentSize.y - POPUP_BORDER.y - POPUP_BORDER.w );
514 ImageActor optionPressedBackground = CreatePressedBackground( optionPressedBackgroundSize );
515 optionPressedContainer.Add( optionPressedBackground );
517 // 10. Add pressed text
518 Toolkit::TextView pressedCaptionTextView = CreateOptionCaption( caption, mTextPressedColor );
519 pressedCaptionTextView.SetSize( GetConstrainedTextSize( Vector2( pressedCaptionTextView.GetNaturalSize() ) ) );
520 optionPressedBackground.Add( pressedCaptionTextView );
522 // 11. Add pressed icon
523 ImageActor pressedIcon = CreateOptionIcon( iconImage, mIconPressedColor );
524 optionPressedBackground.Add( pressedIcon );
526 // 12. Set the pressed option image
527 option.SetSelectedImage( optionPressedContainer );
529 // 13. Add the divider
532 ImageActor divider = CreateDivider();
533 mButtons.Add( divider );
537 void TextInputPopup::Hide(bool animate)
549 mAnimation = Animation::New( HIDE_POPUP_ANIMATION_DURATION );
550 mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut );
551 mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunctions::EaseOut );
554 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnHideFinished );
555 mState = StateHiding;
559 mRoot.SetProperty(Actor::Property::SCALE, Vector3::ZERO);
560 mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f);
561 mState = StateHidden;
566 void TextInputPopup::Show( Actor target, bool animate )
570 mRoot.SetSensitive( true );
580 AddToParent( target );
585 mAnimation = Animation::New( SHOW_POPUP_ANIMATION_DURATION );
586 mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ONE, AlphaFunctions::EaseOut );
587 mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunctions::EaseOut );
590 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnShowFinished );
591 mState = StateShowing;
595 mRoot.SetProperty(Actor::Property::SCALE, Vector3::ONE);
596 mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
602 TextInputPopup::State TextInputPopup::GetState(void) const
607 Actor TextInputPopup::GetRootActor() const
614 void TextInputPopup::SetCutPastePopupColor( const Vector4& color )
616 mBackgroundColor = color;
619 const Vector4& TextInputPopup::GetCutPastePopupColor() const
621 return mBackgroundColor;
624 void TextInputPopup::SetCutPastePopupPressedColor( const Vector4& color )
626 mBackgroundPressedColor = color;
629 const Vector4& TextInputPopup::GetCutPastePopupPressedColor() const
631 return mBackgroundPressedColor;
634 void TextInputPopup::SetCutPastePopupBorderColor( const Vector4& color )
639 const Vector4& TextInputPopup::GetCutPastePopupBorderColor() const
644 void TextInputPopup::SetCutPastePopupIconColor( const Vector4& color )
649 const Vector4& TextInputPopup::GetCutPastePopupIconColor() const
654 void TextInputPopup::SetCutPastePopupIconPressedColor( const Vector4& color )
656 mIconPressedColor = color;
659 const Vector4& TextInputPopup::GetCutPastePopupIconPressedColor()
661 return mIconPressedColor;
664 void TextInputPopup::SetCutPastePopupTextColor( const Vector4& color )
669 const Vector4& TextInputPopup::GetCutPastePopupTextColor()
674 void TextInputPopup::SetCutPastePopupTextPressedColor( const Vector4& color )
676 mTextPressedColor = color;
679 const Vector4& TextInputPopup::GetCutPastePopupTextPressedColor()
681 return mTextPressedColor;
684 void TextInputPopup::TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable )
686 bool match ( false );
687 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
689 ButtonRequirement& button( *it );
690 if ( requiredButton == button.buttonId )
692 button.enabled = enable;
698 void TextInputPopup::SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority )
704 mCutOptionPriority = priority;
709 mCopyOptionPriority = priority;
714 mPasteOptionPriority = priority;
719 mSelectOptionPriority = priority;
722 case ButtonsSelectAll:
724 mSelectAllOptionPriority = priority;
727 case ButtonsClipboard:
729 mClipboardOptionPriority = priority;
734 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
738 CreateOrderedListOfOptions(); // Update list of options as priority changed.
741 unsigned int TextInputPopup::GetButtonPriorityPosition( TextInputPopup::Buttons button ) const
743 unsigned int priority = 0;
749 priority = mCutOptionPriority;
754 priority = mCopyOptionPriority;
759 priority = mPasteOptionPriority;
764 priority = mSelectOptionPriority;
767 case ButtonsSelectAll:
769 priority = mSelectAllOptionPriority;
772 case ButtonsClipboard:
774 priority = mClipboardOptionPriority;
779 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
787 void TextInputPopup::AddPopupOptions()
789 mContentSize = Vector2( POPUP_MIN_SIZE.width, ( POPUP_BORDER.y + POPUP_BORDER.z ) );
791 // 1. Create the background.
794 // 2. Create the tail.
797 // 3. Create the scroll view and Actor to hold buttons.
800 // Clear previous buttons
803 UnparentAndReset( mButtons );
806 mButtons = Actor::New();
807 mButtons.SetParentOrigin( ParentOrigin::CENTER );
808 mButtons.SetAnchorPoint( AnchorPoint::CENTER );
810 // 4. Create the options and add into the scroll view.
811 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
813 const ButtonRequirement& button( *it );
814 if ( button.enabled )
816 AddOption( button.name, button.caption, button.iconImage, it != ( endIt - 1 ) ? false : true );
820 // 5. Calculate size of content and of popup including borders
821 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 );
823 mVisiblePopUpSize = Vector3( popupSize.width - POPUP_BORDER.x - POPUP_BORDER.z , mContentSize.height, 1.0f);
825 mBackground.SetSize( popupSize.x + 28 - POPUP_BORDER.x - POPUP_BORDER.z, popupSize.y + 28 - POPUP_BORDER.y - POPUP_BORDER.w );
826 mButtons.SetSize( mVisiblePopUpSize.GetVectorXY() );
828 // 6. Set the scroll view ruler.
829 UpdateScrollViewRulerAndSize( mVisiblePopUpSize.GetVectorXY() );
832 const Vector2 stencilSize = Vector2( mVisiblePopUpSize.GetVectorXY() );
834 CreateLayer( stencilSize );
835 CreateStencil( stencilSize );
837 mScrollView.Add ( mButtons );
838 mLayer.Add( mScrollView);
839 mLayer.Add( mStencil);
841 mRoot.Add( mBackground );
844 // 8. Set the root size.
845 mRoot.SetSize( popupSize ); // Make Root Actor reflect the size of its content
848 const Vector3& TextInputPopup::GetVisibileSize() const
850 return mVisiblePopUpSize;
853 void TextInputPopup::SetTailPosition( const Vector3& position, bool yAxisFlip )
855 mPopupTailXPosition = std::max( position.x, POPUP_TAIL_SIZE.width*0.5f - mVisiblePopUpSize.width*0.5f + POPUP_BORDER.x );
857 std::min( mPopupTailXPosition, mVisiblePopUpSize.width*0.5f - POPUP_BORDER.x - POPUP_TAIL_SIZE.width*0.5f );
859 mTail.SetX( mPopupTailXPosition );
863 Image tail = ResourceImage::New( POPUP_TAIL_TOP );
864 Image tailEffect = ResourceImage::New( POPUP_TAIL_TOP_EFFECT );
865 Image tailLine = ResourceImage::New( POPUP_TAIL_TOP_LINE );
867 mTail.SetImage( tail );
868 mTailEffect.SetImage( tailEffect );
869 mTailLine.SetImage( tailLine );
871 mTail.SetParentOrigin( ParentOrigin::TOP_CENTER );
872 mTail.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
873 mTail.SetY( POPUP_BORDER.y - POPUP_TAIL_Y_OFFSET );
877 bool TextInputPopup::OnButtonPressed( Toolkit::Button button )
879 mPressedSignal.Emit( button );
883 void TextInputPopup::OnHideFinished(Animation& source)
885 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnHideFinished );
887 mState = StateHidden;
888 mHideFinishedSignal.Emit( *this );
891 void TextInputPopup::OnShowFinished(Animation& source)
893 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnShowFinished );
895 mShowFinishedSignal.Emit( *this );
898 TextInputPopup::PressedSignalType& TextInputPopup::PressedSignal()
900 return mPressedSignal;
903 TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::HideFinishedSignal()
905 return mHideFinishedSignal;
908 TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::ShowFinishedSignal()
910 return mShowFinishedSignal;
913 } // namespace Internal
915 } // namespace Toolkit