+void Controller::ResetText()
+{
+ // Reset buffers.
+ mImpl->mLogicalModel->mText.Clear();
+ ClearModelData();
+
+ // We have cleared everything including the placeholder-text
+ mImpl->PlaceholderCleared();
+
+ // The natural size needs to be re-calculated.
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Apply modifications to the model
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+}
+
+void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
+{
+ // Reset the cursor position
+ if( NULL != mImpl->mEventData )
+ {
+ mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
+
+ // Update the cursor if it's in editing mode.
+ if( ( EventData::EDITING == mImpl->mEventData->mState ) ||
+ ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) )
+ {
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ }
+ }
+}
+
+void Controller::ResetScrollPosition()
+{
+ if( NULL != mImpl->mEventData )
+ {
+ // Reset the scroll position.
+ mImpl->mEventData->mScrollPosition = Vector2::ZERO;
+ mImpl->mEventData->mScrollAfterUpdateCursorPosition = true;
+ }
+}
+
+void Controller::TextReplacedEvent()
+{
+ // Reset buffers.
+ ClearModelData();
+
+ // The natural size needs to be re-calculated.
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Apply modifications to the model
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->UpdateModel( ALL_OPERATIONS );
+ mImpl->mOperationsPending = static_cast<OperationsMask>( LAYOUT |
+ ALIGN |
+ UPDATE_ACTUAL_SIZE |
+ REORDER );
+}
+
+void Controller::TextInsertedEvent()
+{
+ DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
+
+ // TODO - Optimize this
+ ClearModelData();
+
+ // The natural size needs to be re-calculated.
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Apply modifications to the model; TODO - Optimize this
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->UpdateModel( ALL_OPERATIONS );
+ mImpl->mOperationsPending = static_cast<OperationsMask>( LAYOUT |
+ ALIGN |
+ UPDATE_ACTUAL_SIZE |
+ REORDER );
+
+ // Queue a cursor reposition event; this must wait until after DoRelayout()
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ mImpl->mEventData->mScrollAfterUpdateCursorPosition = true;
+}
+
+void Controller::TextDeletedEvent()
+{
+ DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
+
+ // TODO - Optimize this
+ ClearModelData();
+
+ // The natural size needs to be re-calculated.
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Apply modifications to the model; TODO - Optimize this
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->UpdateModel( ALL_OPERATIONS );
+ mImpl->mOperationsPending = static_cast<OperationsMask>( LAYOUT |
+ ALIGN |
+ UPDATE_ACTUAL_SIZE |
+ REORDER );
+
+ // Queue a cursor reposition event; this must wait until after DoRelayout()
+ mImpl->mEventData->mScrollAfterDelete = true;
+}
+
+bool Controller::DoRelayout( const Size& size,
+ OperationsMask operationsRequired,
+ Size& layoutSize )
+{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
+ bool viewUpdated( false );
+
+ // Calculate the operations to be done.
+ const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
+
+ if( LAYOUT & operations )
+ {
+ // Some vectors with data needed to layout and reorder may be void
+ // after the first time the text has been laid out.
+ // Fill the vectors again.
+
+ Length numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs();
+
+ if( 0u == numberOfGlyphs )
+ {
+ // Nothing else to do if there is no glyphs.
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
+ return true;
+ }
+
+ Vector<LineBreakInfo>& lineBreakInfo = mImpl->mLogicalModel->mLineBreakInfo;
+ Vector<WordBreakInfo>& wordBreakInfo = mImpl->mLogicalModel->mWordBreakInfo;
+ Vector<CharacterDirection>& characterDirection = mImpl->mLogicalModel->mCharacterDirections;
+ Vector<GlyphInfo>& glyphs = mImpl->mVisualModel->mGlyphs;
+ Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mVisualModel->mGlyphsToCharacters;
+ Vector<Length>& charactersPerGlyph = mImpl->mVisualModel->mCharactersPerGlyph;
+
+ // Set the layout parameters.
+ LayoutParameters layoutParameters( size,
+ mImpl->mLogicalModel->mText.Begin(),
+ lineBreakInfo.Begin(),
+ wordBreakInfo.Begin(),
+ ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
+ numberOfGlyphs,
+ glyphs.Begin(),
+ glyphsToCharactersMap.Begin(),
+ charactersPerGlyph.Begin() );
+
+ // The laid-out lines.
+ // It's not possible to know in how many lines the text is going to be laid-out,
+ // but it can be resized at least with the number of 'paragraphs' to avoid
+ // some re-allocations.
+ Vector<LineRun>& lines = mImpl->mVisualModel->mLines;
+
+ // Delete any previous laid out lines before setting the new ones.
+ lines.Clear();
+
+ // The capacity of the bidirectional paragraph info is the number of paragraphs.
+ lines.Reserve( mImpl->mLogicalModel->mBidirectionalParagraphInfo.Capacity() );
+
+ // Resize the vector of positions to have the same size than the vector of glyphs.
+ Vector<Vector2>& glyphPositions = mImpl->mVisualModel->mGlyphPositions;
+ glyphPositions.Resize( numberOfGlyphs );
+
+ // Update the visual model.
+ viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
+ glyphPositions,
+ lines,
+ layoutSize );
+
+ if( viewUpdated )
+ {
+ // Reorder the lines
+ if( REORDER & operations )
+ {
+ Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mLogicalModel->mBidirectionalParagraphInfo;
+
+ // Check first if there are paragraphs with bidirectional info.
+ if( 0u != bidirectionalInfo.Count() )
+ {
+ // Get the lines
+ const Length numberOfLines = mImpl->mVisualModel->GetNumberOfLines();
+
+ // Reorder the lines.
+ Vector<BidirectionalLineInfoRun> lineBidirectionalInfoRuns;
+ lineBidirectionalInfoRuns.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
+ ReorderLines( bidirectionalInfo,
+ lines,
+ lineBidirectionalInfoRuns );
+
+ // Set the bidirectional info into the model.
+ const Length numberOfBidirectionalInfoRuns = lineBidirectionalInfoRuns.Count();
+ mImpl->mLogicalModel->SetVisualToLogicalMap( lineBidirectionalInfoRuns.Begin(),
+ numberOfBidirectionalInfoRuns );
+
+ // Set the bidirectional info per line into the layout parameters.
+ layoutParameters.lineBidirectionalInfoRunsBuffer = lineBidirectionalInfoRuns.Begin();
+ layoutParameters.numberOfBidirectionalInfoRuns = numberOfBidirectionalInfoRuns;
+
+ // Get the character to glyph conversion table and set into the layout.
+ layoutParameters.charactersToGlyphsBuffer = mImpl->mVisualModel->mCharactersToGlyph.Begin();
+
+ // Get the glyphs per character table and set into the layout.
+ layoutParameters.glyphsPerCharacterBuffer = mImpl->mVisualModel->mGlyphsPerCharacter.Begin();
+
+ // Re-layout the text. Reorder those lines with right to left characters.
+ mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
+ glyphPositions );
+
+ // Free the allocated memory used to store the conversion table in the bidirectional line info run.
+ for( Vector<BidirectionalLineInfoRun>::Iterator it = lineBidirectionalInfoRuns.Begin(),
+ endIt = lineBidirectionalInfoRuns.End();
+ it != endIt;
+ ++it )
+ {
+ BidirectionalLineInfoRun& bidiLineInfo = *it;
+
+ free( bidiLineInfo.visualToLogicalMap );
+ }
+ }
+ } // REORDER
+
+ // Sets the actual size.
+ if( UPDATE_ACTUAL_SIZE & operations )
+ {
+ mImpl->mVisualModel->SetActualSize( layoutSize );
+ }
+ } // view updated
+ }
+ else
+ {
+ layoutSize = mImpl->mVisualModel->GetActualSize();
+ }
+
+ if( ALIGN & operations )
+ {
+ // The laid-out lines.
+ Vector<LineRun>& lines = mImpl->mVisualModel->mLines;
+
+ mImpl->mLayoutEngine.Align( layoutSize,
+ lines );
+
+ viewUpdated = true;
+ }
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
+ return viewUpdated;
+}
+
+void Controller::SetMultiLineEnabled( bool enable )
+{
+ const LayoutEngine::Layout layout = enable ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX;
+
+ if( layout != mImpl->mLayoutEngine.GetLayout() )
+ {
+ // Set the layout type.
+ mImpl->mLayoutEngine.SetLayout( layout );
+
+ // Set the flags to redo the layout operations
+ const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
+ UPDATE_ACTUAL_SIZE |
+ ALIGN |
+ REORDER );
+
+ mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
+
+ mImpl->RequestRelayout();
+ }
+}
+
+bool Controller::IsMultiLineEnabled() const
+{
+ return LayoutEngine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
+}
+
+void Controller::SetHorizontalAlignment( LayoutEngine::HorizontalAlignment alignment )
+{
+ if( alignment != mImpl->mLayoutEngine.GetHorizontalAlignment() )
+ {
+ // Set the alignment.
+ mImpl->mLayoutEngine.SetHorizontalAlignment( alignment );
+
+ // Set the flag to redo the alignment operation.
+ mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
+
+ mImpl->RequestRelayout();
+ }
+}
+
+LayoutEngine::HorizontalAlignment Controller::GetHorizontalAlignment() const
+{
+ return mImpl->mLayoutEngine.GetHorizontalAlignment();
+}
+
+void Controller::SetVerticalAlignment( LayoutEngine::VerticalAlignment alignment )
+{
+ if( alignment != mImpl->mLayoutEngine.GetVerticalAlignment() )
+ {
+ // Set the alignment.
+ mImpl->mLayoutEngine.SetVerticalAlignment( alignment );
+
+ // Set the flag to redo the alignment operation.
+ // TODO : Is not needed re-layout and reorder again but with the current implementation it is.
+ // Im working on a different patch to fix an issue with the alignment. When that patch
+ // is in, this issue can be fixed.
+ const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
+ UPDATE_ACTUAL_SIZE |
+ ALIGN |
+ REORDER );
+
+ mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
+
+ mImpl->RequestRelayout();
+ }
+}
+
+LayoutEngine::VerticalAlignment Controller::GetVerticalAlignment() const
+{
+ return mImpl->mLayoutEngine.GetVerticalAlignment();
+}
+
+void Controller::CalculateTextAlignment( const Size& size )
+{
+ // Get the direction of the first character.
+ const CharacterDirection firstParagraphDirection = mImpl->mLogicalModel->GetCharacterDirection( 0u );
+
+ const Size& actualSize = mImpl->mVisualModel->GetActualSize();
+
+ // 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 )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+
+ 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 )
+ {
+ 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;
+
+ // Hide the grab handle.
+ mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+
+ // 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 )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
+
+ // IMF manager is no longer handling key-events
+ mImpl->ClearPreEditFlag();
+
+ // Remove the character before the current cursor position
+ bool 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;
+ }
+
+ textChanged = true;
+ }
+ }
+ 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;
+ }
+
+ mImpl->ChangeState( EventData::EDITING ); // todo Confirm this is the best place to change the state of
+
+ 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 removedPreEdit( 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 );
+
+ Vector<Character> utf32Characters;
+ Length characterCount( 0u );
+
+ if( ! text.empty() )
+ {
+ // The placeholder text is no longer needed
+ if( mImpl->IsShowingPlaceholderText() )
+ {
+ ResetText();
+ }
+
+ // 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() )
+ {
+ // Handle the IMF (predicitive text) state changes
+ if( mImpl->mEventData )
+ {
+ if( mImpl->mEventData->mPreEditFlag &&
+ 0 != mImpl->mEventData->mPreEditLength )
+ {
+ // Remove previous pre-edit text
+ CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition;
+ removedPreEdit = RemoveText( -static_cast<int>(offset), mImpl->mEventData->mPreEditLength );
+
+ mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
+ mImpl->mEventData->mPreEditLength = 0;
+ }
+
+ 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->GetNumberOfCharacters();
+
+ // 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( removedPreEdit ||
+ 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();
+ }
+}
+
+void Controller::TapEvent( unsigned int tapCount, float x, float y )
+{
+ DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
+
+ if( NULL != mImpl->mEventData )
+ {
+ if( 1u == tapCount )
+ {
+ bool tapDuringEditMode( EventData::EDITING == mImpl->mEventData->mState );
+
+ if( ! mImpl->IsShowingPlaceholderText() &&
+ EventData::EDITING == mImpl->mEventData->mState )
+ {
+ // Grab handle is not shown until a tap is received whilst EDITING
+ if( tapDuringEditMode )
+ {
+ mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
+ }
+ mImpl->mEventData->mDecorator->SetPopupActive( false );
+ }
+
+ mImpl->ChangeState( EventData::EDITING );
+ }
+ else if( mImpl->mEventData->mSelectionEnabled &&
+ ( 2u == tapCount ) )
+ {
+ mImpl->ChangeState( EventData::SELECTING );
+ }
+ }
+
+ // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
+ if( mImpl->mEventData )
+ {
+ 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();
+ }
+
+ // 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::GetTargetSize( Vector2& targetSize )
+{
+ targetSize = mImpl->mControlSize;
+}
+
+void Controller::AddDecoration( Actor& actor )
+{
+ mImpl->mControlInterface.AddDecoration( actor );
+}
+
+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 HANDLE_TYPE_COUNT:
+ {
+ DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
+ }
+ }
+
+ mImpl->RequestRelayout();
+ }
+}
+
+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:
+ {
+ RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
+ 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()