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/text/decorator/text-decorator.h>
22 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/events/touch-event.h>
28 #include <dali/public-api/events/pan-gesture.h>
29 #include <dali/public-api/images/resource-image.h>
30 #include <dali/public-api/object/property-notification.h>
32 #include <dali/devel-api/rendering/geometry.h>
33 #include <dali/devel-api/rendering/renderer.h>
36 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
40 #define DECORATOR_DEBUG
44 #define MAKE_SHADER(A)#A
48 const char* VERTEX_SHADER = MAKE_SHADER(
49 attribute mediump vec2 aPosition;
50 uniform mediump mat4 uMvpMatrix;
51 uniform mediump vec3 uSize;
55 mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
56 position.xyz *= uSize;
57 gl_Position = uMvpMatrix * position;
61 const char* FRAGMENT_SHADER = MAKE_SHADER(
62 uniform lowp vec4 uColor;
66 gl_FragColor = uColor;
77 #ifdef DECORATOR_DEBUG
78 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
89 const char* DEFAULT_GRAB_HANDLE_IMAGE_RELEASED( DALI_IMAGE_DIR "cursor_handler_center.png" );
91 const int DEFAULT_POPUP_OFFSET( -100.0f ); // Vertical offset of Popup from cursor or handles position.
93 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
94 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
96 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. TODO: due some problems, maybe with the blending function in the text clipping, the color is fully opaque.
98 const Dali::Vector4 HANDLE_COLOR( 0.0f, (183.0f / 255.0f), (229.0f / 255.0f), 1.0f );
100 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
101 const float TO_MILLISECONDS = 1000.f;
102 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
104 const unsigned int SCROLL_TICK_INTERVAL = 50u;
106 const float SCROLL_THRESHOLD = 10.f;
107 const float SCROLL_SPEED = 300.f;
108 const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
111 * structure to hold coordinates of each quad, which will make up the mesh.
113 struct QuadCoordinates
116 * Default constructor
124 * @param[in] x1 left co-ordinate
125 * @param[in] y1 top co-ordinate
126 * @param[in] x2 right co-ordinate
127 * @param[in] y2 bottom co-ordinate
129 QuadCoordinates(float x1, float y1, float x2, float y2)
135 Dali::Vector2 min; ///< top-left (minimum) position of quad
136 Dali::Vector2 max; ///< bottom-right (maximum) position of quad
139 typedef std::vector<QuadCoordinates> QuadContainer;
142 * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
143 * @param[in] boundingRectangle local bounding
144 * @param[out] Vector4 World coordinate bounding Box.
146 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
148 // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
149 Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
151 const float originX = boundingRectangle.x - 0.5f * stageSize.width;
152 const float originY = boundingRectangle.y - 0.5f * stageSize.height;
154 boundingBox = Dali::Vector4( originX,
156 originX + boundingRectangle.width,
157 originY + boundingRectangle.height );
161 } // end of namespace
172 struct Decorator::Impl : public ConnectionTracker
186 : color( Dali::Color::BLACK ),
188 cursorHeight( 0.0f ),
204 grabDisplacementX( 0.f ),
205 grabDisplacementY( 0.f ),
215 ImageActor markerActor;
218 float lineHeight; ///< Not the handle height
219 float grabDisplacementX;
220 float grabDisplacementY;
231 offset( DEFAULT_POPUP_OFFSET )
235 TextSelectionPopup actor;
240 Impl( ControllerInterface& controller,
241 TextSelectionPopupCallbackInterface& callbackInterface )
242 : mController( controller ),
243 mEnabledPopupButtons( TextSelectionPopup::NONE ),
244 mTextSelectionPopupCallbackInterface( callbackInterface ),
245 mHandleColor( HANDLE_COLOR ),
246 mBoundingBox( Rect<int>() ),
247 mHighlightColor( LIGHT_BLUE ),
248 mHighlightPosition( Vector2::ZERO ),
249 mActiveCursor( ACTIVE_CURSOR_NONE ),
250 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
251 mCursorBlinkDuration( 0.0f ),
252 mHandleScrolling( HANDLE_TYPE_COUNT ),
253 mScrollDirection( SCROLL_NONE ),
254 mScrollThreshold( SCROLL_THRESHOLD ),
255 mScrollSpeed( SCROLL_SPEED ),
256 mScrollDistance( SCROLL_DISTANCE ),
258 mActiveCopyPastePopup( false ),
259 mCursorBlinkStatus( true ),
260 mPrimaryCursorVisible( false ),
261 mSecondaryCursorVisible( false ),
262 mSwapSelectionHandles( false ),
263 mNotifyEndOfScroll( false )
265 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
266 mQuadIndexFormat[ "indices" ] = Property::INTEGER;
267 mHighlightMaterial = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
271 * Relayout of the decorations owned by the decorator.
272 * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
274 void Relayout( const Vector2& size )
276 // TODO - Remove this if nothing is active
279 // Show or hide the cursors
284 const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
285 mPrimaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
286 if( mPrimaryCursorVisible )
288 Vector2 position = cursor.position;
290 mPrimaryCursor.SetPosition( position.x,
292 mPrimaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
294 mPrimaryCursor.SetVisible( mPrimaryCursorVisible );
296 if( mSecondaryCursor )
298 const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
299 mSecondaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
300 if( mSecondaryCursorVisible )
302 mSecondaryCursor.SetPosition( cursor.position.x,
304 mSecondaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
306 mSecondaryCursor.SetVisible( mSecondaryCursorVisible );
309 // Show or hide the grab handle
310 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
311 if( grabHandle.active )
313 Vector2 position = grabHandle.position;
315 const bool isVisible = ( position.x <= size.width ) && ( position.x >= 0.f );
323 grabHandle.actor.SetPosition( position.x,
324 position.y + grabHandle.lineHeight ); // TODO : Fix for multiline.
326 grabHandle.actor.SetVisible( isVisible );
328 else if( grabHandle.actor )
330 grabHandle.actor.Unparent();
333 // Show or hide the selection handles/highlight
334 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
335 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
336 if( primary.active || secondary.active )
338 Vector2 primaryPosition = primary.position;
339 Vector2 secondaryPosition = secondary.position;
341 const bool isPrimaryVisible = ( primaryPosition.x <= size.width ) && ( primaryPosition.x >= 0.f );
342 const bool isSecondaryVisible = ( secondaryPosition.x <= size.width ) && ( secondaryPosition.x >= 0.f );
344 if( isPrimaryVisible || isSecondaryVisible )
348 CreateSelectionHandles();
350 if( isPrimaryVisible )
352 primary.actor.SetPosition( primaryPosition.x,
353 primaryPosition.y + primary.lineHeight ); // TODO : Fix for multiline.
355 SetSelectionHandleMarkerSize( primary );
358 if( isSecondaryVisible )
360 secondary.actor.SetPosition( secondaryPosition.x,
361 secondaryPosition.y + secondary.lineHeight ); // TODO : Fix for multiline.
363 SetSelectionHandleMarkerSize( secondary );
366 primary.actor.SetVisible( isPrimaryVisible );
367 secondary.actor.SetVisible( isSecondaryVisible );
376 primary.actor.Unparent();
378 if( secondary.actor )
380 secondary.actor.Unparent();
382 if( mHighlightActor )
384 mHighlightActor.Unparent();
388 if( mActiveCopyPastePopup )
394 if( mCopyPastePopup.actor )
396 mCopyPastePopup.actor.HidePopup();
401 void UpdatePositions( const Vector2& scrollOffset )
403 mCursor[PRIMARY_CURSOR].position += scrollOffset;
404 mCursor[SECONDARY_CURSOR].position += scrollOffset;
405 mHandle[ GRAB_HANDLE ].position += scrollOffset;
406 mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset;
407 mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset;
408 mHighlightPosition += scrollOffset;
409 DeterminePositionPopup();
414 if ( !mCopyPastePopup.actor )
419 if( !mCopyPastePopup.actor.GetParent() )
421 mActiveLayer.Add( mCopyPastePopup.actor );
424 mCopyPastePopup.actor.RaiseAbove( mActiveLayer );
425 mCopyPastePopup.actor.ShowPopup();
428 void DeterminePositionPopup()
430 if ( !mActiveCopyPastePopup )
435 if ( mHandle[LEFT_SELECTION_HANDLE].active || mHandle[RIGHT_SELECTION_HANDLE].active )
437 float minHandleXPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
438 float maxHandleXPosition = std::max ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
440 float minHandleYPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.y, mHandle[RIGHT_SELECTION_HANDLE].position.y );
442 mCopyPastePopup.position.x = minHandleXPosition + ( ( maxHandleXPosition - minHandleXPosition ) *0.5f );
443 mCopyPastePopup.position.y = minHandleYPosition + mCopyPastePopup.offset;
447 mCopyPastePopup.position = Vector3( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f ); //todo 100 to be an offset Property
450 Vector3 popupSize = Vector3( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
452 GetConstrainedPopupPosition( mCopyPastePopup.position, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
454 SetUpPopupPositionNotifications();
456 mCopyPastePopup.actor.SetPosition( mCopyPastePopup.position );
459 void PopupRelayoutComplete( Actor actor )
461 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
463 DeterminePositionPopup();
466 void CreateCursor( ImageActor& cursor, const Vector4& color )
468 cursor = CreateSolidColorActor( color );
469 cursor.SetSortModifier( DECORATION_DEPTH_INDEX );
470 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
471 cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
474 // Add or Remove cursor(s) from parent
477 if( mActiveCursor == ACTIVE_CURSOR_NONE )
481 mPrimaryCursor.Unparent();
483 if( mSecondaryCursor )
485 mSecondaryCursor.Unparent();
490 // Create Primary and or Secondary Cursor(s) if active and add to parent
491 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
492 mActiveCursor == ACTIVE_CURSOR_BOTH )
494 if ( !mPrimaryCursor )
496 CreateCursor( mPrimaryCursor, mCursor[PRIMARY_CURSOR].color );
497 #ifdef DECORATOR_DEBUG
498 mPrimaryCursor.SetName( "PrimaryCursorActor" );
502 if( !mPrimaryCursor.GetParent() )
504 mActiveLayer.Add( mPrimaryCursor );
508 if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
510 if ( !mSecondaryCursor )
512 CreateCursor( mSecondaryCursor, mCursor[SECONDARY_CURSOR].color );
513 #ifdef DECORATOR_DEBUG
514 mSecondaryCursor.SetName( "SecondaryCursorActor" );
518 if( !mSecondaryCursor.GetParent() )
520 mActiveLayer.Add( mSecondaryCursor );
525 if( mSecondaryCursor )
527 mSecondaryCursor.Unparent();
533 bool OnCursorBlinkTimerTick()
536 if ( mPrimaryCursor )
538 mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
540 if ( mSecondaryCursor )
542 mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
545 mCursorBlinkStatus = !mCursorBlinkStatus;
550 void SetupTouchEvents()
554 mTapDetector = TapGestureDetector::New();
555 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
558 if ( !mPanGestureDetector )
560 mPanGestureDetector = PanGestureDetector::New();
561 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
565 void CreateActiveLayer()
569 mActiveLayer = Layer::New();
570 #ifdef DECORATOR_DEBUG
571 mActiveLayer.SetName ( "ActiveLayerActor" );
574 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
575 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
576 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
578 // Add the active layer telling the controller it doesn't need clipping.
579 mController.AddDecoration( mActiveLayer, false );
582 mActiveLayer.RaiseToTop();
585 void SetSelectionHandleMarkerSize( HandleImpl& handle )
587 if ( handle.markerActor )
589 handle.markerActor.SetResizePolicy ( ResizePolicy::FIXED, Dimension::HEIGHT );
590 handle.markerActor.SetSize( 0, handle.lineHeight );
594 void CreateGrabHandle()
596 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
597 if( !grabHandle.actor )
599 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
601 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_RELEASED );
604 grabHandle.actor = ImageActor::New( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
605 grabHandle.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
606 grabHandle.actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
607 // Area that Grab handle responds to, larger than actual handle so easier to move
608 #ifdef DECORATOR_DEBUG
609 grabHandle.actor.SetName( "GrabHandleActor" );
610 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
612 grabHandle.grabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
613 grabHandle.grabArea.SetName( "GrabArea" );
617 grabHandle.grabArea = Actor::New();
618 grabHandle.grabArea.SetName( "GrabArea" );
621 grabHandle.grabArea = Actor::New();
624 grabHandle.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
625 grabHandle.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
626 grabHandle.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
627 grabHandle.grabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
628 grabHandle.actor.Add( grabHandle.grabArea );
629 grabHandle.actor.SetColor( mHandleColor );
631 grabHandle.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnGrabHandleTouched );
632 mTapDetector.Attach( grabHandle.grabArea );
633 mPanGestureDetector.Attach( grabHandle.grabArea );
635 mActiveLayer.Add( grabHandle.actor );
638 if( !grabHandle.actor.GetParent() )
640 mActiveLayer.Add( grabHandle.actor );
644 void CreateHandleMarker( HandleImpl& handle, Image& image, HandleType handleType )
648 handle.markerActor = ImageActor::New( image );
649 handle.markerActor.SetColor( mHandleColor );
650 handle.actor.Add( handle.markerActor );
652 if ( LEFT_SELECTION_HANDLE == handleType )
654 handle.markerActor.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
655 handle.markerActor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
657 else if ( RIGHT_SELECTION_HANDLE == handleType )
659 handle.markerActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
660 handle.markerActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
665 void CreateSelectionHandles()
667 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
670 primary.actor = ImageActor::New( mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
671 #ifdef DECORATOR_DEBUG
672 primary.actor.SetName("SelectionHandleOne");
674 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
675 primary.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
676 primary.flipped = false;
677 primary.actor.SetColor( mHandleColor );
679 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
680 #ifdef DECORATOR_DEBUG
681 primary.grabArea.SetName("SelectionHandleOneGrabArea");
683 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
684 primary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
685 primary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
686 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
688 mTapDetector.Attach( primary.grabArea );
689 mPanGestureDetector.Attach( primary.grabArea );
690 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
692 primary.actor.Add( primary.grabArea );
694 CreateHandleMarker( primary, mHandleImages[LEFT_SELECTION_HANDLE_MARKER][HANDLE_IMAGE_RELEASED], LEFT_SELECTION_HANDLE );
697 if( !primary.actor.GetParent() )
699 mActiveLayer.Add( primary.actor );
702 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
703 if( !secondary.actor )
705 secondary.actor = ImageActor::New( mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
706 #ifdef DECORATOR_DEBUG
707 secondary.actor.SetName("SelectionHandleTwo");
709 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
710 secondary.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
711 secondary.flipped = false;
712 secondary.actor.SetColor( mHandleColor );
714 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
715 #ifdef DECORATOR_DEBUG
716 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
718 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
719 secondary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
720 secondary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
721 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
723 mTapDetector.Attach( secondary.grabArea );
724 mPanGestureDetector.Attach( secondary.grabArea );
725 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
727 secondary.actor.Add( secondary.grabArea );
729 CreateHandleMarker( secondary, mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][HANDLE_IMAGE_RELEASED], RIGHT_SELECTION_HANDLE );
732 if( !secondary.actor.GetParent() )
734 mActiveLayer.Add( secondary.actor );
738 void CreateHighlight()
740 if( !mHighlightActor )
742 mHighlightActor = Actor::New();
744 #ifdef DECORATOR_DEBUG
745 mHighlightActor.SetName( "HighlightActor" );
747 mHighlightActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
748 mHighlightActor.SetSize( 1.0f, 1.0f );
749 mHighlightActor.SetColor( mHighlightColor );
750 mHighlightActor.SetColorMode( USE_OWN_COLOR );
753 // Add the highlight box telling the controller it needs clipping.
754 mController.AddDecoration( mHighlightActor, true );
757 void UpdateHighlight()
759 if ( mHighlightActor )
761 if( !mHighlightQuadList.empty() )
763 Vector< Vector2 > vertices;
764 Vector< unsigned int> indices;
767 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
768 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
770 for( std::size_t v = 0; iter != endIter; ++iter,v+=4 )
773 QuadCoordinates& quad = *iter;
776 vertex.x = quad.min.x;
777 vertex.y = quad.min.y;
778 vertices.PushBack( vertex );
781 vertex.x = quad.max.x;
782 vertex.y = quad.min.y;
783 vertices.PushBack( vertex );
786 vertex.x = quad.min.x;
787 vertex.y = quad.max.y;
788 vertices.PushBack( vertex );
790 // bottom-right (v+3)
791 vertex.x = quad.max.x;
792 vertex.y = quad.max.y;
793 vertices.PushBack( vertex );
795 // triangle A (3, 1, 0)
796 indices.PushBack( v + 3 );
797 indices.PushBack( v + 1 );
798 indices.PushBack( v );
800 // triangle B (0, 2, 3)
801 indices.PushBack( v );
802 indices.PushBack( v + 2 );
803 indices.PushBack( v + 3 );
808 mQuadVertices.SetSize( vertices.Size() );
812 mQuadVertices = PropertyBuffer::New( mQuadVertexFormat, vertices.Size() );
817 mQuadIndices.SetSize( indices.Size() );
821 mQuadIndices = PropertyBuffer::New( mQuadIndexFormat, indices.Size() );
824 mQuadVertices.SetData( &vertices[ 0 ] );
825 mQuadIndices.SetData( &indices[ 0 ] );
829 mQuadGeometry = Geometry::New();
830 mQuadGeometry.AddVertexBuffer( mQuadVertices );
832 mQuadGeometry.SetIndexBuffer( mQuadIndices );
834 if( !mHighlightRenderer )
836 mHighlightRenderer = Dali::Renderer::New( mQuadGeometry, mHighlightMaterial );
837 mHighlightActor.AddRenderer( mHighlightRenderer );
841 mHighlightActor.SetPosition( mHighlightPosition.x,
842 mHighlightPosition.y );
844 mHighlightQuadList.clear();
846 mHighlightRenderer.SetDepthIndex( mTextDepth - 2u ); // text is rendered at mTextDepth and text's shadow at mTextDepth -1u.
850 void OnTap( Actor actor, const TapGesture& tap )
852 if( actor == mHandle[GRAB_HANDLE].actor )
858 void DoPan( HandleImpl& handle, HandleType type, const PanGesture& gesture )
860 if( Gesture::Started == gesture.state )
862 handle.grabDisplacementX = handle.grabDisplacementY = 0;
865 handle.grabDisplacementX += gesture.displacement.x;
866 handle.grabDisplacementY += gesture.displacement.y;
868 const float x = handle.position.x + handle.grabDisplacementX;
869 const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
871 if( Gesture::Started == gesture.state ||
872 Gesture::Continuing == gesture.state )
875 mController.GetTargetSize( targetSize );
877 if( x < mScrollThreshold )
879 mScrollDirection = SCROLL_RIGHT;
880 mHandleScrolling = type;
883 else if( x > targetSize.width - mScrollThreshold )
885 mScrollDirection = SCROLL_LEFT;
886 mHandleScrolling = type;
891 mHandleScrolling = HANDLE_TYPE_COUNT;
893 mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
896 else if( Gesture::Finished == gesture.state ||
897 Gesture::Cancelled == gesture.state )
900 ( mScrollTimer.IsRunning() || mNotifyEndOfScroll ) )
902 mNotifyEndOfScroll = false;
903 mHandleScrolling = HANDLE_TYPE_COUNT;
905 mController.DecorationEvent( type, HANDLE_STOP_SCROLLING, x, y );
909 mController.DecorationEvent( type, HANDLE_RELEASED, x, y );
912 if( GRAB_HANDLE == type )
914 handle.actor.SetImage( mHandleImages[type][HANDLE_IMAGE_RELEASED] );
918 HandleType selectionHandleType = type;
920 if( mSwapSelectionHandles != handle.flipped )
922 selectionHandleType = ( LEFT_SELECTION_HANDLE == type ) ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE;
925 handle.actor.SetImage( mHandleImages[selectionHandleType][HANDLE_IMAGE_RELEASED] );
927 handle.pressed = false;
931 void OnPan( Actor actor, const PanGesture& gesture )
933 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
934 HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
935 HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
937 if( actor == grabHandle.grabArea )
939 DoPan( grabHandle, GRAB_HANDLE, gesture );
941 else if( actor == primarySelectionHandle.grabArea )
943 DoPan( primarySelectionHandle, LEFT_SELECTION_HANDLE, gesture );
945 else if( actor == secondarySelectionHandle.grabArea )
947 DoPan( secondarySelectionHandle, RIGHT_SELECTION_HANDLE, gesture );
951 bool OnGrabHandleTouched( Actor actor, const TouchEvent& event )
953 // Switch between pressed/release grab-handle images
954 if( event.GetPointCount() > 0 &&
955 mHandle[GRAB_HANDLE].actor )
957 const TouchPoint& point = event.GetPoint(0);
959 if( TouchPoint::Down == point.state )
961 mHandle[GRAB_HANDLE].pressed = true;
962 Image imagePressed = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED];
965 mHandle[GRAB_HANDLE].actor.SetImage( imagePressed );
968 else if( ( TouchPoint::Up == point.state ) ||
969 ( TouchPoint::Interrupted == point.state ) )
971 mHandle[GRAB_HANDLE].pressed = false;
972 Image imageReleased = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED];
975 mHandle[GRAB_HANDLE].actor.SetImage( imageReleased );
980 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
984 bool OnHandleOneTouched( Actor actor, const TouchEvent& event )
986 // Switch between pressed/release selection handle images
987 if( event.GetPointCount() > 0 &&
988 mHandle[LEFT_SELECTION_HANDLE].actor )
990 const TouchPoint& point = event.GetPoint(0);
992 const bool flip = mSwapSelectionHandles != mHandle[LEFT_SELECTION_HANDLE].flipped;
993 if( TouchPoint::Down == point.state )
995 mHandle[LEFT_SELECTION_HANDLE].pressed = true;
996 Image imagePressed = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
999 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1002 else if( ( TouchPoint::Up == point.state ) ||
1003 ( TouchPoint::Interrupted == point.state ) )
1005 mHandle[LEFT_SELECTION_HANDLE].pressed = false;
1006 Image imageReleased = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1009 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1014 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1018 bool OnHandleTwoTouched( Actor actor, const TouchEvent& event )
1020 // Switch between pressed/release selection handle images
1021 if( event.GetPointCount() > 0 &&
1022 mHandle[RIGHT_SELECTION_HANDLE].actor )
1024 const TouchPoint& point = event.GetPoint(0);
1026 const bool flip = mSwapSelectionHandles != mHandle[RIGHT_SELECTION_HANDLE].flipped;
1027 if( TouchPoint::Down == point.state )
1029 Image imagePressed = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
1030 mHandle[RIGHT_SELECTION_HANDLE].pressed = true;
1033 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1036 else if( ( TouchPoint::Up == point.state ) ||
1037 ( TouchPoint::Interrupted == point.state ) )
1039 Image imageReleased = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1040 mHandle[RIGHT_SELECTION_HANDLE].pressed = false;
1043 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1048 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1054 float AlternatePopUpPositionRelativeToCursor()
1056 float alternativePosition=0.0f;;
1058 if ( mPrimaryCursor ) // Secondary cursor not used for paste
1060 Cursor cursor = PRIMARY_CURSOR;
1061 alternativePosition = mCursor[cursor].position.y;
1064 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
1066 if( mHandle[GRAB_HANDLE].active )
1068 // If grab handle enabled then position pop-up below the grab handle.
1069 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
1070 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
1071 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
1075 alternativePosition += popupHeight;
1078 return alternativePosition;
1081 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
1083 float alternativeYPosition=0.0f;
1084 // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted
1085 // if can't be positioned above, then position below row.
1086 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
1088 mCopyPastePopup.actor.SetY( alternativeYPosition );
1092 void SetUpPopupPositionNotifications( )
1094 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
1096 // Exceeding vertical boundary
1098 Vector4 worldCoordinatesBoundingBox;
1099 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
1101 float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT);
1103 PropertyNotification verticalExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
1104 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight * 0.5f,
1105 worldCoordinatesBoundingBox.w - popupHeight * 0.5f ) );
1107 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
1110 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
1112 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
1114 // Parent must already by added to Stage for these Get calls to work
1115 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
1116 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
1117 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
1118 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
1120 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
1121 Vector4 boundingRectangleWorld;
1122 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
1124 // Calculate distance to move popup (in local space) so fits within the boundary
1125 float xOffSetToKeepWithinBounds = 0.0f;
1126 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
1128 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
1130 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
1132 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
1135 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
1136 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
1138 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
1141 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
1143 // Prevent pixel mis-alignment by rounding down.
1144 requiredPopupPosition.x = static_cast<int>( requiredPopupPosition.x );
1145 requiredPopupPosition.y = static_cast<int>( requiredPopupPosition.y );
1149 void FlipSelectionHandleImages()
1153 CreateSelectionHandles();
1155 HandleImpl& leftHandle = mHandle[LEFT_SELECTION_HANDLE];
1156 HandleImpl& rightHandle = mHandle[RIGHT_SELECTION_HANDLE];
1158 // If handle pressed and pressed image exists then use pressed image else stick with released image
1159 const HandleImageType leftImageType = ( leftHandle.pressed && mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] ) ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1160 const HandleImageType rightImageType = ( rightHandle.pressed && mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] ) ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1162 const bool leftFlipped = mSwapSelectionHandles != leftHandle.flipped;
1163 const bool rightFlipped = mSwapSelectionHandles != rightHandle.flipped;
1165 leftHandle.actor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE][leftImageType] );
1167 leftHandle.actor.SetAnchorPoint( leftFlipped ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
1169 rightHandle.actor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE][rightImageType] );
1171 rightHandle.actor.SetAnchorPoint( rightFlipped ? AnchorPoint::TOP_RIGHT : AnchorPoint::TOP_LEFT );
1173 if ( leftHandle.markerActor )
1175 leftHandle.markerActor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE_MARKER][leftImageType] );
1177 if ( rightHandle.markerActor )
1179 rightHandle.markerActor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE_MARKER][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][rightImageType] );
1183 void SetScrollThreshold( float threshold )
1185 mScrollThreshold = threshold;
1188 float GetScrollThreshold() const
1190 return mScrollThreshold;
1193 void SetScrollSpeed( float speed )
1195 mScrollSpeed = speed;
1196 mScrollDistance = speed * SCROLL_TICK_INTERVAL * TO_SECONDS;
1199 float GetScrollSpeed() const
1201 return mScrollSpeed;
1204 void NotifyEndOfScroll()
1210 mNotifyEndOfScroll = true;
1215 * Creates and starts a timer to scroll the text when handles are close to the edges of the text.
1217 * It only starts the timer if it's already created.
1219 void StartScrollTimer()
1223 mScrollTimer = Timer::New( SCROLL_TICK_INTERVAL );
1224 mScrollTimer.TickSignal().Connect( this, &Decorator::Impl::OnScrollTimerTick );
1227 if( !mScrollTimer.IsRunning() )
1229 mScrollTimer.Start();
1234 * Stops the timer used to scroll the text.
1236 void StopScrollTimer()
1240 mScrollTimer.Stop();
1245 * Callback called by the timer used to scroll the text.
1247 * It calculates and sets a new scroll position.
1249 bool OnScrollTimerTick()
1251 if( HANDLE_TYPE_COUNT != mHandleScrolling )
1253 mController.DecorationEvent( mHandleScrolling,
1255 mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
1262 ControllerInterface& mController;
1264 TapGestureDetector mTapDetector;
1265 PanGestureDetector mPanGestureDetector;
1266 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1267 Timer mScrollTimer; ///< Timer used to scroll the text when the grab handle is moved close to the edges.
1269 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1270 ImageActor mPrimaryCursor;
1271 ImageActor mSecondaryCursor;
1273 Actor mHighlightActor; ///< Actor to display highlight
1274 Renderer mHighlightRenderer;
1275 Material mHighlightMaterial; ///< Material used for highlight
1276 Property::Map mQuadVertexFormat;
1277 Property::Map mQuadIndexFormat;
1278 PopupImpl mCopyPastePopup;
1279 TextSelectionPopup::Buttons mEnabledPopupButtons; /// Bit mask of currently enabled Popup buttons
1280 TextSelectionPopupCallbackInterface& mTextSelectionPopupCallbackInterface;
1282 Image mHandleImages[HANDLE_TYPE_COUNT][HANDLE_IMAGE_TYPE_COUNT];
1283 Vector4 mHandleColor;
1285 CursorImpl mCursor[CURSOR_COUNT];
1286 HandleImpl mHandle[HANDLE_TYPE_COUNT];
1288 PropertyBuffer mQuadVertices;
1289 PropertyBuffer mQuadIndices;
1290 Geometry mQuadGeometry;
1291 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
1293 Rect<int> mBoundingBox;
1294 Vector4 mHighlightColor; ///< Color of the highlight
1295 Vector2 mHighlightPosition; ///< The position of the highlight actor.
1297 unsigned int mActiveCursor;
1298 unsigned int mCursorBlinkInterval;
1299 float mCursorBlinkDuration;
1300 HandleType mHandleScrolling; ///< The handle which is scrolling.
1301 ScrollDirection mScrollDirection; ///< The direction of the scroll.
1302 float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events.
1303 float mScrollSpeed; ///< The scroll speed in pixels per second.
1304 float mScrollDistance; ///< Distance the text scrolls during a scroll interval.
1305 int mTextDepth; ///< The depth used to render the text.
1307 bool mActiveCopyPastePopup : 1;
1308 bool mCursorBlinkStatus : 1; ///< Flag to switch between blink on and blink off.
1309 bool mPrimaryCursorVisible : 1; ///< Whether the primary cursor is visible.
1310 bool mSecondaryCursorVisible : 1; ///< Whether the secondary cursor is visible.
1311 bool mSwapSelectionHandles : 1; ///< Whether to swap the selection handle images.
1312 bool mNotifyEndOfScroll : 1; ///< Whether to notify the end of the scroll.
1315 DecoratorPtr Decorator::New( ControllerInterface& controller,
1316 TextSelectionPopupCallbackInterface& callbackInterface )
1318 return DecoratorPtr( new Decorator( controller,
1319 callbackInterface ) );
1322 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
1324 mImpl->mBoundingBox = boundingBox;
1327 const Rect<int>& Decorator::GetBoundingBox() const
1329 return mImpl->mBoundingBox;
1332 void Decorator::Relayout( const Vector2& size )
1334 mImpl->Relayout( size );
1337 void Decorator::UpdatePositions( const Vector2& scrollOffset )
1339 mImpl->UpdatePositions( scrollOffset );
1344 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
1346 mImpl->mActiveCursor = activeCursor;
1349 unsigned int Decorator::GetActiveCursor() const
1351 return mImpl->mActiveCursor;
1354 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
1356 mImpl->mCursor[cursor].position.x = x;
1357 mImpl->mCursor[cursor].position.y = y;
1358 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
1359 mImpl->mCursor[cursor].lineHeight = lineHeight;
1362 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
1364 x = mImpl->mCursor[cursor].position.x;
1365 y = mImpl->mCursor[cursor].position.y;
1366 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
1367 lineHeight = mImpl->mCursor[cursor].lineHeight;
1370 const Vector2& Decorator::GetPosition( Cursor cursor ) const
1372 return mImpl->mCursor[cursor].position;
1375 void Decorator::SetCursorColor( Cursor cursor, const Dali::Vector4& color )
1377 mImpl->mCursor[cursor].color = color;
1380 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
1382 return mImpl->mCursor[cursor].color;
1385 void Decorator::StartCursorBlink()
1387 if ( !mImpl->mCursorBlinkTimer )
1389 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
1390 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
1393 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
1395 mImpl->mCursorBlinkTimer.Start();
1399 void Decorator::StopCursorBlink()
1401 if ( mImpl->mCursorBlinkTimer )
1403 mImpl->mCursorBlinkTimer.Stop();
1407 void Decorator::SetCursorBlinkInterval( float seconds )
1409 mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
1412 float Decorator::GetCursorBlinkInterval() const
1414 return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
1417 void Decorator::SetCursorBlinkDuration( float seconds )
1419 mImpl->mCursorBlinkDuration = seconds;
1422 float Decorator::GetCursorBlinkDuration() const
1424 return mImpl->mCursorBlinkDuration;
1429 void Decorator::SetHandleActive( HandleType handleType, bool active )
1431 mImpl->mHandle[handleType].active = active;
1435 // TODO: this is a work-around.
1436 // The problem is the handle actor does not receive the touch event with the Interrupt
1437 // state when the power button is pressed and the application goes to background.
1438 mImpl->mHandle[handleType].pressed = false;
1439 Image imageReleased = mImpl->mHandleImages[handleType][HANDLE_IMAGE_RELEASED];
1440 ImageActor imageActor = mImpl->mHandle[handleType].actor;
1441 if( imageReleased && imageActor )
1443 imageActor.SetImage( imageReleased );
1448 bool Decorator::IsHandleActive( HandleType handleType ) const
1450 return mImpl->mHandle[handleType].active ;
1453 void Decorator::SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image )
1455 mImpl->mHandleImages[handleType][handleImageType] = image;
1458 Dali::Image Decorator::GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const
1460 return mImpl->mHandleImages[handleType][handleImageType];
1463 void Decorator::SetHandleColor( const Vector4& color )
1465 mImpl->mHandleColor = color;
1468 const Vector4& Decorator::GetHandleColor() const
1470 return mImpl->mHandleColor;
1473 void Decorator::SetPosition( HandleType handleType, float x, float y, float height )
1475 // Adjust grab handle displacement
1476 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1478 handle.grabDisplacementX -= x - handle.position.x;
1479 handle.grabDisplacementY -= y - handle.position.y;
1481 handle.position.x = x;
1482 handle.position.y = y;
1483 handle.lineHeight = height;
1486 void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
1488 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1490 x = handle.position.x;
1491 y = handle.position.y;
1492 height = handle.lineHeight;
1495 const Vector2& Decorator::GetPosition( HandleType handleType ) const
1497 return mImpl->mHandle[handleType].position;
1500 void Decorator::SwapSelectionHandlesEnabled( bool enable )
1502 mImpl->mSwapSelectionHandles = enable;
1504 mImpl->FlipSelectionHandleImages();
1507 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1509 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1512 void Decorator::ClearHighlights()
1514 mImpl->mHighlightQuadList.clear();
1515 mImpl->mHighlightPosition = Vector2::ZERO;
1518 void Decorator::SetHighlightColor( const Vector4& color )
1520 mImpl->mHighlightColor = color;
1523 const Vector4& Decorator::GetHighlightColor() const
1525 return mImpl->mHighlightColor;
1528 void Decorator::SetTextDepth( int textDepth )
1530 mImpl->mTextDepth = textDepth;
1533 void Decorator::SetPopupActive( bool active )
1535 mImpl->mActiveCopyPastePopup = active;
1538 bool Decorator::IsPopupActive() const
1540 return mImpl->mActiveCopyPastePopup ;
1543 void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask )
1545 mImpl->mEnabledPopupButtons = enabledButtonsBitMask;
1547 if ( !mImpl->mCopyPastePopup.actor )
1549 mImpl->mCopyPastePopup.actor = TextSelectionPopup::New( &mImpl->mTextSelectionPopupCallbackInterface );
1550 #ifdef DECORATOR_DEBUG
1551 mImpl->mCopyPastePopup.actor.SetName("mCopyPastePopup");
1553 mImpl->mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER );
1554 mImpl->mCopyPastePopup.actor.OnRelayoutSignal().Connect( mImpl, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation
1557 mImpl->mCopyPastePopup.actor.EnableButtons( mImpl->mEnabledPopupButtons );
1560 TextSelectionPopup::Buttons& Decorator::GetEnabledPopupButtons()
1562 return mImpl->mEnabledPopupButtons;
1567 void Decorator::SetScrollThreshold( float threshold )
1569 mImpl->SetScrollThreshold( threshold );
1572 float Decorator::GetScrollThreshold() const
1574 return mImpl->GetScrollThreshold();
1577 void Decorator::SetScrollSpeed( float speed )
1579 mImpl->SetScrollSpeed( speed );
1582 float Decorator::GetScrollSpeed() const
1584 return mImpl->GetScrollSpeed();
1587 void Decorator::NotifyEndOfScroll()
1589 mImpl->NotifyEndOfScroll();
1592 Decorator::~Decorator()
1597 Decorator::Decorator( ControllerInterface& controller,
1598 TextSelectionPopupCallbackInterface& callbackInterface )
1601 mImpl = new Decorator::Impl( controller, callbackInterface );
1606 } // namespace Toolkit