2 * Copyright (c) 2016 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/text-controller.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
29 #include <dali-toolkit/internal/text/bidirectional-support.h>
30 #include <dali-toolkit/internal/text/character-set-conversion.h>
31 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
32 #include <dali-toolkit/internal/text/markup-processor.h>
33 #include <dali-toolkit/internal/text/text-controller-impl.h>
34 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
43 const float MAX_FLOAT = std::numeric_limits<float>::max();
45 const std::string EMPTY_STRING("");
47 float ConvertToEven( float value )
49 int intValue(static_cast<int>( value ));
50 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
65 * @brief Adds a new font description run for the selected text.
67 * The new font parameters are added after the call to this method.
69 * @param[in] eventData The event data pointer.
70 * @param[in] logicalModel The logical model where to add the new font description run.
71 * @param[out] startOfSelectedText Index to the first selected character.
72 * @param[out] lengthOfSelectedText Number of selected characters.
74 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
75 LogicalModelPtr logicalModel,
76 CharacterIndex& startOfSelectedText,
77 Length& lengthOfSelectedText )
79 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
81 // Get start and end position of selection
82 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
83 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
86 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
87 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
89 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
91 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
92 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
94 // Recalculate the selection highlight as the metrics may have changed.
95 eventData->mUpdateLeftSelectionPosition = true;
96 eventData->mUpdateRightSelectionPosition = true;
97 eventData->mUpdateHighlightBox = true;
99 return fontDescriptionRun;
102 // public : Constructor.
104 ControllerPtr Controller::New()
106 return ControllerPtr( new Controller() );
109 ControllerPtr Controller::New( ControlInterface* controlInterface )
111 return ControllerPtr( new Controller( controlInterface ) );
114 ControllerPtr Controller::New( ControlInterface* controlInterface,
115 EditableControlInterface* editableControlInterface )
117 return ControllerPtr( new Controller( controlInterface,
118 editableControlInterface ) );
121 // public : Configure the text controller.
123 void Controller::EnableTextInput( DecoratorPtr decorator )
127 delete mImpl->mEventData;
128 mImpl->mEventData = NULL;
130 // Nothing else to do.
134 if( NULL == mImpl->mEventData )
136 mImpl->mEventData = new EventData( decorator );
140 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
142 // Metrics for bitmap & vector based glyphs are different
143 mImpl->mMetrics->SetGlyphType( glyphType );
145 // Clear the font-specific data
148 mImpl->RequestRelayout();
151 void Controller::SetMarkupProcessorEnabled( bool enable )
153 mImpl->mMarkupProcessorEnabled = enable;
156 bool Controller::IsMarkupProcessorEnabled() const
158 return mImpl->mMarkupProcessorEnabled;
161 void Controller::SetAutoScrollEnabled( bool enable )
163 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
165 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
169 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
170 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
180 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
181 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
188 mImpl->mIsAutoScrollEnabled = enable;
189 mImpl->RequestRelayout();
193 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
194 mImpl->mIsAutoScrollEnabled = false;
198 bool Controller::IsAutoScrollEnabled() const
200 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
202 return mImpl->mIsAutoScrollEnabled;
205 CharacterDirection Controller::GetAutoScrollDirection() const
207 return mImpl->mAutoScrollDirectionRTL;
210 float Controller::GetAutoScrollLineAlignment() const
214 if( mImpl->mModel->mVisualModel &&
215 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
217 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
223 void Controller::SetHorizontalScrollEnabled( bool enable )
225 if( ( NULL != mImpl->mEventData ) &&
226 mImpl->mEventData->mDecorator )
228 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
231 bool Controller::IsHorizontalScrollEnabled() const
233 if( ( NULL != mImpl->mEventData ) &&
234 mImpl->mEventData->mDecorator )
236 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
242 void Controller::SetVerticalScrollEnabled( bool enable )
244 if( ( NULL != mImpl->mEventData ) &&
245 mImpl->mEventData->mDecorator )
247 if( mImpl->mEventData->mDecorator )
249 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
254 bool Controller::IsVerticalScrollEnabled() const
256 if( ( NULL != mImpl->mEventData ) &&
257 mImpl->mEventData->mDecorator )
259 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
265 void Controller::SetSmoothHandlePanEnabled( bool enable )
267 if( ( NULL != mImpl->mEventData ) &&
268 mImpl->mEventData->mDecorator )
270 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
274 bool Controller::IsSmoothHandlePanEnabled() const
276 if( ( NULL != mImpl->mEventData ) &&
277 mImpl->mEventData->mDecorator )
279 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
285 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
287 mImpl->mMaximumNumberOfCharacters = maxCharacters;
290 int Controller::GetMaximumNumberOfCharacters()
292 return mImpl->mMaximumNumberOfCharacters;
295 void Controller::SetEnableCursorBlink( bool enable )
297 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
299 if( NULL != mImpl->mEventData )
301 mImpl->mEventData->mCursorBlinkEnabled = enable;
304 mImpl->mEventData->mDecorator )
306 mImpl->mEventData->mDecorator->StopCursorBlink();
311 bool Controller::GetEnableCursorBlink() const
313 if( NULL != mImpl->mEventData )
315 return mImpl->mEventData->mCursorBlinkEnabled;
321 void Controller::SetMultiLineEnabled( bool enable )
323 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
325 if( layout != mImpl->mLayoutEngine.GetLayout() )
327 // Set the layout type.
328 mImpl->mLayoutEngine.SetLayout( layout );
330 // Set the flags to redo the layout operations
331 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
336 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
338 mImpl->RequestRelayout();
342 bool Controller::IsMultiLineEnabled() const
344 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
347 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
349 if( alignment != mImpl->mModel->mHorizontalAlignment )
351 // Set the alignment.
352 mImpl->mModel->mHorizontalAlignment = alignment;
354 // Set the flag to redo the alignment operation.
355 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
357 mImpl->RequestRelayout();
361 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
363 return mImpl->mModel->mHorizontalAlignment;
366 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
368 if( alignment != mImpl->mModel->mVerticalAlignment )
370 // Set the alignment.
371 mImpl->mModel->mVerticalAlignment = alignment;
373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
375 mImpl->RequestRelayout();
379 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
381 return mImpl->mModel->mVerticalAlignment;
384 void Controller::SetTextElideEnabled( bool enabled )
386 mImpl->mModel->mElideEnabled = enabled;
389 bool Controller::IsTextElideEnabled() const
391 return mImpl->mModel->mElideEnabled;
396 void Controller::SetText( const std::string& text )
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
400 // Reset keyboard as text changed
401 mImpl->ResetImfManager();
403 // Remove the previously set text and style.
409 CharacterIndex lastCursorIndex = 0u;
411 if( NULL != mImpl->mEventData )
413 // If popup shown then hide it by switching to Editing state
414 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
415 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
416 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
417 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
419 mImpl->ChangeState( EventData::EDITING );
425 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
427 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
428 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
430 Length textSize = 0u;
431 const uint8_t* utf8 = NULL;
432 if( mImpl->mMarkupProcessorEnabled )
434 ProcessMarkupString( text, markupProcessData );
435 textSize = markupProcessData.markupProcessedText.size();
437 // This is a bit horrible but std::string returns a (signed) char*
438 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
442 textSize = text.size();
444 // This is a bit horrible but std::string returns a (signed) char*
445 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
448 // Convert text into UTF-32
449 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
450 utf32Characters.Resize( textSize );
452 // Transform a text array encoded in utf8 into an array encoded in utf32.
453 // It returns the actual number of characters.
454 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
455 utf32Characters.Resize( characterCount );
457 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
460 // The characters to be added.
461 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
463 // To reset the cursor position
464 lastCursorIndex = characterCount;
466 // Update the rest of the model during size negotiation
467 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
469 // The natural size needs to be re-calculated.
470 mImpl->mRecalculateNaturalSize = true;
472 // Apply modifications to the model
473 mImpl->mOperationsPending = ALL_OPERATIONS;
477 ShowPlaceholderText();
480 // Resets the cursor position.
481 ResetCursorPosition( lastCursorIndex );
483 // Scrolls the text to make the cursor visible.
484 ResetScrollPosition();
486 mImpl->RequestRelayout();
488 if( NULL != mImpl->mEventData )
490 // Cancel previously queued events
491 mImpl->mEventData->mEventQueue.clear();
494 // Do this last since it provides callbacks into application code.
495 if( NULL != mImpl->mEditableControlInterface )
497 mImpl->mEditableControlInterface->TextChanged();
501 void Controller::GetText( std::string& text ) const
503 if( !mImpl->IsShowingPlaceholderText() )
505 // Retrieves the text string.
506 mImpl->GetText( 0u, text );
510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
514 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
516 if( NULL != mImpl->mEventData )
518 if( PLACEHOLDER_TYPE_INACTIVE == type )
520 mImpl->mEventData->mPlaceholderTextInactive = text;
524 mImpl->mEventData->mPlaceholderTextActive = text;
527 // Update placeholder if there is no text
528 if( mImpl->IsShowingPlaceholderText() ||
529 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
531 ShowPlaceholderText();
536 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
538 if( NULL != mImpl->mEventData )
540 if( PLACEHOLDER_TYPE_INACTIVE == type )
542 text = mImpl->mEventData->mPlaceholderTextInactive;
546 text = mImpl->mEventData->mPlaceholderTextActive;
551 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
555 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
557 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
558 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
562 mImpl->RequestRelayout();
566 // public : Default style & Input style
568 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
570 if( NULL == mImpl->mFontDefaults )
572 mImpl->mFontDefaults = new FontDefaults();
575 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
576 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
577 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
579 // Clear the font-specific data
582 mImpl->RequestRelayout();
585 const std::string& Controller::GetDefaultFontFamily() const
587 if( NULL != mImpl->mFontDefaults )
589 return mImpl->mFontDefaults->mFontDescription.family;
595 void Controller::SetDefaultFontWeight( FontWeight weight )
597 if( NULL == mImpl->mFontDefaults )
599 mImpl->mFontDefaults = new FontDefaults();
602 mImpl->mFontDefaults->mFontDescription.weight = weight;
603 mImpl->mFontDefaults->weightDefined = true;
605 // Clear the font-specific data
608 mImpl->RequestRelayout();
611 bool Controller::IsDefaultFontWeightDefined() const
613 return mImpl->mFontDefaults->weightDefined;
616 FontWeight Controller::GetDefaultFontWeight() const
618 if( NULL != mImpl->mFontDefaults )
620 return mImpl->mFontDefaults->mFontDescription.weight;
623 return TextAbstraction::FontWeight::NORMAL;
626 void Controller::SetDefaultFontWidth( FontWidth width )
628 if( NULL == mImpl->mFontDefaults )
630 mImpl->mFontDefaults = new FontDefaults();
633 mImpl->mFontDefaults->mFontDescription.width = width;
634 mImpl->mFontDefaults->widthDefined = true;
636 // Clear the font-specific data
639 mImpl->RequestRelayout();
642 bool Controller::IsDefaultFontWidthDefined() const
644 return mImpl->mFontDefaults->widthDefined;
647 FontWidth Controller::GetDefaultFontWidth() const
649 if( NULL != mImpl->mFontDefaults )
651 return mImpl->mFontDefaults->mFontDescription.width;
654 return TextAbstraction::FontWidth::NORMAL;
657 void Controller::SetDefaultFontSlant( FontSlant slant )
659 if( NULL == mImpl->mFontDefaults )
661 mImpl->mFontDefaults = new FontDefaults();
664 mImpl->mFontDefaults->mFontDescription.slant = slant;
665 mImpl->mFontDefaults->slantDefined = true;
667 // Clear the font-specific data
670 mImpl->RequestRelayout();
673 bool Controller::IsDefaultFontSlantDefined() const
675 return mImpl->mFontDefaults->slantDefined;
678 FontSlant Controller::GetDefaultFontSlant() const
680 if( NULL != mImpl->mFontDefaults )
682 return mImpl->mFontDefaults->mFontDescription.slant;
685 return TextAbstraction::FontSlant::NORMAL;
688 void Controller::SetDefaultPointSize( float pointSize )
690 if( NULL == mImpl->mFontDefaults )
692 mImpl->mFontDefaults = new FontDefaults();
695 mImpl->mFontDefaults->mDefaultPointSize = pointSize;
696 mImpl->mFontDefaults->sizeDefined = true;
698 // Clear the font-specific data
701 mImpl->RequestRelayout();
704 float Controller::GetDefaultPointSize() const
706 if( NULL != mImpl->mFontDefaults )
708 return mImpl->mFontDefaults->mDefaultPointSize;
714 void Controller::SetDefaultColor( const Vector4& color )
716 mImpl->mTextColor = color;
718 if( !mImpl->IsShowingPlaceholderText() )
720 mImpl->mModel->mVisualModel->SetTextColor( color );
722 mImpl->RequestRelayout();
726 const Vector4& Controller::GetDefaultColor() const
728 return mImpl->mTextColor;
731 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
733 if( NULL != mImpl->mEventData )
735 mImpl->mEventData->mPlaceholderTextColor = textColor;
738 if( mImpl->IsShowingPlaceholderText() )
740 mImpl->mModel->mVisualModel->SetTextColor( textColor );
741 mImpl->RequestRelayout();
745 const Vector4& Controller::GetPlaceholderTextColor() const
747 if( NULL != mImpl->mEventData )
749 return mImpl->mEventData->mPlaceholderTextColor;
755 void Controller::SetShadowOffset( const Vector2& shadowOffset )
757 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
759 mImpl->RequestRelayout();
762 const Vector2& Controller::GetShadowOffset() const
764 return mImpl->mModel->mVisualModel->GetShadowOffset();
767 void Controller::SetShadowColor( const Vector4& shadowColor )
769 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
771 mImpl->RequestRelayout();
774 const Vector4& Controller::GetShadowColor() const
776 return mImpl->mModel->mVisualModel->GetShadowColor();
779 void Controller::SetUnderlineColor( const Vector4& color )
781 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
783 mImpl->RequestRelayout();
786 const Vector4& Controller::GetUnderlineColor() const
788 return mImpl->mModel->mVisualModel->GetUnderlineColor();
791 void Controller::SetUnderlineEnabled( bool enabled )
793 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
795 mImpl->RequestRelayout();
798 bool Controller::IsUnderlineEnabled() const
800 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
803 void Controller::SetUnderlineHeight( float height )
805 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
807 mImpl->RequestRelayout();
810 float Controller::GetUnderlineHeight() const
812 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
815 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
817 if( NULL == mImpl->mEmbossDefaults )
819 mImpl->mEmbossDefaults = new EmbossDefaults();
822 mImpl->mEmbossDefaults->properties = embossProperties;
825 const std::string& Controller::GetDefaultEmbossProperties() const
827 if( NULL != mImpl->mEmbossDefaults )
829 return mImpl->mEmbossDefaults->properties;
835 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
837 if( NULL == mImpl->mOutlineDefaults )
839 mImpl->mOutlineDefaults = new OutlineDefaults();
842 mImpl->mOutlineDefaults->properties = outlineProperties;
845 const std::string& Controller::GetDefaultOutlineProperties() const
847 if( NULL != mImpl->mOutlineDefaults )
849 return mImpl->mOutlineDefaults->properties;
855 void Controller::SetDefaultLineSpacing( float lineSpacing )
857 //TODO finish implementation
858 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
861 float Controller::GetDefaultLineSpacing() const
863 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
866 void Controller::SetInputColor( const Vector4& color )
868 if( NULL != mImpl->mEventData )
870 mImpl->mEventData->mInputStyle.textColor = color;
871 mImpl->mEventData->mInputStyle.isDefaultColor = false;
873 if( EventData::SELECTING == mImpl->mEventData->mState )
875 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
877 // Get start and end position of selection
878 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
879 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
881 // Add the color run.
882 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
883 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
885 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
886 colorRun.color = color;
887 colorRun.characterRun.characterIndex = startOfSelectedText;
888 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
890 // Request to relayout.
891 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
892 mImpl->RequestRelayout();
894 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
895 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
896 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
901 const Vector4& Controller::GetInputColor() const
903 if( NULL != mImpl->mEventData )
905 return mImpl->mEventData->mInputStyle.textColor;
908 // Return the default text's color if there is no EventData.
909 return mImpl->mTextColor;
913 void Controller::SetInputFontFamily( const std::string& fontFamily )
915 if( NULL != mImpl->mEventData )
917 mImpl->mEventData->mInputStyle.familyName = fontFamily;
918 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
920 if( EventData::SELECTING == mImpl->mEventData->mState )
922 CharacterIndex startOfSelectedText = 0u;
923 Length lengthOfSelectedText = 0u;
924 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
925 mImpl->mModel->mLogicalModel,
927 lengthOfSelectedText );
929 fontDescriptionRun.familyLength = fontFamily.size();
930 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
931 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
932 fontDescriptionRun.familyDefined = true;
934 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
936 // Request to relayout.
937 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
945 mImpl->mRecalculateNaturalSize = true;
946 mImpl->RequestRelayout();
948 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
949 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
950 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
952 // As the font changes, recalculate the handle positions is needed.
953 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
954 mImpl->mEventData->mUpdateRightSelectionPosition = true;
955 mImpl->mEventData->mUpdateHighlightBox = true;
956 mImpl->mEventData->mScrollAfterUpdatePosition = true;
961 const std::string& Controller::GetInputFontFamily() const
963 if( NULL != mImpl->mEventData )
965 return mImpl->mEventData->mInputStyle.familyName;
968 // Return the default font's family if there is no EventData.
969 return GetDefaultFontFamily();
972 void Controller::SetInputFontWeight( FontWeight weight )
974 if( NULL != mImpl->mEventData )
976 mImpl->mEventData->mInputStyle.weight = weight;
977 mImpl->mEventData->mInputStyle.isWeightDefined = true;
979 if( EventData::SELECTING == mImpl->mEventData->mState )
981 CharacterIndex startOfSelectedText = 0u;
982 Length lengthOfSelectedText = 0u;
983 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
984 mImpl->mModel->mLogicalModel,
986 lengthOfSelectedText );
988 fontDescriptionRun.weight = weight;
989 fontDescriptionRun.weightDefined = true;
991 // Request to relayout.
992 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1000 mImpl->mRecalculateNaturalSize = true;
1001 mImpl->RequestRelayout();
1003 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1004 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1005 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1007 // As the font might change, recalculate the handle positions is needed.
1008 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1009 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1010 mImpl->mEventData->mUpdateHighlightBox = true;
1011 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1016 bool Controller::IsInputFontWeightDefined() const
1018 bool defined = false;
1020 if( NULL != mImpl->mEventData )
1022 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1028 FontWeight Controller::GetInputFontWeight() const
1030 if( NULL != mImpl->mEventData )
1032 return mImpl->mEventData->mInputStyle.weight;
1035 return GetDefaultFontWeight();
1038 void Controller::SetInputFontWidth( FontWidth width )
1040 if( NULL != mImpl->mEventData )
1042 mImpl->mEventData->mInputStyle.width = width;
1043 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1045 if( EventData::SELECTING == mImpl->mEventData->mState )
1047 CharacterIndex startOfSelectedText = 0u;
1048 Length lengthOfSelectedText = 0u;
1049 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1050 mImpl->mModel->mLogicalModel,
1051 startOfSelectedText,
1052 lengthOfSelectedText );
1054 fontDescriptionRun.width = width;
1055 fontDescriptionRun.widthDefined = true;
1057 // Request to relayout.
1058 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1063 UPDATE_LAYOUT_SIZE |
1066 mImpl->mRecalculateNaturalSize = true;
1067 mImpl->RequestRelayout();
1069 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1070 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1071 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1073 // As the font might change, recalculate the handle positions is needed.
1074 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1075 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1076 mImpl->mEventData->mUpdateHighlightBox = true;
1077 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1082 bool Controller::IsInputFontWidthDefined() const
1084 bool defined = false;
1086 if( NULL != mImpl->mEventData )
1088 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1094 FontWidth Controller::GetInputFontWidth() const
1096 if( NULL != mImpl->mEventData )
1098 return mImpl->mEventData->mInputStyle.width;
1101 return GetDefaultFontWidth();
1104 void Controller::SetInputFontSlant( FontSlant slant )
1106 if( NULL != mImpl->mEventData )
1108 mImpl->mEventData->mInputStyle.slant = slant;
1109 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1111 if( EventData::SELECTING == mImpl->mEventData->mState )
1113 CharacterIndex startOfSelectedText = 0u;
1114 Length lengthOfSelectedText = 0u;
1115 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1116 mImpl->mModel->mLogicalModel,
1117 startOfSelectedText,
1118 lengthOfSelectedText );
1120 fontDescriptionRun.slant = slant;
1121 fontDescriptionRun.slantDefined = true;
1123 // Request to relayout.
1124 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1129 UPDATE_LAYOUT_SIZE |
1132 mImpl->mRecalculateNaturalSize = true;
1133 mImpl->RequestRelayout();
1135 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1136 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1137 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1139 // As the font might change, recalculate the handle positions is needed.
1140 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1141 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1142 mImpl->mEventData->mUpdateHighlightBox = true;
1143 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1148 bool Controller::IsInputFontSlantDefined() const
1150 bool defined = false;
1152 if( NULL != mImpl->mEventData )
1154 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1160 FontSlant Controller::GetInputFontSlant() const
1162 if( NULL != mImpl->mEventData )
1164 return mImpl->mEventData->mInputStyle.slant;
1167 return GetDefaultFontSlant();
1170 void Controller::SetInputFontPointSize( float size )
1172 if( NULL != mImpl->mEventData )
1174 mImpl->mEventData->mInputStyle.size = size;
1175 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1177 if( EventData::SELECTING == mImpl->mEventData->mState )
1179 CharacterIndex startOfSelectedText = 0u;
1180 Length lengthOfSelectedText = 0u;
1181 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1182 mImpl->mModel->mLogicalModel,
1183 startOfSelectedText,
1184 lengthOfSelectedText );
1186 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1187 fontDescriptionRun.sizeDefined = true;
1189 // Request to relayout.
1190 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1195 UPDATE_LAYOUT_SIZE |
1198 mImpl->mRecalculateNaturalSize = true;
1199 mImpl->RequestRelayout();
1201 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1202 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1203 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1205 // As the font might change, recalculate the handle positions is needed.
1206 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1207 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1208 mImpl->mEventData->mUpdateHighlightBox = true;
1209 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1214 float Controller::GetInputFontPointSize() const
1216 if( NULL != mImpl->mEventData )
1218 return mImpl->mEventData->mInputStyle.size;
1221 // Return the default font's point size if there is no EventData.
1222 return GetDefaultPointSize();
1225 void Controller::SetInputLineSpacing( float lineSpacing )
1227 if( NULL != mImpl->mEventData )
1229 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1230 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1234 float Controller::GetInputLineSpacing() const
1236 if( NULL != mImpl->mEventData )
1238 return mImpl->mEventData->mInputStyle.lineSpacing;
1244 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1246 if( NULL != mImpl->mEventData )
1248 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1252 const std::string& Controller::GetInputShadowProperties() const
1254 if( NULL != mImpl->mEventData )
1256 return mImpl->mEventData->mInputStyle.shadowProperties;
1259 return EMPTY_STRING;
1262 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1264 if( NULL != mImpl->mEventData )
1266 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1270 const std::string& Controller::GetInputUnderlineProperties() const
1272 if( NULL != mImpl->mEventData )
1274 return mImpl->mEventData->mInputStyle.underlineProperties;
1277 return EMPTY_STRING;
1280 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1282 if( NULL != mImpl->mEventData )
1284 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1288 const std::string& Controller::GetInputEmbossProperties() const
1290 if( NULL != mImpl->mEventData )
1292 return mImpl->mEventData->mInputStyle.embossProperties;
1295 return GetDefaultEmbossProperties();
1298 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1300 if( NULL != mImpl->mEventData )
1302 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1306 const std::string& Controller::GetInputOutlineProperties() const
1308 if( NULL != mImpl->mEventData )
1310 return mImpl->mEventData->mInputStyle.outlineProperties;
1313 return GetDefaultOutlineProperties();
1316 // public : Queries & retrieves.
1318 Layout::Engine& Controller::GetLayoutEngine()
1320 return mImpl->mLayoutEngine;
1323 View& Controller::GetView()
1325 return mImpl->mView;
1328 Vector3 Controller::GetNaturalSize()
1330 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1331 Vector3 naturalSize;
1333 // Make sure the model is up-to-date before layouting
1334 ProcessModifyEvents();
1336 if( mImpl->mRecalculateNaturalSize )
1338 // Operations that can be done only once until the text changes.
1339 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1346 GET_GLYPH_METRICS );
1348 // Set the update info to relayout the whole text.
1349 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1350 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1352 // Make sure the model is up-to-date before layouting
1353 mImpl->UpdateModel( onlyOnceOperations );
1355 // Layout the text for the new width.
1356 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1358 // Store the actual control's size to restore later.
1359 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1361 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1362 static_cast<OperationsMask>( onlyOnceOperations |
1364 naturalSize.GetVectorXY() );
1366 // Do not do again the only once operations.
1367 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1369 // Do the size related operations again.
1370 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1373 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1375 // Stores the natural size to avoid recalculate it again
1376 // unless the text/style changes.
1377 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1379 mImpl->mRecalculateNaturalSize = false;
1381 // Clear the update info. This info will be set the next time the text is updated.
1382 mImpl->mTextUpdateInfo.Clear();
1384 // Restore the actual control's size.
1385 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1391 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1396 naturalSize.x = ConvertToEven( naturalSize.x );
1397 naturalSize.y = ConvertToEven( naturalSize.y );
1402 float Controller::GetHeightForWidth( float width )
1404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1405 // Make sure the model is up-to-date before layouting
1406 ProcessModifyEvents();
1409 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1411 // Operations that can be done only once until the text changes.
1412 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1419 GET_GLYPH_METRICS );
1421 // Set the update info to relayout the whole text.
1422 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1423 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1425 // Make sure the model is up-to-date before layouting
1426 mImpl->UpdateModel( onlyOnceOperations );
1429 // Layout the text for the new width.
1430 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1432 // Store the actual control's width.
1433 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1435 DoRelayout( Size( width, MAX_FLOAT ),
1436 static_cast<OperationsMask>( onlyOnceOperations |
1440 // Do not do again the only once operations.
1441 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1443 // Do the size related operations again.
1444 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1448 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1450 // Clear the update info. This info will be set the next time the text is updated.
1451 mImpl->mTextUpdateInfo.Clear();
1453 // Restore the actual control's width.
1454 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1460 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1464 return layoutSize.height;
1467 const ModelInterface* const Controller::GetTextModel() const
1469 return mImpl->mModel.Get();
1472 float Controller::GetScrollAmountByUserInput()
1474 float scrollAmount = 0.0f;
1476 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1478 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1479 mImpl->mEventData->mCheckScrollAmount = false;
1481 return scrollAmount;
1484 // public : Relayout.
1486 Controller::UpdateTextType Controller::Relayout( const Size& size )
1488 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1490 UpdateTextType updateTextType = NONE_UPDATED;
1492 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1494 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1496 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1497 updateTextType = MODEL_UPDATED;
1500 // Clear the update info. This info will be set the next time the text is updated.
1501 mImpl->mTextUpdateInfo.Clear();
1503 // Not worth to relayout if width or height is equal to zero.
1504 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1506 return updateTextType;
1509 // Whether a new size has been set.
1510 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1514 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1516 // Layout operations that need to be done if the size changes.
1517 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1520 UPDATE_LAYOUT_SIZE |
1522 // Set the update info to relayout the whole text.
1523 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1524 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1526 // Store the size used to layout the text.
1527 mImpl->mModel->mVisualModel->mControlSize = size;
1530 // Whether there are modify events.
1531 if( 0u != mImpl->mModifyEvents.Count() )
1533 // Style operations that need to be done if the text is modified.
1534 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1538 // Make sure the model is up-to-date before layouting.
1539 ProcessModifyEvents();
1540 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1544 updated = DoRelayout( size,
1545 mImpl->mOperationsPending,
1546 layoutSize ) || updated;
1550 updateTextType = MODEL_UPDATED;
1553 // Do not re-do any operation until something changes.
1554 mImpl->mOperationsPending = NO_OPERATION;
1555 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1557 // Whether the text control is editable
1558 const bool isEditable = NULL != mImpl->mEventData;
1560 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1562 if( newSize && isEditable )
1564 offset = mImpl->mModel->mScrollPosition;
1567 if( !isEditable || !IsMultiLineEnabled() )
1569 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1570 CalculateVerticalOffset( size );
1577 // If there is a new size, the scroll position needs to be clamped.
1578 mImpl->ClampHorizontalScroll( layoutSize );
1580 // Update the decorator's positions is needed if there is a new size.
1581 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1584 // Move the cursor, grab handle etc.
1585 if( mImpl->ProcessInputEvents() )
1587 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1591 // Clear the update info. This info will be set the next time the text is updated.
1592 mImpl->mTextUpdateInfo.Clear();
1593 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1595 return updateTextType;
1598 void Controller::RequestRelayout()
1600 mImpl->RequestRelayout();
1603 // public : Input style change signals.
1605 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1607 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1610 void Controller::ProcessInputStyleChangedSignals()
1612 if( NULL == mImpl->mEventData )
1618 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1619 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1623 const InputStyle::Mask mask = *it;
1625 if( NULL != mImpl->mEditableControlInterface )
1627 // Emit the input style changed signal.
1628 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1632 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1635 // public : Text-input Event Queuing.
1637 void Controller::KeyboardFocusGainEvent()
1639 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1641 if( NULL != mImpl->mEventData )
1643 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1644 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1646 mImpl->ChangeState( EventData::EDITING );
1647 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1648 mImpl->mEventData->mUpdateInputStyle = true;
1650 mImpl->NotifyImfMultiLineStatus();
1651 if( mImpl->IsShowingPlaceholderText() )
1653 // Show alternative placeholder-text when editing
1654 ShowPlaceholderText();
1657 mImpl->RequestRelayout();
1661 void Controller::KeyboardFocusLostEvent()
1663 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1665 if( NULL != mImpl->mEventData )
1667 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1669 mImpl->ChangeState( EventData::INACTIVE );
1671 if( !mImpl->IsShowingRealText() )
1673 // Revert to regular placeholder-text when not editing
1674 ShowPlaceholderText();
1678 mImpl->RequestRelayout();
1681 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1683 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1685 bool textChanged( false );
1687 if( ( NULL != mImpl->mEventData ) &&
1688 ( keyEvent.state == KeyEvent::Down ) )
1690 int keyCode = keyEvent.keyCode;
1691 const std::string& keyString = keyEvent.keyPressed;
1693 // Pre-process to separate modifying events from non-modifying input events.
1694 if( Dali::DALI_KEY_ESCAPE == keyCode )
1696 // Escape key is a special case which causes focus loss
1697 KeyboardFocusLostEvent();
1699 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1700 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1701 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1702 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1704 mImpl->mEventData->mCheckScrollAmount = true;
1706 Event event( Event::CURSOR_KEY_EVENT );
1707 event.p1.mInt = keyCode;
1708 mImpl->mEventData->mEventQueue.push_back( event );
1710 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1712 textChanged = BackspaceKeyEvent();
1714 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1715 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1716 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1718 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1719 mImpl->ChangeState( EventData::INACTIVE );
1721 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1723 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1725 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1726 // and a character is typed after the type of a upper case latin character.
1732 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1734 // IMF manager is no longer handling key-events
1735 mImpl->ClearPreEditFlag();
1737 InsertText( keyString, COMMIT );
1741 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1742 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1743 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) )
1745 // Should not change the state if the key is the shift send by the imf manager.
1746 // Otherwise, when the state is SELECTING the text controller can't send the right
1747 // surrounding info to the imf.
1748 mImpl->ChangeState( EventData::EDITING );
1751 mImpl->RequestRelayout();
1755 ( NULL != mImpl->mEditableControlInterface ) )
1757 // Do this last since it provides callbacks into application code
1758 mImpl->mEditableControlInterface->TextChanged();
1764 void Controller::TapEvent( unsigned int tapCount, float x, float y )
1766 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
1768 if( NULL != mImpl->mEventData )
1770 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
1771 EventData::State state( mImpl->mEventData->mState );
1772 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
1774 if( mImpl->IsClipboardVisible() )
1776 if( EventData::INACTIVE == state || EventData::EDITING == state)
1778 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
1780 relayoutNeeded = true;
1782 else if( 1u == tapCount )
1784 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
1786 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
1789 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
1791 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
1792 relayoutNeeded = true;
1796 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
1798 // Hide placeholder text
1802 if( EventData::INACTIVE == state )
1804 mImpl->ChangeState( EventData::EDITING );
1806 else if( !mImpl->IsClipboardEmpty() )
1808 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
1810 relayoutNeeded = true;
1813 else if( 2u == tapCount )
1815 if( mImpl->mEventData->mSelectionEnabled &&
1816 mImpl->IsShowingRealText() )
1818 SelectEvent( x, y, false );
1821 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
1822 if( relayoutNeeded )
1824 Event event( Event::TAP_EVENT );
1825 event.p1.mUint = tapCount;
1826 event.p2.mFloat = x;
1827 event.p3.mFloat = y;
1828 mImpl->mEventData->mEventQueue.push_back( event );
1830 mImpl->RequestRelayout();
1834 // Reset keyboard as tap event has occurred.
1835 mImpl->ResetImfManager();
1838 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
1840 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
1842 if( NULL != mImpl->mEventData )
1844 Event event( Event::PAN_EVENT );
1845 event.p1.mInt = state;
1846 event.p2.mFloat = displacement.x;
1847 event.p3.mFloat = displacement.y;
1848 mImpl->mEventData->mEventQueue.push_back( event );
1850 mImpl->RequestRelayout();
1854 void Controller::LongPressEvent( Gesture::State state, float x, float y )
1856 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
1858 if( ( state == Gesture::Started ) &&
1859 ( NULL != mImpl->mEventData ) )
1861 if( !mImpl->IsShowingRealText() )
1863 Event event( Event::LONG_PRESS_EVENT );
1864 event.p1.mInt = state;
1865 mImpl->mEventData->mEventQueue.push_back( event );
1866 mImpl->RequestRelayout();
1870 // The 1st long-press on inactive text-field is treated as tap
1871 if( EventData::INACTIVE == mImpl->mEventData->mState )
1873 mImpl->ChangeState( EventData::EDITING );
1875 Event event( Event::TAP_EVENT );
1877 event.p2.mFloat = x;
1878 event.p3.mFloat = y;
1879 mImpl->mEventData->mEventQueue.push_back( event );
1881 mImpl->RequestRelayout();
1883 else if( !mImpl->IsClipboardVisible() )
1885 // Reset the imf manger to commit the pre-edit before selecting the text.
1886 mImpl->ResetImfManager();
1888 SelectEvent( x, y, false );
1894 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1896 // Whether the text needs to be relaid-out.
1897 bool requestRelayout = false;
1899 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
1900 bool retrieveText = false;
1901 bool retrieveCursor = false;
1903 switch( imfEvent.eventName )
1905 case ImfManager::COMMIT:
1907 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
1908 requestRelayout = true;
1909 retrieveCursor = true;
1912 case ImfManager::PREEDIT:
1914 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
1915 requestRelayout = true;
1916 retrieveCursor = true;
1919 case ImfManager::DELETESURROUNDING:
1921 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
1922 imfEvent.numberOfChars,
1923 DONT_UPDATE_INPUT_STYLE );
1927 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
1928 !mImpl->IsPlaceholderAvailable() )
1930 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
1934 ShowPlaceholderText();
1936 mImpl->mEventData->mUpdateCursorPosition = true;
1937 mImpl->mEventData->mScrollAfterDelete = true;
1939 requestRelayout = true;
1943 case ImfManager::GETSURROUNDING:
1945 retrieveText = true;
1946 retrieveCursor = true;
1949 case ImfManager::VOID:
1956 if( requestRelayout )
1958 mImpl->mOperationsPending = ALL_OPERATIONS;
1959 mImpl->RequestRelayout();
1963 CharacterIndex cursorPosition = 0u;
1964 Length numberOfWhiteSpaces = 0u;
1966 if( retrieveCursor )
1968 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
1970 cursorPosition = mImpl->GetLogicalCursorPosition();
1972 if( cursorPosition < numberOfWhiteSpaces )
1974 cursorPosition = 0u;
1978 cursorPosition -= numberOfWhiteSpaces;
1984 mImpl->GetText( numberOfWhiteSpaces, text );
1987 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
1989 if( requestRelayout &&
1990 ( NULL != mImpl->mEditableControlInterface ) )
1992 // Do this last since it provides callbacks into application code
1993 mImpl->mEditableControlInterface->TextChanged();
1996 return callbackData;
1999 void Controller::PasteClipboardItemEvent()
2001 // Retrieve the clipboard contents first
2002 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2003 std::string stringToPaste( notifier.GetContent() );
2005 // Commit the current pre-edit text; the contents of the clipboard should be appended
2006 mImpl->ResetImfManager();
2008 // Temporary disable hiding clipboard
2009 mImpl->SetClipboardHideEnable( false );
2012 PasteText( stringToPaste );
2014 mImpl->SetClipboardHideEnable( true );
2017 // protected : Inherit from Text::Decorator::ControllerInterface.
2019 void Controller::GetTargetSize( Vector2& targetSize )
2021 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2024 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2026 if( NULL != mImpl->mEditableControlInterface )
2028 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2032 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2034 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2036 if( NULL != mImpl->mEventData )
2038 switch( handleType )
2042 Event event( Event::GRAB_HANDLE_EVENT );
2043 event.p1.mUint = state;
2044 event.p2.mFloat = x;
2045 event.p3.mFloat = y;
2047 mImpl->mEventData->mEventQueue.push_back( event );
2050 case LEFT_SELECTION_HANDLE:
2052 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2053 event.p1.mUint = state;
2054 event.p2.mFloat = x;
2055 event.p3.mFloat = y;
2057 mImpl->mEventData->mEventQueue.push_back( event );
2060 case RIGHT_SELECTION_HANDLE:
2062 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2063 event.p1.mUint = state;
2064 event.p2.mFloat = x;
2065 event.p3.mFloat = y;
2067 mImpl->mEventData->mEventQueue.push_back( event );
2070 case LEFT_SELECTION_HANDLE_MARKER:
2071 case RIGHT_SELECTION_HANDLE_MARKER:
2073 // Markers do not move the handles.
2076 case HANDLE_TYPE_COUNT:
2078 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2082 mImpl->RequestRelayout();
2086 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2088 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2090 if( NULL == mImpl->mEventData )
2097 case Toolkit::TextSelectionPopup::CUT:
2099 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2100 mImpl->mOperationsPending = ALL_OPERATIONS;
2102 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2103 !mImpl->IsPlaceholderAvailable() )
2105 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2109 ShowPlaceholderText();
2112 mImpl->mEventData->mUpdateCursorPosition = true;
2113 mImpl->mEventData->mScrollAfterDelete = true;
2115 mImpl->RequestRelayout();
2117 if( NULL != mImpl->mEditableControlInterface )
2119 mImpl->mEditableControlInterface->TextChanged();
2123 case Toolkit::TextSelectionPopup::COPY:
2125 mImpl->SendSelectionToClipboard( false ); // Text not modified
2127 mImpl->mEventData->mUpdateCursorPosition = true;
2129 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2132 case Toolkit::TextSelectionPopup::PASTE:
2134 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2137 case Toolkit::TextSelectionPopup::SELECT:
2139 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2141 if( mImpl->mEventData->mSelectionEnabled )
2143 // Creates a SELECT event.
2144 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2148 case Toolkit::TextSelectionPopup::SELECT_ALL:
2150 // Creates a SELECT_ALL event
2151 SelectEvent( 0.f, 0.f, true );
2154 case Toolkit::TextSelectionPopup::CLIPBOARD:
2156 mImpl->ShowClipboard();
2159 case Toolkit::TextSelectionPopup::NONE:
2167 // private : Update.
2169 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2171 bool removedPrevious( false );
2172 bool maxLengthReached( false );
2174 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2176 if( NULL == mImpl->mEventData )
2181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2182 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2183 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2185 // TODO: At the moment the underline runs are only for pre-edit.
2186 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2188 // Keep the current number of characters.
2189 const Length currentNumberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u;
2191 // Remove the previous IMF pre-edit.
2192 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2194 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2195 mImpl->mEventData->mPreEditLength,
2196 DONT_UPDATE_INPUT_STYLE );
2198 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2199 mImpl->mEventData->mPreEditLength = 0u;
2203 // Remove the previous Selection.
2204 removedPrevious = RemoveSelectedText();
2207 Vector<Character> utf32Characters;
2208 Length characterCount = 0u;
2212 // Convert text into UTF-32
2213 utf32Characters.Resize( text.size() );
2215 // This is a bit horrible but std::string returns a (signed) char*
2216 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2218 // Transform a text array encoded in utf8 into an array encoded in utf32.
2219 // It returns the actual number of characters.
2220 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2221 utf32Characters.Resize( characterCount );
2223 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2224 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2227 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2229 // The placeholder text is no longer needed
2230 if( mImpl->IsShowingPlaceholderText() )
2235 mImpl->ChangeState( EventData::EDITING );
2237 // Handle the IMF (predicitive text) state changes
2238 if( COMMIT == type )
2240 // IMF manager is no longer handling key-events
2241 mImpl->ClearPreEditFlag();
2245 if( !mImpl->mEventData->mPreEditFlag )
2247 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2249 // Record the start of the pre-edit text
2250 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2253 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2254 mImpl->mEventData->mPreEditFlag = true;
2256 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2259 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2261 // Restrict new text to fit within Maximum characters setting.
2262 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2263 maxLengthReached = ( characterCount > maxSizeOfNewText );
2265 // The cursor position.
2266 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2268 // Update the text's style.
2270 // Updates the text style runs by adding characters.
2271 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2273 // Get the character index from the cursor index.
2274 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2276 // Retrieve the text's style for the given index.
2278 mImpl->RetrieveDefaultInputStyle( style );
2279 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2281 // Whether to add a new text color run.
2282 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2284 // Whether to add a new font run.
2285 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2286 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2287 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2288 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2289 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2294 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2295 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2297 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2298 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2299 colorRun.characterRun.characterIndex = cursorIndex;
2300 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2303 if( addFontNameRun ||
2309 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2310 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2312 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2314 if( addFontNameRun )
2316 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2317 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2318 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2319 fontDescriptionRun.familyDefined = true;
2321 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2324 if( addFontWeightRun )
2326 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2327 fontDescriptionRun.weightDefined = true;
2330 if( addFontWidthRun )
2332 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2333 fontDescriptionRun.widthDefined = true;
2336 if( addFontSlantRun )
2338 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2339 fontDescriptionRun.slantDefined = true;
2342 if( addFontSizeRun )
2344 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2345 fontDescriptionRun.sizeDefined = true;
2348 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2349 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2352 // Insert at current cursor position.
2353 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2355 if( cursorIndex < numberOfCharactersInModel )
2357 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2361 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2364 // Mark the first paragraph to be updated.
2365 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2366 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2368 // Update the cursor index.
2369 cursorIndex += maxSizeOfNewText;
2371 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
2374 const Length numberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u;
2376 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2377 mImpl->IsPlaceholderAvailable() )
2379 // Show place-holder if empty after removing the pre-edit text
2380 ShowPlaceholderText();
2381 mImpl->mEventData->mUpdateCursorPosition = true;
2382 mImpl->ClearPreEditFlag();
2384 else if( removedPrevious ||
2385 ( 0 != utf32Characters.Count() ) )
2387 // Queue an inserted event
2388 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2390 mImpl->mEventData->mUpdateCursorPosition = true;
2391 if( numberOfCharacters < currentNumberOfCharacters )
2393 mImpl->mEventData->mScrollAfterDelete = true;
2397 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2401 if( maxLengthReached )
2403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2405 mImpl->ResetImfManager();
2407 if( NULL != mImpl->mEditableControlInterface )
2409 // Do this last since it provides callbacks into application code
2410 mImpl->mEditableControlInterface->MaxLengthReached();
2415 void Controller::PasteText( const std::string& stringToPaste )
2417 InsertText( stringToPaste, Text::Controller::COMMIT );
2418 mImpl->ChangeState( EventData::EDITING );
2419 mImpl->RequestRelayout();
2421 if( NULL != mImpl->mEditableControlInterface )
2423 // Do this last since it provides callbacks into application code
2424 mImpl->mEditableControlInterface->TextChanged();
2428 bool Controller::RemoveText( int cursorOffset,
2429 int numberOfCharacters,
2430 UpdateInputStyleType type )
2432 bool removed = false;
2434 if( NULL == mImpl->mEventData )
2439 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2440 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2442 if( !mImpl->IsShowingPlaceholderText() )
2444 // Delete at current cursor position
2445 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2446 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2448 CharacterIndex cursorIndex = oldCursorIndex;
2450 // Validate the cursor position & number of characters
2451 if( static_cast< CharacterIndex >( std::abs( cursorOffset ) ) <= cursorIndex )
2453 cursorIndex = oldCursorIndex + cursorOffset;
2456 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2458 numberOfCharacters = currentText.Count() - cursorIndex;
2461 if( mImpl->mEventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
2462 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2464 // Mark the paragraphs to be updated.
2465 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2466 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2468 // Update the input style and remove the text's style before removing the text.
2470 if( UPDATE_INPUT_STYLE == type )
2472 // Keep a copy of the current input style.
2473 InputStyle currentInputStyle;
2474 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2476 // Set first the default input style.
2477 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2479 // Update the input style.
2480 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2482 // Compare if the input style has changed.
2483 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2485 if( hasInputStyleChanged )
2487 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2488 // Queue the input style changed signal.
2489 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2493 // Updates the text style runs by removing characters. Runs with no characters are removed.
2494 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2496 // Remove the characters.
2497 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2498 Vector<Character>::Iterator last = first + numberOfCharacters;
2500 currentText.Erase( first, last );
2502 // Cursor position retreat
2503 oldCursorIndex = cursorIndex;
2505 mImpl->mEventData->mScrollAfterDelete = true;
2507 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2515 bool Controller::RemoveSelectedText()
2517 bool textRemoved( false );
2519 if( EventData::SELECTING == mImpl->mEventData->mState )
2521 std::string removedString;
2522 mImpl->RetrieveSelection( removedString, true );
2524 if( !removedString.empty() )
2527 mImpl->ChangeState( EventData::EDITING );
2534 // private : Relayout.
2536 bool Controller::DoRelayout( const Size& size,
2537 OperationsMask operationsRequired,
2540 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2541 bool viewUpdated( false );
2543 // Calculate the operations to be done.
2544 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2546 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2547 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2549 // Get the current layout size.
2550 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2552 if( NO_OPERATION != ( LAYOUT & operations ) )
2554 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2556 // Some vectors with data needed to layout and reorder may be void
2557 // after the first time the text has been laid out.
2558 // Fill the vectors again.
2560 // Calculate the number of glyphs to layout.
2561 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2562 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2563 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2564 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2566 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2567 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2568 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2569 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2571 if( 0u == totalNumberOfGlyphs )
2573 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2575 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2578 // Nothing else to do if there is no glyphs.
2579 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2583 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2584 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2585 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2586 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2587 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2588 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2589 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2591 // Set the layout parameters.
2592 Layout::Parameters layoutParameters( size,
2594 lineBreakInfo.Begin(),
2595 wordBreakInfo.Begin(),
2596 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2598 glyphsToCharactersMap.Begin(),
2599 charactersPerGlyph.Begin(),
2600 charactersToGlyphBuffer,
2601 glyphsPerCharacterBuffer,
2602 totalNumberOfGlyphs,
2603 mImpl->mModel->mHorizontalAlignment );
2605 // Resize the vector of positions to have the same size than the vector of glyphs.
2606 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2607 glyphPositions.Resize( totalNumberOfGlyphs );
2609 // Whether the last character is a new paragraph character.
2610 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2611 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2613 // The initial glyph and the number of glyphs to layout.
2614 layoutParameters.startGlyphIndex = startGlyphIndex;
2615 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2616 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2617 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2619 // Update the visual model.
2621 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2623 mImpl->mModel->mVisualModel->mLines,
2625 mImpl->mModel->mElideEnabled );
2627 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2631 layoutSize = newLayoutSize;
2633 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2635 mImpl->mAutoScrollDirectionRTL = false;
2638 // Reorder the lines
2639 if( NO_OPERATION != ( REORDER & operations ) )
2641 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2642 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2644 // Check first if there are paragraphs with bidirectional info.
2645 if( 0u != bidirectionalInfo.Count() )
2648 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2650 // Reorder the lines.
2651 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2652 ReorderLines( bidirectionalInfo,
2654 requestedNumberOfCharacters,
2655 mImpl->mModel->mVisualModel->mLines,
2656 bidirectionalLineInfo );
2658 // Set the bidirectional info per line into the layout parameters.
2659 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2660 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2662 // Re-layout the text. Reorder those lines with right to left characters.
2663 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2665 requestedNumberOfCharacters,
2668 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2670 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2673 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2679 // Sets the layout size.
2680 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2682 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2687 if( NO_OPERATION != ( ALIGN & operations ) )
2689 // The laid-out lines.
2690 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2692 // Need to align with the control's size as the text may contain lines
2693 // starting either with left to right text or right to left.
2694 mImpl->mLayoutEngine.Align( size,
2696 requestedNumberOfCharacters,
2697 mImpl->mModel->mHorizontalAlignment,
2699 mImpl->mModel->mAlignmentOffset );
2703 #if defined(DEBUG_ENABLED)
2704 std::string currentText;
2705 GetText( currentText );
2706 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2708 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2712 void Controller::CalculateVerticalOffset( const Size& controlSize )
2714 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2716 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2718 // Get the line height of the default font.
2719 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2722 switch( mImpl->mModel->mVerticalAlignment )
2724 case Layout::VERTICAL_ALIGN_TOP:
2726 mImpl->mModel->mScrollPosition.y = 0.f;
2729 case Layout::VERTICAL_ALIGN_CENTER:
2731 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2734 case Layout::VERTICAL_ALIGN_BOTTOM:
2736 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2742 // private : Events.
2744 void Controller::ProcessModifyEvents()
2746 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
2748 if( 0u == events.Count() )
2754 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
2755 endIt = events.End();
2759 const ModifyEvent& event = *it;
2761 if( ModifyEvent::TEXT_REPLACED == event.type )
2763 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
2764 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
2766 TextReplacedEvent();
2768 else if( ModifyEvent::TEXT_INSERTED == event.type )
2770 TextInsertedEvent();
2772 else if( ModifyEvent::TEXT_DELETED == event.type )
2774 // Placeholder-text cannot be deleted
2775 if( !mImpl->IsShowingPlaceholderText() )
2782 if( NULL != mImpl->mEventData )
2784 // When the text is being modified, delay cursor blinking
2785 mImpl->mEventData->mDecorator->DelayCursorBlink();
2788 // Discard temporary text
2792 void Controller::TextReplacedEvent()
2794 // The natural size needs to be re-calculated.
2795 mImpl->mRecalculateNaturalSize = true;
2797 // Apply modifications to the model
2798 mImpl->mOperationsPending = ALL_OPERATIONS;
2801 void Controller::TextInsertedEvent()
2803 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
2805 if( NULL == mImpl->mEventData )
2810 mImpl->mEventData->mCheckScrollAmount = true;
2812 // The natural size needs to be re-calculated.
2813 mImpl->mRecalculateNaturalSize = true;
2815 // Apply modifications to the model; TODO - Optimize this
2816 mImpl->mOperationsPending = ALL_OPERATIONS;
2819 void Controller::TextDeletedEvent()
2821 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
2823 if( NULL == mImpl->mEventData )
2828 mImpl->mEventData->mCheckScrollAmount = true;
2830 // The natural size needs to be re-calculated.
2831 mImpl->mRecalculateNaturalSize = true;
2833 // Apply modifications to the model; TODO - Optimize this
2834 mImpl->mOperationsPending = ALL_OPERATIONS;
2837 void Controller::SelectEvent( float x, float y, bool selectAll )
2839 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
2841 if( NULL != mImpl->mEventData )
2845 Event event( Event::SELECT_ALL );
2846 mImpl->mEventData->mEventQueue.push_back( event );
2850 Event event( Event::SELECT );
2851 event.p2.mFloat = x;
2852 event.p3.mFloat = y;
2853 mImpl->mEventData->mEventQueue.push_back( event );
2856 mImpl->mEventData->mCheckScrollAmount = true;
2857 mImpl->RequestRelayout();
2861 bool Controller::BackspaceKeyEvent()
2863 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
2865 bool removed = false;
2867 if( NULL == mImpl->mEventData )
2872 // IMF manager is no longer handling key-events
2873 mImpl->ClearPreEditFlag();
2875 if( EventData::SELECTING == mImpl->mEventData->mState )
2877 removed = RemoveSelectedText();
2879 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
2881 // Remove the character before the current cursor position
2882 removed = RemoveText( -1,
2884 UPDATE_INPUT_STYLE );
2889 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2890 !mImpl->IsPlaceholderAvailable() )
2892 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2896 ShowPlaceholderText();
2898 mImpl->mEventData->mUpdateCursorPosition = true;
2899 mImpl->mEventData->mScrollAfterDelete = true;
2905 // private : Helpers.
2907 void Controller::ResetText()
2910 mImpl->mModel->mLogicalModel->mText.Clear();
2912 // We have cleared everything including the placeholder-text
2913 mImpl->PlaceholderCleared();
2915 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2916 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2917 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
2919 // Clear any previous text.
2920 mImpl->mTextUpdateInfo.mClearAll = true;
2922 // The natural size needs to be re-calculated.
2923 mImpl->mRecalculateNaturalSize = true;
2925 // Apply modifications to the model
2926 mImpl->mOperationsPending = ALL_OPERATIONS;
2929 void Controller::ShowPlaceholderText()
2931 if( mImpl->IsPlaceholderAvailable() )
2933 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
2935 if( NULL == mImpl->mEventData )
2940 mImpl->mEventData->mIsShowingPlaceholderText = true;
2942 // Disable handles when showing place-holder text
2943 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
2944 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
2945 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
2947 const char* text( NULL );
2950 // TODO - Switch placeholder text styles when changing state
2951 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
2952 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
2954 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
2955 size = mImpl->mEventData->mPlaceholderTextActive.size();
2959 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
2960 size = mImpl->mEventData->mPlaceholderTextInactive.size();
2963 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2964 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2966 // Reset model for showing placeholder.
2967 mImpl->mModel->mLogicalModel->mText.Clear();
2968 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
2970 // Convert text into UTF-32
2971 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
2972 utf32Characters.Resize( size );
2974 // This is a bit horrible but std::string returns a (signed) char*
2975 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
2977 // Transform a text array encoded in utf8 into an array encoded in utf32.
2978 // It returns the actual number of characters.
2979 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
2980 utf32Characters.Resize( characterCount );
2982 // The characters to be added.
2983 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
2985 // Reset the cursor position
2986 mImpl->mEventData->mPrimaryCursorPosition = 0;
2988 // The natural size needs to be re-calculated.
2989 mImpl->mRecalculateNaturalSize = true;
2991 // Apply modifications to the model
2992 mImpl->mOperationsPending = ALL_OPERATIONS;
2994 // Update the rest of the model during size negotiation
2995 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
2999 void Controller::ClearFontData()
3001 if( mImpl->mFontDefaults )
3003 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3006 // Set flags to update the model.
3007 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3008 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3009 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3011 mImpl->mTextUpdateInfo.mClearAll = true;
3012 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3013 mImpl->mRecalculateNaturalSize = true;
3015 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3020 UPDATE_LAYOUT_SIZE |
3025 void Controller::ClearStyleData()
3027 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3028 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3031 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3033 // Reset the cursor position
3034 if( NULL != mImpl->mEventData )
3036 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3038 // Update the cursor if it's in editing mode.
3039 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3041 mImpl->mEventData->mUpdateCursorPosition = true;
3046 void Controller::ResetScrollPosition()
3048 if( NULL != mImpl->mEventData )
3050 // Reset the scroll position.
3051 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3052 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3056 // private : Private contructors & copy operator.
3058 Controller::Controller()
3061 mImpl = new Controller::Impl( NULL, NULL );
3064 Controller::Controller( ControlInterface* controlInterface )
3066 mImpl = new Controller::Impl( controlInterface, NULL );
3069 Controller::Controller( ControlInterface* controlInterface,
3070 EditableControlInterface* editableControlInterface )
3072 mImpl = new Controller::Impl( controlInterface,
3073 editableControlInterface );
3076 // The copy constructor and operator are left unimplemented.
3078 // protected : Destructor.
3080 Controller::~Controller()
3087 } // namespace Toolkit