+ return mImpl->mLayoutEngine.GetVerticalAlignment();
+}
+
+void Controller::CalculateTextAlignment( const Size& size )
+{
+ // Get the direction of the first character.
+ const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u );
+
+ Size actualSize = mImpl->mVisualModel->GetActualSize();
+ if( fabsf( actualSize.height ) < Math::MACHINE_EPSILON_1000 )
+ {
+ // Get the line height of the default font.
+ actualSize.height = mImpl->GetDefaultFontLineHeight();
+ }
+
+ // If the first paragraph is right to left swap ALIGN_BEGIN and ALIGN_END;
+ LayoutEngine::HorizontalAlignment horizontalAlignment = mImpl->mLayoutEngine.GetHorizontalAlignment();
+ if( firstParagraphDirection &&
+ ( LayoutEngine::HORIZONTAL_ALIGN_CENTER != horizontalAlignment ) )
+ {
+ if( LayoutEngine::HORIZONTAL_ALIGN_BEGIN == horizontalAlignment )
+ {
+ horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_END;
+ }
+ else
+ {
+ horizontalAlignment = LayoutEngine::HORIZONTAL_ALIGN_BEGIN;
+ }
+ }
+
+ switch( horizontalAlignment )
+ {
+ case LayoutEngine::HORIZONTAL_ALIGN_BEGIN:
+ {
+ mImpl->mAlignmentOffset.x = 0.f;
+ break;
+ }
+ case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
+ {
+ const int intOffset = static_cast<int>( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment.
+ mImpl->mAlignmentOffset.x = static_cast<float>( intOffset );
+ break;
+ }
+ case LayoutEngine::HORIZONTAL_ALIGN_END:
+ {
+ mImpl->mAlignmentOffset.x = size.width - actualSize.width;
+ break;
+ }
+ }
+
+ const LayoutEngine::VerticalAlignment verticalAlignment = mImpl->mLayoutEngine.GetVerticalAlignment();
+ switch( verticalAlignment )
+ {
+ case LayoutEngine::VERTICAL_ALIGN_TOP:
+ {
+ mImpl->mAlignmentOffset.y = 0.f;
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_CENTER:
+ {
+ const int intOffset = static_cast<int>( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment.
+ mImpl->mAlignmentOffset.y = static_cast<float>( intOffset );
+ break;
+ }
+ case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
+ {
+ mImpl->mAlignmentOffset.y = size.height - actualSize.height;
+ break;
+ }
+ }
+}
+
+LayoutEngine& Controller::GetLayoutEngine()
+{
+ return mImpl->mLayoutEngine;
+}
+
+View& Controller::GetView()
+{
+ return mImpl->mView;
+}
+
+void Controller::KeyboardFocusGainEvent()
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
+
+ if( mImpl->mEventData )
+ {
+ if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
+ ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+ mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
+ }
+
+ if( mImpl->IsShowingPlaceholderText() )
+ {
+ // Show alternative placeholder-text when editing
+ ShowPlaceholderText();
+ }
+
+ mImpl->RequestRelayout();
+ }
+}
+
+void Controller::KeyboardFocusLostEvent()
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
+
+ if( mImpl->mEventData )
+ {
+ if ( EventData::INTERRUPTED != mImpl->mEventData->mState )
+ {
+ mImpl->ChangeState( EventData::INACTIVE );
+
+ if( mImpl->IsShowingPlaceholderText() )
+ {
+ // Revert to regular placeholder-text when not editing
+ ShowPlaceholderText();
+ }
+ }
+ }
+ mImpl->RequestRelayout();
+}
+
+bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
+
+ bool textChanged( false );
+
+ if( mImpl->mEventData &&
+ keyEvent.state == KeyEvent::Down )
+ {
+ int keyCode = keyEvent.keyCode;
+ const std::string& keyString = keyEvent.keyPressed;
+
+ // Pre-process to separate modifying events from non-modifying input events.
+ if( Dali::DALI_KEY_ESCAPE == keyCode )
+ {
+ // Escape key is a special case which causes focus loss
+ KeyboardFocusLostEvent();
+ }
+ else if( Dali::DALI_KEY_CURSOR_LEFT == keyCode ||
+ Dali::DALI_KEY_CURSOR_RIGHT == keyCode ||
+ Dali::DALI_KEY_CURSOR_UP == keyCode ||
+ Dali::DALI_KEY_CURSOR_DOWN == keyCode )
+ {
+ Event event( Event::CURSOR_KEY_EVENT );
+ event.p1.mInt = keyCode;
+ mImpl->mEventData->mEventQueue.push_back( event );
+ }
+ else if( Dali::DALI_KEY_BACKSPACE == keyCode )
+ {
+ textChanged = BackspaceKeyEvent();
+ }
+ else if ( IsKey( keyEvent, Dali::DALI_KEY_POWER ) )
+ {
+ mImpl->ChangeState( EventData::INTERRUPTED ); // State is not INACTIVE as expect to return to edit mode.
+ // Avoids calling the InsertText() method which can delete selected text
+ }
+ else if ( IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
+ IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
+ {
+ mImpl->ChangeState( EventData::INACTIVE );
+ // Menu/Home key behaviour does not allow edit mode to resume like Power key
+ // Avoids calling the InsertText() method which can delete selected text
+ }
+ else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
+ {
+ // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
+ // and a character is typed after the type of a upper case latin character.
+
+ // Do nothing.
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
+
+ // IMF manager is no longer handling key-events
+ mImpl->ClearPreEditFlag();
+
+ InsertText( keyString, COMMIT );
+ textChanged = true;
+ }
+
+ if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
+ ( mImpl->mEventData->mState != EventData::INACTIVE ) )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+ }
+
+ mImpl->RequestRelayout();
+ }
+
+ if( textChanged )
+ {
+ // Do this last since it provides callbacks into application code
+ mImpl->mControlInterface.TextChanged();
+ }
+
+ return false;
+}
+
+void Controller::InsertText( const std::string& text, Controller::InsertType type )
+{
+ bool removedPrevious( false );
+ bool maxLengthReached( false );
+
+ DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
+ this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
+ mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
+
+ // TODO: At the moment the underline runs are only for pre-edit.
+ mImpl->mVisualModel->mUnderlineRuns.Clear();
+
+ Vector<Character> utf32Characters;
+ Length characterCount( 0u );
+
+ // Remove the previous IMF pre-edit (predicitive text)
+ if( mImpl->mEventData &&
+ mImpl->mEventData->mPreEditFlag &&
+ 0 != mImpl->mEventData->mPreEditLength )
+ {
+ CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition;
+
+ removedPrevious = RemoveText( -static_cast<int>(offset), mImpl->mEventData->mPreEditLength );
+
+ mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
+ mImpl->mEventData->mPreEditLength = 0;
+ }
+ else
+ {
+ // Remove the previous Selection
+ removedPrevious = RemoveSelectedText();
+ }
+
+ if( !text.empty() )
+ {
+ // Convert text into UTF-32
+ utf32Characters.Resize( text.size() );
+
+ // This is a bit horrible but std::string returns a (signed) char*
+ const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
+
+ // Transform a text array encoded in utf8 into an array encoded in utf32.
+ // It returns the actual number of characters.
+ characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
+ utf32Characters.Resize( characterCount );
+
+ DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
+ }
+
+ if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
+ {
+ // The placeholder text is no longer needed
+ if( mImpl->IsShowingPlaceholderText() )
+ {
+ ResetText();
+ }
+
+ mImpl->ChangeState( EventData::EDITING );
+
+ // Handle the IMF (predicitive text) state changes
+ if( mImpl->mEventData )
+ {
+ if( COMMIT == type )
+ {
+ // IMF manager is no longer handling key-events
+ mImpl->ClearPreEditFlag();
+ }
+ else // PRE_EDIT
+ {
+ if( !mImpl->mEventData->mPreEditFlag )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state" );
+
+ // Record the start of the pre-edit text
+ mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
+ }
+
+ mImpl->mEventData->mPreEditLength = utf32Characters.Count();
+ mImpl->mEventData->mPreEditFlag = true;
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
+ }
+ }
+
+ const Length numberOfCharactersInModel = mImpl->mLogicalModel->mText.Count();
+
+ // Restrict new text to fit within Maximum characters setting
+ Length maxSizeOfNewText = std::min ( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
+ maxLengthReached = ( characterCount > maxSizeOfNewText );
+
+ // Insert at current cursor position
+ CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
+
+ Vector<Character>& modifyText = mImpl->mLogicalModel->mText;
+
+ if( cursorIndex < numberOfCharactersInModel )
+ {
+ modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
+ }
+ else
+ {
+ modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
+ }
+
+ cursorIndex += maxSizeOfNewText;
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
+ }
+
+ if( 0u == mImpl->mLogicalModel->mText.Count() &&
+ mImpl->IsPlaceholderAvailable() )
+ {
+ // Show place-holder if empty after removing the pre-edit text
+ ShowPlaceholderText();
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ mImpl->ClearPreEditFlag();
+ }
+ else if( removedPrevious ||
+ 0 != utf32Characters.Count() )
+ {
+ // Queue an inserted event
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
+ }
+
+ if( maxLengthReached )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mLogicalModel->mText.Count() );
+
+ mImpl->ResetImfManager();
+
+ // Do this last since it provides callbacks into application code
+ mImpl->mControlInterface.MaxLengthReached();
+ }
+}
+
+bool Controller::RemoveSelectedText()
+{
+ bool textRemoved( false );
+
+ if ( EventData::SELECTING == mImpl->mEventData->mState ||
+ EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
+ {
+ std::string removedString;
+ mImpl->RetrieveSelection( removedString, true );
+
+ if( !removedString.empty() )
+ {
+ textRemoved = true;
+ mImpl->ChangeState( EventData::EDITING );
+ }
+ }
+
+ return textRemoved;
+}
+
+void Controller::TapEvent( unsigned int tapCount, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
+
+ if( NULL != mImpl->mEventData )
+ {
+ if( 1u == tapCount )
+ {
+ if( mImpl->IsShowingRealText() &&
+ EventData::EDITING == mImpl->mEventData->mState )
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
+ }
+ else if( EventData::EDITING_WITH_GRAB_HANDLE != mImpl->mEventData->mState )
+ {
+ // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
+ mImpl->ChangeState( EventData::EDITING );
+ }
+
+ Event event( Event::TAP_EVENT );
+ event.p1.mUint = tapCount;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+
+ mImpl->RequestRelayout();
+ }
+ else if( 2u == tapCount )
+ {
+ if( mImpl->mEventData->mSelectionEnabled &&
+ mImpl->IsShowingRealText() )
+ {
+ SelectEvent( x, y, false );
+ }
+ }
+ }
+
+ // Reset keyboard as tap event has occurred.
+ mImpl->ResetImfManager();
+}
+
+void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
+
+ if( mImpl->mEventData )
+ {
+ Event event( Event::PAN_EVENT );
+ event.p1.mInt = state;
+ event.p2.mFloat = displacement.x;
+ event.p3.mFloat = displacement.y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+
+ mImpl->RequestRelayout();
+ }
+}
+
+void Controller::LongPressEvent( Gesture::State state, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
+
+ if ( mImpl->IsShowingPlaceholderText() || mImpl->mLogicalModel->mText.Count() == 0u )
+ {
+ if ( mImpl->mEventData )
+ {
+ Event event( Event::LONG_PRESS_EVENT );
+ event.p1.mInt = state;
+ mImpl->mEventData->mEventQueue.push_back( event );
+ mImpl->RequestRelayout();
+ }
+ }
+ else if( mImpl->mEventData )
+ {
+ SelectEvent( x, y, false );
+ }
+}
+
+void Controller::SelectEvent( float x, float y, bool selectAll )
+{
+ if( mImpl->mEventData )
+ {
+ if ( mImpl->mEventData->mState == EventData::SELECTING )
+ {
+ mImpl->ChangeState( EventData::SELECTION_CHANGED );
+ }
+ else
+ {
+ mImpl->ChangeState( EventData::SELECTING );
+ }
+
+ if( selectAll )
+ {
+ Event event( Event::SELECT_ALL );
+ mImpl->mEventData->mEventQueue.push_back( event );
+ }
+ else
+ {
+ Event event( Event::SELECT );
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+ mImpl->mEventData->mEventQueue.push_back( event );
+ }
+
+ mImpl->RequestRelayout();
+ }
+}
+
+void Controller::GetTargetSize( Vector2& targetSize )
+{
+ targetSize = mImpl->mVisualModel->mControlSize;
+}
+
+void Controller::AddDecoration( Actor& actor, bool needsClipping )
+{
+ mImpl->mControlInterface.AddDecoration( actor, needsClipping );
+}
+
+void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
+
+ if( mImpl->mEventData )
+ {
+ switch( handleType )
+ {
+ case GRAB_HANDLE:
+ {
+ Event event( Event::GRAB_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case LEFT_SELECTION_HANDLE:
+ {
+ Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case RIGHT_SELECTION_HANDLE:
+ {
+ Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
+ event.p1.mUint = state;
+ event.p2.mFloat = x;
+ event.p3.mFloat = y;
+
+ mImpl->mEventData->mEventQueue.push_back( event );
+ break;
+ }
+ case LEFT_SELECTION_HANDLE_MARKER:
+ case RIGHT_SELECTION_HANDLE_MARKER:
+ {
+ // Markers do not move the handles.
+ break;
+ }
+ case HANDLE_TYPE_COUNT:
+ {
+ DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
+ }
+ }
+
+ mImpl->RequestRelayout();
+ }
+}
+
+void Controller::PasteText( const std::string& stringToPaste )
+{
+ InsertText( stringToPaste, Text::Controller::COMMIT );
+ mImpl->ChangeState( EventData::EDITING );
+ mImpl->RequestRelayout();
+}
+
+void Controller::PasteClipboardItemEvent()
+{
+ ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
+ std::string stringToPaste( notifier.GetContent() );
+ PasteText( stringToPaste );
+}
+
+void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
+{
+ if( NULL == mImpl->mEventData )
+ {
+ return;
+ }
+
+ switch( button )
+ {
+ case Toolkit::TextSelectionPopup::CUT:
+ {
+ mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ if( 0u != mImpl->mLogicalModel->mText.Count() ||
+ !mImpl->IsPlaceholderAvailable() )
+ {
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+ }
+ else
+ {
+ ShowPlaceholderText();
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ }
+ mImpl->RequestRelayout();
+ mImpl->mControlInterface.TextChanged();
+ break;
+ }
+ case Toolkit::TextSelectionPopup::COPY:
+ {
+ mImpl->SendSelectionToClipboard( false ); // Text not modified
+ mImpl->RequestRelayout(); // Handles, Selection Highlight, Popup
+ break;
+ }
+ case Toolkit::TextSelectionPopup::PASTE:
+ {
+ std::string stringToPaste("");
+ mImpl->GetTextFromClipboard( 0, stringToPaste ); // Paste latest item from system clipboard
+ PasteText( stringToPaste );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::SELECT:
+ {
+ const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
+
+ if( mImpl->mEventData->mSelectionEnabled )
+ {
+ // Creates a SELECT event.
+ SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
+ }
+ break;
+ }
+ case Toolkit::TextSelectionPopup::SELECT_ALL:
+ {
+ // Creates a SELECT_ALL event
+ SelectEvent( 0.f, 0.f, true );
+ break;
+ }
+ case Toolkit::TextSelectionPopup::CLIPBOARD:
+ {
+ mImpl->ShowClipboard();
+ break;
+ }
+ case Toolkit::TextSelectionPopup::NONE:
+ {
+ // Nothing to do.
+ break;
+ }
+ }
+}
+
+ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
+{
+ bool update( false );
+ bool requestRelayout = false;
+
+ std::string text;
+ unsigned int cursorPosition( 0 );
+
+ switch ( imfEvent.eventName )
+ {
+ case ImfManager::COMMIT:
+ {
+ InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
+ requestRelayout = true;
+ break;
+ }
+ case ImfManager::PREEDIT:
+ {
+ InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
+ update = true;
+ requestRelayout = true;
+ break;
+ }
+ case ImfManager::DELETESURROUNDING:
+ {
+ update = RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
+
+ if( update )
+ {
+ if( 0u != mImpl->mLogicalModel->mText.Count() ||
+ !mImpl->IsPlaceholderAvailable() )
+ {
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+ }
+ else
+ {
+ ShowPlaceholderText();
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ }
+ }
+ requestRelayout = true;
+ break;
+ }
+ case ImfManager::GETSURROUNDING:
+ {
+ GetText( text );
+ cursorPosition = GetLogicalCursorPosition();
+
+ imfManager.SetSurroundingText( text );
+ imfManager.SetCursorPosition( cursorPosition );
+ break;
+ }
+ case ImfManager::VOID:
+ {
+ // do nothing
+ break;
+ }
+ } // end switch
+
+ if( ImfManager::GETSURROUNDING != imfEvent.eventName )
+ {
+ GetText( text );
+ cursorPosition = GetLogicalCursorPosition();
+ }
+
+ if( requestRelayout )
+ {
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->RequestRelayout();
+
+ // Do this last since it provides callbacks into application code
+ mImpl->mControlInterface.TextChanged();
+ }
+
+ ImfManager::ImfCallbackData callbackData( update, cursorPosition, text, false );
+
+ return callbackData;
+}
+
+Controller::~Controller()
+{
+ delete mImpl;
+}
+
+bool Controller::BackspaceKeyEvent()
+{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
+
+ // IMF manager is no longer handling key-events
+ mImpl->ClearPreEditFlag();
+
+ bool removed( false );
+
+ if ( EventData::SELECTING == mImpl->mEventData->mState ||
+ EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
+ {
+ removed = RemoveSelectedText();
+ }
+ else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
+ {
+ // Remove the character before the current cursor position
+ removed = RemoveText( -1, 1 );
+ }
+
+ if( removed )
+ {
+ if( 0u != mImpl->mLogicalModel->mText.Count() ||
+ !mImpl->IsPlaceholderAvailable() )
+ {
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+ }
+ else
+ {
+ ShowPlaceholderText();
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ }
+ }
+
+ return removed;
+}
+
+void Controller::ShowPlaceholderText()
+{
+ if( mImpl->IsPlaceholderAvailable() )
+ {
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
+
+ mImpl->mEventData->mIsShowingPlaceholderText = true;
+
+ // Disable handles when showing place-holder text
+ mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+
+ const char* text( NULL );
+ size_t size( 0 );
+
+ // TODO - Switch placeholder text styles when changing state
+ if( EventData::INACTIVE != mImpl->mEventData->mState &&
+ 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() )
+ {
+ text = mImpl->mEventData->mPlaceholderTextActive.c_str();
+ size = mImpl->mEventData->mPlaceholderTextActive.size();
+ }
+ else
+ {
+ text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
+ size = mImpl->mEventData->mPlaceholderTextInactive.size();
+ }
+
+ // Reset model for showing placeholder.
+ mImpl->mLogicalModel->mText.Clear();
+ ClearModelData();
+ mImpl->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
+
+ // Convert text into UTF-32
+ Vector<Character>& utf32Characters = mImpl->mLogicalModel->mText;
+ utf32Characters.Resize( size );
+
+ // This is a bit horrible but std::string returns a (signed) char*
+ const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
+
+ // Transform a text array encoded in utf8 into an array encoded in utf32.
+ // It returns the actual number of characters.
+ Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
+ utf32Characters.Resize( characterCount );
+
+ // Reset the cursor position
+ mImpl->mEventData->mPrimaryCursorPosition = 0;
+
+ // The natural size needs to be re-calculated.
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Apply modifications to the model
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+
+ // Update the rest of the model during size negotiation
+ mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
+ }
+}
+
+void Controller::ClearModelData()
+{
+ // n.b. This does not Clear the mText from mLogicalModel
+ mImpl->mLogicalModel->mScriptRuns.Clear();
+ mImpl->mLogicalModel->mFontRuns.Clear();
+ mImpl->mLogicalModel->mLineBreakInfo.Clear();
+ mImpl->mLogicalModel->mWordBreakInfo.Clear();
+ mImpl->mLogicalModel->mBidirectionalParagraphInfo.Clear();
+ mImpl->mLogicalModel->mCharacterDirections.Clear();
+ mImpl->mLogicalModel->mBidirectionalLineInfo.Clear();
+ mImpl->mLogicalModel->mLogicalToVisualMap.Clear();
+ mImpl->mLogicalModel->mVisualToLogicalMap.Clear();
+ mImpl->mVisualModel->mGlyphs.Clear();
+ mImpl->mVisualModel->mGlyphsToCharacters.Clear();
+ mImpl->mVisualModel->mCharactersToGlyph.Clear();
+ mImpl->mVisualModel->mCharactersPerGlyph.Clear();
+ mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
+ mImpl->mVisualModel->mGlyphPositions.Clear();
+ mImpl->mVisualModel->mLines.Clear();
+ mImpl->mVisualModel->ClearCaches();
+}
+
+void Controller::ClearFontData()
+{
+ mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
+ mImpl->mLogicalModel->mFontRuns.Clear();
+ mImpl->mVisualModel->mGlyphs.Clear();
+ mImpl->mVisualModel->mGlyphsToCharacters.Clear();
+ mImpl->mVisualModel->mCharactersToGlyph.Clear();
+ mImpl->mVisualModel->mCharactersPerGlyph.Clear();
+ mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
+ mImpl->mVisualModel->mGlyphPositions.Clear();
+ mImpl->mVisualModel->mLines.Clear();
+ mImpl->mVisualModel->ClearCaches();