2 * Copyright (c) 2017 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 void Controller::SetInputModePassword( bool passwordInput )
1318 if( NULL != mImpl->mEventData )
1320 mImpl->mEventData->mPasswordInput = passwordInput;
1324 bool Controller::IsInputModePassword()
1326 if( NULL != mImpl->mEventData )
1328 return mImpl->mEventData->mPasswordInput;
1333 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1335 if( NULL != mImpl->mEventData )
1337 mImpl->mEventData->mDoubleTapAction = action;
1341 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1343 NoTextTap::Action action = NoTextTap::NO_ACTION;
1345 if( NULL != mImpl->mEventData )
1347 action = mImpl->mEventData->mDoubleTapAction;
1353 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1355 if( NULL != mImpl->mEventData )
1357 mImpl->mEventData->mLongPressAction = action;
1361 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1363 NoTextTap::Action action = NoTextTap::NO_ACTION;
1365 if( NULL != mImpl->mEventData )
1367 action = mImpl->mEventData->mLongPressAction;
1373 // public : Queries & retrieves.
1375 Layout::Engine& Controller::GetLayoutEngine()
1377 return mImpl->mLayoutEngine;
1380 View& Controller::GetView()
1382 return mImpl->mView;
1385 Vector3 Controller::GetNaturalSize()
1387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1388 Vector3 naturalSize;
1390 // Make sure the model is up-to-date before layouting
1391 ProcessModifyEvents();
1393 if( mImpl->mRecalculateNaturalSize )
1395 // Operations that can be done only once until the text changes.
1396 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1403 GET_GLYPH_METRICS );
1405 // Set the update info to relayout the whole text.
1406 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1407 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1409 // Make sure the model is up-to-date before layouting
1410 mImpl->UpdateModel( onlyOnceOperations );
1412 // Layout the text for the new width.
1413 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1415 // Store the actual control's size to restore later.
1416 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1418 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1419 static_cast<OperationsMask>( onlyOnceOperations |
1421 naturalSize.GetVectorXY() );
1423 // Do not do again the only once operations.
1424 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1426 // Do the size related operations again.
1427 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1430 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1432 // Stores the natural size to avoid recalculate it again
1433 // unless the text/style changes.
1434 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1436 mImpl->mRecalculateNaturalSize = false;
1438 // Clear the update info. This info will be set the next time the text is updated.
1439 mImpl->mTextUpdateInfo.Clear();
1441 // Restore the actual control's size.
1442 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1448 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1450 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1453 naturalSize.x = ConvertToEven( naturalSize.x );
1454 naturalSize.y = ConvertToEven( naturalSize.y );
1459 float Controller::GetHeightForWidth( float width )
1461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1462 // Make sure the model is up-to-date before layouting
1463 ProcessModifyEvents();
1466 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1468 // Operations that can be done only once until the text changes.
1469 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1476 GET_GLYPH_METRICS );
1478 // Set the update info to relayout the whole text.
1479 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1480 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1482 // Make sure the model is up-to-date before layouting
1483 mImpl->UpdateModel( onlyOnceOperations );
1486 // Layout the text for the new width.
1487 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1489 // Store the actual control's width.
1490 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1492 DoRelayout( Size( width, MAX_FLOAT ),
1493 static_cast<OperationsMask>( onlyOnceOperations |
1497 // Do not do again the only once operations.
1498 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1500 // Do the size related operations again.
1501 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1505 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1507 // Clear the update info. This info will be set the next time the text is updated.
1508 mImpl->mTextUpdateInfo.Clear();
1510 // Restore the actual control's width.
1511 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1513 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1517 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1518 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1521 return layoutSize.height;
1524 const ModelInterface* const Controller::GetTextModel() const
1526 return mImpl->mModel.Get();
1529 float Controller::GetScrollAmountByUserInput()
1531 float scrollAmount = 0.0f;
1533 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1535 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1536 mImpl->mEventData->mCheckScrollAmount = false;
1538 return scrollAmount;
1541 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1543 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1546 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1547 layoutHeight = layout.height;
1548 scrollPosition = mImpl->mModel->mScrollPosition.y;
1549 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1553 // public : Relayout.
1555 Controller::UpdateTextType Controller::Relayout( const Size& size )
1557 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
1559 UpdateTextType updateTextType = NONE_UPDATED;
1561 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1563 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
1565 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
1566 updateTextType = MODEL_UPDATED;
1569 // Clear the update info. This info will be set the next time the text is updated.
1570 mImpl->mTextUpdateInfo.Clear();
1572 // Not worth to relayout if width or height is equal to zero.
1573 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1575 return updateTextType;
1578 // Whether a new size has been set.
1579 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
1583 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
1585 // Layout operations that need to be done if the size changes.
1586 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1589 UPDATE_LAYOUT_SIZE |
1591 // Set the update info to relayout the whole text.
1592 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1593 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1595 // Store the size used to layout the text.
1596 mImpl->mModel->mVisualModel->mControlSize = size;
1599 // Whether there are modify events.
1600 if( 0u != mImpl->mModifyEvents.Count() )
1602 // Style operations that need to be done if the text is modified.
1603 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1607 // Make sure the model is up-to-date before layouting.
1608 ProcessModifyEvents();
1609 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1613 updated = DoRelayout( size,
1614 mImpl->mOperationsPending,
1615 layoutSize ) || updated;
1619 updateTextType = MODEL_UPDATED;
1622 // Do not re-do any operation until something changes.
1623 mImpl->mOperationsPending = NO_OPERATION;
1624 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
1626 // Whether the text control is editable
1627 const bool isEditable = NULL != mImpl->mEventData;
1629 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1631 if( newSize && isEditable )
1633 offset = mImpl->mModel->mScrollPosition;
1636 if( !isEditable || !IsMultiLineEnabled() )
1638 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1639 CalculateVerticalOffset( size );
1646 // If there is a new size, the scroll position needs to be clamped.
1647 mImpl->ClampHorizontalScroll( layoutSize );
1649 // Update the decorator's positions is needed if there is a new size.
1650 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
1653 // Move the cursor, grab handle etc.
1654 if( mImpl->ProcessInputEvents() )
1656 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1660 // Clear the update info. This info will be set the next time the text is updated.
1661 mImpl->mTextUpdateInfo.Clear();
1662 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1664 return updateTextType;
1667 void Controller::RequestRelayout()
1669 mImpl->RequestRelayout();
1672 // public : Input style change signals.
1674 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1676 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1679 void Controller::ProcessInputStyleChangedSignals()
1681 if( NULL == mImpl->mEventData )
1687 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1688 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1692 const InputStyle::Mask mask = *it;
1694 if( NULL != mImpl->mEditableControlInterface )
1696 // Emit the input style changed signal.
1697 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1701 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1704 // public : Text-input Event Queuing.
1706 void Controller::KeyboardFocusGainEvent()
1708 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1710 if( NULL != mImpl->mEventData )
1712 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1713 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1715 mImpl->ChangeState( EventData::EDITING );
1716 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1717 mImpl->mEventData->mUpdateInputStyle = true;
1719 mImpl->NotifyImfMultiLineStatus();
1720 if( mImpl->IsShowingPlaceholderText() )
1722 // Show alternative placeholder-text when editing
1723 ShowPlaceholderText();
1726 mImpl->RequestRelayout();
1730 void Controller::KeyboardFocusLostEvent()
1732 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1734 if( NULL != mImpl->mEventData )
1736 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1738 mImpl->ChangeState( EventData::INACTIVE );
1740 if( !mImpl->IsShowingRealText() )
1742 // Revert to regular placeholder-text when not editing
1743 ShowPlaceholderText();
1747 mImpl->RequestRelayout();
1750 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1752 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1754 bool textChanged( false );
1756 if( ( NULL != mImpl->mEventData ) &&
1757 ( keyEvent.state == KeyEvent::Down ) )
1759 int keyCode = keyEvent.keyCode;
1760 const std::string& keyString = keyEvent.keyPressed;
1762 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
1764 // Pre-process to separate modifying events from non-modifying input events.
1767 // In some platforms arrive key events with no key code.
1770 else if( Dali::DALI_KEY_ESCAPE == keyCode )
1772 // Escape key is a special case which causes focus loss
1773 KeyboardFocusLostEvent();
1775 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1776 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1777 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1778 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1780 // If don't have any text, do nothing.
1781 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
1786 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
1787 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1788 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
1789 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
1791 // Logic to determine whether this text control will lose focus or not.
1792 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
1793 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
1794 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
1795 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
1796 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
1797 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
1802 mImpl->mEventData->mCheckScrollAmount = true;
1803 Event event( Event::CURSOR_KEY_EVENT );
1804 event.p1.mInt = keyCode;
1805 mImpl->mEventData->mEventQueue.push_back( event );
1807 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1809 textChanged = BackspaceKeyEvent();
1811 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1812 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1813 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1815 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1816 mImpl->ChangeState( EventData::INACTIVE );
1818 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1820 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1822 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1823 // and a character is typed after the type of a upper case latin character.
1829 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1831 // IMF manager is no longer handling key-events
1832 mImpl->ClearPreEditFlag();
1834 InsertText( keyString, COMMIT );
1838 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1839 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1841 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) )
1843 // Should not change the state if the key is the shift send by the imf manager.
1844 // Otherwise, when the state is SELECTING the text controller can't send the right
1845 // surrounding info to the imf.
1846 mImpl->ChangeState( EventData::EDITING );
1849 mImpl->RequestRelayout();
1853 ( NULL != mImpl->mEditableControlInterface ) )
1855 // Do this last since it provides callbacks into application code
1856 mImpl->mEditableControlInterface->TextChanged();
1862 void Controller::TapEvent( unsigned int tapCount, float x, float y )
1864 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
1866 if( NULL != mImpl->mEventData )
1868 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
1869 EventData::State state( mImpl->mEventData->mState );
1870 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
1872 if( mImpl->IsClipboardVisible() )
1874 if( EventData::INACTIVE == state || EventData::EDITING == state)
1876 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
1878 relayoutNeeded = true;
1880 else if( 1u == tapCount )
1882 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
1884 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
1887 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
1889 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
1890 relayoutNeeded = true;
1894 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
1896 // Hide placeholder text
1900 if( EventData::INACTIVE == state )
1902 mImpl->ChangeState( EventData::EDITING );
1904 else if( !mImpl->IsClipboardEmpty() )
1906 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
1908 relayoutNeeded = true;
1911 else if( 2u == tapCount )
1913 if( mImpl->mEventData->mSelectionEnabled &&
1914 mImpl->IsShowingRealText() )
1916 relayoutNeeded = true;
1917 mImpl->mEventData->mIsLeftHandleSelected = true;
1918 mImpl->mEventData->mIsRightHandleSelected = true;
1922 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
1923 if( relayoutNeeded )
1925 Event event( Event::TAP_EVENT );
1926 event.p1.mUint = tapCount;
1927 event.p2.mFloat = x;
1928 event.p3.mFloat = y;
1929 mImpl->mEventData->mEventQueue.push_back( event );
1931 mImpl->RequestRelayout();
1935 // Reset keyboard as tap event has occurred.
1936 mImpl->ResetImfManager();
1939 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
1941 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
1943 if( NULL != mImpl->mEventData )
1945 Event event( Event::PAN_EVENT );
1946 event.p1.mInt = state;
1947 event.p2.mFloat = displacement.x;
1948 event.p3.mFloat = displacement.y;
1949 mImpl->mEventData->mEventQueue.push_back( event );
1951 mImpl->RequestRelayout();
1955 void Controller::LongPressEvent( Gesture::State state, float x, float y )
1957 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
1959 if( ( state == Gesture::Started ) &&
1960 ( NULL != mImpl->mEventData ) )
1962 // The 1st long-press on inactive text-field is treated as tap
1963 if( EventData::INACTIVE == mImpl->mEventData->mState )
1965 mImpl->ChangeState( EventData::EDITING );
1967 Event event( Event::TAP_EVENT );
1969 event.p2.mFloat = x;
1970 event.p3.mFloat = y;
1971 mImpl->mEventData->mEventQueue.push_back( event );
1973 mImpl->RequestRelayout();
1975 else if( !mImpl->IsShowingRealText() )
1977 Event event( Event::LONG_PRESS_EVENT );
1978 event.p1.mInt = state;
1979 event.p2.mFloat = x;
1980 event.p3.mFloat = y;
1981 mImpl->mEventData->mEventQueue.push_back( event );
1982 mImpl->RequestRelayout();
1984 else if( !mImpl->IsClipboardVisible() )
1986 // Reset the imf manager to commit the pre-edit before selecting the text.
1987 mImpl->ResetImfManager();
1989 Event event( Event::LONG_PRESS_EVENT );
1990 event.p1.mInt = state;
1991 event.p2.mFloat = x;
1992 event.p3.mFloat = y;
1993 mImpl->mEventData->mEventQueue.push_back( event );
1994 mImpl->RequestRelayout();
1996 mImpl->mEventData->mIsLeftHandleSelected = true;
1997 mImpl->mEventData->mIsRightHandleSelected = true;
2002 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2004 // Whether the text needs to be relaid-out.
2005 bool requestRelayout = false;
2007 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2008 bool retrieveText = false;
2009 bool retrieveCursor = false;
2011 switch( imfEvent.eventName )
2013 case ImfManager::COMMIT:
2015 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2016 requestRelayout = true;
2017 retrieveCursor = true;
2020 case ImfManager::PREEDIT:
2022 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2023 requestRelayout = true;
2024 retrieveCursor = true;
2027 case ImfManager::DELETESURROUNDING:
2029 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2030 imfEvent.numberOfChars,
2031 DONT_UPDATE_INPUT_STYLE );
2035 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2036 !mImpl->IsPlaceholderAvailable() )
2038 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2042 ShowPlaceholderText();
2044 mImpl->mEventData->mUpdateCursorPosition = true;
2045 mImpl->mEventData->mScrollAfterDelete = true;
2047 requestRelayout = true;
2051 case ImfManager::GETSURROUNDING:
2053 retrieveText = true;
2054 retrieveCursor = true;
2057 case ImfManager::VOID:
2064 if( requestRelayout )
2066 mImpl->mOperationsPending = ALL_OPERATIONS;
2067 mImpl->RequestRelayout();
2071 CharacterIndex cursorPosition = 0u;
2072 Length numberOfWhiteSpaces = 0u;
2074 if( retrieveCursor )
2076 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2078 cursorPosition = mImpl->GetLogicalCursorPosition();
2080 if( cursorPosition < numberOfWhiteSpaces )
2082 cursorPosition = 0u;
2086 cursorPosition -= numberOfWhiteSpaces;
2092 mImpl->GetText( numberOfWhiteSpaces, text );
2095 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2097 if( requestRelayout &&
2098 ( NULL != mImpl->mEditableControlInterface ) )
2100 // Do this last since it provides callbacks into application code
2101 mImpl->mEditableControlInterface->TextChanged();
2104 return callbackData;
2107 void Controller::PasteClipboardItemEvent()
2109 // Retrieve the clipboard contents first
2110 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2111 std::string stringToPaste( notifier.GetContent() );
2113 // Commit the current pre-edit text; the contents of the clipboard should be appended
2114 mImpl->ResetImfManager();
2116 // Temporary disable hiding clipboard
2117 mImpl->SetClipboardHideEnable( false );
2120 PasteText( stringToPaste );
2122 mImpl->SetClipboardHideEnable( true );
2125 // protected : Inherit from Text::Decorator::ControllerInterface.
2127 void Controller::GetTargetSize( Vector2& targetSize )
2129 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2132 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2134 if( NULL != mImpl->mEditableControlInterface )
2136 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2140 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2142 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2144 if( NULL != mImpl->mEventData )
2146 switch( handleType )
2150 Event event( Event::GRAB_HANDLE_EVENT );
2151 event.p1.mUint = state;
2152 event.p2.mFloat = x;
2153 event.p3.mFloat = y;
2155 mImpl->mEventData->mEventQueue.push_back( event );
2158 case LEFT_SELECTION_HANDLE:
2160 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2161 event.p1.mUint = state;
2162 event.p2.mFloat = x;
2163 event.p3.mFloat = y;
2165 mImpl->mEventData->mEventQueue.push_back( event );
2168 case RIGHT_SELECTION_HANDLE:
2170 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2171 event.p1.mUint = state;
2172 event.p2.mFloat = x;
2173 event.p3.mFloat = y;
2175 mImpl->mEventData->mEventQueue.push_back( event );
2178 case LEFT_SELECTION_HANDLE_MARKER:
2179 case RIGHT_SELECTION_HANDLE_MARKER:
2181 // Markers do not move the handles.
2184 case HANDLE_TYPE_COUNT:
2186 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2190 mImpl->RequestRelayout();
2194 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2196 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2198 if( NULL == mImpl->mEventData )
2205 case Toolkit::TextSelectionPopup::CUT:
2207 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2208 mImpl->mOperationsPending = ALL_OPERATIONS;
2210 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2211 !mImpl->IsPlaceholderAvailable() )
2213 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2217 ShowPlaceholderText();
2220 mImpl->mEventData->mUpdateCursorPosition = true;
2221 mImpl->mEventData->mScrollAfterDelete = true;
2223 mImpl->RequestRelayout();
2225 if( NULL != mImpl->mEditableControlInterface )
2227 mImpl->mEditableControlInterface->TextChanged();
2231 case Toolkit::TextSelectionPopup::COPY:
2233 mImpl->SendSelectionToClipboard( false ); // Text not modified
2235 mImpl->mEventData->mUpdateCursorPosition = true;
2237 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2240 case Toolkit::TextSelectionPopup::PASTE:
2242 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2245 case Toolkit::TextSelectionPopup::SELECT:
2247 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2249 if( mImpl->mEventData->mSelectionEnabled )
2251 // Creates a SELECT event.
2252 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2256 case Toolkit::TextSelectionPopup::SELECT_ALL:
2258 // Creates a SELECT_ALL event
2259 SelectEvent( 0.f, 0.f, true );
2262 case Toolkit::TextSelectionPopup::CLIPBOARD:
2264 mImpl->ShowClipboard();
2267 case Toolkit::TextSelectionPopup::NONE:
2275 // private : Update.
2277 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2279 bool removedPrevious( false );
2280 bool maxLengthReached( false );
2282 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2284 if( NULL == mImpl->mEventData )
2289 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2290 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2291 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2293 // TODO: At the moment the underline runs are only for pre-edit.
2294 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2296 // Keep the current number of characters.
2297 const Length currentNumberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u;
2299 // Remove the previous IMF pre-edit.
2300 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2302 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2303 mImpl->mEventData->mPreEditLength,
2304 DONT_UPDATE_INPUT_STYLE );
2306 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2307 mImpl->mEventData->mPreEditLength = 0u;
2311 // Remove the previous Selection.
2312 removedPrevious = RemoveSelectedText();
2315 Vector<Character> utf32Characters;
2316 Length characterCount = 0u;
2320 // Convert text into UTF-32
2321 utf32Characters.Resize( text.size() );
2323 // This is a bit horrible but std::string returns a (signed) char*
2324 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2326 // Transform a text array encoded in utf8 into an array encoded in utf32.
2327 // It returns the actual number of characters.
2328 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2329 utf32Characters.Resize( characterCount );
2331 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2332 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2335 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2337 // The placeholder text is no longer needed
2338 if( mImpl->IsShowingPlaceholderText() )
2343 mImpl->ChangeState( EventData::EDITING );
2345 // Handle the IMF (predicitive text) state changes
2346 if( COMMIT == type )
2348 // IMF manager is no longer handling key-events
2349 mImpl->ClearPreEditFlag();
2353 if( !mImpl->mEventData->mPreEditFlag )
2355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2357 // Record the start of the pre-edit text
2358 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2361 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2362 mImpl->mEventData->mPreEditFlag = true;
2364 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2367 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2369 // Restrict new text to fit within Maximum characters setting.
2370 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2371 maxLengthReached = ( characterCount > maxSizeOfNewText );
2373 // The cursor position.
2374 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2376 // Update the text's style.
2378 // Updates the text style runs by adding characters.
2379 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2381 // Get the character index from the cursor index.
2382 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2384 // Retrieve the text's style for the given index.
2386 mImpl->RetrieveDefaultInputStyle( style );
2387 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2389 // Whether to add a new text color run.
2390 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2392 // Whether to add a new font run.
2393 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2394 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2395 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2396 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2397 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2402 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2403 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2405 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2406 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2407 colorRun.characterRun.characterIndex = cursorIndex;
2408 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2411 if( addFontNameRun ||
2417 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2418 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2420 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2422 if( addFontNameRun )
2424 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2425 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2426 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2427 fontDescriptionRun.familyDefined = true;
2429 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2432 if( addFontWeightRun )
2434 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2435 fontDescriptionRun.weightDefined = true;
2438 if( addFontWidthRun )
2440 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2441 fontDescriptionRun.widthDefined = true;
2444 if( addFontSlantRun )
2446 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2447 fontDescriptionRun.slantDefined = true;
2450 if( addFontSizeRun )
2452 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2453 fontDescriptionRun.sizeDefined = true;
2456 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2457 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2460 // Insert at current cursor position.
2461 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2463 if( cursorIndex < numberOfCharactersInModel )
2465 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2469 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2472 // Mark the first paragraph to be updated.
2473 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2474 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2476 // Update the cursor index.
2477 cursorIndex += maxSizeOfNewText;
2479 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 );
2482 const Length numberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mModel->mLogicalModel->mText.Count() : 0u;
2484 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2485 mImpl->IsPlaceholderAvailable() )
2487 // Show place-holder if empty after removing the pre-edit text
2488 ShowPlaceholderText();
2489 mImpl->mEventData->mUpdateCursorPosition = true;
2490 mImpl->ClearPreEditFlag();
2492 else if( removedPrevious ||
2493 ( 0 != utf32Characters.Count() ) )
2495 // Queue an inserted event
2496 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2498 mImpl->mEventData->mUpdateCursorPosition = true;
2499 if( numberOfCharacters < currentNumberOfCharacters )
2501 mImpl->mEventData->mScrollAfterDelete = true;
2505 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2509 if( maxLengthReached )
2511 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
2513 mImpl->ResetImfManager();
2515 if( NULL != mImpl->mEditableControlInterface )
2517 // Do this last since it provides callbacks into application code
2518 mImpl->mEditableControlInterface->MaxLengthReached();
2523 void Controller::PasteText( const std::string& stringToPaste )
2525 InsertText( stringToPaste, Text::Controller::COMMIT );
2526 mImpl->ChangeState( EventData::EDITING );
2527 mImpl->RequestRelayout();
2529 if( NULL != mImpl->mEditableControlInterface )
2531 // Do this last since it provides callbacks into application code
2532 mImpl->mEditableControlInterface->TextChanged();
2536 bool Controller::RemoveText( int cursorOffset,
2537 int numberOfCharacters,
2538 UpdateInputStyleType type )
2540 bool removed = false;
2542 if( NULL == mImpl->mEventData )
2547 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2548 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2550 if( !mImpl->IsShowingPlaceholderText() )
2552 // Delete at current cursor position
2553 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
2554 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2556 CharacterIndex cursorIndex = oldCursorIndex;
2558 // Validate the cursor position & number of characters
2559 if( static_cast< CharacterIndex >( std::abs( cursorOffset ) ) <= cursorIndex )
2561 cursorIndex = oldCursorIndex + cursorOffset;
2564 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2566 numberOfCharacters = currentText.Count() - cursorIndex;
2569 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.
2570 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2572 // Mark the paragraphs to be updated.
2573 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2574 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2576 // Update the input style and remove the text's style before removing the text.
2578 if( UPDATE_INPUT_STYLE == type )
2580 // Keep a copy of the current input style.
2581 InputStyle currentInputStyle;
2582 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2584 // Set first the default input style.
2585 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2587 // Update the input style.
2588 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2590 // Compare if the input style has changed.
2591 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2593 if( hasInputStyleChanged )
2595 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2596 // Queue the input style changed signal.
2597 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2601 // Updates the text style runs by removing characters. Runs with no characters are removed.
2602 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2604 // Remove the characters.
2605 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2606 Vector<Character>::Iterator last = first + numberOfCharacters;
2608 currentText.Erase( first, last );
2610 // Cursor position retreat
2611 oldCursorIndex = cursorIndex;
2613 mImpl->mEventData->mScrollAfterDelete = true;
2615 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2623 bool Controller::RemoveSelectedText()
2625 bool textRemoved( false );
2627 if( EventData::SELECTING == mImpl->mEventData->mState )
2629 std::string removedString;
2630 mImpl->RetrieveSelection( removedString, true );
2632 if( !removedString.empty() )
2635 mImpl->ChangeState( EventData::EDITING );
2642 // private : Relayout.
2644 bool Controller::DoRelayout( const Size& size,
2645 OperationsMask operationsRequired,
2648 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2649 bool viewUpdated( false );
2651 // Calculate the operations to be done.
2652 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2654 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2655 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2657 // Get the current layout size.
2658 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2660 if( NO_OPERATION != ( LAYOUT & operations ) )
2662 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2664 // Some vectors with data needed to layout and reorder may be void
2665 // after the first time the text has been laid out.
2666 // Fill the vectors again.
2668 // Calculate the number of glyphs to layout.
2669 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
2670 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
2671 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2672 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2674 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2675 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2676 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2677 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
2679 if( 0u == totalNumberOfGlyphs )
2681 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2683 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
2686 // Nothing else to do if there is no glyphs.
2687 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2691 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
2692 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
2693 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
2694 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
2695 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
2696 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
2697 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
2699 // Set the layout parameters.
2700 Layout::Parameters layoutParameters( size,
2702 lineBreakInfo.Begin(),
2703 wordBreakInfo.Begin(),
2704 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2706 glyphsToCharactersMap.Begin(),
2707 charactersPerGlyph.Begin(),
2708 charactersToGlyphBuffer,
2709 glyphsPerCharacterBuffer,
2710 totalNumberOfGlyphs,
2711 mImpl->mModel->mHorizontalAlignment );
2713 // Resize the vector of positions to have the same size than the vector of glyphs.
2714 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
2715 glyphPositions.Resize( totalNumberOfGlyphs );
2717 // Whether the last character is a new paragraph character.
2718 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
2719 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2721 // The initial glyph and the number of glyphs to layout.
2722 layoutParameters.startGlyphIndex = startGlyphIndex;
2723 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2724 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2725 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2727 // Update the visual model.
2729 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2731 mImpl->mModel->mVisualModel->mLines,
2733 mImpl->mModel->mElideEnabled );
2735 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2739 layoutSize = newLayoutSize;
2741 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2743 mImpl->mAutoScrollDirectionRTL = false;
2746 // Reorder the lines
2747 if( NO_OPERATION != ( REORDER & operations ) )
2749 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
2750 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
2752 // Check first if there are paragraphs with bidirectional info.
2753 if( 0u != bidirectionalInfo.Count() )
2756 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
2758 // Reorder the lines.
2759 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2760 ReorderLines( bidirectionalInfo,
2762 requestedNumberOfCharacters,
2763 mImpl->mModel->mVisualModel->mLines,
2764 bidirectionalLineInfo );
2766 // Set the bidirectional info per line into the layout parameters.
2767 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2768 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2770 // Re-layout the text. Reorder those lines with right to left characters.
2771 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2773 requestedNumberOfCharacters,
2776 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2778 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
2781 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2787 // Sets the layout size.
2788 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2790 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
2795 if( NO_OPERATION != ( ALIGN & operations ) )
2797 // The laid-out lines.
2798 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
2800 // Need to align with the control's size as the text may contain lines
2801 // starting either with left to right text or right to left.
2802 mImpl->mLayoutEngine.Align( size,
2804 requestedNumberOfCharacters,
2805 mImpl->mModel->mHorizontalAlignment,
2807 mImpl->mModel->mAlignmentOffset );
2811 #if defined(DEBUG_ENABLED)
2812 std::string currentText;
2813 GetText( currentText );
2814 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2816 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2820 void Controller::CalculateVerticalOffset( const Size& controlSize )
2822 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2824 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2826 // Get the line height of the default font.
2827 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2830 switch( mImpl->mModel->mVerticalAlignment )
2832 case Layout::VERTICAL_ALIGN_TOP:
2834 mImpl->mModel->mScrollPosition.y = 0.f;
2837 case Layout::VERTICAL_ALIGN_CENTER:
2839 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2842 case Layout::VERTICAL_ALIGN_BOTTOM:
2844 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
2850 // private : Events.
2852 void Controller::ProcessModifyEvents()
2854 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
2856 if( 0u == events.Count() )
2862 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
2863 endIt = events.End();
2867 const ModifyEvent& event = *it;
2869 if( ModifyEvent::TEXT_REPLACED == event.type )
2871 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
2872 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
2874 TextReplacedEvent();
2876 else if( ModifyEvent::TEXT_INSERTED == event.type )
2878 TextInsertedEvent();
2880 else if( ModifyEvent::TEXT_DELETED == event.type )
2882 // Placeholder-text cannot be deleted
2883 if( !mImpl->IsShowingPlaceholderText() )
2890 if( NULL != mImpl->mEventData )
2892 // When the text is being modified, delay cursor blinking
2893 mImpl->mEventData->mDecorator->DelayCursorBlink();
2896 // Discard temporary text
2900 void Controller::TextReplacedEvent()
2902 // The natural size needs to be re-calculated.
2903 mImpl->mRecalculateNaturalSize = true;
2905 // Apply modifications to the model
2906 mImpl->mOperationsPending = ALL_OPERATIONS;
2909 void Controller::TextInsertedEvent()
2911 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
2913 if( NULL == mImpl->mEventData )
2918 mImpl->mEventData->mCheckScrollAmount = true;
2920 // The natural size needs to be re-calculated.
2921 mImpl->mRecalculateNaturalSize = true;
2923 // Apply modifications to the model; TODO - Optimize this
2924 mImpl->mOperationsPending = ALL_OPERATIONS;
2927 void Controller::TextDeletedEvent()
2929 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
2931 if( NULL == mImpl->mEventData )
2936 mImpl->mEventData->mCheckScrollAmount = true;
2938 // The natural size needs to be re-calculated.
2939 mImpl->mRecalculateNaturalSize = true;
2941 // Apply modifications to the model; TODO - Optimize this
2942 mImpl->mOperationsPending = ALL_OPERATIONS;
2945 void Controller::SelectEvent( float x, float y, bool selectAll )
2947 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
2949 if( NULL != mImpl->mEventData )
2953 Event event( Event::SELECT_ALL );
2954 mImpl->mEventData->mEventQueue.push_back( event );
2958 Event event( Event::SELECT );
2959 event.p2.mFloat = x;
2960 event.p3.mFloat = y;
2961 mImpl->mEventData->mEventQueue.push_back( event );
2964 mImpl->mEventData->mCheckScrollAmount = true;
2965 mImpl->mEventData->mIsLeftHandleSelected = true;
2966 mImpl->mEventData->mIsRightHandleSelected = true;
2967 mImpl->RequestRelayout();
2971 bool Controller::BackspaceKeyEvent()
2973 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
2975 bool removed = false;
2977 if( NULL == mImpl->mEventData )
2982 // IMF manager is no longer handling key-events
2983 mImpl->ClearPreEditFlag();
2985 if( EventData::SELECTING == mImpl->mEventData->mState )
2987 removed = RemoveSelectedText();
2989 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
2991 // Remove the character before the current cursor position
2992 removed = RemoveText( -1,
2994 UPDATE_INPUT_STYLE );
2999 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3000 !mImpl->IsPlaceholderAvailable() )
3002 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3006 ShowPlaceholderText();
3008 mImpl->mEventData->mUpdateCursorPosition = true;
3009 mImpl->mEventData->mScrollAfterDelete = true;
3015 // private : Helpers.
3017 void Controller::ResetText()
3020 mImpl->mModel->mLogicalModel->mText.Clear();
3022 // We have cleared everything including the placeholder-text
3023 mImpl->PlaceholderCleared();
3025 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3026 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3027 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3029 // Clear any previous text.
3030 mImpl->mTextUpdateInfo.mClearAll = true;
3032 // The natural size needs to be re-calculated.
3033 mImpl->mRecalculateNaturalSize = true;
3035 // Apply modifications to the model
3036 mImpl->mOperationsPending = ALL_OPERATIONS;
3039 void Controller::ShowPlaceholderText()
3041 if( mImpl->IsPlaceholderAvailable() )
3043 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3045 if( NULL == mImpl->mEventData )
3050 mImpl->mEventData->mIsShowingPlaceholderText = true;
3052 // Disable handles when showing place-holder text
3053 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3054 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3055 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3057 const char* text( NULL );
3060 // TODO - Switch placeholder text styles when changing state
3061 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3062 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3064 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3065 size = mImpl->mEventData->mPlaceholderTextActive.size();
3069 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3070 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3073 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3074 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3076 // Reset model for showing placeholder.
3077 mImpl->mModel->mLogicalModel->mText.Clear();
3078 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3080 // Convert text into UTF-32
3081 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3082 utf32Characters.Resize( size );
3084 // This is a bit horrible but std::string returns a (signed) char*
3085 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3087 // Transform a text array encoded in utf8 into an array encoded in utf32.
3088 // It returns the actual number of characters.
3089 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3090 utf32Characters.Resize( characterCount );
3092 // The characters to be added.
3093 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3095 // Reset the cursor position
3096 mImpl->mEventData->mPrimaryCursorPosition = 0;
3098 // The natural size needs to be re-calculated.
3099 mImpl->mRecalculateNaturalSize = true;
3101 // Apply modifications to the model
3102 mImpl->mOperationsPending = ALL_OPERATIONS;
3104 // Update the rest of the model during size negotiation
3105 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3109 void Controller::ClearFontData()
3111 if( mImpl->mFontDefaults )
3113 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3116 // Set flags to update the model.
3117 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3118 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3119 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3121 mImpl->mTextUpdateInfo.mClearAll = true;
3122 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3123 mImpl->mRecalculateNaturalSize = true;
3125 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3130 UPDATE_LAYOUT_SIZE |
3135 void Controller::ClearStyleData()
3137 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3138 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3141 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3143 // Reset the cursor position
3144 if( NULL != mImpl->mEventData )
3146 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3148 // Update the cursor if it's in editing mode.
3149 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3151 mImpl->mEventData->mUpdateCursorPosition = true;
3156 void Controller::ResetScrollPosition()
3158 if( NULL != mImpl->mEventData )
3160 // Reset the scroll position.
3161 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3162 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3166 // private : Private contructors & copy operator.
3168 Controller::Controller()
3171 mImpl = new Controller::Impl( NULL, NULL );
3174 Controller::Controller( ControlInterface* controlInterface )
3176 mImpl = new Controller::Impl( controlInterface, NULL );
3179 Controller::Controller( ControlInterface* controlInterface,
3180 EditableControlInterface* editableControlInterface )
3182 mImpl = new Controller::Impl( controlInterface,
3183 editableControlInterface );
3186 // The copy constructor and operator are left unimplemented.
3188 // protected : Destructor.
3190 Controller::~Controller()
3197 } // namespace Toolkit