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 )
125 if( NULL == mImpl->mEventData )
127 mImpl->mEventData = new EventData( decorator );
131 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
133 // Metrics for bitmap & vector based glyphs are different
134 mImpl->mMetrics->SetGlyphType( glyphType );
136 // Clear the font-specific data
139 mImpl->RequestRelayout();
142 void Controller::SetMarkupProcessorEnabled( bool enable )
144 mImpl->mMarkupProcessorEnabled = enable;
147 bool Controller::IsMarkupProcessorEnabled() const
149 return mImpl->mMarkupProcessorEnabled;
152 void Controller::SetAutoScrollEnabled( bool enable )
154 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == LayoutEngine::SINGLE_LINE_BOX)?"true":"false", this );
156 if ( mImpl->mLayoutEngine.GetLayout() == LayoutEngine::SINGLE_LINE_BOX )
160 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
161 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
171 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
172 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
179 mImpl->mAutoScrollEnabled = enable;
180 mImpl->RequestRelayout();
184 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
185 mImpl->mAutoScrollEnabled = false;
189 bool Controller::IsAutoScrollEnabled() const
191 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", (mImpl->mAutoScrollEnabled)?"true":"false" );
193 return mImpl->mAutoScrollEnabled;
196 CharacterDirection Controller::GetAutoScrollDirection() const
198 return mImpl->mAutoScrollDirectionRTL;
201 float Controller::GetAutoScrollLineAlignment() const
205 if( mImpl->mVisualModel &&
206 ( 0u != mImpl->mVisualModel->mLines.Count() ) )
208 offset = ( *mImpl->mVisualModel->mLines.Begin() ).alignmentOffset;
214 void Controller::SetHorizontalScrollEnabled( bool enable )
216 if( ( NULL != mImpl->mEventData ) &&
217 mImpl->mEventData->mDecorator )
219 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
223 bool Controller::IsHorizontalScrollEnabled() const
225 if( ( NULL != mImpl->mEventData ) &&
226 mImpl->mEventData->mDecorator )
228 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
234 void Controller::SetVerticalScrollEnabled( bool enable )
236 if( ( NULL != mImpl->mEventData ) &&
237 mImpl->mEventData->mDecorator )
239 if( mImpl->mEventData->mDecorator )
241 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
246 bool Controller::IsVerticalScrollEnabled() const
248 if( ( NULL != mImpl->mEventData ) &&
249 mImpl->mEventData->mDecorator )
251 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
257 void Controller::SetSmoothHandlePanEnabled( bool enable )
259 if( ( NULL != mImpl->mEventData ) &&
260 mImpl->mEventData->mDecorator )
262 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
266 bool Controller::IsSmoothHandlePanEnabled() const
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
277 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
279 mImpl->mMaximumNumberOfCharacters = maxCharacters;
282 int Controller::GetMaximumNumberOfCharacters()
284 return mImpl->mMaximumNumberOfCharacters;
287 void Controller::SetEnableCursorBlink( bool enable )
289 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
291 if( NULL != mImpl->mEventData )
293 mImpl->mEventData->mCursorBlinkEnabled = enable;
296 mImpl->mEventData->mDecorator )
298 mImpl->mEventData->mDecorator->StopCursorBlink();
303 bool Controller::GetEnableCursorBlink() const
305 if( NULL != mImpl->mEventData )
307 return mImpl->mEventData->mCursorBlinkEnabled;
313 void Controller::SetMultiLineEnabled( bool enable )
315 const LayoutEngine::Layout layout = enable ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX;
317 if( layout != mImpl->mLayoutEngine.GetLayout() )
319 // Set the layout type.
320 mImpl->mLayoutEngine.SetLayout( layout );
322 // Set the flags to redo the layout operations
323 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
328 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
330 mImpl->RequestRelayout();
334 bool Controller::IsMultiLineEnabled() const
336 return LayoutEngine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
339 void Controller::SetHorizontalAlignment( LayoutEngine::HorizontalAlignment alignment )
341 if( alignment != mImpl->mLayoutEngine.GetHorizontalAlignment() )
343 // Set the alignment.
344 mImpl->mLayoutEngine.SetHorizontalAlignment( alignment );
346 // Set the flag to redo the alignment operation.
347 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
349 mImpl->RequestRelayout();
353 LayoutEngine::HorizontalAlignment Controller::GetHorizontalAlignment() const
355 return mImpl->mLayoutEngine.GetHorizontalAlignment();
358 void Controller::SetVerticalAlignment( LayoutEngine::VerticalAlignment alignment )
360 if( alignment != mImpl->mLayoutEngine.GetVerticalAlignment() )
362 // Set the alignment.
363 mImpl->mLayoutEngine.SetVerticalAlignment( alignment );
365 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
367 mImpl->RequestRelayout();
371 LayoutEngine::VerticalAlignment Controller::GetVerticalAlignment() const
373 return mImpl->mLayoutEngine.GetVerticalAlignment();
378 void Controller::SetText( const std::string& text )
380 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
382 // Reset keyboard as text changed
383 mImpl->ResetImfManager();
385 // Remove the previously set text and style.
391 CharacterIndex lastCursorIndex = 0u;
393 if( NULL != mImpl->mEventData )
395 // If popup shown then hide it by switching to Editing state
396 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
397 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
398 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
399 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
401 mImpl->ChangeState( EventData::EDITING );
407 mImpl->mVisualModel->SetTextColor( mImpl->mTextColor );
409 MarkupProcessData markupProcessData( mImpl->mLogicalModel->mColorRuns,
410 mImpl->mLogicalModel->mFontDescriptionRuns );
412 Length textSize = 0u;
413 const uint8_t* utf8 = NULL;
414 if( mImpl->mMarkupProcessorEnabled )
416 ProcessMarkupString( text, markupProcessData );
417 textSize = markupProcessData.markupProcessedText.size();
419 // This is a bit horrible but std::string returns a (signed) char*
420 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
424 textSize = text.size();
426 // This is a bit horrible but std::string returns a (signed) char*
427 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
430 // Convert text into UTF-32
431 Vector<Character>& utf32Characters = mImpl->mLogicalModel->mText;
432 utf32Characters.Resize( textSize );
434 // Transform a text array encoded in utf8 into an array encoded in utf32.
435 // It returns the actual number of characters.
436 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
437 utf32Characters.Resize( characterCount );
439 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
440 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mLogicalModel->mText.Count() );
442 // The characters to be added.
443 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mLogicalModel->mText.Count();
445 // To reset the cursor position
446 lastCursorIndex = characterCount;
448 // Update the rest of the model during size negotiation
449 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
451 // The natural size needs to be re-calculated.
452 mImpl->mRecalculateNaturalSize = true;
454 // Apply modifications to the model
455 mImpl->mOperationsPending = ALL_OPERATIONS;
459 ShowPlaceholderText();
462 // Resets the cursor position.
463 ResetCursorPosition( lastCursorIndex );
465 // Scrolls the text to make the cursor visible.
466 ResetScrollPosition();
468 mImpl->RequestRelayout();
470 if( NULL != mImpl->mEventData )
472 // Cancel previously queued events
473 mImpl->mEventData->mEventQueue.clear();
476 // Do this last since it provides callbacks into application code.
477 if( NULL != mImpl->mEditableControlInterface )
479 mImpl->mEditableControlInterface->TextChanged();
483 void Controller::GetText( std::string& text ) const
485 if( !mImpl->IsShowingPlaceholderText() )
487 // Retrieves the text string.
488 mImpl->GetText( 0u, text );
492 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
496 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
498 if( NULL != mImpl->mEventData )
500 if( PLACEHOLDER_TYPE_INACTIVE == type )
502 mImpl->mEventData->mPlaceholderTextInactive = text;
506 mImpl->mEventData->mPlaceholderTextActive = text;
509 // Update placeholder if there is no text
510 if( mImpl->IsShowingPlaceholderText() ||
511 ( 0u == mImpl->mLogicalModel->mText.Count() ) )
513 ShowPlaceholderText();
518 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
520 if( NULL != mImpl->mEventData )
522 if( PLACEHOLDER_TYPE_INACTIVE == type )
524 text = mImpl->mEventData->mPlaceholderTextInactive;
528 text = mImpl->mEventData->mPlaceholderTextActive;
533 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
535 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
537 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
539 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
540 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
544 mImpl->RequestRelayout();
548 // public : Default style & Input style
550 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
552 if( NULL == mImpl->mFontDefaults )
554 mImpl->mFontDefaults = new FontDefaults();
557 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
558 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
559 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
561 // Clear the font-specific data
564 mImpl->RequestRelayout();
567 const std::string& Controller::GetDefaultFontFamily() const
569 if( NULL != mImpl->mFontDefaults )
571 return mImpl->mFontDefaults->mFontDescription.family;
577 void Controller::SetDefaultFontWeight( FontWeight weight )
579 if( NULL == mImpl->mFontDefaults )
581 mImpl->mFontDefaults = new FontDefaults();
584 mImpl->mFontDefaults->mFontDescription.weight = weight;
585 mImpl->mFontDefaults->weightDefined = true;
587 // Clear the font-specific data
590 mImpl->RequestRelayout();
593 bool Controller::IsDefaultFontWeightDefined() const
595 return mImpl->mFontDefaults->weightDefined;
598 FontWeight Controller::GetDefaultFontWeight() const
600 if( NULL != mImpl->mFontDefaults )
602 return mImpl->mFontDefaults->mFontDescription.weight;
605 return TextAbstraction::FontWeight::NORMAL;
608 void Controller::SetDefaultFontWidth( FontWidth width )
610 if( NULL == mImpl->mFontDefaults )
612 mImpl->mFontDefaults = new FontDefaults();
615 mImpl->mFontDefaults->mFontDescription.width = width;
616 mImpl->mFontDefaults->widthDefined = true;
618 // Clear the font-specific data
621 mImpl->RequestRelayout();
624 bool Controller::IsDefaultFontWidthDefined() const
626 return mImpl->mFontDefaults->widthDefined;
629 FontWidth Controller::GetDefaultFontWidth() const
631 if( NULL != mImpl->mFontDefaults )
633 return mImpl->mFontDefaults->mFontDescription.width;
636 return TextAbstraction::FontWidth::NORMAL;
639 void Controller::SetDefaultFontSlant( FontSlant slant )
641 if( NULL == mImpl->mFontDefaults )
643 mImpl->mFontDefaults = new FontDefaults();
646 mImpl->mFontDefaults->mFontDescription.slant = slant;
647 mImpl->mFontDefaults->slantDefined = true;
649 // Clear the font-specific data
652 mImpl->RequestRelayout();
655 bool Controller::IsDefaultFontSlantDefined() const
657 return mImpl->mFontDefaults->slantDefined;
660 FontSlant Controller::GetDefaultFontSlant() const
662 if( NULL != mImpl->mFontDefaults )
664 return mImpl->mFontDefaults->mFontDescription.slant;
667 return TextAbstraction::FontSlant::NORMAL;
670 void Controller::SetDefaultPointSize( float pointSize )
672 if( NULL == mImpl->mFontDefaults )
674 mImpl->mFontDefaults = new FontDefaults();
677 mImpl->mFontDefaults->mDefaultPointSize = pointSize;
678 mImpl->mFontDefaults->sizeDefined = true;
680 // Clear the font-specific data
683 mImpl->RequestRelayout();
686 float Controller::GetDefaultPointSize() const
688 if( NULL != mImpl->mFontDefaults )
690 return mImpl->mFontDefaults->mDefaultPointSize;
696 void Controller::SetTextColor( const Vector4& textColor )
698 mImpl->mTextColor = textColor;
700 if( !mImpl->IsShowingPlaceholderText() )
702 mImpl->mVisualModel->SetTextColor( textColor );
704 mImpl->RequestRelayout();
708 const Vector4& Controller::GetTextColor() const
710 return mImpl->mTextColor;
713 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
715 if( NULL != mImpl->mEventData )
717 mImpl->mEventData->mPlaceholderTextColor = textColor;
720 if( mImpl->IsShowingPlaceholderText() )
722 mImpl->mVisualModel->SetTextColor( textColor );
723 mImpl->RequestRelayout();
727 const Vector4& Controller::GetPlaceholderTextColor() const
729 if( NULL != mImpl->mEventData )
731 return mImpl->mEventData->mPlaceholderTextColor;
737 void Controller::SetShadowOffset( const Vector2& shadowOffset )
739 mImpl->mVisualModel->SetShadowOffset( shadowOffset );
741 mImpl->RequestRelayout();
744 const Vector2& Controller::GetShadowOffset() const
746 return mImpl->mVisualModel->GetShadowOffset();
749 void Controller::SetShadowColor( const Vector4& shadowColor )
751 mImpl->mVisualModel->SetShadowColor( shadowColor );
753 mImpl->RequestRelayout();
756 const Vector4& Controller::GetShadowColor() const
758 return mImpl->mVisualModel->GetShadowColor();
761 void Controller::SetDefaultShadowProperties( const std::string& shadowProperties )
763 if( NULL == mImpl->mShadowDefaults )
765 mImpl->mShadowDefaults = new ShadowDefaults();
768 mImpl->mShadowDefaults->properties = shadowProperties;
771 const std::string& Controller::GetDefaultShadowProperties() const
773 if( NULL != mImpl->mShadowDefaults )
775 return mImpl->mShadowDefaults->properties;
781 void Controller::SetUnderlineColor( const Vector4& color )
783 mImpl->mVisualModel->SetUnderlineColor( color );
785 mImpl->RequestRelayout();
788 const Vector4& Controller::GetUnderlineColor() const
790 return mImpl->mVisualModel->GetUnderlineColor();
793 void Controller::SetUnderlineEnabled( bool enabled )
795 mImpl->mVisualModel->SetUnderlineEnabled( enabled );
797 mImpl->RequestRelayout();
800 bool Controller::IsUnderlineEnabled() const
802 return mImpl->mVisualModel->IsUnderlineEnabled();
805 void Controller::SetUnderlineHeight( float height )
807 mImpl->mVisualModel->SetUnderlineHeight( height );
809 mImpl->RequestRelayout();
812 float Controller::GetUnderlineHeight() const
814 return mImpl->mVisualModel->GetUnderlineHeight();
817 void Controller::SetDefaultUnderlineProperties( const std::string& underlineProperties )
819 if( NULL == mImpl->mUnderlineDefaults )
821 mImpl->mUnderlineDefaults = new UnderlineDefaults();
824 mImpl->mUnderlineDefaults->properties = underlineProperties;
827 const std::string& Controller::GetDefaultUnderlineProperties() const
829 if( NULL != mImpl->mUnderlineDefaults )
831 return mImpl->mUnderlineDefaults->properties;
837 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
839 if( NULL == mImpl->mEmbossDefaults )
841 mImpl->mEmbossDefaults = new EmbossDefaults();
844 mImpl->mEmbossDefaults->properties = embossProperties;
847 const std::string& Controller::GetDefaultEmbossProperties() const
849 if( NULL != mImpl->mEmbossDefaults )
851 return mImpl->mEmbossDefaults->properties;
857 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
859 if( NULL == mImpl->mOutlineDefaults )
861 mImpl->mOutlineDefaults = new OutlineDefaults();
864 mImpl->mOutlineDefaults->properties = outlineProperties;
867 const std::string& Controller::GetDefaultOutlineProperties() const
869 if( NULL != mImpl->mOutlineDefaults )
871 return mImpl->mOutlineDefaults->properties;
877 void Controller::SetDefaultLineSpacing( float lineSpacing )
879 //TODO finish implementation
880 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
883 float Controller::GetDefaultLineSpacing() const
885 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
888 void Controller::SetInputColor( const Vector4& color )
890 if( NULL != mImpl->mEventData )
892 mImpl->mEventData->mInputStyle.textColor = color;
893 mImpl->mEventData->mInputStyle.isDefaultColor = false;
895 if( EventData::SELECTING == mImpl->mEventData->mState )
897 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
899 // Get start and end position of selection
900 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
901 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
903 // Add the color run.
904 const VectorBase::SizeType numberOfRuns = mImpl->mLogicalModel->mColorRuns.Count();
905 mImpl->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
907 ColorRun& colorRun = *( mImpl->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
908 colorRun.color = color;
909 colorRun.characterRun.characterIndex = startOfSelectedText;
910 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
912 // Request to relayout.
913 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
914 mImpl->RequestRelayout();
916 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
917 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
918 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
923 const Vector4& Controller::GetInputColor() const
925 if( NULL != mImpl->mEventData )
927 return mImpl->mEventData->mInputStyle.textColor;
930 // Return the default text's color if there is no EventData.
931 return mImpl->mTextColor;
935 void Controller::SetInputFontFamily( const std::string& fontFamily )
937 if( NULL != mImpl->mEventData )
939 mImpl->mEventData->mInputStyle.familyName = fontFamily;
940 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
942 if( EventData::SELECTING == mImpl->mEventData->mState )
944 CharacterIndex startOfSelectedText = 0u;
945 Length lengthOfSelectedText = 0u;
946 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
947 mImpl->mLogicalModel,
949 lengthOfSelectedText );
951 fontDescriptionRun.familyLength = fontFamily.size();
952 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
953 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
954 fontDescriptionRun.familyDefined = true;
956 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
958 // Request to relayout.
959 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
967 mImpl->mRecalculateNaturalSize = true;
968 mImpl->RequestRelayout();
970 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
971 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
972 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
974 // As the font changes, recalculate the handle positions is needed.
975 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
976 mImpl->mEventData->mUpdateRightSelectionPosition = true;
977 mImpl->mEventData->mUpdateHighlightBox = true;
978 mImpl->mEventData->mScrollAfterUpdatePosition = true;
983 const std::string& Controller::GetInputFontFamily() const
985 if( NULL != mImpl->mEventData )
987 return mImpl->mEventData->mInputStyle.familyName;
990 // Return the default font's family if there is no EventData.
991 return GetDefaultFontFamily();
994 void Controller::SetInputFontWeight( FontWeight weight )
996 if( NULL != mImpl->mEventData )
998 mImpl->mEventData->mInputStyle.weight = weight;
999 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1001 if( EventData::SELECTING == mImpl->mEventData->mState )
1003 CharacterIndex startOfSelectedText = 0u;
1004 Length lengthOfSelectedText = 0u;
1005 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1006 mImpl->mLogicalModel,
1007 startOfSelectedText,
1008 lengthOfSelectedText );
1010 fontDescriptionRun.weight = weight;
1011 fontDescriptionRun.weightDefined = true;
1013 // Request to relayout.
1014 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1019 UPDATE_LAYOUT_SIZE |
1022 mImpl->mRecalculateNaturalSize = true;
1023 mImpl->RequestRelayout();
1025 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1026 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1027 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1029 // As the font might change, recalculate the handle positions is needed.
1030 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1031 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1032 mImpl->mEventData->mUpdateHighlightBox = true;
1033 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1038 bool Controller::IsInputFontWeightDefined() const
1040 bool defined = false;
1042 if( NULL != mImpl->mEventData )
1044 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1050 FontWeight Controller::GetInputFontWeight() const
1052 if( NULL != mImpl->mEventData )
1054 return mImpl->mEventData->mInputStyle.weight;
1057 return GetDefaultFontWeight();
1060 void Controller::SetInputFontWidth( FontWidth width )
1062 if( NULL != mImpl->mEventData )
1064 mImpl->mEventData->mInputStyle.width = width;
1065 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1067 if( EventData::SELECTING == mImpl->mEventData->mState )
1069 CharacterIndex startOfSelectedText = 0u;
1070 Length lengthOfSelectedText = 0u;
1071 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1072 mImpl->mLogicalModel,
1073 startOfSelectedText,
1074 lengthOfSelectedText );
1076 fontDescriptionRun.width = width;
1077 fontDescriptionRun.widthDefined = true;
1079 // Request to relayout.
1080 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1085 UPDATE_LAYOUT_SIZE |
1088 mImpl->mRecalculateNaturalSize = true;
1089 mImpl->RequestRelayout();
1091 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1092 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1093 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1095 // As the font might change, recalculate the handle positions is needed.
1096 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1097 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1098 mImpl->mEventData->mUpdateHighlightBox = true;
1099 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1104 bool Controller::IsInputFontWidthDefined() const
1106 bool defined = false;
1108 if( NULL != mImpl->mEventData )
1110 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1116 FontWidth Controller::GetInputFontWidth() const
1118 if( NULL != mImpl->mEventData )
1120 return mImpl->mEventData->mInputStyle.width;
1123 return GetDefaultFontWidth();
1126 void Controller::SetInputFontSlant( FontSlant slant )
1128 if( NULL != mImpl->mEventData )
1130 mImpl->mEventData->mInputStyle.slant = slant;
1131 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1133 if( EventData::SELECTING == mImpl->mEventData->mState )
1135 CharacterIndex startOfSelectedText = 0u;
1136 Length lengthOfSelectedText = 0u;
1137 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1138 mImpl->mLogicalModel,
1139 startOfSelectedText,
1140 lengthOfSelectedText );
1142 fontDescriptionRun.slant = slant;
1143 fontDescriptionRun.slantDefined = true;
1145 // Request to relayout.
1146 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1151 UPDATE_LAYOUT_SIZE |
1154 mImpl->mRecalculateNaturalSize = true;
1155 mImpl->RequestRelayout();
1157 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1158 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1159 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1161 // As the font might change, recalculate the handle positions is needed.
1162 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1163 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1164 mImpl->mEventData->mUpdateHighlightBox = true;
1165 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1170 bool Controller::IsInputFontSlantDefined() const
1172 bool defined = false;
1174 if( NULL != mImpl->mEventData )
1176 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1182 FontSlant Controller::GetInputFontSlant() const
1184 if( NULL != mImpl->mEventData )
1186 return mImpl->mEventData->mInputStyle.slant;
1189 return GetDefaultFontSlant();
1192 void Controller::SetInputFontPointSize( float size )
1194 if( NULL != mImpl->mEventData )
1196 mImpl->mEventData->mInputStyle.size = size;
1197 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1199 if( EventData::SELECTING == mImpl->mEventData->mState )
1201 CharacterIndex startOfSelectedText = 0u;
1202 Length lengthOfSelectedText = 0u;
1203 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1204 mImpl->mLogicalModel,
1205 startOfSelectedText,
1206 lengthOfSelectedText );
1208 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1209 fontDescriptionRun.sizeDefined = true;
1211 // Request to relayout.
1212 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1217 UPDATE_LAYOUT_SIZE |
1220 mImpl->mRecalculateNaturalSize = true;
1221 mImpl->RequestRelayout();
1223 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1224 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1225 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1227 // As the font might change, recalculate the handle positions is needed.
1228 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1229 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1230 mImpl->mEventData->mUpdateHighlightBox = true;
1231 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1236 float Controller::GetInputFontPointSize() const
1238 if( NULL != mImpl->mEventData )
1240 return mImpl->mEventData->mInputStyle.size;
1243 // Return the default font's point size if there is no EventData.
1244 return GetDefaultPointSize();
1247 void Controller::SetInputLineSpacing( float lineSpacing )
1249 if( NULL != mImpl->mEventData )
1251 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1252 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1256 float Controller::GetInputLineSpacing() const
1258 if( NULL != mImpl->mEventData )
1260 return mImpl->mEventData->mInputStyle.lineSpacing;
1266 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1268 if( NULL != mImpl->mEventData )
1270 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1274 const std::string& Controller::GetInputShadowProperties() const
1276 if( NULL != mImpl->mEventData )
1278 return mImpl->mEventData->mInputStyle.shadowProperties;
1281 return GetDefaultShadowProperties();
1284 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1286 if( NULL != mImpl->mEventData )
1288 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1292 const std::string& Controller::GetInputUnderlineProperties() const
1294 if( NULL != mImpl->mEventData )
1296 return mImpl->mEventData->mInputStyle.underlineProperties;
1299 return GetDefaultUnderlineProperties();
1302 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1304 if( NULL != mImpl->mEventData )
1306 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1310 const std::string& Controller::GetInputEmbossProperties() const
1312 if( NULL != mImpl->mEventData )
1314 return mImpl->mEventData->mInputStyle.embossProperties;
1317 return GetDefaultEmbossProperties();
1320 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1322 if( NULL != mImpl->mEventData )
1324 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1328 const std::string& Controller::GetInputOutlineProperties() const
1330 if( NULL != mImpl->mEventData )
1332 return mImpl->mEventData->mInputStyle.outlineProperties;
1335 return GetDefaultOutlineProperties();
1338 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1340 if( NULL != mImpl->mEventData )
1342 mImpl->mEventData->mDoubleTapAction = action;
1346 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1348 NoTextTap::Action action = NoTextTap::NO_ACTION;
1350 if( NULL != mImpl->mEventData )
1352 action = mImpl->mEventData->mDoubleTapAction;
1358 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1360 if( NULL != mImpl->mEventData )
1362 mImpl->mEventData->mLongPressAction = action;
1366 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1368 NoTextTap::Action action = NoTextTap::NO_ACTION;
1370 if( NULL != mImpl->mEventData )
1372 return mImpl->mEventData->mLongPressAction;
1378 // public : Queries & retrieves.
1380 LayoutEngine& Controller::GetLayoutEngine()
1382 return mImpl->mLayoutEngine;
1385 View& Controller::GetView()
1387 return mImpl->mView;
1390 const Vector2& Controller::GetScrollPosition() const
1392 return mImpl->mScrollPosition;
1395 Vector3 Controller::GetNaturalSize()
1397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1398 Vector3 naturalSize;
1400 // Make sure the model is up-to-date before layouting
1401 ProcessModifyEvents();
1403 if( mImpl->mRecalculateNaturalSize )
1405 // Operations that can be done only once until the text changes.
1406 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1413 GET_GLYPH_METRICS );
1415 // Set the update info to relayout the whole text.
1416 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1417 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mLogicalModel->mText.Count();
1419 // Make sure the model is up-to-date before layouting
1420 mImpl->UpdateModel( onlyOnceOperations );
1422 // Layout the text for the new width.
1423 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1425 // Store the actual control's size to restore later.
1426 const Size actualControlSize = mImpl->mVisualModel->mControlSize;
1428 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1429 static_cast<OperationsMask>( onlyOnceOperations |
1431 naturalSize.GetVectorXY() );
1433 // Do not do again the only once operations.
1434 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1436 // Do the size related operations again.
1437 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1440 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1442 // Stores the natural size to avoid recalculate it again
1443 // unless the text/style changes.
1444 mImpl->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1446 mImpl->mRecalculateNaturalSize = false;
1448 // Clear the update info. This info will be set the next time the text is updated.
1449 mImpl->mTextUpdateInfo.Clear();
1451 // Restore the actual control's size.
1452 mImpl->mVisualModel->mControlSize = actualControlSize;
1454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1458 naturalSize = mImpl->mVisualModel->GetNaturalSize();
1460 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1463 naturalSize.x = ConvertToEven( naturalSize.x );
1464 naturalSize.y = ConvertToEven( naturalSize.y );
1469 float Controller::GetHeightForWidth( float width )
1471 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1472 // Make sure the model is up-to-date before layouting
1473 ProcessModifyEvents();
1476 if( fabsf( width - mImpl->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
1478 // Operations that can be done only once until the text changes.
1479 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1486 GET_GLYPH_METRICS );
1488 // Set the update info to relayout the whole text.
1489 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1490 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mLogicalModel->mText.Count();
1492 // Make sure the model is up-to-date before layouting
1493 mImpl->UpdateModel( onlyOnceOperations );
1496 // Layout the text for the new width.
1497 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1499 // Store the actual control's width.
1500 const float actualControlWidth = mImpl->mVisualModel->mControlSize.width;
1502 DoRelayout( Size( width, MAX_FLOAT ),
1503 static_cast<OperationsMask>( onlyOnceOperations |
1507 // Do not do again the only once operations.
1508 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1510 // Do the size related operations again.
1511 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1515 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1517 // Clear the update info. This info will be set the next time the text is updated.
1518 mImpl->mTextUpdateInfo.Clear();
1520 // Restore the actual control's width.
1521 mImpl->mVisualModel->mControlSize.width = actualControlWidth;
1523 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1527 layoutSize = mImpl->mVisualModel->GetLayoutSize();
1528 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1531 return layoutSize.height;
1534 // public : Relayout.
1536 Controller::UpdateTextType Controller::Relayout( const Size& size )
1538 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, (mImpl->mAutoScrollEnabled)?"true":"false" );
1540 UpdateTextType updateTextType = NONE_UPDATED;
1542 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
1544 if( 0u != mImpl->mVisualModel->mGlyphPositions.Count() )
1546 mImpl->mVisualModel->mGlyphPositions.Clear();
1547 updateTextType = MODEL_UPDATED;
1550 // Clear the update info. This info will be set the next time the text is updated.
1551 mImpl->mTextUpdateInfo.Clear();
1553 // Not worth to relayout if width or height is equal to zero.
1554 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
1556 return updateTextType;
1559 // Whether a new size has been set.
1560 const bool newSize = ( size != mImpl->mVisualModel->mControlSize );
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mVisualModel->mControlSize.width, mImpl->mVisualModel->mControlSize.height );
1566 // Layout operations that need to be done if the size changes.
1567 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1570 UPDATE_LAYOUT_SIZE |
1572 // Set the update info to relayout the whole text.
1573 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1574 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1576 // Store the size used to layout the text.
1577 mImpl->mVisualModel->mControlSize = size;
1580 // Whether there are modify events.
1581 if( 0u != mImpl->mModifyEvents.Count() )
1583 // Style operations that need to be done if the text is modified.
1584 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1588 // Make sure the model is up-to-date before layouting.
1589 ProcessModifyEvents();
1590 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
1594 updated = DoRelayout( size,
1595 mImpl->mOperationsPending,
1596 layoutSize ) || updated;
1600 updateTextType = MODEL_UPDATED;
1603 // Do not re-do any operation until something changes.
1604 mImpl->mOperationsPending = NO_OPERATION;
1606 // Whether the text control is editable
1607 const bool isEditable = NULL != mImpl->mEventData;
1609 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
1611 if( newSize && isEditable )
1613 offset = mImpl->mScrollPosition;
1616 if( !isEditable || !IsMultiLineEnabled() )
1618 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
1619 CalculateVerticalOffset( size );
1626 // If there is a new size, the scroll position needs to be clamped.
1627 mImpl->ClampHorizontalScroll( layoutSize );
1629 // Update the decorator's positions is needed if there is a new size.
1630 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mScrollPosition - offset );
1633 // Move the cursor, grab handle etc.
1634 if( mImpl->ProcessInputEvents() )
1636 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
1640 // Clear the update info. This info will be set the next time the text is updated.
1641 mImpl->mTextUpdateInfo.Clear();
1642 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
1644 return updateTextType;
1647 // public : Input style change signals.
1649 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1651 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
1654 void Controller::ProcessInputStyleChangedSignals()
1656 if( NULL == mImpl->mEventData )
1662 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1663 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1667 const InputStyle::Mask mask = *it;
1669 if( NULL != mImpl->mEditableControlInterface )
1671 // Emit the input style changed signal.
1672 mImpl->mEditableControlInterface->InputStyleChanged( mask );
1676 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1679 // public : Text-input Event Queuing.
1681 void Controller::KeyboardFocusGainEvent()
1683 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
1685 if( NULL != mImpl->mEventData )
1687 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
1688 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
1690 mImpl->ChangeState( EventData::EDITING );
1691 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
1692 mImpl->mEventData->mUpdateInputStyle = true;
1694 mImpl->NotifyImfMultiLineStatus();
1695 if( mImpl->IsShowingPlaceholderText() )
1697 // Show alternative placeholder-text when editing
1698 ShowPlaceholderText();
1701 mImpl->RequestRelayout();
1705 void Controller::KeyboardFocusLostEvent()
1707 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
1709 if( NULL != mImpl->mEventData )
1711 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
1713 mImpl->ChangeState( EventData::INACTIVE );
1715 if( !mImpl->IsShowingRealText() )
1717 // Revert to regular placeholder-text when not editing
1718 ShowPlaceholderText();
1722 mImpl->RequestRelayout();
1725 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
1727 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
1729 bool textChanged = false;
1730 bool relayoutNeeded = false;
1732 if( ( NULL != mImpl->mEventData ) &&
1733 ( keyEvent.state == KeyEvent::Down ) )
1735 int keyCode = keyEvent.keyCode;
1736 const std::string& keyString = keyEvent.keyPressed;
1738 // Pre-process to separate modifying events from non-modifying input events.
1739 if( Dali::DALI_KEY_ESCAPE == keyCode )
1741 // Escape key is a special case which causes focus loss
1742 KeyboardFocusLostEvent();
1744 // Will request for relayout.
1745 relayoutNeeded = true;
1747 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
1748 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
1749 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
1750 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
1752 Event event( Event::CURSOR_KEY_EVENT );
1753 event.p1.mInt = keyCode;
1754 mImpl->mEventData->mEventQueue.push_back( event );
1756 // Will request for relayout.
1757 relayoutNeeded = true;
1759 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
1761 textChanged = BackspaceKeyEvent();
1763 // Will request for relayout.
1764 relayoutNeeded = true;
1766 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
1767 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
1768 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
1770 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
1771 mImpl->ChangeState( EventData::INACTIVE );
1773 // Will request for relayout.
1774 relayoutNeeded = true;
1776 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1778 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
1780 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
1781 // and a character is typed after the type of a upper case latin character.
1785 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
1787 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
1792 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
1794 // IMF manager is no longer handling key-events
1795 mImpl->ClearPreEditFlag();
1797 InsertText( keyString, COMMIT );
1800 // Will request for relayout.
1801 relayoutNeeded = true;
1804 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
1805 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
1806 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
1807 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
1808 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
1810 // Should not change the state if the key is the shift send by the imf manager.
1811 // Otherwise, when the state is SELECTING the text controller can't send the right
1812 // surrounding info to the imf.
1813 mImpl->ChangeState( EventData::EDITING );
1815 // Will request for relayout.
1816 relayoutNeeded = true;
1819 if( relayoutNeeded )
1821 mImpl->RequestRelayout();
1826 ( NULL != mImpl->mEditableControlInterface ) )
1828 // Do this last since it provides callbacks into application code
1829 mImpl->mEditableControlInterface->TextChanged();
1835 void Controller::TapEvent( unsigned int tapCount, float x, float y )
1837 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
1839 if( NULL != mImpl->mEventData )
1841 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
1842 EventData::State state( mImpl->mEventData->mState );
1843 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
1845 if( 1u == tapCount )
1847 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
1849 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
1852 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
1854 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
1855 relayoutNeeded = true;
1859 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
1861 // Hide placeholder text
1865 if( EventData::INACTIVE == state )
1867 mImpl->ChangeState( EventData::EDITING );
1869 else if( !mImpl->IsClipboardEmpty() )
1871 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
1873 relayoutNeeded = true;
1876 else if( 2u == tapCount )
1878 if( mImpl->mEventData->mSelectionEnabled &&
1879 mImpl->IsShowingRealText() )
1881 relayoutNeeded = true;
1882 mImpl->mEventData->mIsLeftHandleSelected = true;
1883 mImpl->mEventData->mIsRightHandleSelected = true;
1887 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
1888 if( relayoutNeeded )
1890 Event event( Event::TAP_EVENT );
1891 event.p1.mUint = tapCount;
1892 event.p2.mFloat = x;
1893 event.p3.mFloat = y;
1894 mImpl->mEventData->mEventQueue.push_back( event );
1896 mImpl->RequestRelayout();
1900 // Reset keyboard as tap event has occurred.
1901 mImpl->ResetImfManager();
1904 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
1906 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
1908 if( NULL != mImpl->mEventData )
1910 Event event( Event::PAN_EVENT );
1911 event.p1.mInt = state;
1912 event.p2.mFloat = displacement.x;
1913 event.p3.mFloat = displacement.y;
1914 mImpl->mEventData->mEventQueue.push_back( event );
1916 mImpl->RequestRelayout();
1920 void Controller::LongPressEvent( Gesture::State state, float x, float y )
1922 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
1924 if( ( state == Gesture::Started ) &&
1925 ( NULL != mImpl->mEventData ) )
1927 // The 1st long-press on inactive text-field is treated as tap
1928 if( EventData::INACTIVE == mImpl->mEventData->mState )
1930 mImpl->ChangeState( EventData::EDITING );
1932 Event event( Event::TAP_EVENT );
1934 event.p2.mFloat = x;
1935 event.p3.mFloat = y;
1936 mImpl->mEventData->mEventQueue.push_back( event );
1938 mImpl->RequestRelayout();
1940 else if( !mImpl->IsShowingRealText() )
1942 Event event( Event::LONG_PRESS_EVENT );
1943 event.p1.mInt = state;
1944 event.p2.mFloat = x;
1945 event.p3.mFloat = y;
1946 mImpl->mEventData->mEventQueue.push_back( event );
1947 mImpl->RequestRelayout();
1951 // Reset the imf manager to commit the pre-edit before selecting the text.
1952 mImpl->ResetImfManager();
1954 Event event( Event::LONG_PRESS_EVENT );
1955 event.p1.mInt = state;
1956 event.p2.mFloat = x;
1957 event.p3.mFloat = y;
1958 mImpl->mEventData->mEventQueue.push_back( event );
1959 mImpl->RequestRelayout();
1961 mImpl->mEventData->mIsLeftHandleSelected = true;
1962 mImpl->mEventData->mIsRightHandleSelected = true;
1967 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1969 // Whether the text needs to be relaid-out.
1970 bool requestRelayout = false;
1972 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
1973 bool retrieveText = false;
1974 bool retrieveCursor = false;
1976 switch( imfEvent.eventName )
1978 case ImfManager::COMMIT:
1980 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
1981 requestRelayout = true;
1982 retrieveCursor = true;
1985 case ImfManager::PREEDIT:
1987 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
1988 requestRelayout = true;
1989 retrieveCursor = true;
1992 case ImfManager::DELETESURROUNDING:
1994 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
1995 imfEvent.numberOfChars,
1996 DONT_UPDATE_INPUT_STYLE );
2000 if( ( 0u != mImpl->mLogicalModel->mText.Count() ) ||
2001 !mImpl->IsPlaceholderAvailable() )
2003 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2007 ShowPlaceholderText();
2009 mImpl->mEventData->mUpdateCursorPosition = true;
2010 mImpl->mEventData->mScrollAfterDelete = true;
2012 requestRelayout = true;
2016 case ImfManager::GETSURROUNDING:
2018 retrieveText = true;
2019 retrieveCursor = true;
2022 case ImfManager::VOID:
2029 if( requestRelayout )
2031 mImpl->mOperationsPending = ALL_OPERATIONS;
2032 mImpl->RequestRelayout();
2036 CharacterIndex cursorPosition = 0u;
2037 Length numberOfWhiteSpaces = 0u;
2039 if( retrieveCursor )
2041 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2043 cursorPosition = mImpl->GetLogicalCursorPosition();
2045 if( cursorPosition < numberOfWhiteSpaces )
2047 cursorPosition = 0u;
2051 cursorPosition -= numberOfWhiteSpaces;
2057 mImpl->GetText( numberOfWhiteSpaces, text );
2060 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2062 if( requestRelayout &&
2063 ( NULL != mImpl->mEditableControlInterface ) )
2065 // Do this last since it provides callbacks into application code
2066 mImpl->mEditableControlInterface->TextChanged();
2069 return callbackData;
2072 void Controller::PasteClipboardItemEvent()
2074 // Retrieve the clipboard contents first
2075 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2076 std::string stringToPaste( notifier.GetContent() );
2078 // Commit the current pre-edit text; the contents of the clipboard should be appended
2079 mImpl->ResetImfManager();
2081 // Temporary disable hiding clipboard
2082 mImpl->SetClipboardHideEnable( false );
2085 PasteText( stringToPaste );
2087 mImpl->SetClipboardHideEnable( true );
2090 // protected : Inherit from Text::Decorator::ControllerInterface.
2092 void Controller::GetTargetSize( Vector2& targetSize )
2094 targetSize = mImpl->mVisualModel->mControlSize;
2097 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2099 if( NULL != mImpl->mEditableControlInterface )
2101 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2105 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2107 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2109 if( NULL != mImpl->mEventData )
2111 switch( handleType )
2115 Event event( Event::GRAB_HANDLE_EVENT );
2116 event.p1.mUint = state;
2117 event.p2.mFloat = x;
2118 event.p3.mFloat = y;
2120 mImpl->mEventData->mEventQueue.push_back( event );
2123 case LEFT_SELECTION_HANDLE:
2125 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2126 event.p1.mUint = state;
2127 event.p2.mFloat = x;
2128 event.p3.mFloat = y;
2130 mImpl->mEventData->mEventQueue.push_back( event );
2133 case RIGHT_SELECTION_HANDLE:
2135 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2136 event.p1.mUint = state;
2137 event.p2.mFloat = x;
2138 event.p3.mFloat = y;
2140 mImpl->mEventData->mEventQueue.push_back( event );
2143 case LEFT_SELECTION_HANDLE_MARKER:
2144 case RIGHT_SELECTION_HANDLE_MARKER:
2146 // Markers do not move the handles.
2149 case HANDLE_TYPE_COUNT:
2151 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2155 mImpl->RequestRelayout();
2159 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2161 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2163 if( NULL == mImpl->mEventData )
2170 case Toolkit::TextSelectionPopup::CUT:
2172 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2173 mImpl->mOperationsPending = ALL_OPERATIONS;
2175 if( ( 0u != mImpl->mLogicalModel->mText.Count() ) ||
2176 !mImpl->IsPlaceholderAvailable() )
2178 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2182 ShowPlaceholderText();
2185 mImpl->mEventData->mUpdateCursorPosition = true;
2186 mImpl->mEventData->mScrollAfterDelete = true;
2188 mImpl->RequestRelayout();
2190 if( NULL != mImpl->mEditableControlInterface )
2192 mImpl->mEditableControlInterface->TextChanged();
2196 case Toolkit::TextSelectionPopup::COPY:
2198 mImpl->SendSelectionToClipboard( false ); // Text not modified
2200 mImpl->mEventData->mUpdateCursorPosition = true;
2202 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2205 case Toolkit::TextSelectionPopup::PASTE:
2207 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2210 case Toolkit::TextSelectionPopup::SELECT:
2212 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2214 if( mImpl->mEventData->mSelectionEnabled )
2216 // Creates a SELECT event.
2217 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2221 case Toolkit::TextSelectionPopup::SELECT_ALL:
2223 // Creates a SELECT_ALL event
2224 SelectEvent( 0.f, 0.f, true );
2227 case Toolkit::TextSelectionPopup::CLIPBOARD:
2229 mImpl->ShowClipboard();
2232 case Toolkit::TextSelectionPopup::NONE:
2240 // private : Update.
2242 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2244 bool removedPrevious( false );
2245 bool maxLengthReached( false );
2247 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2249 if( NULL == mImpl->mEventData )
2254 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2255 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2256 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2258 // TODO: At the moment the underline runs are only for pre-edit.
2259 mImpl->mVisualModel->mUnderlineRuns.Clear();
2261 // Keep the current number of characters.
2262 const Length currentNumberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mLogicalModel->mText.Count() : 0u;
2264 // Remove the previous IMF pre-edit.
2265 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2267 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2268 mImpl->mEventData->mPreEditLength,
2269 DONT_UPDATE_INPUT_STYLE );
2271 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2272 mImpl->mEventData->mPreEditLength = 0u;
2276 // Remove the previous Selection.
2277 removedPrevious = RemoveSelectedText();
2280 Vector<Character> utf32Characters;
2281 Length characterCount = 0u;
2285 // Convert text into UTF-32
2286 utf32Characters.Resize( text.size() );
2288 // This is a bit horrible but std::string returns a (signed) char*
2289 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2291 // Transform a text array encoded in utf8 into an array encoded in utf32.
2292 // It returns the actual number of characters.
2293 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2294 utf32Characters.Resize( characterCount );
2296 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2297 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2300 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2302 // The placeholder text is no longer needed
2303 if( mImpl->IsShowingPlaceholderText() )
2308 mImpl->ChangeState( EventData::EDITING );
2310 // Handle the IMF (predicitive text) state changes
2311 if( COMMIT == type )
2313 // IMF manager is no longer handling key-events
2314 mImpl->ClearPreEditFlag();
2318 if( !mImpl->mEventData->mPreEditFlag )
2320 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2322 // Record the start of the pre-edit text
2323 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2326 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2327 mImpl->mEventData->mPreEditFlag = true;
2329 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2332 const Length numberOfCharactersInModel = mImpl->mLogicalModel->mText.Count();
2334 // Restrict new text to fit within Maximum characters setting.
2335 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2336 maxLengthReached = ( characterCount > maxSizeOfNewText );
2338 // The cursor position.
2339 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2341 // Update the text's style.
2343 // Updates the text style runs by adding characters.
2344 mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2346 // Get the character index from the cursor index.
2347 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2349 // Retrieve the text's style for the given index.
2351 mImpl->RetrieveDefaultInputStyle( style );
2352 mImpl->mLogicalModel->RetrieveStyle( styleIndex, style );
2354 // Whether to add a new text color run.
2355 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2357 // Whether to add a new font run.
2358 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2359 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2360 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2361 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2362 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2367 const VectorBase::SizeType numberOfRuns = mImpl->mLogicalModel->mColorRuns.Count();
2368 mImpl->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2370 ColorRun& colorRun = *( mImpl->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2371 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2372 colorRun.characterRun.characterIndex = cursorIndex;
2373 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2376 if( addFontNameRun ||
2382 const VectorBase::SizeType numberOfRuns = mImpl->mLogicalModel->mFontDescriptionRuns.Count();
2383 mImpl->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2385 FontDescriptionRun& fontDescriptionRun = *( mImpl->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2387 if( addFontNameRun )
2389 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2390 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2391 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2392 fontDescriptionRun.familyDefined = true;
2394 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2397 if( addFontWeightRun )
2399 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2400 fontDescriptionRun.weightDefined = true;
2403 if( addFontWidthRun )
2405 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2406 fontDescriptionRun.widthDefined = true;
2409 if( addFontSlantRun )
2411 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2412 fontDescriptionRun.slantDefined = true;
2415 if( addFontSizeRun )
2417 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2418 fontDescriptionRun.sizeDefined = true;
2421 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2422 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2425 // Insert at current cursor position.
2426 Vector<Character>& modifyText = mImpl->mLogicalModel->mText;
2428 if( cursorIndex < numberOfCharactersInModel )
2430 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2434 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2437 // Mark the first paragraph to be updated.
2438 if( LayoutEngine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2440 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2441 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2442 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2443 mImpl->mTextUpdateInfo.mClearAll = true;
2447 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2448 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2451 // Update the cursor index.
2452 cursorIndex += maxSizeOfNewText;
2454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
2457 const Length numberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mLogicalModel->mText.Count() : 0u;
2459 if( ( 0u == mImpl->mLogicalModel->mText.Count() ) &&
2460 mImpl->IsPlaceholderAvailable() )
2462 // Show place-holder if empty after removing the pre-edit text
2463 ShowPlaceholderText();
2464 mImpl->mEventData->mUpdateCursorPosition = true;
2465 mImpl->ClearPreEditFlag();
2467 else if( removedPrevious ||
2468 ( 0 != utf32Characters.Count() ) )
2470 // Queue an inserted event
2471 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
2473 mImpl->mEventData->mUpdateCursorPosition = true;
2474 if( numberOfCharacters < currentNumberOfCharacters )
2476 mImpl->mEventData->mScrollAfterDelete = true;
2480 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2484 if( maxLengthReached )
2486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mLogicalModel->mText.Count() );
2488 mImpl->ResetImfManager();
2490 if( NULL != mImpl->mEditableControlInterface )
2492 // Do this last since it provides callbacks into application code
2493 mImpl->mEditableControlInterface->MaxLengthReached();
2498 void Controller::PasteText( const std::string& stringToPaste )
2500 InsertText( stringToPaste, Text::Controller::COMMIT );
2501 mImpl->ChangeState( EventData::EDITING );
2502 mImpl->RequestRelayout();
2504 if( NULL != mImpl->mEditableControlInterface )
2506 // Do this last since it provides callbacks into application code
2507 mImpl->mEditableControlInterface->TextChanged();
2511 bool Controller::RemoveText( int cursorOffset,
2512 int numberOfCharacters,
2513 UpdateInputStyleType type )
2515 bool removed = false;
2517 if( NULL == mImpl->mEventData )
2522 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
2523 this, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
2525 if( !mImpl->IsShowingPlaceholderText() )
2527 // Delete at current cursor position
2528 Vector<Character>& currentText = mImpl->mLogicalModel->mText;
2529 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2531 CharacterIndex cursorIndex = oldCursorIndex;
2533 // Validate the cursor position & number of characters
2534 if( static_cast< CharacterIndex >( std::abs( cursorOffset ) ) <= cursorIndex )
2536 cursorIndex = oldCursorIndex + cursorOffset;
2539 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
2541 numberOfCharacters = currentText.Count() - cursorIndex;
2544 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.
2545 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
2547 // Mark the paragraphs to be updated.
2548 if( LayoutEngine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2550 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2551 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2552 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
2553 mImpl->mTextUpdateInfo.mClearAll = true;
2557 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2558 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
2561 // Update the input style and remove the text's style before removing the text.
2563 if( UPDATE_INPUT_STYLE == type )
2565 // Keep a copy of the current input style.
2566 InputStyle currentInputStyle;
2567 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
2569 // Set first the default input style.
2570 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
2572 // Update the input style.
2573 mImpl->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
2575 // Compare if the input style has changed.
2576 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
2578 if( hasInputStyleChanged )
2580 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
2581 // Queue the input style changed signal.
2582 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
2586 // Updates the text style runs by removing characters. Runs with no characters are removed.
2587 mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
2589 // Remove the characters.
2590 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
2591 Vector<Character>::Iterator last = first + numberOfCharacters;
2593 currentText.Erase( first, last );
2595 // Cursor position retreat
2596 oldCursorIndex = cursorIndex;
2598 mImpl->mEventData->mScrollAfterDelete = true;
2600 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
2608 bool Controller::RemoveSelectedText()
2610 bool textRemoved( false );
2612 if( EventData::SELECTING == mImpl->mEventData->mState )
2614 std::string removedString;
2615 mImpl->RetrieveSelection( removedString, true );
2617 if( !removedString.empty() )
2620 mImpl->ChangeState( EventData::EDITING );
2627 // private : Relayout.
2629 bool Controller::DoRelayout( const Size& size,
2630 OperationsMask operationsRequired,
2633 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
2634 bool viewUpdated( false );
2636 // Calculate the operations to be done.
2637 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
2639 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
2640 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
2642 // Get the current layout size.
2643 layoutSize = mImpl->mVisualModel->GetLayoutSize();
2645 if( NO_OPERATION != ( LAYOUT & operations ) )
2647 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
2649 // Some vectors with data needed to layout and reorder may be void
2650 // after the first time the text has been laid out.
2651 // Fill the vectors again.
2653 // Calculate the number of glyphs to layout.
2654 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mVisualModel->mCharactersToGlyph;
2655 const Vector<Length>& glyphsPerCharacter = mImpl->mVisualModel->mGlyphsPerCharacter;
2656 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
2657 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
2659 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
2660 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
2661 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
2662 const Length totalNumberOfGlyphs = mImpl->mVisualModel->mGlyphs.Count();
2664 if( 0u == totalNumberOfGlyphs )
2666 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2668 mImpl->mVisualModel->SetLayoutSize( Size::ZERO );
2671 // Nothing else to do if there is no glyphs.
2672 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
2676 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mLogicalModel->mLineBreakInfo;
2677 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mLogicalModel->mWordBreakInfo;
2678 const Vector<CharacterDirection>& characterDirection = mImpl->mLogicalModel->mCharacterDirections;
2679 const Vector<GlyphInfo>& glyphs = mImpl->mVisualModel->mGlyphs;
2680 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mVisualModel->mGlyphsToCharacters;
2681 const Vector<Length>& charactersPerGlyph = mImpl->mVisualModel->mCharactersPerGlyph;
2682 const Character* const textBuffer = mImpl->mLogicalModel->mText.Begin();
2684 // Set the layout parameters.
2685 LayoutParameters layoutParameters( size,
2687 lineBreakInfo.Begin(),
2688 wordBreakInfo.Begin(),
2689 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
2691 glyphsToCharactersMap.Begin(),
2692 charactersPerGlyph.Begin(),
2693 charactersToGlyphBuffer,
2694 glyphsPerCharacterBuffer,
2695 totalNumberOfGlyphs );
2697 // Resize the vector of positions to have the same size than the vector of glyphs.
2698 Vector<Vector2>& glyphPositions = mImpl->mVisualModel->mGlyphPositions;
2699 glyphPositions.Resize( totalNumberOfGlyphs );
2701 // Whether the last character is a new paragraph character.
2702 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mLogicalModel->mText.Count() - 1u ) ) );
2703 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
2705 // The initial glyph and the number of glyphs to layout.
2706 layoutParameters.startGlyphIndex = startGlyphIndex;
2707 layoutParameters.numberOfGlyphs = numberOfGlyphs;
2708 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
2709 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
2711 // Update the visual model.
2713 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
2715 mImpl->mVisualModel->mLines,
2718 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
2722 layoutSize = newLayoutSize;
2724 if ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
2726 mImpl->mAutoScrollDirectionRTL = false;
2729 // Reorder the lines
2730 if( NO_OPERATION != ( REORDER & operations ) )
2732 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mLogicalModel->mBidirectionalParagraphInfo;
2733 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mLogicalModel->mBidirectionalLineInfo;
2735 // Check first if there are paragraphs with bidirectional info.
2736 if( 0u != bidirectionalInfo.Count() )
2739 const Length numberOfLines = mImpl->mVisualModel->mLines.Count();
2741 // Reorder the lines.
2742 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
2743 ReorderLines( bidirectionalInfo,
2745 requestedNumberOfCharacters,
2746 mImpl->mVisualModel->mLines,
2747 bidirectionalLineInfo );
2749 // Set the bidirectional info per line into the layout parameters.
2750 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
2751 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
2753 // Re-layout the text. Reorder those lines with right to left characters.
2754 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
2756 requestedNumberOfCharacters,
2759 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
2761 const LineRun* const firstline = mImpl->mVisualModel->mLines.Begin();
2764 mImpl->mAutoScrollDirectionRTL = firstline->direction;
2770 // Sets the layout size.
2771 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2773 mImpl->mVisualModel->SetLayoutSize( layoutSize );
2778 if( NO_OPERATION != ( ALIGN & operations ) )
2780 // The laid-out lines.
2781 Vector<LineRun>& lines = mImpl->mVisualModel->mLines;
2783 // Need to align with the control's size as the text may contain lines
2784 // starting either with left to right text or right to left.
2785 mImpl->mLayoutEngine.Align( size,
2787 requestedNumberOfCharacters,
2789 mImpl->mAlignmentOffset );
2793 #if defined(DEBUG_ENABLED)
2794 std::string currentText;
2795 GetText( currentText );
2796 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
2798 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
2802 void Controller::CalculateVerticalOffset( const Size& controlSize )
2804 Size layoutSize = mImpl->mVisualModel->GetLayoutSize();
2806 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
2808 // Get the line height of the default font.
2809 layoutSize.height = mImpl->GetDefaultFontLineHeight();
2812 switch( mImpl->mLayoutEngine.GetVerticalAlignment() )
2814 case LayoutEngine::VERTICAL_ALIGN_TOP:
2816 mImpl->mScrollPosition.y = 0.f;
2819 case LayoutEngine::VERTICAL_ALIGN_CENTER:
2821 mImpl->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
2824 case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
2826 mImpl->mScrollPosition.y = controlSize.height - layoutSize.height;
2832 // private : Events.
2834 void Controller::ProcessModifyEvents()
2836 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
2838 if( 0u == events.Count() )
2844 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
2845 endIt = events.End();
2849 const ModifyEvent& event = *it;
2851 if( ModifyEvent::TEXT_REPLACED == event.type )
2853 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
2854 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
2856 TextReplacedEvent();
2858 else if( ModifyEvent::TEXT_INSERTED == event.type )
2860 TextInsertedEvent();
2862 else if( ModifyEvent::TEXT_DELETED == event.type )
2864 // Placeholder-text cannot be deleted
2865 if( !mImpl->IsShowingPlaceholderText() )
2872 if( NULL != mImpl->mEventData )
2874 // When the text is being modified, delay cursor blinking
2875 mImpl->mEventData->mDecorator->DelayCursorBlink();
2878 // Discard temporary text
2882 void Controller::TextReplacedEvent()
2884 // The natural size needs to be re-calculated.
2885 mImpl->mRecalculateNaturalSize = true;
2887 // Apply modifications to the model
2888 mImpl->mOperationsPending = ALL_OPERATIONS;
2891 void Controller::TextInsertedEvent()
2893 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
2895 if( NULL == mImpl->mEventData )
2900 // The natural size needs to be re-calculated.
2901 mImpl->mRecalculateNaturalSize = true;
2903 // Apply modifications to the model; TODO - Optimize this
2904 mImpl->mOperationsPending = ALL_OPERATIONS;
2907 void Controller::TextDeletedEvent()
2909 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
2911 if( NULL == mImpl->mEventData )
2916 // The natural size needs to be re-calculated.
2917 mImpl->mRecalculateNaturalSize = true;
2919 // Apply modifications to the model; TODO - Optimize this
2920 mImpl->mOperationsPending = ALL_OPERATIONS;
2923 void Controller::SelectEvent( float x, float y, bool selectAll )
2925 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
2927 if( NULL != mImpl->mEventData )
2931 Event event( Event::SELECT_ALL );
2932 mImpl->mEventData->mEventQueue.push_back( event );
2936 Event event( Event::SELECT );
2937 event.p2.mFloat = x;
2938 event.p3.mFloat = y;
2939 mImpl->mEventData->mEventQueue.push_back( event );
2942 mImpl->mEventData->mIsLeftHandleSelected = true;
2943 mImpl->mEventData->mIsRightHandleSelected = true;
2944 mImpl->RequestRelayout();
2948 bool Controller::BackspaceKeyEvent()
2950 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
2952 bool removed = false;
2954 if( NULL == mImpl->mEventData )
2959 // IMF manager is no longer handling key-events
2960 mImpl->ClearPreEditFlag();
2962 if( EventData::SELECTING == mImpl->mEventData->mState )
2964 removed = RemoveSelectedText();
2966 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
2968 // Remove the character before the current cursor position
2969 removed = RemoveText( -1,
2971 UPDATE_INPUT_STYLE );
2976 if( ( 0u != mImpl->mLogicalModel->mText.Count() ) ||
2977 !mImpl->IsPlaceholderAvailable() )
2979 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2983 ShowPlaceholderText();
2985 mImpl->mEventData->mUpdateCursorPosition = true;
2986 mImpl->mEventData->mScrollAfterDelete = true;
2992 // private : Helpers.
2994 void Controller::ResetText()
2997 mImpl->mLogicalModel->mText.Clear();
2999 // We have cleared everything including the placeholder-text
3000 mImpl->PlaceholderCleared();
3002 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3003 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3004 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3006 // Clear any previous text.
3007 mImpl->mTextUpdateInfo.mClearAll = true;
3009 // The natural size needs to be re-calculated.
3010 mImpl->mRecalculateNaturalSize = true;
3012 // Apply modifications to the model
3013 mImpl->mOperationsPending = ALL_OPERATIONS;
3016 void Controller::ShowPlaceholderText()
3018 if( mImpl->IsPlaceholderAvailable() )
3020 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3022 if( NULL == mImpl->mEventData )
3027 mImpl->mEventData->mIsShowingPlaceholderText = true;
3029 // Disable handles when showing place-holder text
3030 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3031 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3032 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3034 const char* text( NULL );
3037 // TODO - Switch placeholder text styles when changing state
3038 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3039 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3041 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3042 size = mImpl->mEventData->mPlaceholderTextActive.size();
3046 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3047 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3050 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3051 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3053 // Reset model for showing placeholder.
3054 mImpl->mLogicalModel->mText.Clear();
3055 mImpl->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3057 // Convert text into UTF-32
3058 Vector<Character>& utf32Characters = mImpl->mLogicalModel->mText;
3059 utf32Characters.Resize( size );
3061 // This is a bit horrible but std::string returns a (signed) char*
3062 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3064 // Transform a text array encoded in utf8 into an array encoded in utf32.
3065 // It returns the actual number of characters.
3066 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3067 utf32Characters.Resize( characterCount );
3069 // The characters to be added.
3070 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3072 // Reset the cursor position
3073 mImpl->mEventData->mPrimaryCursorPosition = 0;
3075 // The natural size needs to be re-calculated.
3076 mImpl->mRecalculateNaturalSize = true;
3078 // Apply modifications to the model
3079 mImpl->mOperationsPending = ALL_OPERATIONS;
3081 // Update the rest of the model during size negotiation
3082 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3086 void Controller::ClearFontData()
3088 if( mImpl->mFontDefaults )
3090 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3093 // Set flags to update the model.
3094 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3095 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3096 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mLogicalModel->mText.Count();
3098 mImpl->mTextUpdateInfo.mClearAll = true;
3099 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3100 mImpl->mRecalculateNaturalSize = true;
3102 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3107 UPDATE_LAYOUT_SIZE |
3112 void Controller::ClearStyleData()
3114 mImpl->mLogicalModel->mColorRuns.Clear();
3115 mImpl->mLogicalModel->ClearFontDescriptionRuns();
3118 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3120 // Reset the cursor position
3121 if( NULL != mImpl->mEventData )
3123 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3125 // Update the cursor if it's in editing mode.
3126 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3128 mImpl->mEventData->mUpdateCursorPosition = true;
3133 void Controller::ResetScrollPosition()
3135 if( NULL != mImpl->mEventData )
3137 // Reset the scroll position.
3138 mImpl->mScrollPosition = Vector2::ZERO;
3139 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3143 // private : Private contructors & copy operator.
3145 Controller::Controller()
3148 mImpl = new Controller::Impl( NULL, NULL );
3151 Controller::Controller( ControlInterface* controlInterface )
3153 mImpl = new Controller::Impl( controlInterface, NULL );
3156 Controller::Controller( ControlInterface* controlInterface,
3157 EditableControlInterface* editableControlInterface )
3159 mImpl = new Controller::Impl( controlInterface,
3160 editableControlInterface );
3163 // The copy constructor and operator are left unimplemented.
3165 // protected : Destructor.
3167 Controller::~Controller()
3174 } // namespace Toolkit