+ if( IsShowingPlaceholderText() )
+ {
+ // Do not want to use the place-holder text to set the cursor position.
+
+ // Use the line's height of the font's family set to set the cursor's size.
+ // If there is no font's family set, use the default font.
+ // Use the current alignment to place the cursor at the beginning, center or end of the box.
+
+ float lineHeight = 0.f;
+
+ FontId defaultFontId = 0u;
+ if( NULL == mFontDefaults )
+ {
+ defaultFontId = mFontClient.GetFontId( EMPTY_STRING,
+ EMPTY_STRING );
+ }
+ else
+ {
+ defaultFontId = mFontDefaults->GetFontId( mFontClient );
+ }
+
+ Text::FontMetrics fontMetrics;
+ mFontClient.GetFontMetrics( defaultFontId, fontMetrics );
+
+ lineHeight = fontMetrics.ascender - fontMetrics.descender;
+
+
+ Vector2 cursorPosition;
+
+ switch( mLayoutEngine.GetHorizontalAlignment() )
+ {
+ case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
+ {
+ cursorPosition.x = 1.f;
+ break;
+ }
+ case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
+ {
+ cursorPosition.x = floor( 0.5f * mControlSize.width );
+ break;
+ }
+ case LayoutEngine::HORIZONTAL_ALIGN_END:
+ {
+ cursorPosition.x = mControlSize.width;
+ break;
+ }
+ }
+
+ switch( mLayoutEngine.GetVerticalAlignment() )
+ {
+ case LayoutEngine::VERTICAL_ALIGN_TOP:
+ {
+ cursorPosition.y = 0.f;
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_CENTER:
+ {
+ cursorPosition.y = floorf( 0.5f * ( mControlSize.height - lineHeight ) );
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
+ {
+ cursorPosition.y = mControlSize.height - lineHeight;
+ break;
+ }
+ }
+
+ mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
+ cursorPosition.x,
+ cursorPosition.y,
+ lineHeight,
+ lineHeight );
+ }
+ else
+ {
+ CursorInfo cursorInfo;
+ GetCursorPosition( mEventData->mPrimaryCursorPosition,
+ cursorInfo );
+
+ const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+
+ // Sets the cursor position.
+ mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.primaryCursorHeight,
+ cursorInfo.lineHeight );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Primary cursor position: %f,%f\n", cursorPosition.x, cursorPosition.y );
+
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( GRAB_HANDLE,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.lineHeight );
+
+ if( cursorInfo.isSecondaryCursor )
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_BOTH );
+ mEventData->mDecorator->SetPosition( SECONDARY_CURSOR,
+ cursorInfo.secondaryPosition.x + offset.x,
+ cursorInfo.secondaryPosition.y + offset.y,
+ cursorInfo.secondaryCursorHeight,
+ cursorInfo.lineHeight );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y );
+ }
+ else
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
+ }
+ }
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::UpdateCursorPosition\n" );
+}
+
+void Controller::Impl::UpdateSelectionHandle( HandleType handleType )
+{
+ if( ( LEFT_SELECTION_HANDLE != handleType ) &&
+ ( RIGHT_SELECTION_HANDLE != handleType ) )
+ {
+ return;
+ }
+
+ const bool leftSelectionHandle = LEFT_SELECTION_HANDLE == handleType;
+ const CharacterIndex index = leftSelectionHandle ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
+
+ CursorInfo cursorInfo;
+ GetCursorPosition( index,
+ cursorInfo );
+
+ const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( handleType,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.lineHeight );
+
+ // If selection handle at start of the text and other at end of the text then all text is selected.
+ const CharacterIndex startOfSelection = std::min( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition );
+ const CharacterIndex endOfSelection = std::max ( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition );
+ mEventData->mAllTextSelected = ( startOfSelection == 0 ) && ( endOfSelection == mLogicalModel->mText.Count() );
+}
+
+void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
+{
+ // Clamp between -space & 0 (and the text alignment).
+ if( actualSize.width > mControlSize.width )
+ {
+ const float space = ( actualSize.width - mControlSize.width ) + mAlignmentOffset.x;
+ mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x < -space ) ? -space : mEventData->mScrollPosition.x;
+ mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x > -mAlignmentOffset.x ) ? -mAlignmentOffset.x : mEventData->mScrollPosition.x;
+
+ mEventData->mDecoratorUpdated = true;
+ }
+ else
+ {
+ mEventData->mScrollPosition.x = 0.f;
+ }
+}
+
+void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
+{
+ // Clamp between -space & 0 (and the text alignment).
+ if( actualSize.height > mControlSize.height )
+ {
+ const float space = ( actualSize.height - mControlSize.height ) + mAlignmentOffset.y;
+ mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y < -space ) ? -space : mEventData->mScrollPosition.y;
+ mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y > -mAlignmentOffset.y ) ? -mAlignmentOffset.y : mEventData->mScrollPosition.y;
+
+ mEventData->mDecoratorUpdated = true;
+ }
+ else
+ {
+ mEventData->mScrollPosition.y = 0.f;
+ }
+}
+
+void Controller::Impl::ScrollToMakePositionVisible( const Vector2& position )
+{
+ Vector2 offset;
+ bool updateDecorator = false;
+ if( position.x < 0.f )
+ {
+ offset.x = -position.x;
+ mEventData->mScrollPosition.x += offset.x;
+ updateDecorator = true;
+ }
+ else if( position.x > mControlSize.width )
+ {
+ offset.x = mControlSize.width - position.x;
+ mEventData->mScrollPosition.x += offset.x;
+ updateDecorator = true;
+ }
+
+ if( updateDecorator && mEventData->mDecorator )
+ {
+ mEventData->mDecorator->UpdatePositions( offset );
+ }
+
+ // TODO : calculate the vertical scroll.
+}
+
+void Controller::Impl::ScrollTextToMatchCursor()
+{
+ // Get the current cursor position in decorator coords.
+ const Vector2& currentCursorPosition = mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
+
+ // Calculate the new cursor position.