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.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
264 textView.SetWidthExceedPolicy( Toolkit::TextView::EllipsizeEnd );
265 textView.SetHeightExceedPolicy( Toolkit::TextView::EllipsizeEnd );
266 textView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
267 textView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
268 textView.SetY( -OPTION_PADDING.w + POPUP_BORDER.w );
270 MarkupProcessor::StyledTextArray styledCaptionEllipsize;
271 MarkupProcessor::SetTextStyle( Text("..."), styledCaptionEllipsize, style );
272 textView.SetEllipsizeText( styledCaptionEllipsize );
274 const float textWidth = textView.GetWidthForHeight( OPTION_TEXT_MIN_SIZE.y );
275 textView.SetSize( textWidth, OPTION_TEXT_MIN_SIZE.y );
280 void TextInputPopup::CreateBackground()
282 // Create background-panel if not already created (required if we have at least one option)
285 Image bgImg = ResourceImage::New( POPUP_BACKGROUND );
286 mBackground = ImageActor::New( bgImg );
287 mBackground.SetAnchorPoint( AnchorPoint::CENTER );
288 mBackground.SetParentOrigin( ParentOrigin::CENTER );
289 mBackground.SetName( "text-input-popup-background" );
290 mBackground.SetColor( mBackgroundColor );
292 Image bgEffectImg = ResourceImage::New( POPUP_BACKGROUND_EFFECT );
293 mBackgroundEffect = ImageActor::New( bgEffectImg );
294 mBackgroundEffect.SetAnchorPoint( AnchorPoint::CENTER );
295 mBackgroundEffect.SetParentOrigin( ParentOrigin::CENTER );
296 mBackgroundEffect.SetName( "text-input-popup-background-effect" );
297 mBackgroundEffect.SetSizeMode( SIZE_EQUAL_TO_PARENT );
298 mBackgroundEffect.SetZ( 1.0f );
299 mBackground.Add( mBackgroundEffect );
301 Image bgLine = ResourceImage::New( POPUP_BACKGROUND_LINE );
302 mBackgroundLine = ImageActor::New( bgLine );
303 mBackgroundLine.SetAnchorPoint( AnchorPoint::CENTER);
304 mBackgroundLine.SetParentOrigin( ParentOrigin::CENTER );
305 mBackgroundLine.SetName( "text-input-popup-background-effect" );
306 mBackgroundLine.SetSizeMode( SIZE_EQUAL_TO_PARENT );
307 mBackgroundLine.SetColor( mLineColor );
308 mBackgroundLine.SetZ( 0.1f );
309 mBackgroundEffect.Add( mBackgroundLine );
315 void TextInputPopup::CreateTail()
319 Image tail = ResourceImage::New( POPUP_TAIL_BOTTOM );
320 mTail = ImageActor::New( tail );
321 mTail.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
322 mTail.SetAnchorPoint( AnchorPoint::TOP_CENTER );
323 mTail.SetName( "text-input-popup-tail" );
324 mTail.SetPosition( 0.0f, POPUP_TAIL_Y_OFFSET - POPUP_BORDER.w, 1.2f );
325 mTail.SetColor( mBackgroundColor );
327 Image tailEffect = ResourceImage::New( POPUP_TAIL_BOTTOM_EFFECT );
328 mTailEffect = ImageActor::New( tailEffect );
329 mTailEffect.SetParentOrigin( ParentOrigin::CENTER );
330 mTailEffect.SetAnchorPoint( AnchorPoint::CENTER );
331 mTailEffect.SetName( "text-input-popup-tail-effect" );
332 mTailEffect.SetSizeMode( SIZE_EQUAL_TO_PARENT );
333 mTailEffect.SetZ( 0.1f );
334 mTail.Add( mTailEffect );
336 Image tailLine = ResourceImage::New( POPUP_TAIL_BOTTOM_LINE );
337 mTailLine = ImageActor::New( tailLine );
338 mTailLine.SetParentOrigin( ParentOrigin::CENTER );
339 mTailLine.SetAnchorPoint( AnchorPoint::CENTER );
340 mTailLine.SetSizeMode( SIZE_EQUAL_TO_PARENT );
341 mTailLine.SetName( "text-input-popup-tail-line" );
342 mTailLine.SetColor( mLineColor );
343 mTailLine.SetZ( 0.1f );
344 mTailEffect.Add( mTailLine );
348 ImageActor TextInputPopup::CreateDivider()
350 ImageActor divider = Toolkit::CreateSolidColorActor( mLineColor );
351 divider.SetParentOrigin( ParentOrigin::TOP_LEFT );
352 divider.SetAnchorPoint( AnchorPoint::TOP_LEFT );
353 divider.SetSize( POPUP_DIVIDER_SIZE.width , mContentSize.height );
354 divider.SetPosition( mContentSize.width - POPUP_DIVIDER_SIZE.width, 0.0f );
356 // Keep track of all the dividers. As their height's need to be updated to the max of all
357 // buttons currently added.
358 mDividerContainer.push_back( divider );
363 ImageActor TextInputPopup::CreatePressedBackground( const Vector2& requiredSize )
365 ImageActor pressedBg = Toolkit::CreateSolidColorActor( mBackgroundPressedColor );
366 pressedBg.SetDrawMode( DrawMode::OVERLAY );
367 pressedBg.SetParentOrigin( ParentOrigin::CENTER );
368 pressedBg.SetAnchorPoint( AnchorPoint::CENTER );
369 pressedBg.SetSize( requiredSize );
373 TextInputPopup::ButtonRequirement TextInputPopup::CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
374 const std::string& name, const std::string& caption, Image iconImage, bool enabled )
376 TextInputPopup::ButtonRequirement currentButton;
377 currentButton.buttonId = buttonId;
378 currentButton.orderOfPriority = orderOfPriority;
379 currentButton.name = name;
380 currentButton.caption = caption;
381 currentButton.iconImage = iconImage;
382 currentButton.enabled = enabled;
384 return currentButton;
387 void TextInputPopup::CreateOrderedListOfOptions()
389 mOrderListOfButtons.clear();
391 for ( std::size_t index= 0; index < ButtonsEnumEnd; index++ )
393 TextInputPopup::ButtonRequirement currentButton;
395 // Create button for each possible option using Option priority
400 Image cutIcon = ResourceImage::New( OPTION_ICON_CUT );
401 currentButton = CreateRequiredButton( ButtonsCut, mCutOptionPriority, OPTION_CUT, GET_LOCALE_TEXT("IDS_COM_BODY_CUT"), cutIcon, false );
406 Image copyIcon = ResourceImage::New( OPTION_ICON_COPY );
407 currentButton = CreateRequiredButton( ButtonsCopy, mCopyOptionPriority, OPTION_COPY, GET_LOCALE_TEXT("IDS_COM_BODY_COPY"), copyIcon, false );
412 Image pasteIcon = ResourceImage::New( OPTION_ICON_PASTE );
413 currentButton = CreateRequiredButton( ButtonsPaste, mPasteOptionPriority, OPTION_PASTE, GET_LOCALE_TEXT("IDS_COM_BODY_PASTE"), pasteIcon, false );
418 Image selectIcon = ResourceImage::New( OPTION_ICON_SELECT );
419 currentButton = CreateRequiredButton( ButtonsSelect, mSelectOptionPriority, OPTION_SELECT_WORD, GET_LOCALE_TEXT("IDS_COM_SK_SELECT"), selectIcon, false );
422 case ButtonsSelectAll:
424 Image selectAllIcon = ResourceImage::New( OPTION_ICON_SELECT_ALL );
425 currentButton = CreateRequiredButton( ButtonsSelectAll, mSelectAllOptionPriority, OPTION_SELECT_ALL, GET_LOCALE_TEXT("IDS_COM_BODY_SELECT_ALL"), selectAllIcon, false );
428 case ButtonsClipboard:
430 Image clipboardIcon = ResourceImage::New( OPTION_ICON_CLIPBOARD );
431 currentButton = CreateRequiredButton( ButtonsClipboard, mClipboardOptionPriority, OPTION_CLIPBOARD, GET_LOCALE_TEXT("IDS_COM_BODY_CLIPBOARD"), clipboardIcon, false );
438 // Insert button in list of buttons in order of priority setting.
439 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
441 const ButtonRequirement& button( *it );
442 if ( currentButton.orderOfPriority < button.orderOfPriority )
444 if ( currentButton.orderOfPriority != 0 ) // If order priority 0 then do not add button as not required.
446 mOrderListOfButtons.insert( it, currentButton );
454 mOrderListOfButtons.push_back( currentButton );
459 Vector2 TextInputPopup::GetConstrainedTextSize( const Vector2& textSize )
461 return Vector2( std::min( textSize.width, OPTION_MAX_SIZE.width - OPTION_PADDING.x - OPTION_PADDING.y ), textSize.height );
464 void TextInputPopup::AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption)
466 // 1. Create container for text and icon when not pressed.
467 Actor optionContainer = Actor::New();
468 optionContainer.SetParentOrigin( ParentOrigin::TOP_LEFT );
469 optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
472 Toolkit::TextView captionTextView = CreateOptionCaption( caption, mTextColor );
473 optionContainer.Add( captionTextView );
476 ImageActor icon = CreateOptionIcon( iconImage, mIconColor );
477 optionContainer.Add( icon );
479 // 4. Calculate the size of option.
480 const Vector2 textSize = Vector2( captionTextView.GetNaturalSize() );
481 captionTextView.SetSize( GetConstrainedTextSize( textSize ) );
484 const Vector2 optionSize( std::max( textSize.x, OPTION_ICON_SIZE.x ) + OPTION_PADDING.x + OPTION_PADDING.z,
485 OPTION_PADDING.z + OPTION_ICON_SIZE.y + OPTION_GAP_ICON_TEXT + textSize.y + OPTION_MAX_SIZE.y );
488 Vector2 constrainedOptionSize = Min( Max( optionSize, OPTION_MIN_SIZE ), OPTION_MAX_SIZE );
490 constrainedOptionSize.height = constrainedOptionSize.height - POPUP_BORDER.y - POPUP_BORDER.z;
492 // 5. Create a option.
493 Toolkit::PushButton option = Toolkit::PushButton::New();
494 option.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
495 option.SetParentOrigin( ParentOrigin::TOP_LEFT );
496 option.SetAnchorPoint( AnchorPoint::TOP_LEFT );
497 option.SetSize( constrainedOptionSize );
498 option.SetX( mContentSize.x );
499 option.SetName( name );
500 option.SetAnimationTime( 0.0f );
501 option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed );
502 mButtons.Add( option );
504 // 6. Set the normal option image.
505 option.SetButtonImage( optionContainer );
507 // 7. Update the content size.
508 mContentSize.x += constrainedOptionSize.x;
509 mContentSize.y = std::max ( constrainedOptionSize.y, mContentSize.y );
511 // 8. Create the pressed container.
512 Actor optionPressedContainer = Actor::New();
514 // 9. Add option pressed background.
515 Vector2 optionPressedBackgroundSize( constrainedOptionSize.x - POPUP_BORDER.x, mContentSize.y - POPUP_BORDER.y - POPUP_BORDER.w );
516 ImageActor optionPressedBackground = CreatePressedBackground( optionPressedBackgroundSize );
517 optionPressedContainer.Add( optionPressedBackground );
519 // 10. Add pressed text
520 Toolkit::TextView pressedCaptionTextView = CreateOptionCaption( caption, mTextPressedColor );
521 pressedCaptionTextView.SetSize( GetConstrainedTextSize( Vector2( pressedCaptionTextView.GetNaturalSize() ) ) );
522 optionPressedBackground.Add( pressedCaptionTextView );
524 // 11. Add pressed icon
525 ImageActor pressedIcon = CreateOptionIcon( iconImage, mIconPressedColor );
526 optionPressedBackground.Add( pressedIcon );
528 // 12. Set the pressed option image
529 option.SetSelectedImage( optionPressedContainer );
531 // 13. Add the divider
534 ImageActor divider = CreateDivider();
535 mButtons.Add( divider );
539 void TextInputPopup::Hide(bool animate)
551 mAnimation = Animation::New( HIDE_POPUP_ANIMATION_DURATION );
552 mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ZERO, AlphaFunctions::EaseOut );
553 mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunctions::EaseOut );
556 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnHideFinished );
557 mState = StateHiding;
561 mRoot.SetProperty(Actor::Property::SCALE, Vector3::ZERO);
562 mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f);
563 mState = StateHidden;
568 void TextInputPopup::Show( Actor target, bool animate )
572 mRoot.SetSensitive( true );
582 AddToParent( target );
587 mAnimation = Animation::New( SHOW_POPUP_ANIMATION_DURATION );
588 mAnimation.AnimateTo( Property(mRoot, Actor::Property::SCALE), Vector3::ONE, AlphaFunctions::EaseOut );
589 mAnimation.AnimateTo( Property(mRoot, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunctions::EaseOut );
592 mAnimation.FinishedSignal().Connect( this, &TextInputPopup::OnShowFinished );
593 mState = StateShowing;
597 mRoot.SetProperty(Actor::Property::SCALE, Vector3::ONE);
598 mRoot.SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
604 TextInputPopup::State TextInputPopup::GetState(void) const
609 Actor TextInputPopup::GetRootActor() const
616 void TextInputPopup::SetCutPastePopupColor( const Vector4& color )
618 mBackgroundColor = color;
621 const Vector4& TextInputPopup::GetCutPastePopupColor() const
623 return mBackgroundColor;
626 void TextInputPopup::SetCutPastePopupPressedColor( const Vector4& color )
628 mBackgroundPressedColor = color;
631 const Vector4& TextInputPopup::GetCutPastePopupPressedColor() const
633 return mBackgroundPressedColor;
636 void TextInputPopup::SetCutPastePopupBorderColor( const Vector4& color )
641 const Vector4& TextInputPopup::GetCutPastePopupBorderColor() const
646 void TextInputPopup::SetCutPastePopupIconColor( const Vector4& color )
651 const Vector4& TextInputPopup::GetCutPastePopupIconColor() const
656 void TextInputPopup::SetCutPastePopupIconPressedColor( const Vector4& color )
658 mIconPressedColor = color;
661 const Vector4& TextInputPopup::GetCutPastePopupIconPressedColor()
663 return mIconPressedColor;
666 void TextInputPopup::SetCutPastePopupTextColor( const Vector4& color )
671 const Vector4& TextInputPopup::GetCutPastePopupTextColor()
676 void TextInputPopup::SetCutPastePopupTextPressedColor( const Vector4& color )
678 mTextPressedColor = color;
681 const Vector4& TextInputPopup::GetCutPastePopupTextPressedColor()
683 return mTextPressedColor;
686 void TextInputPopup::TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable )
688 bool match ( false );
689 for( std::vector<ButtonRequirement>::iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt && !match ); ++it )
691 ButtonRequirement& button( *it );
692 if ( requiredButton == button.buttonId )
694 button.enabled = enable;
700 void TextInputPopup::SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority )
706 mCutOptionPriority = priority;
711 mCopyOptionPriority = priority;
716 mPasteOptionPriority = priority;
721 mSelectOptionPriority = priority;
724 case ButtonsSelectAll:
726 mSelectAllOptionPriority = priority;
729 case ButtonsClipboard:
731 mClipboardOptionPriority = priority;
736 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
740 CreateOrderedListOfOptions(); // Update list of options as priority changed.
743 unsigned int TextInputPopup::GetButtonPriorityPosition( TextInputPopup::Buttons button ) const
745 unsigned int priority = 0;
751 priority = mCutOptionPriority;
756 priority = mCopyOptionPriority;
761 priority = mPasteOptionPriority;
766 priority = mSelectOptionPriority;
769 case ButtonsSelectAll:
771 priority = mSelectAllOptionPriority;
774 case ButtonsClipboard:
776 priority = mClipboardOptionPriority;
781 DALI_ASSERT_DEBUG( "ButtonsEnumEnd used but an invalid choice");
789 void TextInputPopup::AddPopupOptions()
791 mContentSize = Vector2( POPUP_MIN_SIZE.width, ( POPUP_BORDER.y + POPUP_BORDER.z ) );
793 // 1. Create the background.
796 // 2. Create the tail.
799 // 3. Create the scroll view and Actor to hold buttons.
802 // Clear previous buttons
805 UnparentAndReset( mButtons );
808 mButtons = Actor::New();
809 mButtons.SetParentOrigin( ParentOrigin::CENTER );
810 mButtons.SetAnchorPoint( AnchorPoint::CENTER );
812 // 4. Create the options and add into the scroll view.
813 for( std::vector<ButtonRequirement>::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it )
815 const ButtonRequirement& button( *it );
816 if ( button.enabled )
818 AddOption( button.name, button.caption, button.iconImage, it != ( endIt - 1 ) ? false : true );
822 // 5. Calculate size of content and of popup including borders
823 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 );
825 mVisiblePopUpSize = Vector3( popupSize.width - POPUP_BORDER.x - POPUP_BORDER.z , mContentSize.height, 1.0f);
827 mBackground.SetSize( popupSize.x + 28 - POPUP_BORDER.x - POPUP_BORDER.z, popupSize.y + 28 - POPUP_BORDER.y - POPUP_BORDER.w );
828 mButtons.SetSize( mVisiblePopUpSize.GetVectorXY() );
830 // 6. Set the scroll view ruler.
831 UpdateScrollViewRulerAndSize( mVisiblePopUpSize.GetVectorXY() );
834 const Vector2 stencilSize = Vector2( mVisiblePopUpSize.GetVectorXY() );
836 CreateLayer( stencilSize );
837 CreateStencil( stencilSize );
839 mScrollView.Add ( mButtons );
840 mLayer.Add( mScrollView);
841 mLayer.Add( mStencil);
843 mRoot.Add( mBackground );
846 // 8. Set the root size.
847 mRoot.SetSize( popupSize ); // Make Root Actor reflect the size of its content
850 const Vector3& TextInputPopup::GetVisibileSize() const
852 return mVisiblePopUpSize;
855 void TextInputPopup::SetTailPosition( const Vector3& position, bool yAxisFlip )
857 mPopupTailXPosition = std::max( position.x, POPUP_TAIL_SIZE.width*0.5f - mVisiblePopUpSize.width*0.5f + POPUP_BORDER.x );
859 std::min( mPopupTailXPosition, mVisiblePopUpSize.width*0.5f - POPUP_BORDER.x - POPUP_TAIL_SIZE.width*0.5f );
861 mTail.SetX( mPopupTailXPosition );
865 Image tail = ResourceImage::New( POPUP_TAIL_TOP );
866 Image tailEffect = ResourceImage::New( POPUP_TAIL_TOP_EFFECT );
867 Image tailLine = ResourceImage::New( POPUP_TAIL_TOP_LINE );
869 mTail.SetImage( tail );
870 mTailEffect.SetImage( tailEffect );
871 mTailLine.SetImage( tailLine );
873 mTail.SetParentOrigin( ParentOrigin::TOP_CENTER );
874 mTail.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
875 mTail.SetY( POPUP_BORDER.y - POPUP_TAIL_Y_OFFSET );
879 bool TextInputPopup::OnButtonPressed( Toolkit::Button button )
881 mPressedSignal.Emit( button );
885 void TextInputPopup::OnHideFinished(Animation& source)
887 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnHideFinished );
889 mState = StateHidden;
890 mHideFinishedSignal.Emit( *this );
893 void TextInputPopup::OnShowFinished(Animation& source)
895 source.FinishedSignal().Disconnect( this, &TextInputPopup::OnShowFinished );
897 mShowFinishedSignal.Emit( *this );
900 TextInputPopup::PressedSignalType& TextInputPopup::PressedSignal()
902 return mPressedSignal;
905 TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::HideFinishedSignal()
907 return mHideFinishedSignal;
910 TextInputPopup::VisibilityChangeFinishedSignalType& TextInputPopup::ShowFinishedSignal()
912 return mShowFinishedSignal;
915 } // namespace Internal
917 } // namespace Toolkit