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>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/devel-api/actors/mesh-actor.h>
28 #include <dali/public-api/animation/constraint.h>
29 #include <dali/public-api/common/constants.h>
30 #include <dali/public-api/common/stage.h>
31 #include <dali/public-api/events/tap-gesture.h>
32 #include <dali/public-api/events/tap-gesture-detector.h>
33 #include <dali/public-api/events/touch-event.h>
34 #include <dali/public-api/events/pan-gesture.h>
35 #include <dali/public-api/events/pan-gesture-detector.h>
36 #include <dali/devel-api/geometry/mesh.h>
37 #include <dali/devel-api/geometry/mesh-data.h>
38 #include <dali/public-api/images/resource-image.h>
39 #include <dali/public-api/math/rect.h>
40 #include <dali/public-api/math/vector2.h>
41 #include <dali/public-api/math/vector4.h>
42 #include <dali/public-api/object/property-notification.h>
43 #include <dali/public-api/signals/connection-tracker.h>
46 #include <dali-toolkit/public-api/controls/control.h>
47 #include <dali-toolkit/public-api/controls/control-impl.h>
48 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
49 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
50 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
51 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
54 #define DECORATOR_DEBUG
64 #ifdef DECORATOR_DEBUG
65 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
76 const char* DEFAULT_GRAB_HANDLE_IMAGE_RELEASED( DALI_IMAGE_DIR "insertpoint-icon.png" );
77 const char* DEFAULT_GRAB_HANDLE_IMAGE_PRESSED( DALI_IMAGE_DIR "insertpoint-icon-pressed.png" );
78 const char* DEFAULT_SELECTION_HANDLE_ONE_RELEASED( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
79 const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
80 const char* DEFAULT_SELECTION_HANDLE_TWO_RELEASED( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
81 const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
83 const int DEFAULT_POPUP_OFFSET( -100.0f ); // Vertical offset of Popup from cursor or handles position.
85 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f );
86 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
88 const Dali::Vector4 LIGHT_BLUE( (0xb2 / 255.0f), (0xeb / 255.0f), (0xf2 / 255.0f), 0.5f ); // The text highlight color.
90 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
91 const float TO_MILLISECONDS = 1000.f;
92 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
94 const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
96 const unsigned int SCROLL_TICK_INTERVAL = 50u;
98 const float SCROLL_THRESHOLD = 10.f;
99 const float SCROLL_SPEED = 300.f;
100 const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
103 * structure to hold coordinates of each quad, which will make up the mesh.
105 struct QuadCoordinates
108 * Default constructor
116 * @param[in] x1 left co-ordinate
117 * @param[in] y1 top co-ordinate
118 * @param[in] x2 right co-ordinate
119 * @param[in] y2 bottom co-ordinate
121 QuadCoordinates(float x1, float y1, float x2, float y2)
127 Dali::Vector2 min; ///< top-left (minimum) position of quad
128 Dali::Vector2 max; ///< bottom-right (maximum) position of quad
131 typedef std::vector<QuadCoordinates> QuadContainer;
134 * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
135 * @param[in] boundingRectangle local bounding
136 * @param[out] Vector4 World coordinate bounding Box.
138 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
140 // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
141 Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
143 const float originX = boundingRectangle.x - 0.5f * stageSize.width;
144 const float originY = boundingRectangle.y - 0.5f * stageSize.height;
146 boundingBox = Dali::Vector4( originX,
148 originX + boundingRectangle.width,
149 originY + boundingRectangle.height );
153 } // end of namespace
164 struct Decorator::Impl : public ConnectionTracker
178 : color( Dali::Color::BLACK ),
180 cursorHeight( 0.0f ),
196 grabDisplacementX( 0.f ),
197 grabDisplacementY( 0.f ),
209 float lineHeight; ///< Not the handle height
210 float grabDisplacementX;
211 float grabDisplacementY;
222 offset( DEFAULT_POPUP_OFFSET )
226 TextSelectionPopup actor;
231 Impl( ControllerInterface& controller,
232 TextSelectionPopupCallbackInterface& callbackInterface )
233 : mController( controller ),
234 mEnabledPopupButtons( TextSelectionPopup::NONE ),
235 mTextSelectionPopupCallbackInterface( callbackInterface ),
236 mBoundingBox( Rect<int>() ),
237 mHighlightColor( LIGHT_BLUE ),
238 mActiveCursor( ACTIVE_CURSOR_NONE ),
239 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
240 mCursorBlinkDuration( 0.0f ),
241 mHandleScrolling( HANDLE_TYPE_COUNT ),
242 mScrollDirection( SCROLL_NONE ),
243 mScrollThreshold( SCROLL_THRESHOLD ),
244 mScrollSpeed( SCROLL_SPEED ),
245 mScrollDistance( SCROLL_DISTANCE ),
246 mActiveCopyPastePopup( false ),
247 mCursorBlinkStatus( true ),
248 mPrimaryCursorVisible( false ),
249 mSecondaryCursorVisible( false ),
250 mSwapSelectionHandles( false )
255 * Relayout of the decorations owned by the decorator.
256 * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
258 void Relayout( const Vector2& size )
260 // TODO - Remove this if nothing is active
263 // Show or hide the cursors
267 const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
268 mPrimaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
269 if( mPrimaryCursorVisible )
271 Vector2 position = cursor.position;
272 if( GRAB_HANDLE == mHandleScrolling )
274 if( mScrollDirection == SCROLL_RIGHT )
280 position.x = size.width;
284 mPrimaryCursor.SetPosition( position.x,
286 mPrimaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
288 mPrimaryCursor.SetVisible( mPrimaryCursorVisible );
290 if( mSecondaryCursor )
292 const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
293 mSecondaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
294 if( mSecondaryCursorVisible )
296 mSecondaryCursor.SetPosition( cursor.position.x,
298 mSecondaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
300 mSecondaryCursor.SetVisible( mSecondaryCursorVisible );
303 // Show or hide the grab handle
304 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
305 if( grabHandle.active )
307 Vector2 position = grabHandle.position;
309 if( GRAB_HANDLE == mHandleScrolling )
311 if( mScrollDirection == SCROLL_RIGHT )
317 position.x = size.width;
321 const bool isVisible = ( position.x <= size.width ) && ( position.x >= 0.f );
329 grabHandle.actor.SetPosition( position.x,
330 position.y + grabHandle.lineHeight );
332 grabHandle.actor.SetVisible( isVisible );
334 else if( grabHandle.actor )
336 UnparentAndReset( grabHandle.actor );
339 // Show or hide the selection handles/highlight
340 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
341 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
342 if( primary.active || secondary.active )
344 Vector2 primaryPosition = primary.position;
345 Vector2 secondaryPosition = secondary.position;
347 if( LEFT_SELECTION_HANDLE == mHandleScrolling )
349 if( mScrollDirection == SCROLL_RIGHT )
351 primaryPosition.x = 0.f;
355 primaryPosition.x = size.width;
358 else if( RIGHT_SELECTION_HANDLE == mHandleScrolling )
360 if( mScrollDirection == SCROLL_RIGHT )
362 secondaryPosition.x = 0.f;
366 secondaryPosition.x = size.width;
370 const bool isPrimaryVisible = ( primaryPosition.x <= size.width ) && ( primaryPosition.x >= 0.f );
371 const bool isSecondaryVisible = ( secondaryPosition.x <= size.width ) && ( secondaryPosition.x >= 0.f );
373 if( isPrimaryVisible || isSecondaryVisible )
377 CreateSelectionHandles();
379 if( isPrimaryVisible )
381 primary.actor.SetPosition( primaryPosition.x,
382 primaryPosition.y + primary.lineHeight );
385 if( isSecondaryVisible )
387 secondary.actor.SetPosition( secondaryPosition.x,
388 secondaryPosition.y + secondary.lineHeight );
391 primary.actor.SetVisible( isPrimaryVisible );
392 secondary.actor.SetVisible( isSecondaryVisible );
399 UnparentAndReset( primary.actor );
400 UnparentAndReset( secondary.actor );
401 UnparentAndReset( mHighlightMeshActor );
404 if ( mActiveCopyPastePopup )
406 // todo Swap UnparentAndReset for DeterminePositionPopup() if mCopyPastePopup.actor valid Once the issue with the labels disappearing is fixed.
407 UnparentAndReset( mCopyPastePopup.actor );
408 if ( !mCopyPastePopup.actor )
410 mCopyPastePopup.actor = TextSelectionPopup::New( mEnabledPopupButtons, &mTextSelectionPopupCallbackInterface );
411 #ifdef DECORATOR_DEBUG
412 mCopyPastePopup.actor.SetName("mCopyPastePopup");
414 mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER );
415 mCopyPastePopup.actor.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation
416 mActiveLayer.Add ( mCopyPastePopup.actor );
421 if ( mCopyPastePopup.actor )
423 UnparentAndReset( mCopyPastePopup.actor );
428 void UpdatePositions( const Vector2& scrollOffset )
430 mCursor[PRIMARY_CURSOR].position += scrollOffset;
431 mCursor[SECONDARY_CURSOR].position += scrollOffset;
432 mHandle[ GRAB_HANDLE ].position += scrollOffset;
433 mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset;
434 mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset;
435 mHighlightPosition += scrollOffset;
438 void DeterminePositionPopup()
440 if ( !mActiveCopyPastePopup )
445 if ( mHandle[LEFT_SELECTION_HANDLE].active || mHandle[RIGHT_SELECTION_HANDLE].active )
447 float minHandleXPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
448 float maxHandleXPosition = std::max ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
450 float minHandleYPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.y, mHandle[RIGHT_SELECTION_HANDLE].position.y );
452 mCopyPastePopup.position.x = minHandleXPosition + ( ( maxHandleXPosition - minHandleXPosition ) *0.5f );
453 mCopyPastePopup.position.y = minHandleYPosition + mCopyPastePopup.offset;
457 mCopyPastePopup.position = Vector3( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f ); //todo 100 to be an offset Property
460 Vector3 popupSize = Vector3( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
462 GetConstrainedPopupPosition( mCopyPastePopup.position, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
464 SetUpPopupPositionNotifications();
466 mCopyPastePopup.actor.SetPosition( mCopyPastePopup.position );
469 void PopupRelayoutComplete( Actor actor )
471 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
472 mCopyPastePopup.actor.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopupRelayoutComplete );
474 DeterminePositionPopup();
477 void CreateCursor( ImageActor& cursor, const Vector4& color )
479 cursor = CreateSolidColorActor( color );
480 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
481 cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
484 // Add or Remove cursor(s) from parent
487 if( mActiveCursor == ACTIVE_CURSOR_NONE )
489 UnparentAndReset( mPrimaryCursor );
490 UnparentAndReset( mSecondaryCursor );
494 /* Create Primary and or Secondary Cursor(s) if active and add to parent */
495 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
496 mActiveCursor == ACTIVE_CURSOR_BOTH )
498 if ( !mPrimaryCursor )
500 CreateCursor( mPrimaryCursor, mCursor[PRIMARY_CURSOR].color );
501 #ifdef DECORATOR_DEBUG
502 mPrimaryCursor.SetName( "PrimaryCursorActor" );
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" );
516 mActiveLayer.Add( mSecondaryCursor );
521 UnparentAndReset( mSecondaryCursor );
526 bool OnCursorBlinkTimerTick()
529 if ( mPrimaryCursor )
531 mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
533 if ( mSecondaryCursor )
535 mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
538 mCursorBlinkStatus = !mCursorBlinkStatus;
543 void SetupTouchEvents()
547 mTapDetector = TapGestureDetector::New();
548 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
551 if ( !mPanGestureDetector )
553 mPanGestureDetector = PanGestureDetector::New();
554 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
558 void CreateActiveLayer()
562 mActiveLayer = Layer::New();
563 #ifdef DECORATOR_DEBUG
564 mActiveLayer.SetName ( "ActiveLayerActor" );
567 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
568 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
569 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
571 // Add the active layer telling the controller it doesn't need clipping.
572 mController.AddDecoration( mActiveLayer, false );
575 mActiveLayer.RaiseToTop();
578 void CreateGrabHandle()
580 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
581 if( !grabHandle.actor )
583 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
585 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_RELEASED );
587 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] )
589 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_PRESSED );
592 grabHandle.actor = ImageActor::New( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
593 grabHandle.actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
594 grabHandle.actor.SetDrawMode( DrawMode::OVERLAY );
595 // Area that Grab handle responds to, larger than actual handle so easier to move
596 #ifdef DECORATOR_DEBUG
597 grabHandle.actor.SetName( "GrabHandleActor" );
598 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
600 grabHandle.grabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
601 grabHandle.grabArea.SetName( "GrabArea" );
605 grabHandle.grabArea = Actor::New();
606 grabHandle.grabArea.SetName( "GrabArea" );
609 grabHandle.grabArea = Actor::New();
612 grabHandle.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
613 grabHandle.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
614 grabHandle.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
615 grabHandle.grabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
616 grabHandle.actor.Add( grabHandle.grabArea );
618 grabHandle.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnGrabHandleTouched );
619 mTapDetector.Attach( grabHandle.grabArea );
620 mPanGestureDetector.Attach( grabHandle.grabArea );
622 mActiveLayer.Add( grabHandle.actor );
626 void CreateSelectionHandles()
628 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
631 if( !mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
633 mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE_RELEASED );
635 if( !mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] )
637 mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE_PRESSED );
640 primary.actor = ImageActor::New( mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
641 #ifdef DECORATOR_DEBUG
642 primary.actor.SetName("SelectionHandleOne");
644 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
645 primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
646 primary.flipped = false;
648 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
649 #ifdef DECORATOR_DEBUG
650 primary.grabArea.SetName("SelectionHandleOneGrabArea");
652 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
653 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
654 primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
656 mTapDetector.Attach( primary.grabArea );
657 mPanGestureDetector.Attach( primary.grabArea );
658 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
660 primary.actor.Add( primary.grabArea );
661 mActiveLayer.Add( primary.actor );
664 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
665 if( !secondary.actor )
667 if( !mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
669 mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO_RELEASED );
671 if( !mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] )
673 mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO_PRESSED );
676 secondary.actor = ImageActor::New( mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
677 #ifdef DECORATOR_DEBUG
678 secondary.actor.SetName("SelectionHandleTwo");
680 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
681 secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
682 secondary.flipped = false;
684 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
685 #ifdef DECORATOR_DEBUG
686 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
688 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
689 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
690 secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
692 mTapDetector.Attach( secondary.grabArea );
693 mPanGestureDetector.Attach( secondary.grabArea );
694 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
696 secondary.actor.Add( secondary.grabArea );
697 mActiveLayer.Add( secondary.actor );
701 void CreateHighlight()
703 if ( !mHighlightMeshActor )
705 mHighlightMaterial = Material::New( "HighlightMaterial" );
706 mHighlightMaterial.SetDiffuseColor( mHighlightColor );
708 mHighlightMeshData.SetMaterial( mHighlightMaterial );
709 mHighlightMeshData.SetHasNormals( true );
711 mHighlightMesh = Mesh::New( mHighlightMeshData );
713 mHighlightMeshActor = MeshActor::New( mHighlightMesh );
714 #ifdef DECORATOR_DEBUG
715 mHighlightMeshActor.SetName( "HighlightMeshActor" );
717 mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
719 // Add the highlight box telling the controller it needs clipping.
720 mController.AddDecoration( mHighlightMeshActor, true );
723 mHighlightMeshActor.SetPosition( mHighlightPosition.x, mHighlightPosition.y, DISPLAYED_HIGHLIGHT_Z_OFFSET );
726 void UpdateHighlight()
728 // Construct a Mesh with a texture to be used as the highlight 'box' for selected text
730 // Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
732 // [ TOP ] [ TOP ] [TOP ] [ TOP ] [ TOP ] [ TOP ]
733 // [ MIDDLE ] [BOTTOM] [BOTTOM] [ MIDDLE ] [ MIDDLE ]
734 // [ BOTTOM] [ MIDDLE ] [ MIDDLE ]
735 // [BOTTOM] [ MIDDLE ]
738 // Each quad is created as 2 triangles.
739 // Middle is just 1 quad regardless of its size.
753 if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
755 MeshData::VertexContainer vertices;
756 Dali::MeshData::FaceIndices faceIndices;
758 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
759 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
761 // vertex position defaults to (0 0 0)
762 MeshData::Vertex vertex;
763 // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
766 for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
768 // Add each quad geometry (a sub-selection) to the mesh data.
778 QuadCoordinates& quad = *iter;
780 vertex.x = quad.min.x;
781 vertex.y = quad.min.y;
782 vertices.push_back( vertex );
785 vertex.x = quad.max.x;
786 vertex.y = quad.min.y;
787 vertices.push_back( vertex );
790 vertex.x = quad.min.x;
791 vertex.y = quad.max.y;
792 vertices.push_back( vertex );
794 // bottom-right (v+3)
795 vertex.x = quad.max.x;
796 vertex.y = quad.max.y;
797 vertices.push_back( vertex );
799 // triangle A (3, 1, 0)
800 faceIndices.push_back( v + 3 );
801 faceIndices.push_back( v + 1 );
802 faceIndices.push_back( v );
804 // triangle B (0, 2, 3)
805 faceIndices.push_back( v );
806 faceIndices.push_back( v + 2 );
807 faceIndices.push_back( v + 3 );
809 mHighlightMeshData.SetFaceIndices( faceIndices );
812 BoneContainer bones(0); // passed empty as bones not required
813 mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
814 mHighlightMesh.UpdateMeshData( mHighlightMeshData );
818 void OnTap( Actor actor, const TapGesture& tap )
820 if( actor == mHandle[GRAB_HANDLE].actor )
826 void DoPan( HandleImpl& handle, HandleType type, const PanGesture& gesture )
828 if( Gesture::Started == gesture.state )
830 handle.grabDisplacementX = handle.grabDisplacementY = 0;
833 handle.grabDisplacementX += gesture.displacement.x;
834 handle.grabDisplacementY += gesture.displacement.y;
836 const float x = handle.position.x + handle.grabDisplacementX;
837 const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
839 if( Gesture::Started == gesture.state ||
840 Gesture::Continuing == gesture.state )
843 mController.GetTargetSize( targetSize );
845 if( x < mScrollThreshold )
847 mScrollDirection = SCROLL_RIGHT;
848 mHandleScrolling = type;
851 else if( x > targetSize.width - mScrollThreshold )
853 mScrollDirection = SCROLL_LEFT;
854 mHandleScrolling = type;
859 mHandleScrolling = HANDLE_TYPE_COUNT;
861 mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
864 else if( Gesture::Finished == gesture.state ||
865 Gesture::Cancelled == gesture.state )
867 if( mScrollTimer && mScrollTimer.IsRunning() )
869 mHandleScrolling = HANDLE_TYPE_COUNT;
871 mController.DecorationEvent( type, HANDLE_STOP_SCROLLING, x, y );
875 mController.DecorationEvent( type, HANDLE_RELEASED, x, y );
878 if( GRAB_HANDLE == type )
880 handle.actor.SetImage( mHandleImages[type][HANDLE_IMAGE_RELEASED] );
884 HandleType selectionHandleType = type;
886 if( mSwapSelectionHandles != handle.flipped )
888 selectionHandleType = ( LEFT_SELECTION_HANDLE == type ) ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE;
891 handle.actor.SetImage( mHandleImages[selectionHandleType][HANDLE_IMAGE_RELEASED] );
893 handle.pressed = false;
897 void OnPan( Actor actor, const PanGesture& gesture )
899 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
900 HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
901 HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
903 if( actor == grabHandle.grabArea )
905 DoPan( grabHandle, GRAB_HANDLE, gesture );
907 else if( actor == primarySelectionHandle.grabArea )
909 DoPan( primarySelectionHandle, LEFT_SELECTION_HANDLE, gesture );
911 else if( actor == secondarySelectionHandle.grabArea )
913 DoPan( secondarySelectionHandle, RIGHT_SELECTION_HANDLE, gesture );
917 bool OnGrabHandleTouched( Actor actor, const TouchEvent& event )
919 // Switch between pressed/release grab-handle images
920 if( event.GetPointCount() > 0 &&
921 mHandle[GRAB_HANDLE].actor )
923 const TouchPoint& point = event.GetPoint(0);
925 if( TouchPoint::Down == point.state )
927 mHandle[GRAB_HANDLE].pressed = true;
928 Image imagePressed = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED];
931 mHandle[GRAB_HANDLE].actor.SetImage( imagePressed );
934 else if( TouchPoint::Up == point.state )
936 mHandle[GRAB_HANDLE].pressed = false;
937 Image imageReleased = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED];
940 mHandle[GRAB_HANDLE].actor.SetImage( imageReleased );
945 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
949 bool OnHandleOneTouched( Actor actor, const TouchEvent& event )
951 // Switch between pressed/release selection handle images
952 if( event.GetPointCount() > 0 &&
953 mHandle[LEFT_SELECTION_HANDLE].actor )
955 const TouchPoint& point = event.GetPoint(0);
957 const bool flip = mSwapSelectionHandles != mHandle[LEFT_SELECTION_HANDLE].flipped;
958 if( TouchPoint::Down == point.state )
960 mHandle[LEFT_SELECTION_HANDLE].pressed = true;
961 Image imagePressed = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
964 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imagePressed );
967 else if( TouchPoint::Up == point.state )
969 mHandle[LEFT_SELECTION_HANDLE].pressed = false;
970 Image imageReleased = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
973 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imageReleased );
978 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
982 bool OnHandleTwoTouched( Actor actor, const TouchEvent& event )
984 // Switch between pressed/release selection handle images
985 if( event.GetPointCount() > 0 &&
986 mHandle[RIGHT_SELECTION_HANDLE].actor )
988 const TouchPoint& point = event.GetPoint(0);
990 const bool flip = mSwapSelectionHandles != mHandle[RIGHT_SELECTION_HANDLE].flipped;
991 if( TouchPoint::Down == point.state )
993 Image imagePressed = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
994 mHandle[RIGHT_SELECTION_HANDLE].pressed = true;
997 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1000 else if( TouchPoint::Up == point.state )
1002 Image imageReleased = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1003 mHandle[RIGHT_SELECTION_HANDLE].pressed = false;
1006 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1011 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1017 float AlternatePopUpPositionRelativeToCursor()
1019 float alternativePosition=0.0f;;
1021 if ( mPrimaryCursor ) // Secondary cursor not used for paste
1023 Cursor cursor = PRIMARY_CURSOR;
1024 alternativePosition = mCursor[cursor].position.y;
1027 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
1029 if( mHandle[GRAB_HANDLE].active )
1031 // If grab handle enabled then position pop-up below the grab handle.
1032 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
1033 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
1034 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
1038 alternativePosition += popupHeight;
1041 return alternativePosition;
1044 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
1046 float alternativeYPosition=0.0f;
1047 // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted
1048 // if can't be positioned above, then position below row.
1049 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
1051 mCopyPastePopup.actor.SetY( alternativeYPosition );
1055 void SetUpPopupPositionNotifications( )
1057 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
1059 // Exceeding vertical boundary
1061 Vector4 worldCoordinatesBoundingBox;
1062 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
1064 float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT);
1066 PropertyNotification verticalExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
1067 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight * 0.5f,
1068 worldCoordinatesBoundingBox.w - popupHeight * 0.5f ) );
1070 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
1073 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
1075 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
1077 // Parent must already by added to Stage for these Get calls to work
1078 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
1079 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
1080 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
1081 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
1083 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
1084 Vector4 boundingRectangleWorld;
1085 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
1087 // Calculate distance to move popup (in local space) so fits within the boundary
1088 float xOffSetToKeepWithinBounds = 0.0f;
1089 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
1091 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
1093 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
1095 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
1098 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
1099 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
1101 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
1104 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
1106 // Prevent pixel mis-alignment by rounding down.
1107 requiredPopupPosition.x = static_cast<int>( requiredPopupPosition.x );
1108 requiredPopupPosition.y = static_cast<int>( requiredPopupPosition.y );
1112 void FlipSelectionHandleImages()
1116 CreateSelectionHandles();
1118 HandleImpl& leftHandle = mHandle[LEFT_SELECTION_HANDLE];
1119 HandleImpl& rightHandle = mHandle[RIGHT_SELECTION_HANDLE];
1121 const HandleImageType leftImageType = leftHandle.pressed ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1122 const HandleImageType rightImageType = rightHandle.pressed ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1123 const bool leftFlipped = mSwapSelectionHandles != leftHandle.flipped;
1124 const bool rightFlipped = mSwapSelectionHandles != rightHandle.flipped;
1126 leftHandle.actor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE][leftImageType] );
1128 leftHandle.actor.SetAnchorPoint( leftFlipped ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
1130 rightHandle.actor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE][rightImageType] );
1132 rightHandle.actor.SetAnchorPoint( rightFlipped ? AnchorPoint::TOP_RIGHT : AnchorPoint::TOP_LEFT );
1135 void SetScrollThreshold( float threshold )
1137 mScrollThreshold = threshold;
1140 float GetScrollThreshold() const
1142 return mScrollThreshold;
1145 void SetScrollSpeed( float speed )
1147 mScrollSpeed = speed;
1148 mScrollDistance = speed * SCROLL_TICK_INTERVAL * TO_SECONDS;
1151 float GetScrollSpeed() const
1153 return mScrollSpeed;
1157 * Creates and starts a timer to scroll the text when handles are close to the edges of the text.
1159 * It only starts the timer if it's already created.
1161 void StartScrollTimer()
1165 mScrollTimer = Timer::New( SCROLL_TICK_INTERVAL );
1166 mScrollTimer.TickSignal().Connect( this, &Decorator::Impl::OnScrollTimerTick );
1169 if( !mScrollTimer.IsRunning() )
1171 mScrollTimer.Start();
1176 * Stops the timer used to scroll the text.
1178 void StopScrollTimer()
1182 mScrollTimer.Stop();
1187 * Callback called by the timer used to scroll the text.
1189 * It calculates and sets a new scroll position.
1191 bool OnScrollTimerTick()
1193 if( HANDLE_TYPE_COUNT != mHandleScrolling )
1195 mController.DecorationEvent( mHandleScrolling,
1197 mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
1204 ControllerInterface& mController;
1206 TapGestureDetector mTapDetector;
1207 PanGestureDetector mPanGestureDetector;
1208 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1209 Timer mScrollTimer; ///< Timer used to scroll the text when the grab handle is moved close to the edges.
1211 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1212 ImageActor mPrimaryCursor;
1213 ImageActor mSecondaryCursor;
1214 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1216 PopupImpl mCopyPastePopup;
1217 TextSelectionPopup::Buttons mEnabledPopupButtons; /// Bit mask of currently enabled Popup buttons
1218 TextSelectionPopupCallbackInterface& mTextSelectionPopupCallbackInterface;
1220 Image mHandleImages[HANDLE_TYPE_COUNT][HANDLE_IMAGE_TYPE_COUNT];
1222 Mesh mHighlightMesh; ///< Mesh for highlight
1223 MeshData mHighlightMeshData; ///< Mesh Data for highlight
1224 Material mHighlightMaterial; ///< Material used for highlight
1226 CursorImpl mCursor[CURSOR_COUNT];
1227 HandleImpl mHandle[HANDLE_TYPE_COUNT];
1228 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
1229 Vector2 mHighlightPosition; ///< The position of the highlight actor.
1231 Rect<int> mBoundingBox;
1232 Vector4 mHighlightColor; ///< Color of the highlight
1234 unsigned int mActiveCursor;
1235 unsigned int mCursorBlinkInterval;
1236 float mCursorBlinkDuration;
1237 HandleType mHandleScrolling; ///< The handle which is scrolling.
1238 ScrollDirection mScrollDirection; ///< The direction of the scroll.
1239 float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events.
1240 float mScrollSpeed; ///< The scroll speed in pixels per second.
1241 float mScrollDistance; ///< Distance the text scrolls during a scroll interval.
1242 unsigned int mScrollInterval; ///< Time in milliseconds of a scroll interval.
1244 bool mActiveCopyPastePopup : 1;
1245 bool mCursorBlinkStatus : 1; ///< Flag to switch between blink on and blink off.
1246 bool mPrimaryCursorVisible : 1; ///< Whether the primary cursor is visible.
1247 bool mSecondaryCursorVisible : 1; ///< Whether the secondary cursor is visible.
1248 bool mSwapSelectionHandles : 1; ///< Whether to swap the selection handle images.
1251 DecoratorPtr Decorator::New( ControllerInterface& controller,
1252 TextSelectionPopupCallbackInterface& callbackInterface )
1254 return DecoratorPtr( new Decorator( controller,
1255 callbackInterface ) );
1258 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
1260 mImpl->mBoundingBox = boundingBox;
1263 const Rect<int>& Decorator::GetBoundingBox() const
1265 return mImpl->mBoundingBox;
1268 void Decorator::Relayout( const Vector2& size )
1270 mImpl->Relayout( size );
1273 void Decorator::UpdatePositions( const Vector2& scrollOffset )
1275 mImpl->UpdatePositions( scrollOffset );
1280 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
1282 mImpl->mActiveCursor = activeCursor;
1285 unsigned int Decorator::GetActiveCursor() const
1287 return mImpl->mActiveCursor;
1290 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
1292 mImpl->mCursor[cursor].position.x = x;
1293 mImpl->mCursor[cursor].position.y = y;
1294 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
1295 mImpl->mCursor[cursor].lineHeight = lineHeight;
1298 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
1300 x = mImpl->mCursor[cursor].position.x;
1301 y = mImpl->mCursor[cursor].position.y;
1302 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
1303 lineHeight = mImpl->mCursor[cursor].lineHeight;
1306 const Vector2& Decorator::GetPosition( Cursor cursor ) const
1308 return mImpl->mCursor[cursor].position;
1311 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
1313 mImpl->mCursor[cursor].color = color;
1316 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
1318 return mImpl->mCursor[cursor].color;
1321 void Decorator::StartCursorBlink()
1323 if ( !mImpl->mCursorBlinkTimer )
1325 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
1326 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
1329 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
1331 mImpl->mCursorBlinkTimer.Start();
1335 void Decorator::StopCursorBlink()
1337 if ( mImpl->mCursorBlinkTimer )
1339 mImpl->mCursorBlinkTimer.Stop();
1343 void Decorator::SetCursorBlinkInterval( float seconds )
1345 mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
1348 float Decorator::GetCursorBlinkInterval() const
1350 return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
1353 void Decorator::SetCursorBlinkDuration( float seconds )
1355 mImpl->mCursorBlinkDuration = seconds;
1358 float Decorator::GetCursorBlinkDuration() const
1360 return mImpl->mCursorBlinkDuration;
1365 void Decorator::SetHandleActive( HandleType handleType, bool active )
1367 mImpl->mHandle[handleType].active = active;
1370 bool Decorator::IsHandleActive( HandleType handleType ) const
1372 return mImpl->mHandle[handleType].active ;
1375 void Decorator::SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image )
1377 mImpl->mHandleImages[handleType][handleImageType] = image;
1380 Dali::Image Decorator::GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const
1382 return mImpl->mHandleImages[handleType][handleImageType];
1385 void Decorator::SetPosition( HandleType handleType, float x, float y, float height )
1387 // Adjust grab handle displacement
1388 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1390 handle.grabDisplacementX -= x - handle.position.x;
1391 handle.grabDisplacementY -= y - handle.position.y;
1393 handle.position.x = x;
1394 handle.position.y = y;
1395 handle.lineHeight = height;
1398 void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
1400 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1402 x = handle.position.x;
1403 y = handle.position.y;
1404 height = handle.lineHeight;
1407 const Vector2& Decorator::GetPosition( HandleType handleType ) const
1409 return mImpl->mHandle[handleType].position;
1412 void Decorator::SwapSelectionHandlesEnabled( bool enable )
1414 mImpl->mSwapSelectionHandles = enable;
1416 mImpl->FlipSelectionHandleImages();
1419 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1421 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1424 void Decorator::ClearHighlights()
1426 mImpl->mHighlightQuadList.clear();
1427 mImpl->mHighlightPosition = Vector2::ZERO;
1430 void Decorator::SetHighlightColor( const Vector4& color )
1432 mImpl->mHighlightColor = color;
1435 const Vector4& Decorator::GetHighlightColor() const
1437 return mImpl->mHighlightColor;
1440 void Decorator::SetPopupActive( bool active )
1442 mImpl->mActiveCopyPastePopup = active;
1445 bool Decorator::IsPopupActive() const
1447 return mImpl->mActiveCopyPastePopup ;
1450 void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask )
1452 mImpl->mEnabledPopupButtons = enabledButtonsBitMask;
1455 TextSelectionPopup::Buttons& Decorator::GetEnabledPopupButtons()
1457 return mImpl->mEnabledPopupButtons;
1462 void Decorator::SetScrollThreshold( float threshold )
1464 mImpl->SetScrollThreshold( threshold );
1467 float Decorator::GetScrollThreshold() const
1469 return mImpl->GetScrollThreshold();
1472 void Decorator::SetScrollSpeed( float speed )
1474 mImpl->SetScrollSpeed( speed );
1477 float Decorator::GetScrollSpeed() const
1479 return mImpl->GetScrollSpeed();
1482 Decorator::~Decorator()
1487 Decorator::Decorator( ControllerInterface& controller,
1488 TextSelectionPopupCallbackInterface& callbackInterface )
1491 mImpl = new Decorator::Impl( controller, callbackInterface );
1496 } // namespace Toolkit